Skip to main content

Phantom

A class in Root.Township, Alta.Intelligence.

The phantom creature agent. It switches between solid and immaterial, gets knocked back by tool hits, cracks when a mining echo goes off near it, and fades away at daytime. The server runs its AI and syncs its state.

Constructors​

MemberWhat it is
Phantom()Unity makes components itself; use AddComponent or spawn a prefab instead of new.

Fields​

42 private and internal fields
MemberWhat it is
private static Dictionary<ActionComponent, ActionTarget<Phantom>> actionTargetMapStatic cache of the materialize, dematerialize and hit actions built from each action component.
private PooledObject activeVisionAttackEffectThe playing vision attack effect, if any.
private float crackedDurationSeconds a phantom stays cracked. Default 30.
private Timeline.IEntry crackedEntryTimeline entry that ends the cracked state.
private ActionComponent deMaterializeActionAction started on the server when the phantom turns immaterial.
private float dematerializedKnockbackHurtValueHurt added towards the attacker when an immaterial phantom is hit. Default 0.5.
private float dematerializeKnockBackMultiplierKnockback distance factor for an immaterial phantom. Default 0.5.
private TransformEvent fadeOnDayEffectEffect event played where the phantom fades out.
private AltaEvent fadeOnDayServerEvent fired on the server when the phantom fades.
private bool hasKnockbackDetectorWhether both the knockback detector and its collider are set.
private int immaterialLayerPhysics layer the colliders use while immaterial.
private bool isCrackedWhether the phantom is cracked (stuck after a mining echo). Synced to clients.
private bool isFadingOnActionFailWhether the phantom fades when it finds nothing to do. Default true.
private bool isStartingImaterialWhether the phantom spawns immaterial.
private string killedAnimationParameterNetworked animator bool set on death.
private TriggerImpactDetector knockbackDetectorTrigger impact detector used while immaterial. Cleared when the phantom turns solid.
private Collider knockbackDetectorColliderThe knockback detector's collider, only on while immaterial, and only on the server.
private AnimationCurve knockBackDistanceBasedOnDamageCurve from a hit's health damage to knockback distance.
private float knockbackLerpSpeedHow fast the phantom slides to the knockback position. Default 3.
private Vector3 knockbackPositionWhere the current knockback is sliding the phantom to.
private Quaternion? knockbackRotationRotation to turn to during a knockback, facing the attacker. Null when immaterial.
private float knockbackRotationLerpSpeedHow fast the phantom turns during a knockback. Default 3.
private ActionComponent materializeActionAction started on the server when the phantom turns solid.
private ActionComponent materializedHitActionAction started on the server when a solid phantom is knocked back.
private StatDefinition materializedStatDefinitionStat whose base is set to 0 when a cracked phantom is hit.
private float maxRadiusFromEchoToCrackLargest mining echo radius that can crack the phantom. Default 15.
private TransformEvent onBeginCrackEffectEffect event played when the phantom cracks.
private TransformEvent onFinishCrackEffectEffect event played when the crack wears off.
private float onKnockBackSpeedSetSpeed and walker power right after a knockback ends, before recovery. Default 0.1.
private ActionComponentSet passiveActionsThe action set the phantom starts with.
private static Dictionary<ActionComponentSet, ActionSet<Phantom>> passiveActionSetMapStatic cache of the action set built from each passive set asset.
private IUnityUpdateMethod recoverSpeedThe registered knockback or speed recovery update.
private int solidLayerPhysics layer the colliders use while solid.
private float speedRecoveryRateSpeed regained per second after a knockback. Default 0.1.
private MethodSync syncCrackEffectNetwork sync for the cracked state.
private MethodSync syncFadeNetwork sync for fading out.
private MethodSync syncMaterializedStatusNetwork sync for the solid or immaterial state.
private ViewCone viewConeBacking field for the view cone.
private Stat visibilityStatThe visibility stat, set to 1 when solid and 0 when immaterial.
private StatDefinition visibilityStatDefinitionDefinition used to find visibilityStat.
private PooledObjectDefinition visionAttackEffectEffect played by ActiveVisionAttackEffect.
private Transform visionAttackEffectRootTransform the vision attack effect is attached to.

Properties​

MemberWhat it is
bool IsMaterialized { get; private set; }True while the phantom is solid. An immaterial phantom is on a different collision layer.
Stat SpeedStat { get; private set; }The phantom's speed stat. Knockback sets it to zero and it recovers over time.
1 private and internal property
MemberWhat it is
private ViewCone Alta.Intelligence.IHasViewCone.ViewCone { get; }The phantom's view cone, for view cone senses and actions.

Methods​

MemberWhat it is
void ActiveVisionAttackEffect()Client: starts the vision attack effect, replacing any one already playing.
void Crack()While immaterial, cracks the phantom for a set time (30 seconds by default) and syncs the crack effect.
void DeactiveVisionAttackEffect()Stops the vision attack effect if it's playing.
override void Initialize()Sets up the sync methods and starts the phantom immaterial if its prefab says so.
void KnockBack(ImpactHitWithTool hitWithTool)Server: pushes the phantom away from a tool hit and slows it, recovering speed over time. Hitting a cracked phantom instead ends the crack.
override void OnConnected(Player player)Sends the materialized state to a player who has just spawned the phantom.
void SetMarialized(bool isMaterialized)Switches between solid and immaterial while alive. The server also plays the matching action, sets visibility and syncs it.
protected override void InitializeAi()Server: sets up its actions, fading at daytime or when no action is found, reveal, hit knockback and mining echo listening.
protected override void InitializeStatic()Creates the shared action lookup tables for all phantoms.
protected override void Killed(HealthObject healthobject)Sets the killed animation parameter as well as the normal death handling.
protected override void OnDestroy()Server: cancels the crack timer and stops listening for mining echoes.
12 private and internal methods
MemberWhat it is
private void FadeNoAction()Fades the phantom out when a decision finds nothing to do, if isFadingOnActionFail is set.
private void FadeOnDay(bool isNight)When it's day (or the phantom is dead), kills it, turns off collision, plays the fade effect, tells clients and fires fadeOnDayServer.
private void FinishCracked()Ends the cracked state after crackedDuration, plays the end effect and tells clients.
private void KnockBack()Server: pushes the phantom away from a tool hit and slows it, recovering speed over time. Hitting a cracked phantom instead ends the crack.
private void OnImpactReceived(ImpactHit hit)Health hit handler that knocks the phantom back for tool hits.
private void OnSceneDestroy(NetworkEntity entity, bool isUnload)Unhooks the night change event and stops any knockback or speed recovery update.
private void RecoverSpeed()Per frame update that raises the speed stat and walker power back to 1 after a knockback.
private void Reveal()Called when an effect reveals the phantom. Deals 10 cripple damage and no health damage.
private void SyncCrackedEffect(IPlayer player, Stream stream)Network handler (SyncD) that sends the cracked flag and plays the start or end crack effect on clients.
private void SyncFade(IPlayer player, Stream stream)Network handler (SyncC) that turns off collision and plays the fade effect on clients.
private void SyncMaterializedStatus(IPlayer player, Stream stream)Network handler (SyncB) that sends whether the phantom is solid and applies it on clients. Also sent to each player on connect.
private void IListenToMiningEcho.Update(Vector3 center, float radius)Mining echo listener: cracks an immaterial phantom inside the echo radius, if the radius is at most maxRadiusFromEchoToCrack.