public override bool HasJobOnCell(Pawn pawn, IntVec3 c) { Plant plant = c.GetPlant(pawn.Map); if (plant == null) { return(false); } if (plant.IsForbidden(pawn)) { return(false); } if (plant.HarvestableNow && plant.LifeStage == PlantLifeStage.Mature) { if (plant.YieldNow() <= 0) { return(false); } if (!pawn.CanReserve(plant, 1, -1, null, false)) { return(false); } return(true); } return(false); }
protected override IEnumerable <Toil> MakeNewToils() { Init(); yield return(Toils_JobTransforms.MoveCurrentTargetIntoQueue(TargetIndex.A)); Toil initExtractTargetFromQueue = Toils_JobTransforms.ClearDespawnedNullOrForbiddenQueuedTargets(TargetIndex.A, (RequiredDesignation != null) ? ((Func <Thing, bool>)((Thing t) => base.Map.designationManager.DesignationOn(t, RequiredDesignation) != null)) : null); yield return(initExtractTargetFromQueue); yield return(Toils_JobTransforms.SucceedOnNoTargetInQueue(TargetIndex.A)); yield return(Toils_JobTransforms.ExtractNextTargetFromQueue(TargetIndex.A)); Toil toil = Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.Touch).JumpIfDespawnedOrNullOrForbidden(TargetIndex.A, initExtractTargetFromQueue); if (RequiredDesignation != null) { toil.FailOnThingMissingDesignation(TargetIndex.A, RequiredDesignation); } yield return(toil); Toil cut = new Toil(); cut.tickAction = delegate { Pawn actor = cut.actor; if (actor.skills != null) { actor.skills.Learn(SkillDefOf.Plants, xpPerTick); } float statValue = actor.GetStatValue(StatDefOf.PlantWorkSpeed); Plant plant = Plant; statValue *= Mathf.Lerp(3.3f, 1f, plant.Growth); workDone += statValue; if (workDone >= plant.def.plant.harvestWork) { if (plant.def.plant.harvestedThingDef != null) { if (actor.RaceProps.Humanlike && plant.def.plant.harvestFailable && !plant.Blighted && Rand.Value > actor.GetStatValue(StatDefOf.PlantHarvestYield)) { MoteMaker.ThrowText((pawn.DrawPos + plant.DrawPos) / 2f, base.Map, "TextMote_HarvestFailed".Translate(), 3.65f); } else { int num = plant.YieldNow(); if (num > 0) { Thing thing = ThingMaker.MakeThing(plant.def.plant.harvestedThingDef); thing.stackCount = num; if (actor.Faction != Faction.OfPlayer) { thing.SetForbidden(value: true); } Find.QuestManager.Notify_PlantHarvested(actor, thing); GenPlace.TryPlaceThing(thing, actor.Position, base.Map, ThingPlaceMode.Near); actor.records.Increment(RecordDefOf.PlantsHarvested); } } } plant.def.plant.soundHarvestFinish.PlayOneShot(actor); plant.PlantCollected(); workDone = 0f; ReadyForNextToil(); } }; cut.FailOnDespawnedNullOrForbidden(TargetIndex.A); if (RequiredDesignation != null) { cut.FailOnThingMissingDesignation(TargetIndex.A, RequiredDesignation); } cut.FailOnCannotTouch(TargetIndex.A, PathEndMode.Touch); cut.defaultCompleteMode = ToilCompleteMode.Never; cut.WithEffect(EffecterDefOf.Harvest, TargetIndex.A); cut.WithProgressBar(TargetIndex.A, () => workDone / Plant.def.plant.harvestWork, interpolateBetweenActorAndTarget: true); cut.PlaySustainerOrSound(() => Plant.def.plant.soundHarvesting); cut.activeSkill = (() => SkillDefOf.Plants); yield return(cut); Toil toil2 = PlantWorkDoneToil(); if (toil2 != null) { yield return(toil2); } yield return(Toils_Jump.Jump(initExtractTargetFromQueue)); }
protected override IEnumerable <Toil> MakeNewToils() { this.Init(); yield return(Toils_JobTransforms.MoveCurrentTargetIntoQueue(TargetIndex.A)); Toil initExtractTargetFromQueue = Toils_JobTransforms.ClearDespawnedNullOrForbiddenQueuedTargets(TargetIndex.A, (this.RequiredDesignation == null) ? null : new Func <Thing, bool>((Thing t) => this.Map.designationManager.DesignationOn(t, this.RequiredDesignation) != null)); yield return(initExtractTargetFromQueue); yield return(Toils_JobTransforms.SucceedOnNoTargetInQueue(TargetIndex.A)); yield return(Toils_JobTransforms.ExtractNextTargetFromQueue(TargetIndex.A, true)); Toil gotoThing = Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.Touch).JumpIfDespawnedOrNullOrForbidden(TargetIndex.A, initExtractTargetFromQueue); if (this.RequiredDesignation != null) { gotoThing.FailOnThingMissingDesignation(TargetIndex.A, this.RequiredDesignation); } yield return(gotoThing); Toil cut = new Toil(); cut.tickAction = delegate() { Pawn actor = cut.actor; if (actor.skills != null) { actor.skills.Learn(SkillDefOf.Plants, this.xpPerTick, false); } float statValue = actor.GetStatValue(StatDefOf.PlantWorkSpeed, true); float num = statValue; Plant plant = this.Plant; num *= Mathf.Lerp(3.3f, 1f, plant.Growth); this.workDone += num; if (this.workDone >= plant.def.plant.harvestWork) { if (plant.def.plant.harvestedThingDef != null) { if (actor.RaceProps.Humanlike && plant.def.plant.harvestFailable && Rand.Value > actor.GetStatValue(StatDefOf.PlantHarvestYield, true)) { Vector3 loc = (this.pawn.DrawPos + plant.DrawPos) / 2f; MoteMaker.ThrowText(loc, this.Map, "TextMote_HarvestFailed".Translate(), 3.65f); } else { int num2 = plant.YieldNow(); if (num2 > 0) { Thing thing = ThingMaker.MakeThing(plant.def.plant.harvestedThingDef, null); thing.stackCount = num2; if (actor.Faction != Faction.OfPlayer) { thing.SetForbidden(true, true); } GenPlace.TryPlaceThing(thing, actor.Position, this.Map, ThingPlaceMode.Near, null, null); actor.records.Increment(RecordDefOf.PlantsHarvested); } } } plant.def.plant.soundHarvestFinish.PlayOneShot(actor); plant.PlantCollected(); this.workDone = 0f; this.ReadyForNextToil(); return; } }; cut.FailOnDespawnedNullOrForbidden(TargetIndex.A); if (this.RequiredDesignation != null) { cut.FailOnThingMissingDesignation(TargetIndex.A, this.RequiredDesignation); } cut.FailOnCannotTouch(TargetIndex.A, PathEndMode.Touch); cut.defaultCompleteMode = ToilCompleteMode.Never; cut.WithEffect(EffecterDefOf.Harvest, TargetIndex.A); cut.WithProgressBar(TargetIndex.A, () => this.workDone / this.Plant.def.plant.harvestWork, true, -0.5f); cut.PlaySustainerOrSound(() => this.Plant.def.plant.soundHarvesting); cut.activeSkill = (() => SkillDefOf.Plants); yield return(cut); Toil plantWorkDoneToil = this.PlantWorkDoneToil(); if (plantWorkDoneToil != null) { yield return(plantWorkDoneToil); } yield return(Toils_Jump.Jump(initExtractTargetFromQueue)); yield break; }
public override bool HasJobOnCell(Pawn pawn, IntVec3 c) { Plant plant = c.GetPlant(pawn.Map); return(plant != null && !plant.IsForbidden(pawn) && plant.HarvestableNow && plant.LifeStage == PlantLifeStage.Mature && plant.YieldNow() > 0 && pawn.CanReserve(plant, 1, -1, null, false)); }