github.com/df-mc/dragonfly@v0.9.13/server/entity/effect/slowness.go (about)

     1  package effect
     2  
     3  import (
     4  	"github.com/df-mc/dragonfly/server/world"
     5  	"image/color"
     6  )
     7  
     8  // Slowness is a lasting effect that decreases the movement speed of a living entity by 15% for each level
     9  // that the effect has.
    10  type Slowness struct {
    11  	nopLasting
    12  }
    13  
    14  // Start ...
    15  func (Slowness) Start(e world.Entity, lvl int) {
    16  	slowness := 1 - float64(lvl)*0.15
    17  	if slowness <= 0 {
    18  		slowness = 0.00001
    19  	}
    20  	if l, ok := e.(living); ok {
    21  		l.SetSpeed(l.Speed() * slowness)
    22  	}
    23  }
    24  
    25  // End ...
    26  func (Slowness) End(e world.Entity, lvl int) {
    27  	slowness := 1 - float64(lvl)*0.15
    28  	if slowness <= 0 {
    29  		slowness = 0.00001
    30  	}
    31  	if l, ok := e.(living); ok {
    32  		l.SetSpeed(l.Speed() / slowness)
    33  	}
    34  }
    35  
    36  // RGBA ...
    37  func (Slowness) RGBA() color.RGBA {
    38  	return color.RGBA{R: 0x5a, G: 0x6c, B: 0x81, A: 0xff}
    39  }