public override AcceptanceReport CanDesignateThing(Thing t)
        {
            // If the thing isn't a plant
            if (t.def.plant == null)
            {
                return(false);
            }

            // If the thing doesn't have a matching PlantWithSecondaryDef
            if (!(t is PlantWithSecondary))
            {
                return("ZEN_MustDesignatePlantsWithSecondary".Translate());
            }
            // If the thing is already designated
            if (Map.designationManager.DesignationOn(t, designationDef) != null)
            {
                return(false);
            }
            // If the secondary resource isn't harvestable
            PlantWithSecondary plant = t as PlantWithSecondary;

            if (!plant.Sec_HarvestableNow)
            {
                return("ZEN_MustDesignateHarvestableSecondary".Translate());
            }
            return(true);
        }
        public override bool HasJobOnCell(Pawn pawn, IntVec3 c)
        {
            List <Thing>       list  = c.GetThingList(pawn.Map);
            PlantWithSecondary plant = null;

            for (int t = 0; t < list.Count; t++)
            {
                if (list[t] is PlantWithSecondary)
                {
                    plant = (PlantWithSecondary)list[t];
                    break;
                }
            }
            return(plant != null && !plant.IsForbidden(pawn) && plant.Sec_HarvestableNow && pawn.CanReserve(plant) && HarvestableLocation(plant, c));
        }
        private bool HasHarvestJobOnCell(Pawn pawn, IntVec3 c)
        {
            Plant plant = c.GetPlant(pawn.Map);

            if (!(plant is PlantWithSecondary))
            {
                return(false);
            }
            PlantWithSecondary sec = (PlantWithSecondary)plant;

            return(plant != null &&
                   !plant.IsForbidden(pawn) &&
                   sec.Sec_HarvestableNow &&
                   plant.LifeStage == PlantLifeStage.Mature &&
                   pawn.CanReserve(plant, 1, -1, null, false) &&
                   HarvestableLocation(plant, c));
        }
        public override Job JobOnThing(Pawn pawn, Thing t, bool forced = false)
        {
            if (t.def.category != ThingCategory.Plant)
            {
                return(null);
            }

            if (!(t is PlantWithSecondary))
            {
                return(null);
            }

            PlantWithSecondary plant = (PlantWithSecondary)t;

            if (!plant.Sec_HarvestableNow)
            {
                return(null);
            }

            Job   job  = new Job(ZenDefOf.ZEN_PlantsHarvestSecondary);
            Map   map  = pawn.Map;
            Room  room = t.Position.GetRoom(map, RegionType.Set_Passable);
            float num  = 0f;

            for (int i = 0; i < 40; i++)
            {
                IntVec3 c2 = t.Position + GenRadial.RadialPattern[i];
                if (c2.GetRoom(map, RegionType.Set_Passable) == room)
                {
                    if (HasHarvestJobOnCell(pawn, c2))
                    {
                        num += 250f;
                        if (num > 2400f)
                        {
                            break;
                        }
                        job.AddQueuedTarget(TargetIndex.A, plant);
                    }
                }
            }
            if (job.targetQueueA != null && job.targetQueueA.Count >= 3)
            {
                job.targetQueueA.SortBy((LocalTargetInfo targ) => targ.Cell.DistanceToSquared(pawn.Position));
            }
            return(job);
        }
        public override AcceptanceReport CanDesignateCell(IntVec3 c)
        {
            if (!c.InBounds(Map) || c.Fogged(Map))
            {
                return(false);
            }
            PlantWithSecondary plant = c.GetPlant(Map) as PlantWithSecondary;

            if (plant == null)
            {
                return("ZEN_MustDesignatePlantsWithSecondary".Translate());
            }
            AcceptanceReport result = CanDesignateThing(plant);

            if (!result.Accepted)
            {
                return(result);
            }
            return(true);
        }
Esempio n. 6
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            yield return(Toils_Reserve.Reserve(TargetIndex.A, 1, -1, null));

            yield return(Toils_Goto.GotoCell(TargetIndex.A, PathEndMode.Touch).FailOn(() => GenPlant.AdjacentSowBlocker(job.plantDefToSow, TargetA.Cell, Map) != null).FailOn(() => !job.plantDefToSow.CanEverPlantAt(TargetLocA, Map)));

            Toil sowToil = new Toil()
            {
                initAction = delegate {
                    TargetThingA = GenSpawn.Spawn(job.plantDefToSow, TargetLocA, Map);
                    pawn.Reserve(TargetThingA, job);
                    PlantWithSecondary plant = (PlantWithSecondary)TargetThingA;
                    plant.Growth = 0f;
                    plant.sown   = true;
                },
                tickAction = delegate {
                    Pawn actor = GetActor();
                    if (actor.skills != null)
                    {
                        actor.skills.Learn(SkillDefOf.Growing, 0.11f, false);
                    }
                    float statValue          = actor.GetStatValue(StatDefOf.PlantWorkSpeed, true);
                    float num                = statValue;
                    PlantWithSecondary plant = Plant;
                    if (plant.LifeStage != PlantLifeStage.Sowing)
                    {
                        Log.Error(this + " getting sowing work while not in Sowing life stage.");
                    }
                    sowWorkDone += num;
                    if (sowWorkDone >= plant.def.plant.sowWork)
                    {
                        plant.Growth     = 0.05f;
                        plant.Sec_Growth = 0.05f;
                        Map.mapDrawer.MapMeshDirty(plant.Position, MapMeshFlag.Things);
                        actor.records.Increment(RecordDefOf.PlantsSown);
                        ReadyForNextToil();
                        return;
                    }
                },
                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, true, -0.5f);
            sowToil.PlaySustainerOrSound(() => SoundDefOf.Interact_Sow);
            sowToil.AddFinishAction(delegate {
                if (TargetThingA != null)
                {
                    PlantWithSecondary plant = (PlantWithSecondary)GetActor().CurJob.GetTarget(TargetIndex.A).Thing;
                    if (sowWorkDone < plant.def.plant.sowWork && !TargetThingA.Destroyed)
                    {
                        TargetThingA.Destroy(DestroyMode.Vanish);
                    }
                }
            });
            yield return(sowToil);

            if (pawn.story.traits.HasTrait(TraitDefOf.GreenThumb))
            {
                yield return(new Toil {
                    initAction = delegate {
                        pawn.needs.mood.thoughts.memories.TryGainMemory(ThoughtDefOf.GreenThumbHappy, null);
                    }
                });
            }
        }