Skip to main content

Explosive

A class in Root.Township, the global namespace.

Networked explosion: when triggered, the server damages health objects and impact detectors in range with linear falloff and can push rigidbodies; the effect plays on every client.

Constructors​

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

Fields​

22 private and internal fields
MemberWhat it is
private Pickup basePickupPickup the explosive belongs to, used for the wielder.
private float blastForceExplosion force applied to rigidbodies in range.
private bool btnTriggerInspector button that calls Trigger.
private ImpactChannel[] channelsImpact channels a detector needs to be hit.
private float crippleDamageCripple damage at full effectiveness.
private float damageFallOffDistance between maxDamageRange and range.
private HashSet<ImpactDetector> detectorsImpact detectors without a health target hit by this blast.
private PooledObjectDefinitionBase effectDefinitionPooled effect played on explosion.
private EvaluateWielder getWielderDelegate that returns the entity and player credited with the damage.
private int hardnessLevelHighest detector hardness that can be hit; -1 skips the check.
private float healthDamageHealth damage at full effectiveness.
private HashSet<HealthObject> healthsHealth objects hit by this blast.
private ImpactType impactTypeImpact type of the hit, explosive by default.
private bool isTriggeredSet once Trigger has run.
private LayerMask layerMaskLayers the overlap sphere checks.
private float maxDamageRangeDistance within which targets take full damage.
private float maxDamageRangeSquaredSquare of maxDamageRange.
private bool moveObjectsInspector toggle that shows blastForce; the force is applied whenever it is above zero.
private float playerDamageMultiplierMultiplier on health damage dealt to players.
private float rangeFurthest distance anything is affected.
private float rangeSquaredSquare of range.
private MethodSync syncEffectMethod sync that tells clients to play the effect.

Methods​

MemberWhat it is
override void Initialize()Creates the effect sync.
override void InitializeAsServer(SpawnData data)Works out who gets credit for the damage: the parent pickup's last interactor, or the prefab root if there is no pickup.
void OnDrawGizmosSelected()Draws the full-damage and maximum ranges.
void Trigger()Server: overlap-spheres the range, damages matching detectors and health objects once each, applies blast force, plays the effect and syncs it.
protected virtual PooledObject GetEffect(Vector3 position, Quaternion rotation)Spawns the pooled explosion effect at a position; override to change the effect.
3 private and internal methods
MemberWhat it is
private bool GetEffectiveness(Vector3 position, Vector3 origin, out float effectiveness)Gives 1 inside maxDamageRange, falling linearly to 0 at range; false when out of range.
private void RootChanged(CraftingPart newRoot)When crafted into a new root, moves the last player interactor to the new root's pickup and tracks that.
private void SyncEffect(IPlayer player, Stream stream)On remote clients (not headless), plays the effect at the explosive's position.