github.com/df-mc/dragonfly@v0.9.13/server/entity/effect/instant_health.go (about) 1 package effect 2 3 import ( 4 "github.com/df-mc/dragonfly/server/world" 5 "image/color" 6 "time" 7 ) 8 9 // InstantHealth is an instant effect that causes the player that it is applied to immediately regain some 10 // health. The amount of health regained depends on the effect level and potency. 11 type InstantHealth struct { 12 // Potency specifies the potency of the instant health. By default, this value is 1, which means 100% of 13 // the instant health will be applied to an entity. A lingering health potion, for example, has a potency 14 // of 0.5: It heals 1 heart (per tick) instead of 2. 15 Potency float64 16 } 17 18 // WithPotency ... 19 func (i InstantHealth) WithPotency(potency float64) Type { 20 i.Potency = potency 21 return i 22 } 23 24 // Apply instantly heals the world.Entity passed for a bit of health, depending on the effect level and 25 // potency. 26 func (i InstantHealth) Apply(e world.Entity, lvl int, _ time.Duration) { 27 if i.Potency == 0 { 28 // Potency of 1 by default. 29 i.Potency = 1 30 } 31 base := 2 << lvl 32 if l, ok := e.(living); ok { 33 l.Heal(float64(base)*i.Potency, InstantHealingSource{}) 34 } 35 } 36 37 // RGBA ... 38 func (InstantHealth) RGBA() color.RGBA { 39 return color.RGBA{R: 0xf8, G: 0x24, B: 0x23, A: 0xff} 40 } 41 42 // InstantHealingSource is a healing source used when an entity regains 43 // health from an effect.InstantHealth. 44 type InstantHealingSource struct{} 45 46 func (InstantHealingSource) HealingSource() {}