Esempio n. 1
0
        private static void SyncStationDetailsControl(
            GameSession game,
            string panelName,
            StationInfo station)
        {
            ShipSectionAsset shipSectionAsset = game.AssetDatabase.ShipSections.First <ShipSectionAsset>((Func <ShipSectionAsset, bool>)(x => x.FileName == station.DesignInfo.DesignSections[0].FilePath));
            int   crew                 = shipSectionAsset.Crew;
            float structure            = station.DesignInfo.Structure;
            int   stationUpkeepCost    = GameSession.CalculateStationUpkeepCost(game.GameDatabase, game.AssetDatabase, station);
            float tacticalSensorRange  = shipSectionAsset.TacticalSensorRange;
            float strategicSensorRange = shipSectionAsset.StrategicSensorRange;

            foreach (DesignModuleInfo module in station.DesignInfo.DesignSections[0].Modules)
            {
                DesignModuleInfo dmi           = module;
                LogicalModule    logicalModule = game.AssetDatabase.Modules.First <LogicalModule>((Func <LogicalModule, bool>)(x => x.ModulePath == game.GameDatabase.GetModuleAsset(dmi.ModuleID)));
                crew += logicalModule.Crew;
                tacticalSensorRange += logicalModule.SensorBonus;
            }
            string propertyValue1 = crew.ToString();
            string propertyValue2 = strategicSensorRange.ToString();
            string propertyValue3 = tacticalSensorRange.ToString();
            string propertyValue4 = stationUpkeepCost.ToString();
            string propertyValue5 = structure.ToString();

            game.UI.SetPropertyString(game.UI.Path(panelName, "popVal"), "text", propertyValue1);
            game.UI.SetPropertyString(game.UI.Path(panelName, "stratVal"), "text", propertyValue2);
            game.UI.SetPropertyString(game.UI.Path(panelName, "tactVal"), "text", propertyValue3);
            game.UI.SetPropertyString(game.UI.Path(panelName, "maintVal"), "text", propertyValue4);
            game.UI.SetPropertyString(game.UI.Path(panelName, "structVal"), "text", propertyValue5);
        }
Esempio n. 2
0
        private void AddTurretsToShipDummy(
            App game,
            string preferredMount,
            Faction faction,
            ShipSectionAsset section,
            ShipDummy.ShipDummyPart sectionPart,
            IEnumerable <WeaponAssignment> assignedWeapons,
            IEnumerable <LogicalWeapon> preferredWeapons,
            IEnumerable <LogicalWeapon> weapons,
            IEnumerable <LogicalTurretHousing> turretHousings,
            LogicalModule module,
            ShipDummy.ShipDummyPart modulePart,
            LogicalBank bank)
        {
            int                designID          = 0;
            int                targetFilter      = 0;
            int                fireMode          = 0;
            string             moduleNodeName    = modulePart != null ? modulePart.AttachedNodeName : "";
            LogicalWeapon      weapon            = ShipDummy.SelectWeapon(section, bank, assignedWeapons, preferredWeapons, weapons, moduleNodeName, out designID, out targetFilter, out fireMode);
            LogicalTurretClass weaponTurretClass = weapon.GetLogicalTurretClassForMount(bank.TurretSize, bank.TurretClass);

            if (weaponTurretClass == null)
            {
                App.Log.Warn(string.Format("Ship Dummy - did not find weapon turret class for: Bank Size [" + bank.TurretSize.ToString() + "], Bank Class [" + bank.TurretClass.ToString() + "] in section [" + section.FileName + "]"), "design");
            }
            else
            {
                LogicalTurretHousing housing = turretHousings.First <LogicalTurretHousing>((Func <LogicalTurretHousing, bool>)(housingCandidate =>
                {
                    if (weaponTurretClass.TurretClass == housingCandidate.Class && weapon.DefaultWeaponSize == housingCandidate.WeaponSize)
                    {
                        return(bank.TurretSize == housingCandidate.MountSize);
                    }
                    return(false);
                }));
                new MountObject.WeaponModels().FillOutModelFilesWithWeapon(weapon, faction, weapons);
                LogicalBank localBank = bank;
                foreach (LogicalMount mount in ((IEnumerable <LogicalMount>)section.Mounts).Where <LogicalMount>((Func <LogicalMount, bool>)(x => x.Bank == localBank)))
                {
                    string baseModel       = Ship.FixAssetNameForDLC(weaponTurretClass.GetBaseModel(faction, mount, housing), preferredMount);
                    string turretModelName = Ship.FixAssetNameForDLC(weaponTurretClass.GetTurretModelName(faction, mount, housing), preferredMount);
                    string barrelModelName = Ship.FixAssetNameForDLC(weaponTurretClass.GetBarrelModelName(faction, mount), preferredMount);
                    this.AddTurretModels(game, baseModel, turretModelName, barrelModelName, mount.NodeName, sectionPart);
                }
                if (modulePart == null || module == null)
                {
                    return;
                }
                foreach (LogicalMount mount in ((IEnumerable <LogicalMount>)module.Mounts).Where <LogicalMount>((Func <LogicalMount, bool>)(x => x.Bank == localBank)))
                {
                    string baseModel       = Ship.FixAssetNameForDLC(weaponTurretClass.GetBaseModel(faction, mount, housing), preferredMount);
                    string turretModelName = Ship.FixAssetNameForDLC(weaponTurretClass.GetTurretModelName(faction, mount, housing), preferredMount);
                    string barrelModelName = Ship.FixAssetNameForDLC(weaponTurretClass.GetBarrelModelName(faction, mount), preferredMount);
                    this.AddTurretModels(game, baseModel, turretModelName, barrelModelName, mount.NodeName, modulePart);
                }
            }
        }
Esempio n. 3
0
 public ModuleSelectorItem(UICommChannel ui, string id, LogicalModule module)
     : base(ui, id, "WeaponSelectorIcon")
 {
     if (module == null)
     {
         throw new ArgumentNullException(nameof(module));
     }
     this.Module = module;
     this._selectedOverlayImage = new Image(ui, this.UI.Path(id, "selectedOverlay"));
     this.SetSprite(module.Icon);
     this.UI.SetPostMouseOverEvents(this.ID, true);
 }
Esempio n. 4
0
        protected void SyncBuildQueue()
        {
            this.App.UI.ClearItems("moduleQue");
            StationInfo             si   = this.App.GameDatabase.GetStationInfo(this._selectedStation.OrbitalObjectID);
            List <DesignModuleInfo> list = this.App.GameDatabase.GetQueuedStationModules(si.DesignInfo.DesignSections[0]).ToList <DesignModuleInfo>();
            int num = 0;

            foreach (DesignModuleInfo designModuleInfo in list)
            {
                DesignModuleInfo module = designModuleInfo;
                this.App.UI.AddItem("moduleQue", "", module.ID, "");
                string itemGlobalId = this.App.UI.GetItemGlobalID("moduleQue", "", module.ID, "");
                StationModules.StationModule stationModule = ((IEnumerable <StationModules.StationModule>)StationModules.Modules).Where <StationModules.StationModule>((Func <StationModules.StationModule, bool>)(x =>
                {
                    ModuleEnums.StationModuleType smType            = x.SMType;
                    ModuleEnums.StationModuleType?stationModuleType = module.StationModuleType;
                    if (smType == stationModuleType.GetValueOrDefault())
                    {
                        return(stationModuleType.HasValue);
                    }
                    return(false);
                })).First <StationModules.StationModule>();
                StationModuleQueue.UpdateStationMapsForFaction(this.App.LocalPlayer.Faction.Name);
                LogicalModule logicalModule = this.App.AssetDatabase.Modules.First <LogicalModule>((Func <LogicalModule, bool>)(x => x.ModulePath == this.App.AssetDatabase.GetStationModuleAsset(module.StationModuleType.Value, StationModuleQueue.GetModuleFactionDefault(module.StationModuleType.Value, this.App.Game.GetPlayerObject(si.PlayerID).Faction))));
                num += logicalModule.SavingsCost;
                this.App.UI.SetPropertyString(this.App.UI.Path(itemGlobalId, "moduleName"), "text", stationModule.Name + " - $" + logicalModule.SavingsCost.ToString("N0"));
                this.App.UI.SetVisible(this.App.UI.Path(itemGlobalId, "deleteButton"), true);
                this.App.UI.SetPropertyString(this.App.UI.Path(itemGlobalId, "deleteButton"), "id", "modque|" + ((int)module.StationModuleType.Value).ToString());
                this.App.UI.SetPropertyColor(this.App.UI.Path(itemGlobalId, "moduleName"), "color", new Vector3((float)byte.MaxValue, (float)byte.MaxValue, (float)byte.MaxValue));
            }
            int userItemId = 999000;

            foreach (KeyValuePair <ModuleEnums.StationModuleType, int> keyValuePair in this._queuedItemMap.ToList <KeyValuePair <ModuleEnums.StationModuleType, int> >().Where <KeyValuePair <ModuleEnums.StationModuleType, int> >((Func <KeyValuePair <ModuleEnums.StationModuleType, int>, bool>)(x => x.Value > 0)))
            {
                KeyValuePair <ModuleEnums.StationModuleType, int> thing = keyValuePair;
                for (int index = 0; index < thing.Value; ++index)
                {
                    this.App.UI.AddItem("moduleQue", "", userItemId, "");
                    string itemGlobalId = this.App.UI.GetItemGlobalID("moduleQue", "", userItemId, "");
                    StationModules.StationModule stationModule = ((IEnumerable <StationModules.StationModule>)StationModules.Modules).Where <StationModules.StationModule>((Func <StationModules.StationModule, bool>)(x => x.SMType == thing.Key)).First <StationModules.StationModule>();
                    StationModuleQueue.UpdateStationMapsForFaction(this.App.LocalPlayer.Faction.Name);
                    LogicalModule logicalModule = this.App.AssetDatabase.Modules.First <LogicalModule>((Func <LogicalModule, bool>)(x => x.ModulePath == this.App.AssetDatabase.GetStationModuleAsset(thing.Key, StationModuleQueue.GetModuleFactionDefault(thing.Key, this.App.Game.GetPlayerObject(si.PlayerID).Faction))));
                    num += logicalModule.SavingsCost;
                    this.App.UI.SetPropertyString(this.App.UI.Path(itemGlobalId, "moduleName"), "text", stationModule.Name + " - $" + logicalModule.SavingsCost.ToString("N0"));
                    this.App.UI.SetPropertyColor(this.App.UI.Path(itemGlobalId, "moduleName"), "color", new Vector3((float)byte.MaxValue, 200f, 50f));
                    this.App.UI.SetVisible(this.App.UI.Path(itemGlobalId, "deleteButton"), false);
                    ++userItemId;
                }
            }
            this.App.UI.SetText("queueCost", "$" + num.ToString("N0"));
            this.App.UI.SetText("turnsToComplete", list.Count.ToString() + " " + App.Localize("@UI_GENERAL_TURNS"));
        }
Esempio n. 5
0
        public static void SyncSectionArmor(
            App game,
            string panelId,
            ShipSectionAsset sectionAsset,
            DesignInfo design)
        {
            string panelId1 = game.UI.Path(panelId, "partArmor");
            string panelId2 = game.UI.Path(panelId, "partArmorTop");
            string panelId3 = game.UI.Path(panelId, "partArmorBtm");
            string panelId4 = game.UI.Path(panelId, "partArmorSide");
            string panelId5 = game.UI.Path(panelId, "partStruct");
            string panelId6 = game.UI.Path(panelId, "partStructBar");
            int    num1     = 0;
            int    num2     = sectionAsset.Structure;

            if (design != null)
            {
                DesignSectionInfo designSectionInfo = ((IEnumerable <DesignSectionInfo>)design.DesignSections).FirstOrDefault <DesignSectionInfo>((Func <DesignSectionInfo, bool>)(x => x.FilePath == sectionAsset.FileName));
                List <string>     list = designSectionInfo.Techs.Select <int, string>((Func <int, string>)(x => game.GameDatabase.GetTechFileID(x))).ToList <string>();
                num1 = Ship.GetArmorBonusFromTech(game.AssetDatabase, list);
                num2 = Ship.GetStructureWithTech(game.AssetDatabase, list, num2);
                foreach (DesignModuleInfo module in designSectionInfo.Modules)
                {
                    string        moduleAsset   = game.GameDatabase.GetModuleAsset(module.ModuleID);
                    LogicalModule logicalModule = game.AssetDatabase.Modules.FirstOrDefault <LogicalModule>((Func <LogicalModule, bool>)(x => x.ModulePath == moduleAsset));
                    if (logicalModule != null)
                    {
                        num2 += (int)logicalModule.StructureBonus;
                    }
                }
            }
            int    propertyValue1 = sectionAsset.Armor[1].Y + num1;
            int    propertyValue2 = sectionAsset.Armor[3].Y + num1;
            int    propertyValue3 = Math.Max(sectionAsset.Armor[2].Y, sectionAsset.Armor[0].Y) + num1;
            int    num3           = sectionAsset.Armor[1].X * (sectionAsset.Armor[1].Y + num1) + sectionAsset.Armor[3].X * (sectionAsset.Armor[3].Y + num1) + sectionAsset.Armor[0].X * (sectionAsset.Armor[0].Y + num1) + sectionAsset.Armor[2].X * (sectionAsset.Armor[2].Y + num1);
            int    propertyValue4 = 10;
            int    propertyValue5 = 10000;
            string text1          = num3.ToString("N0");
            string text2          = num2.ToString("N0");

            game.UI.SetText(panelId1, text1);
            game.UI.SetPropertyInt(panelId2, "value", propertyValue1);
            game.UI.SetPropertyInt(panelId3, "value", propertyValue2);
            game.UI.SetPropertyInt(panelId4, "value", propertyValue3);
            game.UI.SetPropertyInt(panelId2, "max_value", propertyValue4);
            game.UI.SetPropertyInt(panelId3, "max_value", propertyValue4);
            game.UI.SetPropertyInt(panelId4, "max_value", propertyValue4);
            game.UI.SetText(panelId5, text2);
            game.UI.SetPropertyInt(panelId6, "value", num2);
            game.UI.SetPropertyInt(panelId6, "max_value", propertyValue5);
        }
Esempio n. 6
0
        private void UpdateStationDesignInfo(DesignInfo di)
        {
            int num = 0;

            foreach (DesignSectionInfo designSection in di.DesignSections)
            {
                DesignSectionInfo dsi = designSection;
                if (dsi.WeaponBanks != null)
                {
                    dsi.WeaponBanks.Clear();
                }
                ShipSectionAsset section = this.App.AssetDatabase.ShipSections.First <ShipSectionAsset>((Func <ShipSectionAsset, bool>)(x => x.FileName == dsi.FilePath));
                if (dsi.Modules != null)
                {
                    foreach (DesignModuleInfo module in dsi.Modules)
                    {
                        string        moduleass     = this.App.GameDatabase.GetModuleAsset(module.ModuleID);
                        LogicalModule logicalModule = this.App.AssetDatabase.Modules.First <LogicalModule>((Func <LogicalModule, bool>)(x => x.ModulePath == moduleass));
                        if (logicalModule != null && ((IEnumerable <LogicalBank>)logicalModule.Banks).Count <LogicalBank>() > 0)
                        {
                            int fireMode = 0;
                            ShipSectionAsset            shipSectionAsset = this._ship.DesignInfo.DesignSections[0].ShipSectionAsset;
                            IEnumerable <LogicalWeapon> preferredWeapons = LogicalWeapon.EnumerateWeaponFits(shipSectionAsset.Faction, shipSectionAsset.SectionName, this.App.GameDatabase.GetAvailableWeapons(this.App.AssetDatabase, this.App.LocalPlayer.ID).Where <LogicalWeapon>((Func <LogicalWeapon, bool>)(weapona => weapona.IsVisible)), logicalModule.Banks[0].TurretSize, logicalModule.Banks[0].TurretClass).Where <LogicalWeapon>((Func <LogicalWeapon, bool>)(x =>
                            {
                                if ((double)x.Range <= 1500.0)
                                {
                                    return(x.DefaultWeaponSize == WeaponEnums.WeaponSizes.VeryLight);
                                }
                                return(true);
                            }));
                            int           designID;
                            int           targetFilter;
                            LogicalWeapon logicalWeapon = Ship.SelectWeapon(section, logicalModule.Banks[0], (IEnumerable <WeaponAssignment>)null, preferredWeapons, this.App.GameDatabase.GetAvailableWeapons(this.App.AssetDatabase, this.App.LocalPlayer.ID), module.MountNodeName, out designID, out targetFilter, out fireMode);
                            int?          nullable      = new int?();
                            if (logicalWeapon != null && !module.WeaponID.HasValue)
                            {
                                nullable = this.App.GameDatabase.GetWeaponID(logicalWeapon.FileName, this.App.LocalPlayer.ID);
                            }
                            else if (module.WeaponID.HasValue)
                            {
                                nullable = module.WeaponID;
                            }
                            this.ModuleBankdict[module.ID] = module.MountNodeName;
                            ++num;
                            module.WeaponID = nullable;
                        }
                    }
                }
            }
        }
Esempio n. 7
0
 public void SetModule(LogicalModule primary)
 {
     if (primary == null)
     {
         return;
     }
     this.UI.SetPropertyString("moduleIcon", "sprite", primary.Icon);
     this.UI.SetVisible("moduleIcon", true);
     this.UI.SetText("moduleTitle", primary.ModuleTitle ?? string.Empty);
     this.UI.SetText("moduleAbility", primary.Description ?? string.Empty);
     this.UI.SetText("powerAttribute", primary.PowerBonus.ToString());
     this.UI.SetText("supplyAttribute", primary.Supply.ToString());
     this.UI.SetText("crewAttribute", primary.Crew.ToString());
     this.UI.SetText("structureValue", primary.Structure.ToString());
     this.UI.SetText("costDisplay.costValue", primary.SavingsCost.ToString());
 }
Esempio n. 8
0
        public int GetMinStructure(GameDatabase db, AssetDatabase ab)
        {
            int num = 0;

            if (this.Modules != null)
            {
                foreach (DesignModuleInfo module in this.Modules)
                {
                    string        mPath         = db.GetModuleAsset(module.ModuleID);
                    LogicalModule logicalModule = ab.Modules.FirstOrDefault <LogicalModule>((Func <LogicalModule, bool>)(x => x.ModulePath == mPath));
                    if (logicalModule != null)
                    {
                        num += (int)logicalModule.StructureBonus;
                    }
                }
                num = -num;
            }
            return(num);
        }
Esempio n. 9
0
 public void SetAvailableModules(
     IEnumerable <LogicalModule> modules,
     LogicalModule selected,
     bool enableSelection = true)
 {
     if (enableSelection)
     {
         this._page.DetachItems();
     }
     this.DisposeItems();
     this._items.Clear();
     foreach (ModuleSelectorItem moduleSelectorItem in modules.Select <LogicalModule, ModuleSelectorItem>((Func <LogicalModule, ModuleSelectorItem>)(module => new ModuleSelectorItem(this.UI, Guid.NewGuid().ToString(), module))))
     {
         this._items[moduleSelectorItem.ID] = moduleSelectorItem;
     }
     if (enableSelection)
     {
         ModuleSelectorItem moduleSelectorItem1 = new ModuleSelectorItem(this.UI, Guid.NewGuid().ToString(), new LogicalModule()
         {
             ModuleName  = App.Localize("@UI_MODULENAME_NO_MODULE"),
             ModuleTitle = App.Localize("@UI_MODULENAME_NO_MODULE"),
             Description = App.Localize("@UI_NO_MODULE_DESC"),
             Icon        = "moduleicon_no_selection"
         });
         this._items[moduleSelectorItem1.ID] = moduleSelectorItem1;
         bool flag = false;
         if (selected != null)
         {
             ModuleSelectorItem moduleSelectorItem2 = this._items.Values.FirstOrDefault <ModuleSelectorItem>((Func <ModuleSelectorItem, bool>)(x => x.Module == selected));
             if (moduleSelectorItem2 != null)
             {
                 this.HoverItem(moduleSelectorItem2);
                 flag = true;
             }
         }
         if (!flag)
         {
             this.HoverItem(moduleSelectorItem1);
         }
     }
     this._page.ReplaceItems((IEnumerable <ModuleSelectorItem>) this._items.Values, enableSelection);
 }
Esempio n. 10
0
        protected override void OnPanelMessage(string panelName, string msgType, string[] msgParams)
        {
            if (!(msgType == "button_clicked"))
            {
                return;
            }
            if (panelName == "cancelButton")
            {
                this._app.UI.CloseDialog((Dialog)this, true);
                this.HideWeaponSelector();
            }
            if (panelName == "okButton")
            {
                this.RetrofitShips();
                this._app.UI.CloseDialog((Dialog)this, true);
                this.HideWeaponSelector();
            }
            if (!this.BankDict.ContainsKey(panelName))
            {
                return;
            }
            this.SelectBank(this.BankDict[panelName]);
            string           asset            = this.App.GameDatabase.GetWeaponAsset(this._selectedModule.WeaponID.Value);
            LogicalWeapon    selected         = this.App.AssetDatabase.Weapons.First <LogicalWeapon>((Func <LogicalWeapon, bool>)(x => x.FileName == asset));
            ShipSectionAsset shipSectionAsset = this._ship.DesignInfo.DesignSections[0].ShipSectionAsset;
            string           moduleass        = this.App.GameDatabase.GetModuleAsset(this._selectedModule.ModuleID);
            LogicalModule    logicalModule    = this.App.AssetDatabase.Modules.First <LogicalModule>((Func <LogicalModule, bool>)(x => x.ModulePath == moduleass));

            this.PopulateWeaponSelector(LogicalWeapon.EnumerateWeaponFits(shipSectionAsset.Faction, shipSectionAsset.SectionName, this.App.GameDatabase.GetAvailableWeapons(this.App.AssetDatabase, this.App.LocalPlayer.ID).Where <LogicalWeapon>((Func <LogicalWeapon, bool>)(weapon => weapon.IsVisible)), logicalModule.Banks[0].TurretSize, logicalModule.Banks[0].TurretClass).Where <LogicalWeapon>((Func <LogicalWeapon, bool>)(x =>
            {
                if ((double)x.Range <= 1500.0)
                {
                    return(x.DefaultWeaponSize == WeaponEnums.WeaponSizes.VeryLight);
                }
                return(true);
            })).ToList <LogicalWeapon>(), selected);
            this.selecteditem = this.ItemIDDict[panelName];
        }
Esempio n. 11
0
 public void Dispose()
 {
     this._attachment = (LogicalModuleMount)null;
     this._module     = (LogicalModule)null;
     this._section    = (Section)null;
 }
Esempio n. 12
0
        private void SyncFleet()
        {
            FleetInfo fleetInfo = this.App.GameDatabase.GetFleetInfo(this._syncedFleet);

            if (fleetInfo == null)
            {
                return;
            }
            IEnumerable <ShipInfo> shipInfoByFleetId = this.App.GameDatabase.GetShipInfoByFleetID(fleetInfo.ID, true);
            List <object>          objectList        = new List <object>();
            int num1 = 0;

            foreach (ShipInfo shipInfo1 in shipInfoByFleetId)
            {
                ShipInfo ship  = shipInfo1;
                bool     flag1 = true;
                ++num1;
                objectList.Add((object)true);
                objectList.Add((object)ship.DesignID);
                objectList.Add((object)ship.ID);
                objectList.Add((object)ship.DesignInfo.Name);
                objectList.Add((object)ship.ShipName);
                bool          flag2              = false;
                string        str                = "";
                PlatformTypes?platformType       = ship.DesignInfo.GetPlatformType();
                bool          flag3              = false;
                bool          flag4              = ship.IsPoliceShip();
                int           defenseAssetCpCost = this.App.AssetDatabase.DefenseManagerSettings.GetDefenseAssetCPCost(ship.DesignInfo);
                if (ship.IsMinelayer())
                {
                    flag2 = true;
                    foreach (DesignSectionInfo designSection in ship.DesignInfo.DesignSections)
                    {
                        foreach (WeaponBankInfo weaponBank in designSection.WeaponBanks)
                        {
                            string wasset = this.App.GameDatabase.GetWeaponAsset(weaponBank.WeaponID.Value);
                            if (wasset.Contains("Min_"))
                            {
                                LogicalWeapon logicalWeapon = this.App.AssetDatabase.Weapons.FirstOrDefault <LogicalWeapon>((Func <LogicalWeapon, bool>)(x => x.FileName == wasset));
                                if (logicalWeapon != null)
                                {
                                    str = logicalWeapon.IconSpriteName;
                                    break;
                                }
                            }
                        }
                    }
                }
                else if (ship.IsSDB())
                {
                    flag3 = true;
                }
                else if (ship.IsPoliceShip())
                {
                    flag4 = true;
                }
                objectList.Add((object)flag2);
                objectList.Add((object)flag3);
                objectList.Add((object)str);
                objectList.Add(platformType.HasValue ? (object)platformType.Value.ToString() : (object)string.Empty);
                objectList.Add((object)flag4);
                if (defenseAssetCpCost == 0)
                {
                    objectList.Add((object)this.App.GameDatabase.GetShipCommandPointCost(ship.ID, true));
                }
                else
                {
                    objectList.Add((object)defenseAssetCpCost);
                }
                objectList.Add((object)this.App.GameDatabase.GetDesignCommandPointQuota(this.App.AssetDatabase, ship.DesignInfo.ID));
                objectList.Add((object)flag1);
                int num2 = 0;
                int num3 = 0;
                int num4 = 0;
                int num5 = 0;
                int num6 = 0;
                int num7 = 0;
                ShipSectionAsset           shipSectionAsset1 = (ShipSectionAsset)null;
                List <SectionInstanceInfo> list1             = this.App.GameDatabase.GetShipSectionInstances(ship.ID).ToList <SectionInstanceInfo>();
                if (list1.Count != ship.DesignInfo.DesignSections.Length)
                {
                    throw new InvalidDataException(string.Format("Mismatched design section vs ship section instance count for designId={0} and shipId={1}.", (object)ship.DesignInfo.ID, (object)ship.ID));
                }
                for (int i = 0; i < ((IEnumerable <DesignSectionInfo>)ship.DesignInfo.DesignSections).Count <DesignSectionInfo>(); ++i)
                {
                    if (list1.Count <= i)
                    {
                        App.Log.Warn("Tried syncing ship with no section", "game");
                    }
                    else
                    {
                        ShipSectionAsset shipSectionAsset2 = this.App.AssetDatabase.GetShipSectionAsset(ship.DesignInfo.DesignSections[i].FilePath);
                        if (shipSectionAsset2.Type == ShipSectionType.Mission)
                        {
                            shipSectionAsset1 = shipSectionAsset2;
                        }
                        SectionInstanceInfo sectionInstanceInfo = list1.First <SectionInstanceInfo>((Func <SectionInstanceInfo, bool>)(x => x.SectionID == ship.DesignInfo.DesignSections[i].ID));
                        num6 += shipSectionAsset2.ConstructionPoints;
                        num7 += shipSectionAsset2.ColonizationSpace;
                        num5 += shipSectionAsset2.Structure;
                        num3 += shipSectionAsset2.RepairPoints;
                        num4 += sectionInstanceInfo.Structure;
                        num2 += sectionInstanceInfo.RepairPoints;
                        Dictionary <ArmorSide, DamagePattern> armorInstances = this.App.GameDatabase.GetArmorInstances(sectionInstanceInfo.ID);
                        if (armorInstances.Count > 0)
                        {
                            for (int index = 0; index < 4; ++index)
                            {
                                num5 += armorInstances[(ArmorSide)index].Width * armorInstances[(ArmorSide)index].Height * 3;
                                for (int x = 0; x < armorInstances[(ArmorSide)index].Width; ++x)
                                {
                                    for (int y = 0; y < armorInstances[(ArmorSide)index].Height; ++y)
                                    {
                                        if (!armorInstances[(ArmorSide)index].GetValue(x, y))
                                        {
                                            num4 += 3;
                                        }
                                    }
                                }
                            }
                        }
                        List <ModuleInstanceInfo> list2  = this.App.GameDatabase.GetModuleInstances(sectionInstanceInfo.ID).ToList <ModuleInstanceInfo>();
                        List <DesignModuleInfo>   module = ship.DesignInfo.DesignSections[i].Modules;
                        for (int mod = 0; mod < module.Count; ++mod)
                        {
                            ModuleInstanceInfo moduleInstanceInfo = list2.First <ModuleInstanceInfo>((Func <ModuleInstanceInfo, bool>)(x => x.ModuleNodeID == module[mod].MountNodeName));
                            string             modAsset           = this.App.GameDatabase.GetModuleAsset(module[mod].ModuleID);
                            LogicalModule      logicalModule      = this.App.AssetDatabase.Modules.Where <LogicalModule>((Func <LogicalModule, bool>)(x => x.ModulePath == modAsset)).First <LogicalModule>();
                            num5 += (int)logicalModule.Structure;
                            num4 += moduleInstanceInfo.Structure;
                            num3 += logicalModule.RepairPointsBonus;
                            num2 += moduleInstanceInfo.RepairPoints;
                        }
                        foreach (WeaponInstanceInfo weaponInstanceInfo in this.App.GameDatabase.GetWeaponInstances(list1[i].ID).ToList <WeaponInstanceInfo>())
                        {
                            num5 += (int)weaponInstanceInfo.MaxStructure;
                            num4 += (int)weaponInstanceInfo.Structure;
                        }
                    }
                }
                objectList.Add((object)num4);
                objectList.Add((object)num5);
                objectList.Add((object)num2);
                objectList.Add((object)num3);
                objectList.Add((object)num6);
                objectList.Add((object)num7);
                IEnumerable <ShipInfo> ridersByParentId = this.App.GameDatabase.GetBattleRidersByParentID(ship.ID);
                objectList.Add((object)ridersByParentId.Count <ShipInfo>());
                foreach (ShipInfo shipInfo2 in ridersByParentId)
                {
                    objectList.Add((object)shipInfo2.ID);
                }
                objectList.Add((object)0);
                objectList.Add((object)shipSectionAsset1.RealClass);
                objectList.Add((object)shipSectionAsset1.BattleRiderType);
                Matrix?shipSystemPosition = this.App.GameDatabase.GetShipSystemPosition(ship.ID);
                objectList.Add((object)(shipSystemPosition.HasValue ? 1 : 0));
                if (shipSystemPosition.HasValue)
                {
                    objectList.Add((object)shipSystemPosition.Value);
                }
            }
            objectList.Insert(0, (object)num1);
            int systemDefensePoints = this.App.GameDatabase.GetSystemDefensePoints(fleetInfo.SystemID, this.App.LocalPlayer.ID);

            objectList.Insert(1, (object)systemDefensePoints);
            objectList.Insert(2, (object)fleetInfo.ID);
            this.PostSetProp("SyncShips", objectList.ToArray());
        }
Esempio n. 13
0
        public override void Initialize()
        {
            this.App.UI.HideTooltip();
            this.Allshiptog = false;
            DesignInfo newestRetrofitDesign = Kerberos.Sots.StarFleet.StarFleet.GetNewestRetrofitDesign(this._ship.DesignInfo, this.App.GameDatabase.GetVisibleDesignInfosForPlayer(this.App.LocalPlayer.ID));

            this.App.UI.SetText(this.App.UI.Path(this.ID, RetrofitShipDialog.currentnameID), this._ship.DesignInfo.Name);
            this.App.UI.SetText(this.App.UI.Path(this.ID, RetrofitShipDialog.retrofitnameID), newestRetrofitDesign.Name);
            this.App.UI.SetText(this.App.UI.Path(this.ID, RetrofitShipDialog.RetrofitCostID), Kerberos.Sots.StarFleet.StarFleet.CalculateRetrofitCost(this.App, this._ship.DesignInfo, newestRetrofitDesign).ToString());
            this.App.UI.SetText(this.App.UI.Path(this.ID, RetrofitShipDialog.RetrofitTimeID), Kerberos.Sots.StarFleet.StarFleet.GetTimeRequiredToRetrofit(this.App, this._ship, 1).ToString());
            this.App.GameDatabase.GetFleetInfo(this._ship.FleetID);
            List <ShipInfo> list    = this.App.GameDatabase.GetShipInfoByFleetID(this._ship.FleetID, false).ToList <ShipInfo>();
            List <int>      intList = new List <int>();

            foreach (ShipInfo shipInfo in list)
            {
                if (shipInfo.DesignID == this._ship.DesignID)
                {
                    intList.Add(shipInfo.ID);
                }
            }
            if (Kerberos.Sots.StarFleet.StarFleet.FleetCanFunctionWithoutShips(this.App, this._ship.FleetID, (IEnumerable <int>)intList))
            {
                this.App.UI.SetVisible(this.App.UI.Path(this.ID, "allships"), true);
            }
            else
            {
                this.App.UI.SetVisible(this.App.UI.Path(this.ID, "allships"), false);
            }
            if (this._weaponTooltip == null)
            {
                this._weaponTooltip = new WeaponHoverPanel(this.App.UI, this.App.UI.Path(this.ID, "WeaponPanel"), "weaponInfo");
            }
            if (this._moduleTooltip == null)
            {
                this._moduleTooltip = new ModuleHoverPanel(this.App.UI, this.App.UI.Path(this.ID, "WeaponPanel"), "moduleInfo");
            }
            List <LogicalWeapon> source1 = new List <LogicalWeapon>();

            foreach (DesignSectionInfo designSection in newestRetrofitDesign.DesignSections)
            {
                foreach (WeaponBankInfo weaponBank in (IEnumerable <WeaponBankInfo>)designSection.WeaponBanks)
                {
                    if (weaponBank.WeaponID.HasValue)
                    {
                        string        weaponPath = this.App.GameDatabase.GetWeaponAsset(weaponBank.WeaponID.Value);
                        LogicalWeapon weapon     = this.App.AssetDatabase.Weapons.First <LogicalWeapon>((Func <LogicalWeapon, bool>)(x => x.FileName == weaponPath));
                        if (weapon != null && source1.Where <LogicalWeapon>((Func <LogicalWeapon, bool>)(x => x.FileName == weapon.FileName)).Count <LogicalWeapon>() == 0)
                        {
                            source1.Add(weapon);
                        }
                    }
                }
            }
            this._weaponTooltip.SetAvailableWeapons((IEnumerable <LogicalWeapon>)source1, true);
            List <LogicalModule> source2 = new List <LogicalModule>();

            foreach (DesignSectionInfo designSection in newestRetrofitDesign.DesignSections)
            {
                foreach (DesignModuleInfo module1 in (IEnumerable <DesignModuleInfo>)designSection.Modules)
                {
                    string        modulePath = this.App.GameDatabase.GetModuleAsset(module1.ModuleID);
                    LogicalModule module     = this.App.AssetDatabase.Modules.First <LogicalModule>((Func <LogicalModule, bool>)(x => x.ModulePath == modulePath));
                    if (module != null && source2.Where <LogicalModule>((Func <LogicalModule, bool>)(x => x.ModulePath == module.ModulePath)).Count <LogicalModule>() == 0)
                    {
                        source2.Add(module);
                    }
                }
            }
            this._moduleTooltip.SetAvailableModules((IEnumerable <LogicalModule>)source2, (LogicalModule)null, false);
            DesignInfo designInfo = this._ship.DesignInfo;

            if (this._oldweaponTooltip == null)
            {
                this._oldweaponTooltip = new WeaponHoverPanel(this.App.UI, this.App.UI.Path(this.ID, "OldWeaponPanel"), "oldweaponInfo");
            }
            if (this._oldmoduleTooltip == null)
            {
                this._oldmoduleTooltip = new ModuleHoverPanel(this.App.UI, this.App.UI.Path(this.ID, "OldWeaponPanel"), "oldmoduleInfo");
            }
            List <LogicalWeapon> source3 = new List <LogicalWeapon>();

            foreach (DesignSectionInfo designSection in designInfo.DesignSections)
            {
                foreach (WeaponBankInfo weaponBank in (IEnumerable <WeaponBankInfo>)designSection.WeaponBanks)
                {
                    if (weaponBank.WeaponID.HasValue)
                    {
                        string        weaponPath = this.App.GameDatabase.GetWeaponAsset(weaponBank.WeaponID.Value);
                        LogicalWeapon weapon     = this.App.AssetDatabase.Weapons.First <LogicalWeapon>((Func <LogicalWeapon, bool>)(x => x.FileName == weaponPath));
                        if (weapon != null && source3.Where <LogicalWeapon>((Func <LogicalWeapon, bool>)(x => x.FileName == weapon.FileName)).Count <LogicalWeapon>() == 0)
                        {
                            source3.Add(weapon);
                        }
                    }
                }
            }
            this._oldweaponTooltip.SetAvailableWeapons((IEnumerable <LogicalWeapon>)source3, true);
            List <LogicalModule> source4 = new List <LogicalModule>();

            foreach (DesignSectionInfo designSection in designInfo.DesignSections)
            {
                foreach (DesignModuleInfo module1 in (IEnumerable <DesignModuleInfo>)designSection.Modules)
                {
                    string        modulePath = this.App.GameDatabase.GetModuleAsset(module1.ModuleID);
                    LogicalModule module     = this.App.AssetDatabase.Modules.First <LogicalModule>((Func <LogicalModule, bool>)(x => x.ModulePath == modulePath));
                    if (module != null && source4.Where <LogicalModule>((Func <LogicalModule, bool>)(x => x.ModulePath == module.ModulePath)).Count <LogicalModule>() == 0)
                    {
                        source4.Add(module);
                    }
                }
            }
            this._oldmoduleTooltip.SetAvailableModules((IEnumerable <LogicalModule>)source4, (LogicalModule)null, false);
        }
Esempio n. 14
0
        private Budget(
            GameDatabase gamedb,
            AssetDatabase assetdb,
            GameSession game,
            PlayerInfo playerInfo,
            FactionInfo playerFactionInfo,
            double maxDriveSpeed,
            double incomeFromTrade,
            SpendingCaps spendingCaps,
            IEnumerable <ColonyInfo> colonyInfos,
            Dictionary <int, PlanetInfo> planetInfos,
            Dictionary <int, OrbitalObjectInfo> orbitalObjectInfos,
            Dictionary <int, StarSystemInfo> starSystemInfos,
            HashSet <int> starSystemsWithGates,
            IEnumerable <StationInfo> stationInfos,
            IEnumerable <DesignInfo> reserveShipDesignInfos,
            IEnumerable <DesignInfo> shipDesignInfos,
            IEnumerable <DesignInfo> eliteShipDesignInfos,
            IEnumerable <DesignInfo> additionalShipDesignInfos)
        {
            this.CurrentSavings  = playerInfo.Savings;
            this.SavingsInterest = playerFactionInfo.Name != "loa" ? GameSession.CalculateSavingsInterest(game, playerInfo) : 0.0;
            this.DebtInterest    = playerFactionInfo.Name != "loa" ? GameSession.CalculateDebtInterest(game, playerInfo) : 0.0;
            this.TradeRevenue    = incomeFromTrade;
            this.TaxRevenue      = colonyInfos.Sum <ColonyInfo>((Func <ColonyInfo, double>)(x => Colony.GetTaxRevenue(game.App, playerInfo, x)));
            float num1 = gamedb.GetNameValue <float>("EconomicEfficiency") / 100f;

            this.TradeRevenue *= (double)num1;
            this.TradeRevenue *= (double)game.GameDatabase.GetStratModifierFloatToApply(StratModifiers.TradeRevenue, playerInfo.ID);
            this.TaxRevenue   *= (double)num1;
            Player playerObject1 = game.GetPlayerObject(playerInfo.ID);

            if (playerObject1 == null || !playerObject1.IsAI())
            {
                this.CurrentStationUpkeepExpenses = GameSession.CalculateStationUpkeepCosts(gamedb, assetdb, stationInfos);
                this.CurrentShipUpkeepExpenses    = GameSession.CalculateFleetUpkeepCosts(assetdb, reserveShipDesignInfos, shipDesignInfos, eliteShipDesignInfos);
                this.AdditionalUpkeepExpenses     = GameSession.CalculateShipUpkeepCosts(assetdb, additionalShipDesignInfos, 1f, false);
            }
            this.ColonySupportExpenses = colonyInfos.Sum <ColonyInfo>((Func <ColonyInfo, double>)(x =>
            {
                OrbitalObjectInfo orbitalObjectInfo = orbitalObjectInfos[x.OrbitalObjectID];
                PlanetInfo planetInfo         = planetInfos[x.OrbitalObjectID];
                StarSystemInfo starSystemInfo = starSystemInfos[orbitalObjectInfo.StarSystemID];
                return(Colony.GetColonySupportCost(gamedb, assetdb, playerInfo, playerFactionInfo, orbitalObjectInfos[x.OrbitalObjectID], planetInfos[x.OrbitalObjectID], starSystemInfos[orbitalObjectInfos[x.OrbitalObjectID].StarSystemID], orbitalObjectInfos, planetInfos, starSystemInfos, starSystemsWithGates.Contains(orbitalObjectInfos[x.OrbitalObjectID].StarSystemID), maxDriveSpeed));
            }));
            this.IORevenue = 0.0;
            List <int> list1         = gamedb.GetPlayerColonySystemIDs(playerInfo.ID).ToList <int>();
            int        num2          = list1.Where <int>((Func <int, bool>)(x => gamedb.GetStarSystemInfo(x).IsOpen)).Count <int>();
            Player     playerObject2 = game.GetPlayerObject(playerInfo.ID);
            float      num3          = 0.0f;

            foreach (int num4 in list1)
            {
                List <BuildOrderInfo> list2 = gamedb.GetBuildOrdersForSystem(num4).ToList <BuildOrderInfo>();
                float num5 = 0.0f;
                foreach (ColonyInfo colony in gamedb.GetColonyInfosForSystem(num4).ToList <ColonyInfo>())
                {
                    if (colony.PlayerID == playerInfo.ID)
                    {
                        num5 += Colony.GetConstructionPoints(game, colony);
                    }
                }
                float num6 = num5 * game.GetStationBuildModifierForSystem(num4, playerInfo.ID);
                foreach (BuildOrderInfo buildOrderInfo in list2)
                {
                    DesignInfo designInfo = gamedb.GetDesignInfo(buildOrderInfo.DesignID);
                    if (designInfo.PlayerID == playerInfo.ID)
                    {
                        int num7 = designInfo.SavingsCost;
                        if (designInfo.IsLoaCube())
                        {
                            num7 = buildOrderInfo.LoaCubes * assetdb.LoaCostPerCube;
                        }
                        int   num8 = buildOrderInfo.ProductionTarget - buildOrderInfo.Progress;
                        float num9 = 0.0f;
                        if (!designInfo.isPrototyped)
                        {
                            num9 = (float)(int)((double)num6 * ((double)gamedb.GetStratModifierFloatToApply(StratModifiers.PrototypeTimeModifier, playerInfo.ID) - 1.0));
                            switch (designInfo.Class)
                            {
                            case ShipClass.Cruiser:
                                num7 = (int)((double)designInfo.SavingsCost * (double)gamedb.GetStratModifierFloatToApply(StratModifiers.PrototypeSavingsCostModifierCR, playerInfo.ID));
                                break;

                            case ShipClass.Dreadnought:
                                num7 = (int)((double)designInfo.SavingsCost * (double)gamedb.GetStratModifierFloatToApply(StratModifiers.PrototypeSavingsCostModifierDN, playerInfo.ID));
                                break;

                            case ShipClass.Leviathan:
                                num7 = (int)((double)designInfo.SavingsCost * (double)gamedb.GetStratModifierFloatToApply(StratModifiers.PrototypeSavingsCostModifierLV, playerInfo.ID));
                                break;

                            case ShipClass.Station:
                                RealShipClasses?realShipClass = designInfo.GetRealShipClass();
                                if ((realShipClass.GetValueOrDefault() != RealShipClasses.Platform ? 0 : (realShipClass.HasValue ? 1 : 0)) != 0)
                                {
                                    num7 = (int)((double)designInfo.SavingsCost * (double)gamedb.GetStratModifierFloatToApply(StratModifiers.PrototypeSavingsCostModifierPF, playerInfo.ID));
                                    break;
                                }
                                break;
                            }
                        }
                        if (playerInfo.isStandardPlayer && playerObject2.IsAI() && playerObject2.Faction.Name == "loa")
                        {
                            num7 = (int)((double)num7 * 1.0);
                        }
                        if ((double)num8 <= (double)num6 - (double)num9)
                        {
                            num3 += (float)num7;
                            num6 -= (float)num8;
                        }
                        this.TotalBuildShipCosts += (double)num7;
                    }
                }
                this.IORevenue += (double)num6;
            }
            this.IORevenue            *= (double)game.GameDatabase.GetStratModifierFloatToApply(StratModifiers.IORevenue, playerInfo.ID);
            this.PendingBuildShipsCost = (double)num3;
            foreach (MissionInfo missionInfo in game.GameDatabase.GetMissionInfos().Where <MissionInfo>((Func <MissionInfo, bool>)(x => x.Type == MissionType.CONSTRUCT_STN)))
            {
                FleetInfo fleetInfo = game.GameDatabase.GetFleetInfo(missionInfo.FleetID);
                if (fleetInfo.PlayerID == playerInfo.ID)
                {
                    MissionEstimate missionEstimate = Kerberos.Sots.StarFleet.StarFleet.GetMissionEstimate(game, missionInfo.Type, (StationType)missionInfo.StationType.Value, fleetInfo.ID, missionInfo.TargetSystemID, missionInfo.TargetOrbitalObjectID, (List <int>)null, 1, false, new float?(), new float?());
                    this.TotalBuildStationsCost += (double)missionEstimate.ConstructionCost;
                    if (missionEstimate.TotalTurns - 1 - missionEstimate.TurnsToReturn <= 1)
                    {
                        this.PendingBuildStationsCost += (double)missionEstimate.ConstructionCost;
                    }
                }
            }
            foreach (MissionInfo missionInfo in game.GameDatabase.GetMissionInfos().Where <MissionInfo>((Func <MissionInfo, bool>)(x =>
            {
                if (x.Type == MissionType.UPGRADE_STN)
                {
                    return(x.Duration > 0);
                }
                return(false);
            })))
            {
                FleetInfo fleetInfo = game.GameDatabase.GetFleetInfo(missionInfo.FleetID);
                if (game.GameDatabase.GetStationInfo(missionInfo.TargetOrbitalObjectID) != null && fleetInfo.PlayerID == playerInfo.ID && game.GameDatabase.GetWaypointsByMissionID(missionInfo.ID).First <WaypointInfo>().Type != WaypointType.ReturnHome)
                {
                    StationInfo stationInfo = game.GameDatabase.GetStationInfo(missionInfo.TargetOrbitalObjectID);
                    if (stationInfo.DesignInfo.StationLevel + 1 <= 5)
                    {
                        MissionEstimate missionEstimate   = Kerberos.Sots.StarFleet.StarFleet.GetMissionEstimate(game, missionInfo.Type, stationInfo.DesignInfo.StationType, fleetInfo.ID, missionInfo.TargetSystemID, missionInfo.TargetOrbitalObjectID, (List <int>)null, stationInfo.DesignInfo.StationLevel + 1, false, new float?(), new float?());
                        DesignInfo      stationDesignInfo = DesignLab.CreateStationDesignInfo(game.AssetDatabase, game.GameDatabase, fleetInfo.PlayerID, stationInfo.DesignInfo.StationType, stationInfo.DesignInfo.StationLevel + 1, false);
                        this.TotalBuildStationsCost += (double)stationDesignInfo.SavingsCost;
                        if (missionEstimate.TotalTurns - 1 - missionEstimate.TurnsToReturn <= 1)
                        {
                            this.PendingBuildStationsCost += (double)stationDesignInfo.SavingsCost;
                        }
                    }
                }
            }
            foreach (StationInfo stationInfo in game.GameDatabase.GetStationInfosByPlayerID(playerInfo.ID))
            {
                List <DesignModuleInfo> queuedModules = game.GameDatabase.GetQueuedStationModules(stationInfo.DesignInfo.DesignSections[0]).ToList <DesignModuleInfo>();
                if (queuedModules.Count > 0)
                {
                    LogicalModule logicalModule1 = game.AssetDatabase.Modules.First <LogicalModule>((Func <LogicalModule, bool>)(x => x.ModulePath == game.GameDatabase.GetModuleAsset(queuedModules.First <DesignModuleInfo>().ModuleID)));
                    if (logicalModule1 != null)
                    {
                        this.PendingStationsModulesCost += (double)logicalModule1.SavingsCost;
                    }
                    foreach (DesignModuleInfo designModuleInfo in queuedModules)
                    {
                        DesignModuleInfo dmi            = designModuleInfo;
                        LogicalModule    logicalModule2 = game.AssetDatabase.Modules.First <LogicalModule>((Func <LogicalModule, bool>)(x => x.ModulePath == game.GameDatabase.GetModuleAsset(dmi.ModuleID)));
                        if (logicalModule2 != null)
                        {
                            this.TotalStationsModulesCost += (double)logicalModule2.SavingsCost;
                        }
                    }
                }
            }
            this.TotalRevenue     = this.TradeRevenue + this.TaxRevenue + this.IORevenue + this.SavingsInterest;
            this.RequiredSecurity = (int)Math.Ceiling(((double)num2 / (double)list1.Count != 0.0 ? ((double)assetdb.BaseCorruptionRate + 0.0199999995529652 * ((double)playerInfo.RateImmigration * 10.0)) / (2.0 * (double)playerInfo.RateGovernmentResearch) : 0.0) * 100.0);
            if (playerFactionInfo.Name == "loa")
            {
                this.RequiredSecurity = 0;
            }
            this.CorruptionExpenses = this.TotalRevenue * (double)Math.Max(0.0f, (float)(((double)assetdb.BaseCorruptionRate + 0.0199999995529652 * ((double)playerInfo.RateImmigration * 10.0) - 2.0 * ((double)playerInfo.RateGovernmentResearch * (double)playerInfo.RateGovernmentSecurity)) * ((double)num2 / (double)list1.Count)));
            if (playerFactionInfo.Name == "loa")
            {
                this.CorruptionExpenses = 0.0;
            }
            this.UpkeepExpenses              = this.CurrentShipUpkeepExpenses + this.CurrentStationUpkeepExpenses + this.AdditionalUpkeepExpenses;
            this.TotalExpenses               = this.UpkeepExpenses + this.ColonySupportExpenses + this.DebtInterest + this.CorruptionExpenses;
            this.OperatingBudget             = this.TotalRevenue - this.TotalExpenses;
            this.DisposableIncome            = Math.Max(this.OperatingBudget, 0.0);
            this.NetSavingsLoss              = Math.Max(-this.OperatingBudget, 0.0) + this.PendingBuildShipsCost + this.PendingBuildStationsCost + this.PendingStationsModulesCost;
            this.RequestedGovernmentSpending = this.DisposableIncome * (double)playerInfo.RateGovernmentResearch;
            SpendingPool pool = new SpendingPool();

            this.ResearchSpending            = new ResearchSpending(playerInfo, this.DisposableIncome - this.RequestedGovernmentSpending, pool, spendingCaps);
            this.SecuritySpending            = new SecuritySpending(playerInfo, this.RequestedGovernmentSpending * (double)playerInfo.RateGovernmentSecurity, pool, spendingCaps);
            this.StimulusSpending            = new StimulusSpending(playerInfo, this.RequestedGovernmentSpending * (double)playerInfo.RateGovernmentStimulus, pool, spendingCaps);
            this.ProjectedGovernmentSpending = this.SecuritySpending.ProjectedTotal + this.StimulusSpending.ProjectedTotal;
            this.UnspentIncome    = pool.Excess;
            this.NetSavingsIncome = this.DisposableIncome - this.ResearchSpending.RequestedTotal - this.SecuritySpending.RequestedTotal - this.StimulusSpending.RequestedTotal + this.UnspentIncome;
            this.ProjectedSavings = this.CurrentSavings + this.NetSavingsIncome - this.NetSavingsLoss;
        }
Esempio n. 15
0
        public static void Simulate(GameSession game, int systemId, List <FleetInfo> fleets)
        {
            if (ScriptHost.AllowConsole)
            {
                App.Log.Trace(string.Format("Simulating AI combat at: {0}", (object)systemId), "combat");
            }
            List <PlanetCombatInfo> planets = new List <PlanetCombatInfo>();

            PlanetInfo[] systemPlanetInfos = game.GameDatabase.GetStarSystemPlanetInfos(systemId);
            if (systemPlanetInfos != null)
            {
                foreach (PlanetInfo planetInfo in systemPlanetInfos)
                {
                    planets.Add(new PlanetCombatInfo()
                    {
                        planetInfo = planetInfo,
                        colonyInfo = game.GameDatabase.GetColonyInfoForPlanet(planetInfo.ID)
                    });
                }
            }
            Dictionary <FleetInfo, List <ShipCombatInfo> > shipCombatInfo = new Dictionary <FleetInfo, List <ShipCombatInfo> >();

            foreach (FleetInfo fleet in fleets)
            {
                List <ShipCombatInfo> shipCombatInfoList = new List <ShipCombatInfo>();
                foreach (ShipInfo shipInfo in game.GameDatabase.GetShipInfoByFleetID(fleet.ID, true).ToList <ShipInfo>())
                {
                    if (shipInfo.DesignInfo.Class != ShipClass.BattleRider)
                    {
                        ShipCombatInfo sci = new ShipCombatInfo();
                        sci.shipInfo = shipInfo;
                        float num = 1f;
                        if (shipInfo.DesignInfo.Class == ShipClass.Cruiser || shipInfo.DesignInfo.Class == ShipClass.Dreadnought)
                        {
                            num = 3f;
                        }
                        sci.armorFactor     = (float)shipInfo.DesignInfo.Armour / num;
                        sci.structureFactor = shipInfo.DesignInfo.Structure / num;
                        foreach (DesignSectionInfo designSection in shipInfo.DesignInfo.DesignSections)
                        {
                            ShipSectionAsset shipSectionAsset = game.AssetDatabase.GetShipSectionAsset(designSection.FilePath);
                            foreach (WeaponBankInfo weaponBank in designSection.WeaponBanks)
                            {
                                WeaponBankInfo wbi = weaponBank;
                                if (wbi.WeaponID.HasValue)
                                {
                                    string              weaponName = Path.GetFileNameWithoutExtension(game.GameDatabase.GetWeaponAsset(wbi.WeaponID.Value));
                                    LogicalWeapon       lw         = game.AssetDatabase.Weapons.FirstOrDefault <LogicalWeapon>((Func <LogicalWeapon, bool>)(weapon => string.Equals(weapon.WeaponName, weaponName, StringComparison.InvariantCultureIgnoreCase)));
                                    List <LogicalMount> list       = ((IEnumerable <LogicalMount>)shipSectionAsset.Mounts).Where <LogicalMount>((Func <LogicalMount, bool>)(x => x.Bank.GUID == wbi.BankGUID)).ToList <LogicalMount>();
                                    int totalMounts = list.Count <LogicalMount>() <= 0 ? 1 : list.Count <LogicalMount>();
                                    foreach (LogicalMount logicalMount in list)
                                    {
                                        switch (logicalMount.Bank.TurretClass)
                                        {
                                        case WeaponEnums.TurretClasses.Drone:
                                            ++sci.drones;
                                            continue;

                                        case WeaponEnums.TurretClasses.DestroyerRider:
                                        case WeaponEnums.TurretClasses.CruiserRider:
                                        case WeaponEnums.TurretClasses.DreadnoughtRider:
                                            ++sci.battleRiders;
                                            continue;

                                        default:
                                            CombatSimulator.ApplyWeaponStats(sci, lw, totalMounts);
                                            continue;
                                        }
                                    }
                                }
                            }
                            foreach (DesignModuleInfo module in designSection.Modules)
                            {
                                DesignModuleInfo mod           = module;
                                LogicalModule    logicalModule = game.AssetDatabase.Modules.First <LogicalModule>((Func <LogicalModule, bool>)(x => x.ModulePath == game.GameDatabase.GetModuleAsset(mod.ModuleID)));
                                if (logicalModule != null && mod.WeaponID.HasValue)
                                {
                                    foreach (LogicalBank bank in logicalModule.Banks)
                                    {
                                        LogicalBank         lb          = bank;
                                        string              weaponName2 = Path.GetFileNameWithoutExtension(game.GameDatabase.GetWeaponAsset(mod.WeaponID.Value));
                                        LogicalWeapon       lw          = game.AssetDatabase.Weapons.FirstOrDefault <LogicalWeapon>((Func <LogicalWeapon, bool>)(weapon => string.Equals(weapon.WeaponName, weaponName2, StringComparison.InvariantCultureIgnoreCase)));
                                        List <LogicalMount> list        = ((IEnumerable <LogicalMount>)shipSectionAsset.Mounts).Where <LogicalMount>((Func <LogicalMount, bool>)(x => x.Bank.GUID == lb.GUID)).ToList <LogicalMount>();
                                        int totalMounts = list.Count <LogicalMount>() <= 0 ? 1 : list.Count <LogicalMount>();
                                        foreach (LogicalMount logicalMount in list)
                                        {
                                            CombatSimulator.ApplyWeaponStats(sci, lw, totalMounts);
                                        }
                                    }
                                }
                            }
                        }
                        shipCombatInfoList.Add(sci);
                    }
                }
                shipCombatInfo.Add(fleet, shipCombatInfoList);
            }
            if (fleets.Count <FleetInfo>() > 1)
            {
                CombatSimulator.TrackingPhase(shipCombatInfo, 4f);
                CombatSimulator.DirectPhase(shipCombatInfo, 4f);
                CombatSimulator.TrackingPhase(shipCombatInfo, 1f);
                CombatSimulator.DirectPhase(shipCombatInfo, 2f);
                CombatSimulator.BombardmentPhase(game.GameDatabase, shipCombatInfo, planets, 1f);
            }
            else
            {
                CombatSimulator.BombardmentPhase(game.GameDatabase, shipCombatInfo, planets, 2f);
            }
            CombatSimulator.CompleteSimulation(game, systemId, shipCombatInfo, planets);
        }
Esempio n. 16
0
        private static IGameObject CreateShipCompound(
            App game,
            CombatConfig.DataContext context,
            XmlElement node)
        {
            XmlElement xmlElement1 = node["ShipName"];
            XmlElement xmlElement2 = node["ShipDesign"];
            XmlElement source1     = xmlElement2["Weapons"];
            XmlElement source2     = xmlElement2["Modules"];
            XmlElement xmlElement3 = xmlElement2["WeaponAssignments"];
            XmlElement xmlElement4 = xmlElement2["ModuleAssignments"];
            XmlElement source3     = xmlElement2["Sections"];
            List <WeaponAssignment> weaponAssignmentList = new List <WeaponAssignment>();
            List <ModuleAssignment> moduleAssignmentList = new List <ModuleAssignment>();
            List <ShipSectionAsset> sectionAssets        = new List <ShipSectionAsset>();
            List <LogicalModule>    logicalModuleList    = new List <LogicalModule>();

            if (source3 != null)
            {
                List <XmlElement> list = source3.OfType <XmlElement>().Where <XmlElement>((Func <XmlElement, bool>)(x => x.Name.Equals("Section", StringComparison.InvariantCulture))).ToList <XmlElement>();
                list.Select <XmlElement, string>((Func <XmlElement, string>)(x => x["SectionFile"].InnerText));
                foreach (XmlElement source4 in list)
                {
                    string           sectionFile      = source4["SectionFile"].InnerText;
                    ShipSectionAsset shipSectionAsset = game.AssetDatabase.ShipSections.FirstOrDefault <ShipSectionAsset>((Func <ShipSectionAsset, bool>)(x => x.FileName == sectionFile));
                    sectionAssets.Add(shipSectionAsset);
                    List <LogicalModule> source5 = new List <LogicalModule>();
                    foreach (XmlElement xmlElement5 in source4.OfType <XmlElement>().Where <XmlElement>((Func <XmlElement, bool>)(x => x.Name.Equals("Module", StringComparison.InvariantCulture))))
                    {
                        string        moduleNodeName = xmlElement5["Mount"].InnerText;
                        string        modulePath     = xmlElement5["ModuleId"].InnerText;
                        LogicalModule logicalModule  = game.AssetDatabase.Modules.First <LogicalModule>((Func <LogicalModule, bool>)(x => x.ModulePath == modulePath));
                        if (!source5.Contains(logicalModule))
                        {
                            source5.Add(logicalModule);
                        }
                        moduleAssignmentList.Add(new ModuleAssignment()
                        {
                            ModuleMount      = ((IEnumerable <LogicalModuleMount>)shipSectionAsset.Modules).First <LogicalModuleMount>((Func <LogicalModuleMount, bool>)(x => x.NodeName == moduleNodeName)),
                            Module           = logicalModule,
                            PsionicAbilities = (SectionEnumerations.PsionicAbility[])null
                        });
                    }
                    IEnumerable <LogicalBank> source6 = ((IEnumerable <LogicalBank>)shipSectionAsset.Banks).Concat <LogicalBank>(source5.SelectMany <LogicalModule, LogicalBank>((Func <LogicalModule, IEnumerable <LogicalBank> >)(x => (IEnumerable <LogicalBank>)x.Banks)));
                    foreach (XmlElement xmlElement5 in source4.OfType <XmlElement>().Where <XmlElement>((Func <XmlElement, bool>)(x => x.Name.Equals("Bank", StringComparison.InvariantCulture))))
                    {
                        Guid   bankGuid   = Guid.Parse(xmlElement5["Id"].InnerText);
                        string weaponName = xmlElement5["Weapon"].InnerText;
                        weaponAssignmentList.Add(new WeaponAssignment()
                        {
                            Bank   = source6.First <LogicalBank>((Func <LogicalBank, bool>)(x => x.GUID == bankGuid)),
                            Weapon = game.AssetDatabase.Weapons.First <LogicalWeapon>((Func <LogicalWeapon, bool>)(x => x.WeaponName == weaponName))
                        });
                    }
                }
            }
            IEnumerable <string> weapons = source1 == null ? (IEnumerable <string>) new string[0] : source1.OfType <XmlElement>().Where <XmlElement>((Func <XmlElement, bool>)(x => x.Name.Equals("string", StringComparison.InvariantCulture))).Select <XmlElement, string>((Func <XmlElement, string>)(x => x.InnerText));
            IEnumerable <string> modules = source2 == null ? (IEnumerable <string>) new string[0] : source2.OfType <XmlElement>().Where <XmlElement>((Func <XmlElement, bool>)(x => x.Name.Equals("string", StringComparison.InvariantCulture))).Select <XmlElement, string>((Func <XmlElement, string>)(x => x.InnerText));
            string str = xmlElement1 == null ? "USS Placeholder" : xmlElement1.InnerText;
            int    integerOrDefault = node["PlayerID"].ExtractIntegerOrDefault(0);
            Player player           = game.GetPlayer(integerOrDefault);
            Ship   ship             = Ship.CreateShip(game, new CreateShipParams()
            {
                player           = player,
                sections         = (IEnumerable <ShipSectionAsset>)sectionAssets,
                turretHousings   = game.AssetDatabase.TurretHousings,
                weapons          = game.AssetDatabase.Weapons,
                preferredWeapons = game.AssetDatabase.Weapons.Where <LogicalWeapon>((Func <LogicalWeapon, bool>)(x => weapons.Contains <string>(x.Name))),
                assignedWeapons  = (IEnumerable <WeaponAssignment>)weaponAssignmentList,
                modules          = game.AssetDatabase.Modules,
                preferredModules = game.AssetDatabase.Modules.Where <LogicalModule>((Func <LogicalModule, bool>)(x => modules.Contains <string>(x.ModuleName))),
                assignedModules  = (IEnumerable <ModuleAssignment>)moduleAssignmentList,
                psionics         = game.AssetDatabase.Psionics,
                faction          = game.AssetDatabase.Factions.First <Faction>((Func <Faction, bool>)(x => sectionAssets.First <ShipSectionAsset>().Faction == x.Name)),
                shipName         = str,
                inputID          = context.InputID
            });
            Vector3 vector3OrDefault1 = node["Position"].ExtractVector3OrDefault(Vector3.Zero);
            Vector3 vector3OrDefault2 = node["Rotation"].ExtractVector3OrDefault(Vector3.Zero);

            context.TransformPositionAndRotation(ref vector3OrDefault1, ref vector3OrDefault2);
            ship.Position = vector3OrDefault1;
            ship.Rotation = vector3OrDefault2;
            return((IGameObject)ship);
        }
Esempio n. 17
0
        public static IEnumerable <CarrierWingData> GetDesignBattleriderWingData(
            App App,
            DesignInfo des)
        {
            int num1 = 0;
            int num2 = 0;
            List <CarrierWingData> source = new List <CarrierWingData>();

            foreach (DesignSectionInfo designSection in des.DesignSections)
            {
                ShipSectionAsset shipSectionAsset = App.AssetDatabase.GetShipSectionAsset(designSection.FilePath);
                if (shipSectionAsset.Type == ShipSectionType.Mission)
                {
                    int battleRiderType = (int)shipSectionAsset.BattleRiderType;
                }
                num1 += RiderManager.GetNumRiderSlots(App, designSection);
                foreach (LogicalBank bank1 in shipSectionAsset.Banks)
                {
                    LogicalBank bank = bank1;
                    if (RiderManager.IsRiderBank(bank))
                    {
                        List <LogicalMount>       list       = ((IEnumerable <LogicalMount>)shipSectionAsset.Mounts).Where <LogicalMount>((Func <LogicalMount, bool>)(x => x.Bank == bank)).ToList <LogicalMount>();
                        WeaponEnums.TurretClasses mountClass = bank.TurretClass;
                        int count = list.Count;
                        int riderSlotsPerSquad = BattleRiderSquad.GetMinRiderSlotsPerSquad(mountClass, des.Class);
                        int numRidersPerSquad  = BattleRiderSquad.GetNumRidersPerSquad(mountClass, des.Class, Math.Max(count, riderSlotsPerSquad));
                        int num3 = numRidersPerSquad > count ? 1 : count / numRidersPerSquad;
                        for (int index1 = 0; index1 < num3; ++index1)
                        {
                            int        num4    = Math.Min(count, numRidersPerSquad);
                            List <int> intList = new List <int>();
                            for (int index2 = 0; index2 < num4; ++index2)
                            {
                                intList.Add(num2);
                                ++num2;
                            }
                            CarrierWingData carrierWingData = source.FirstOrDefault <CarrierWingData>((Func <CarrierWingData, bool>)(x =>
                            {
                                if (x.Class == mountClass)
                                {
                                    return(x.SlotIndexes.Count < numRidersPerSquad);
                                }
                                return(false);
                            }));
                            if (carrierWingData != null)
                            {
                                carrierWingData.SlotIndexes.AddRange((IEnumerable <int>)intList);
                            }
                            else
                            {
                                source.Add(new CarrierWingData()
                                {
                                    SlotIndexes = intList,
                                    Class       = mountClass
                                });
                            }
                        }
                    }
                    else if (WeaponEnums.IsWeaponBattleRider(bank.TurretClass))
                    {
                        num2 += ((IEnumerable <LogicalMount>)shipSectionAsset.Mounts).Count <LogicalMount>((Func <LogicalMount, bool>)(x => x.Bank == bank));
                    }
                }
                foreach (DesignModuleInfo module in designSection.Modules)
                {
                    string        path          = App.GameDatabase.GetModuleAsset(module.ModuleID);
                    LogicalModule logicalModule = App.AssetDatabase.Modules.FirstOrDefault <LogicalModule>((Func <LogicalModule, bool>)(x => x.ModulePath == path));
                    foreach (LogicalBank bank1 in logicalModule.Banks)
                    {
                        LogicalBank bank = bank1;
                        if (RiderManager.IsRiderBank(bank))
                        {
                            int        count   = ((IEnumerable <LogicalMount>)logicalModule.Mounts).Where <LogicalMount>((Func <LogicalMount, bool>)(x => x.Bank == bank)).ToList <LogicalMount>().Count;
                            List <int> intList = new List <int>();
                            for (int index = 0; index < count; ++index)
                            {
                                intList.Add(num2);
                                ++num2;
                            }
                            source.Add(new CarrierWingData()
                            {
                                SlotIndexes = intList,
                                Class       = bank.TurretClass,
                                DefaultType = logicalModule.AbilityType == ModuleEnums.ModuleAbilities.KingfisherRider ? BattleRiderTypes.scout : BattleRiderTypes.Unspecified
                            });
                        }
                        else if (WeaponEnums.IsWeaponBattleRider(bank.TurretClass))
                        {
                            num2 += ((IEnumerable <LogicalMount>)logicalModule.Mounts).Count <LogicalMount>((Func <LogicalMount, bool>)(x => x.Bank == bank));
                        }
                    }
                }
            }
            return((IEnumerable <CarrierWingData>)source);
        }
Esempio n. 18
0
        public ShipDummy(App game, CreateShipDummyParams dummyParams)
        {
            this.ShipID = dummyParams.ShipID;
            this._checkStatusBootstrapped = false;
            this._shipClass = dummyParams.Sections.First <ShipSectionAsset>().Class;
            ShipSectionAsset shipSectionAsset = dummyParams.Sections.FirstOrDefault <ShipSectionAsset>((Func <ShipSectionAsset, bool>)(x => x.Type == ShipSectionType.Mission));

            ShipDummy.ShipDummyPart shipDummyPart1 = new ShipDummy.ShipDummyPart();
            shipDummyPart1.Model     = game.AddObject <StaticModel>((object)Ship.FixAssetNameForDLC(shipSectionAsset.ModelName, dummyParams.PreferredMount));
            shipDummyPart1.IsSection = true;
            this._dummyParts.Add(shipDummyPart1);
            this._objects.Add((IGameObject)shipDummyPart1.Model);
            foreach (ShipSectionAsset section in dummyParams.Sections)
            {
                ShipDummy.ShipDummyPart sectionPart = shipDummyPart1;
                if (section != shipSectionAsset)
                {
                    ShipDummy.ShipDummyPart shipDummyPart2 = new ShipDummy.ShipDummyPart();
                    shipDummyPart2.Model            = game.AddObject <StaticModel>((object)Ship.FixAssetNameForDLC(section.ModelName, dummyParams.PreferredMount));
                    shipDummyPart2.AttachedModel    = (IGameObject)shipDummyPart1.Model;
                    shipDummyPart2.AttachedNodeName = section.Type.ToString();
                    shipDummyPart2.IsSection        = true;
                    this._dummyParts.Add(shipDummyPart2);
                    this._objects.Add((IGameObject)shipDummyPart2.Model);
                    sectionPart = shipDummyPart2;
                }
                for (int index = 0; index < section.Banks.Length; ++index)
                {
                    LogicalBank bank = section.Banks[index];
                    this.AddTurretsToShipDummy(game, dummyParams.PreferredMount, dummyParams.ShipFaction, section, sectionPart, dummyParams.AssignedWeapons, dummyParams.PreferredWeapons, game.AssetDatabase.Weapons, game.AssetDatabase.TurretHousings, (LogicalModule)null, (ShipDummy.ShipDummyPart)null, bank);
                }
                for (int sectionModuleMountIndex = 0; sectionModuleMountIndex < section.Modules.Length; ++sectionModuleMountIndex)
                {
                    LogicalModuleMount moduleMount = section.Modules[sectionModuleMountIndex];
                    if (dummyParams.AssignedModules != null)
                    {
                        LogicalModule    module           = (LogicalModule)null;
                        ModuleAssignment moduleAssignment = dummyParams.AssignedModules.FirstOrDefault <ModuleAssignment>((Func <ModuleAssignment, bool>)(x => x.ModuleMount == moduleMount));
                        if (moduleAssignment != null)
                        {
                            module = moduleAssignment.Module;
                        }
                        if (module == null)
                        {
                            module = LogicalModule.EnumerateModuleFits(dummyParams.PreferredModules, section, sectionModuleMountIndex, false).FirstOrDefault <LogicalModule>();
                        }
                        if (module != null)
                        {
                            ShipDummy.ShipDummyPart modulePart = new ShipDummy.ShipDummyPart();
                            modulePart.Model            = game.AddObject <StaticModel>((object)module.ModelPath);
                            modulePart.AttachedModel    = (IGameObject)sectionPart.Model;
                            modulePart.AttachedNodeName = moduleMount.NodeName;
                            this._dummyParts.Add(modulePart);
                            this._objects.Add((IGameObject)modulePart.Model);
                            for (int index = 0; index < module.Banks.Length; ++index)
                            {
                                LogicalBank bank = module.Banks[index];
                                this.AddTurretsToShipDummy(game, dummyParams.PreferredMount, dummyParams.ShipFaction, section, sectionPart, dummyParams.AssignedWeapons, dummyParams.PreferredWeapons, game.AssetDatabase.Weapons, game.AssetDatabase.TurretHousings, module, modulePart, bank);
                            }
                        }
                    }
                }
            }
            this._objects.Add((IGameObject)game.AddObject <RigidBody>((object)1f, (object)false));
        }
Esempio n. 19
0
        public static CreateShipDummyParams ObtainShipDummyParams(
            App game,
            ShipInfo shipInfo)
        {
            IEnumerable <string>    modules              = game.AssetDatabase.Modules.Select <LogicalModule, string>((Func <LogicalModule, string>)(x => x.ModuleName));
            IEnumerable <string>    weapons              = game.AssetDatabase.Weapons.Select <LogicalWeapon, string>((Func <LogicalWeapon, string>)(x => x.Name));
            DesignInfo              designInfo           = shipInfo.DesignInfo;
            List <ShipSectionAsset> shipSectionAssetList = new List <ShipSectionAsset>();
            List <ModuleAssignment> moduleAssignmentList = new List <ModuleAssignment>();
            List <WeaponAssignment> weaponAssignmentList = new List <WeaponAssignment>();

            foreach (DesignSectionInfo designSection in designInfo.DesignSections)
            {
                DesignSectionInfo sectionInfo      = designSection;
                ShipSectionAsset  shipSectionAsset = game.AssetDatabase.ShipSections.First <ShipSectionAsset>((Func <ShipSectionAsset, bool>)(x => x.FileName == sectionInfo.FilePath));
                shipSectionAssetList.Add(shipSectionAsset);
                foreach (LogicalBank bank1 in shipSectionAsset.Banks)
                {
                    LogicalBank    bank           = bank1;
                    WeaponBankInfo weaponBankInfo = sectionInfo.WeaponBanks.FirstOrDefault <WeaponBankInfo>((Func <WeaponBankInfo, bool>)(x => x.BankGUID == bank.GUID));
                    bool           flag           = false;
                    if (weaponBankInfo != null && weaponBankInfo.WeaponID.HasValue)
                    {
                        string           weaponName       = Path.GetFileNameWithoutExtension(game.GameDatabase.GetWeaponAsset(weaponBankInfo.WeaponID.Value));
                        WeaponAssignment weaponAssignment = new WeaponAssignment()
                        {
                            ModuleNode          = "",
                            Bank                = bank,
                            Weapon              = game.AssetDatabase.Weapons.First <LogicalWeapon>((Func <LogicalWeapon, bool>)(weapon => string.Equals(weapon.WeaponName, weaponName, StringComparison.InvariantCultureIgnoreCase))),
                            DesignID            = weaponBankInfo == null || !weaponBankInfo.DesignID.HasValue ? 0 : weaponBankInfo.DesignID.Value,
                            InitialTargetFilter = new int?(weaponBankInfo.FilterMode ?? 0),
                            InitialFireMode     = new int?(weaponBankInfo.FiringMode ?? 0)
                        };
                        weaponAssignmentList.Add(weaponAssignment);
                        flag = true;
                    }
                    if (!flag && !string.IsNullOrEmpty(bank.DefaultWeaponName))
                    {
                        WeaponAssignment weaponAssignment = new WeaponAssignment()
                        {
                            ModuleNode = "",
                            Bank       = bank,
                            Weapon     = game.AssetDatabase.Weapons.First <LogicalWeapon>((Func <LogicalWeapon, bool>)(weapon => string.Equals(weapon.WeaponName, bank.DefaultWeaponName, StringComparison.InvariantCultureIgnoreCase))),
                            DesignID   = weaponBankInfo == null || !weaponBankInfo.DesignID.HasValue ? 0 : weaponBankInfo.DesignID.Value
                        };
                        weaponAssignmentList.Add(weaponAssignment);
                    }
                }
                foreach (LogicalModuleMount module in shipSectionAsset.Modules)
                {
                    LogicalModuleMount sectionModule    = module;
                    DesignModuleInfo   designModuleInfo = sectionInfo.Modules.FirstOrDefault <DesignModuleInfo>((Func <DesignModuleInfo, bool>)(x => x.MountNodeName == sectionModule.NodeName));
                    if (designModuleInfo != null)
                    {
                        string        path          = game.GameDatabase.GetModuleAsset(designModuleInfo.ModuleID);
                        LogicalModule logicalModule = game.AssetDatabase.Modules.FirstOrDefault <LogicalModule>((Func <LogicalModule, bool>)(x => x.ModulePath == path));
                        moduleAssignmentList.Add(new ModuleAssignment()
                        {
                            ModuleMount = sectionModule,
                            Module      = logicalModule
                        });
                        if (designModuleInfo.WeaponID.HasValue)
                        {
                            string           weaponPath       = game.GameDatabase.GetWeaponAsset(designModuleInfo.WeaponID.Value);
                            WeaponAssignment weaponAssignment = new WeaponAssignment()
                            {
                                ModuleNode = designModuleInfo.MountNodeName,
                                Bank       = logicalModule.Banks[0],
                                Weapon     = game.AssetDatabase.Weapons.First <LogicalWeapon>((Func <LogicalWeapon, bool>)(x => x.FileName == weaponPath)),
                                DesignID   = 0
                            };
                            weaponAssignmentList.Add(weaponAssignment);
                        }
                    }
                }
            }
            ShipSectionAsset missionSection = shipSectionAssetList.FirstOrDefault <ShipSectionAsset>((Func <ShipSectionAsset, bool>)(x => x.Type == ShipSectionType.Mission));
            Faction          faction        = game.AssetDatabase.Factions.First <Faction>((Func <Faction, bool>)(x => missionSection.Faction == x.Name));
            Player           playerObject   = game.Game.GetPlayerObject(designInfo.PlayerID);
            Subfaction       subfaction     = faction.Subfactions[Math.Min(playerObject.SubfactionIndex, faction.Subfactions.Length - 1)];

            return(new CreateShipDummyParams()
            {
                ShipID = shipInfo.ID,
                PreferredMount = Ship.GetPreferredMount(game, playerObject, faction, shipSectionAssetList),
                ShipFaction = faction,
                Sections = (IEnumerable <ShipSectionAsset>)shipSectionAssetList.ToArray(),
                AssignedModules = (IEnumerable <ModuleAssignment>)moduleAssignmentList.ToArray(),
                PreferredModules = game.AssetDatabase.Modules.Where <LogicalModule>((Func <LogicalModule, bool>)(x => modules.Contains <string>(x.ModuleName))),
                AssignedWeapons = (IEnumerable <WeaponAssignment>)weaponAssignmentList.ToArray(),
                PreferredWeapons = game.AssetDatabase.Weapons.Where <LogicalWeapon>((Func <LogicalWeapon, bool>)(x => weapons.Contains <string>(x.Name)))
            });
        }
Esempio n. 20
0
        private void SyncFleet(int fleetID)
        {
            this.App.GameDatabase.GetFleetInfo(fleetID);
            IEnumerable <ShipInfo> shipInfoByFleetId = this.App.GameDatabase.GetShipInfoByFleetID(fleetID, false);
            List <object>          objectList        = new List <object>();
            int num1 = 0;

            foreach (ShipInfo shipInfo in shipInfoByFleetId)
            {
                DesignInfo             designInfo = shipInfo.DesignInfo;
                int                    num2       = 0;
                int                    count1     = objectList.Count;
                BattleRiderTypes       type       = BattleRiderTypes.Unspecified;
                int                    num3       = 0;
                List <CarrierWingData> source     = new List <CarrierWingData>();
                foreach (DesignSectionInfo designSection in designInfo.DesignSections)
                {
                    ShipSectionAsset shipSectionAsset = this.App.AssetDatabase.GetShipSectionAsset(designSection.FilePath);
                    if (shipSectionAsset.Type == ShipSectionType.Mission)
                    {
                        type = shipSectionAsset.BattleRiderType;
                    }
                    num2 += RiderManager.GetNumRiderSlots(this.App, designSection);
                    foreach (LogicalBank bank1 in shipSectionAsset.Banks)
                    {
                        LogicalBank bank = bank1;
                        if (RiderManager.IsRiderBank(bank))
                        {
                            List <LogicalMount>       list       = ((IEnumerable <LogicalMount>)shipSectionAsset.Mounts).Where <LogicalMount>((Func <LogicalMount, bool>)(x => x.Bank == bank)).ToList <LogicalMount>();
                            WeaponEnums.TurretClasses mountClass = bank.TurretClass;
                            int count2             = list.Count;
                            int riderSlotsPerSquad = BattleRiderSquad.GetMinRiderSlotsPerSquad(mountClass, designInfo.Class);
                            int numRidersPerSquad  = BattleRiderSquad.GetNumRidersPerSquad(mountClass, designInfo.Class, Math.Max(count2, riderSlotsPerSquad));
                            int num4 = numRidersPerSquad > count2 ? 1 : count2 / numRidersPerSquad;
                            for (int index1 = 0; index1 < num4; ++index1)
                            {
                                int        num5    = Math.Min(count2, numRidersPerSquad);
                                List <int> intList = new List <int>();
                                for (int index2 = 0; index2 < num5; ++index2)
                                {
                                    intList.Add(num3);
                                    ++num3;
                                }
                                CarrierWingData carrierWingData = source.FirstOrDefault <CarrierWingData>((Func <CarrierWingData, bool>)(x =>
                                {
                                    if (x.Class == mountClass)
                                    {
                                        return(x.SlotIndexes.Count < numRidersPerSquad);
                                    }
                                    return(false);
                                }));
                                if (carrierWingData != null)
                                {
                                    carrierWingData.SlotIndexes.AddRange((IEnumerable <int>)intList);
                                }
                                else
                                {
                                    source.Add(new CarrierWingData()
                                    {
                                        SlotIndexes = intList,
                                        Class       = mountClass
                                    });
                                }
                            }
                            foreach (LogicalMount logicalMount in list)
                            {
                                objectList.Add((object)(int)bank.TurretClass);
                            }
                        }
                        else if (WeaponEnums.IsWeaponBattleRider(bank.TurretClass))
                        {
                            num3 += ((IEnumerable <LogicalMount>)shipSectionAsset.Mounts).Count <LogicalMount>((Func <LogicalMount, bool>)(x => x.Bank == bank));
                        }
                    }
                    foreach (DesignModuleInfo module in designSection.Modules)
                    {
                        string        path          = this.App.GameDatabase.GetModuleAsset(module.ModuleID);
                        LogicalModule logicalModule = this.App.AssetDatabase.Modules.FirstOrDefault <LogicalModule>((Func <LogicalModule, bool>)(x => x.ModulePath == path));
                        foreach (LogicalBank bank1 in logicalModule.Banks)
                        {
                            LogicalBank bank = bank1;
                            if (RiderManager.IsRiderBank(bank))
                            {
                                List <LogicalMount> list = ((IEnumerable <LogicalMount>)logicalModule.Mounts).Where <LogicalMount>((Func <LogicalMount, bool>)(x => x.Bank == bank)).ToList <LogicalMount>();
                                int        count2        = list.Count;
                                List <int> intList       = new List <int>();
                                for (int index = 0; index < count2; ++index)
                                {
                                    intList.Add(num3);
                                    ++num3;
                                }
                                source.Add(new CarrierWingData()
                                {
                                    SlotIndexes = intList,
                                    Class       = bank.TurretClass,
                                    DefaultType = logicalModule.AbilityType == ModuleEnums.ModuleAbilities.KingfisherRider ? BattleRiderTypes.scout : BattleRiderTypes.Unspecified
                                });
                                foreach (LogicalMount logicalMount in list)
                                {
                                    objectList.Add((object)(int)bank.TurretClass);
                                }
                            }
                            else if (WeaponEnums.IsWeaponBattleRider(bank.TurretClass))
                            {
                                num3 += ((IEnumerable <LogicalMount>)logicalModule.Mounts).Count <LogicalMount>((Func <LogicalMount, bool>)(x => x.Bank == bank));
                            }
                        }
                    }
                }
                objectList.Insert(count1, (object)num2);
                int    num6 = 0;
                string str1 = "";
                string str2 = "";
                foreach (DesignSectionInfo designSection in designInfo.DesignSections)
                {
                    ShipSectionAsset shipSectionAsset = designSection.ShipSectionAsset;
                    num6 += shipSectionAsset.ReserveSize;
                    if (shipSectionAsset.Type == ShipSectionType.Mission)
                    {
                        str1 = App.Localize(shipSectionAsset.Title);
                    }
                    if (shipSectionAsset.Type == ShipSectionType.Engine)
                    {
                        str2 = App.Localize(shipSectionAsset.Title);
                    }
                }
                if (num6 > 0 || num2 > 0 || type.IsBattleRiderType())
                {
                    objectList.Add((object)shipInfo.DesignID);
                    objectList.Add((object)shipInfo.ID);
                    objectList.Add((object)designInfo.Name);
                    objectList.Add((object)shipInfo.ShipName);
                    objectList.Add((object)num6);
                    objectList.Add((object)(int)designInfo.Class);
                    objectList.Add((object)(int)type);
                    objectList.Add((object)shipInfo.ParentID);
                    objectList.Add((object)shipInfo.RiderIndex);
                    objectList.Add((object)str1);
                    objectList.Add((object)str2);
                    if (num2 > 0)
                    {
                        objectList.Add((object)source.Count);
                        foreach (CarrierWingData carrierWingData in source)
                        {
                            objectList.Add((object)carrierWingData.SlotIndexes.Count);
                            foreach (int slotIndex in carrierWingData.SlotIndexes)
                            {
                                objectList.Add((object)slotIndex);
                            }
                            objectList.Add((object)(int)carrierWingData.Class);
                            objectList.Add((object)(int)carrierWingData.DefaultType);
                        }
                    }
                    else if (num6 > 0)
                    {
                        objectList.Add((object)0);
                    }
                    ++num1;
                }
                else
                {
                    objectList.RemoveRange(count1, objectList.Count - count1);
                }
            }
            objectList.Insert(0, (object)num1);
            this.PostSetProp("SyncShips", objectList.ToArray());
        }