Example #1
0
 public static bool NeedsToBeManagedByRopeModified(Pawn animal)
 {
     if (IsMountableUtility.IsCurrentlyMounted(animal))
     {
         return(true);
     }
     else
     {
         return(AnimalPenUtility.NeedsToBeManagedByRope(animal));
     }
 }
Example #2
0
        private static bool TryParkAnimalPen(JobDriver __instance, ExtendedPawnData pawnData, ref IntVec3 parkLoc, Toil toil)
        {
            bool succeeded = false;
            var  pen       = AnimalPenUtility.GetPenAnimalShouldBeTakenTo(__instance.pawn, pawnData.mount, out string failReason, true, true, false, true);

            if (pen != null)
            {
                parkLoc = AnimalPenUtility.FindPlaceInPenToStand(pen, __instance.pawn);

                if (toil.actor.Map.reachability.CanReach(toil.actor.Position, parkLoc, PathEndMode.OnCell, TraverseParms.For(TraverseMode.PassDoors, Danger.Deadly, false)))
                {
                    toil.actor.pather.StartPath(parkLoc, PathEndMode.OnCell);
                    succeeded = true;
                }
            }
            else
            {
                Log.Message(pawnData.mount.Name + " failed: " + failReason);
            }
            return(succeeded);
        }
        private bool ShouldAlert()
        {
            List <Map> maps = Find.Maps;

            foreach (Map map in maps)
            {
                Area_GU areaNoMount            = (Area_GU)map.areaManager.GetLabeled(Base.NOMOUNT_LABEL);
                Area_GU areaDropAnimal         = (Area_GU)map.areaManager.GetLabeled(Base.DROPANIMAL_LABEL);
                var     unropablePlayerAnimals = map.mapPawns.SpawnedColonyAnimals.Where(animal => animal.Faction == Faction.OfPlayer && !AnimalPenUtility.NeedsToBeManagedByRope(animal));

                if (unropablePlayerAnimals.Count() > 0 && areaNoMount != null && areaDropAnimal != null && areaNoMount.ActiveCells.Count() > 0 && areaDropAnimal.ActiveCells.Count() == 0)
                {
                    return(true);
                }
            }
            return(false);
        }
Example #4
0
        static void Postfix(JobDriver __instance, ref List <Toil> ___toils)
        {
            if (__instance.pawn.Map == null)
            {
                return;
            }
            if (__instance.pawn.Faction != Faction.OfPlayer || __instance.pawn.Drafted)
            {
                return;
            }
            ExtendedDataStorage store = Base.Instance.GetExtendedDataStorage();

            if (store == null)
            {
                return;
            }
            ExtendedPawnData pawnData = store.GetExtendedDataFor(__instance.pawn);


            Area_GU     areaNoMount    = (Area_GU)__instance.pawn.Map.areaManager.GetLabeled(Base.NOMOUNT_LABEL);
            Area_GU     areaDropAnimal = (Area_GU)__instance.pawn.Map.areaManager.GetLabeled(Base.DROPANIMAL_LABEL);
            bool        startedPark    = false;
            IntVec3     originalLoc    = new IntVec3();
            IntVec3     parkLoc        = new IntVec3();
            PathEndMode endMode;

            if (pawnData.mount != null && areaNoMount != null)
            {
                foreach (Toil toil in ___toils)
                {
                    //checkedToil makes sure the ActiveCells.Contains is only called once, preventing performance impact.
                    toil.AddPreTickAction(delegate
                    {
                        if (__instance.pawn.IsHashIntervalTick(60) && !startedPark && pawnData.mount != null && __instance.pawn.CurJobDef != JobDefOf.RopeToPen && areaNoMount.ActiveCells.Contains(toil.actor.pather.Destination.Cell))
                        {
                            originalLoc = toil.actor.pather.Destination.Cell;
                            if (AnimalPenUtility.NeedsToBeManagedByRope(pawnData.mount) || areaDropAnimal == null)
                            {
                                startedPark = TryParkAnimalPen(__instance, pawnData, ref parkLoc, toil);
                            }
                            else
                            {
                                startedPark = TryParkAnimalDropSpot(areaDropAnimal, ref parkLoc, toil);
                            }
                        }
                        //checkedToil = true;
                        if (startedPark && toil.actor.pather.nextCell == parkLoc)
                        {
                            pawnData.mount = null;
                            toil.actor.pather.StartPath(originalLoc, PathEndMode.OnCell);
                            if (pawnData.owning != null)
                            {
                                ExtendedPawnData animalData = store.GetExtendedDataFor(pawnData.owning);
                                animalData.ownedBy          = null;
                                pawnData.owning             = null;
                            }
                        }
                    });
                }
            }
        }
        public override IEnumerable <Toil> MakeNewToils()
        {
            this.FailOn(() => pawn.Map == null || this.Followee == null);
            initialJob = Followee.CurJobDef;
            Toil firstToil = new Toil {
                initAction = delegate
                {
                    WalkRandomNearby();
                }
            };

            firstToil.defaultCompleteMode = ToilCompleteMode.Instant;
            yield return(firstToil);

            Toil toil = new Toil
            {
                tickAction = delegate
                {
                    if (this.Followee.Map == null ||
                        this.Followee.Dead ||
                        this.Followee.Downed ||
                        this.Followee.InMentalState ||
                        this.Followee.InBed() ||
                        this.Followee.CurJobDef == GUC_JobDefOf.Mount ||
                        pawn.health.HasHediffsNeedingTend() ||
                        (pawn.needs.food != null && pawn.needs.food.CurCategory >= HungerCategory.UrgentlyHungry) ||
                        pawn.needs.rest != null && pawn.needs.rest.CurCategory >= RestCategory.VeryTired ||
                        (this.Followee.GetRoom() != null && !(this.Followee.GetRoom().Role == GU_RR_DefOf.Barn || this.Followee.GetRoom().Role == RoomRoleDefOf.None)))//Don't allow animals to follow pawns inside
                    {
                        this.EndJobWith(JobCondition.Succeeded);
                        return;
                    }

                    if (pawn.IsHashIntervalTick(moveInterval) && !this.pawn.pather.Moving)
                    {
                        WalkRandomNearby();
                        moveInterval = Rand.Range(300, 600);
                    }
                    if (TimeUntilExpire(pawn.CurJob) < 10 && Followee.CurJobDef == initialJob)
                    {
                        pawn.CurJob.expiryInterval += 1000;
                    }
                },
                defaultCompleteMode = ToilCompleteMode.Never
            };

            toil.AddFinishAction(() =>
            {
                if (this.Followee.CurJobDef != GUC_JobDefOf.Mount)
                {
                    var pen = AnimalPenUtility.GetPenAnimalShouldBeTakenTo(this.Followee, this.pawn, out string failReason, true, true, false, true);
                    if (pen != null)
                    {
                        IntVec3 c = AnimalPenUtility.FindPlaceInPenToStand(pen, this.Followee);
                        this.Followee.jobs.jobQueue.EnqueueFirst(new Job(JobDefOf.RopeToPen, this.pawn, c));
                    }
                }

                UnsetOwnership();
            });
            yield return(toil);
        }
Example #6
0
 static bool Prefix(Pawn pawn, ref bool __result)
 {
     __result = AnimalPenUtility.IsRopeManagedAnimalDef(pawn.def) && pawn.Spawned;
     return(false);
 }