Ejemplo n.º 1
0
        protected override void UpdateSystem(
            StarMapSystem o,
            StarSystemInfo systemInfo,
            StarMapBase.SyncContext context)
        {
            int?systemProvinceId = this._db.GetStarSystemProvinceID(systemInfo.ID);

            o.SetProvince(systemProvinceId.HasValue ? this.Provinces.Reverse[systemProvinceId.Value] : (StarMapProvince)null);
            o.SetPosition(systemInfo.Origin);
            o.SetTerrain(systemInfo.TerrainID.HasValue ? this.Terrain.Reverse[systemInfo.TerrainID.Value] : (StarMapTerrain)null);
            IEnumerable <int> orbitalObjectIds = this._db.GetStarSystemOrbitalObjectIDs(systemInfo.ID);
            List <int>        source           = new List <int>();
            bool flag1 = false;
            List <StationInfo>    list1       = this._db.GetStationForSystem(systemInfo.ID).Where <StationInfo>((Func <StationInfo, bool>)(x => x.DesignInfo.StationType == StationType.NAVAL)).ToList <StationInfo>();
            Dictionary <int, int> dictionary1 = new Dictionary <int, int>();
            bool flag2 = false;

            foreach (int planetID in orbitalObjectIds)
            {
                AIColonyIntel ci = this._db.GetColonyIntelForPlanet(this._sim.LocalPlayer.ID, planetID);
                if (ci != null)
                {
                    if (!dictionary1.ContainsKey(ci.OwningPlayerID))
                    {
                        dictionary1.Add(ci.OwningPlayerID, 0);
                    }
                    Dictionary <int, int> dictionary2;
                    int owningPlayerId;
                    (dictionary2 = dictionary1)[owningPlayerId = ci.OwningPlayerID] = dictionary2[owningPlayerId] + 1;
                    if (ci.OwningPlayerID == this._sim.LocalPlayer.ID)
                    {
                        flag1 = true;
                    }
                    source.Add(ci.OwningPlayerID);
                    List <TreatyInfo> list2 = this._sim.GameDatabase.GetTreatyInfos().ToList <TreatyInfo>().Where <TreatyInfo>((Func <TreatyInfo, bool>)(x => x.Type == TreatyType.Trade)).ToList <TreatyInfo>();
                    if (flag1 || list2.Any <TreatyInfo>((Func <TreatyInfo, bool>)(x =>
                    {
                        if (x.InitiatingPlayerId == this._sim.LocalPlayer.ID && x.ReceivingPlayerId == ci.OwningPlayerID)
                        {
                            return(true);
                        }
                        if (x.ReceivingPlayerId == this._sim.LocalPlayer.ID)
                        {
                            return(x.InitiatingPlayerId == ci.OwningPlayerID);
                        }
                        return(false);
                    })))
                    {
                        flag2 = true;
                    }
                }
            }
            if (dictionary1.Count == 0)
            {
                foreach (StationInfo stationInfo in list1)
                {
                    if (stationInfo.PlayerID == this._sim.LocalPlayer.ID)
                    {
                        flag1 = true;
                    }
                }
            }
            if (flag1)
            {
                float supportRange = GameSession.GetSupportRange(this._db.AssetDatabase, this._db, this._sim.LocalPlayer.ID);
                o.SetSupportRange(supportRange);
            }
            int?systemOwningPlayer = this._db.GetSystemOwningPlayer(systemInfo.ID);

            if (systemOwningPlayer.HasValue && this._sim.GameDatabase.IsStarSystemVisibleToPlayer(this._sim.LocalPlayer.ID, systemInfo.ID) && StarMap.IsInRange(this._sim.GameDatabase, this._sim.LocalPlayer.ID, systemInfo.ID))
            {
                o.SetPlayerBadge(Path.GetFileNameWithoutExtension(this._db.GetPlayerInfo(systemOwningPlayer.Value).BadgeAssetPath));
                o.SetOwningPlayer(this._sim.GetPlayerObject(systemOwningPlayer.Value));
            }
            else
            {
                o.SetPlayerBadge("");
                o.SetOwningPlayer((Player)null);
            }
            source.Sort();
            o.SetPlayers(source.Select <int, Player>((Func <int, Player>)(playerId => this._sim.GetPlayerObject(playerId))).ToArray <Player>());
            List <PlayerInfo> playerInfos = context.PlayerInfos;
            List <Player>     playerList1 = new List <Player>();
            List <Player>     playerList2 = new List <Player>();

            foreach (PlayerInfo playerInfo in playerInfos)
            {
                if (this._db.SystemHasGate(systemInfo.ID, playerInfo.ID) && (playerInfo.ID == this._sim.LocalPlayer.ID || this._db.IsSurveyed(this._sim.LocalPlayer.ID, systemInfo.ID) && StarMap.IsInRange(this._db, playerInfo.ID, systemInfo.ID)))
                {
                    playerList1.Add(this._sim.GetPlayerObject(playerInfo.ID));
                }
                if (this._db.SystemHasAccelerator(systemInfo.ID, playerInfo.ID) && (playerInfo.ID == this._sim.LocalPlayer.ID || this._db.IsSurveyed(this._sim.LocalPlayer.ID, systemInfo.ID) && StarMap.IsInRange(this._db, playerInfo.ID, systemInfo.ID)))
                {
                    playerList2.Add(this._sim.GetPlayerObject(playerInfo.ID));
                }
                IEnumerable <StationInfo> forSystemAndPlayer = this._db.GetStationForSystemAndPlayer(systemInfo.ID, playerInfo.ID);
                if (playerInfo.ID == this._sim.LocalPlayer.ID)
                {
                    o.SetHasNavalStation(forSystemAndPlayer.Any <StationInfo>((Func <StationInfo, bool>)(x =>
                    {
                        if (x.PlayerID == this._sim.LocalPlayer.ID && x.DesignInfo.StationLevel > 0)
                        {
                            return(x.DesignInfo.StationType == StationType.NAVAL);
                        }
                        return(false);
                    })));
                    o.SetHasScienceStation(forSystemAndPlayer.Any <StationInfo>((Func <StationInfo, bool>)(x =>
                    {
                        if (x.PlayerID == this._sim.LocalPlayer.ID && x.DesignInfo.StationLevel > 0)
                        {
                            return(x.DesignInfo.StationType == StationType.SCIENCE);
                        }
                        return(false);
                    })));
                    o.SetHasTradeStation(forSystemAndPlayer.Any <StationInfo>((Func <StationInfo, bool>)(x =>
                    {
                        if (x.PlayerID == this._sim.LocalPlayer.ID && x.DesignInfo.StationLevel > 0)
                        {
                            return(x.DesignInfo.StationType == StationType.CIVILIAN);
                        }
                        return(false);
                    })));
                    o.SetHasDiploStation(forSystemAndPlayer.Any <StationInfo>((Func <StationInfo, bool>)(x =>
                    {
                        if (x.PlayerID == this._sim.LocalPlayer.ID && x.DesignInfo.StationLevel > 0)
                        {
                            return(x.DesignInfo.StationType == StationType.DIPLOMATIC);
                        }
                        return(false);
                    })));
                }
                o.SetStationCapacity(this._db.GetNumberMaxStationsSupportedBySystem(this._sim, systemInfo.ID, this._sim.LocalPlayer.ID));
                if (playerInfo.ID == this._sim.LocalPlayer.ID && systemOwningPlayer.HasValue)
                {
                    int cruiserEquivalent      = this._db.GetSystemSupportedCruiserEquivalent(this._sim, systemInfo.ID, playerInfo.ID);
                    int remainingSupportPoints = this._db.GetRemainingSupportPoints(this._sim, systemInfo.ID, playerInfo.ID);
                    if (systemOwningPlayer.Value == this._sim.LocalPlayer.ID)
                    {
                        o.SetNavalCapacity(cruiserEquivalent);
                        o.SetNavalUsage(cruiserEquivalent - remainingSupportPoints);
                    }
                    else
                    {
                        o.SetNavalCapacity(0);
                        o.SetNavalUsage(0);
                    }
                }
            }
            o.SetColonyTrapped(this._sim.GameDatabase.GetColonyTrapInfosAtSystem(systemInfo.ID).Where <ColonyTrapInfo>((Func <ColonyTrapInfo, bool>)(x =>
            {
                if (this._sim.GameDatabase.GetFleetInfo(x.FleetID) != null)
                {
                    return(this._sim.GameDatabase.GetFleetInfo(x.FleetID).PlayerID == this._sim.LocalPlayer.ID);
                }
                return(false);
            })).Any <ColonyTrapInfo>());
            o.SetPlayersWithGates(playerList1.ToArray());
            o.SetPlayersWithAccelerators(playerList2.ToArray());
            o.SetSensorRange(this._sim.GameDatabase.GetSystemStratSensorRange(systemInfo.ID, this._sim.LocalPlayer.ID));
            TradeResultsTable tradeResultsTable   = this._sim.GameDatabase.GetTradeResultsTable();
            TradeResultsTable resultsHistoryTable = this._sim.GameDatabase.GetLastTradeResultsHistoryTable();

            if (flag2 && tradeResultsTable.TradeNodes.ContainsKey(systemInfo.ID))
            {
                if (resultsHistoryTable.TradeNodes.ContainsKey(systemInfo.ID))
                {
                    o.SetTradeValues(this._sim, tradeResultsTable.TradeNodes[systemInfo.ID], resultsHistoryTable.TradeNodes[systemInfo.ID], systemInfo.ID);
                }
                else
                {
                    o.SetTradeValues(this._sim, tradeResultsTable.TradeNodes[systemInfo.ID], new TradeNode(), systemInfo.ID);
                }
            }
            else
            {
                o.SetTradeValues(this._sim, new TradeNode(), new TradeNode(), systemInfo.ID);
            }
            int exploredByPlayer = this._db.GetLastTurnExploredByPlayer(this._sim.LocalPlayer.ID, systemInfo.ID);
            int turnCount        = this._db.GetTurnCount();

            o.SetIsSurveyed(exploredByPlayer != 0);
            this.SetSystemHasBeenRecentlySurveyed(this.Systems.Reverse[systemInfo.ID], exploredByPlayer != 0 && turnCount - exploredByPlayer <= 5 && !flag1);
            this.SetSystemHasRecentCombat(this.Systems.Reverse[systemInfo.ID], this._sim.CombatData.GetFirstCombatInSystem(this._sim.GameDatabase, systemInfo.ID, this._sim.GameDatabase.GetTurnCount() - 1) != null);
            this.SetSystemIsMissionTarget(this.Systems.Reverse[systemInfo.ID], this._db.GetPlayerMissionInfosAtSystem(this._sim.LocalPlayer.ID, systemInfo.ID).Any <MissionInfo>(), this._db.GetPlayerInfo(this._sim.LocalPlayer.ID).PrimaryColor);
            bool flag3 = SuperNova.IsPlayerSystemsInSuperNovaEffectRanges(this._db, this._sim.LocalPlayer.ID, systemInfo.ID) || NeutronStar.IsPlayerSystemsInNeutronStarEffectRanges(this._sim, this._sim.LocalPlayer.ID, systemInfo.ID);

            this.SetSystemRequriesSuperNovaWarning(this.Systems.Reverse[systemInfo.ID], flag3);
            this.UpdateSystemTrade(systemInfo.ID);
            o.SetHasLoaGate(this._db.GetFleetInfoBySystemID(systemInfo.ID, FleetType.FL_ACCELERATOR).Any <FleetInfo>());
        }
Ejemplo n.º 2
0
        public void UpdateTurn(GameSession game)
        {
            foreach (FleetInfo fleetInfo in game.GameDatabase.GetFleetInfosByPlayerID(this.PlayerId, FleetType.FL_NORMAL).ToList <FleetInfo>())
            {
                game.GameDatabase.RemoveFleet(fleetInfo.ID);
            }
            foreach (DesignInfo designInfo in game.GameDatabase.GetDesignInfosForPlayer(this.PlayerId).ToList <DesignInfo>())
            {
                if (designInfo.ID != this.PirateBaseDesignId)
                {
                    game.GameDatabase.RemovePlayerDesign(designInfo.ID);
                }
            }
            List <PirateBaseInfo> pirateBases = game.GameDatabase.GetPirateBaseInfos().ToList <PirateBaseInfo>();

            foreach (PirateBaseInfo pbi in pirateBases)
            {
                if (game.GameDatabase.GetStationInfo(pbi.BaseStationId) == null)
                {
                    game.GameDatabase.RemoveEncounter(pbi.Id);
                }
                else
                {
                    --pbi.TurnsUntilAddShip;
                    if (pbi.TurnsUntilAddShip <= 0)
                    {
                        pbi.TurnsUntilAddShip = game.AssetDatabase.GlobalPiracyData.PiracyBaseTurnsPerUpdate;
                        pbi.NumShips          = Math.Min(pbi.NumShips + 1, game.AssetDatabase.GlobalPiracyData.PiracyTotalMaxShips);
                    }
                    game.GameDatabase.UpdatePirateBaseInfo(pbi);
                }
            }
            Random            safeRandom        = App.GetSafeRandom();
            float             piracyBaseOdds1   = game.AssetDatabase.GlobalPiracyData.PiracyBaseOdds;
            TradeResultsTable tradeResultsTable = game.GameDatabase.GetTradeResultsTable();
            List <PlayerInfo> list    = game.GameDatabase.GetStandardPlayerInfos().ToList <PlayerInfo>();
            List <int>        intList = new List <int>();

            foreach (PlayerInfo playerInfo in list)
            {
                if (game.AssetDatabase.GetFaction(playerInfo.FactionID).HasSlaves())
                {
                    IEnumerable <int> playerColonySystemIds = game.GameDatabase.GetPlayerColonySystemIDs(playerInfo.ID);
                    intList.AddRange(playerColonySystemIds);
                }
            }
            foreach (KeyValuePair <int, TradeNode> tradeNode in tradeResultsTable.TradeNodes)
            {
                float piracyBaseOdds2 = game.AssetDatabase.GlobalPiracyData.PiracyBaseOdds;
                int?  p = game.GameDatabase.GetSystemOwningPlayer(tradeNode.Key);
                if (p.HasValue && list.Any <PlayerInfo>((Func <PlayerInfo, bool>)(x => x.ID == p.Value)) && (tradeNode.Value.Freighters != 0 && !intList.Contains(tradeNode.Key)))
                {
                    Player playerObject = game.GetPlayerObject(p.Value);
                    if (playerObject == null || !playerObject.IsAI())
                    {
                        foreach (FleetInfo fleetInfo in game.GameDatabase.GetFleetInfoBySystemID(tradeNode.Key, FleetType.FL_DEFENSE).ToList <FleetInfo>())
                        {
                            foreach (ShipInfo shipInfo in game.GameDatabase.GetShipInfoByFleetID(fleetInfo.ID, false).ToList <ShipInfo>())
                            {
                                if (shipInfo.IsPoliceShip() && game.GameDatabase.GetShipSystemPosition(shipInfo.ID).HasValue)
                                {
                                    piracyBaseOdds2 += game.AssetDatabase.GlobalPiracyData.PiracyModPolice;
                                }
                            }
                        }
                        float val1 = game.AssetDatabase.GlobalPiracyData.PiracyModNoNavalBase;
                        foreach (StationInfo stationInfo in game.GameDatabase.GetStationForSystem(tradeNode.Key).ToList <StationInfo>())
                        {
                            if (stationInfo.DesignInfo.StationType == StationType.NAVAL)
                            {
                                val1 = Math.Min(val1, (float)stationInfo.DesignInfo.StationLevel * game.AssetDatabase.GlobalPiracyData.PiracyModNavalBase);
                            }
                        }
                        float   num1             = piracyBaseOdds2 + ((double)val1 < 0.0 ? val1 : game.AssetDatabase.GlobalPiracyData.PiracyModNoNavalBase);
                        Vector3 starSystemOrigin = game.GameDatabase.GetStarSystemOrigin(tradeNode.Key);
                        foreach (int systemId in intList)
                        {
                            if ((double)(game.GameDatabase.GetStarSystemOrigin(systemId) - starSystemOrigin).Length < (double)game.AssetDatabase.GlobalPiracyData.PiracyMinZuulProximity)
                            {
                                num1 += game.AssetDatabase.GlobalPiracyData.PiracyModZuulProximity;
                            }
                        }
                        if (game.GameDatabase.GetStarSystemInfo(tradeNode.Key).IsOpen)
                        {
                            num1 += 0.02f;
                        }
                        int num2 = 0;
                        if (pirateBases.Count > 0)
                        {
                            num2 = game.GameDatabase.GetSystemsInRange(starSystemOrigin, (float)game.AssetDatabase.GlobalPiracyData.PiracyBaseRange).ToList <StarSystemInfo>().Where <StarSystemInfo>((Func <StarSystemInfo, bool>)(x => pirateBases.Any <PirateBaseInfo>((Func <PirateBaseInfo, bool>)(y => y.SystemId == x.ID)))).Count <StarSystemInfo>();
                        }
                        if (num2 > 0)
                        {
                            num1 += game.AssetDatabase.GlobalPiracyData.PiracyBaseMod;
                        }
                        float num3 = num1 * game.GameDatabase.GetStratModifier <float>(StratModifiers.ChanceOfPirates, p.Value);
                        if (safeRandom.CoinToss((double)num3) || Pirates.ForceEncounter)
                        {
                            int num4     = (game.GameDatabase.GetStarSystemInfo(tradeNode.Key).ProvinceID.HasValue ? 0 : 1) + game.AssetDatabase.GlobalPiracyData.PiracyBaseShipBonus * num2;
                            int numShips = safeRandom.Next(game.AssetDatabase.GlobalPiracyData.PiracyMinShips + num4, game.AssetDatabase.GlobalPiracyData.PiracyMaxShips + num4 + 1);
                            this.SpawnPirateFleet(game, tradeNode.Key, numShips);
                        }
                    }
                }
            }
        }