Ejemplo n.º 1
0
        public int SpawnPirateFleet(GameSession game, int targetSystem, int numShips)
        {
            Random random  = new Random();
            int    fleetID = game.GameDatabase.InsertFleet(this.PlayerID, 0, targetSystem, 0, "Pirate Raiders", FleetType.FL_NORMAL);
            Dictionary <LogicalWeapon, int> dictionary1 = new Dictionary <LogicalWeapon, int>();
            List <PlayerInfo> list1          = game.GameDatabase.GetStandardPlayerInfos().ToList <PlayerInfo>();
            List <PlayerInfo> playerInfoList = new List <PlayerInfo>();

            foreach (PlayerInfo playerInfo in list1)
            {
                Faction faction = game.AssetDatabase.GetFaction(playerInfo.FactionID);
                if (faction.Name != "liir_zuul" && faction.Name != "hiver" && faction.Name != "loa")
                {
                    playerInfoList.Add(playerInfo);
                }
                foreach (LogicalWeapon key in game.GameDatabase.GetAvailableWeapons(game.AssetDatabase, playerInfo.ID).ToList <LogicalWeapon>())
                {
                    if (!dictionary1.ContainsKey(key))
                    {
                        dictionary1.Add(key, 1);
                    }
                    else
                    {
                        Dictionary <LogicalWeapon, int> dictionary2;
                        LogicalWeapon index;
                        (dictionary2 = dictionary1)[index = key] = dictionary2[index] + 1;
                    }
                }
            }
            if (playerInfoList.Count > 0)
            {
                List <LogicalWeapon> availableWeapons = new List <LogicalWeapon>();
                foreach (LogicalWeapon logicalWeapon in game.AssetDatabase.Weapons.ToList <LogicalWeapon>())
                {
                    if (((IEnumerable <LogicalTurretClass>)logicalWeapon.TurretClasses).Count <LogicalTurretClass>() > 0 && WeaponEnums.IsBattleRider(logicalWeapon.DefaultWeaponClass))
                    {
                        availableWeapons.Add(logicalWeapon);
                    }
                }
                foreach (KeyValuePair <LogicalWeapon, int> keyValuePair in dictionary1)
                {
                    if (keyValuePair.Value > 1 && !availableWeapons.Contains(keyValuePair.Key))
                    {
                        availableWeapons.Add(keyValuePair.Key);
                    }
                }
                for (int index1 = 0; index1 < numShips + 1; ++index1)
                {
                    PlayerInfo playerInfo = random.Choose <PlayerInfo>((IList <PlayerInfo>)playerInfoList);
                    Faction    faction    = game.AssetDatabase.GetFaction(playerInfo.FactionID);
                    DesignInfo design1    = DesignLab.DesignShip(game, ShipClass.BattleRider, ShipRole.BOARDINGPOD, WeaponRole.PLANET_ATTACK, playerInfo.ID);
                    DesignInfo design2    = DesignLab.DesignShip(game, ShipClass.BattleRider, ShipRole.DRONE, WeaponRole.UNDEFINED, playerInfo.ID);
                    design1.PlayerID = this.PlayerID;
                    design2.PlayerID = this.PlayerID;
                    game.GameDatabase.InsertDesignByDesignInfo(design1);
                    game.GameDatabase.InsertDesignByDesignInfo(design2);
                    DesignInfo designInfo1;
                    if (index1 == 0)
                    {
                        DesignInfo designInfo2 = DesignLab.DesignShip(game, ShipClass.Cruiser, ShipRole.COMMAND, WeaponRole.UNDEFINED, playerInfo.ID);
                        designInfo1 = new DesignInfo(playerInfo.ID, "", new string[3]
                        {
                            ((IEnumerable <DesignSectionInfo>)designInfo2.DesignSections).First <DesignSectionInfo>((Func <DesignSectionInfo, bool>)(x => x.ShipSectionAsset.Type == ShipSectionType.Command)).FilePath,
                            ((IEnumerable <DesignSectionInfo>)designInfo2.DesignSections).First <DesignSectionInfo>((Func <DesignSectionInfo, bool>)(x => x.ShipSectionAsset.Type == ShipSectionType.Mission)).FilePath,
                            ((IEnumerable <DesignSectionInfo>)designInfo2.DesignSections).First <DesignSectionInfo>((Func <DesignSectionInfo, bool>)(x => x.ShipSectionAsset.Type == ShipSectionType.Engine)).FilePath
                        });
                    }
                    else
                    {
                        List <ShipSectionAsset> availableSections = game.GetAvailableShipSections(playerInfo.ID).ToList <ShipSectionAsset>();
                        List <string>           list2             = ((IEnumerable <string>)Pirates.availableCommandSections).ToList <string>();
                        List <string>           list3             = ((IEnumerable <string>)Pirates.availableMissionSections).ToList <string>();
                        List <string>           list4             = ((IEnumerable <string>)Pirates.availableEngineSections).ToList <string>();
                        for (int index2 = 0; index2 < list2.Count <string>(); ++index2)
                        {
                            list2[index2] = string.Format("factions\\{0}\\sections\\{1}", (object)faction.Name, (object)list2[index2]);
                        }
                        for (int index2 = 0; index2 < list3.Count <string>(); ++index2)
                        {
                            list3[index2] = string.Format("factions\\{0}\\sections\\{1}", (object)faction.Name, (object)list3[index2]);
                        }
                        for (int index2 = 0; index2 < list4.Count <string>(); ++index2)
                        {
                            list4[index2] = string.Format("factions\\{0}\\sections\\{1}", (object)faction.Name, (object)list4[index2]);
                        }
                        list2.RemoveAll((Predicate <string>)(x => !availableSections.Any <ShipSectionAsset>((Func <ShipSectionAsset, bool>)(y => y.FileName == x))));
                        list3.RemoveAll((Predicate <string>)(x => !availableSections.Any <ShipSectionAsset>((Func <ShipSectionAsset, bool>)(y => y.FileName == x))));
                        list4.RemoveAll((Predicate <string>)(x => !availableSections.Any <ShipSectionAsset>((Func <ShipSectionAsset, bool>)(y => y.FileName == x))));
                        designInfo1 = new DesignInfo(playerInfo.ID, "", new string[3]
                        {
                            random.Choose <string>((IList <string>)list2),
                            random.Choose <string>((IList <string>)list3),
                            random.Choose <string>((IList <string>)list4)
                        });
                    }
                    designInfo1.Name = DesignLab.GenerateDesignName(game.AssetDatabase, game.GameDatabase, (DesignInfo)null, designInfo1, DesignLab.NameGenerators.FactionRandom);
                    DesignLab.SummarizeDesign(game.AssetDatabase, game.GameDatabase, designInfo1);
                    DesignInfo design3 = DesignLab.AssignWeaponsToDesign(game, designInfo1, availableWeapons, this.PlayerId, WeaponRole.BRAWLER, (AITechStyles)null);
                    design3.PlayerID = this.PlayerID;
                    int designID  = game.GameDatabase.InsertDesignByDesignInfo(design3);
                    int carrierID = game.GameDatabase.InsertShip(fleetID, designID, null, (ShipParams)0, new int?(), 0);
                    game.AddDefaultStartingRiders(fleetID, designID, carrierID);
                }
            }
            return(fleetID);
        }