public static Toil GotoCastPosition(TargetIndex targetInd, bool closeIfDowned = false, float maxRangeFactor = 1f) { Toil toil = new Toil(); toil.initAction = delegate { Pawn actor = toil.actor; Job curJob = actor.jobs.curJob; Thing thing = curJob.GetTarget(targetInd).Thing; Pawn pawn = thing as Pawn; CastPositionRequest newReq = default(CastPositionRequest); newReq.caster = toil.actor; newReq.target = thing; newReq.verb = curJob.verbToUse; newReq.maxRangeFromTarget = ((!closeIfDowned || pawn == null || !pawn.Downed) ? Mathf.Max(curJob.verbToUse.verbProps.range * maxRangeFactor, 1.42f) : Mathf.Min(curJob.verbToUse.verbProps.range, pawn.RaceProps.executionRange)); newReq.wantCoverFromTarget = false; if (!CastPositionFinder.TryFindCastPosition(newReq, out IntVec3 dest)) { toil.actor.jobs.EndCurrentJob(JobCondition.Incompletable); } else { toil.actor.pather.StartPath(dest, PathEndMode.OnCell); actor.Map.pawnDestinationReservationManager.Reserve(actor, curJob, dest); } }; toil.FailOnDespawnedOrNull(targetInd); toil.defaultCompleteMode = ToilCompleteMode.PatherArrival; return(toil); }
public static Toil GotoCastPosition(TargetIndex targetInd, bool closeIfDowned = false, float maxRangeFactor = 1f) { Toil toil = new Toil(); toil.initAction = delegate() { Pawn actor = toil.actor; Job curJob = actor.jobs.curJob; Thing thing = curJob.GetTarget(targetInd).Thing; Pawn pawn = thing as Pawn; IntVec3 intVec; if (!CastPositionFinder.TryFindCastPosition(new CastPositionRequest { caster = toil.actor, target = thing, verb = curJob.verbToUse, maxRangeFromTarget = ((closeIfDowned && pawn != null && pawn.Downed) ? Mathf.Min(curJob.verbToUse.verbProps.range, (float)pawn.RaceProps.executionRange) : Mathf.Max(curJob.verbToUse.verbProps.range * maxRangeFactor, 1.42f)), wantCoverFromTarget = false }, out intVec)) { toil.actor.jobs.EndCurrentJob(JobCondition.Incompletable, true); return; } toil.actor.pather.StartPath(intVec, PathEndMode.OnCell); actor.Map.pawnDestinationReservationManager.Reserve(actor, curJob, intVec); }; toil.FailOnDespawnedOrNull(targetInd); toil.defaultCompleteMode = ToilCompleteMode.PatherArrival; return(toil); }
public static Toil GotoCastPosition(TargetIndex targetInd, bool closeIfDowned = false, float maxRangeFactor = 1f) { Toil toil = new Toil(); toil.initAction = () => { Pawn actor = toil.actor; Job curJob = actor.jobs.curJob; Thing targThing = curJob.GetTarget(targetInd).Thing; Pawn targPawn = targThing as Pawn; //We get closer if the target is downed and we can CastPositionRequest req = new CastPositionRequest(); req.caster = toil.actor; req.target = targThing; req.verb = curJob.verbToUse; req.maxRangeFromTarget = (!closeIfDowned || targPawn == null || !targPawn.Downed) ? Mathf.Max(curJob.verbToUse.verbProps.range * maxRangeFactor, ShootTuning.MeleeRange) : Mathf.Min(curJob.verbToUse.verbProps.range, targPawn.RaceProps.executionRange); req.wantCoverFromTarget = false; IntVec3 dest; if (!CastPositionFinder.TryFindCastPosition(req, out dest)) { toil.actor.jobs.EndCurrentJob(JobCondition.Incompletable); return; } toil.actor.pather.StartPath(dest, PathEndMode.OnCell); actor.Map.pawnDestinationReservationManager.Reserve(actor, curJob, dest); }; toil.FailOnDespawnedOrNull(targetInd); toil.defaultCompleteMode = ToilCompleteMode.PatherArrival; return(toil); }