Beispiel #1
0
        // ReSharper disable once InconsistentNaming
        public static void Postfix_JobDriver_Wait_CheckForAutoAttack(JobDriver_Wait __instance)
        {
            if (__instance.pawn.Downed ||
                __instance.pawn.stances.FullBodyBusy ||
                !__instance.pawn.RaceProps.Animal ||
                !__instance.job.canUseRangedWeapon ||
                __instance.job.def != JobDefOf.Wait_Combat)
            {
                return;
            }
            var currentEffectiveVerb = __instance.pawn.CurrentEffectiveVerb;

            if (currentEffectiveVerb == null || currentEffectiveVerb.verbProps.IsMeleeAttack)
            {
                return;
            }
            var flags = TargetScanFlags.NeedLOSToAll | TargetScanFlags.NeedThreat | TargetScanFlags.NeedAutoTargetable;

            if (currentEffectiveVerb.IsIncendiary())
            {
                flags |= TargetScanFlags.NeedNonBurning;
            }
            var thing = (Thing)AttackTargetFinder.BestShootTargetFromCurrentPosition(__instance.pawn, flags);

            if (thing == null)
            {
                return;
            }
            __instance.pawn.TryStartAttack((LocalTargetInfo)thing);
            __instance.collideWithPawns = true;
        }
 public static bool Prefix(ref JobDriver_Wait __instance, Toil wait)
 {
     // Default to Amble since it instead defaults to Job
     // This causes disallowedLocomotionUrgencies to be difficult to use otherwise for non-action pawns
     __instance.job.locomotionUrgency = LocomotionUrgency.Amble;
     return(true);
 }
 private static void JobDriver_Wait_CheckForAutoAttackPostfix(JobDriver_Wait __instance)
 {
     if (__instance.pawn.Faction != null || __instance.pawn.Downed || __instance.pawn.stances.FullBodyBusy)
     {
         return;
     }
     if ((__instance.pawn.story == null || !__instance.pawn.story.WorkTagIsDisabled(WorkTags.Violent)) && __instance.job.def == JobDefOf.Wait_Combat && (__instance.pawn.drafter == null || __instance.pawn.drafter.FireAtWill))
     {
         Verb currentEffectiveVerb = __instance.pawn.CurrentEffectiveVerb;
         if (currentEffectiveVerb != null && !currentEffectiveVerb.verbProps.IsMeleeAttack)
         {
             TargetScanFlags targetScanFlags = TargetScanFlags.NeedLOSToPawns | TargetScanFlags.NeedLOSToNonPawns | TargetScanFlags.NeedThreat;
             if (currentEffectiveVerb.IsIncendiary())
             {
                 targetScanFlags |= TargetScanFlags.NeedNonBurning;
             }
             Thing thing = (Thing)AttackTargetFinder.BestShootTargetFromCurrentPosition(__instance.pawn, targetScanFlags, null, 0f, 9999f);
             if (thing != null)
             {
                 __instance.pawn.TryStartAttack(thing);
                 __instance.collideWithPawns = true;
                 return;
             }
         }
     }
     return;
 }
        public static void DoBehaviorForPawn(JobDriver_Wait driver)
        {
            var hunter = driver.pawn;

            if (!AllowToolController.Instance.Handles.PartyHuntSetting || !WorldSettings.PawnIsPartyHunting(hunter))
            {
                return;
            }
            var verb = hunter.TryGetAttackVerb(null, !hunter.IsColonist);

            if (hunter.Faction != null &&
                driver.job.def == JobDefOf.Wait_Combat &&
                AllowToolUtility.PawnCapableOfViolence(hunter) &&
                !hunter.stances.FullBodyBusy)
            {
                // fire at target
                if (hunter.drafter.FireAtWill)
                {
                    // fudge melee range for easier target acquisition
                    var weaponRange = verb.verbProps.IsMeleeAttack ? 2 : verb.verbProps.range;
                    var target      = TryFindHuntingTarget(hunter, verb.verbProps.minRange, weaponRange, HuntingTargetAttackFilter);
                    if (target != null)
                    {
                        hunter.TryStartAttack(target);
                        ResetAutoUndraftTimer(hunter.drafter);
                        if (target.Dead && WorldSettings.UnforbidDrops)
                        {
                            target.Corpse?.SetForbidden(false, false);
                        }
                    }
                }

                // finish off targets. Wait for everyone to finish firing to avoid catching stray bullets
                if (!hunter.stances.FullBodyBusy && WorldSettings.AutoFinishOff &&
                    CanDoCommonerWork(hunter) && !AnyHuntingPartyMembersInCombat(hunter, MaxPartyMemberDistance))
                {
                    // try mark a downed animal
                    var target = TryFindHuntingTarget(hunter, 0, MaxFinishOffDistance, HuntingTargetFinishFilter);
                    if (target != null)
                    {
                        target.ToggleDesignation(AllowToolDefOf.FinishOffDesignation, true);
                    }
                    // query work giver for finish off job in range
                    var job = WorkGiver_FinishOff.CreateInstance().TryGetJobInRange(hunter, MaxFinishOffDistance);
                    if (job != null)
                    {
                        hunter.jobs.StartJob(job, JobCondition.Ongoing, null, true);
                        if (hunter.jobs.curDriver is JobDriver_FinishOff jdfo && WorldSettings.UnforbidDrops)
                        {
                            jdfo.UnforbidBody = true;
                        }
                        // return to starting position
                        hunter.jobs.jobQueue.EnqueueFirst(JobMaker.MakeJob(JobDefOf.Goto, hunter.Position));
                    }
                }
            }
        }
Beispiel #5
0
 private static void VerbGiverExtended(JobDriver_Wait __instance)
 {
     if (__instance.pawn.Downed)
     {
         return;
     }
     if (__instance.pawn.Faction != null && __instance.job.def == JobDefOf.Wait_Combat && (__instance.pawn.drafter == null || __instance.pawn.drafter.FireAtWill))
     {
         PCF_VanillaExtender.CheckForAutoAttack(__instance);
     }
 }
 public static void DoPartyHunting(JobDriver_Wait __instance)
 {
     PartyHuntController.DoBehaviorForPawn(__instance);
 }
Beispiel #7
0
 public static bool PreFix(ref JobDriver_Wait __instance)
 {
     return(__instance.pawn == null || ThingCompUtility.TryGetComp <PawnCamoData>(__instance.pawn).LastCamoCorrectTick + 120 <= Find.TickManager.TicksGame);
 }