Sentientaxe
Overview
The sentientaxe component imparts personality and contextual awareness to an axe (typically the Woodie Axe), enabling it to vocalize reactions and commentary via the lucy_classified component when equipped by or associated with a player. It tracks ownership, schedules periodic conversational prompts, and responds to player actions and state changes (e.g., chopping, carving,Werebeaver transformation).
Dependencies & Tags
Component Dependencies:
inst.components.equippable(for equip/hold status checks)inst.components.inventoryitem(for ownership, held status, and container placement)inst.components.health(indirectly, to check if owner is dead)inst.lucy_classified(assumed to be the speech component, used via.Say())inst.sg(stategraph, used to check transformation state tags)
Tags:
- No new tags are added or removed by this component itself.
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
inst | Entity | — | Reference to the axe entity this component is attached to. |
owner | Entity? | nil | The current player who owns this axe (set via SetOwner). |
convo_task | DoLaterTask? | nil | Scheduled task for next spontaneous conversation. |
say_task | DoLaterTask? | nil | Scheduled speech task (used for delayed or queued speech). |
warnlevel | number | 0 | Unused in current logic (historical or reserved). |
waslow | boolean | false | Unused in current logic (historical or reserved). |
_lastcarvingtalks | table<string, number> | {} | Tracks last time each carving action triggered speech, keyed by "carve_<recipe>". |
Main Functions
SetOwner(owner)
- Description: Assigns a new owner to the axe. Removes event listeners from the previous owner and attaches corresponding listeners to the new owner. Resets internal state (e.g., cooldowns, conversation tasks). If a new owner is assigned, it schedules an immediate or delayed conversation based on state.
- Parameters:
owner(Entity?): The player entity becoming the new owner. Ifnil, the axe becomes unowned and stops listening for owner-specific events.
OnBuildItem(recipename)
- Description: Triggers a contextual remark when the axe’s owner completes crafting a recipe. Only triggers if the recipe has a defined comment string (in
STRINGS.LUCY["carve_<recipe>"]) and the cooldown (defined byTUNING.LUCY_CARVING_TALK_COOLDOWN) has elapsed. - Parameters:
recipename(string?): Name of the recipe just crafted (e.g., "loggy"). Returns early ifnil.
OnFinishedWork(target, action)
- Description: Triggers a comment when the axe finishes a work action. Specifically triggers on
ACTIONS.CHOPif the axe is currently equipped and has an owner. - Parameters:
target(Entity?): Target entity of the work action (unused in logic).action(string): Action type (e.g.,"chop").
OnWereEaterChanged(old, new, istransforming)
- Description: Issues warnings based on Woodie’s werebeaver hunger level (from
wereeatercomponent). Skips if transforming or if level didn’t decrease. Offers two levels of warnings (early/late) only when the axe is held. - Parameters:
old(number): Previous hunger level.new(number): New hunger level.istransforming(boolean): Whether the transformation is currently in progress.
OnBecomeHuman()
- Description: Speaks when Woodie reverts to human form (near owner only). Cancels pending speech if not near.
- Parameters: None.
OnBecomeWere()
- Description: Speaks when Woodie transforms into a werebeaver (near owner only). Cancels pending speech if not near.
- Parameters: None.
Say(list, sound_override, delay)
- Description: Plays a random line from
list(array of strings) usinglucy_classified:Say(), optionally with a custom sound override. Supports delayed speech viadelay. Cancels any pending speech first. Resets conversation scheduling timer after speech (if owner exists). - Parameters:
list(string[]): List of possible speech lines to choose from.sound_override(string?): Optional custom sound path.delay(number?): Optional delay (in seconds or ticks) before speaking.
ScheduleConversation(delay)
- Description: Schedules a future spontaneous conversation (e.g., quoting current item state). Cancels any existing conversation task.
- Parameters:
delay(number?): Time until next conversation. Defaults to10 + random(0–5)if omitted.
MakeConversation()
- Description: Evaluates the axe’s current state and owner proximity to select and speak a contextual phrase: ground, equipped, or in container. Always reschedules the next conversation afterward.
- Parameters: None.
ShouldMakeConversation()
- Description: Helper that determines if the axe should speak at this moment. Returns
falseif owner is dead, transforming, or a were/beaver ghost. - Parameters: None.
Events & Listeners
- Listens for
"axepossessedbyplayer"→ callsOnAxePossessedByPlayer. - Listens for
"axerejectedowner"→ callsOnAxeRejectedOwner. - Listens for
"axerejectedotheraxe"→ callsOnAxeRejectedOtherAxe. - While owned, listens to:
"ondropped"→ callstoground."equipped"→ callsonequipped."builditem"(on owner) → callsOnBuildItem."finishedwork"(on owner) → callsOnFinishedWork."wereeaterchanged"(on owner) → callsOnWereEaterChanged."startwereplayer"(on owner) → callsOnBecomeHuman."stopwereplayer"(on owner) → callsOnBecomeWere.