Lunarthrall Plantspawner
Overview
This is a TheWorld-level world component responsible for managing the lunar rift-triggered infestation cycle of lunar plants into Lunarthrall gestalt minions. It coordinates with rift spawners, plant herds, and game time to schedule and execute spawning waves, handle onscreen/offscreen target selection, and clean up when the rift ends or waves are depleted.
Dependencies & Tags
- Relies on the following world components:
riftspawner,timer. - Listens to events:
ms_lunarrift_maxsizeplantherdspawnedms_lunarportal_removedlunarthrallplant_infestedtimerdonems_gestalt_possession
- Tags involved (via
PLANT_MUST,PLANTS_MUST,HUSK_MUST):"lunarthrall_plant","plant","lunarplant_target","epiccorpse","lunarthrall_plant"(again for husks). - No direct component additions to its own entity (
self.instisTheWorld).
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
inst | Entity | — | The world entity instance (TheWorld). |
waves_to_release | number? | nil | Remaining wave count (set when rift reaches max size). |
plantherds | table | {} | List of registered plant herds (Plantherd instances) used for infestation target selection. |
spawntasks | table | {} | Tracks active spawner tasks (for cancellation on cleanup). |
targetedplants | table | {} | Map of plant GUIDs currently selected for infestation (used to prevent overlap/duplication). |
currentrift | Entity? | nil | Reference to the active lunarrift_portal rift entity, if any. |
Main Functions
SpawnGestalt(target, rift)
- Description: Spawns a
lunarthrall_plant_gestaltprefab. Ifriftis provided and valid, spawns it at the rift’s position and plays a sound; otherwise spawns it offscreen (using a spiral search) and moves it toward the target. - Parameters:
target(Entity): The plant entity that the gestalt will infest.rift(Entity?): Optional rift from which to spawn.
SpawnPlant(target)
- Description: Infests a target plant with a
lunarthrall_plant(husk) directly (offscreen infestation). Callsinfest()andplaySpawnAnimation()on the new plant. - Parameters:
target(Entity): The plant to infest.
InvadeTarget(target)
- Description: Decides whether to spawn a gestalt (if target is onscreen) or directly infest the plant (if offscreen).
- Parameters:
target(Entity): The plant to infest.
FindHerd()
- Description: Selects a suitable plant herd for infestation. Filters herds based on available uninfested, non-withered members that are far enough from existing husks (
EXISTING_PLANT_SPACE = 30). Returns a random herd from the top 5 candidates ranked by valid member count. - Returns:
Entity?— A plant herd entity, ornilif no viable herd found.
FindWildPatch()
- Description: Scans the world for wild plants (with tags
"plant"and"lunarplant_target") not yet infested. Searches 10 random points within a 40-unit radius on land and picks the location with the most plants within 20 units. Returns the list of plants at that best location. - Returns:
table?— Array of plant entities, ornilif none found.
FindPlant()
- Description: Returns a random infestable plant from all registered herds, checking via
caninfest(). - Returns:
Entity?— An infestable plant entity, ornil.
MoveGestaltToPlant(thrall)
- Description: Offsets the given
lunarthrall_plant_gestaltto an offscreen position using a spiral outward search, then assigns it to trackplant_target. - Parameters:
thrall(Entity): The gestalt entity to position.
RemoveWave()
- Description: Decrements the remaining wave count. If the count reaches zero, cancels all pending tasks, and starts a 10-second timer to finish/remove the rift.
- No parameters.
setHerdsOnPlantable(plantable)
- Description: Adds
knownlocationsandherdmembercomponents to a plantable entity, and assigns it to adomesticplantherd. Used to register plants for potential herd infestation. - Parameters:
plantable(Entity): The plant entity to prepare for herd membership.
OnSave()
- Description: Serializes core state for savegames (rift GUID, wave count, task remainders). Returns
{state, refs}format expected by DST save system. - Returns:
{state: table, refs: table}
OnLoad(data)
- Description: Loads the
waves_to_releasevalue from saved data. - Parameters:
data(table?): Saved state data.
LoadPostPass(newents, data)
- Description: Resolves entity references (e.g., rift) and restores pending tasks (spawntask, nextspawn) after loading.
- Parameters:
newents(table): Map of GUID → entity for newly loaded ents.data(table?): Saved task data.
GetDebugString()
- Description: Returns a formatted debug string showing remaining waves and timing info.
- Returns:
string
LongUpdate(dt)
- Description: Keeps task timers updated during long frame gaps (e.g., save/load or lag), by rescheduling them with reduced remaining time.
- Parameters:
dt(number): Delta time since last update.
Events & Listeners
- Listens for:
ms_lunarrift_maxsize→OnLunarRiftReachedMaxSizeplantherdspawned→OnPlantHerdSpawnedms_lunarportal_removed→OnLunarPortalRemovedlunarthrallplant_infested→OnPlantInfestedtimerdone→OnTimerDonems_gestalt_possession→OnGestaltPossession
- Emits:
"finish_rift"event on the rift entity (viaPushEvent) when its lifecycle ends (after 10 seconds from wave completion).