aoespell
Overview
The aoespell component provides core functionality for managing and casting Area of Effect (AoE) spells within Don't Starve Together. It allows an entity to define a custom spell execution logic, verify casting conditions based on various other components (like spellbook, aoetargeting, fueled), and notify the caster of the spell's outcome. Its primary responsibility is to abstract the complexities of spell casting and condition checking into a reusable component.
Dependencies & Tags
This component relies on or interacts with the following other components and game elements:
inst.components.spellbook: Used to check if the item can be used as a spell by thedoer.inst.components.inventoryitem: Checks if the item is owned by thedoerif it's an inventory item.inst.components.fueled: Checks if a fueled item (like a staff) has fuel.inst.components.aoetargeting: Used to retrieve specific targeting rules such asalwaysvalid,allowwater,deployradius, andallowriding.doer.components.rider: Checks if thedoeris riding a mount, and if casting is disallowed while riding.TheWorld.Map: CallsTheWorld.Map:CanCastAtPointto determine if the target position is valid for casting.
None identified.
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
spellfn | function | nil | A custom Lua function that defines the actual effect of the spell when it is cast. It is expected to be set via SetSpellFn. When called, it receives (inst, doer, pos) as arguments and should return (success, reason), where success is a boolean and reason is an optional string explaining failure. |
Main Functions
SetSpellFn(fn)
- Description: Sets the custom function that will be executed when the spell is cast. This function defines the actual effects of the AoE spell.
- Parameters:
fn: (function) The function to be called whenCastSpellis executed. It should accept(inst, doer, pos)and optionally return(success, reason).
CastSpell(doer, pos)
- Description: Executes the spell's custom logic (defined by
self.spellfn) at the specified position. It also pushes anoncastaoespellevent to thedoerafter attempting the cast. - Parameters:
doer: (entity) The entity attempting to cast the spell.pos: (vector3) The target position for the spell in the world.
CanCast(doer, pos)
- Description: Determines if the spell can be cast by the
doerat the givenpos. This function performs a series of checks based on various components and world conditions. - Parameters:
doer: (entity) The entity attempting to cast the spell.pos: (vector3) The target position for the spell in the world.
- Checks Performed:
- Verifies that
self.spellfnhas been set. - If
insthas aspellbookcomponent:- Checks
spellbook:CanBeUsedBy(doer). - If
insthas aninventoryitemcomponent, ensuresdoeris theGetGrandOwner(). - If
insthas afueledcomponent, ensures it's notIsEmpty(). - If
instis a player, ensuresinstis thedoer.
- Checks
- If
insthas anaoetargetingcomponent:- Checks
aoetargeting:IsEnabled(). - Retrieves
alwaysvalid,allowwater,deployradius, andallowridingfromaoetargeting.
- Checks
- Checks if the
doeris riding (doer.components.rider:IsRiding()) and ifallowridingis false. - Finally, calls
TheWorld.Map:CanCastAtPoint(pos, alwayspassable, allowwater, deployradius)to validate the map position.
- Verifies that
Events & Listeners
- Pushes Event:
oncastaoespell: Pushed to thedoerentity afterCastSpellis called.- Data:
{ item = self.inst, pos = pos, success = success }item: The spell item (the entity with this component).pos: The target position where the spell was cast.success: A boolean indicating if the spell'sspellfnexecuted successfully.
- Data: