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.
- Listed in Creatures and AI
- Inherits or implements
Agent<Phantom>,IHasViewCone,IListenToMiningEcho - Derived types
Phantom,PlayerLikeSpectralGhost - Documented in Other creatures, Creature data, Creatures and AI
Constructors
| Member | What it is |
|---|---|
Phantom() | Unity makes components itself; use AddComponent or spawn a prefab instead of new. |
Fields
42 private and internal fields
| Member | What it is |
|---|---|
private static Dictionary<ActionComponent, ActionTarget<Phantom>> actionTargetMap | Static cache of the materialize, dematerialize and hit actions built from each action component. |
private PooledObject activeVisionAttackEffect | The playing vision attack effect, if any. |
private float crackedDuration | Seconds a phantom stays cracked. Default 30. |
private Timeline.IEntry crackedEntry | Timeline entry that ends the cracked state. |
private ActionComponent deMaterializeAction | Action started on the server when the phantom turns immaterial. |
private float dematerializedKnockbackHurtValue | Hurt added towards the attacker when an immaterial phantom is hit. Default 0.5. |
private float dematerializeKnockBackMultiplier | Knockback distance factor for an immaterial phantom. Default 0.5. |
private TransformEvent fadeOnDayEffect | Effect event played where the phantom fades out. |
private AltaEvent fadeOnDayServer | Event fired on the server when the phantom fades. |
private bool hasKnockbackDetector | Whether both the knockback detector and its collider are set. |
private int immaterialLayer | Physics layer the colliders use while immaterial. |
private bool isCracked | Whether the phantom is cracked (stuck after a mining echo). Synced to clients. |
private bool isFadingOnActionFail | Whether the phantom fades when it finds nothing to do. Default true. |
private bool isStartingImaterial | Whether the phantom spawns immaterial. |
private string killedAnimationParameter | Networked animator bool set on death. |
private TriggerImpactDetector knockbackDetector | Trigger impact detector used while immaterial. Cleared when the phantom turns solid. |
private Collider knockbackDetectorCollider | The knockback detector's collider, only on while immaterial, and only on the server. |
private AnimationCurve knockBackDistanceBasedOnDamage | Curve from a hit's health damage to knockback distance. |
private float knockbackLerpSpeed | How fast the phantom slides to the knockback position. Default 3. |
private Vector3 knockbackPosition | Where the current knockback is sliding the phantom to. |
private Quaternion? knockbackRotation | Rotation to turn to during a knockback, facing the attacker. Null when immaterial. |
private float knockbackRotationLerpSpeed | How fast the phantom turns during a knockback. Default 3. |
private ActionComponent materializeAction | Action started on the server when the phantom turns solid. |
private ActionComponent materializedHitAction | Action started on the server when a solid phantom is knocked back. |
private StatDefinition materializedStatDefinition | Stat whose base is set to 0 when a cracked phantom is hit. |
private float maxRadiusFromEchoToCrack | Largest mining echo radius that can crack the phantom. Default 15. |
private TransformEvent onBeginCrackEffect | Effect event played when the phantom cracks. |
private TransformEvent onFinishCrackEffect | Effect event played when the crack wears off. |
private float onKnockBackSpeedSet | Speed and walker power right after a knockback ends, before recovery. Default 0.1. |
private ActionComponentSet passiveActions | The action set the phantom starts with. |
private static Dictionary<ActionComponentSet, ActionSet<Phantom>> passiveActionSetMap | Static cache of the action set built from each passive set asset. |
private IUnityUpdateMethod recoverSpeed | The registered knockback or speed recovery update. |
private int solidLayer | Physics layer the colliders use while solid. |
private float speedRecoveryRate | Speed regained per second after a knockback. Default 0.1. |
private MethodSync syncCrackEffect | Network sync for the cracked state. |
private MethodSync syncFade | Network sync for fading out. |
private MethodSync syncMaterializedStatus | Network sync for the solid or immaterial state. |
private ViewCone viewCone | Backing field for the view cone. |
private Stat visibilityStat | The visibility stat, set to 1 when solid and 0 when immaterial. |
private StatDefinition visibilityStatDefinition | Definition used to find visibilityStat. |
private PooledObjectDefinition visionAttackEffect | Effect played by ActiveVisionAttackEffect. |
private Transform visionAttackEffectRoot | Transform the vision attack effect is attached to. |
Properties
| Member | What 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
| Member | What it is |
|---|---|
private ViewCone Alta.Intelligence.IHasViewCone.ViewCone { get; } | The phantom's view cone, for view cone senses and actions. |
Methods
| Member | What 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
| Member | What 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. |