Ejemplo n.º 1
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            this.FailOnDespawnedNullOrForbidden(TargetIndex.A);
            yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.InteractionCell));

            Toil research = new Toil();

            research.tickAction = delegate
            {
                Pawn  actor = research.actor;
                float num   = 1.1f * actor.GetStatValue(StatDefOf.ResearchSpeed, true);
                num *= this.$this.TargetThingA.GetStatValue(StatDefOf.ResearchSpeedFactor, true);
                Find.ResearchManager.ResearchPerformed(num, actor);
                actor.skills.Learn(SkillDefOf.Intellectual, 0.11f, false);
                actor.GainComfortFromCellIfPossible();
            };
            research.FailOn(() => this.$this.Project == null);
            research.FailOn(() => !this.$this.Project.CanBeResearchedAt(this.$this.ResearchBench, false));
            research.FailOnCannotTouch(TargetIndex.A, PathEndMode.InteractionCell);
            research.WithEffect(EffecterDefOf.Research, TargetIndex.A);
            research.WithProgressBar(TargetIndex.A, delegate
            {
                ResearchProjectDef project = this.$this.Project;
                if (project == null)
                {
                    return(0f);
                }
                return(project.ProgressPercent);
            }, false, -0.5f);
            research.defaultCompleteMode = ToilCompleteMode.Delay;
            research.defaultDuration     = 4000;
            yield return(research);

            yield return(Toils_General.Wait(2));
        }
        protected override IEnumerable <Toil> MakeNewToils()
        {
            this.FailOnDespawnedNullOrForbidden(TargetIndex.A);
            this.FailOnCellMissingDesignation(TargetIndex.A, DesignationDefOf.Mine);
            yield return(Toils_Reserve.Reserve(TargetIndex.A, 1, -1, null));

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

            var mine = new Toil();

            mine.tickAction = delegate
            {
                var actor      = mine.actor;
                var mineTarget = MineTarget;
                if (ticksToPickHit < -100)
                {
                    ResetTicksToPickHit();
                }
                if (actor.skills != null)
                {
                    actor.skills.Learn(SkillDefOf.Mining, 0.11f, false);
                }
                ticksToPickHit--;
                if (ticksToPickHit <= 0)
                {
                    var position = mineTarget.Position;
                    if (effecter == null)
                    {
                        effecter = EffecterDefOf.Mine.Spawn();
                    }
                    effecter.Trigger(actor, mineTarget);
                    var num      = 80;
                    var mineable = mineTarget as Mineable;
                    if (mineable == null || mineTarget.HitPoints > num)
                    {
                        var actor2 = mine.actor;
                        var dinfo  = new DamageInfo(DamageDefOf.Mining, num, -1f, actor2, null, null,
                                                    DamageInfo.SourceCategory.ThingOrUnknown);
                        mineTarget.TakeDamage(dinfo);
                    }
                    else
                    {
                        mineable.DestroyMined(actor);
                    }
                    if (mineTarget.Destroyed)
                    {
                        actor.Map.mineStrikeManager.CheckStruckOre(position, mineTarget.def, actor);
                        actor.records.Increment(RecordDefOf.CellsMined);
                        ReadyForNextToil();
                        return;
                    }
                    ResetTicksToPickHit();
                }
            };
            mine.defaultCompleteMode = ToilCompleteMode.Never;
            mine.WithProgressBar(TargetIndex.A,
                                 () => 1f - (float)MineTarget.HitPoints / (float)MineTarget.MaxHitPoints, false, -0.5f);
            mine.FailOnCannotTouch(TargetIndex.A, PathEndMode.Touch);
            yield return(mine);
        }
Ejemplo n.º 3
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            yield return(Toils_Goto.GotoCell(TargetIndex.A, PathEndMode.Touch));

            Toil clearToil = new Toil();

            clearToil.tickAction = delegate
            {
                Pawn  actor     = clearToil.actor;
                float statValue = actor.GetStatValue(StatDefOf.UnskilledLaborSpeed, true);
                float num       = statValue;
                this.$this.workDone += num;
                if (this.$this.workDone >= this.$this.TotalNeededWork)
                {
                    this.$this.Map.snowGrid.SetDepth(this.$this.TargetLocA, 0f);
                    this.$this.ReadyForNextToil();
                    return;
                }
            };
            clearToil.defaultCompleteMode = ToilCompleteMode.Never;
            clearToil.WithEffect(EffecterDefOf.ClearSnow, TargetIndex.A);
            clearToil.PlaySustainerOrSound(() => SoundDefOf.Interact_CleanFilth);
            clearToil.WithProgressBar(TargetIndex.A, () => this.$this.workDone / this.$this.TotalNeededWork, true, -0.5f);
            clearToil.FailOnCannotTouch(TargetIndex.A, PathEndMode.Touch);
            yield return(clearToil);
        }
Ejemplo n.º 4
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            this.FailOn(condition: () => !this.Comp.CanDrillNow());
            yield return(Toils_Goto.GotoThing(ind: TargetIndex.A, peMode: PathEndMode.Touch).FailOnDespawnedNullOrForbidden(ind: TargetIndex.A));

            Toil mine = new Toil();

            mine.WithEffect(effectDef: EffecterDefOf.Drill, ind: TargetIndex.A);
            mine.WithProgressBar(ind: TargetIndex.A, progressGetter: () => this.Comp.Progress);
            mine.tickAction = delegate
            {
                Pawn minePawn = mine.actor;
                this.Comp.Drill(miningPoints: minePawn.GetStatValue(stat: StatDefOf.MiningSpeed) / TICKS);
                minePawn.skills.Learn(sDef: SkillDefOf.Mining, xp: 0.125f);
                if (!(this.Comp.Progress >= 1))
                {
                    return;
                }
                this.Comp.DrillWorkDone(driller: minePawn);
                this.EndJobWith(condition: JobCondition.Succeeded);
                minePawn.records.Increment(def: RecordDefOf.CellsMined);
            };
            mine.WithEffect(effectDef: this.TargetThingA.def.repairEffect, ind: TargetIndex.A);
            mine.defaultCompleteMode = ToilCompleteMode.Never;
            yield return(mine);
        }
Ejemplo n.º 5
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            Toil doFor = new Toil()
            {
                initAction = () =>
                {
                    if (this.age > this.durationTicks)
                    {
                        this.EndJobWith(JobCondition.InterruptForced);
                    }
                },
                tickAction = () =>
                {
                    if (age > durationTicks)
                    {
                        this.EndJobWith(JobCondition.Succeeded);
                    }
                    age++;
                },
                defaultCompleteMode = ToilCompleteMode.Never
            };

            doFor.defaultDuration = this.durationTicks;
            doFor.WithProgressBar(TargetIndex.A, delegate
            {
                if (this.pawn.DestroyedOrNull() || this.pawn.Dead || this.pawn.Downed)
                {
                    return(1f);
                }
                return(1f - ((float)doFor.actor.jobs.curDriver.ticksLeftThisToil / this.durationTicks));
            }, false, 0f);
            yield return(doFor);
        }
        protected override IEnumerable <Toil> MakeNewToils()
        {
            this.FailOnDespawnedOrNull(TargetIndex.B);
            yield return(Toils_Goto.Goto(TargetIndex.B, this.PathEndMode));

            Toil doWork = new Toil();

            doWork.initAction = delegate()
            {
                this.workLeft = 65f;
            };
            doWork.tickAction = delegate()
            {
                float statValue = doWork.actor.GetStatValue(StatDefOf.ConstructionSpeed, true);
                this.workLeft -= statValue;
                if (this.workLeft <= 0f)
                {
                    this.DoEffect();
                    this.ReadyForNextToil();
                }
            };
            doWork.FailOnCannotTouch(TargetIndex.B, this.PathEndMode);
            doWork.PlaySoundAtStart(SoundDefOf.Roof_Start);
            doWork.PlaySoundAtEnd(SoundDefOf.Roof_Finish);
            doWork.WithEffect(EffecterDefOf.RoofWork, TargetIndex.A);
            doWork.FailOn(new Func <bool>(this.DoWorkFailOn));
            doWork.WithProgressBar(TargetIndex.A, () => 1f - this.workLeft / 65f, false, -0.5f);
            doWork.defaultCompleteMode = ToilCompleteMode.Never;
            yield return(doWork);

            yield break;
        }
Ejemplo n.º 7
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            this.FailOn(() => {
                if (this.Comp.CanDrillNow())
                {
                    return(false);
                }
                return(true);
            });
            yield return(Toils_Reserve.Reserve(TargetIndex.A).FailOnDespawnedNullOrForbidden(TargetIndex.A));

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

            Toil mine = new Toil();

            mine.WithEffect(EffecterDefOf.Drill, TargetIndex.A);
            mine.WithProgressBar(TargetIndex.A, () => this.Comp.Progress);
            mine.tickAction = delegate
            {
                Pawn pawn = mine.actor;
                this.Comp.Drill(pawn.GetStatValue(StatDefOf.MiningSpeed) / ticks);
                pawn.skills.Learn(SkillDefOf.Mining, 0.125f);
                if (this.Comp.Progress >= 1)
                {
                    this.Comp.DrillWorkDone(pawn);
                    EndJobWith(JobCondition.Succeeded);
                    pawn.records.Increment(RecordDefOf.CellsMined);
                }
            };
            mine.WithEffect(this.TargetThingA.def.repairEffect, TargetIndex.A);
            mine.defaultCompleteMode = ToilCompleteMode.Never;
            yield return(mine);
        }
Ejemplo n.º 8
0
        private Toil DoWork()
        {
            Toil doWork = new Toil()
                          .FailOnDespawnedOrNull(TargetIndex.A)
                          .FailOnCannotTouch(TargetIndex.A, PathEndMode.Touch);

            doWork.initAction = delegate
            {
                workLeft          = InitialNeededWork;
                initialNeededWork = workLeft;
            };

            doWork.tickAction = delegate
            {
                workLeft -= this.pawn.GetStatValue(StatDefOf.ConstructionSpeed);
                // do pawn skill increment, or f**k it doesn't matter?
                if (workLeft <= 0f)
                {
                    doWork.actor.jobs.curDriver.ReadyForNextToil();
                }
            };

            doWork.defaultCompleteMode = ToilCompleteMode.Never;

            return(doWork.WithProgressBar(TargetIndex.A, () => 1f - workLeft / initialNeededWork));
        }
Ejemplo n.º 9
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            this.FailOn(() => (!job.ignoreDesignations && base.Map.designationManager.DesignationAt(base.TargetLocA, DesDef) == null) ? true : false);
            this.FailOnDespawnedNullOrForbidden(TargetIndex.A);
            yield return(Toils_Goto.GotoCell(TargetIndex.A, PathEndMode.Touch));

            Toil doWork = new Toil();

            doWork.initAction = delegate
            {
                workLeft = BaseWorkAmount;
            };
            doWork.tickAction = delegate
            {
                float num = doWork.actor.GetStatValue(StatDefOf.SmoothingSpeed) * 1.7f;
                workLeft -= num;
                if (doWork.actor.skills != null)
                {
                    doWork.actor.skills.Learn(SkillDefOf.Construction, 0.1f);
                }
                if (workLeft <= 0f)
                {
                    DoEffect();
                    base.Map.designationManager.DesignationAt(base.TargetLocA, DesDef)?.Delete();
                    ReadyForNextToil();
                }
            };
            doWork.FailOnCannotTouch(TargetIndex.A, PathEndMode.Touch);
            doWork.WithProgressBar(TargetIndex.A, () => 1f - workLeft / (float)BaseWorkAmount);
            doWork.defaultCompleteMode = ToilCompleteMode.Never;
            doWork.activeSkill         = () => SkillDefOf.Construction;
            yield return(doWork);
        }
Ejemplo n.º 10
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            yield return(Toils_Reserve.Reserve(TargetIndex.A, 1, -1, null));

            yield return(Toils_Reserve.Reserve(TargetIndex.B, 1, -1, null));

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

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

            yield return(Toils_Haul.CarryHauledThingToCell(TargetIndex.B));

            Toil t2 = Toils_General.Wait(1000);

            t2.AddFailCondition(() => !this.Emitter.GetComp <CompPowerTrader>().PowerOn);
            t2 = t2.WithProgressBar(TargetIndex.A, () => (1000f - (float)this.ticksLeftThisToil) / 1000f, false, -0.5f);
            yield return(t2);

            yield return(new Toil
            {
                defaultCompleteMode = ToilCompleteMode.Instant,
                initAction = delegate()
                {
                    Pawn simPawn = this.MakeGeniusPawn();
                    this.Emitter.GetComp <CompHoloEmitter>().SimPawn = simPawn;
                    this.Emitter.GetComp <CompHoloEmitter>().SetUpPawn();
                    this.Disk.Destroy(DestroyMode.Vanish);
                }
            });

            yield return(Toils_Reserve.Release(TargetIndex.B));

            yield break;
        }
Ejemplo n.º 11
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            this.FailOnDespawnedNullOrForbidden(TargetIndex.A);
            yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.InteractionCell));

            Toil research = new Toil();

            research.tickAction = delegate
            {
                Pawn  actor     = research.actor;
                float statValue = actor.GetStatValue(StatDefOf.ResearchSpeed);
                statValue *= base.TargetThingA.GetStatValue(StatDefOf.ResearchSpeedFactor);
                Find.ResearchManager.ResearchPerformed(statValue, actor);
                actor.skills.Learn(SkillDefOf.Intellectual, 0.1f);
                actor.GainComfortFromCellIfPossible(chairsOnly: true);
            };
            research.FailOn(() => Project == null);
            research.FailOn(() => !Project.CanBeResearchedAt(ResearchBench, ignoreResearchBenchPowerStatus: false));
            research.FailOnCannotTouch(TargetIndex.A, PathEndMode.InteractionCell);
            research.WithEffect(EffecterDefOf.Research, TargetIndex.A);
            research.WithProgressBar(TargetIndex.A, () => Project?.ProgressPercent ?? 0f);
            research.defaultCompleteMode = ToilCompleteMode.Delay;
            research.defaultDuration     = 4000;
            research.activeSkill         = () => SkillDefOf.Intellectual;
            yield return(research);

            yield return(Toils_General.Wait(2));
        }
        protected override IEnumerable <Toil> MakeNewToils()
        {
            this.FailOnDespawnedNullOrForbidden(TargetIndex.A);
            this.FailOnDestroyedOrNull(TargetIndex.B);
            this.FailOnDespawnedOrNull(TargetIndex.C);
            yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.Touch));

            Toil doWork = new Toil();

            doWork.initAction = delegate {
                this.totalWorkNeeded = Shelf.CombineWorkNeeded(TargetC.Thing);
                this.workPerformed   = 0;
            };
            doWork.tickAction = delegate {
                this.workPerformed += this.pawn.GetStatValue(StatDefOf.WorkSpeedGlobal, true);
                if (this.workPerformed >= this.totalWorkNeeded)
                {
                    doWork.actor.jobs.curDriver.ReadyForNextToil();
                }
            };
            doWork.defaultCompleteMode = ToilCompleteMode.Never;
            doWork.WithProgressBar(TargetIndex.A, () => this.workPerformed / this.totalWorkNeeded, false, -0.5f);
            yield return(doWork);

            yield return(new Toil {
                initAction = delegate {
                    Shelf.OverstackThings(TargetThingB, TargetC.Thing);
                    this.pawn.Map.reservationManager.Release(this.job.targetA, this.pawn, this.job);
                    this.pawn.Map.reservationManager.Release(this.job.targetC, this.pawn, this.job);
                },
                defaultCompleteMode = ToilCompleteMode.Instant
            });
        }
        protected override IEnumerable <Toil> MakeNewToils()
        {
            yield return(Toils_Goto.GotoCell(TargetIndex.A, PathEndMode.Touch).FailOn(() => PlantUtility.AdjacentSowBlocker(this.job.plantDefToSow, this.TargetA.Cell, this.Map) != null).FailOn(() => !this.job.plantDefToSow.CanEverPlantAt(this.TargetLocA, this.Map)));

            Toil sowToil = new Toil();

            sowToil.initAction = delegate()
            {
                this.TargetThingA = GenSpawn.Spawn(this.job.plantDefToSow, this.TargetLocA, this.Map, WipeMode.Vanish);
                this.pawn.Reserve(this.TargetThingA, sowToil.actor.CurJob, 1, -1, null, true);
                Plant plant = (Plant)this.TargetThingA;
                plant.Growth = 0f;
                plant.sown   = true;
            };
            sowToil.tickAction = delegate()
            {
                Pawn actor = sowToil.actor;
                if (actor.skills != null)
                {
                    actor.skills.Learn(SkillDefOf.Plants, 0.085f, false);
                }
                float statValue = actor.GetStatValue(StatDefOf.PlantWorkSpeed, true);
                float num       = statValue;
                Plant plant     = this.Plant;
                if (plant.LifeStage != PlantLifeStage.Sowing)
                {
                    Log.Error(this.$this + " getting sowing work while not in Sowing life stage.", false);
                }
                this.sowWorkDone += num;
                if (this.sowWorkDone >= plant.def.plant.sowWork)
                {
                    plant.Growth = 0.05f;
                    this.Map.mapDrawer.MapMeshDirty(plant.Position, MapMeshFlag.Things);
                    actor.records.Increment(RecordDefOf.PlantsSown);
                    this.ReadyForNextToil();
                    return;
                }
            };
            sowToil.defaultCompleteMode = ToilCompleteMode.Never;
            sowToil.FailOnDespawnedNullOrForbidden(TargetIndex.A);
            sowToil.FailOnCannotTouch(TargetIndex.A, PathEndMode.Touch);
            sowToil.WithEffect(EffecterDefOf.Sow, TargetIndex.A);
            sowToil.WithProgressBar(TargetIndex.A, () => this.sowWorkDone / this.Plant.def.plant.sowWork, true, -0.5f);
            sowToil.PlaySustainerOrSound(() => SoundDefOf.Interact_Sow);
            sowToil.AddFinishAction(delegate
            {
                if (this.TargetThingA != null)
                {
                    Plant plant = (Plant)sowToil.actor.CurJob.GetTarget(TargetIndex.A).Thing;
                    if (this.sowWorkDone < plant.def.plant.sowWork && !this.TargetThingA.Destroyed)
                    {
                        this.TargetThingA.Destroy(DestroyMode.Vanish);
                    }
                }
            });
            sowToil.activeSkill = (() => SkillDefOf.Plants);
            yield return(sowToil);

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

            startingDurability = Durability;
            var maintenance = new Toil();

            maintenance.tickAction = delegate
            {
                Pawn pawn = maintenance.actor;
                Durability += pawn.GetStatValue(StatDefOf.ConstructionSpeed) / fullRepairTicks;
                pawn.skills.Learn(SkillDefOf.Construction, 0.125f);

                if (Durability > .99f)
                {
                    pawn.records.Increment(RecordDefOf.ThingsRepaired);
                    pawn.jobs.EndCurrentJob(JobCondition.Succeeded);
                }
            };
            maintenance.FailOnCannotTouch(TargetIndex.A, PathEndMode.Touch);
            maintenance.WithEffect(TargetThingA.def.repairEffect, TargetIndex.A);
            maintenance.WithProgressBar(TargetIndex.A, progress, true);
            maintenance.defaultCompleteMode = ToilCompleteMode.Never;
            yield return(maintenance);
        }
Ejemplo n.º 15
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            this.FailOnDestroyedNullOrForbidden(TargetIndex.A);

            Toil mending = new Toil();

            mending.defaultCompleteMode = ToilCompleteMode.Never;
            mending.socialMode          = RandomSocialMode.SuperActive;
            mending.WithProgressBar(TargetIndex.A, () => workDone / mendingWorks);
            mending.PlaySustainerOrSound(SoundDefOf.Interact_CleanFilth);
            mending.tickAction = () =>
            {
                workDone++;
                if (workDone >= mendingWorks)
                {
                    var   thing         = this.job.targetA.Thing;
                    float repairRateMin = 1f / SkillRecord.MaxLevel * 0.1f;
                    float repairRateMax = Math.Max(1, pawn.skills.GetSkill(SkillDefOf.Crafting).Level) / (float)SkillRecord.MaxLevel * 0.1f;
                    float repairRate    = Rand.Range(repairRateMin, repairRateMax);
                    thing.HitPoints = Math.Min(thing.MaxHitPoints, thing.HitPoints + (int)(thing.MaxHitPoints * repairRate));
                    this.ReadyForNextToil();
                }
            };

            yield return(mending);

            yield break;
        }
Ejemplo n.º 16
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            Toil wait = new Toil();

            wait.tickAction = delegate
            {
                Pawn actor = wait.actor;
                this.gatherProgress += actor.GetStatValue(StatDefOf.AnimalGatherSpeed, true);
                if (this.gatherProgress >= this.WorkTotal)
                {
                    Pawn milkedPawn = actor;
                    milkedPawn.TryGetComp <CompMilkableHumanoid>().GatherMilkSelf();
                    actor.jobs.EndCurrentJob(JobCondition.Succeeded, true);
                }
            };

            wait.AddEndCondition(delegate
            {
                Pawn milkedPawn = wait.actor;
                if (!milkedPawn.TryGetComp <CompMilkableHumanoid>().ActiveAndCanBeMilked)
                {
                    return(JobCondition.Incompletable);
                }
                return(JobCondition.Ongoing);
            });
            wait.defaultCompleteMode = ToilCompleteMode.Never;
            wait.WithProgressBar(TargetIndex.A, () => this.gatherProgress / this.WorkTotal, false, -0.5f);
            yield return(wait);
        }
Ejemplo n.º 17
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            yield return(Toils_Goto.GotoCell(TargetIndex.A, PathEndMode.Touch));

            Toil tillCell = new Toil();

            tillCell.initAction = delegate()
            {
                this.workdone = 0f;
            };
            tillCell.tickAction = delegate()
            {
                Pawn  actor     = tillCell.actor;
                float statValue = actor.GetStatValue(StatDefOf.PlantWorkSpeed, true);
                float num       = statValue;
                this.workdone += num;
                if (actor.skills != null)
                {
                    actor.skills.Learn(SkillDefOf.Plants, 0.05f, false);
                }
                if (this.workdone >= this.Map.terrainGrid.TerrainAt(this.TargetA.Cell).GetModExtension <TerrainExtension>().tillWorkAmount)
                {
                    this.Map.terrainGrid.SetTerrain(TargetLocA, this.Map.terrainGrid.TerrainAt(this.TargetA.Cell).GetModExtension <TerrainExtension>().tillsTo);
                    this.ReadyForNextToil();
                    return;
                }
            };
            tillCell.FailOnCannotTouch(TargetIndex.A, PathEndMode.Touch);
            tillCell.WithProgressBar(TargetIndex.A, () => this.workdone / this.Map.terrainGrid.TerrainAt(this.TargetA.Cell).GetModExtension <TerrainExtension>().tillWorkAmount, false, -0.5f);
            tillCell.defaultCompleteMode = ToilCompleteMode.Never;
            tillCell.activeSkill         = (() => SkillDefOf.Plants);
            yield return(tillCell);

            yield break;
        }
        protected override IEnumerable <Toil> MakeNewToils()
        {
            this.FailOnDespawnedOrNull(TargetIndex.B);
            yield return(Toils_Goto.Goto(TargetIndex.B, PathEndMode));

            Toil doWork = new Toil();

            doWork.initAction = delegate
            {
                workLeft = 65f;
            };
            doWork.tickAction = delegate
            {
                float num = doWork.actor.GetStatValue(StatDefOf.ConstructionSpeed) * 1.7f;
                workLeft -= num;
                if (workLeft <= 0f)
                {
                    DoEffect();
                    ReadyForNextToil();
                }
            };
            doWork.FailOnCannotTouch(TargetIndex.B, PathEndMode);
            doWork.PlaySoundAtStart(SoundDefOf.Roof_Start);
            doWork.PlaySoundAtEnd(SoundDefOf.Roof_Finish);
            doWork.WithEffect(EffecterDefOf.RoofWork, TargetIndex.A);
            doWork.FailOn(DoWorkFailOn);
            doWork.WithProgressBar(TargetIndex.A, () => 1f - workLeft / 65f);
            doWork.defaultCompleteMode = ToilCompleteMode.Never;
            doWork.activeSkill         = () => SkillDefOf.Construction;
            yield return(doWork);
        }
Ejemplo n.º 19
0
        // Token: 0x06000010 RID: 16 RVA: 0x00002787 File Offset: 0x00000987
        protected override IEnumerable <Toil> MakeNewToils()
        {
            var wait = new Toil();

            wait.tickAction = delegate
            {
                var actor = wait.actor;
                gatherProgress += actor.GetStatValue(StatDefOf.AnimalGatherSpeed);
                if (!(gatherProgress >= WorkTotal))
                {
                    return;
                }

                actor.TryGetComp <CompWidowMilkableHumanoid>().GatherMilkSelf();
                actor.jobs.EndCurrentJob(JobCondition.Succeeded);
            };
            wait.AddEndCondition(delegate
            {
                var actor  = wait.actor;
                var result = !actor.TryGetComp <CompWidowMilkableHumanoid>().ActiveAndCanBeMilked
                    ? JobCondition.Incompletable
                    : JobCondition.Ongoing;

                return(result);
            });
            wait.defaultCompleteMode = ToilCompleteMode.Never;
            wait.WithProgressBar(TargetIndex.A, () => gatherProgress / WorkTotal);
            yield return(wait);
        }
        public Toil Cultivate()
        {
            var targetCell = CurJob.targetA.Cell;

            var toil = new Toil();
            toil.initAction = () =>
            {
                workTicks = Mathf.RoundToInt(terrainReplacements[targetCell.GetTerrain()].GetStatValueAbstract(StatDefOf.WorkToMake) * pawn.GetStatValue(StatDefOf.PlantWorkSpeed));
                pawn.jobs.curDriver.ticksLeftThisToil = workTicks;
            };
            toil.tickAction = () =>
            {
                if (--pawn.jobs.curDriver.ticksLeftThisToil < 0)
                {
                    // remove designation
                    var designation = Find.DesignationManager.DesignationAt(targetCell,
                        DefDatabase<DesignationDef>.GetNamed("CultivateLand"));
                    if (designation != null)
                    {
                        Find.DesignationManager.RemoveDesignation(designation);
                    }

                    // replace terrain
                    Find.TerrainGrid.SetTerrain(targetCell, terrainReplacements[targetCell.GetTerrain()]);

                    ReadyForNextToil();
                }
            };
            toil.defaultCompleteMode = ToilCompleteMode.Never;
            toil.FailOnCellMissingDesignation(CellInd, DefDatabase<DesignationDef>.GetNamed("CultivateLand"));
            toil.WithEffect(() => EffecterDef.Named("CutStone"), CellInd);
            toil.PlaySustainerOrSound(() => DefDatabase<SoundDef>.GetNamedSilentFail("Recipe_Surgery"));
            toil.WithProgressBar(CellInd, () => 1f - (float) pawn.jobs.curDriver.ticksLeftThisToil/workTicks);
            return toil;
        }
Ejemplo n.º 21
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            this.FailOnDespawnedNullOrForbidden(TargetIndex.A);
            yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.Touch));

            Toil wait = new Toil();

            wait.initAction = delegate()
            {
                Pawn actor = wait.actor;
                actor.pather.StopDead();
            };
            wait.tickAction = delegate()
            {
                Pawn       actor = wait.actor;
                Plant_Nest nest  = (Plant_Nest)this.job.targetA.Thing;
                this.gatherProgress += actor.GetStatValue(StatDefOf.PlantWorkSpeed, true);
                if (this.gatherProgress >= this.WorkTotal)
                {
                    actor.jobs.EndCurrentJob(JobCondition.Succeeded, true, true);
                    if (!Rand.Chance(actor.GetStatValue(StatDefOf.PlantHarvestYield, true)))
                    {
                        nest.nectarAmount /= 2;
                        MoteMaker.ThrowText((actor.DrawPos + nest.DrawPos) / 2f, actor.Map, "TextMote_ProductWasted".Translate(), 3.65f);
                    }
                    else
                    {
                        int i = GenMath.RoundRandom((float)1 * (float)nest.nectarAmount);
                        int totalExtracted = 0;
                        while (i > 0)
                        {
                            int num = Mathf.Clamp(i, 1, PurpleIvyDefOf.PI_Nectar.stackLimit);
                            i -= num;
                            totalExtracted += num;
                            Thing thing = ThingMaker.MakeThing(PurpleIvyDefOf.PI_Nectar, null);
                            thing.stackCount = num;
                            GenPlace.TryPlaceThing(thing, actor.Position, actor.Map, ThingPlaceMode.Near, null, null, default(Rot4));
                        }
                        nest.nectarAmount -= totalExtracted;
                        if (nest.nectarAmount < 0)
                        {
                            nest.nectarAmount = 0;
                        }
                    }
                }
            };
            wait.FailOnDespawnedOrNull(TargetIndex.A);
            wait.FailOnCannotTouch(TargetIndex.A, PathEndMode.Touch);
            wait.AddEndCondition(delegate
            {
                return(JobCondition.Ongoing);
            });
            wait.defaultCompleteMode = ToilCompleteMode.Never;
            wait.WithProgressBar(TargetIndex.A, () => this.gatherProgress / this.WorkTotal, false, -0.5f);
            wait.activeSkill = (() => SkillDefOf.Plants);
            yield return(wait);

            yield break;
        }
        protected override IEnumerable <Toil> MakeNewToils()
        {
            // Go to hairdressing table
            var gotoToil = Toils_Goto.GotoThing(TableIndex, PathEndMode.InteractionCell);

            yield return(gotoToil);

            // Bring up interface
            yield return(new Toil()
            {
                initAction = () =>
                {
                    Find.WindowStack.Add(new Dialog_ChangeHairstyle(this));
                },
                defaultCompleteMode = ToilCompleteMode.Never
            });

            // Change hairstyle
            var hairdressToil = new Toil
            {
                tickAction = () =>
                {
                    // Work on changing hairstyle
                    restyleTicksDone += pawn.GetStatValue(RimWorld.StatDefOf.GeneralLaborSpeed);
                    if (restyleTicksDone >= ticksToRestyle)
                    {
                        if (AnyChanges)
                        {
                            FilthMaker.TryMakeFilth(pawn.Position, pawn.Map, ThingDefOf.VHE_Filth_Hair, 3);
                        }

                        if (newHairDef != null)
                        {
                            pawn.story.hairDef = newHairDef;
                        }
                        if (newHairColour.HasValue)
                        {
                            pawn.story.hairColor = newHairColour.Value;
                        }

                        if (newBeardDef != null)
                        {
                            this.pawn.style.beardDef = newBeardDef;
                        }

                        pawn.Drawer.renderer.graphics.ResolveAllGraphics();
                        PortraitsCache.SetDirty(pawn);
                        GlobalTextureAtlasManager.TryMarkPawnFrameSetDirty(pawn);
                        pawn.jobs.EndCurrentJob(JobCondition.Succeeded);
                    }
                },
                defaultCompleteMode = ToilCompleteMode.Never
            };

            hairdressToil.WithProgressBar(TableIndex, () => restyleTicksDone / ticksToRestyle, true);
            hairdressToil.FailOnCannotTouch(TableIndex, PathEndMode.Touch);
            hairdressToil.PlaySustainerOrSound(SoundDefOf.Recipe_Tailor);
            yield return(hairdressToil);
        }
        protected override IEnumerable <Toil> MakeNewToils()
        {
            HediffComp_Menstruation Comp = pawn.GetMenstruationComp();

            //this.FailOn(delegate
            //{
            //    return !(Comp.TotalCumPercent > 0.001);
            //});
            yield return(Toils_Goto.GotoThing(TargetIndex.B, PathEndMode.ClosestTouch));

            Toil excreting = Toils_General.Wait(excretingTime, TargetIndex.None);//duration of

            excreting.WithProgressBarToilDelay(TargetIndex.A);
            yield return(excreting);

            yield return(new Toil()
            {
                initAction = delegate()
                {
                    if (Comp.TotalCumPercent > 0.001)
                    {
                        CumMixture mixture = Comp.MixtureOut(RJWSexperience.VariousDefOf.GatheredCum, 0.5f);
                        float amount = mixture.Volume;
                        if (mixture.ispurecum)
                        {
                            Bucket.AddCum(amount);
                        }
                        else
                        {
                            GatheredCumMixture cummixture = (GatheredCumMixture)ThingMaker.MakeThing(VariousDefOf.GatheredCumMixture);
                            cummixture.InitwithCum(mixture);
                            Bucket.AddCum(amount, cummixture);
                        }
                    }
                    else
                    {
                        ReadyForNextToil();
                    }
                    if (Comp.TotalCumPercent > 0.001)
                    {
                        JumpToToil(excreting);
                    }
                }
            });

            Toil cleaning = new Toil();

            cleaning.initAction = CleaningInit;
            cleaning.tickAction = CleaningTick;
            cleaning.AddFinishAction(Finish);
            cleaning.defaultCompleteMode = ToilCompleteMode.Never;
            cleaning.WithProgressBar(TargetIndex.A, () => progress / CleaningTime);

            yield return(cleaning);

            //yield return excreting;
            yield break;
        }
        // Token: 0x06000046 RID: 70 RVA: 0x000040B9 File Offset: 0x000022B9
        protected override IEnumerable <Toil> MakeNewToils()
        {
            this.FailOnDespawnedNullOrForbidden(TargetIndex.A);
            this.FailOnDowned(TargetIndex.A);
            this.FailOnNotCasualInterruptible(TargetIndex.A);
            yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.Touch));

            Toil wait = new Toil();

            wait.initAction = delegate()
            {
                Pawn actor = wait.actor;
                Pawn pawn  = (Pawn)wait.actor.CurJob.GetTarget(TargetIndex.A).Thing;
                actor.pather.StopDead();
                PawnUtility.ForceWait(pawn, 15000, null, true);
            };
            wait.tickAction = delegate()
            {
                Pawn actor = wait.actor;
                this.gatherProgress += actor.GetStatValue(StatDefOf.AnimalGatherSpeed, true);
                bool flag = this.gatherProgress >= this.WorkTotal;
                if (flag)
                {
                    this.GetComp((Pawn)((Thing)this.job.GetTarget(TargetIndex.A))).Gathered(this.pawn);
                    actor.jobs.EndCurrentJob(JobCondition.Succeeded, true, true);
                }
            };
            wait.AddFinishAction(delegate
            {
                Pawn pawn = (Pawn)wait.actor.CurJob.GetTarget(TargetIndex.A).Thing;
                bool flag = pawn.jobs.curJob.def == JobDefOf.Wait_MaintainPosture;
                if (flag)
                {
                    pawn.jobs.EndCurrentJob(JobCondition.InterruptForced, true, true);
                }
            });
            wait.FailOnDespawnedOrNull(TargetIndex.A);
            wait.FailOnCannotTouch(TargetIndex.A, PathEndMode.Touch);
            wait.AddEndCondition(delegate
            {
                bool flag = !this.GetComp((Pawn)((Thing)this.job.GetTarget(TargetIndex.A))).ActiveAndFull;
                JobCondition result;
                if (flag)
                {
                    result = JobCondition.Incompletable;
                }
                else
                {
                    result = JobCondition.Ongoing;
                }
                return(result);
            });
            wait.defaultCompleteMode = ToilCompleteMode.Never;
            wait.WithProgressBar(TargetIndex.A, () => this.gatherProgress / this.WorkTotal, false, -0.5f);
            yield return(wait);

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

            Toil wait = new Toil();

            wait.initAction = delegate()
            {
                Pawn actor = wait.actor;
                Pawn pawn  = (Pawn)this.job.GetTarget(TargetIndex.A).Thing;
                actor.pather.StopDead();
                PawnUtility.ForceWait(pawn, 15000, null, true);
            };
            wait.tickAction = delegate()
            {
                Pawn actor = wait.actor;
                actor.skills.Learn(SkillDefOf.Animals, 0.13f, false);
                this.gatherProgress += actor.GetStatValue(StatDefOf.AnimalGatherSpeed, true);
                if (this.gatherProgress >= this.WorkTotal)
                {
                    this.GetSpecificComp((Pawn)((Thing)this.job.GetTarget(TargetIndex.A))).InformGathered(this.pawn);
                    actor.jobs.EndCurrentJob(JobCondition.Succeeded, true, true);
                    if (ModLister.HasActiveModWithName("Alpha Animals"))
                    {
                        actor.health.AddHediff(HediffDef.Named("AA_GatheredResource"));
                    }
                }
            };
            wait.AddFinishAction(delegate
            {
                Pawn pawn = (Pawn)this.job.GetTarget(TargetIndex.A).Thing;
                if (pawn != null && pawn.CurJobDef == JobDefOf.Wait_MaintainPosture)
                {
                    pawn.jobs.EndCurrentJob(JobCondition.InterruptForced, true, true);
                }
            });
            wait.FailOnDespawnedOrNull(TargetIndex.A);
            wait.FailOnCannotTouch(TargetIndex.A, PathEndMode.Touch);
            wait.AddEndCondition(delegate
            {
                if (!this.GetComp((Pawn)((Thing)this.job.GetTarget(TargetIndex.A))).ActiveAndFull)
                {
                    return(JobCondition.Incompletable);
                }
                return(JobCondition.Ongoing);
            });
            wait.defaultCompleteMode = ToilCompleteMode.Never;
            wait.WithProgressBar(TargetIndex.A, () => this.gatherProgress / this.WorkTotal, false, -0.5f);
            wait.activeSkill = (() => SkillDefOf.Animals);

            yield return(wait);

            yield break;
        }
Ejemplo n.º 26
0
        public static Toil ChewIngestible(Pawn chewer, float durationMultiplier, TargetIndex ingestibleInd, TargetIndex eatSurfaceInd = TargetIndex.None)
        {
            Toil toil = new Toil();

            toil.initAction = delegate
            {
                Pawn  actor  = toil.actor;
                Thing thing4 = actor.CurJob.GetTarget(ingestibleInd).Thing;

                toil.actor.pather.StopDead();
                actor.jobs.curDriver.ticksLeftThisToil = Mathf.RoundToInt((float)GetIngestibleProperties(thing4).baseIngestTicks *durationMultiplier);
                if (thing4.Spawned)
                {
                    thing4.Map.physicalInteractionReservationManager.Reserve(chewer, actor.CurJob, thing4);
                }
            };
            toil.tickAction = delegate
            {
                if (chewer != toil.actor)
                {
                    toil.actor.rotationTracker.FaceCell(chewer.Position);
                }
                else
                {
                    Thing thing3 = toil.actor.CurJob.GetTarget(ingestibleInd).Thing;
                    if (thing3 != null && thing3.Spawned)
                    {
                        toil.actor.rotationTracker.FaceCell(thing3.Position);
                    }
                    else if (eatSurfaceInd != 0 && toil.actor.CurJob.GetTarget(eatSurfaceInd).IsValid)
                    {
                        toil.actor.rotationTracker.FaceCell(toil.actor.CurJob.GetTarget(eatSurfaceInd).Cell);
                    }
                }
                toil.actor.GainComfortFromCellIfPossible();
            };
            toil.WithProgressBar(ingestibleInd, delegate
            {
                Thing thing2 = toil.actor.CurJob.GetTarget(ingestibleInd).Thing;
                return((thing2 == null) ? 1f : (1f - (float)toil.actor.jobs.curDriver.ticksLeftThisToil / Mathf.Round((float)thing2.GetIngestibleProperties().baseIngestTicks *durationMultiplier)));
            });
            toil.defaultCompleteMode = ToilCompleteMode.Delay;
            toil.AddFinishAction(delegate
            {
                if (chewer != null && chewer.CurJob != null)
                {
                    Thing thing = chewer.CurJob.GetTarget(ingestibleInd).Thing;
                    if (thing != null && chewer.Map.physicalInteractionReservationManager.IsReservedBy(chewer, thing))
                    {
                        chewer.Map.physicalInteractionReservationManager.Release(chewer, toil.actor.CurJob, thing);
                    }
                }
            });
            toil.handlingFacing = true;
            AddIngestionEffects(toil, chewer, ingestibleInd, eatSurfaceInd);
            return(toil);
        }
Ejemplo n.º 27
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            this.FailOn(() => this.Map.zoneManager.ZoneAt(this.TargetLocA) == null || this.Map.zoneManager.ZoneAt(this.TargetLocA).GetType().ToString() != "IceIsNice.Zone_IceMine");
            yield return(Toils_Reserve.Reserve(TargetIndex.A, 1, -1, ReservationLayerDefOf.Floor));

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

            Toil doWork = new Toil();

            doWork.initAction = delegate
            {
                this.workLeft       = this.BaseWorkAmount;
                this.ticksToPickHit = this.BaseTicksBetweenPickHits;
            };
            doWork.tickAction = delegate
            {
                Pawn actor = this.CurToil.actor;
                this.ticksToPickHit--;
                if (this.ticksToPickHit <= 0f)
                {
                    float num = (this.SpeedStat == null) ? 1f : this.pawn.GetStatValue(this.SpeedStat, true);
                    this.workLeft      -= num;
                    this.ticksToPickHit = this.BaseTicksBetweenPickHits;
                    if (this.effecter == null)
                    {
                        this.effecter = EffecterDefOf.Mine.Spawn();
                    }
                    TargetInfo tar = new TargetInfo(this.TargetLocA, this.Map);
                    this.effecter.Trigger(actor, tar);
                }
                if (actor.skills != null)
                {
                    actor.skills.Learn(SkillDefOf.Mining, 0.11f, false);
                }
                if (this.clearSnow)
                {
                    this.Map.snowGrid.SetDepth(this.TargetLocA, 0f);
                }
                if (this.workLeft <= 0f)
                {
                    this.Map.zoneManager.ZoneAt(this.TargetLocA).RemoveCell(this.TargetLocA);
                    this.Map.terrainGrid.SetTerrain(this.TargetLocA, DefDatabase <TerrainDef> .GetNamed("WaterMovingShallow", true));
                    actor.records.Increment(RecordDefOf.CellsMined);
                    //GenSpawn.Spawn(DefDatabase<ThingDef>.GetNamed(IceThingDef.Ice, true), this.TargetLocA, this.Map);
                    Thing yield = ThingMaker.MakeThing(DefDatabase <ThingDef> .GetNamed(IceThingDef.Ice, true), null);
                    yield.stackCount = 3;
                    GenPlace.TryPlaceThing(yield, this.TargetLocA, this.Map, ThingPlaceMode.Near, null);
                    this.ReadyForNextToil();
                    return;
                }
            };
            doWork.FailOnCannotTouch(TargetIndex.A, PathEndMode.Touch);
            doWork.WithProgressBar(TargetIndex.A, () => 1f - this.workLeft / (float)this.BaseWorkAmount, false, -0.5f);
            doWork.defaultCompleteMode = ToilCompleteMode.Never;
            yield return(doWork);
        }
Ejemplo n.º 28
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            yield return(Toils_Goto.GotoCell(TargetIndex.A, PathEndMode.Touch).FailOn(() => PlantUtility.AdjacentSowBlocker(job.plantDefToSow, base.TargetA.Cell, base.Map) != null).FailOn(() => !job.plantDefToSow.CanEverPlantAt_NewTemp(base.TargetLocA, base.Map)));

            Toil sowToil = new Toil();

            sowToil.initAction = delegate
            {
                base.TargetThingA = GenSpawn.Spawn(job.plantDefToSow, base.TargetLocA, base.Map);
                pawn.Reserve(base.TargetThingA, sowToil.actor.CurJob);
                Plant obj = (Plant)base.TargetThingA;
                obj.Growth = 0f;
                obj.sown   = true;
            };
            sowToil.tickAction = delegate
            {
                Pawn actor = sowToil.actor;
                if (actor.skills != null)
                {
                    actor.skills.Learn(SkillDefOf.Plants, 0.085f);
                }
                float statValue = actor.GetStatValue(StatDefOf.PlantWorkSpeed);
                Plant plant2    = Plant;
                if (plant2.LifeStage != 0)
                {
                    Log.Error(string.Concat(this, " getting sowing work while not in Sowing life stage."));
                }
                sowWorkDone += statValue;
                if (sowWorkDone >= plant2.def.plant.sowWork)
                {
                    plant2.Growth = 0.05f;
                    base.Map.mapDrawer.MapMeshDirty(plant2.Position, MapMeshFlag.Things);
                    actor.records.Increment(RecordDefOf.PlantsSown);
                    ReadyForNextToil();
                }
            };
            sowToil.defaultCompleteMode = ToilCompleteMode.Never;
            sowToil.FailOnDespawnedNullOrForbidden(TargetIndex.A);
            sowToil.FailOnCannotTouch(TargetIndex.A, PathEndMode.Touch);
            sowToil.WithEffect(EffecterDefOf.Sow, TargetIndex.A);
            sowToil.WithProgressBar(TargetIndex.A, () => sowWorkDone / Plant.def.plant.sowWork, interpolateBetweenActorAndTarget: true);
            sowToil.PlaySustainerOrSound(() => SoundDefOf.Interact_Sow);
            sowToil.AddFinishAction(delegate
            {
                if (base.TargetThingA != null)
                {
                    Plant plant = (Plant)sowToil.actor.CurJob.GetTarget(TargetIndex.A).Thing;
                    if (sowWorkDone < plant.def.plant.sowWork && !base.TargetThingA.Destroyed)
                    {
                        base.TargetThingA.Destroy();
                    }
                }
            });
            sowToil.activeSkill = () => SkillDefOf.Plants;
            yield return(sowToil);
        }
Ejemplo n.º 29
0
        protected IEnumerable <Toil> MakeNewToils(HediffDef hediffDef)
        {
            this.FailOnDespawnedNullOrForbidden(TargetIndex.A);
            //this.FailOnDowned(TargetIndex.A);
            this.FailOnAggroMentalState(TargetIndex.A);
            yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.Touch));

            Toil wait = new Toil();

            wait.initAction = delegate
            {
                Pawn actor2 = wait.actor;
                Pawn pawn2  = (Pawn)job.GetTarget(TargetIndex.A).Thing;
                actor2.pather.StopDead();
                PawnUtility.ForceWait(pawn2, 15000, null, maintainPosture: true);
            };
            wait.tickAction = delegate
            {
                ticks++;
            };
            wait.AddFinishAction(delegate
            {
                Pawn pawn = (Pawn)job.GetTarget(TargetIndex.A).Thing;
                if (pawn != null)
                {
                    Hediff hediff = pawn.health.hediffSet.GetFirstHediffOfDef(hediffDef, false);
                    if (hediff == null)
                    {
                        hediff = HediffMaker.MakeHediff(hediffDef, pawn, null);
                        pawn.health.AddHediff(hediff, null, null);
                    }
                    else
                    {
                        pawn.health.hediffSet.hediffs.Remove(hediff);
                    }
                    if (pawn.CurJobDef == JobDefOf.Wait_MaintainPosture)
                    {
                        pawn.jobs.EndCurrentJob(JobCondition.InterruptForced);
                    }
                }
            });
            wait.FailOnDespawnedOrNull(TargetIndex.A);
            wait.FailOnCannotTouch(TargetIndex.A, PathEndMode.Touch);
            wait.AddEndCondition(() =>
            {
                if (ticks >= BGP.Unchain_Ticks)
                {
                    return(JobCondition.Succeeded);
                }
                return(JobCondition.Ongoing);
            }
                                 );
            wait.defaultCompleteMode = ToilCompleteMode.Never;
            wait.WithProgressBar(TargetIndex.A, () => ticks / BGP.Unchain_Ticks);
            yield return(wait);
        }
Ejemplo n.º 30
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            // 移動
            yield return(Toils_Goto.GotoCell(GetSnowCellIndex, PathEndMode.Touch));

            // 雪を集める
            var getToil = new Toil();

            getToil.tickAction = () =>
            {
                var   actor     = getToil.actor;
                float statValue = actor.GetStatValue(StatDefOf.WorkSpeedGlobal, true);
                float num       = statValue;
                this.workDone += num;
                if (this.workDone >= WorkGiver_GetSnow.ConsumeSnowPerOne * 100f)
                {
                    var snowDepth = this.Map.snowGrid.GetDepth(this.TargetLocA);
                    snowDepth = Math.Max(0f, snowDepth - WorkGiver_GetSnow.ConsumeSnowPerOne);
                    this.Map.snowGrid.SetDepth(this.TargetLocA, snowDepth);
                    this.ReadyForNextToil();
                    return;
                }
            };
            getToil.defaultCompleteMode = ToilCompleteMode.Never;
            getToil.WithEffect(EffecterDefOf.ClearSnow, GetSnowCellIndex);
            getToil.PlaySustainerOrSound(() => SoundDefOf.Interact_CleanFilth);
            getToil.WithProgressBar(GetSnowCellIndex, () => this.workDone / this.TotalNeededWork, true, -0.5f);
            getToil.FailOnCannotTouch(GetSnowCellIndex, PathEndMode.Touch);
            yield return(getToil);

            // 雪玉生成
            var makeToil = new Toil();

            makeToil.initAction = () =>
            {
                var actor     = makeToil.actor;
                var snowThing = ThingMaker.MakeThing(MizuDef.Thing_Snowball);
                snowThing.stackCount = 1;

                if (!GenPlace.TryPlaceThing(snowThing, actor.Position, actor.Map, ThingPlaceMode.Near, null))
                {
                    Log.Error(string.Concat(new object[]
                    {
                        actor,
                        " could not drop recipe product ",
                        snowThing,
                        " near ",
                        this.TargetLocA
                    }));
                }
            };
            makeToil.defaultCompleteMode = ToilCompleteMode.Instant;
            yield return(makeToil);
        }
Ejemplo n.º 31
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            this.FailOnDestroyedOrNull(TargetIndex.A);
            this.FailOnDowned(TargetIndex.A);
            //this.FailOnCannotTouch(TargetIndex.A, PathEndMode.Touch);
            yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.Touch));

            Toil waitFor = new Toil()
            {
                initAction = () =>
                {
                    if (TargetB != null)
                    {
                        this.waitForPawn = TargetB.Thing as Pawn;
                        if (this.waitForPawn != null && this.waitForPawn.jobs != null && this.waitForPawn.jobs.curJob != null && this.waitForPawn.CurJobDef != null)
                        {
                            this.targetJobDef = this.waitForPawn.CurJobDef;
                        }
                    }
                    this.durationTicks = this.job.expiryInterval;
                    if (this.age > this.durationTicks)
                    {
                        this.EndJobWith(JobCondition.InterruptForced);
                    }
                },
                tickAction = () =>
                {
                    if (this.waitForPawn != null)
                    {
                        if (this.targetJobDef != null && this.waitForPawn.jobs != null && this.waitForPawn.jobs.curJob != null && this.waitForPawn.CurJobDef != this.targetJobDef)
                        {
                            this.EndJobWith(JobCondition.InterruptForced);
                        }
                    }
                    if (age > durationTicks)
                    {
                        this.EndJobWith(JobCondition.Succeeded);
                    }
                    age++;
                },
                defaultCompleteMode = ToilCompleteMode.Never
            };

            waitFor.defaultDuration = this.durationTicks;
            waitFor.WithProgressBar(TargetIndex.A, delegate
            {
                if (this.pawn.DestroyedOrNull() || this.pawn.Dead || this.pawn.Downed)
                {
                    return(1f);
                }
                return(1f - (float)waitFor.actor.jobs.curDriver.ticksLeftThisToil / this.durationTicks);
            }, false, 0f);
            yield return(waitFor);
        }
Ejemplo n.º 32
0
        // added support for fuel burners
        public static Toil DoRecipeWork()
        {
            // research injection. initialized here to check if research project wan't change during work
            var startedResearch = Find.ResearchManager.currentProj;

            var toil = new Toil();
            toil.initAction = () =>
            {
                var actor = toil.actor;
                var curJob = actor.jobs.curJob;
                var curDriver = actor.jobs.curDriver as JobDriver_DoBill;

                var unfinishedThing = curJob.GetTarget(TargetIndex.B).Thing as UnfinishedThing;
                if (unfinishedThing != null && unfinishedThing.Initialized)
                {
                    curDriver.workLeft = unfinishedThing.workLeft;
                }
                else
                {
                    // research injection
                    var researchComp =
                        toil.actor.jobs.curJob.GetTarget(TargetIndex.A).Thing.TryGetComp<CompResearcher>();
                    if (researchComp != null)
                    {
                        curDriver.workLeft = startedResearch.CostApparent -
                                             startedResearch.ProgressApparent;
                    }
                    else
                    {
                        curDriver.workLeft = curJob.bill.recipe.WorkAmountTotal(unfinishedThing?.Stuff);
                    }

                    if (unfinishedThing != null)
                    {
                        unfinishedThing.workLeft = curDriver.workLeft;
                    }
                }
                curDriver.billStartTick = Find.TickManager.TicksGame;
                curJob.bill.Notify_DoBillStarted();
            };
            toil.tickAction = () =>
            {
                var actor = toil.actor;
                var curJob = actor.jobs.curJob;

                actor.GainComfortFromCellIfPossible();

                // burner support injection
                var burner = curJob.GetTarget(TargetIndex.A).Thing.TryGetComp<CompFueled>();
                if (burner != null && burner.internalTemp < burner.compFueled.Properties.operatingTemp)
                {
                    return;
                }

                var unfinishedThing = curJob.GetTarget(TargetIndex.B).Thing as UnfinishedThing;
                if (unfinishedThing != null && unfinishedThing.Destroyed)
                {
                    actor.jobs.EndCurrentJob(JobCondition.Incompletable);
                    return;
                }

                curJob.bill.Notify_PawnDidWork(actor);

                var billGiverWithTickAction =
                    curJob.GetTarget(TargetIndex.A).Thing as IBillGiverWithTickAction;
                billGiverWithTickAction?.BillTick();

                if (curJob.RecipeDef.workSkill != null)
                {
                    actor.skills.GetSkill(curJob.RecipeDef.workSkill)
                        .Learn(LearnRates.XpPerTickRecipeBase*curJob.RecipeDef.workSkillLearnFactor);
                }

                var workProgress = (curJob.RecipeDef.workSpeedStat != null)
                    ? actor.GetStatValue(curJob.RecipeDef.workSpeedStat)
                    : 1f;

                var curDriver = actor.jobs.curDriver as JobDriver_DoBill;
                var building_WorkTable = curDriver.BillGiver as Building_WorkTable;
                var researchComp = curJob.GetTarget(TargetIndex.A).Thing.TryGetComp<CompResearcher>();
                if (building_WorkTable != null)
                {
                    // research injection
                    workProgress *= researchComp == null
                        ? building_WorkTable.GetStatValue(StatDefOf.WorkTableWorkSpeedFactor)
                        : building_WorkTable.GetStatValue(StatDefOf.ResearchSpeedFactor);
                }

                if (DebugSettings.fastCrafting)
                {
                    workProgress *= 30f;
                }

                curDriver.workLeft -= workProgress;
                if (unfinishedThing != null)
                {
                    unfinishedThing.workLeft = curDriver.workLeft;
                }

                // research injection
                if (researchComp != null)
                {
                    if (Find.ResearchManager.currentProj != null && Find.ResearchManager.currentProj == startedResearch)
                    {
                        Find.ResearchManager.ResearchPerformed(workProgress, actor);
                    }
                    if (Find.ResearchManager.currentProj != startedResearch)
                    {
                        actor.jobs.EndCurrentJob(JobCondition.Succeeded);
                        // scatter around all ingridients
                        foreach (var cell in building_WorkTable.IngredientStackCells)
                        {
                            var ingridientsOnCell =
                                Find.ThingGrid.ThingsListAtFast(cell)?
                                    .Where(thing => thing.def.category == ThingCategory.Item)
                                    .ToList();
                            if (!ingridientsOnCell.NullOrEmpty())
                            {
                                Thing dummy;
                                // despawn thing to spawn again with TryPlaceThing
                                ingridientsOnCell.FirstOrDefault().DeSpawn();
                                if (
                                    !GenPlace.TryPlaceThing(ingridientsOnCell.FirstOrDefault(),
                                        building_WorkTable.InteractionCell,
                                        ThingPlaceMode.Near, out dummy))
                                {
                                    Log.Error("No free spot for " + ingridientsOnCell);
                                }
                            }
                        }
                    }
                }
                else if (curDriver.workLeft <= 0f)
                {
                    curDriver.ReadyForNextToil();
                }

                if (curJob.bill.recipe.UsesUnfinishedThing)
                {
                    var num2 = Find.TickManager.TicksGame - curDriver.billStartTick;
                    if (num2 >= 3000 && num2%1000 == 0)
                    {
                        actor.jobs.CheckForJobOverride();
                    }
                }
            };
            toil.defaultCompleteMode = ToilCompleteMode.Never;
            toil.WithEffect(() => toil.actor.CurJob.bill.recipe.effectWorking, TargetIndex.A);
            toil.PlaySustainerOrSound(() => toil.actor.CurJob.bill.recipe.soundWorking);
            toil.WithProgressBar(TargetIndex.A, () =>
            {
                var actor = toil.actor;
                var curJob = actor.CurJob;
                var unfinishedThing = curJob.GetTarget(TargetIndex.B).Thing as UnfinishedThing;
                var researchComp = curJob.GetTarget(TargetIndex.A).Thing.TryGetComp<CompResearcher>();
                // research injection
                return researchComp == null
                    ? 1f - ((JobDriver_DoBill) actor.jobs.curDriver).workLeft/
                      curJob.bill.recipe.WorkAmountTotal(unfinishedThing?.Stuff)
                    : startedResearch.ProgressPercent;
            });
            return toil;
        }
        public Toil CollectClay(int ticksToCollect)
        {
            var targetCell = CurJob.targetA.Cell;

            var toil = new Toil();
            toil.initAction = () =>
            {
                pawn.jobs.curDriver.ticksLeftThisToil =
                    Mathf.RoundToInt(ticksToCollect*pawn.GetStatValue(StatDef.Named("CollectingSpeed")));
                totalWork = pawn.jobs.curDriver.ticksLeftThisToil;
            };
            toil.tickAction = () =>
            {
                if (--pawn.jobs.curDriver.ticksLeftThisToil < 0)
                {
                    // remove designation
                    var designation = Find.DesignationManager.DesignationAt(targetCell,
                        DefDatabase<DesignationDef>.GetNamed("CollectClay"));
                    if (designation != null)
                    {
                        Find.DesignationManager.RemoveDesignation(designation);
                    }

                    // replace terrain
                    if (Find.TerrainGrid.TerrainAt(targetCell) == TerrainDef.Named("Mud"))
                        Find.TerrainGrid.SetTerrain(targetCell, DefDatabase<TerrainDef>.GetNamed("Soil"));
                    if (Find.TerrainGrid.TerrainAt(targetCell) == TerrainDef.Named("SoilRich"))
                        Find.TerrainGrid.SetTerrain(targetCell, DefDatabase<TerrainDef>.GetNamed("Soil"));
                    if (Find.TerrainGrid.TerrainAt(targetCell) == TerrainDef.Named("WaterShallow"))
                    {
                        Find.TerrainGrid.SetTerrain(targetCell, DefDatabase<TerrainDef>.GetNamed("WaterDeep"));

                        var list = new List<Thing>(Find.ThingGrid.ThingsListAtFast(targetCell)
                            .Where(thing => thing.def.category == ThingCategory.Item ||
                                            thing.def.category == ThingCategory.Pawn));
                        foreach (var thing in list)
                        {
                            Thing dummy;
                            // despawn thing to spawn again with TryPlaceThing
                            thing.DeSpawn();
                            if (!GenPlace.TryPlaceThing(thing, thing.Position, ThingPlaceMode.Near, out dummy))
                            {
                                Log.Error("No free spot for " + thing);
                            }
                        }
                    }

                    // spawn resources
                    var clayRed = ThingMaker.MakeThing(ThingDef.Named("ClumpClayGray"));
                    clayRed.stackCount = Rand.RangeInclusive(25, 75);
                    GenPlace.TryPlaceThing(clayRed, targetCell, ThingPlaceMode.Near);

                    // Rand.Value = Rand.Range(0, 1)
                    if (Rand.Value < RareResourceSpawnChance)
                    {
                        var clayWhite = ThingMaker.MakeThing(ThingDef.Named("ClumpClayWhite"));
                        clayWhite.stackCount = Rand.RangeInclusive(5, 10);
                        GenPlace.TryPlaceThing(clayWhite, targetCell, ThingPlaceMode.Near);
                    }

                    ReadyForNextToil();
                }
            };
            toil.defaultCompleteMode = ToilCompleteMode.Never;
            toil.FailOnCellMissingDesignation(CellInd, DefDatabase<DesignationDef>.GetNamed("CollectClay"));
            toil.WithEffect(() => EffecterDef.Named("CutStone"), CellInd);
            toil.PlaySustainerOrSound(() => DefDatabase<SoundDef>.GetNamedSilentFail("Recipe_Surgery"));
            toil.WithProgressBar(CellInd, () => 1f - (float) pawn.jobs.curDriver.ticksLeftThisToil/totalWork);
            return toil;
        }