예제 #1
0
        public virtual void GiveRandomAbilityAtLevel(int?forLevel = null)
        {
            if (!this.giveRandomAbilities)
            {
                return;
            }

            forLevel = forLevel ?? this.level;

            CompAbilities     comp        = this.pawn.GetComp <CompAbilities>();
            List <AbilityDef> abilityDefs = DefDatabase <AbilityDef> .AllDefsListForReading.Where(def => !comp.HasAbility(def) && def.requiredHediff != null && def.requiredHediff.hediffDef == this.def && def.requiredHediff.minimumLevel <= forLevel && (def.requiredTrait == null || this.pawn.story.traits.HasTrait(def.requiredTrait))).ToList();

            IEnumerable <AbilityDef> abilityDefsAtLevel = abilityDefs.Where(def => def.requiredHediff.minimumLevel == forLevel);

            if (!abilityDefsAtLevel.TryRandomElement(out AbilityDef abilityDef))
            {
                abilityDef = abilityDefs.RandomElement();
            }

            comp.GiveAbility(abilityDef);
        }