Class Damage

All Implemented Interfaces:
ICancellableEcsEvent, IMetaStore<Damage>

public class Damage extends CancellableEcsEvent implements IMetaStore<Damage>
A wrapper around a damage event.

Contains the amount of damage, the source of the damage and any extra information about the damage needed.

If cancelled, no damage will be applied.

  • Field Details

    • META_REGISTRY

      @Nonnull public static final MetaRegistry<Damage> META_REGISTRY
      The meta registry for registering damage-specific metaobjects
    • HIT_LOCATION

      @Nonnull public static final MetaKey<org.joml.Vector4d> HIT_LOCATION
      A meta key that holds the hit location of the damage event
    • HIT_ANGLE

      @Nonnull public static final MetaKey<Float> HIT_ANGLE
      A meta key that holds the hit angle of the damage event
    • IMPACT_PARTICLES

      @Nonnull public static final MetaKey<Damage.Particles> IMPACT_PARTICLES
      A meta key that holds the particles to be applied after processing the affiliated damage entry
    • IMPACT_SOUND_EFFECT

      @Nonnull public static final MetaKey<Damage.SoundEffect> IMPACT_SOUND_EFFECT
      A meta key that holds the impact sound effect to be played upon processing the affiliated damage entry
    • PLAYER_IMPACT_SOUND_EFFECT

      @Nonnull public static final MetaKey<Damage.SoundEffect> PLAYER_IMPACT_SOUND_EFFECT
      A meta key that holds the player impact sound effect to be played upon player impact
    • CAMERA_EFFECT

      @Nonnull public static final MetaKey<Damage.CameraEffect> CAMERA_EFFECT
      A meta key that holds the camera effects to be applied after processing the affiliated damage entry
    • DEATH_ICON

      @Nonnull public static final MetaKey<String> DEATH_ICON
      A meta key that holds the death icon string to be used upon death from this damage entry
    • BLOCKED

      @Nonnull public static final MetaKey<Boolean> BLOCKED
      A meta key that indicates whether the damage was blocked (e.g. shield/block)
    • STAMINA_DRAIN_MULTIPLIER

      @Nonnull public static final MetaKey<Float> STAMINA_DRAIN_MULTIPLIER
      A meta key that holds the stamina drain multiplier for this damage entry
    • CAN_BE_PREDICTED

      @Nonnull public static final MetaKey<Boolean> CAN_BE_PREDICTED
      This has been added to display particles for all players (including damage source) in case damage can be predicted (ie projectiles at the moment)
    • INTERACTION_TYPE

      @Nonnull public static final MetaKey<InteractionType> INTERACTION_TYPE
      The interaction type of the chain that dealt this damage (e.g. Primary for a basic weapon swing). Absent for damage that did not come from an interaction chain.
    • KNOCKBACK_COMPONENT

      @Nonnull public static final MetaKey<KnockbackComponent> KNOCKBACK_COMPONENT
      A meta key that holds the knockback component for the target of this damage entry
    • NULL_SOURCE

      @Nonnull public static final Damage.Source NULL_SOURCE
      A reusable null source for damage entries
  • Constructor Details

    • Damage

      public Damage(@Nonnull Damage.Source source, @Nonnull DamageCause damageCause, float amount)
      Default Constructor for a Damage instance
      Parameters:
      source - The source of the damage
      damageCause - The cause of the damage
      amount - The amount of damage applied
    • Damage

      public Damage(@Nonnull Damage.Source source, int damageCauseIndex, float amount)
      Default Constructor for a Damage instance
      Parameters:
      source - The source of the damage
      damageCauseIndex - The index for the damage cause asset that was the cause of the damage
      amount - The amount of damage applied
  • Method Details

    • getDamageCauseIndex

      public int getDamageCauseIndex()
      Returns:
      the index of the cause of the damage.
    • setDamageCauseIndex

      public void setDamageCauseIndex(int damageCauseIndex)
      Called to set the index of the cause of the damage.
      Parameters:
      damageCauseIndex - The new damage cause index.
    • getCause

      @Deprecated @Nullable public DamageCause getCause()
      Deprecated.
      Returns the cause of the damage.
      Returns:
      The cause of the damage event.
    • getSource

      @Nonnull public Damage.Source getSource()
      Returns the source of this damage.
      Returns:
      The source of the damage event.
    • setSource

      public void setSource(@Nonnull Damage.Source source)
      Changes the source of this damage event.
      Parameters:
      source - The new source of the event.
    • getAmount

      public float getAmount()
      Returns the current amount of damage to be dealt
      Returns:
      The damage to be dealt.
    • setAmount

      public void setAmount(float amount)
      Changes the amount of damage that will be dealt.
      Parameters:
      amount - The new damage to be dealt.
    • getInitialAmount

      public float getInitialAmount()
      Returns the initial amount of damage this event was created with.

      This value cannot be changed by any damage system.

      Returns:
      The initial amount of damage that was attempted to be dealt.
    • getDeathMessage

      @Nonnull public Message getDeathMessage(@Nonnull Ref<EntityStore> targetRef, @Nonnull ComponentAccessor<EntityStore> componentAccessor)
      Builds a Message containing a death message relevant to this damage event.

      The death message is decided by the Damage.Source using information from this class.

      Parameters:
      targetRef - The entity reference of the target entity.
      componentAccessor - The ComponentAccessor<EntityStore> for component access.
      Returns:
      The built death message.
    • getMetaStore

      @Nonnull public IMetaStoreImpl<Damage> getMetaStore()
      Description copied from interface: IMetaStore
      Returns the meta store object.
      Specified by:
      getMetaStore in interface IMetaStore<Damage>
      Returns:
      MetaStore object