示例#1
0
        public static void Postfix(Pawn __result)
        {
            PawnKindAbilityExtension abilityExtension = __result.kindDef.GetModExtension <PawnKindAbilityExtension>();

            if (abilityExtension == null)
            {
                return;
            }

            if (abilityExtension.implantDef != null)
            {
                Hediff_Abilities implant = __result.health.hediffSet.GetFirstHediffOfDef(abilityExtension.implantDef) as Hediff_Abilities ??
                                           HediffMaker.MakeHediff(abilityExtension.implantDef, __result,
                                                                  __result.RaceProps.body.GetPartsWithDef(BodyPartDefOf.Brain).FirstOrFallback()) as Hediff_Abilities;
                if (implant != null)
                {
                    implant.giveRandomAbilities = abilityExtension.giveRandomAbilities;
                    __result.health.AddHediff(implant);
                    implant.SetLevelTo(abilityExtension.initialLevel);
                }
            }

            CompAbilities comp = __result.GetComp <CompAbilities>();

            foreach (AbilityDef abilityDef in abilityExtension.giveAbilities)
            {
                comp.GiveAbility(abilityDef);
            }
        }
示例#2
0
        private static void GiveAbility()
        {
            List <DebugMenuOption> list = new List <DebugMenuOption>();

            foreach (Abilities.AbilityDef def in DefDatabase <Abilities.AbilityDef> .AllDefs)
            {
                Abilities.AbilityDef abilityDef = def;

                list.Add(new
                         DebugMenuOption($"{(abilityDef.requiredHediff != null ? $"{abilityDef.requiredHediff.hediffDef.LabelCap} ({abilityDef.requiredHediff.minimumLevel}): " : string.Empty)}{abilityDef.LabelCap}",
                                         DebugMenuOptionMode.Tool, () =>
                {
                    foreach (Pawn item in (from t in Find.CurrentMap.thingGrid.ThingsAt(UI.MouseCell())
                                           where t is Pawn
                                           select t).Cast <Pawn>())
                    {
                        CompAbilities abilityComp = item.TryGetComp <CompAbilities>();
                        if (abilityComp != null)
                        {
                            abilityComp.GiveAbility(abilityDef);
                            DebugActionsUtility.DustPuffFrom(item);
                        }
                    }
                }));
            }

            Find.WindowStack.Add(new Dialog_DebugOptionListLister(list));
        }
示例#3
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);
        }