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]);
            }
        }
Beispiel #2
0
        public override void Execute(ShipContext context)
        {
            //Debug.Log($"In randomly orbit action");
            if (context.targetComp.target != null)
            {
                var AIShipComp = context.AiShipComp;
                AIShipComp.Navigation.SetNavState(EAINavState.ORBIT);
                AIShipComp.Navigation.HasReachedTarget = false;
                //AiShipComp.TargetPositionOffset = ZenUtils.Vec3Util.GetRandomVector(3, 3, 3);
                //AiShipComp.TargetPositionOffset = GetRandomOrbitPosition(15, 6);

                //Find new orbit point with no immediate collisions
                bool FoundFreePoint = false;
                while (!FoundFreePoint)
                {
                    //Try getting vector on the other side of the target diff
                    AIShipComp.Navigation.TargetPositionOffset = (context.targetComp.target.position - context.transform.position)
                                                                 + GetRandomOrbitPosition(MinOrbitRange, MaxOrbitRange);
                    if (!Physics.Linecast(context.transform.position,
                                          context.targetComp.target.position + AIShipComp.Navigation.TargetPositionOffset,
                                          ZenUtils.LayerMaskFromIDs(SRLayers.foreground, SRLayers.npc, SRLayers.player)))
                    {
                        FoundFreePoint = true;
                    }
                    else
                    {
                        Debug.Log("Point is collision course");
                    }
                }
            }
        }
        //private Highlighter targetHighlighter;
        //private GameObject radarRIDGO;
        //private FX_3DRadar_RID radarRID;

        public override bool Init()
        {
            player              = engine.FindEntity(Res.Entities.Player);
            cam                 = Camera.main;
            targetComp          = player.GetComponent <TargetComp>();
            selectableLayerMask = ZenUtils.LayerMaskFromIDs(SRLayerMask.npc, SRLayerMask.foreground);

            player.GetComponent <CommandComp>().SelectTarget.Where(x => x).Subscribe(SelectTargetClicked);
            //radarRIDGO = GameObject.Find("Target_1");
            //radarRID = radarRIDGO.GetComponent<FX_3DRadar_RID>();
            return(false);
        }
        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());
                    }
                }
            }
        }