Yoth Knightmanager
Overview
This component orchestrates the Knight Shrine–triggered event logic for the Year of the Horse (YOTH) update, specifically managing when and how Yoth Knights are summoned when a Princess wielder is near an active Knight Shrine and free of cooldowns. It operates exclusively on the master simulation and coordinates interactions between shrines, princesses (players holding the Knight Hat), and knight summoning logic.
Dependencies & Tags
- Component Requirements: This component expects
instto be an entity with a validTransformandIsPointNearHole/FindWalkableOffsetsupport in the world context. It does not add any components toinst, but relies on external components such as:petleash(on the hat object passed toRegisterPrincess)yoth_princesscooldown_buff(on player entities)
- Tags Used:
gilded_knight(used viaTheSim:CountEntitiesto check for existing knights)
- World Event Listeners: Listens for
ms_knightshrineactivated,ms_knightshrinedeactivated,ms_register_yoth_princess, andms_unregister_yoth_princess.
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
shrines | table | {} | Tracks active Knight Shrines (keys are shrine entities, values are true). |
princesses | table | {} | Maps player entities to their equipped Knight Hat (from RegisterPrincess). |
hats | table | {} | Inverted mapping of princesses: maps hats to their associated player. |
rescheduletasks | table | {} | Stores pending DoTaskInTime task handles keyed by player entity, for rescheduling knight spawn checks. |
Main Functions
OnKnightShrineActivated(shrine)
- Description: Registers an active Knight Shrine in the
shrinestable. - Parameters:
shrine: Entity — the shrine that became active.
OnKnightShrineDeactivated(shrine)
- Description: Removes a Knight Shrine from the
shrinestable. - Parameters:
shrine: Entity — the shrine that was deactivated.
IsKnightShrineActive()
- Description: Returns
trueif any Knight Shrine is currently active and the YOTH event is running. - Parameters: None.
GetActiveKnightShrines()
- Description: Returns the
shrinestable (a set of active shrine entities). - Parameters: None.
IsOnCooldown(owner)
- Description: Determines whether the given
owner(player or non-player entity) is currently on cooldown for summoning knights. For non-players (e.g., dropped hats), it checks the nearest players in range. - Parameters:
owner: Entity — the player or entity associated with the princess/hat.
SpawnKnights(hat, pos)
- Description: Spawns four Yoth Knights in sequence with slight delays and a warning sound. Uses the
petleashcomponent on thehatto spawnknight_yothpets at computed offsets. - Parameters:
hat: Entity — the Knight Hat item withpetleashcomponent.pos: Vector3 — world position where the warning sound should play (knights spawn at offset locations).
RescheduleSpawnKnights(owner, timetocheck)
- Description: Cancels any pending spawn check task for
ownerand schedules a new one (default: 5–6 seconds). Used to defer summoning attempts (e.g., after cooldown expiration). - Parameters:
owner: Entity — the player entity.timetocheck: number (optional) — delay in seconds before retrying.
TryToSpawnKnights(owner)
- Description: Evaluates and executes the conditions required to spawn knights: checks princess registration, cooldown status, absence of existing knights, no platform, and valid spawn position. If conditions met, calls
SpawnKnights. - Parameters:
owner: Entity — the player associated with the princess.
RegisterPrincess(owner, hat)
- Description: Registers a player-hat pair as a princess. If on cooldown initially, emits
yoth_oncooldownevent for feedback. Schedules a spawn check with a small delay (~0.5–0.75s). - Parameters:
owner: Entity — the player wielding the hat.hat: Entity — the Knight Hat item.
UnregisterPrincess(owner, hat)
- Description: Unregisters a princess. Cancels pending tasks and emits
yoth_oncooldown_cancelfor UI updates. - Parameters:
owner: Entity — the player.hat: Entity — the Knight Hat item.
GetDebugString()
- Description: Currently returns an empty string; reserved for future debugging output.
- Parameters: None.
Events & Listeners
- Listens for:
"ms_knightshrineactivated"→ callsOnKnightShrineActivated_Bridge"ms_knightshrinedeactivated"→ callsOnKnightShrineDeactivated_Bridge"ms_register_yoth_princess"→ callsRegisterPrincess_Bridge"ms_unregister_yoth_princess"→ callsUnregisterPrincess_Bridge
- Emits events (via
owner:PushEvent):"yoth_oncooldown"— when princess registration occurs while already on cooldown."yoth_oncooldown_cancel"— when unregistering a princess.