Class EntityScript<T extends IEntity>

java.lang.Object
de.gurkenlabs.litiengine.scripting.AbstractScript<T>
de.gurkenlabs.litiengine.scripting.EntityScript<T>
Type Parameters:
T - The required entity host type.
All Implemented Interfaces:
ScriptInstance
Direct Known Subclasses:
CreatureScript

public abstract class EntityScript<T extends IEntity> extends AbstractScript<T>
Base class for scripts attached to an entity.
  • Constructor Details

    • EntityScript

      public EntityScript()
  • Method Details

    • attached

      protected final void attached() throws Exception
      Description copied from class: AbstractScript
      Called after the context is installed and the script becomes active.
      Overrides:
      attached in class AbstractScript<T extends IEntity>
      Throws:
      Exception - if initialization fails.
    • detached

      protected final void detached() throws Exception
      Description copied from class: AbstractScript
      Called before context-owned resources are released.
      Overrides:
      detached in class AbstractScript<T extends IEntity>
      Throws:
      Exception - if cleanup fails.
    • onLoaded

      protected void onLoaded() throws Exception
      Called from the entity's loaded event after its environment is available.
      Throws:
      Exception - if initialization fails.
    • onUnloaded

      protected void onUnloaded() throws Exception
      Called when the entity controller is detached or the entity is removed.
      Throws:
      Exception - if cleanup fails.
    • onMessage

      protected void onMessage(EntityMessageEvent event) throws Exception
      Called for messages delivered to the attached entity.
      Parameters:
      event - The message event.
      Throws:
      Exception - if handling fails.
    • onMessage

      protected void onMessage(String message, Object sender) throws Exception
      Called when a text message is received by the attached entity.
      Parameters:
      message - The message text.
      sender - The sending object, or null.
      Throws:
      Exception - if handling fails.
    • onHit

      protected void onHit(EntityHitEvent event) throws Exception
      Called when the attached combat entity is hit.
      Parameters:
      event - The hit event.
      Throws:
      Exception - if handling fails.
    • onHit

      protected void onHit() throws Exception
      Called when the attached combat entity is hit.
      Throws:
      Exception - if handling fails.
    • onDeath

      protected void onDeath(ICombatEntity entity, EntityHitEvent hitEvent) throws Exception
      Called when the attached combat entity dies.
      Parameters:
      entity - The entity that died.
      hitEvent - The final hit, or null when no hit caused the death.
      Throws:
      Exception - if handling fails.
    • onDeath

      protected void onDeath() throws Exception
      Called when the attached combat entity dies.
      Throws:
      Exception - if handling fails.
    • onCollision

      protected void onCollision(CollisionEvent event) throws Exception
      Called when the attached collision entity collides with another collision entity.
      Parameters:
      event - The collision details.
      Throws:
      Exception - if handling fails.
    • onCollision

      protected void onCollision() throws Exception
      Called when the attached collision entity collides with another collision entity.
      Throws:
      Exception - if handling fails.
    • onInteract

      protected void onInteract(IEntity source) throws Exception
      Called when another entity interacts with the attached entity.
      Parameters:
      source - The interacting entity.
      Throws:
      Exception - if handling fails.
    • onAction

      protected void onAction(String action) throws Exception
      Called when an entity action is performed on the attached entity.
      Parameters:
      action - The action identifier.
      Throws:
      Exception - if handling fails.
    • sendMessage

      public void sendMessage(String message)
      Sends a message from this entity to all of its listeners.
      Parameters:
      message - The message text.
    • sendMessage

      public void sendMessage(IEntity receiver, String message)
      Sends a message from this entity to a target receiver entity.
      Parameters:
      receiver - The receiving entity.
      message - The message text.
    • remove

      public void remove()
      Removes this entity from its current environment.
    • isDead

      public boolean isDead()
      Checks if the host entity is dead (if it is a combat entity).
      Returns:
      true if the host is a dead combat entity.
    • die

      public void die()
      Marks the host combat entity as dead.
    • resurrect

      public void resurrect()
      Resurrects the host combat entity.
    • getHealth

      public int getHealth()
      Returns current health / hitpoints (or 0 if not a combat entity).
      Returns:
      The current hit points, or zero for non-combat hosts.
    • getMaxHealth

      public int getMaxHealth()
      Returns maximum health / hitpoints (or 0 if not a combat entity).
      Returns:
      The maximum hit points, or zero for non-combat hosts.