protected override IEnumerable <Toil> MakeNewToils()
        {
            yield return(Toils_Misc.ThrowColonistAttackingMote(TargetIndex.A));

            Verb_UseAbility verb = this.pawn.CurJob.verbToUse as Verb_UseAbility;

            if (this.TargetA.HasThing)
            {
                Toil getInRangeToil = Toils_Combat.GotoCastPosition(TargetIndex.A, false);
                yield return(getInRangeToil);
            }

            Find.Targeter.targetingVerb = verb;
            yield return(Toils_Combat.CastVerb(TargetIndex.A, false));

            //CompAbilityUser.IsActive = true;
            this.AddFinishAction(() =>
            {
                //   //Log.Message("FinishACtion");
                //if (CompAbilityUser.IsActive)
                //{
                //PsykerUtility.PsykerShockEvents(CompAbilityUser, CompAbilityUser.curPower.PowerLevel);
                //}
                if (this.CompAbilityUsers is List <CompAbilityUser> users && !users.NullOrEmpty())
                {
                    foreach (CompAbilityUser u in users)
                    {
                        u.PostAbilityAttempt(this.pawn, verb.ability.powerdef);
                    }
                }
                //this.CompAbilityUser.ShotFired = true;
            });
        }
        protected override IEnumerable <Toil> MakeNewToils()
        {
            yield return(Toils_Misc.ThrowColonistAttackingMote(TargetIndex.A));

            Verb_UseAbility verb = this.pawn.CurJob.verbToUse as Verb_UseAbility;

            //Toil getInRangeToil = GotoCastPosition(TargetIndex.A, false);
            //yield return getInRangeToil;

            Find.Targeter.targetingVerb = verb;
            yield return(Toils_Combat.CastVerb(TargetIndex.A, false));

            this.AddFinishAction(() =>
            {
                //if (compAbilityUser.IsActive)
                //{

                //}
                //compAbilityUser.IsActive = false;
                if (this.CompAbilityUsers is List <CompAbilityUser> users && !users.NullOrEmpty())
                {
                    foreach (CompAbilityUser u in users)
                    {
                        u.PostAbilityAttempt(this.pawn, verb.ability.powerdef);
                    }
                }
            });
        }
예제 #3
0
 // RimWorld.Targeter
 public void BeginTargetingWithVerb(Verb_UseAbility verbToAdd, TargetingParameters targetParams, Action <LocalTargetInfo> action, Pawn caster = null, Action actionWhenFinished = null, Texture2D mouseAttachment = null)
 {
     verbToAdd.timeSavingActionVariable         = this.action;
     Find.Targeter.targetingVerb                = verbToAdd;
     Find.Targeter.targetingVerbAdditionalPawns = null;
     AccessTools.Field(typeof(Targeter), "action").SetValue(Find.Targeter, action);
     AccessTools.Field(typeof(Targeter), "targetParams").SetValue(Find.Targeter, targetParams);
     AccessTools.Field(typeof(Targeter), "caster").SetValue(Find.Targeter, caster);
     AccessTools.Field(typeof(Targeter), "actionWhenFinished").SetValue(Find.Targeter, actionWhenFinished);
     AccessTools.Field(typeof(Targeter), "mouseAttachment").SetValue(Find.Targeter, mouseAttachment);
 }
예제 #4
0
        public void UpdateAbilities()
        {
            if (this.IsInitialized)
            {
                this.AbilityVerbs.Clear();
                List <PawnAbility> abList = new List <PawnAbility>();

                abList.AddRange(this.Powers);
                abList.AddRange(this.temporaryWeaponPowers);
                abList.AddRange(this.temporaryApparelPowers);

                this.allPowers.Clear();

                this.allPowers = abList;

//                Log.Message("UpdateAbilities : with "+this.allPowers.Count+" powers");

                for (int i = 0; i < this.allPowers.Count; i++)
                {
                    Verb_UseAbility newVerb = (Verb_UseAbility)Activator.CreateInstance(abList[i].powerdef.MainVerb.verbClass);
                    if (!this.AbilityVerbs.Any(item => item.verbProps == newVerb.verbProps))
                    {
                        ////Log.Message("UpdateAbilities: Added to AbilityVerbs");
                        newVerb.caster    = this.AbilityUser;
                        newVerb.ability   = abList[i];
                        newVerb.verbProps = abList[i].powerdef.MainVerb;
                        this.AbilityVerbs.Add(newVerb);
                    }
                }

                /*
                 * this.pawnAbilities.Clear();
                 *
                 * foreach (PawnAbility pow in abList)
                 * {
                 * Verb_UseAbility newVerb = (Verb_UseAbility)Activator.CreateInstance(pow.powerdef.MainVerb.verbClass);
                 * if (!AbilityVerbs.Any(item => item.verbProps == newVerb.verbProps))
                 * {
                 * ////Log.Message("UpdateAbilities: Added to pawnAbilities");
                 * newVerb.caster = this.abilityUser;
                 * newVerb.ability = pow;
                 * newVerb.verbProps = pow.powerdef.MainVerb;
                 * pawnAbilities.Add(pow, newVerb);
                 * }
                 * }
                 * //       //Log.Message(this.PawnAbilitys.Count.ToString());
                 */
            }
        }
예제 #5
0
        // RimWorld.Targeter
        public void BeginTargetingWithVerb(Verb_UseAbility verbToAdd, TargetingParameters targetParams,
                                           Action <LocalTargetInfo> action, Pawn caster = null, Action actionWhenFinished = null,
                                           Texture2D mouseAttachment = null)
        {
            verbToAdd.timeSavingActionVariable = this.action;
            var targeter = Find.Targeter;

            targeter.targetingSource = verbToAdd;
            targeter.targetingSourceAdditionalPawns   = null;
            targeterActionField(targeter)             = action;
            targeterCasterField(targeter)             = caster;
            targeterTargetParamsField(targeter)       = targetParams;
            targeterActionWhenFinishedField(targeter) = actionWhenFinished;
            targeterMouseAttachmentField(targeter)    = mouseAttachment;
        }
예제 #6
0
 public static void TargeterUpdate_PostFix(Targeter __instance)
 {
     if (Find.Targeter.targetingVerb != null)
     {
         ////Log.Message("2");
         if (Find.Targeter.targetingVerb is Verb_UseAbility)
         {
             ////Log.Message("3");
             Verb_UseAbility targetVerb = Find.Targeter.targetingVerb as Verb_UseAbility;
             if (targetVerb.UseAbilityProps.abilityDef.MainVerb.TargetAoEProperties != null)
             {
                 ////Log.Message("4");
                 if (targetVerb.UseAbilityProps.abilityDef.MainVerb.TargetAoEProperties.range > 0)
                 {
                     ////Log.Message("6");
                     GenDraw.DrawRadiusRing(UI.MouseCell(), targetVerb.UseAbilityProps.abilityDef.MainVerb.TargetAoEProperties.range);
                 }
             }
         }
     }
 }
예제 #7
0
 public virtual bool CanCastPowerCheck(Verb_UseAbility verbAbility, out string reason)
 {
     reason = "";
     return(true);
 }
예제 #8
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);
        }
예제 #9
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);
            });
예제 #10
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;
        }