Skip to main content

Attackdodger

Overview

The Attackdodger component provides a framework for an entity to evade incoming attacks. It allows for custom logic to determine if a dodge is possible and what action occurs during the dodge. It also manages a cooldown to prevent the entity from dodging too frequently. This component is typically used in conjunction with a combat component, which would call CanDodge and Dodge when the entity is targeted.

Dependencies & Tags

None identified.

Properties

PropertyTypeDefault ValueDescription
ondodgefnfunctionnilA callback function that is executed when the entity performs a dodge.
candodgefnfunctionnilA callback function that determines if the entity is allowed to dodge.
cooldowntimenumbernilThe duration in seconds that the entity must wait before dodging again.
oncooldownbooleanfalseA flag indicating if the dodge ability is currently on cooldown.
cooldowntasktasknilA reference to the scheduled task that will end the cooldown.

Main Functions

SetOnDodgeFn(fn)

  • Description: Sets the callback function to be executed when the entity successfully dodges an attack.
  • Parameters:
    • fn (function): The function to call on a dodge. It receives the entity instance (inst) and the attacker as arguments.

SetCanDodgeFn(fn)

  • Description: Sets the callback function that determines if the entity is currently capable of dodging. This function is checked before a dodge is attempted.
  • Parameters:
    • fn (function): The function to call to check for dodge eligibility. It receives the entity instance (inst) and the attacker as arguments and should return true or false.

SetCooldownTime(n)

  • Description: Sets the cooldown period for the dodge ability. After a dodge, the entity will be unable to dodge again until this time has passed.
  • Parameters:
    • n (number): The cooldown duration in seconds.

CanDodge(attacker)

  • Description: Checks if the entity is able to perform a dodge. It evaluates both the custom candodgefn (if set) and the current cooldown status (if a cooldowntime is set). If both are configured, both must pass. If only one is configured, only that condition is checked.
  • Parameters:
    • attacker (Entity): The entity that is initiating the attack.

Dodge(attacker)

  • Description: Executes the dodge action. This calls the ondodgefn and, if a cooldown is configured, puts the ability on cooldown.
  • Parameters:
    • attacker (Entity): The entity that is initiating the attack.