public virtual void Tick(CompAbilityUser abilityUser)
        {
            var rate = -1;

            switch (Props.tickerType)
            {
            case TickerType.Rare:
                rate = 250;
                break;

            case TickerType.Normal:
                rate = 60;
                break;

            case TickerType.Long:
                rate = 2000;
                break;
            }
            if (rate != -1)
            {
                if (Find.TickManager.TicksGame % rate == 0 && CanDoEffect(abilityUser))
                {
                    TryDoEffect(abilityUser);
                }
            }
        }
Beispiel #2
0
        public virtual bool CanDoEffect(CompAbilityUser abilityUser)
        {
            if (abilityUser == null)
            {
                return(false);
            }
            var pawn = abilityUser.Pawn;

            if (pawn == null)
            {
                return(false);
            }
            if (pawn.jobs == null)
            {
                return(false);
            }
            if (Props.awakeOnly && pawn.CurJob?.def == JobDefOf.LayDown || pawn.Downed)
            {
                return(false);
            }
            if (pawn.mindState == null)
            {
                return(false);
            }
            if (Props.combatOnly && Props.combatOnly && !pawn.mindState.anyCloseHostilesRecently)
            {
                return(false);
            }
            return(true);
        }
Beispiel #3
0
        public static Action TryCastAbility(Pawn pawn, LocalTargetInfo target, CompAbilityUser compAbilityUser, Verb_UseAbility verb, AbilityDef psydef)
        {
            Action act = new Action(delegate
            {
                compAbilityUser.CurTarget   = null;
                compAbilityUser.CurTarget   = target;
                compAbilityUser.curVerb     = verb;
                compAbilityUser.curPower    = psydef;
                compAbilityUser.curRotation = Rot4.South;
                if (target != null && target.Thing != null)
                {
                    compAbilityUser.curRotation = target.Thing.Rotation;
                }

                Job job;
                if (target != null)
                {
                    job = CompAbilityUser.AbilityJob(verb.UseAbilityProps.AbilityTargetCategory, target);
                }
                else
                {
                    job = CompAbilityUser.AbilityJob(verb.UseAbilityProps.AbilityTargetCategory, pawn);
                }
                job.playerForced = true;
                job.verbToUse    = verb;
                if (target != null)
                {
                    if (target.Thing is Pawn pawn2)
                    {
                        job.killIncappedTarget = pawn2.Downed;
                    }
                }

                pawn.jobs.TryTakeOrderedJob(job);
            });
Beispiel #4
0
 public virtual void DoEffect(CompAbilityUser abilityUser)
 {
     if (Props?.hediffs is List <HediffDef> hList)
     {
         foreach (var h in hList)
         {
             HealthUtility.AdjustSeverity(abilityUser.Pawn, h, 1f);
         }
     }
 }
Beispiel #5
0
        public PawnAbility(CompAbilityUser comp)
        {
            if (comp.Pawn == null)
            {
                throw new ArgumentNullException("comp.Pawn cannot be null");
            }
#pragma warning disable CS0618 // Type or member is obsolete
            abilityUser = comp;
            DebugMessage($"new PawnAbility({comp}) => abilityUser={abilityUser}");
#pragma warning restore CS0618 // Type or member is obsolete
        }
Beispiel #6
0
        internal void Initialize(CompAbilityUser abilityUser, AbilityDef powerDef, int ticksUntilCasting)
        {
            if (abilityUser.Pawn == null)
            {
                throw new ArgumentNullException("comp.Pawn cannot be null");
            }
            DebugMessage($"PawnAbility.Initialize({this}, {abilityUser}, {powerDef}, {ticksUntilCasting})");
#pragma warning disable CS0618 // Type or member is obsolete
            this.abilityUser = abilityUser;
#pragma warning restore CS0618 // Type or member is obsolete
            this.powerDef          = powerDef;
            this.ticksUntilCasting = ticksUntilCasting;
        }
Beispiel #7
0
        public PawnAbility(AbilityData data)
        {
            var pawn = data.Pawn;

            if (pawn == null)
            {
                throw new ArgumentNullException("data.Pawn cannot be null");
            }
#pragma warning disable CS0618 // Type or member is obsolete
            abilityUser = pawn.GetExactCompAbilityUser(data.AbilityClass);
            DebugMessage($"new PawnAbility{data} => abilityUser={abilityUser}");
#pragma warning restore CS0618 // Type or member is obsolete
        }
Beispiel #8
0
 public PawnAbility(Pawn user, AbilityDef pdef)
 {
     if (user == null)
     {
         throw new ArgumentNullException("user cannot be null");
     }
     if (pdef == null)
     {
         throw new ArgumentNullException("pdef cannot be null");
     }
     abilityUser = user.GetCompAbilityUser();
     powerDef    = pdef;
     DebugMessage($"new PawnAbility({user}, {pdef}) => abilityUser={abilityUser}");
 }
Beispiel #9
0
        public virtual void Tick(CompAbilityUser abilityUser)
        {
            var rate = Props.tickerType switch
            {
                TickerType.Normal => GenTicks.TicksPerRealSecond, // TODO: shouldn't this be 1 instead?
                TickerType.Rare => GenTicks.TickRareInterval,
                TickerType.Long => GenTicks.TickLongInterval,
                _ => - 1,
            };

            if (rate != -1)
            {
                if (Find.TickManager.TicksGame % rate == 0 && CanDoEffect(abilityUser))
                {
                    TryDoEffect(abilityUser);
                }
            }
        }
Beispiel #10
0
        public override void Notify_Equipped(Pawn pawn)
        {
            base.Notify_Equipped(pawn);
            var abilityUserClass = Props.AbilityUserClass;
            var abilities        = Props.Abilities;

            //Log.Message("  Found CompAbilityItem, for CompAbilityUser of " + abilityUserClass);
            foreach (var cau in pawn.GetCompAbilityUsers())
            {
                AddAbilityFunc addAbilityFunc = parent is Apparel ? cau.AddApparelAbility : cau.AddWeaponAbility;
                //Log.Message("  Found CompAbilityUser, " + cau + " : " + cau.GetType() + ":" + abilityUserClass);
                if (cau.GetType() == abilityUserClass)
                {
                    //Log.Message("  and they match types");
                    AbilityUserTarget = cau;
                    foreach (var abdef in abilities)
                    {
                        addAbilityFunc(abdef);
                    }
                }
            }
        }
Beispiel #11
0
        public virtual bool IsInIgnoreHediffList(Hediff hediff)
        {
            if (hediff != null)
            {
                if (hediff.def != null)
                {
                    CompAbilityUser compAbility = this.Caster.TryGetComp <CompAbilityUser>();
                    if (compAbility != null)
                    {
                        if (compAbility.IgnoredHediffs() != null)
                        {
                            if (compAbility.IgnoredHediffs().Contains(hediff.def))
                            {
                                //Log.Message("IgnoreHediff Passed");
                                return(true);
                            }
                        }
                    }
                }
            }

            return(false);
        }
Beispiel #12
0
 public PawnAbility(CompAbilityUser comp)
 {
     pawn        = comp.AbilityUser;
     abilityUser = comp;
     //Log.Message("PawnAbility Created: " + this.Def.defName);
 }
Beispiel #13
0
 public PawnAbility(CompAbilityUser comp) => this.pawn = comp.AbilityUser;
 public AbilityPowerManager(CompAbilityUser CompAbilityUser)
 {
     this.CompAbilityUser = CompAbilityUser;
 }
Beispiel #15
0
 public AbilityData(CompAbilityUser abilityUser)
 {
     abilityClass = abilityUser.GetType();
     pawn         = abilityUser.Pawn;
 }
 public Command_PawnAbility(CompAbilityUser compAbilityUser, PawnAbility ability)
 {
     this.compAbilityUser = compAbilityUser;
     this.pawnAbility     = ability;
 }
Beispiel #17
0
 public virtual bool TryDoEffect(CompAbilityUser abilityUser)
 {
     DoEffect(abilityUser);
     return(true);
 }
Beispiel #18
0
 public PawnAbility(AbilityData data)
 {
     pawn        = data.Pawn;
     abilityUser = data.Pawn.AllComps.FirstOrDefault(x => x.GetType() == data.AbilityClass) as CompAbilityUser;
     //Log.Message("PawnAbility Created: " + this.Def.defName);
 }
Beispiel #19
0
        public IEnumerable <Command_PawnAbility> GetPawnAbilityVerbs()
        {
            //Log.ErrorOnce("GetPawnAbilityVerbs Called", 912912);
            List <Verb_UseAbility> temp = new List <Verb_UseAbility>();

            temp.AddRange(this.AbilityVerbs);
            for (int i = 0; i < this.allPowers.Count; i++)
            {
                int                    j            = i;
                Verb_UseAbility        newVerb      = temp[j];
                VerbProperties_Ability newVerbProps = newVerb.UseAbilityProps;
                newVerb.caster    = this.AbilityUser;
                newVerb.verbProps = temp[j].verbProps;

                Command_PawnAbility command_CastPower = new Command_PawnAbility(this, this.allPowers[i])
                {
                    verb         = newVerb,
                    defaultLabel = this.allPowers[j].powerdef.LabelCap
                };


                //GetDesc
                StringBuilder s = new StringBuilder();
                s.AppendLine(this.allPowers[j].powerdef.GetDescription());
                s.AppendLine(PostAbilityVerbCompDesc(newVerb.UseAbilityProps));
                command_CastPower.defaultDesc = s.ToString();
                s = null;


                command_CastPower.targetingParams = this.allPowers[j].powerdef.MainVerb.targetParams;
                //command_CastPower.targetingParams = TargetingParameters.ForAttackAny();

                //if (newVerb.useAbilityProps.AbilityTargetCategory == AbilityTargetCategory.TargetSelf)
                //{
                //    command_CastPower.targetingParams = TargetingParameters.ForSelf(this.abilityUser);
                //}
                //else
                //{
                //    command_CastPower.targetingParams = TargetingParameters.
                //}
                command_CastPower.icon = this.allPowers[j].powerdef.uiIcon;
                //string str;
                //if (FloatMenuUtility.GetAttackAction(this.abilityUser, LocalTargetInfo.Invalid, out str) == null)
                //{
                //    command_CastPower.Disable(str.CapitalizeFirst() + ".");
                //}
                command_CastPower.action = delegate(Thing target)
                {
                    Action attackAction = CompAbilityUser.TryCastAbility(this.AbilityUser, target, this, newVerb, this.allPowers[j].powerdef as AbilityDef);
                    if (attackAction != null)
                    {
                        if (CanOverpowerTarget(this.AbilityUser, target, this.allPowers[j].powerdef as AbilityDef))
                        {
                            attackAction();
                        }
                    }
                };
                if (newVerb.caster.Faction != Faction.OfPlayer)
                {
                    command_CastPower.Disable("CannotOrderNonControlled".Translate());
                }
                string reason = "";
                if (newVerb.CasterIsPawn)
                {
                    if (newVerb.CasterPawn.story.WorkTagIsDisabled(WorkTags.Violent) && this.allPowers[j].powerdef.MainVerb.isViolent)
                    {
                        command_CastPower.Disable("IsIncapableOfViolence".Translate(new object[]
                        {
                            newVerb.CasterPawn.NameStringShort
                        }));
                    }
                    else if (!newVerb.CasterPawn.drafter.Drafted)
                    {
                        command_CastPower.Disable("IsNotDrafted".Translate(new object[]
                        {
                            newVerb.CasterPawn.NameStringShort
                        }));
                    }
                    else if (!newVerb.ability.CanFire)
                    {
                        command_CastPower.Disable("AU_PawnAbilityRecharging".Translate(new object[]
                        {
                            newVerb.CasterPawn.NameStringShort
                        }));
                    }
                    //This is a hook for modders.
                    else if (!CanCastPowerCheck(newVerb, out reason))
                    {
                        command_CastPower.Disable(reason.Translate(new object[]
                        {
                            newVerb.CasterPawn.NameStringShort
                        }));
                    }
                }
                yield return(command_CastPower);
            }
            temp = null;
            yield break;
        }
 public Command_PawnAbility(CompAbilityUser compAbilityUser, PawnAbility ability, int ticks)
 {
     this.compAbilityUser = compAbilityUser;
     pawnAbility          = ability;
     curTicks             = ticks;
 }
Beispiel #21
0
        // RimWorld.Targeter
        public static bool ProcessInputEvents_PreFix(Targeter __instance)
        {
            AccessTools.Method(typeof(Targeter), "ConfirmStillValid").Invoke(__instance, null);
            if (Event.current.type == EventType.MouseDown)
            {
                ////Log.Message("1");
                if (Event.current.button == 0 && __instance.IsTargeting)
                {
                    ////Log.Message("2");
                    if (__instance.targetingVerb != null)
                    {
                        ////Log.Message("3");
                        if (__instance.targetingVerb is Verb_UseAbility)
                        {
                            Verb_UseAbility abilityVerb = __instance.targetingVerb as Verb_UseAbility;
                            ////Log.Message("4");
                            //if (((Action<LocalTargetInfo>)AccessTools.Field(typeof(Targeter), "action").GetValue(__instance)) != null)
                            //{

                            ////Log.Message("5");
                            //TargetingParameters targetParams = (TargetingParameters)AccessTools.Field(typeof(Targeter), "targetParams").GetValue(__instance);
                            if (abilityVerb.ability.powerdef.MainVerb.AbilityTargetCategory != AbilityTargetCategory.TargetSelf)
                            {
                                TargetingParameters targetParams = abilityVerb.ability.powerdef.MainVerb.targetParams;
                                if (targetParams != null)
                                {
                                    ////Log.Message("6");
                                    IEnumerable <LocalTargetInfo> source = GenUI.TargetsAtMouse(targetParams, false);
                                    if (source != null && source.Count <LocalTargetInfo>() > 0)
                                    {
                                        ////Log.Message("7");
                                        if (source.Any <LocalTargetInfo>())
                                        {
                                            //Pawn caster = (Pawn)AccessTools.Field(typeof(Targeter), "caster").GetValue(__instance);
                                            Pawn caster = (Pawn)__instance.targetingVerb.caster;
                                            CompAbilityUser.TryCastAbility(caster, source.First <LocalTargetInfo>(), caster.GetComp <CompAbilityUser>(), (Verb_UseAbility)__instance.targetingVerb, ((Verb_UseAbility)(__instance.targetingVerb)).ability.powerdef as AbilityDef)?.Invoke();

                                            ////Log.Message("8");
                                            //AccessTools.Method(typeof(Targeter), "action").Invoke(__instance, new object[] {  });
                                            SoundDefOf.TickHigh.PlayOneShotOnCamera();
                                            __instance.StopTargeting();
                                            Event.current.Use();
                                            return(false);
                                        }
                                    }
                                }
                            }
                            else
                            {
                                //Pawn caster = (Pawn)AccessTools.Field(typeof(Targeter), "caster").GetValue(__instance);
                                Pawn caster = (Pawn)__instance.targetingVerb.caster;
                                CompAbilityUser.TryCastAbility(caster, null, caster.GetComp <CompAbilityUser>(), (Verb_UseAbility)__instance.targetingVerb, ((Verb_UseAbility)(__instance.targetingVerb)).ability.powerdef as AbilityDef)?.Invoke();

                                ////Log.Message("8");
                                //AccessTools.Method(typeof(Targeter), "action").Invoke(__instance, new object[] {  });
                                SoundDefOf.TickHigh.PlayOneShotOnCamera();
                                __instance.StopTargeting();
                                Event.current.Use();
                                return(false);
                            }

                            //}
                        }
                    }
                }
            }
            return(true);
        }