aoeweapon_base
Overview
The aoeweapon_base component serves as a versatile base for entities (typically weapons or tools) that need to interact with various types of targets in an Area-of-Effect (AOE) or general interaction manner. It centralizes logic for performing work actions (chopping, mining, hammering), picking items, and engaging in combat. It also provides customizable callbacks for pre-hit, hit, and miss events, and handles the physics-based tossing of entities.
Dependencies & Tags
This component interacts with and expects the following components on other entities:
target.components.workabletarget.components.pickabledoer.components.combattarget.components.minetarget.components.inventoryitemtarget.Physics(Physics component)
Tags Set/Used by this Component:
- Initial
self.tags:{"_combat", "pickable", "NPC_workable"} self.notags:{"FX", "DECOR", "INLIMBO"}- Generated
self.combinedtags: This table dynamically combinesself.tagswith tags derived fromself.workactions(e.g.,ACTIONS.CHOPadds "CHOP_workable" tocombinedtags).
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
inst | Entity | The component's owning entity | A reference to the entity this component is attached to. |
damage | number | 10 | The base damage value inflicted when attacking a combat target. |
onprehitfn | function | nil | A callback function executed before the main OnHit logic. Signature: (weapon_inst, doer, target). |
onhitfn | function | nil | A callback function executed after a successful interaction (work, pick, or combat hit) in OnHit. Signature: (weapon_inst, doer, target). |
onmissfn | function | nil | A callback function executed if no successful interaction occurs during OnHit. Signature: (weapon_inst, doer, target). |
canpick | boolean | nil | If true, the weapon can attempt to pick pickable targets via OnHit. |
stimuli | string | nil | An optional string representing a combat stimulus (e.g., "POISON") to be applied during attacks. |
tags | table (of strings) | {"_combat", "pickable", "NPC_workable"} | A list of general tags associated with the weapon's interaction capabilities, used in _CombineTags. |
notags | table (of strings) | {"FX", "DECOR", "INLIMBO"} | A list of tags that targets must not possess for certain interactions to proceed. |
combinedtags | table (of strings) | nil (dynamically generated) | A unique, combined list of tags and dynamically generated tags based on workactions (e.g., "CHOP_workable"). |
workactions | table (indexed by ACTIONS) | nil (initially ACTIONS.CHOP, ACTIONS.HAMMER, ACTIONS.MINE, ACTIONS.DIG) | A lookup table ([ACTION_CONSTANT] = true) indicating which ACTIONS this weapon can perform on workable targets. |
Main Functions
AOEWeapon_Base:SetDamage(dmg)
- Description: Sets the base damage value for this weapon.
- Parameters:
dmg(number) - The new damage value.
AOEWeapon_Base:SetStimuli(stimuli)
- Description: Sets the combat stimulus string to be applied by this weapon during attacks.
- Parameters:
stimuli(string) - The stimulus string (e.g., "POISON").
AOEWeapon_Base:SetWorkActions(...)
- Description: Configures the specific types of work actions (e.g., chopping, mining) this weapon can perform on
workabletargets. This method automatically updates thecombinedtagsproperty. - Parameters:
...(ACTIONSconstants) - One or moreACTIONSconstants (e.g.,ACTIONS.CHOP,ACTIONS.HAMMER).
AOEWeapon_Base:SetTags(...)
- Description: Sets a list of general tags associated with this weapon. These tags are incorporated into the
combinedtagsproperty. - Parameters:
...(string) - One or more string tags.
AOEWeapon_Base:_CombineTags()
- Description: An internal helper function responsible for generating the
self.combinedtagstable. It collects unique tags fromself.tagsand dynamically generates tags based onself.workactions(e.g.,ACTIONS.CHOPresults in "CHOP_workable"). This combined list can be useful for target filtering and interaction logic. - Parameters: None.
AOEWeapon_Base:SetNoTags(...)
- Description: Sets a list of tags that targets must not possess for certain interactions to be considered valid (e.g., for picking).
- Parameters:
...(string) - One or more string tags.
AOEWeapon_Base:SetOnPreHitFn(fn)
- Description: Sets a callback function that will be executed before the main interaction logic in
AOEWeapon_Base:OnHit. - Parameters:
fn(function) - The function to call. It receives(weapon_inst, doer, target)as arguments.
AOEWeapon_Base:SetOnHitFn(fn)
- Description: Sets a callback function that will be executed after a successful interaction (working, picking, or combat hit) within
AOEWeapon_Base:OnHit. - Parameters:
fn(function) - The function to call. It receives(weapon_inst, doer, target)as arguments.
AOEWeapon_Base:SetOnMissFn(fn)
- Description: Sets a callback function that will be executed if
AOEWeapon_Base:OnHitfails to perform any valid interaction. - Parameters:
fn(function) - The function to call. It receives(weapon_inst, doer, target)as arguments.
AOEWeapon_Base:OnHit(doer, target)
- Description: This is the core interaction method. It attempts to interact with the
targetbased on its components and tags, following a priority order:workable>pickable>combat.- If
self.onprehitfnis set, it is called. - It checks if the
targetisworkableand if this weapon has a matchingworkactionfor it.- Special handling for
NPC_workable(e.g., campfires). - For
ACTIONS.DIG, it ensures the target is not a spawner. - If workable,
target.components.workable:Destroy(doer)is called. If the target remains valid and gains the "stump" tag (e.g., after chopping a tree), it is immediately removed.
- Special handling for
- If not workable, it then checks if
self.canpickistrue, and if thetargetispickableand notintense. If so,target.components.pickable:Pick(self.inst)is called. - If neither workable nor pickable, it checks if
doer.components.combatcan target thetargetand if they are not allies. If so,doer.components.combat:DoAttack(target, nil, nil, self.stimuli)is performed. - Finally, if any interaction was successful,
self.onhitfnis called; otherwise,self.onmissfnis called.
- If
- Parameters:
doer(Entity) - The entity performing the action (e.g., the player wielding the weapon).target(Entity) - The entity being interacted with.
AOEWeapon_Base:OnToss(doer, target, sourceposition, basespeed, startradius)
- Description: Simulates the physical tossing of the
targetentity from thedoer. It deactivatesminecomponents on the target if present, ensures the target has activePhysics, and calculates a trajectory. It includes logic to prevent tossing objects out of the world boundaries by adjusting the initial angle. - Parameters:
doer(Entity) - The entity initiating the toss.target(Entity) - The entity to be tossed.sourceposition(Vector3, optional) - The explicit starting position for the toss. Ifnil, thedoer's world position is used.basespeed(number, optional) - The base linear speed applied during the toss. Defaults to1.startradius(number, optional) - The initial distance from thesourcepositionat which to place thetargetbefore applying velocity. Defaults to0, but is set to at least the combined physics radii ofdoerandtargetto prevent clipping.
Events & Listeners
None identified.