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); }
protected override IEnumerable <Toil> MakeNewToils() { yield return(Toils_Goto.GotoCell(TargetIndex.A, PathEndMode.Touch).FailOn(() => PlantUtility.AdjacentSowBlocker(this.$this.job.plantDefToSow, this.$this.TargetA.Cell, this.$this.Map) != null).FailOn(() => !this.$this.job.plantDefToSow.CanEverPlantAt(this.$this.TargetLocA, this.$this.Map))); Toil sowToil = new Toil(); sowToil.initAction = delegate { this.$this.TargetThingA = GenSpawn.Spawn(this.$this.job.plantDefToSow, this.$this.TargetLocA, this.$this.Map, WipeMode.Vanish); this.$this.pawn.Reserve(this.$this.TargetThingA, sowToil.actor.CurJob, 1, -1, null, true); Plant plant = (Plant)this.$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.$this.Plant; if (plant.LifeStage != PlantLifeStage.Sowing) { Log.Error(this.$this + " getting sowing work while not in Sowing life stage.", false); } this.$this.sowWorkDone += num; if (this.$this.sowWorkDone >= plant.def.plant.sowWork) { plant.Growth = 0.05f; this.$this.Map.mapDrawer.MapMeshDirty(plant.Position, MapMeshFlag.Things); actor.records.Increment(RecordDefOf.PlantsSown); this.$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.$this.sowWorkDone / this.$this.Plant.def.plant.sowWork, true, -0.5f); sowToil.PlaySustainerOrSound(() => SoundDefOf.Interact_Sow); sowToil.AddFinishAction(delegate { if (this.$this.TargetThingA != null) { Plant plant = (Plant)sowToil.actor.CurJob.GetTarget(TargetIndex.A).Thing; if (this.$this.sowWorkDone < plant.def.plant.sowWork && !this.$this.TargetThingA.Destroyed) { this.$this.TargetThingA.Destroy(DestroyMode.Vanish); } } }); sowToil.activeSkill = (() => SkillDefOf.Plants); yield return(sowToil); }
public override Job JobOnCell(Pawn pawn, IntVec3 c, bool forced = false) { Map map = pawn.Map; if (c.IsForbidden(pawn)) { return(null); } if (!PlantUtility.GrowthSeasonNow(c, map, forSowing: true)) { return(null); } if (WorkGiver_Grower.wantedPlantDef == null) { WorkGiver_Grower.wantedPlantDef = WorkGiver_Grower.CalculateWantedPlantDef(c, map); if (WorkGiver_Grower.wantedPlantDef == null) { return(null); } } List <Thing> thingList = c.GetThingList(map); bool flag = false; for (int i = 0; i < thingList.Count; i++) { Thing thing = thingList[i]; if (thing.def == WorkGiver_Grower.wantedPlantDef) { return(null); } if ((thing is Blueprint || thing is Frame) && thing.Faction == pawn.Faction) { flag = true; } } if (flag) { Thing edifice = c.GetEdifice(map); if (edifice == null || edifice.def.fertility < 0f) { return(null); } } if (WorkGiver_Grower.wantedPlantDef.plant.cavePlant) { if (!c.Roofed(map)) { JobFailReason.Is(CantSowCavePlantBecauseUnroofedTrans); return(null); } if (map.glowGrid.GameGlowAt(c, ignoreCavePlants: true) > 0f) { JobFailReason.Is(CantSowCavePlantBecauseOfLightTrans); return(null); } } if (WorkGiver_Grower.wantedPlantDef.plant.interferesWithRoof && c.Roofed(pawn.Map)) { return(null); } Plant plant = c.GetPlant(map); if (plant != null && plant.def.plant.blockAdjacentSow) { if (!pawn.CanReserve(plant, 1, -1, null, forced) || plant.IsForbidden(pawn)) { return(null); } return(JobMaker.MakeJob(JobDefOf.CutPlant, plant)); } Thing thing2 = PlantUtility.AdjacentSowBlocker(WorkGiver_Grower.wantedPlantDef, c, map); if (thing2 != null) { Plant plant2 = thing2 as Plant; if (plant2 != null && pawn.CanReserve(plant2, 1, -1, null, forced) && !plant2.IsForbidden(pawn)) { IPlantToGrowSettable plantToGrowSettable = plant2.Position.GetPlantToGrowSettable(plant2.Map); if (plantToGrowSettable == null || plantToGrowSettable.GetPlantDefToGrow() != plant2.def) { return(JobMaker.MakeJob(JobDefOf.CutPlant, plant2)); } } return(null); } if (WorkGiver_Grower.wantedPlantDef.plant.sowMinSkill > 0 && pawn.skills != null && pawn.skills.GetSkill(SkillDefOf.Plants).Level < WorkGiver_Grower.wantedPlantDef.plant.sowMinSkill) { JobFailReason.Is("UnderAllowedSkill".Translate(WorkGiver_Grower.wantedPlantDef.plant.sowMinSkill), def.label); return(null); } for (int j = 0; j < thingList.Count; j++) { Thing thing3 = thingList[j]; if (!thing3.def.BlocksPlanting()) { continue; } if (!pawn.CanReserve(thing3, 1, -1, null, forced)) { return(null); } if (thing3.def.category == ThingCategory.Plant) { if (!thing3.IsForbidden(pawn)) { return(JobMaker.MakeJob(JobDefOf.CutPlant, thing3)); } return(null); } if (thing3.def.EverHaulable) { return(HaulAIUtility.HaulAsideJobFor(pawn, thing3)); } return(null); } if (!WorkGiver_Grower.wantedPlantDef.CanEverPlantAt_NewTemp(c, map) || !PlantUtility.GrowthSeasonNow(c, map, forSowing: true) || !pawn.CanReserve(c, 1, -1, null, forced)) { return(null); } Job job = JobMaker.MakeJob(JobDefOf.Sow, c); job.plantDefToSow = WorkGiver_Grower.wantedPlantDef; return(job); }
// Token: 0x060000AB RID: 171 RVA: 0x00005B20 File Offset: 0x00003D20 public override Job JobOnCell(Pawn pawn, IntVec3 c, bool forced = false) { Map map = pawn.Map; bool flag = c.IsForbidden(pawn); Job result; if (flag) { result = null; } else { bool flag2 = !PlantUtility.GrowthSeasonNow(c, map, false); if (flag2) { result = null; } else { bool flag3 = WorkGiver_WPGrower.wantedPlantDef == null; if (flag3) { WorkGiver_WPGrower.wantedPlantDef = WorkGiver_WPGrower.CalculateWantedPlantDef(c, map); bool flag4 = WorkGiver_WPGrower.wantedPlantDef == null; if (flag4) { return(null); } } List <Thing> thingList = c.GetThingList(map); bool flag5 = false; for (int i = 0; i < thingList.Count; i++) { Thing thing = thingList[i]; bool flag6 = thing.def == WorkGiver_WPGrower.wantedPlantDef; if (flag6) { return(null); } bool flag7 = (thing is Blueprint || thing is Frame) && thing.Faction == pawn.Faction; if (flag7) { flag5 = true; } } bool flag8 = flag5; if (flag8) { Thing edifice = c.GetEdifice(map); bool flag9 = edifice == null || edifice.def.fertility < 0f; if (flag9) { return(null); } } bool cavePlant = WorkGiver_WPGrower.wantedPlantDef.plant.cavePlant; if (cavePlant) { bool flag10 = !c.Roofed(map); if (flag10) { JobFailReason.Is(WorkGiver_WPGrowerSow.CantSowCavePlantBecauseUnroofedTrans, null); return(null); } bool flag11 = map.glowGrid.GameGlowAt(c, true) > 0f; if (flag11) { JobFailReason.Is(WorkGiver_WPGrowerSow.CantSowCavePlantBecauseOfLightTrans, null); return(null); } } Plant plant = c.GetPlant(map); bool flag12 = plant != null && plant.def.plant.blockAdjacentSow; if (flag12) { bool flag13 = !pawn.CanReserve(plant, 1, -1, null, false) || plant.IsForbidden(pawn); if (flag13) { result = null; } else { result = new Job(JobDefOf.CutPlant, plant); } } else { Thing thing2 = PlantUtility.AdjacentSowBlocker(WorkGiver_WPGrower.wantedPlantDef, c, map); bool flag14 = thing2 != null; if (flag14) { Plant plant2 = thing2 as Plant; bool flag15 = plant2 != null && pawn.CanReserve(plant2, 1, -1, null, false) && !plant2.IsForbidden(pawn); if (flag15) { IPlantToGrowSettable plantToGrowSettable = plant2.Position.GetPlantToGrowSettable(plant2.Map); bool flag16 = plantToGrowSettable == null || plantToGrowSettable.GetPlantDefToGrow() != plant2.def; if (flag16) { return(new Job(JobDefOf.CutPlant, plant2)); } } result = null; } else { bool flag17 = WorkGiver_WPGrower.wantedPlantDef.plant.sowMinSkill > 0 && pawn.skills != null && pawn.skills.GetSkill(SkillDefOf.Plants).Level < WorkGiver_WPGrower.wantedPlantDef.plant.sowMinSkill; if (flag17) { result = null; } else { int j = 0; while (j < thingList.Count) { Thing thing3 = thingList[j]; bool blockPlanting = thing3.def.BlockPlanting; if (blockPlanting) { bool flag18 = !pawn.CanReserve(thing3, 1, -1, null, false); if (flag18) { return(null); } bool flag19 = thing3.def.category == ThingCategory.Plant; if (flag19) { bool flag20 = !thing3.IsForbidden(pawn); if (flag20) { return(new Job(JobDefOf.CutPlant, thing3)); } return(null); } else { bool everHaulable = thing3.def.EverHaulable; if (everHaulable) { return(HaulAIUtility.HaulAsideJobFor(pawn, thing3)); } return(null); } } else { j++; } } bool flag21 = !WorkGiver_WPGrower.wantedPlantDef.CanEverPlantAt(c, map) || !PlantUtility.GrowthSeasonNow(c, map, false) || !pawn.CanReserve(c, 1, -1, null, false); if (flag21) { result = null; } else { result = new Job(WPJobDefOf.WPSow, c) { plantDefToSow = WorkGiver_WPGrower.wantedPlantDef }; } } } } } } return(result); }
public override Job JobOnCell(Pawn pawn, IntVec3 c, bool forced = false) { Map map = pawn.Map; if (c.IsForbidden(pawn)) { return(null); } if (!PlantUtility.GrowthSeasonNow(c, map, true)) { return(null); } if (WorkGiver_Grower.wantedPlantDef == null) { WorkGiver_Grower.wantedPlantDef = WorkGiver_Grower.CalculateWantedPlantDef(c, map); if (WorkGiver_Grower.wantedPlantDef == null) { return(null); } } List <Thing> thingList = c.GetThingList(map); bool flag = false; for (int i = 0; i < thingList.Count; i++) { Thing thing = thingList[i]; if (thing.def == WorkGiver_Grower.wantedPlantDef) { return(null); } if ((thing is Blueprint || thing is Frame) && thing.Faction == pawn.Faction) { flag = true; } } if (flag) { Thing edifice = c.GetEdifice(map); if (edifice == null || edifice.def.fertility < 0f) { return(null); } } if (WorkGiver_Grower.wantedPlantDef.plant.cavePlant) { if (!c.Roofed(map)) { JobFailReason.Is(WorkGiver_GrowerSow.CantSowCavePlantBecauseUnroofedTrans, null); return(null); } if (map.glowGrid.GameGlowAt(c, true) > 0f) { JobFailReason.Is(WorkGiver_GrowerSow.CantSowCavePlantBecauseOfLightTrans, null); return(null); } } if (WorkGiver_Grower.wantedPlantDef.plant.interferesWithRoof && c.Roofed(pawn.Map)) { return(null); } Plant plant = c.GetPlant(map); if (plant != null && plant.def.plant.blockAdjacentSow) { LocalTargetInfo target = plant; if (!pawn.CanReserve(target, 1, -1, null, forced) || plant.IsForbidden(pawn)) { return(null); } return(new Job(JobDefOf.CutPlant, plant)); } else { Thing thing2 = PlantUtility.AdjacentSowBlocker(WorkGiver_Grower.wantedPlantDef, c, map); if (thing2 != null) { Plant plant2 = thing2 as Plant; if (plant2 != null) { LocalTargetInfo target = plant2; if (pawn.CanReserve(target, 1, -1, null, forced) && !plant2.IsForbidden(pawn)) { IPlantToGrowSettable plantToGrowSettable = plant2.Position.GetPlantToGrowSettable(plant2.Map); if (plantToGrowSettable == null || plantToGrowSettable.GetPlantDefToGrow() != plant2.def) { return(new Job(JobDefOf.CutPlant, plant2)); } } } return(null); } if (WorkGiver_Grower.wantedPlantDef.plant.sowMinSkill > 0 && pawn.skills != null && pawn.skills.GetSkill(SkillDefOf.Plants).Level < WorkGiver_Grower.wantedPlantDef.plant.sowMinSkill) { return(null); } int j = 0; while (j < thingList.Count) { Thing thing3 = thingList[j]; if (thing3.def.BlockPlanting) { LocalTargetInfo target = thing3; if (!pawn.CanReserve(target, 1, -1, null, forced)) { return(null); } if (thing3.def.category == ThingCategory.Plant) { if (!thing3.IsForbidden(pawn)) { return(new Job(JobDefOf.CutPlant, thing3)); } return(null); } else { if (thing3.def.EverHaulable) { return(HaulAIUtility.HaulAsideJobFor(pawn, thing3)); } return(null); } } else { j++; } } if (WorkGiver_Grower.wantedPlantDef.CanEverPlantAt(c, map) && PlantUtility.GrowthSeasonNow(c, map, true)) { LocalTargetInfo target = c; if (pawn.CanReserve(target, 1, -1, null, forced)) { return(new Job(JobDefOf.Sow, c) { plantDefToSow = WorkGiver_Grower.wantedPlantDef }); } } return(null); } }
public bool MoveNext() { uint num = (uint)this.$PC; this.$PC = -1; switch (num) { case 0u: this.$current = 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)); if (!this.$disposing) { this.$PC = 1; } return(true); case 1u: < MakeNewToils > c__AnonStorey.sowToil = new Toil(); < MakeNewToils > c__AnonStorey.sowToil.initAction = delegate() { < MakeNewToils > c__AnonStorey.< > f__ref$0.$this.TargetThingA = GenSpawn.Spawn(< MakeNewToils > c__AnonStorey.< > f__ref$0.$this.job.plantDefToSow, <MakeNewToils> c__AnonStorey.< > f__ref$0.$this.TargetLocA, <MakeNewToils> c__AnonStorey.< > f__ref$0.$this.Map, WipeMode.Vanish);
protected override IEnumerable <Toil> MakeNewToils() { _003CMakeNewToils_003Ec__Iterator0 _003CMakeNewToils_003Ec__Iterator = (_003CMakeNewToils_003Ec__Iterator0) /*Error near IL_0036: stateMachine*/; yield return(Toils_Goto.GotoCell(TargetIndex.A, PathEndMode.Touch).FailOn(() => PlantUtility.AdjacentSowBlocker(_003CMakeNewToils_003Ec__Iterator._0024this.job.plantDefToSow, _003CMakeNewToils_003Ec__Iterator._0024this.TargetA.Cell, _003CMakeNewToils_003Ec__Iterator._0024this.Map) != null).FailOn(() => !_003CMakeNewToils_003Ec__Iterator._0024this.job.plantDefToSow.CanEverPlantAt(_003CMakeNewToils_003Ec__Iterator._0024this.TargetLocA, _003CMakeNewToils_003Ec__Iterator._0024this.Map))); /*Error: Unable to find new state assignment for yield return*/; }