コード例 #1
0
        private static void SimulateSwarmerNest(
            Random rand,
            GameSession game,
            int systemId,
            FleetInfo randomsFleet,
            int aiPlayerID,
            List <FleetInfo> aiPlayerFleets)
        {
            int numToKill = rand.NextInclusive(2, 4);
            Dictionary <FleetInfo, List <ShipInfo> > shipsInFleets = CombatSimulatorRandoms.GetShipsInFleets(game, aiPlayerFleets);

            shipsInFleets.Sum <KeyValuePair <FleetInfo, List <ShipInfo> > >((Func <KeyValuePair <FleetInfo, List <ShipInfo> >, int>)(x => x.Value.Count));
            if (shipsInFleets.Sum <KeyValuePair <FleetInfo, List <ShipInfo> > >((Func <KeyValuePair <FleetInfo, List <ShipInfo> >, int>)(x =>
            {
                if (x.Value.Count <= 0)
                {
                    return(0);
                }
                return(x.Value.Sum <ShipInfo>((Func <ShipInfo, int>)(y =>
                {
                    if (y.DesignInfo == null)
                    {
                        return 0;
                    }
                    return CombatAI.GetShipStrength(y.DesignInfo.Class) / 3;
                })));
            })) <= 2)
            {
                foreach (KeyValuePair <FleetInfo, List <ShipInfo> > keyValuePair in shipsInFleets)
                {
                    foreach (ShipInfo shipInfo in keyValuePair.Value)
                    {
                        game.GameDatabase.RemoveShip(shipInfo.ID);
                    }
                    CombatSimulatorRandoms.FleetDestroyed(game, randomsFleet.PlayerID, keyValuePair.Key, (ShipInfo)null);
                    game.GameDatabase.RemoveFleet(keyValuePair.Key.ID);
                }
                if (game.GameDatabase.GetShipInfoByFleetID(randomsFleet.ID, false).ToList <ShipInfo>().Count != 0)
                {
                    return;
                }
                game.GameDatabase.RemoveFleet(randomsFleet.ID);
            }
            else
            {
                CombatSimulatorRandoms.UpdateShipsKilled(game, rand, shipsInFleets, randomsFleet.PlayerID, numToKill);
                List <ShipInfo> list = game.GameDatabase.GetShipInfoByFleetID(randomsFleet.ID, false).ToList <ShipInfo>();
                if (list.Count > 0)
                {
                    CombatSimulatorRandoms.FleetDestroyed(game, aiPlayerID, randomsFleet, list.First <ShipInfo>());
                }
                game.GameDatabase.RemoveFleet(randomsFleet.ID);
            }
        }
コード例 #2
0
        private static void UpdateShipsKilled(
            GameSession game,
            Random rand,
            Dictionary <FleetInfo, List <ShipInfo> > aiPlayerShips,
            int randomsPlayerID,
            int numToKill)
        {
            int num1 = numToKill;

            for (int index = 0; index < numToKill && num1 > 0 && aiPlayerShips.Keys.Count > 0; ++index)
            {
                bool flag = false;
                while (!flag && aiPlayerShips.Keys.Count > 0)
                {
                    int num2 = 0;
                    foreach (KeyValuePair <FleetInfo, List <ShipInfo> > aiPlayerShip in aiPlayerShips)
                    {
                        num2 += aiPlayerShip.Value.Count;
                        foreach (ShipInfo shipInfo in aiPlayerShip.Value)
                        {
                            ShipInfo ship = shipInfo;
                            if (rand.CoinToss(50))
                            {
                                num1 -= CombatAI.GetShipStrength(ship.DesignInfo.Class) / 3;
                                if (ship.DesignInfo.IsSuulka())
                                {
                                    TurnEvent turnEvent = game.GameDatabase.GetTurnEventsByTurnNumber(game.GameDatabase.GetTurnCount(), aiPlayerShip.Key.PlayerID).FirstOrDefault <TurnEvent>((Func <TurnEvent, bool>)(x => x.ShipID == ship.ID));
                                    if (turnEvent != null)
                                    {
                                        game.GameDatabase.RemoveTurnEvent(turnEvent.ID);
                                    }
                                    game.GameDatabase.InsertTurnEvent(new TurnEvent()
                                    {
                                        EventType    = TurnEventType.EV_SUULKA_DIES,
                                        EventMessage = TurnEventMessage.EM_SUULKA_DIES,
                                        PlayerID     = randomsPlayerID,
                                        SystemID     = aiPlayerShip.Key.SystemID,
                                        ShipID       = ship.ID,
                                        DesignID     = ship.DesignID,
                                        TurnNumber   = game.GameDatabase.GetTurnCount(),
                                        ShowsDialog  = false
                                    });
                                    SuulkaInfo suulkaByShipId = game.GameDatabase.GetSuulkaByShipID(ship.ID);
                                    if (suulkaByShipId != null)
                                    {
                                        game.GameDatabase.RemoveSuulka(suulkaByShipId.ID);
                                    }
                                }
                                game.GameDatabase.RemoveShip(ship.ID);
                                aiPlayerShip.Value.Remove(ship);
                                flag = true;
                                break;
                            }
                        }
                        if (flag)
                        {
                            if (aiPlayerShip.Value.Count == 0)
                            {
                                CombatSimulatorRandoms.FleetDestroyed(game, randomsPlayerID, aiPlayerShip.Key, (ShipInfo)null);
                                game.GameDatabase.RemoveFleet(aiPlayerShip.Key.ID);
                                aiPlayerShips.Remove(aiPlayerShip.Key);
                                break;
                            }
                            break;
                        }
                    }
                    if (num2 == 0)
                    {
                        break;
                    }
                }
            }
            foreach (KeyValuePair <FleetInfo, List <ShipInfo> > aiPlayerShip in aiPlayerShips)
            {
                if (aiPlayerShip.Value.Count > 0)
                {
                    CombatSimulatorRandoms.CheckFleetCommandPoints(game, aiPlayerShip.Key, aiPlayerShip.Value);
                }
            }
        }
コード例 #3
0
        private void UpdateTargetSelection()
        {
            List <Ship> source = new List <Ship>();

            if (this.m_TaskGroupObjective.m_TargetEnemyGroup != null)
            {
                foreach (Ship ship in this.m_TaskGroupObjective.m_TargetEnemyGroup.m_Ships)
                {
                    if (Ship.IsActiveShip(ship) && ship.IsDetected(this.m_CommanderAI.m_Player))
                    {
                        source.Add(ship);
                    }
                }
            }
            bool flag = false;

            if (source.Count > 0)
            {
                --this.m_ClearTargetsUpdate;
                if (this.m_ClearTargetsUpdate <= 0)
                {
                    flag = true;
                    this.m_ClearTargetsUpdate = BaseAttackShipControl.kUpdateClearTarget;
                }
            }
            else
            {
                this.m_ClearTargetsUpdate = BaseAttackShipControl.kUpdateClearTarget;
            }
            List <Ship> shipList = new List <Ship>();

            foreach (Ship ship in this.m_Ships)
            {
                shipList.Add(ship);
                if (ship.Target != null && ship.Target is Ship)
                {
                    Ship s = ship.Target as Ship;
                    if (!Ship.IsActiveShip(s) || !source.Any <Ship>((Func <Ship, bool>)(x => x == s)) || flag)
                    {
                        this.SetNewTarget(ship, (IGameObject)null);
                    }
                }
            }
            if (shipList.Count == 0 || source.Count == 0)
            {
                return;
            }
            ShipTargetComparision targetComparision = new ShipTargetComparision(this.m_CommanderAI, this.GetCurrentPosition());

            source.Sort((IComparer <Ship>)targetComparision);
            this.m_GroupPriorityTarget = (Ship)null;
            foreach (Ship ship in source)
            {
                Ship e = ship;
                if (!this.m_CommanderAI.GetTaskGroups().Any <TaskGroup>((Func <TaskGroup, bool>)(x => x.IsDesiredGroupTargetTaken((TaskGroupShipControl)this, e))))
                {
                    this.m_GroupPriorityTarget = e;
                    break;
                }
            }
            if (this.m_GroupPriorityTarget == null)
            {
                this.m_GroupPriorityTarget = source.First <Ship>();
            }
            int targetShipScore = this.m_CommanderAI.GetTargetShipScore(this.m_GroupPriorityTarget);

            while (targetShipScore > 0 && shipList.Count > 0)
            {
                Ship  ship1 = (Ship)null;
                int   num1  = 0;
                float num2  = float.MaxValue;
                foreach (Ship ship2 in shipList)
                {
                    float lengthSquared = (ship2.Maneuvering.Position - this.m_GroupPriorityTarget.Maneuvering.Position).LengthSquared;
                    if ((double)lengthSquared < (double)num2)
                    {
                        num1  = CombatAI.GetShipStrength(this.m_GroupPriorityTarget);
                        num2  = lengthSquared;
                        ship1 = ship2;
                    }
                }
                if (ship1 != null)
                {
                    this.SetNewTarget(ship1, (IGameObject)this.m_GroupPriorityTarget);
                    targetShipScore -= num1;
                    shipList.Remove(ship1);
                }
                else
                {
                    break;
                }
            }
            if (shipList.Count <= 0)
            {
                return;
            }
            foreach (Ship ship1 in shipList)
            {
                Ship  ship2 = (Ship)null;
                float num   = float.MaxValue;
                foreach (Ship ship3 in source)
                {
                    if (ship3 != this.m_GroupPriorityTarget)
                    {
                        float lengthSquared = (ship1.Maneuvering.Position - ship3.Maneuvering.Position).LengthSquared;
                        if ((double)lengthSquared < (double)num)
                        {
                            num   = lengthSquared;
                            ship2 = ship3;
                        }
                    }
                }
                if (ship2 != null)
                {
                    this.SetNewTarget(ship1, (IGameObject)ship2);
                }
                else
                {
                    this.SetNewTarget(ship1, (IGameObject)this.m_GroupPriorityTarget);
                }
            }
        }