Moonaltarlinktarget
Based on game build 714014 | Last updated: 2026-03-03
Overview
MoonAltarLinkTarget is a passive component attached to moon altar prefabs (e.g., moon_altar, moon_altar_cosmic, moon_altar_astral) that facilitates dynamic linking between altars. It periodically scans the world for other compatible altars within a configurable radius and attempts to form a valid triangular link. If three mutually reachable altars satisfy geometric and storm-related constraints, it spawns a moon_altar_link entity and notifies the moonstormmanager to validate the configuration. The component is primarily used in the Moon Altar event system to enable coordinated ritual mechanics.
Usage example
-- Add the component to a moon altar entity (e.g., in its prefab definition)
inst:AddComponent("moonaltarlinktarget")
-- Optionally define custom linking rules or callbacks
inst.components.moonaltarlinktarget.canbelinkedfn = function(entity)
return not entity:IsAsleep() and not entity:HasTag("playerready")
end
-- Manually trigger a link search (e.g., after altar state changes)
inst.components.moonaltarlinktarget:TryEstablishLink()
Dependencies & tags
Components used:
moonaltarlink(viainst.components.moonaltarlinktarget.link.components.moonaltarlink)moonstormmanager(viaTheWorld.components.moonstormmanager)Transform(viainst.Transform:GetWorldPosition())
Tags:
- Adds
moonaltarlinktargetautomatically. - Removes
moonaltarlinktargetwhen removed from an entity.
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
link | Entity? | nil | Reference to the moon_altar_link entity if currently linked; nil otherwise. |
link_radius | number | 20 | Maximum distance (in units) to search for other altars. |
canbelinkedfn | function? | nil | Optional predicate function that determines whether this altar may participate in a link. Receives inst as argument and returns boolean. |
onfoundotheraltarfn | function? | nil | Optional callback invoked when another altar is found during link search. Receives (this_altar, other_altar) arguments. |
onlinkfn | function? | nil | Not initialized in constructor, but used externally: invoked on this altar when linked. |
onlinkbrokenfn | function? | nil | Not initialized in constructor, but used externally: invoked on this altar when link is broken. |
Main functions
TryEstablishLink()
- Description: Scans the world for up to two additional compatible moon altars within
link_radius, forms a triangle if valid, and initiates a link viamoon_altar_link:EstablishLink. Callsmoonstormmanager:TestAltarTriangleValidto ensure the triangle passes storm-related checks. Stops after finding two valid altars (total of three including itself). - Parameters: None.
- Returns:
nil. - Error states:
- If fewer than two compatible altars are found or eligible (including radius and
CanBeLinkedchecks), no link is formed. - If
TheWorld.components.moonstormmanageris missing orTestAltarTriangleValidreturnsfalse, no link occurs.
- If fewer than two compatible altars are found or eligible (including radius and
CanBeLinked()
- Description: Determines whether this altar is eligible to participate in a new link, based on a custom predicate if defined.
- Parameters: None.
- Returns:
boolean—trueifcanbelinkedfnisnilor returnstrue; otherwise, the result ofcanbelinkedfn(inst). - Error states: None.
Events & listeners
- Listens to:
onremove— triggersbreaklinkcallback to automatically break any existing link when the entity is removed. - Pushes:
onfoundotheraltarfncallback (if assigned) is invoked internally when another altar is found.- No direct
PushEventcalls are made by this component.