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

     1  package effect
     2  
     3  import (
     4  	"github.com/df-mc/dragonfly/server/world"
     5  	"image/color"
     6  	"time"
     7  )
     8  
     9  // InstantDamage is an instant effect that causes a living entity to immediately take some damage, depending
    10  // on the level and the potency of the effect.
    11  type InstantDamage struct {
    12  	// Potency specifies the potency of the instant damage. By default, this value is 1, which means 100% of
    13  	// the instant damage will be applied to an entity. A lingering damage potion, for example, has a potency
    14  	// of 0.5: It deals 1.5 hearts damage (per tick) instead of 3.
    15  	Potency float64
    16  }
    17  
    18  // WithPotency ...
    19  func (i InstantDamage) WithPotency(potency float64) Type {
    20  	i.Potency = potency
    21  	return i
    22  }
    23  
    24  // Apply ...
    25  func (i InstantDamage) Apply(e world.Entity, lvl int, _ time.Duration) {
    26  	if i.Potency == 0 {
    27  		// Potency of 1 by default.
    28  		i.Potency = 1
    29  	}
    30  	base := 3 << lvl
    31  	if l, ok := e.(living); ok {
    32  		l.Hurt(float64(base)*i.Potency, InstantDamageSource{})
    33  	}
    34  }
    35  
    36  // RGBA ...
    37  func (InstantDamage) RGBA() color.RGBA {
    38  	return color.RGBA{R: 0x43, G: 0x0a, B: 0x09, A: 0xff}
    39  }
    40  
    41  // InstantDamageSource is used for damage caused by an effect.InstantDamage
    42  // applied to an entity.
    43  type InstantDamageSource struct{}
    44  
    45  func (InstantDamageSource) ReducedByArmour() bool     { return false }
    46  func (InstantDamageSource) ReducedByResistance() bool { return true }
    47  func (InstantDamageSource) Fire() bool                { return false }