Ejemplo n.º 1
0
        //JoyGiver_SocialRelax.TryFindIngestibleToNurse
        public static void VampsCanDrinkBloodWineNotHumans(JoyGiver_SocialRelax __instance, IntVec3 center, Pawn ingester, ref Thing ingestible, ref bool __result)
        {
            if (ingester.IsVampire() || ingestible?.def?.graphicData?.texPath != "Things/Item/Resource/BloodWine")
            {
                return;
            }

            Thing newIngestible = null;

            __result   = VanillaModified_TryFindIngestibleToNurse(__instance, center, ingester, out newIngestible);
            ingestible = newIngestible;
        }
Ejemplo n.º 2
0
        private static bool VanillaModified_TryFindIngestibleToNurse(JoyGiver_SocialRelax __instance, IntVec3 center, Pawn ingester, out Thing ingestible)
        {
            if (ingester.IsTeetotaler())
            {
                ingestible = null;
                return(false);
            }
            if (ingester.drugs == null)
            {
                ingestible = null;
                return(false);
            }
            AccessTools.Field(typeof(JoyGiver_SocialRelax), "nurseableDrugs").SetValue(__instance, new List <ThingDef>());
            DrugPolicy currentPolicy = ingester.drugs.CurrentPolicy;

            for (int i = 0; i < currentPolicy.Count; i++)
            {
                if (currentPolicy[i].allowedForJoy && currentPolicy[i].drug.ingestible.nurseable)
                {
                    ((List <ThingDef>)AccessTools.Field(typeof(JoyGiver_SocialRelax), "nurseableDrugs").GetValue(__instance)).Add(currentPolicy[i].drug);
                }
            }
            ((List <ThingDef>)AccessTools.Field(typeof(JoyGiver_SocialRelax), "nurseableDrugs").GetValue(__instance)).Shuffle();
            for (int j = 0; j < ((List <ThingDef>)AccessTools.Field(typeof(JoyGiver_SocialRelax), "nurseableDrugs").GetValue(__instance)).Count; j++)
            {
                List <Thing> list = ingester.Map.listerThings.ThingsOfDef(((List <ThingDef>)AccessTools.Field(typeof(JoyGiver_SocialRelax), "nurseableDrugs").GetValue(__instance))[j]);
                if (list.Count > 0)
                {
                    Predicate <Thing> validator = delegate(Thing t)
                    {
                        if (t.def?.graphicData?.texPath == "Things/Item/Resource/BloodWine")
                        {
                            return(false);
                        }
                        if (ingester.CanReserve(t))
                        {
                            return(!t.IsForbidden(ingester));
                        }
                        return(false);
                    };
                    ingestible = GenClosest.ClosestThing_Global_Reachable(center, ingester.Map, list, PathEndMode.OnCell, TraverseParms.For(ingester), 40f, validator);
                    if (ingestible != null)
                    {
                        return(true);
                    }
                }
            }
            ingestible = null;
            return(false);
        }
Ejemplo n.º 3
0
 public static void SearchForSocialRelax(List <Pawn> pawns)
 {
     foreach (var pawn in pawns)
     {
         if (!pawn.mindState.IsIdle && pawn.CurJobDef != JobDefOf.SocialRelax)
         {
             Job result = null;
             try
             {
                 var joyGiver = new JoyGiver_SocialRelax();
                 result = joyGiver.TryGiveJob(pawn);
             }
             catch (Exception exception)
             {
                 JobUtility.TryStartErrorRecoverJob(pawn, pawn.ToStringSafe() + " threw exception while determining job (main)", exception);
             }
             if (result != null && result.def != JobDefOf.GotoWander)
             {
                 pawn.jobs.TryTakeOrderedJob(result);
             }
         }
     }
 }
Ejemplo n.º 4
0
        internal static Job _TryGiveJobInt(this JoyGiver_SocialRelax obj, Pawn pawn, Predicate <CompGatherSpot> gatherSpotValidator)
        {
            var JoyGiver_SocialRelax_TryUseThing = new _JoyGiver_SocialRelax._TryUseThing();

            JoyGiver_SocialRelax_TryUseThing.pawn = pawn;

            if (GatherSpotLister.activeSpots.NullOrEmpty())
            {
                return((Job)null);
            }

            var workingSpots               = _JoyGiver_SocialRelax.workingSpots();
            var NumRadiusCells             = _JoyGiver_SocialRelax.NumRadiusCells();
            var RadialPatternMiddleOutward = _JoyGiver_SocialRelax.RadialPatternMiddleOutward();

            workingSpots.Clear();
            for (int index = 0; index < GatherSpotLister.activeSpots.Count; ++index)
            {
                workingSpots.Add(GatherSpotLister.activeSpots[index]);
            }

            CompGatherSpot compGatherSpot;

            while (GenCollection.TryRandomElement <CompGatherSpot>(workingSpots, out compGatherSpot))
            {
                workingSpots.Remove(compGatherSpot);
                if (
                    (!compGatherSpot.parent.IsForbidden(pawn)) &&
                    (pawn.CanReach(
                         compGatherSpot.parent,
                         PathEndMode.Touch,
                         Danger.None,
                         false)) &&
                    (compGatherSpot.parent.IsSociallyProper(pawn)) &&
                    (
                        (gatherSpotValidator == null) ||
                        (gatherSpotValidator(compGatherSpot))
                    )
                    )
                {
                    Job job = (Job)null;
                    if (compGatherSpot.parent.def.surfaceType == SurfaceType.Eat)
                    {
                        for (int index = 0; index < 30; ++index)
                        {
                            Building sittableThing = compGatherSpot.parent.RandomAdjacentCellCardinal().GetEdifice();
                            if (
                                (sittableThing != null) &&
                                (sittableThing.def.building.isSittable) &&
                                (pawn.CanReserve(
                                     (TargetInfo)((Thing)sittableThing),
                                     1))
                                )
                            {
                                job = new Job(
                                    JobDefOf.SocialRelax,
                                    (TargetInfo)((Thing)compGatherSpot.parent),
                                    (TargetInfo)((Thing)sittableThing));
                            }
                        }
                    }
                    else
                    {
                        for (int index = 0; index < RadialPatternMiddleOutward.Count; ++index)
                        {
                            Building sittableThing = (compGatherSpot.parent.Position + RadialPatternMiddleOutward[index]).GetEdifice();
                            if (
                                (sittableThing != null) &&
                                (sittableThing.def.building.isSittable) &&
                                (
                                    (pawn.CanReserve(
                                         (TargetInfo)((Thing)sittableThing),
                                         1)) &&
                                    (!sittableThing.IsForbidden(pawn)) &&
                                    (GenSight.LineOfSight(
                                         compGatherSpot.parent.Position,
                                         sittableThing.Position,
                                         true))
                                )
                                )
                            {
                                job = new Job(
                                    JobDefOf.SocialRelax,
                                    (TargetInfo)((Thing)compGatherSpot.parent),
                                    (TargetInfo)((Thing)sittableThing));
                                break;
                            }
                        }
                        if (job == null)
                        {
                            for (int index = 0; index < 30; ++index)
                            {
                                IntVec3 occupySpot = compGatherSpot.parent.Position + GenRadial.RadialPattern[Rand.Range(1, NumRadiusCells)];
                                if (
                                    (pawn.CanReserveAndReach(
                                         occupySpot,
                                         PathEndMode.OnCell,
                                         Danger.None,
                                         1)) &&
                                    (occupySpot.GetEdifice() == null) &&
                                    (GenSight.LineOfSight(
                                         compGatherSpot.parent.Position,
                                         occupySpot,
                                         true))
                                    )
                                {
                                    job = new Job(
                                        JobDefOf.SocialRelax,
                                        (TargetInfo)((Thing)compGatherSpot.parent),
                                        (TargetInfo)occupySpot);
                                }
                            }
                        }
                    }
                    if (job == null)
                    {
                        return((Job)null);
                    }
                    if (
                        (pawn.RaceProps.ToolUser) &&
                        (pawn.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation)) &&
                        (
                            (pawn.story == null) ||
                            (pawn.story.traits.DegreeOfTrait(TraitDefOf.DrugDesire) >= 0)
                        )
                        )
                    {
                        List <Thing> list = Find.ListerThings.AllThings.Where(t => (
                                                                                  (t.def.IsAlcohol()) ||
                                                                                  (t is Building_AutomatedFactory)
                                                                                  )).ToList();
                        if (list.Count > 0)
                        {
                            Predicate <Thing> validator = new Predicate <Thing>(JoyGiver_SocialRelax_TryUseThing.CanUseThing);
                            Thing             thing     = GenClosest.ClosestThing_Global_Reachable(
                                compGatherSpot.parent.Position,
                                list,
                                PathEndMode.OnCell,
                                TraverseParms.For(
                                    JoyGiver_SocialRelax_TryUseThing.pawn,
                                    JoyGiver_SocialRelax_TryUseThing.pawn.NormalMaxDanger()),
                                40f,
                                validator);
                            if (thing != null)
                            {
                                job.targetC       = (TargetInfo)thing;
                                job.maxNumToCarry = Mathf.Min(thing.stackCount, thing.def.ingestible.maxNumToIngestAtOnce);
                            }
                        }
                    }
                    return(job);
                }
            }
            return((Job)null);
        }