//[DebuggerHidden]
        protected override IEnumerable <Toil> MakeNewToils()
        {
            ProblemWorker_Hacker pw = GetProblemWorker();

            if (pw == null)
            {
                yield break;
            }
            this.AddEndCondition(() => pw.IsRunning() && !pw.HasHackingStopped() && (TargetThingA.TryGetComp <CompHacked>()?.investigatable ?? false)
                                ? JobCondition.Ongoing : JobCondition.Incompletable);
            this.FailOnDespawnedNullOrForbidden(TargetIndex.A);
            yield return(Toils_Reserve.Reserve(TargetIndex.A, 1));

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

            Toil doWork = new Toil().FailOnDestroyedNullOrForbidden(TargetIndex.A).FailOnCannotTouch(TargetIndex.A, PathEndMode.Touch);

            doWork.initAction = () => {
                this.totalWorkNeeded = 300f;
                this.workLeft        = this.totalWorkNeeded;
            };
            doWork.tickAction = () => {
                this.workLeft -= this.pawn.GetStatValue(StatDefOf.ResearchSpeed, true);
                this.pawn.skills.GetSkill(SkillDefOf.Intellectual).Learn(5f, false);
                if (this.workLeft <= 0f)
                {
                    doWork.actor.jobs.curDriver.ReadyForNextToil();
                }
            };
            doWork.defaultCompleteMode = ToilCompleteMode.Never;
            doWork.WithProgressBar(TargetIndex.A, () => 1f - this.workLeft / this.totalWorkNeeded, false, -0.5f);
            yield return(doWork);

            Toil foundEm = new Toil();

            foundEm.defaultCompleteMode = ToilCompleteMode.Instant;
            foundEm.initAction          = delegate {
                ResearchProjectDef current = Find.ResearchManager.currentProj;
                Find.ResearchManager.currentProj = DefDatabase <ResearchProjectDef> .GetNamed("HackingCountermeasures");

                Find.ResearchManager.ResearchPerformed(500 / 0.007f, null);                     //Constant from inside ResearchManager
                Find.ResearchManager.currentProj = current;
                this.pawn.skills.GetSkill(SkillDefOf.Intellectual).Learn(500f, false);
                TargetThingA.TryGetComp <CompHacked>().investigatable = false;
                Find.LetterStack.ReceiveLetter("ProblemHackerInvestigateHackingLetterLabel".Translate(),
                                               "ProblemHackerInvestigateHackingLetterText".Translate(this.pawn.NameStringShort), LetterDefOf.PositiveEvent);
            };
            yield return(foundEm);
        }
Beispiel #2
0
        //[DebuggerHidden]
        protected override IEnumerable <Toil> MakeNewToils()
        {
            ProblemWorker_Hacker pw = GetProblemWorker();

            if (pw == null)
            {
                yield break;
            }
            this.AddEndCondition(() => pw.IsRunning() && !pw.HasHackingStopped() && TargetThingA.TryGetComp <CompHacked>() != null
                                ? JobCondition.Ongoing : JobCondition.Incompletable);
            this.FailOnDespawnedNullOrForbidden(TargetIndex.A);
            yield return(Toils_Reserve.Reserve(TargetIndex.A, 1));

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

            Toil doWork = new Toil().FailOnDestroyedNullOrForbidden(TargetIndex.A).FailOnCannotTouch(TargetIndex.A, PathEndMode.Touch);

            doWork.initAction = () => {
                this.totalWorkNeeded = 100f;
                this.workLeft        = this.totalWorkNeeded;
            };
            doWork.tickAction = () => {
                this.workLeft -= this.pawn.GetStatValue(StatDefOf.ResearchSpeed, true);
                this.pawn.skills.GetSkill(SkillDefOf.Intellectual).Learn(5f, false);
                if (this.workLeft <= 0f)
                {
                    doWork.actor.jobs.curDriver.ReadyForNextToil();
                }
            };
            doWork.defaultCompleteMode = ToilCompleteMode.Never;
            doWork.WithProgressBar(TargetIndex.A, () => 1f - this.workLeft / this.totalWorkNeeded, false, -0.5f);
            yield return(doWork);

            Toil foundEm = new Toil();

            foundEm.defaultCompleteMode = ToilCompleteMode.Instant;
            foundEm.initAction          = delegate {
                FindExt.DynamicComponentManager.RemoveDynamicThingComp <CompHacked> (TargetThingA as ThingWithComps);
            };
            yield return(foundEm);
        }