Esempio n. 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);
            }
        }
Esempio n. 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));
        }
Esempio n. 3
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            this.FailOnDespawnedOrNull(TargetIndex.A);



            //yield return Toils_Combat.GotoCastPosition(TargetIndex.A);

            CompAbilities comp     = this.pawn.GetComp <CompAbilities>();
            Toil          waitToil = Toils_General.Wait(comp.currentlyCasting.GetCastTimeForPawn(), TargetIndex.A);

            waitToil.WithProgressBarToilDelay(TargetIndex.C);
            yield return(waitToil);

            Toil castToil = new Toil();

            castToil.initAction = () =>
            {
                LocalTargetInfo target = castToil.actor.jobs.curJob.GetTarget(TargetIndex.A);
                comp.currentlyCasting.Cast(target);
            };
            castToil.defaultCompleteMode = ToilCompleteMode.Instant;
            castToil.atomicWithPrevious  = true;
            yield return(castToil);
        }
Esempio n. 4
0
        public static void Postfix(Pawn __instance, ref Verb __result, Thing target)
        {
            CompAbilities compAbilities = __instance.TryGetComp <CompAbilities>();

            if (compAbilities == null)
            {
                return;
            }

            List <Verb_CastAbility> verbs = compAbilities.LearnedAbilities.Where(ab => ab.CanAutoCast && ab.IsEnabledForPawn(out string _) && (target == null || ab.CanHitTarget(target)))
                                            .Select(ab => ab.verb).ToList();

            if (verbs.NullOrEmpty())
            {
                return;
            }

            if (target != null)
            {
                if (verbs.Select(ve => new Tuple <Verb, float>(ve, ve.ability.Chance)).AddItem(new Tuple <Verb, float>(__result, 1f))
                    .TryRandomElementByWeight(t => t.Item2, out Tuple <Verb, float> result))
                {
                    __result = result.Item1;
                }
            }
            else
            {
                Verb verb = verbs.AddItem(__result).MaxBy(ve => ve.verbProps.range);
                __result = verb;
            }
        }
Esempio n. 5
0
        public override bool CanBeUsedBy(Pawn p, out string failReason)
        {
            if (!base.CanBeUsedBy(p, out failReason))
            {
                return(false);
            }

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

            return(comp != null);
        }
Esempio n. 6
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);
        }