public override Job JobOnCell(Pawn pawn, IntVec3 c, bool forced = false)
        {
            Map map = pawn.Map;
            Job result;

            if (c.IsForbidden(pawn))
            {
                result = null;
            }
            else if (!GenPlant.GrowthSeasonNow(c, map, true))
            {
                result = null;
            }
            else
            {
                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))
                {
                    result = null;
                }
                else
                {
                    Plant plant = c.GetPlant(map);
                    if (plant != null)
                    {
                        if (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));
                        }
                    }
                    Thing thing2 = GenPlant.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));
                                }
                            }
                        }
                        result = null;
                    }
                    else
                    {
                        if (WorkGiver_Grower.wantedPlantDef.plant.sowMinSkill > 0)
                        {
                            if (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) && GenPlant.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
                                });
                            }
                        }
                        result = null;
                    }
                }
            }
            return(result);
        }
예제 #2
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            yield return(Toils_Goto.GotoCell(TargetIndex.A, PathEndMode.Touch).FailOn(() => GenPlant.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);
                this.$this.pawn.Reserve(this.$this.TargetThingA, sowToil.actor.CurJob, 1, -1, null);
                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.Growing, 0.11f, 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.");
                }
                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);
                    }
                }
            });
            yield return(sowToil);

            if (this.pawn.story.traits.HasTrait(TraitDefOf.GreenThumb))
            {
                yield return(new Toil
                {
                    initAction = delegate
                    {
                        this.$this.pawn.needs.mood.thoughts.memories.TryGainMemory(ThoughtDefOf.GreenThumbHappy, null);
                    }
                });
            }
        }
        protected override IEnumerable <Toil> MakeNewToils()
        {
            _003CMakeNewToils_003Ec__Iterator0 _003CMakeNewToils_003Ec__Iterator = (_003CMakeNewToils_003Ec__Iterator0) /*Error near IL_003a: stateMachine*/;

            yield return(Toils_Goto.GotoCell(TargetIndex.A, PathEndMode.Touch).FailOn(() => GenPlant.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*/;
        }
예제 #4
0
            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(() => GenPlant.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);
예제 #5
0
        public override Job JobOnCell(Pawn pawn, IntVec3 c)
        {
            Map map = pawn.Map;

            if (c.IsForbidden(pawn))
            {
                return(null);
            }
            if (!GenPlant.GrowthSeasonNow(c, map))
            {
                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 < 0.0))
                {
                    goto IL_00dc;
                }
                return(null);
            }
            goto IL_00dc;
IL_00dc:
            if (WorkGiver_Grower.wantedPlantDef.plant.cavePlant)
            {
                if (!c.Roofed(map))
                {
                    JobFailReason.Is(WorkGiver_GrowerSow.CantSowCavePlantBecauseUnroofedTrans);
                    return(null);
                }
                if (map.glowGrid.GameGlowAt(c, true) > 0.0)
                {
                    JobFailReason.Is(WorkGiver_GrowerSow.CantSowCavePlantBecauseOfLightTrans);
                    return(null);
                }
            }
            Plant plant = c.GetPlant(map);

            if (plant != null && plant.def.plant.blockAdjacentSow)
            {
                if (pawn.CanReserve(plant, 1, -1, null, false) && !plant.IsForbidden(pawn))
                {
                    return(new Job(JobDefOf.CutPlant, plant));
                }
                return(null);
            }
            Thing thing2 = GenPlant.AdjacentSowBlocker(WorkGiver_Grower.wantedPlantDef, c, map);

            if (thing2 != null)
            {
                Plant plant2 = thing2 as Plant;
                if (plant2 != null && pawn.CanReserve(plant2, 1, -1, null, false) && !plant2.IsForbidden(pawn))
                {
                    IPlantToGrowSettable plantToGrowSettable = plant2.Position.GetPlantToGrowSettable(plant2.Map);
                    if (plantToGrowSettable != null && plantToGrowSettable.GetPlantDefToGrow() == plant2.def)
                    {
                        goto IL_0211;
                    }
                    return(new Job(JobDefOf.CutPlant, plant2));
                }
                goto IL_0211;
            }
            if (WorkGiver_Grower.wantedPlantDef.plant.sowMinSkill > 0 && pawn.skills != null && pawn.skills.GetSkill(SkillDefOf.Growing).Level < WorkGiver_Grower.wantedPlantDef.plant.sowMinSkill)
            {
                return(null);
            }
            for (int j = 0; j < thingList.Count; j++)
            {
                Thing thing3 = thingList[j];
                if (thing3.def.BlockPlanting)
                {
                    if (!pawn.CanReserve(thing3, 1, -1, null, false))
                    {
                        return(null);
                    }
                    if (thing3.def.category == ThingCategory.Plant)
                    {
                        if (!thing3.IsForbidden(pawn))
                        {
                            return(new Job(JobDefOf.CutPlant, thing3));
                        }
                        return(null);
                    }
                    if (thing3.def.EverHaulable)
                    {
                        return(HaulAIUtility.HaulAsideJobFor(pawn, thing3));
                    }
                    return(null);
                }
            }
            if (WorkGiver_Grower.wantedPlantDef.CanEverPlantAt(c, map) && GenPlant.GrowthSeasonNow(c, map) && pawn.CanReserve(c, 1, -1, null, false))
            {
                Job job = new Job(JobDefOf.Sow, c);
                job.plantDefToSow = WorkGiver_Grower.wantedPlantDef;
                return(job);
            }
            return(null);

IL_0211:
            return(null);
        }