public override void Update() { var areas = engine.Get(ComponentTypes.MissileAreaDamageComp); for (int i = areas.Count - 1; i >= 0; i--) { //#HERE: testing rotations and area explosions causing other missiles to throw exceptions var hits = PerformAreaCast((MissileAreaDamageComp)areas[i]); foreach (var hit in hits) { var ew = (EntityWrapper)hit.gameObject.GetComponentDownThenUp <EntityWrapper>(); if (ew != null) { //Debug.Log($"adding dmg comp to {ew.Entity.EntityName}"); var lmc = ((MissileAreaDamageComp)areas[i]).GetComponent <LaunchedMissileComp>(); var dc = ew.Entity.GetOrAddComponent <DamageComp>(ComponentTypes.DamageComp); dc.damagePackets.Push(new DamagePacket(lmc.projectileInfo.HullDamage, lmc.projectileInfo.ShieldDamage)); ZenUtils.ApplyExplosionForce(ew, lmc.Owner.Wrapper.transform.position, lmc.projectileInfo.ExplosionForce); } } //Adding damage comp here so the missile itself explodes //areas[i].Owner.AddComponent(ComponentTypes.DamageComp); areas[i].GetComponent <DamageComp>().damagePackets.Push(new DamagePacket()); areas[i].Owner.RemoveComponent(areas[i]); } }
public override void Update() { var matches = missileMatcher.GetMatches(); foreach (var match in matches) { var cc = match.GetComponent <CollisionEnterComp>(); var lmc = match.GetComponent <LaunchedMissileComp>(); if (lmc.projectileInfo.ExplosionImpactRadius > 0 && cc.Other.Count > 0) { Debug.Log($"Performing area explosion from collision"); RangedCombatHelper.PerformAreaExplosion(lmc); } else { foreach (var coll in cc.Other) { //var oth = coll.gameObject.GetComponent<EntityWrapper>(); var oth = coll.gameObject.GetEntityWrapper(); if (oth != null) { if (!oth.Entity.HasComponent(ComponentTypes.DamageComp)) { Debug.Log($"Missile Collision system adding collision to {oth.Entity.EntityName}"); var dc = oth.Entity.GetOrAddComponent <DamageComp>(ComponentTypes.DamageComp); dc.damagePackets.Push(new DamagePacket(lmc.projectileInfo.HullDamage, lmc.projectileInfo.ShieldDamage)); ZenUtils.ApplyExplosionForce(oth, coll.contacts[0].point, lmc.projectileInfo.ExplosionImpactRadius); } } } if (cc.Other.Count > 0) // missile hit *something* so blow up { Debug.Log($"Missile Collision system adding damage from collision to missile"); match.GetOrAddComponent <DamageComp>(ComponentTypes.DamageComp).damagePackets.Push(new DamagePacket()); } } } }