Beispiel #1
0
        public static Ability MakeAbility(AbilityDef abilityDef)
        {
            Ability ability = (Ability)Activator.CreateInstance(abilityDef.thingClass);

            ability.def = abilityDef;
            ability.PostMake();
            return(ability);
        }
Beispiel #2
0
        private List <AbilityDef> SelectAbilities(CharacterClassModifier classSettings, ref List <AbilityDef> excludedAbilities, List <AbilityDef> existingAbilities = null)
        {
            List <AbilityDef> abilities = existingAbilities;

            if (abilities.NullOrEmpty())
            {
                abilities = new List <AbilityDef>();
            }

            // Get excluded abilities.
            if (classSettings.excludedAbilities != null)
            {
                excludedAbilities = classSettings.excludedAbilities;
            }

            // Insert the guaranteed abilities.
            foreach (AbilityDef ability in classSettings.abilities)
            {
                if (excludedAbilities.NullOrEmpty() || !excludedAbilities.Contains(ability))
                {
                    abilities.Insert(0, ability);
                }
            }

            // Get the abilities with tags.
            foreach (AbilitySelector abilitySelector in classSettings.numberOfAbilitiesWithTags)
            {
                List <AbilityDef> abilitiesWithTags = new List <AbilityDef>();
                foreach (AbilityDef ability in DefDatabase <AbilityDef> .AllDefs)
                {
                    if (!excludedAbilities.NullOrEmpty() && excludedAbilities.Contains(ability))
                    {
                        continue;
                    }

                    if ((abilitySelector.requireAllTags && ability.HasAllTags(abilitySelector.tags)) ||
                        (!abilitySelector.requireAllTags && ability.HasAnyTag(abilitySelector.tags)))
                    {
                        abilitiesWithTags.Add(ability);
                    }
                }

                for (int i = 0; !abilitiesWithTags.NullOrEmpty() && i < abilitySelector.targetNumber; i++)
                {
                    AbilityDef ability = abilitiesWithTags.RandomElement();
                    abilities.Add(ability);
                    abilitiesWithTags.Remove(ability);
                }
            }

            // Get the abilities in categories.
            foreach (AbilitySelector abilitySelector in classSettings.numberOfAbilitiesInCategories)
            {
                List <AbilityDef> abilitiesInCategories = new List <AbilityDef>();
                foreach (AbilityDef ability in DefDatabase <AbilityDef> .AllDefs)
                {
                    if (!excludedAbilities.NullOrEmpty() && excludedAbilities.Contains(ability))
                    {
                        continue;
                    }

                    if (ability.InAnyOfAbilityCategories(abilitySelector.abilityCategoryDefs))
                    {
                        abilitiesInCategories.Add(ability);
                    }
                }

                for (int i = 0; !abilitiesInCategories.NullOrEmpty() && i < abilitySelector.targetNumber; i++)
                {
                    AbilityDef ability = abilitiesInCategories.RandomElement();
                    abilities.Add(ability);
                    abilitiesInCategories.Remove(ability);
                }
            }

            // Eliminate duplicates.
            abilities.RemoveDuplicates();

            return(abilities);
        }
Beispiel #3
0
 public Ability(AbilityDef abilityDef)
 {
     def = abilityDef;
 }
Beispiel #4
0
        private List <AbilityDef> SelectAbilities(CharacterClassModifier classSettings, List <AbilityDef> existingAbilities = null)
        {
            List <AbilityDef> abilities = existingAbilities;

            if (abilities.NullOrEmpty())
            {
                abilities = new List <AbilityDef>();
            }

            // Insert the guaranteed abilities.
            abilities.InsertRange(0, classSettings.abilities);

            // Get the abilities with tags.
            foreach (AbilitySelector abilitySelector in classSettings.numberOfAbilitiesWithTags)
            {
                List <AbilityDef> abilitiesWithTags = new List <AbilityDef>();
                foreach (AbilityDef ability in DefDatabase <AbilityDef> .AllDefs)
                {
                    if ((abilitySelector.requireAllTags && ability.HasAllTags(abilitySelector.tags)) ||
                        (!abilitySelector.requireAllTags && ability.HasAnyTag(abilitySelector.tags)))
                    {
                        abilitiesWithTags.Add(ability);
                    }
                }

                for (int i = 0; !abilitiesWithTags.NullOrEmpty() && i < abilitySelector.targetNumber; i++)
                {
                    AbilityDef ability = abilitiesWithTags.RandomElement();
                    abilities.Add(ability);
                    abilitiesWithTags.Remove(ability);
                }
            }

            // Get the abilities in categories.
            foreach (AbilitySelector abilitySelector in classSettings.numberOfAbilitiesInCategories)
            {
                List <AbilityDef> abilitiesInCategories = new List <AbilityDef>();
                foreach (AbilityDef ability in DefDatabase <AbilityDef> .AllDefs)
                {
                    if (ability.InAnyOfAbilityCategories(abilitySelector.abilityCategoryDefs))
                    {
                        abilitiesInCategories.Add(ability);
                    }
                }

                for (int i = 0; !abilitiesInCategories.NullOrEmpty() && i < abilitySelector.targetNumber; i++)
                {
                    AbilityDef ability = abilitiesInCategories.RandomElement();
                    abilities.Add(ability);
                    abilitiesInCategories.Remove(ability);
                }
            }

            // Eliminate duplicates and only allow the maximum number.
            abilities.RemoveDuplicates();
            if (classSettings.maximumNumberOfAbilities < 0) // infinite.
            {
                return(abilities);
            }

            int n = abilities.Count - classSettings.maximumNumberOfAbilities;

            while (!abilities.NullOrEmpty() && n > 0) // limited.
            {
                abilities.RemoveLast();
                n--;
            }

            return(abilities);
        }
Beispiel #5
0
 public CustomAbility(AbilityDef abilityDef)
 {
     def = abilityDef;
 }