示例#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);
        }
        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)))
            });
        }