Пример #1
0
        private static LogicalWeapon SelectWeapon(
            ShipSectionAsset section,
            LogicalBank bank,
            IEnumerable <WeaponAssignment> assignedWeapons,
            IEnumerable <LogicalWeapon> preferredWeapons,
            IEnumerable <LogicalWeapon> weapons,
            string moduleNodeName,
            out int designID,
            out int targetFilter,
            out int fireMode)
        {
            LogicalWeapon logicalWeapon = (LogicalWeapon)null;

            designID     = 0;
            targetFilter = 0;
            fireMode     = 0;
            if (assignedWeapons != null)
            {
                WeaponAssignment weaponAssignment = assignedWeapons.FirstOrDefault <WeaponAssignment>((Func <WeaponAssignment, bool>)(x =>
                {
                    if (x.Bank != bank)
                    {
                        return(false);
                    }
                    if (x.ModuleNode != null)
                    {
                        return(x.ModuleNode == moduleNodeName);
                    }
                    return(true);
                }));
                if (weaponAssignment != null)
                {
                    logicalWeapon = weaponAssignment.Weapon;
                    designID      = weaponAssignment.DesignID;
                    targetFilter  = weaponAssignment.InitialTargetFilter ?? 0;
                    fireMode      = weaponAssignment.InitialFireMode ?? 0;
                }
            }
            if (logicalWeapon == null && !string.IsNullOrEmpty(bank.DefaultWeaponName))
            {
                logicalWeapon = weapons.FirstOrDefault <LogicalWeapon>((Func <LogicalWeapon, bool>)(x => string.Equals(x.WeaponName, bank.DefaultWeaponName, StringComparison.InvariantCultureIgnoreCase)));
            }
            if (logicalWeapon == null && preferredWeapons != null)
            {
                logicalWeapon = LogicalWeapon.EnumerateWeaponFits(section.Faction, section.SectionName, preferredWeapons, bank.TurretSize, bank.TurretClass).FirstOrDefault <LogicalWeapon>();
            }
            if (logicalWeapon == null)
            {
                logicalWeapon = LogicalWeapon.EnumerateWeaponFits(section.Faction, section.SectionName, weapons, bank.TurretSize, bank.TurretClass).FirstOrDefault <LogicalWeapon>();
            }
            if (logicalWeapon == null)
            {
                logicalWeapon = weapons.First <LogicalWeapon>();
            }
            return(logicalWeapon);
        }
Пример #2
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;
                        }
                    }
                }
            }
        }
Пример #3
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];
        }