ImpactDetector
A class in Root.Township, Alta.Impact.
Component that receives hits from ImpactTools, particles and liquids on an object such as a creature, player or breakable. It filters by impact channel and passes hits on through Hit; tool hits are mostly worked out on the swinging player's client and synced.
- Listed in Items, inventory and logic
- Inherits or implements
MonoBehaviour,IListenToPhysicalMaterial,INetworkEntityBehaviour,IInitializeAsLocalPlayer,IInitializeAsRemotePlayer - Derived types
CraftableImpactDetectorBase - Nested types
ImpactSyncArguments - Documented in Impacts and hit detection
Constructors
| Member | What it is |
|---|---|
ImpactDetector() | Unity makes components itself; use AddComponent or spawn a prefab instead of new. |
Fields
| Member | What it is |
|---|---|
protected NetworkEntity entity | The NetworkEntity on the same object. |
16 private and internal fields
| Member | What it is |
|---|---|
private ImpactChannel[] channels | Impact channels this detector responds to. Particle hits on other channels are ignored. |
private Dictionary<Collider, ImpactDetectorColliderModifier> colliderModifiers | Per-collider modifiers, filled from mappedColliders in Awake. |
private ImpactDetectorSettings currentSettings | Backing field for Settings. |
private ImpactDetectorCentral detectorCentral | Optional ImpactDetectorCentral on the same object that syncs impacts for this detector. |
private EquipmentReference equipmentSlot | Equipment reference whose armour is returned by CurrentArmor. |
private uint hardnessLevel | Backing field for HardnessLevel. Set from the physical material. |
private HealthObject healthTarget | Backing field for HealthTarget. |
private Dictionary<ImpactTool, float> hitCooldowns | Per-tool time before which further hits from that tool are ignored (the global hit cooldown). |
private List<ImpactImmunityGroup> immunityGroups | Backing field for ImmunityGroups. |
private bool isLocalClient | True when this detector is on the local player's own body. |
private bool isOverridingImpactorEffects | Backing field for IsOverridingImpactorEffects. |
private bool isPartOfPlayerController | True when this detector is on any player's body. |
private static Logger logger | NLog logger for this class. |
private ColliderMap[] mappedColliders | Collider and modifier pairs, copied into colliderModifiers on Awake. |
private static List<ParticleCollisionEvent> particleCollisions | Shared reusable list for particle collision events. |
private MethodSyncStruct<ImpactDetector.ImpactSyncArguments> syncImpact | Method sync that sends client-resolved hits (SyncImpact) to the server and other clients. |
Properties
| Member | What it is |
|---|---|
ImpactChannel[] Channels { get; } | The impact channels this detector responds to. |
Dictionary<Collider, ImpactDetectorColliderModifier> ColliderModifiers { get; } | Per-collider modifiers (for example weak spots) set up in the editor. |
ArmorDefinition CurrentArmor { get; } | The armour in the linked equipment slot, if any. |
uint HardnessLevel { get; set; } | How hard the surface is. Updated from the physical material when it changes. |
bool HasHealth { get; private set; } | True when HealthTarget is set. |
HealthObject HealthTarget { get; set; } | The HealthObject that takes damage from hits on this detector. |
IEnumerable<ImpactImmunityGroup> ImmunityGroups { get; } | Groups of tools this detector ignores. |
bool IsOverridingImpactorEffects { get; } | When true, the detector's own effects are used instead of the impactor's. |
ImpactDetectorSettings Settings { get; set; } | The detector settings. Swapping them moves the effects listener to the new settings. |
1 private and internal property
| Member | What it is |
|---|---|
private NetworkEntity Alta.Networking.INetworkEntityBehaviour.Entity { get; } | Explicit interface property returning the detector's entity field. |
Events
| Member | What it is |
|---|---|
event ImpactHandler Hit | Raised for every accepted hit, both tool hits and direct OnImpactHit calls. |
event ImpactHandler ParticleHit | Raised when a matching ParticleImpactor particle hits. |
Methods
| Member | What it is |
|---|---|
void OnCollisionEnter(Collision collision) | Unity callback. Sends a collision with a wielded, moving tool to the delayed impact resolver; skips it on the server when a client should decide it. |
void OnImpactHit(ImpactHit impact) | Raises Hit for a hit that did not come from a tool collision. |
void OnParticleCollision(GameObject other) | Unity callback. Turns ParticleImpactor particles into ParticleHit events and, on the server, applies skin-consumable liquid splashes. |
void OnToolHit(ImpactHitWithTool impactWithTool) | Handles a tool hit: per-tool cooldown, path experience on the server, damage popups, syncs the hit if a local player caused it, then raises Hit. |
void SyncImpact(IPlayer player, Stream stream, ImpactDetector.ImpactSyncArguments arguments) | Network handler for a synced hit. Rebuilds the hit from the tool entity and applies it; the server refuses hits from anyone but the tool's last holder. |
protected virtual void Awake() | Hooks the settings' hit effects (not on headless servers) and builds the collider modifier map. |
protected virtual void PreReceiveSyncedHit() | Hook for subclasses, called just before a hit received from the network is applied. |
17 private and internal methods
| Member | What it is |
|---|---|
private void HandleParticleAsLiquidCollision(GameObject other) | Server: when a liquid particle hits a detector with health, applies the liquid's effects if it can be absorbed through skin. |
private void HandleParticleHit(GameObject other) | Builds an ImpactHit from a ParticleImpactor on a matching channel and raises ParticleHit. Called from OnParticleCollision. |
private void Alta.Networking.INetworkEntityBehaviour.Initialize() | Creates the syncImpact method sync, unless an ImpactDetectorCentral sends impacts for this detector instead. |
private void IInitializeAsLocalPlayer.InitializeAsLocalPlayer(PlayerController playerController) | Marks the detector as part of the local player's body (isPartOfPlayerController and isLocalClient). |
private void IInitializeAsRemotePlayer.InitializeAsRemotePlayer(PlayerController playerController) | Marks the detector as part of a remote player's body. |
private void Alta.Networking.INetworkEntityBehaviour.InitializeAsServer(SpawnData spawnData) | Does nothing. |
private bool IsForcedClientSideImpact(ImpactTool tool) | True for a player-body detector unless the tool is held by a real player, so the hit player's client resolves it. |
private bool IsImpactClientSideOnly(ImpactTool tool, out PlayerController wielder) | True when a player wields the tool and the target is not a player, so the wielder's client resolves the hit. |
private bool IsLocalPlayerBeingHit(ImpactHitWithTool impactWithTool) | True on the local player's own body detectors when the hit is a forced client-side impact. |
private bool IsLocalPlayerHittingNonPlayer(ImpactHitWithTool impactWithTool) | True when the local player wields the tool and the target is not a player. |
private void Alta.Networking.INetworkEntityBehaviour.OnConnected(Player player) | Does nothing. |
private void Alta.Networking.INetworkEntityBehaviour.OnDisconnected(Player player) | Does nothing. |
private void RenderDamagePopup(ImpactHitWithTool impactWithTool) | Shows a damage popup at the hit point, split into base and bonus damage, and optionally a damage message. |
private void RunPlayerEvents(ImpactHitWithTool impactWithTool) | Server: if the hit counts for a progression path, reports it to the hitting player's events manager for experience. |
private void IListenToPhysicalMaterial.SetPhysicalMaterial(PhysicalMaterial newMaterial) | Copies the new physical material's hardness level into hardnessLevel. |
private static bool ShouldRefuseSyncedHit(NetworkEntity toolEntity, IPlayer fromPlayer) | Server: refuses a synced hit when the tool's last interactor is not the sending player. Off in local tests. |
private void UpdateDebugDamageDisplayer(ImpactHitWithTool impactWithTool) | Reports dealt damage to the hitting player's damage displayer, when that player is local. |
Used in
Members of other types that take, return or hold a ImpactDetector:
ForgedModel<TB, TA>.impactDetector, ForgedModel<TB, TA>.ImpactDetector, ConfirmationCraftingPart.ClientSideNailHitSync.GetImpactDamage, GenericCraftingNail.impactDetector, GenericCraftingNail.ImpactDetector, GenericCraftingStation.ClientSideNailHitSync.GetImpactDamage, ContactPointStructure.ContactPointStructure, ContactPointStructure.Detector, DelayedImpactResolver.Hit, DelayedImpactResolver.ProcessImmediate, DelayedImpactResolver.ImpactDetectorHit.impactDetector, DelayedImpactResolver.ImpactDetectorHit.ImpactDetectorHit, EmbeddableSurface.detector, ImpactDetectorCentral.availableDetectors, ImpactDetectorCentral.SendArguments, ImpactDetectorCentral.CentralizedArguments.detector, ImpactDetectorCentral.CentralizedArguments.Serialize, ImpactHit.ImpactDetector, ImpactHit.ImpactHit, ImpactHitThresholdTrigger.detector, ImpactHitTrigger.detector, ImpactHitWithTool.ImpactHitWithTool, ImpactTool.GenerateHit, ImpactTool.GenerateImpactOnDetector, ImpactTool.GetImpactDamageOn, SparkSecondaryDetector.baseDetector, TriggerImpactTool.ignore, TriggerImpactTool.DelayedHit.DelayedHit, TriggerImpactTool.DelayedHit.detector, DestroyableStaticObject.detectors, WoodcutTree.impactDetector, WoodcutTreeModel.impactDetector, WoodcutTreeModel.SetImpactDetector, BuildupPickup.impactDetector, Explosive.detectors, Fuse.impactDetector, HealthObject.impactDetectors, ImpactDetectionLogic.impactDetector, Rock.impactDetector, SteelSong.activeDetectors, SteelSong.activeEffects, SteelSong.detectorHitCount, SteelSong.detectorMap, SteelSong.ReleaseImpactorEffect.