Example #1
0
 // RimWorld.Targeter
 private static void CastPawnVerb(Verb verb)
 {
     foreach (TargetInfo current in GenUI.TargetsAtMouse(verb.verbProps.targetParams, false))
     {
         TargetInfo targetA = current;
         if (verb.verbProps.MeleeRange)
         {
             Job job = new Job(JobDefOf.AttackMelee, targetA);
             job.playerForced = true;
             Pawn pawn = targetA.Thing as Pawn;
             if (pawn != null)
             {
                 job.killIncappedTarget = pawn.Downed;
             }
             verb.CasterPawn.drafter.TakeOrderedJob(job);
         }
         else
         {
             JobDef jDef;
             if (verb.verbProps.ai_IsWeapon)
             {
                 jDef = JobDefOf.AttackStatic;
             }
             else
             {
                 jDef = JobDefOf.UseVerbOnThing;
             }
             Job job2 = new Job(jDef);
             job2.verbToUse = verb;
             job2.targetA   = targetA;
             verb.CasterPawn.drafter.TakeOrderedJob(job2);
         }
     }
 }
Example #2
0
 protected override LocalTargetInfo CurrentTargetUnderMouse()
 {
     if (!IsTargeting)
     {
         return(LocalTargetInfo.Invalid);
     }
     return(GenUI.TargetsAtMouse(targetParams).FirstOrFallback(LocalTargetInfo.Invalid));
 }
Example #3
0
        private LocalTargetInfo CurrentTargetUnderMouse(bool mustBeHittableNowIfNotMelee)
        {
            LocalTargetInfo result;

            if (!this.IsTargeting)
            {
                result = LocalTargetInfo.Invalid;
            }
            else
            {
                TargetingParameters clickParams     = (this.targetingVerb == null) ? this.targetParams : this.targetingVerb.verbProps.targetParams;
                LocalTargetInfo     localTargetInfo = LocalTargetInfo.Invalid;
                using (IEnumerator <LocalTargetInfo> enumerator = GenUI.TargetsAtMouse(clickParams, false).GetEnumerator())
                {
                    if (enumerator.MoveNext())
                    {
                        LocalTargetInfo localTargetInfo2 = enumerator.Current;
                        localTargetInfo = localTargetInfo2;
                    }
                }
                if (localTargetInfo.IsValid && mustBeHittableNowIfNotMelee && !(localTargetInfo.Thing is Pawn) && this.targetingVerb != null && !this.targetingVerb.verbProps.IsMeleeAttack)
                {
                    if (this.targetingVerbAdditionalPawns != null && this.targetingVerbAdditionalPawns.Any <Pawn>())
                    {
                        bool flag = false;
                        for (int i = 0; i < this.targetingVerbAdditionalPawns.Count; i++)
                        {
                            Verb verb = this.GetTargetingVerb(this.targetingVerbAdditionalPawns[i]);
                            if (verb != null && verb.CanHitTarget(localTargetInfo))
                            {
                                flag = true;
                                break;
                            }
                        }
                        if (!flag)
                        {
                            localTargetInfo = LocalTargetInfo.Invalid;
                        }
                    }
                    else if (!this.targetingVerb.CanHitTarget(localTargetInfo))
                    {
                        localTargetInfo = LocalTargetInfo.Invalid;
                    }
                }
                result = localTargetInfo;
            }
            return(result);
        }
        private LocalTargetInfo CurrentTargetUnderMouse()
        {
            if (!this.IsTargeting)
            {
                return(LocalTargetInfo.Invalid);
            }
            LocalTargetInfo localTarget = LocalTargetInfo.Invalid;

            using (IEnumerator <LocalTargetInfo> enumerator = GenUI.TargetsAtMouse(this.targetParams, false).GetEnumerator())
            {
                if (enumerator.MoveNext())
                {
                    LocalTargetInfo localTarget2 = enumerator.Current;
                    localTarget = localTarget2;
                }
            }
            return(localTarget);
        }
            private static LocalTargetInfo CurrentTargetUnderMouse(Targeter targeter, bool mustBeHittableNowIfNotMelee)
            {
                if (!targeter.IsTargeting)
                {
                    return(LocalTargetInfo.Invalid);
                }
                var targetParams = Traverse.Create(targeter).Field("targetParams").GetValue <TargetingParameters>();
                TargetingParameters clickParams     = (targeter.targetingSource == null) ? targetParams : targeter.targetingSource.GetVerb.verbProps.targetParams;
                LocalTargetInfo     localTargetInfo = LocalTargetInfo.Invalid;

                using (IEnumerator <LocalTargetInfo> enumerator = GenUI.TargetsAtMouse(clickParams, false).GetEnumerator())
                {
                    if (enumerator.MoveNext())
                    {
                        LocalTargetInfo localTargetInfo2 = enumerator.Current;
                        localTargetInfo = localTargetInfo2;
                    }
                }
                if (localTargetInfo.IsValid && mustBeHittableNowIfNotMelee && !(localTargetInfo.Thing is Pawn) && targeter.targetingSource != null && !targeter.targetingSource.GetVerb.verbProps.IsMeleeAttack)
                {
                    if (targeter.targetingSourceAdditionalPawns != null && targeter.targetingSourceAdditionalPawns.Any <Pawn>())
                    {
                        bool flag = false;
                        for (int i = 0; i < targeter.targetingSourceAdditionalPawns.Count; i++)
                        {
                            Verb verb = GetTargetingVerb(targeter, targeter.targetingSourceAdditionalPawns[i]);
                            if (verb != null && verb.CanHitTarget(localTargetInfo))
                            {
                                flag = true;
                                break;
                            }
                        }
                        if (!flag)
                        {
                            localTargetInfo = LocalTargetInfo.Invalid;
                        }
                    }
                    else if (!targeter.targetingSource.CanHitTarget(localTargetInfo))
                    {
                        localTargetInfo = LocalTargetInfo.Invalid;
                    }
                }
                return(localTargetInfo);
            }
Example #6
0
        private static void CastVerb(this Targeter _this)
        {
            Verb        targetingVerb = _this.GetVerb();
            List <Pawn> targetingVerbAdditionalPawns = _this.GetVerbAdditional();

            if (targetingVerb.CasterIsPawn)
            {
                CastPawnVerb(targetingVerb);
                for (int i = 0; i < targetingVerbAdditionalPawns.Count; i++)
                {
                    Verb verb = (from x in targetingVerbAdditionalPawns[i].equipment.AllEquipmentVerbs
                                 where x.verbProps == targetingVerb.verbProps
                                 select x).FirstOrDefault <Verb>();
                    if (verb != null)
                    {
                        CastPawnVerb(verb);
                    }
                }
            }
            else if (targetingVerb.caster is Building_Turret)
            {
                TargetInfo targ = TargetInfo.Invalid;
                if (targetingVerb.CanTargetCell)
                {
                    targ = Gen.MouseCell();
                    if (!targ.Cell.InBounds())
                    {
                        targ = TargetInfo.Invalid;
                    }
                }
                using (IEnumerator <TargetInfo> enumerator = GenUI.TargetsAtMouse(targetingVerb.verbProps.targetParams, false).GetEnumerator())
                {
                    if (enumerator.MoveNext())
                    {
                        TargetInfo current = enumerator.Current;
                        targ = current;
                    }
                }

                ((Building_Turret)targetingVerb.caster).OrderAttack(targ);
            }
            else if (targetingVerb.caster is Vehicle_Turret)
            {
                TargetInfo targ = TargetInfo.Invalid;
                if (targetingVerb.CanTargetCell)
                {
                    targ = Gen.MouseCell();
                    if (!targ.Cell.InBounds())
                    {
                        targ = TargetInfo.Invalid;
                    }
                }
                using (IEnumerator <TargetInfo> enumerator = GenUI.TargetsAtMouse(targetingVerb.verbProps.targetParams, false).GetEnumerator())
                {
                    if (enumerator.MoveNext())
                    {
                        TargetInfo current = enumerator.Current;
                        targ = current;
                    }
                }

                ((Vehicle_Turret)targetingVerb.caster).OrderAttack(targ);
            }
        }
Example #7
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);
        }