コード例 #1
0
        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);
        }
コード例 #2
0
        public static Toil WaitWith(TargetIndex targetInd, int ticks, bool useProgressBar = false, bool maintainPosture = false)
        {
            Toil toil = new Toil();

            toil.initAction = delegate
            {
                toil.actor.pather.StopDead();
                Pawn pawn = toil.actor.CurJob.GetTarget(targetInd).Thing as Pawn;
                if (pawn != null)
                {
                    if (pawn == toil.actor)
                    {
                        Log.Warning("Executing WaitWith toil but otherPawn is the same as toil.actor", false);
                    }
                    else
                    {
                        Pawn pawn2            = pawn;
                        int  ticks2           = ticks;
                        bool maintainPosture2 = maintainPosture;
                        PawnUtility.ForceWait(pawn2, ticks2, null, maintainPosture2);
                    }
                }
            };
            toil.FailOnDespawnedOrNull(targetInd);
            toil.FailOnCannotTouch(targetInd, PathEndMode.Touch);
            toil.defaultCompleteMode = ToilCompleteMode.Delay;
            toil.defaultDuration     = ticks;
            if (useProgressBar)
            {
                toil.WithProgressBarToilDelay(targetInd, false, -0.5f);
            }
            return(toil);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        public static Toil GotoThing(TargetIndex ind, IntVec3 exactCell)
        {
            Toil toil = new Toil();

            toil.initAction = delegate
            {
                toil.actor.pather.StartPath(exactCell, PathEndMode.OnCell);
            };
            toil.defaultCompleteMode = ToilCompleteMode.PatherArrival;
            toil.FailOnDespawnedOrNull(ind);
            return(toil);
        }
コード例 #5
0
        public static Toil GotoThing(TargetIndex ind, PathEndMode peMode)
        {
            Toil toil = new Toil();

            toil.initAction = delegate
            {
                Pawn actor = toil.actor;
                actor.pather.StartPath(actor.jobs.curJob.GetTarget(ind), peMode);
            };
            toil.defaultCompleteMode = ToilCompleteMode.PatherArrival;
            toil.FailOnDespawnedOrNull(ind);
            return(toil);
        }
コード例 #6
0
        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);
        }