Пример #1
0
        protected override Job TryGiveJob(Pawn pawn)
        {
            PawnAutocleaner cleaner = pawn as PawnAutocleaner;

            if (cleaner == null)
            {
                return(null);
            }
            if (!cleaner.active)
            {
                return(null);
            }

            Map map = pawn.Map;

            if (map == null)
            {
                return(null);
            }
            if (SuitablePosition(pawn.Position, map))
            {
                return(null);
            }

            IntVec3 target = Autocleaner.settings.lowQualityPathing ? FindSuitablePositionRandom(pawn, map, pawn.Position) : FindSuitablePosition(pawn, map, pawn.Position);

            if (target != IntVec3.Invalid)
            {
                Job job = JobMaker.MakeJob(Globals.AutocleanerGoto, target);
                return(job);
            }

            return(null);
        }
        protected override Job TryGiveJob(Pawn pawn)
        {
            PawnAutocleaner cleaner = pawn as PawnAutocleaner;

            if (cleaner == null)
            {
                return(null);
            }
            if (!cleaner.active)
            {
                return(null);
            }
            if (cleaner.health.summaryHealth.SummaryHealthPercent >= 1)
            {
                return(null);
            }
            if (cleaner.charge < cleaner.AutoDef.charge * 0.75f)
            {
                return(null);
            }

            Job job = JobMaker.MakeJob(Globals.AutocleanerWaitForRepair);

            return(job);
        }
        protected override IEnumerable <Toil> MakeNewToils()
        {
            this.FailOnDespawnedNullOrForbidden(TargetIndex.A);
            yield return(Toils_Goto.GotoThing(TargetIndex.B, PathEndMode.Touch).FailOnDespawnedNullOrForbidden(TargetIndex.B).FailOnSomeonePhysicallyInteracting(TargetIndex.B));

            yield return(Toils_Haul.StartCarryThing(TargetIndex.B, false, false, false));

            yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.Touch));

            float workNeeded = 1000;
            float workDone   = 0;
            Toil  repair     = new Toil();

            repair.tickAction = delegate()
            {
                Pawn actor = repair.actor;
                actor.skills.Learn(SkillDefOf.Construction, 0.05f, false);
                float num = actor.GetStatValue(StatDefOf.ConstructionSpeed, true) * 1.7f;
                workDone += num;
                if (workDone >= workNeeded)
                {
                    PawnAutocleaner cleaner = TargetThingA as PawnAutocleaner;
                    if (cleaner == null)
                    {
                        EndJobWith(JobCondition.Incompletable);
                        return;
                    }

                    cleaner.health.Reset();

                    job.GetTarget(TargetIndex.B).Thing.Destroy(DestroyMode.Vanish);
                    actor.records.Increment(RecordDefOf.ThingsRepaired);

                    EffecterDefOf.Deflect_Metal.Spawn().Trigger(job.targetA.Thing, pawn);
                    EndJobWith(JobCondition.Succeeded);
                }
            };
            repair.defaultCompleteMode = ToilCompleteMode.Never;
            repair.activeSkill         = () => SkillDefOf.Construction;
            repair.FailOnDespawnedOrNull(TargetIndex.A);
            repair.WithProgressBar(TargetIndex.A, () => workDone / workNeeded, false, -0.5f);
            repair.FailOnCannotTouch(TargetIndex.A, PathEndMode.Touch);
            repair.WithEffect(TargetThingA.def.repairEffect, TargetIndex.A);
            yield return(repair);

            yield break;
        }
Пример #4
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            PawnAutocleaner   cleaner = pawn as PawnAutocleaner;
            AutocleanerJobDef def     = job.def as AutocleanerJobDef;

            if (cleaner == null || def == null)
            {
                EndJobWith(JobCondition.Incompletable);
                yield break;
            }

            yield return(new Toil()
            {
                initAction = delegate()
                {
                    Map.pawnDestinationReservationManager.Reserve(pawn, job, pawn.Position);
                    pawn.pather.StopDead();
                },
                tickAction = delegate()
                {
                    if (!pawn.IsHashIntervalTick(60))
                    {
                        return;
                    }

                    if (cleaner.charge < cleaner.AutoDef.charge * 0.75f)
                    {
                        EndJobWith(JobCondition.InterruptForced);
                        return;
                    }
                    if (cleaner.health.summaryHealth.SummaryHealthPercent >= 1)
                    {
                        EndJobWith(JobCondition.Succeeded);
                        return;
                    }
                },
                defaultCompleteMode = ToilCompleteMode.Never,
            });

            yield break;
        }
        protected override Job TryGiveJob(Pawn pawn)
        {
            PawnAutocleaner cleaner = pawn as PawnAutocleaner;

            if (cleaner == null)
            {
                return(null);
            }
            if (!cleaner.active)
            {
                return(null);
            }
            if (cleaner.LowPower)
            {
                return(null);
            }
            if (cleaner.health.summaryHealth.SummaryHealthPercent < 1)
            {
                return(null);
            }

            WorkGiverCleanFilth scanner = Globals.AutocleanerCleanFilth.Worker as WorkGiverCleanFilth;

            if (scanner == null)
            {
                return(null);
            }

            IEnumerable <Thing> enumerable = scanner.PotentialWorkThingsGlobal(pawn).Where(x => scanner.HasJobOnThing(pawn, x));
            Danger maxDanger = (pawn.playerSettings != null && pawn.playerSettings.UsesConfigurableHostilityResponse && pawn.playerSettings.hostilityResponse != HostilityResponseMode.Flee) ? Danger.Deadly : Danger.None;
            Thing  thing     = GenClosest.ClosestThing_Global_Reachable(pawn.Position, pawn.Map, enumerable, scanner.PathEndMode, TraverseParms.For(pawn, maxDanger, TraverseMode.ByPawn, false), 9999f);

            if (thing == null)
            {
                return(null);
            }

            Job job = scanner.JobOnThing(pawn, thing, false);

            return(job);
        }
Пример #6
0
        protected override Job TryGiveJob(Pawn pawn)
        {
            PawnAutocleaner cleaner = pawn as PawnAutocleaner;

            if (cleaner == null)
            {
                return(null);
            }
            if (!cleaner.active)
            {
                return(null);
            }
            if (cleaner.charge >= cleaner.AutoDef.charge)
            {
                return(null);
            }

            Job job = JobMaker.MakeJob(Globals.AutocleanerCharge);

            return(job);
        }
Пример #7
0
        public override bool HasJobOnThing(Pawn pawn, Thing t, bool forced = false)
        {
            PawnAutocleaner cleaner = t as PawnAutocleaner;

            if (cleaner == null || !cleaner.Broken)
            {
                return(false);
            }

            if (cleaner.CurJobDef == Globals.AutocleanerClean || cleaner.CurJobDef == Globals.AutocleanerGoto)
            {
                JobFailReason.Is("AutocleanerNotStationary".Translate(), null);
                return(false);
            }

            if (FindClosestComponent(pawn) == null)
            {
                JobFailReason.Is("NoComponentsToRepair".Translate(), null);
                return(false);
            }

            return(pawn.CanReserve(t, 1, -1, null, forced));
        }
        protected override IEnumerable <Toil> MakeNewToils()
        {
            PawnAutocleaner   cleaner = pawn as PawnAutocleaner;
            AutocleanerJobDef def     = job.def as AutocleanerJobDef;

            CompPowerTrader comp = pawn.TryGetComp <CompPowerTrader>();

            if (comp != null)
            {
                PowerConnectionMaker.DisconnectFromPowerNet(comp);
            }

            Toil initExtractTargetFromQueue = Toils_JobTransforms.ClearDespawnedNullOrForbiddenQueuedTargets(TargetIndex.A, null);

            yield return(initExtractTargetFromQueue);

            yield return(Toils_JobTransforms.SucceedOnNoTargetInQueue(TargetIndex.A));

            yield return(Toils_JobTransforms.ExtractNextTargetFromQueue(TargetIndex.A, true));

            yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.OnCell).JumpIfDespawnedOrNullOrForbidden(TargetIndex.A, initExtractTargetFromQueue).JumpIfOutsideHomeArea(TargetIndex.A, initExtractTargetFromQueue));

            Toil clean = new Toil();

            clean.initAction = delegate()
            {
                cleaningWorkDone          = 0f;
                totalCleaningWorkDone     = 0f;
                totalCleaningWorkRequired = Filth.def.filth.cleaningWorkToReduceThickness * Filth.thickness;
            };
            clean.tickAction = delegate()
            {
                Filth filth = Filth;
                cleaningWorkDone      += 1f;
                totalCleaningWorkDone += 1f;

                if (cleaner != null && def != null)
                {
                    cleaner.charge -= def.activeDischargePerSecond / cleaner.AutoDef.dischargePeriodTicks;

                    if (cleaner.LowPower)
                    {
                        EndJobWith(JobCondition.Incompletable);
                        return;
                    }
                }

                if (cleaningWorkDone > filth.def.filth.cleaningWorkToReduceThickness)
                {
                    filth.ThinFilth();
                    cleaningWorkDone = 0f;
                    if (filth.Destroyed)
                    {
                        clean.actor.records.Increment(RecordDefOf.MessesCleaned);
                        ReadyForNextToil();
                        return;
                    }
                }
            };
            clean.defaultCompleteMode = ToilCompleteMode.Never;
            clean.WithProgressBar(TargetIndex.A, () => totalCleaningWorkDone / totalCleaningWorkRequired, true, -0.5f);
            clean.PlaySustainerOrSound(() => SoundDefOf.Interact_CleanFilth);
            clean.JumpIfDespawnedOrNullOrForbidden(TargetIndex.A, initExtractTargetFromQueue);
            clean.JumpIfOutsideHomeArea(TargetIndex.A, initExtractTargetFromQueue);
            yield return(clean);

            yield return(Toils_Jump.Jump(initExtractTargetFromQueue));

            yield break;
        }