Пример #1
0
        internal static void TryUpdateAbilities(Pilot pilot)
        {
            // skip pilots with specified pilot tags
            foreach (var tag in pilot.pilotDef.PilotTags)
            {
                if (Settings.IgnorePilotsWithTags.Exists(x => tag.StartsWith(x)))
                {
                    return;
                }
            }

            if (dataManager.PilotDefs.Exists(pilot.pilotDef.Description.Id) &&
                pilot.pilotDef == dataManager.PilotDefs.Get(pilot.pilotDef.Description.Id))
            {
                // the pilot is set to use the actual pilotdef object in datamanager!
                // need to make sure that this pilot has it's own unique pilot def before we modify it
                pilot.ForceRefreshDef();
            }

            var pilotDef        = pilot.pilotDef;
            var reloadAbilities = false;

            reloadAbilities |= UpdateAbilitiesFromTree(pilotDef);
            reloadAbilities |= UpdateAbilitiesFromTags(pilotDef);

            if (pilot.Team != null)
            {
                reloadAbilities = UpdateAbilitiesFromFaction(pilotDef, pilot.Team.FactionValue) | reloadAbilities;

                if (pilot.Team.TeamController == TeamController.Computer)
                {
                    reloadAbilities |= SwapAIAbilities(pilotDef);
                }
            }

            if (reloadAbilities)
            {
                if (pilotDef.AbilityDefs != null)
                {
                    pilotDef.AbilityDefs.Clear();
                }

                if (pilotDef.DataManager == null)
                {
                    pilotDef.DataManager = dataManager;
                }

                pilotDef.ForceRefreshAbilityDefs();
            }
        }
Пример #2
0
        internal static void TryUpdateAbilities(Pilot pilot)
        {
            if (dataManager.PilotDefs.Exists(pilot.pilotDef.Description.Id) &&
                pilot.pilotDef == dataManager.PilotDefs.Get(pilot.pilotDef.Description.Id))

            {
                // the pilot is set to use the actual pilotdef object in datamanager!
                // need to make sure that this pilot has it's own unique pilot def before we modify it
                pilot.ForceRefreshDef();
            }

            var pilotDef        = pilot.pilotDef;
            var reloadAbilities = false;

            // skip pilots with specified pilot tags
            foreach (var tag in pilot.pilotDef.PilotTags)
            {
                if (Settings.IgnorePilotsWithTags.Exists(x => tag.StartsWith(x)))
                {
                    return;
                }
            }


            reloadAbilities |= UpdateAbilitiesFromTree(pilotDef);
            reloadAbilities |= UpdateAbilitiesFromTags(pilotDef);

            var duplicateAbilities =
                pilotDef.abilityDefNames.GroupBy(x => x).Where(x => x.Count() > 1).Select(x => x.Key);

            foreach (var abilityName in duplicateAbilities)
            {
                if (!Settings.IgnoreAbilities.Exists(x => abilityName.StartsWith(x)) &&
                    Settings.RemoveDuplicateAbilities)
                {
                    HBSLog.Log($"{pilotDef.Description.Id}: Removing duplicate '{abilityName}'s");
                    pilotDef.abilityDefNames.RemoveAll(x => x == abilityName);
                    pilotDef.abilityDefNames.Add(abilityName);
                    reloadAbilities = true;
                }
            }

            if (pilot.Team != null)
            {
                reloadAbilities = UpdateAbilitiesFromFaction(pilotDef, pilot.Team.FactionValue) | reloadAbilities;

                if (pilot.Team.TeamController == TeamController.Computer)
                {
                    reloadAbilities |= SwapAIAbilities(pilotDef);
                }
            }

            reloadAbilities = UpgradeAbilities(pilotDef);

            if (reloadAbilities)
            {
                if (pilotDef.AbilityDefs != null)
                {
                    pilotDef.AbilityDefs.Clear();
                }

                if (pilotDef.DataManager == null)
                {
                    pilotDef.DataManager = dataManager;
                }

                pilotDef.ForceRefreshAbilityDefs();
            }
        }