Esempio n. 1
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);
        }
Esempio n. 2
0
        public static VonNeumann ResumeEncounter(GameDatabase gamedb)
        {
            VonNeumann vonNeumann = new VonNeumann();
            PlayerInfo playerInfo = gamedb.GetPlayerInfos().ToList <PlayerInfo>().FirstOrDefault <PlayerInfo>((Func <PlayerInfo, bool>)(x =>
            {
                if (!x.isStandardPlayer)
                {
                    return(x.Name.Contains("Von Neumann"));
                }
                return(false);
            }));

            vonNeumann.PlayerId = playerInfo.ID;
            List <DesignInfo> list = gamedb.GetDesignInfosForPlayer(vonNeumann.PlayerId).ToList <DesignInfo>();

            foreach (KeyValuePair <VonNeumann.VonNeumannShipDesigns, VonNeumann.VonNeumannDesignInfo> keyValuePair in new Dictionary <VonNeumann.VonNeumannShipDesigns, VonNeumann.VonNeumannDesignInfo>((IDictionary <VonNeumann.VonNeumannShipDesigns, VonNeumann.VonNeumannDesignInfo>)VonNeumann.StaticShipDesigns))
            {
                KeyValuePair <VonNeumann.VonNeumannShipDesigns, VonNeumann.VonNeumannDesignInfo> kvp = keyValuePair;
                DesignInfo designInfo = list.FirstOrDefault <DesignInfo>((Func <DesignInfo, bool>)(x => x.DesignSections[0].FilePath.EndsWith(kvp.Value.AssetName)));
                if (designInfo != null)
                {
                    VonNeumann.StaticShipDesigns[kvp.Key].DesignId = designInfo.ID;
                }
            }
            FleetInfo fleetInfo = gamedb.GetFleetInfosByPlayerID(vonNeumann.PlayerID, FleetType.FL_NORMAL).ToList <FleetInfo>().FirstOrDefault <FleetInfo>((Func <FleetInfo, bool>)(x => x.Name == "Von Neumann NeoBerserker"));

            if (fleetInfo != null)
            {
                vonNeumann.HomeWorldSystemId = fleetInfo.SystemID;
                PlanetInfo planetInfo = gamedb.GetPlanetInfosOrbitingStar(fleetInfo.SystemID).ToList <PlanetInfo>().FirstOrDefault <PlanetInfo>();
                if (planetInfo != null)
                {
                    vonNeumann.HomeWorldPlanetId = planetInfo.ID;
                }
            }
            return(vonNeumann);
        }
Esempio n. 3
0
 public static Matrix GetBaseEnemyFleetTrans(App app, int systemID)
 {
     return(VonNeumann.GetSpawnTransform(app, systemID));
 }
Esempio n. 4
0
        public void SendCollector(GameSession game, ref VonNeumannInfo vi, bool forceHomeworldAttack = false)
        {
            List <FleetInfo>     list = game.GameDatabase.GetFleetInfosByPlayerID(this.PlayerId, FleetType.FL_NORMAL).ToList <FleetInfo>();
            VonNeumannGlobalData globalVonNeumannData = game.AssetDatabase.GlobalVonNeumannData;
            FleetInfo            fleetInfo            = VonNeumann.GetCollectorFleetInfo(list);

            if (fleetInfo == null)
            {
                DesignInfo designInfo = game.GameDatabase.GetDesignInfo(VonNeumann.StaticShipDesigns[VonNeumann.VonNeumannShipDesigns.CollectorMothership].DesignId);
                if ((double)vi.Resources > (double)designInfo.ProductionCost / (double)game.AssetDatabase.DefaultStratModifiers[StratModifiers.OverharvestModifier])
                {
                    vi.Resources -= (int)((double)designInfo.ProductionCost / (double)game.AssetDatabase.DefaultStratModifiers[StratModifiers.OverharvestModifier]);
                    vi.FleetId    = new int?(game.GameDatabase.InsertFleet(this.PlayerId, 0, vi.SystemId, vi.SystemId, "Von Neumann Collector", FleetType.FL_NORMAL));
                    game.GameDatabase.InsertShip(vi.FleetId.Value, VonNeumann.StaticShipDesigns[VonNeumann.VonNeumannShipDesigns.CollectorMothership].DesignId, null, (ShipParams)0, new int?(), 0);
                    fleetInfo = game.GameDatabase.GetFleetInfo(vi.FleetId.Value);
                }
                else
                {
                    vi.Resources = 0;
                    vi.FleetId   = new int?(game.GameDatabase.InsertFleet(this.PlayerId, 0, vi.SystemId, vi.SystemId, "Von Neumann Collector", FleetType.FL_NORMAL));
                    game.GameDatabase.InsertShip(vi.FleetId.Value, VonNeumann.StaticShipDesigns[VonNeumann.VonNeumannShipDesigns.CollectorMothership].DesignId, null, (ShipParams)0, new int?(), 0);
                    fleetInfo = game.GameDatabase.GetFleetInfo(vi.FleetId.Value);
                }
                int sysId = vi.LastCollectionSystem;
                if (!vi.TargetInfos.Any <VonNeumannTargetInfo>((Func <VonNeumannTargetInfo, bool>)(x => x.SystemId == sysId)) && sysId != 0)
                {
                    vi.TargetInfos.Add(new VonNeumannTargetInfo()
                    {
                        SystemId    = sysId,
                        ThreatLevel = 1
                    });
                }
            }
            else if (vi.LastCollectionSystem != 0)
            {
                foreach (int num1 in game.GameDatabase.GetStarSystemOrbitalObjectIDs(fleetInfo.SystemID).ToList <int>())
                {
                    PlanetInfo        planetInfo        = game.GameDatabase.GetPlanetInfo(num1);
                    LargeAsteroidInfo largeAsteroidInfo = game.GameDatabase.GetLargeAsteroidInfo(num1);
                    int num2 = globalVonNeumannData.SalvageCapacity - vi.ResourcesCollectedLastTurn;
                    if (planetInfo != null)
                    {
                        if (planetInfo.Resources > num2)
                        {
                            planetInfo.Resources         -= num2;
                            vi.ResourcesCollectedLastTurn = globalVonNeumannData.SalvageCapacity;
                            break;
                        }
                        vi.ResourcesCollectedLastTurn += planetInfo.Resources;
                        planetInfo.Resources           = 0;
                        game.GameDatabase.UpdatePlanet(planetInfo);
                    }
                    else if (largeAsteroidInfo != null)
                    {
                        if (largeAsteroidInfo.Resources > num2)
                        {
                            largeAsteroidInfo.Resources  -= num2;
                            vi.ResourcesCollectedLastTurn = globalVonNeumannData.SalvageCapacity;
                            break;
                        }
                        vi.ResourcesCollectedLastTurn += largeAsteroidInfo.Resources;
                        largeAsteroidInfo.Resources    = 0;
                        game.GameDatabase.UpdateLargeAsteroidInfo(largeAsteroidInfo);
                    }
                }
                vi.Resources      += vi.ResourcesCollectedLastTurn;
                fleetInfo.SystemID = vi.SystemId;
                game.GameDatabase.UpdateFleetLocation(fleetInfo.ID, fleetInfo.SystemID, new int?());
            }
            vi.LastCollectionSystem = 0;
            int turnCount = game.GameDatabase.GetTurnCount();

            if (fleetInfo == null || turnCount <= vi.LastCollectionTurn + globalVonNeumannData.SalvageCycle && !forceHomeworldAttack && !this.ForceVonNeumannAttackCycle)
            {
                return;
            }
            vi.LastCollectionTurn = turnCount;
            List <int> intList = new List <int>();

            foreach (int num in game.GameDatabase.GetStarSystemIDs().ToList <int>())
            {
                int system = num;
                if (!vi.TargetInfos.Any <VonNeumannTargetInfo>((Func <VonNeumannTargetInfo, bool>)(x => x.SystemId == system)))
                {
                    int?systemOwningPlayer = game.GameDatabase.GetSystemOwningPlayer(system);
                    if (systemOwningPlayer.HasValue)
                    {
                        Player playerObject = game.GetPlayerObject(systemOwningPlayer.Value);
                        if (playerObject == null || playerObject.IsAI())
                        {
                            continue;
                        }
                    }
                    intList.Add(system);
                }
            }
            if (intList.Count <= 0)
            {
                return;
            }
            fleetInfo.SystemID      = forceHomeworldAttack || this.ForceVonNeumannAttackCycle ? game.GameDatabase.GetOrbitalObjectInfo(game.GameDatabase.GetPlayerInfo(game.LocalPlayer.ID).Homeworld.Value).StarSystemID : intList[App.GetSafeRandom().Next(intList.Count)];
            vi.FleetId              = new int?(fleetInfo.ID);
            vi.LastCollectionSystem = fleetInfo.SystemID;
            game.GameDatabase.UpdateFleetLocation(fleetInfo.ID, fleetInfo.SystemID, new int?());
        }
Esempio n. 5
0
        private void ProcessTargets(GameSession game, ref VonNeumannInfo vi)
        {
            List <FleetInfo> list                  = game.GameDatabase.GetFleetInfosByPlayerID(this.PlayerId, FleetType.FL_NORMAL).ToList <FleetInfo>();
            FleetInfo        seekerFleetInfo       = VonNeumann.GetSeekerFleetInfo(list);
            FleetInfo        berserkerFleetInfo    = VonNeumann.GetBerserkerFleetInfo(list);
            FleetInfo        systemKillerFleetInfo = VonNeumann.GetSystemKillerFleetInfo(list);
            int lastTargetSystem = vi.LastTargetSystem;
            VonNeumannTargetInfo neumannTargetInfo1 = vi.TargetInfos.FirstOrDefault <VonNeumannTargetInfo>((Func <VonNeumannTargetInfo, bool>)(x => x.SystemId == lastTargetSystem));

            if (neumannTargetInfo1 != null)
            {
                FleetInfo fleetInfo = (FleetInfo)null;
                switch (neumannTargetInfo1.ThreatLevel)
                {
                case 1:
                    fleetInfo = seekerFleetInfo;
                    break;

                case 2:
                    fleetInfo = berserkerFleetInfo;
                    break;

                case 3:
                    fleetInfo = systemKillerFleetInfo;
                    break;
                }
                if (fleetInfo == null)
                {
                    if (neumannTargetInfo1.ThreatLevel < 3)
                    {
                        ++neumannTargetInfo1.ThreatLevel;
                    }
                }
                else
                {
                    vi.TargetInfos.Remove(neumannTargetInfo1);
                    game.GameDatabase.RemoveVonNeumannTargetInfo(vi.Id, neumannTargetInfo1.SystemId);
                    fleetInfo.SystemID = vi.SystemId;
                    game.GameDatabase.UpdateFleetLocation(fleetInfo.ID, fleetInfo.SystemID, new int?());
                    vi.FleetId = new int?(fleetInfo.ID);
                }
            }
            vi.LastTargetSystem = 0;
            int turnCount = game.GameDatabase.GetTurnCount();

            if (turnCount <= vi.LastTargetTurn + game.AssetDatabase.GlobalVonNeumannData.TargetCycle && !this.ForceVonNeumannAttackCycle)
            {
                return;
            }
            vi.LastTargetTurn = turnCount;
            VonNeumannTargetInfo neumannTargetInfo2 = vi.TargetInfos.FirstOrDefault <VonNeumannTargetInfo>();

            if (neumannTargetInfo2 == null)
            {
                return;
            }
            switch (neumannTargetInfo2.ThreatLevel)
            {
            case 1:
                if (seekerFleetInfo != null)
                {
                    seekerFleetInfo.SystemID = neumannTargetInfo2.SystemId;
                    vi.LastTargetSystem      = neumannTargetInfo2.SystemId;
                    game.GameDatabase.UpdateFleetLocation(seekerFleetInfo.ID, seekerFleetInfo.SystemID, new int?());
                    vi.FleetId = new int?(seekerFleetInfo.ID);
                    break;
                }
                if (vi.ProjectDesignId.HasValue)
                {
                    break;
                }
                vi.ProjectDesignId = new int?(VonNeumann.StaticShipDesigns[VonNeumann.VonNeumannShipDesigns.SeekerMothership].DesignId);
                break;

            case 2:
                if (berserkerFleetInfo != null)
                {
                    berserkerFleetInfo.SystemID = neumannTargetInfo2.SystemId;
                    vi.LastTargetSystem         = neumannTargetInfo2.SystemId;
                    game.GameDatabase.UpdateFleetLocation(berserkerFleetInfo.ID, berserkerFleetInfo.SystemID, new int?());
                    vi.FleetId = new int?(berserkerFleetInfo.ID);
                    break;
                }
                if (vi.ProjectDesignId.HasValue)
                {
                    break;
                }
                vi.ProjectDesignId = new int?(VonNeumann.StaticShipDesigns[VonNeumann.VonNeumannShipDesigns.BerserkerMothership].DesignId);
                break;

            case 3:
                if (systemKillerFleetInfo != null)
                {
                    systemKillerFleetInfo.SystemID = neumannTargetInfo2.SystemId;
                    vi.LastTargetSystem            = neumannTargetInfo2.SystemId;
                    game.GameDatabase.UpdateFleetLocation(systemKillerFleetInfo.ID, systemKillerFleetInfo.SystemID, new int?());
                    vi.FleetId = new int?(systemKillerFleetInfo.ID);
                    break;
                }
                if (vi.ProjectDesignId.HasValue)
                {
                    break;
                }
                vi.ProjectDesignId = new int?(VonNeumann.StaticShipDesigns[VonNeumann.VonNeumannShipDesigns.PlanetKiller].DesignId);
                break;
            }
        }