Exemplo n.º 1
0
        public void AddInstance(GameDatabase gamedb, AssetDatabase assetdb, int?targetSystem = null)
        {
            Random safeRandom = App.GetSafeRandom();
            int    id;

            if (!targetSystem.HasValue)
            {
                List <KeyValuePair <StarSystemInfo, Vector3> > list  = EncounterTools.GetOutlyingStars(gamedb).ToList <KeyValuePair <StarSystemInfo, Vector3> >();
                List <KeyValuePair <StarSystemInfo, Vector3> > range = list.GetRange(0, (int)Math.Ceiling((double)list.Count / 3.0));
                if (range.Count == 0)
                {
                    return;
                }
                id = safeRandom.Choose <KeyValuePair <StarSystemInfo, Vector3> >((IList <KeyValuePair <StarSystemInfo, Vector3> >)range).Key.ID;
            }
            else
            {
                id = targetSystem.Value;
            }
            gamedb.InsertIncomingGM(id, EasterEgg.GM_LOCUST_SWARM, gamedb.GetTurnCount() + 1);
            foreach (PlayerInfo playerInfo in gamedb.GetStandardPlayerInfos().ToList <PlayerInfo>())
            {
                if (gamedb.GetStratModifier <int>(StratModifiers.GrandMenaceWarningTime, playerInfo.ID) > 0)
                {
                    gamedb.InsertTurnEvent(new TurnEvent()
                    {
                        EventType    = TurnEventType.EV_INCOMING_LOCUST,
                        EventMessage = TurnEventMessage.EM_INCOMING_LOCUST,
                        PlayerID     = playerInfo.ID,
                        TurnNumber   = gamedb.GetTurnCount()
                    });
                }
            }
        }
Exemplo n.º 2
0
        public void AddInstance(GameDatabase gamedb, AssetDatabase assetdb, int?targetSystem = null)
        {
            Random safeRandom = App.GetSafeRandom();
            List <KeyValuePair <StarSystemInfo, Vector3> > outlyingStars = EncounterTools.GetOutlyingStars(gamedb);
            StarSystemInfo starSystemInfo;

            if (targetSystem.HasValue)
            {
                starSystemInfo = gamedb.GetStarSystemInfo(targetSystem.Value);
            }
            else
            {
                int count = outlyingStars.Count / 3;
                if (count <= 0)
                {
                    return;
                }
                List <KeyValuePair <StarSystemInfo, Vector3> > range = outlyingStars.GetRange(0, count);
                starSystemInfo = safeRandom.Choose <KeyValuePair <StarSystemInfo, Vector3> >((IList <KeyValuePair <StarSystemInfo, Vector3> >)range).Key;
            }
            gamedb.InsertIncomingGM(starSystemInfo.ID, EasterEgg.GM_SYSTEM_KILLER, gamedb.GetTurnCount() + 1);
            foreach (PlayerInfo playerInfo in gamedb.GetStandardPlayerInfos().ToList <PlayerInfo>())
            {
                if (gamedb.GetStratModifier <int>(StratModifiers.GrandMenaceWarningTime, playerInfo.ID) > 0)
                {
                    gamedb.InsertTurnEvent(new TurnEvent()
                    {
                        EventType    = TurnEventType.EV_INCOMING_SYSTEMKILLER,
                        EventMessage = TurnEventMessage.EM_INCOMING_SYSTEMKILLER,
                        PlayerID     = playerInfo.ID,
                        TurnNumber   = gamedb.GetTurnCount()
                    });
                }
            }
        }
Exemplo n.º 3
0
        public void ExecuteInstance(GameDatabase gamedb, AssetDatabase assetdb, int systemid)
        {
            StarSystemInfo starSystemInfo1 = gamedb.GetStarSystemInfo(systemid);
            StarSystemInfo starSystemInfo2 = EncounterTools.GetClosestStars(gamedb, starSystemInfo1).Last <StarSystemInfo>();
            int            fleetID         = gamedb.InsertFleet(this.PlayerId, 0, 0, 0, "System Killer", FleetType.FL_NORMAL);

            gamedb.InsertShip(fleetID, this._systemKillerDesignId, null, (ShipParams)0, new int?(), 0);
            int missionID = gamedb.InsertMission(fleetID, MissionType.STRIKE, starSystemInfo1.ID, 0, 0, 0, false, new int?());

            gamedb.InsertWaypoint(missionID, WaypointType.TravelTo, new int?(starSystemInfo1.ID));
            gamedb.InsertMoveOrder(fleetID, 0, starSystemInfo1.Origin - Vector3.Normalize(starSystemInfo2.Origin - starSystemInfo1.Origin) * 10f, starSystemInfo1.ID, Vector3.Zero);
            gamedb.InsertSystemKillerInfo(new SystemKillerInfo()
            {
                Target  = starSystemInfo2.Origin,
                FleetId = new int?(fleetID)
            });
        }
Exemplo n.º 4
0
        public static VonNeumann InitializeEncounter(
            GameDatabase gamedb,
            AssetDatabase assetdb)
        {
            VonNeumann vonNeumann = new VonNeumann();

            vonNeumann.PlayerId = gamedb.InsertPlayer("Von Neumann", "vonneumann", new int?(), assetdb.RandomEncounterPrimaryColor, new Vector3(0.0f), "", "\\base\\factions\\vonneumann\\avatars\\Vonneumann_Avatar.tga", 0.0, 0, false, false, false, 0, AIDifficulty.Normal);
            foreach (KeyValuePair <VonNeumann.VonNeumannShipDesigns, VonNeumann.VonNeumannDesignInfo> keyValuePair in VonNeumann.StaticShipDesigns.ToList <KeyValuePair <VonNeumann.VonNeumannShipDesigns, VonNeumann.VonNeumannDesignInfo> >())
            {
                DesignInfo design = new DesignInfo(vonNeumann.PlayerId, keyValuePair.Key.ToString(), new string[1]
                {
                    string.Format("factions\\{0}\\sections\\{1}", (object)"vonneumann", (object)keyValuePair.Value.AssetName)
                });
                DesignLab.SummarizeDesign(assetdb, gamedb, design);
                VonNeumann.StaticShipDesigns[keyValuePair.Key] = new VonNeumann.VonNeumannDesignInfo()
                {
                    DesignId  = gamedb.InsertDesignByDesignInfo(design),
                    AssetName = keyValuePair.Value.AssetName
                };
            }
            vonNeumann._outlyingStars = EncounterTools.GetOutlyingStars(gamedb);
            return(vonNeumann);
        }
Exemplo n.º 5
0
        private int SetNextScoutTarget(
            GameSession game,
            LocustSwarmInfo info,
            StarSystemInfo currentSystem,
            LocustSwarmScoutInfo scout,
            List <int> scoutedSystems)
        {
            List <int>            previousTargets = game.GameDatabase.GetLocustSwarmTargets().ToList <int>();
            List <StarSystemInfo> closestStars    = EncounterTools.GetClosestStars(game.GameDatabase, currentSystem);

            closestStars.RemoveAll((Predicate <StarSystemInfo>)(x => previousTargets.Contains(x.ID)));
            closestStars.RemoveAll((Predicate <StarSystemInfo>)(x => scoutedSystems.Contains(x.ID)));
            if (closestStars.Count > 0)
            {
                scout.TargetSystemId = closestStars.First <StarSystemInfo>().ID;
                int num = game.GameDatabase.InsertFleet(this.PlayerId, 0, currentSystem.ID, currentSystem.ID, "Locust Swarm Scout", FleetType.FL_NORMAL);
                game.GameDatabase.TransferShip(scout.ShipId, num);
                int missionID = game.GameDatabase.InsertMission(num, MissionType.SURVEY, scout.TargetSystemId, 0, 0, 0, false, new int?());
                Kerberos.Sots.StarFleet.StarFleet.SetWaypointsForMission(game, MissionType.SURVEY, missionID, num, scout.TargetSystemId, 0, new int?(currentSystem.ID));
                game.GameDatabase.UpdateLocustSwarmScoutInfo(scout);
            }
            return(scout.TargetSystemId);
        }
Exemplo n.º 6
0
        public static List <KeyValuePair <StarSystemInfo, Vector3> > GetOutlyingStars(
            GameDatabase gamedb)
        {
            App.GetSafeRandom();
            float num1 = 10f;
            int   num2 = 20;
            List <StarSystemInfo> list1 = gamedb.GetStarSystemInfos().ToList <StarSystemInfo>();
            List <StarSystemInfo> list2 = list1.Where <StarSystemInfo>((Func <StarSystemInfo, bool>)(x => EncounterTools.IsSystemInhabited(gamedb, x.ID))).ToList <StarSystemInfo>();
            List <StarSystemInfo> starSystemInfoList = new List <StarSystemInfo>();
            int count = list1.Count;

            foreach (StarSystemInfo starSystemInfo in list1)
            {
                StarSystemInfo si = starSystemInfo;
                if (!list2.Contains(si) && (double)num1 < (double)list2.Min <StarSystemInfo>((Func <StarSystemInfo, float>)(x => (x.Origin - si.Origin).Length)))
                {
                    starSystemInfoList.Add(si);
                }
            }
            Dictionary <StarSystemInfo, Vector3> source = new Dictionary <StarSystemInfo, Vector3>();

            foreach (StarSystemInfo starSystemInfo in starSystemInfoList)
            {
                StarSystemInfo si = starSystemInfo;
                list1.Sort((Comparison <StarSystemInfo>)((x, y) => EncounterTools.DistanceBetween(x, si).CompareTo(EncounterTools.DistanceBetween(y, si))));
                Vector3 vector3 = new Vector3(0.0f);
                for (int index = 0; index < num2 && index < count; ++index)
                {
                    if (si != list1[index])
                    {
                        vector3 += Vector3.Normalize(si.Origin - list1[index].Origin);
                    }
                }
                source.Add(si, vector3);
            }
            return(source.OrderBy <KeyValuePair <StarSystemInfo, Vector3>, float>((Func <KeyValuePair <StarSystemInfo, Vector3>, float>)(x => - x.Value.Length)).ToList <KeyValuePair <StarSystemInfo, Vector3> >());
        }
Exemplo n.º 7
0
 public static List <StarSystemInfo> GetClosestStars(
     GameDatabase game,
     int SystemId)
 {
     return(EncounterTools.GetClosestStars(game, game.GetStarSystemInfo(SystemId)));
 }
Exemplo n.º 8
0
        public void UpdateTurn(GameSession game, int id)
        {
            SystemKillerInfo si        = game.GameDatabase.GetSystemKillerInfo(id);
            FleetInfo        fleetInfo = si.FleetId.HasValue ? game.GameDatabase.GetFleetInfo(si.FleetId.Value) : (FleetInfo)null;

            if (fleetInfo == null)
            {
                game.GameDatabase.RemoveEncounter(si.Id);
            }
            else
            {
                MissionInfo    missionByFleetId = game.GameDatabase.GetMissionByFleetID(fleetInfo.ID);
                StarSystemInfo systemInfo       = game.GameDatabase.GetStarSystemInfo(fleetInfo.SystemID);
                if (game.GameDatabase.GetMoveOrderInfoByFleetID(fleetInfo.ID) != null)
                {
                    return;
                }
                List <OrbitalObjectInfo> list = game.GameDatabase.GetStarSystemOrbitalObjectInfos(fleetInfo.SystemID).ToList <OrbitalObjectInfo>();
                list.RemoveAll((Predicate <OrbitalObjectInfo>)(x =>
                {
                    if (game.GameDatabase.GetAsteroidBeltInfo(x.ID) == null && game.GameDatabase.GetLargeAsteroidInfo(x.ID) == null)
                    {
                        return(game.GameDatabase.GetStationInfo(x.ID) != null);
                    }
                    return(true);
                }));
                if (list.Any <OrbitalObjectInfo>())
                {
                    if (game.isHostilesAtSystem(this.PlayerId, fleetInfo.SystemID))
                    {
                        return;
                    }
                    OrbitalObjectInfo orbitalObjectInfo = list.OrderBy <OrbitalObjectInfo, float>((Func <OrbitalObjectInfo, float>)(x => x.OrbitalPath.Scale.Length)).First <OrbitalObjectInfo>();
                    game.GameDatabase.InsertTurnEvent(new TurnEvent()
                    {
                        EventType    = TurnEventType.EV_PLANET_DESTROYED,
                        EventMessage = TurnEventMessage.EM_PLANET_DESTROYED,
                        PlayerID     = this.PlayerId,
                        SystemID     = orbitalObjectInfo.StarSystemID,
                        OrbitalID    = orbitalObjectInfo.ID,
                        TurnNumber   = game.GameDatabase.GetTurnCount(),
                        ShowsDialog  = false
                    });
                    game.GameDatabase.DestroyOrbitalObject(game, orbitalObjectInfo.ID);
                }
                else
                {
                    if (missionByFleetId != null)
                    {
                        game.GameDatabase.RemoveMission(missionByFleetId.ID);
                    }
                    List <StarSystemInfo> closestStars = EncounterTools.GetClosestStars(game.GameDatabase, fleetInfo.SystemID);
                    double         maxCos         = Math.Cos(Math.PI / 3.0);
                    StarSystemInfo starSystemInfo = closestStars.FirstOrDefault <StarSystemInfo>((Func <StarSystemInfo, bool>)(x => (double)Vector3.Dot(Vector3.Normalize(si.Target - systemInfo.Origin), Vector3.Normalize(x.Origin - systemInfo.Origin)) > maxCos));
                    if (starSystemInfo == (StarSystemInfo)null)
                    {
                        foreach (int standardPlayerId in game.GameDatabase.GetStandardPlayerIDs())
                        {
                            if (StarMap.IsInRange(game.GameDatabase, standardPlayerId, game.GameDatabase.GetFleetLocation(fleetInfo.ID, false).Coords, 1f, (Dictionary <int, List <ShipInfo> >)null))
                            {
                                game.GameDatabase.InsertTurnEvent(new TurnEvent()
                                {
                                    EventType    = TurnEventType.EV_SYS_KILLER_LEAVING,
                                    EventMessage = TurnEventMessage.EM_SYS_KILLER_LEAVING,
                                    PlayerID     = this.PlayerID,
                                    TurnNumber   = game.GameDatabase.GetTurnCount()
                                });
                            }
                        }
                        game.GameDatabase.RemoveFleet(fleetInfo.ID);
                        game.GameDatabase.RemoveEncounter(si.Id);
                    }
                    else
                    {
                        int missionID = game.GameDatabase.InsertMission(fleetInfo.ID, MissionType.STRIKE, starSystemInfo.ID, 0, 0, 0, false, new int?());
                        game.GameDatabase.InsertWaypoint(missionID, WaypointType.TravelTo, new int?(starSystemInfo.ID));
                        game.GameDatabase.InsertMoveOrder(fleetInfo.ID, 0, game.GameDatabase.GetStarSystemOrigin(fleetInfo.SystemID), starSystemInfo.ID, Vector3.Zero);
                        game.GameDatabase.UpdateFleetLocation(fleetInfo.ID, 0, new int?());
                    }
                    if (systemInfo != (StarSystemInfo)null)
                    {
                        game.GameDatabase.DestroyStarSystem(game, systemInfo.ID);
                    }
                    if (!(game.App.CurrentState is StarMapState))
                    {
                        return;
                    }
                    ((StarMapState)game.App.CurrentState).ClearSelectedObject();
                    ((StarMapState)game.App.CurrentState).RefreshStarmap(StarMapState.StarMapRefreshType.REFRESH_ALL);
                }
            }
        }
Exemplo n.º 9
0
        public void HandleGardenerCaptured(
            GameSession game,
            GameDatabase gamedb,
            int playerId,
            int gardenerId)
        {
            GardenerInfo gardenerInfo = gamedb.GetGardenerInfo(gardenerId);

            if (gardenerInfo == null)
            {
                return;
            }
            FleetInfo fleetInfo = gamedb.GetFleetInfo(gardenerInfo.FleetId);

            if (fleetInfo == null)
            {
                return;
            }
            if (gardenerInfo.DeepSpaceSystemId.HasValue)
            {
                foreach (StationInfo stationInfo in game.GameDatabase.GetStationForSystem(gardenerInfo.DeepSpaceSystemId.Value).ToList <StationInfo>())
                {
                    game.GameDatabase.DestroyStation(game, stationInfo.ID, 0);
                }
            }
            fleetInfo.PlayerID = playerId;
            gamedb.UpdateFleetInfo(fleetInfo);
            FleetLocation         fleetLocation   = gamedb.GetFleetLocation(fleetInfo.ID, false);
            List <StarSystemInfo> closestStars    = EncounterTools.GetClosestStars(gamedb, fleetLocation.Coords);
            StarSystemInfo        starSystemInfo1 = (StarSystemInfo)null;

            foreach (StarSystemInfo starSystemInfo2 in closestStars)
            {
                int?systemOwningPlayer = gamedb.GetSystemOwningPlayer(starSystemInfo2.ID);
                if (systemOwningPlayer.HasValue && systemOwningPlayer.Value == playerId)
                {
                    starSystemInfo1 = starSystemInfo2;
                    break;
                }
            }
            if (!(starSystemInfo1 != (StarSystemInfo)null))
            {
                return;
            }
            MissionInfo missionByFleetId = gamedb.GetMissionByFleetID(fleetInfo.ID);

            if (missionByFleetId != null)
            {
                gamedb.RemoveMission(missionByFleetId.ID);
            }
            MoveOrderInfo orderInfoByFleetId = gamedb.GetMoveOrderInfoByFleetID(fleetInfo.ID);

            if (orderInfoByFleetId != null)
            {
                gamedb.RemoveMoveOrder(orderInfoByFleetId.ID);
            }
            int missionID = gamedb.InsertMission(fleetInfo.ID, MissionType.RETURN, starSystemInfo1.ID, 0, 0, 0, false, new int?());

            gamedb.InsertWaypoint(missionID, WaypointType.TravelTo, new int?(starSystemInfo1.ID));
            gamedb.InsertMoveOrder(fleetInfo.ID, 0, fleetLocation.Coords, starSystemInfo1.ID, Vector3.Zero);
            this.SpawnProteanChaser(game, gardenerInfo);
        }
Exemplo n.º 10
0
        private bool SetNextWorldTarget(
            GameSession game,
            LocustSwarmInfo info,
            FleetInfo fleet,
            StarSystemInfo currentSystem)
        {
            List <int>            previousTargets = game.GameDatabase.GetLocustSwarmTargets().ToList <int>();
            List <StarSystemInfo> source          = new List <StarSystemInfo>();

            if (game.GameDatabase.HasEndOfFleshExpansion())
            {
                List <LocustSwarmScoutInfo> list = game.GameDatabase.GetLocustSwarmScoutsForLocustNest(info.Id).ToList <LocustSwarmScoutInfo>();
                if (list.Count > 0)
                {
                    bool flag1 = true;
                    foreach (LocustSwarmScoutInfo locustSwarmScoutInfo in list)
                    {
                        ShipInfo shipInfo = game.GameDatabase.GetShipInfo(locustSwarmScoutInfo.ShipId, false);
                        if (shipInfo != null)
                        {
                            int fleetId1 = shipInfo.FleetID;
                            int?fleetId2 = info.FleetId;
                            if ((fleetId1 != fleetId2.GetValueOrDefault() ? 1 : (!fleetId2.HasValue ? 1 : 0)) != 0)
                            {
                                flag1 = false;
                                break;
                            }
                        }
                    }
                    if (!flag1)
                    {
                        return(true);
                    }
                    bool flag2 = false;
                    List <StarSystemInfo> starSystemInfoList = new List <StarSystemInfo>();
                    foreach (LocustSwarmScoutTargetInfo swarmScoutTargetInfo in game.GameDatabase.GetLocustSwarmScoutTargetInfos().ToList <LocustSwarmScoutTargetInfo>())
                    {
                        if (swarmScoutTargetInfo.SystemId != currentSystem.ID)
                        {
                            flag2 = true;
                            int num = 0;
                            foreach (PlanetInfo planetInfo in ((IEnumerable <PlanetInfo>)game.GameDatabase.GetStarSystemPlanetInfos(swarmScoutTargetInfo.SystemId)).ToList <PlanetInfo>())
                            {
                                num += planetInfo.Resources;
                            }
                            if (num > 0)
                            {
                                StarSystemInfo starSystemInfo = game.GameDatabase.GetStarSystemInfo(swarmScoutTargetInfo.SystemId);
                                if (swarmScoutTargetInfo.IsHostile)
                                {
                                    starSystemInfoList.Add(starSystemInfo);
                                }
                                else
                                {
                                    source.Add(starSystemInfo);
                                }
                            }
                        }
                    }
                    if (!flag2)
                    {
                        source = EncounterTools.GetClosestStars(game.GameDatabase, currentSystem);
                    }
                    if (source.Count == 0)
                    {
                        source.AddRange((IEnumerable <StarSystemInfo>)starSystemInfoList);
                    }
                    source.OrderBy <StarSystemInfo, float>((Func <StarSystemInfo, float>)(x => (x.Origin - currentSystem.Origin).LengthSquared));
                }
                else
                {
                    source = EncounterTools.GetClosestStars(game.GameDatabase, currentSystem);
                }
            }
            else
            {
                source = EncounterTools.GetClosestStars(game.GameDatabase, currentSystem);
            }
            source.RemoveAll((Predicate <StarSystemInfo>)(x => previousTargets.Contains(x.ID)));
            if (source.Count <= 0)
            {
                return(false);
            }
            game.GameDatabase.InsertLocustSwarmTarget(info.Id, fleet.SystemID);
            int id        = source.First <StarSystemInfo>().ID;
            int missionID = game.GameDatabase.InsertMission(fleet.ID, MissionType.STRIKE, source.First <StarSystemInfo>().ID, 0, 0, 0, false, new int?());

            game.GameDatabase.InsertWaypoint(missionID, WaypointType.TravelTo, new int?(id));
            this.UpdateScoutedSystems(game, id);
            return(true);
        }