示例#1
0
        private static ShipCombatInfo SelectTargetShip(
            FleetInfo currentFleet,
            Dictionary <FleetInfo, List <ShipCombatInfo> > shipCombatInfo)
        {
            IEnumerable <KeyValuePair <FleetInfo, List <ShipCombatInfo> > > source = shipCombatInfo.Where <KeyValuePair <FleetInfo, List <ShipCombatInfo> > >((Func <KeyValuePair <FleetInfo, List <ShipCombatInfo> >, bool>)(x =>
            {
                if (x.Key != currentFleet)
                {
                    return(CombatSimulator.IsFleetAlive(x.Value));
                }
                return(false);
            }));

            if (source.Count <KeyValuePair <FleetInfo, List <ShipCombatInfo> > >() == 0)
            {
                return((ShipCombatInfo)null);
            }
            int index = CombatSimulator._rand.Next(0, source.Count <KeyValuePair <FleetInfo, List <ShipCombatInfo> > >() - 1);
            KeyValuePair <FleetInfo, List <ShipCombatInfo> > keyValuePair = source.ElementAt <KeyValuePair <FleetInfo, List <ShipCombatInfo> > >(index);
            ShipCombatInfo shipCombatInfo1 = (ShipCombatInfo)null;

            foreach (ShipCombatInfo shipCombatInfo2 in keyValuePair.Value)
            {
                if (shipCombatInfo2.shipInfo.DesignInfo.Role == ShipRole.COMMAND && (double)shipCombatInfo2.structureFactor > 0.0)
                {
                    shipCombatInfo1 = shipCombatInfo2;
                    break;
                }
            }
            if (shipCombatInfo1 == null)
            {
                foreach (ShipCombatInfo shipCombatInfo2 in keyValuePair.Value)
                {
                    if ((double)shipCombatInfo2.structureFactor > 0.0)
                    {
                        shipCombatInfo1 = shipCombatInfo2;
                        break;
                    }
                }
            }
            return(shipCombatInfo1);
        }
示例#2
0
        private static void CompleteSimulation(
            GameSession game,
            int systemId,
            Dictionary <FleetInfo, List <ShipCombatInfo> > shipCombatInfo,
            List <PlanetCombatInfo> planets)
        {
            CombatData combatData = game.CombatData.AddCombat(GameSession.GetNextUniqueCombatID(), systemId, game.GameDatabase.GetTurnCount());

            foreach (KeyValuePair <FleetInfo, List <ShipCombatInfo> > keyValuePair1 in shipCombatInfo)
            {
                PlayerCombatData orAddPlayer = combatData.GetOrAddPlayer(keyValuePair1.Key.PlayerID);
                orAddPlayer.VictoryStatus = GameSession.VictoryStatus.Draw;
                foreach (ShipCombatInfo shipCombatInfo1 in keyValuePair1.Value)
                {
                    ShipCombatInfo sci = shipCombatInfo1;
                    if ((double)sci.structureFactor == 0.0)
                    {
                        if (sci.shipInfo.DesignInfo.IsSuulka())
                        {
                            TurnEvent turnEvent = game.GameDatabase.GetTurnEventsByTurnNumber(game.GameDatabase.GetTurnCount(), orAddPlayer.PlayerID).FirstOrDefault <TurnEvent>((Func <TurnEvent, bool>)(x => x.ShipID == sci.shipInfo.ID));
                            if (turnEvent != null)
                            {
                                game.GameDatabase.RemoveTurnEvent(turnEvent.ID);
                            }
                            List <int> intList1 = new List <int>();
                            List <int> intList2 = new List <int>();
                            foreach (KeyValuePair <FleetInfo, List <ShipCombatInfo> > keyValuePair2 in shipCombatInfo)
                            {
                                if (orAddPlayer.PlayerID != keyValuePair2.Key.PlayerID && !intList1.Contains(keyValuePair2.Key.PlayerID) && !intList2.Contains(keyValuePair2.Key.PlayerID))
                                {
                                    switch (game.GameDatabase.GetDiplomacyStateBetweenPlayers(orAddPlayer.PlayerID, keyValuePair2.Key.PlayerID))
                                    {
                                    case DiplomacyState.WAR:
                                        intList1.Add(keyValuePair2.Key.PlayerID);
                                        continue;

                                    case DiplomacyState.NEUTRAL:
                                        intList2.Add(keyValuePair2.Key.PlayerID);
                                        continue;

                                    default:
                                        continue;
                                    }
                                }
                            }
                            int num = 0;
                            if (intList1.Count > 0)
                            {
                                num = App.GetSafeRandom().Choose <int>((IList <int>)intList1);
                            }
                            else if (intList2.Count > 0)
                            {
                                num = App.GetSafeRandom().Choose <int>((IList <int>)intList2);
                            }
                            game.GameDatabase.InsertTurnEvent(new TurnEvent()
                            {
                                EventType    = TurnEventType.EV_SUULKA_DIES,
                                EventMessage = TurnEventMessage.EM_SUULKA_DIES,
                                PlayerID     = num,
                                SystemID     = systemId,
                                ShipID       = sci.shipInfo.ID,
                                DesignID     = sci.shipInfo.DesignID,
                                TurnNumber   = game.GameDatabase.GetTurnCount(),
                                ShowsDialog  = false
                            });
                            SuulkaInfo suulkaByShipId = game.GameDatabase.GetSuulkaByShipID(sci.shipInfo.ID);
                            if (suulkaByShipId != null)
                            {
                                game.GameDatabase.RemoveSuulka(suulkaByShipId.ID);
                            }
                        }
                        game.GameDatabase.RemoveShip(sci.shipInfo.ID);
                        GameTrigger.PushEvent(EventType.EVNT_SHIPDIED, (object)sci.shipInfo.DesignInfo.Class, game);
                        orAddPlayer.AddShipData(sci.shipInfo.DesignID, 0.0f, 0.0f, 0, true);
                        if (ScriptHost.AllowConsole)
                        {
                            App.Log.Trace(string.Format("Ship destroyed: {0} ({1})", (object)sci.shipInfo.ID, (object)sci.shipInfo.ShipName), "combat");
                        }
                    }
                    else
                    {
                        if (sci.shipInfo.DesignInfo == null)
                        {
                            sci.shipInfo.DesignInfo = game.GameDatabase.GetDesignInfo(sci.shipInfo.DesignID);
                        }
                        foreach (SectionInstanceInfo sectionInstanceInfo in game.GameDatabase.GetShipSectionInstances(sci.shipInfo.ID).ToList <SectionInstanceInfo>())
                        {
                            SectionInstanceInfo sii = sectionInstanceInfo;
                            int minStructure        = ((IEnumerable <DesignSectionInfo>)sci.shipInfo.DesignInfo.DesignSections).First <DesignSectionInfo>((Func <DesignSectionInfo, bool>)(x => x.ID == sii.SectionID)).GetMinStructure(game.GameDatabase, game.AssetDatabase);
                            sii.Structure -= sii.Structure - (int)Math.Round((double)sci.structureFactor);
                            sii.Structure  = Math.Max(sii.Structure, minStructure);
                            game.GameDatabase.UpdateSectionInstance(sii);
                            if (sii.Structure == minStructure)
                            {
                                foreach (ModuleInstanceInfo module in game.GameDatabase.GetModuleInstances(sii.ID).ToList <ModuleInstanceInfo>())
                                {
                                    module.Structure = 0;
                                    game.GameDatabase.UpdateModuleInstance(module);
                                }
                                foreach (WeaponInstanceInfo weapon in game.GameDatabase.GetWeaponInstances(sii.ID).ToList <WeaponInstanceInfo>())
                                {
                                    weapon.Structure = 0.0f;
                                    game.GameDatabase.UpdateWeaponInstance(weapon);
                                }
                            }
                        }
                    }
                }
                if (!CombatSimulator.IsFleetAlive(keyValuePair1.Value))
                {
                    game.GameDatabase.RemoveFleet(keyValuePair1.Key.ID);
                    GameTrigger.PushEvent(EventType.EVNT_FLEETDIED, (object)keyValuePair1.Key.Name, game);
                    if (ScriptHost.AllowConsole)
                    {
                        App.Log.Trace(string.Format("Fleet destroyed: {0} ({1})", (object)keyValuePair1.Key.ID, (object)keyValuePair1.Key.Name), "combat");
                    }
                }
                else
                {
                    CombatSimulator.CheckFleetCommandPoints(game, keyValuePair1.Key);
                }
            }
            bool flag = true;

            foreach (PlanetCombatInfo planet in planets)
            {
                game.GameDatabase.UpdatePlanet(planet.planetInfo);
                if (planet.colonyInfo != null)
                {
                    if (planet.colonyInfo.ImperialPop <= 0.0)
                    {
                        game.GameDatabase.RemoveColonyOnPlanet(planet.planetInfo.ID);
                        if (ScriptHost.AllowConsole)
                        {
                            App.Log.Trace(string.Format("Colony defeated: planetid={0}", (object)planet.planetInfo.ID), "combat");
                        }
                    }
                    else
                    {
                        flag = false;
                        planet.colonyInfo.DamagedLastTurn = true;
                        game.GameDatabase.UpdateColony(planet.colonyInfo);
                        foreach (ColonyFactionInfo faction in planet.colonyInfo.Factions)
                        {
                            game.GameDatabase.UpdateCivilianPopulation(faction);
                        }
                    }
                }
            }
            if (flag)
            {
                foreach (StationInfo stationInfo in game.GameDatabase.GetStationForSystem(systemId).ToList <StationInfo>())
                {
                    game.GameDatabase.DestroyStation(game, stationInfo.ID, 0);
                }
            }
            game.GameDatabase.InsertCombatData(systemId, combatData.CombatID, combatData.Turn, combatData.ToByteArray());
        }