コード例 #1
0
        public void RequestTargetFromParent(SwarmerAttackerControl sac)
        {
            if (this.m_TargetList.Count == 0)
            {
                return;
            }
            SwarmerTarget swarmerTarget1 = (SwarmerTarget)null;
            SwarmerTarget swarmerTarget2 = (SwarmerTarget)null;
            SwarmerTarget swarmerTarget3 = (SwarmerTarget)null;
            float         num1           = float.MaxValue;
            float         num2           = float.MaxValue;
            float         num3           = float.MaxValue;

            foreach (SwarmerTarget target1 in this.m_TargetList)
            {
                int   num4 = 0;
                int   num5 = 0;
                float num6 = 0.0f;
                if (target1.Target is Ship)
                {
                    Ship      target2   = target1.Target as Ship;
                    ShipClass shipClass = target2.ShipClass;
                    num4 = SwarmerAttackerControl.NumSwarmersPerShip(shipClass) - target1.SwarmersOnTarget;
                    num5 = SwarmerAttackerControl.NumGuardiansPerShip(shipClass) - target1.GuardiansOnTarget;
                    num6 = (target2.Position - sac.GetShip().Position).LengthSquared;
                    if ((double)num6 < (double)num3)
                    {
                        num3           = num6;
                        swarmerTarget3 = target1;
                    }
                }
                else if (target1.Target is StellarBody)
                {
                    StellarBody target2       = target1.Target as StellarBody;
                    int         num7          = this.m_NumSwarmersToAttackPlanet - this.m_AttackingPlanetSwarmers.Count;
                    int         num8          = this.m_NumGardiansToAttackPlanet - this.m_AttackingPlanetGardians.Count;
                    float       lengthSquared = (target2.Parameters.Position - sac.GetShip().Position).LengthSquared;
                    if ((double)lengthSquared < (double)num2)
                    {
                        num2           = lengthSquared;
                        swarmerTarget2 = target1;
                        continue;
                    }
                    continue;
                }
                if (sac.Type == SwarmerAttackerType.GAURDIAN)
                {
                    if (num5 <= 0)
                    {
                        continue;
                    }
                }
                else if (num4 <= 0)
                {
                    continue;
                }
                if ((double)num6 < (double)num1)
                {
                    num1           = num6;
                    swarmerTarget1 = target1;
                }
            }
            if (swarmerTarget2 != null)
            {
                if (this.m_AttackingPlanetSwarmers.Contains(sac.GetShip().ObjectID) || this.m_AttackingPlanetGardians.Contains(sac.GetShip().ObjectID))
                {
                    swarmerTarget1 = swarmerTarget2;
                }
                else if ((sac.Type == SwarmerAttackerType.GAURDIAN ? this.m_NumGardiansToAttackPlanet - this.m_AttackingPlanetGardians.Count : this.m_NumSwarmersToAttackPlanet - this.m_AttackingPlanetSwarmers.Count) > 0)
                {
                    swarmerTarget1 = swarmerTarget2;
                }
            }
            if (swarmerTarget1 != null || swarmerTarget3 != null)
            {
                if (sac.Type == SwarmerAttackerType.GAURDIAN)
                {
                    if (swarmerTarget1 != null)
                    {
                        swarmerTarget1.IncGuardiansOnTarget();
                    }
                    else
                    {
                        swarmerTarget3.IncGuardiansOnTarget();
                    }
                }
                else if (swarmerTarget1 != null)
                {
                    swarmerTarget1.IncSwarmersOnTarget();
                }
                else
                {
                    swarmerTarget3.IncSwarmersOnTarget();
                }
                if (swarmerTarget1 != null)
                {
                    sac.SetTarget(swarmerTarget1.Target);
                    if (!(swarmerTarget1.Target is StellarBody) || this.m_AttackingPlanetSwarmers.Contains(sac.GetShip().ObjectID) || this.m_AttackingPlanetGardians.Contains(sac.GetShip().ObjectID))
                    {
                        return;
                    }
                    if (sac.Type == SwarmerAttackerType.GAURDIAN)
                    {
                        this.m_AttackingPlanetGardians.Add(sac.GetShip().ObjectID);
                    }
                    else
                    {
                        this.m_AttackingPlanetSwarmers.Add(sac.GetShip().ObjectID);
                    }
                }
                else
                {
                    sac.SetTarget(swarmerTarget3.Target);
                }
            }
            else
            {
                sac.SetTarget((IGameObject)null);
            }
        }
コード例 #2
0
        public override void FindNewTarget(IEnumerable <IGameObject> objs)
        {
            List <SwarmerTarget> source            = new List <SwarmerTarget>();
            List <SwarmerTarget> swarmerTargetList = new List <SwarmerTarget>();

            foreach (SwarmerTarget target in this.m_TargetList)
            {
                target.ClearNumTargets();
            }
            source.AddRange((IEnumerable <SwarmerTarget>) this.m_TargetList);
            foreach (IGameObject gameObject in objs)
            {
                if (gameObject is Ship)
                {
                    Ship ship = gameObject as Ship;
                    if (Ship.IsActiveShip(ship) && (this.m_IsDeepSpace || ship.IsDetected(this.m_SwarmerSpawner.Player)) && ship.Player != this.m_SwarmerSpawner.Player)
                    {
                        swarmerTargetList.Add(new SwarmerTarget()
                        {
                            Target = (IGameObject)ship
                        });
                        SwarmerTarget swarmerTarget = source.FirstOrDefault <SwarmerTarget>((Func <SwarmerTarget, bool>)(x => x.Target == ship));
                        if (swarmerTarget != null)
                        {
                            source.Remove(swarmerTarget);
                        }
                    }
                }
                else if (gameObject is StellarBody)
                {
                    StellarBody planet = gameObject as StellarBody;
                    if (planet.Population > 0.0)
                    {
                        swarmerTargetList.Add(new SwarmerTarget()
                        {
                            Target = (IGameObject)planet
                        });
                        SwarmerTarget swarmerTarget = source.FirstOrDefault <SwarmerTarget>((Func <SwarmerTarget, bool>)(x => x.Target == planet));
                        if (swarmerTarget != null)
                        {
                            source.Remove(swarmerTarget);
                        }
                    }
                }
            }
            if (source.Count > 0)
            {
                foreach (SwarmerAttackerControl spawnedSwarmer in this.m_SpawnedSwarmers)
                {
                    SwarmerAttackerControl swarmer = spawnedSwarmer;
                    if (source.Any <SwarmerTarget>((Func <SwarmerTarget, bool>)(x => x.Target == swarmer.GetTarget())))
                    {
                        swarmer.SetTarget((IGameObject)null);
                    }
                }
                foreach (SwarmerAttackerControl spawnedGuardian in this.m_SpawnedGuardians)
                {
                    SwarmerAttackerControl guardian = spawnedGuardian;
                    if (source.Any <SwarmerTarget>((Func <SwarmerTarget, bool>)(x => x.Target == guardian.GetTarget())))
                    {
                        guardian.SetTarget((IGameObject)null);
                    }
                }
            }
            if (swarmerTargetList.Count > this.m_TargetList.Count)
            {
                foreach (SwarmerTarget target in this.m_TargetList)
                {
                    target.ClearNumTargets();
                    int num1 = 0;
                    int num2 = 0;
                    if (target.Target is Ship)
                    {
                        ShipClass shipClass = (target.Target as Ship).ShipClass;
                        num1 = SwarmerAttackerControl.NumSwarmersPerShip(shipClass);
                        num2 = SwarmerAttackerControl.NumGuardiansPerShip(shipClass);
                    }
                    else if (target.Target is StellarBody)
                    {
                        num1 = this.m_NumSwarmersToAttackPlanet;
                        num2 = this.m_NumGardiansToAttackPlanet;
                    }
                    foreach (SwarmerAttackerControl spawnedSwarmer in this.m_SpawnedSwarmers)
                    {
                        if (spawnedSwarmer.GetTarget() == target.Target)
                        {
                            if (num1 > 0)
                            {
                                --num1;
                                target.IncSwarmersOnTarget();
                            }
                            else
                            {
                                spawnedSwarmer.SetTarget((IGameObject)null);
                            }
                        }
                    }
                    foreach (SwarmerAttackerControl spawnedGuardian in this.m_SpawnedGuardians)
                    {
                        if (spawnedGuardian.GetTarget() == target.Target)
                        {
                            if (num2 > 0)
                            {
                                --num2;
                                target.IncGuardiansOnTarget();
                            }
                            else
                            {
                                spawnedGuardian.SetTarget((IGameObject)null);
                            }
                        }
                    }
                }
            }
            else
            {
                foreach (SwarmerAttackerControl spawnedSwarmer in this.m_SpawnedSwarmers)
                {
                    SwarmerAttackerControl swarmer = spawnedSwarmer;
                    if (swarmer.GetTarget() != null)
                    {
                        this.m_TargetList.FirstOrDefault <SwarmerTarget>((Func <SwarmerTarget, bool>)(x => x.Target == swarmer.GetTarget()))?.IncSwarmersOnTarget();
                    }
                }
                foreach (SwarmerAttackerControl spawnedGuardian in this.m_SpawnedGuardians)
                {
                    SwarmerAttackerControl guardian = spawnedGuardian;
                    if (guardian.GetTarget() != null)
                    {
                        this.m_TargetList.FirstOrDefault <SwarmerTarget>((Func <SwarmerTarget, bool>)(x => x.Target == guardian.GetTarget()))?.IncGuardiansOnTarget();
                    }
                }
            }
            foreach (SwarmerTarget swarmerTarget in swarmerTargetList)
            {
                SwarmerTarget target = swarmerTarget;
                if (!this.m_TargetList.Any <SwarmerTarget>((Func <SwarmerTarget, bool>)(x => x.Target == target.Target)))
                {
                    target.ClearNumTargets();
                    this.m_TargetList.Add(target);
                }
            }
            this.m_UpdateTargetList = false;
        }