コード例 #1
0
 public static bool TryGiveJobFromJoyGiverDefDirect(JobGiver_Work __instance, ref Job __result, JoyGiverDef def, Pawn pawn)
 {
     pawnx    = pawn;
     defx     = def;
     __result = defx.Worker.TryGiveJob(pawnx);
     return(false);
 }
コード例 #2
0
 private static void Postfix(JoyGiverDef def, Pawn pawn)
 {
     if (pawn.InspirationDef == VSIE_DefOf.VSIE_Party_Frenzy)
     {
         VSIE_Utils.SocialInteractionsManager.Notify_AspirationProgress(pawn);
     }
 }
コード例 #3
0
 public Job DoTryGiveJob(Pawn pawn, Thing t, JoyGiverDef def)
 {
     if (!WatchBuildingUtility.TryFindBestWatchCell(t, pawn, def.desireSit, out var result, out var chair))
     {
         return(null);
     }
     return(JobMaker.MakeJob(def.jobDef, t, result, chair));
 }
コード例 #4
0
        static bool Prefix(ref Job __result, Pawn pawn, Thing t, bool forced)
        {
            if (!Settings.give_sick_joy_drugs)
            {
                return(true);
            }
            //
            Pawn sick = (Pawn)t;
            List <JoyGiverDef> defs = DefDatabase <JoyGiverDef> .AllDefsListForReading.FindAll(
                d => d.giverClass == typeof(JoyGiver_Ingest) ||
                d.giverClass == typeof(JoyGiver_TakeDrug_Patient) ||
                d.giverClass == typeof(JoyGiver_VisitSickPawn));

            //
            var chances = new DefMap <JoyGiverDef, float>();

            foreach (var d in defs)
            {
                if (d.Worker.CanBeGivenTo(pawn))
                {
                    chances[d] = (d.giverClass == typeof(JoyGiver_TakeDrug_Patient) ? 4f : d.Worker.GetChance(sick)) * Mathf.Max(0.001f, Mathf.Pow(1f - sick.needs.joy.tolerances[d.joyKind], 5f));
                }
                else
                {
                    chances[d] = 0f;
                }
            }
            JoyGiverDef def     = null;
            Job         newJob  = null;
            int         counter = 0;

            while (counter < defs.Count && defs.TryRandomElementByWeight(d => chances[d], out def))
            {
                if (def.giverClass == typeof(JoyGiver_VisitSickPawn))
                {
                    return(true);
                }
                //
                newJob = def.Worker.TryGiveJob(sick);
                if (newJob != null)
                {
                    __result         = JobMaker.MakeJob(JobDefOf.FeedPatient);
                    __result.targetA = newJob.targetA;
                    __result.targetB = t;
                    __result.count   = newJob.count;

                    return(false);
                }
                chances[def] = 0f;
                counter++;
            }

            return(true);
        }
コード例 #5
0
        /// <summary>
        /// Tries to give the pawn a job from joy giver definition
        /// </summary>
        /// <param name="def">The definition.</param>
        /// <param name="pawn">The pawn.</param>
        /// <returns></returns>
        protected override Job TryGiveJobFromJoyGiverDefDirect(JoyGiverDef def, Pawn pawn)
        {
            if (!def.IsValidFor(pawn))
            {
                return(null);
            }

            var joyNeed = pawn.needs?.joy?.CurLevelPercentage ?? 1;

            if (joyNeed > 0.75f)
            {
                return(null);                 //make sure we don't assign the need constantly
            }
            return(base.TryGiveJobFromJoyGiverDefDirect(def, pawn));
        }
コード例 #6
0
        private List <JoyGiverDef> PopulateChances(Pawn pawn)
        {
            var chemicalDef = DefDatabase <JoyKindDef> .GetNamed("Chemical");

            var gluttonousDef = DefDatabase <JoyKindDef> .GetNamed("Gluttonous");

            List <JoyGiverDef> allDefsListForReading = DefDatabase <JoyGiverDef> .AllDefsListForReading;

            if (allDefsListForReading == null)
            {
                Log.ErrorOnce("AllDefsListForReading == null", 331093564);
                return(new List <JoyGiverDef>());
            }
            int i = 0;

            while (i < allDefsListForReading.Count)
            {
                // What is going on here with the jumps!? Is this a decompiler artifact?
                JoyGiverDef joyGiverDef = allDefsListForReading[i];

                // Exclude consumption-based joys (Spirits cannot now eat!)
                if (joyGiverDef.joyKind == chemicalDef || joyGiverDef.joyKind == gluttonousDef)
                {
                    goto IL_A5;
                }

                if (joyGiverDef.pctPawnsEverDo >= 1f)
                {
                    goto IL_6B;
                }
                Rand.PushSeed();
                Rand.Seed = (pawn.thingIDNumber ^ 63216713);
                if (Rand.Value < joyGiverDef.pctPawnsEverDo)
                {
                    Rand.PopSeed();
                    goto IL_6B;
                }
                Rand.PopSeed();
IL_A5:
                i++;
                continue;
IL_6B:
                float num = joyGiverDef.Worker.GetChance(pawn);
                joyGiverChances[joyGiverDef] = num;
                goto IL_A5;
            }
            return(allDefsListForReading);
        }
コード例 #7
0
        public Job TryCreateJob(Pawn pawn, Thing t, bool forced = false)
        {
            JoyGiverDef def = null;
            JobDef defj = null;

            if (t as Building_ShootingRange != null)
            {
                def = (t as Building_ShootingRange).GetJoyGiverDef();
                defj = DefDatabase<JobDef>.GetNamed("UseShootingRange_NonJoy_Work");
            }
            if (t as Building_MartialArtsTarget != null)
            {
                def = (t as Building_MartialArtsTarget).GetJoyGiverDef();
                defj = DefDatabase<JobDef>.GetNamed("UseMartialArtsTarget_NonJoy_Work");
            }

            if (!CanPawnWorkThisJob(pawn, t, forced))
                return null;

            return DoTryGiveJob(pawn, t, def, defj);
        }
コード例 #8
0
        public bool CanPawnWorkThisJob(Pawn pawn, Thing t, bool forced = false)
        {
            JoyGiverDef def = null;
            int typeOfTarget = 0;

            if (!pawn.CanReserve(t, 1))
                return false;

            if (!pawn.CanReach(t, PathEndMode, Danger.Deadly))
                return false;

            if (t as Building_ShootingRange != null)
            {
                def = (t as Building_ShootingRange).GetJoyGiverDef();
                typeOfTarget = 1; // Shooting Range
            }
            if (t as Building_MartialArtsTarget != null)
            {
                def = (t as Building_MartialArtsTarget).GetJoyGiverDef();
                typeOfTarget = 2; // Martial Arts
            }

            if (def == null)
                return false;

            Verb attackVerb = null;
            if (pawn != null)
                attackVerb = pawn.TryGetAttackVerb(t, false);

            // Shooting range + Melee -> No Go
            if ((attackVerb == null || attackVerb.verbProps == null || attackVerb.verbProps.IsMeleeAttack) && typeOfTarget == 1)
                return false;

            // Martial Arts + Weapon -> No Go
            if (!attackVerb.verbProps.IsMeleeAttack && typeOfTarget == 2)
                return false;

            return true;
        }
コード例 #9
0
        private List <JoyGiverDef> PopulateChances(Pawn pawn)
        {
            List <JoyGiverDef> allDefsListForReading = DefDatabase <JoyGiverDef> .AllDefsListForReading;

            if (allDefsListForReading == null)
            {
                Log.Message("AllDefsListForReading == null");
                return(new List <JoyGiverDef>());
            }
            int i = 0;

            while (i < allDefsListForReading.Count)
            {
                JoyGiverDef joyGiverDef = allDefsListForReading[i];
                if (joyGiverDef.pctPawnsEverDo >= 1f)
                {
                    goto IL_6B;
                }
                Rand.PushState();
                Rand.Seed = (pawn.thingIDNumber ^ 63216713);
                if (Rand.Value < joyGiverDef.pctPawnsEverDo)
                {
                    Rand.PopState();
                    goto IL_6B;
                }
                Rand.PopState();
IL_A5:
                i++;
                continue;
IL_6B:
                float num = joyGiverDef.Worker.GetChance(pawn);
                joyGiverChances[joyGiverDef] = num;
                goto IL_A5;
            }
            return(allDefsListForReading);
        }
コード例 #10
0
        public Job TryGiveJob(Pawn pawn, Thing targetThing, bool NoJoyCheck, JoyGiverDef def)
        {
            Verb attackVerb = null;

            if (pawn != null)
            {
                attackVerb = pawn.TryGetAttackVerb(targetThing, false);

                if (pawn.story == null ||
                    (pawn.story.DisabledWorkTagsBackstoryAndTraits & WorkTags.Violent) == WorkTags.Violent)
                {
                    //Log.Error("Prevented Joy because of Incapable of Violent!");
                    attackVerb = null;
                }
            }

            if (attackVerb == null || attackVerb.verbProps == null) // || !attackVerb.verbProps.IsMeleeAttack)
            {
                return(null);
            }

            //return base.TryGiveJob(pawn);

            // From base.TryGiveJob(pawn)
            List <Thing>      searchSet = pawn.Map.listerThings.ThingsOfDef(def.thingDefs[0]);
            Predicate <Thing> predicate = delegate(Thing t)
            {
                if (!pawn.CanReserve(t, def.jobDef.joyMaxParticipants))
                {
                    return(false);
                }
                if (t.IsForbidden(pawn))
                {
                    return(false);
                }
                if (!t.IsSociallyProper(pawn))
                {
                    return(false);
                }
                CompPowerTrader compPowerTrader = t.TryGetComp <CompPowerTrader>();
                return(compPowerTrader == null || compPowerTrader.PowerOn);  // && (!this.def.unroofedOnly || !t.Position.Roofed(pawn.Map));
            };
            Predicate <Thing> validator = predicate;

            // Changed thing definition from base.TryGiveJob(pawn)
            // Because of selection via building
            // ---
            Thing thing = null;

            if (targetThing != null)
            {
                if (pawn.CanReach(targetThing.Position, PathEndMode.Touch, Danger.Some) && validator(targetThing))
                {
                    thing = targetThing;
                }
            }
            if (targetThing == null)
            {
                thing = GenClosest.ClosestThing_Global_Reachable(pawn.Position, pawn.Map, searchSet, PathEndMode.OnCell, TraverseParms.For(pawn, Danger.Some, TraverseMode.ByPawn, false), 9999f, validator, null);
            }
            // ---

            if (thing != null)
            {
                Job job = DoTryGiveJob(pawn, thing, def);
                if (job != null)
                {
                    return(job);
                }
            }
            return(null);
        }
コード例 #11
0
        private static bool Prefix(JobGiver_GetJoy __instance, ref Job __result, Pawn pawn)
        {
            var timeAssignmentDef =
                pawn.timetable == null ? TimeAssignmentDefOf.Anything : pawn.timetable.CurrentAssignment;
            bool result;

            if (timeAssignmentDef != TimeAssignmentDefDinner.DinnerDef)
            {
                result = true;
            }
            else
            {
                if (pawn.InBed() && HealthAIUtility.ShouldSeekMedicalRest(pawn))
                {
                    __result = null;
                    result   = false;
                }
                else
                {
                    var allDefsListForReading = DefDatabase <JoyGiverDef> .AllDefsListForReading;
                    var tolerances            = pawn.needs.joy.tolerances;
                    foreach (var joyGiverDef in allDefsListForReading)
                    {
                        joyGiverChances[joyGiverDef] = 0f;
                        if (joyGiverDef.joyKind != JoyKindDefOf.Gluttonous &&
                            joyGiverDef.defName != "SocialRelax")
                        {
                            continue;
                        }

                        if (!pawn.needs.joy.tolerances.BoredOf(joyGiverDef.joyKind) &&
                            joyGiverDef.Worker.CanBeGivenTo(pawn))
                        {
                            if (joyGiverDef.pctPawnsEverDo < 1f)
                            {
                                Rand.PushState(pawn.thingIDNumber ^ 63216713);
                                if (Rand.Value >= joyGiverDef.pctPawnsEverDo)
                                {
                                    Rand.PopState();
                                    goto IL_196;
                                }

                                Rand.PopState();
                            }

                            var num  = tolerances[joyGiverDef.joyKind];
                            var num2 = Mathf.Pow(1f - num, 5f);
                            num2 = Mathf.Max(0.001f, num2);
                            joyGiverChances[joyGiverDef] = joyGiverDef.Worker.GetChance(pawn) * num2;
                        }

                        IL_196 :;
                    }

                    var num3 = 0;
                    Job job;
                    for (;;)
                    {
                        var  joyGiverDef2 = new JoyGiverDef();
                        bool hasJoyGiver;
                        if (num3 < joyGiverChances.Count)
                        {
                            hasJoyGiver = allDefsListForReading.TryRandomElementByWeight(d => joyGiverChances[d],
                                                                                         out joyGiverDef2);
                        }
                        else
                        {
                            hasJoyGiver = false;
                        }

                        if (!hasJoyGiver)
                        {
                            goto Block_17;
                        }

                        if (pawn.needs.joy.CurLevel < 0.95f || joyGiverDef2.joyKind != JoyKindDefOf.Gluttonous)
                        {
                            job = TryGiveJobFromJoyGiverDefDirect(joyGiverDef2, pawn);
                            if (job != null)
                            {
                                break;
                            }
                        }

                        joyGiverChances[joyGiverDef2] = 0f;
                        num3++;
                    }

                    __result = job;
                    return(false);

Block_17:
                    __result = null;
                    result   = false;
                }
            }

            return(result);
        }
コード例 #12
0
 // Token: 0x0600002B RID: 43 RVA: 0x0000378C File Offset: 0x0000198C
 protected static Job TryGiveJobFromJoyGiverDefDirect(JoyGiverDef def, Pawn pawn)
 {
     return(def.Worker.TryGiveJob(pawn));
 }
コード例 #13
0
 public bool JoyGiverAllowedCrutch(JoyGiverDef def)
 {
     return(JoyGiverAllowed(def));
 }
コード例 #14
0
 public Job TryGiveJobFromJoyGiverDefDirectCrutch(JoyGiverDef def, Pawn pawn)
 {
     return(TryGiveJobFromJoyGiverDefDirect(def, pawn));
 }
 protected static Job TryGiveJobFromJoyGiverDefDirect(JoyGiverDef def, Pawn pawn)
 {
     //Log.Message("def {0} trygivejob".Translate(def.defName));
     return(def.Worker.TryGiveJob(pawn));
 }
        static bool Prefix(JobGiver_GetJoy __instance, ref Job __result, Pawn pawn)
        {
            TimeAssignmentDef timeAssignmentDef = ((pawn.timetable == null) ? TimeAssignmentDefOf.Anything : pawn.timetable.CurrentAssignment);

            if (timeAssignmentDef != TimeAssignmentDefDinner.DinnerDef)
            {
                return(true);
            }

            if (pawn.InBed() && HealthAIUtility.ShouldSeekMedicalRest(pawn))
            {
                __result = null;
                return(false);
            }
            List <JoyGiverDef> allDefsListForReading = DefDatabase <JoyGiverDef> .AllDefsListForReading;
            JoyToleranceSet    tolerances            = pawn.needs.joy.tolerances;

            for (int i = 0; i < allDefsListForReading.Count; i++)
            {
                JoyGiverDef joyGiverDef = allDefsListForReading[i];
                joyGiverChances[joyGiverDef] = 0f;
                if (joyGiverDef.joyKind != JoyKindDefOf.Gluttonous && joyGiverDef.defName != "SocialRelax")
                {
                    continue;                                                                                       //选择暴食和社交休闲娱乐
                }
                //Log.Message("{0} getchance baoshi".Translate(pawn.Label));
                if (!pawn.needs.joy.tolerances.BoredOf(joyGiverDef.joyKind) && joyGiverDef.Worker.CanBeGivenTo(pawn))
                {
                    if (joyGiverDef.pctPawnsEverDo < 1f)
                    {
                        Rand.PushState(pawn.thingIDNumber ^ 63216713);
                        if (Rand.Value >= joyGiverDef.pctPawnsEverDo)
                        {
                            Rand.PopState();
                            goto IL_11A;
                        }
                        Rand.PopState();
                    }
                    float num  = tolerances[joyGiverDef.joyKind];
                    float num2 = Mathf.Pow(1f - num, 5f);
                    num2 = Mathf.Max(0.001f, num2);
                    joyGiverChances[joyGiverDef] = joyGiverDef.Worker.GetChance(pawn) * num2;
                }
                IL_11A :;
            }
            int         num3 = 0;
            JoyGiverDef def;

            while (num3 < joyGiverChances.Count && allDefsListForReading.TryRandomElementByWeight((JoyGiverDef d) => joyGiverChances[d], out def))
            {
                //if(pawn.needs.joy.CurLevel>0.3f && def.joyKind == JoyKindDefOf.Gluttonous && pawn.timetable.GetAssignment((GenLocalDate.HourOfDay(pawn) + 1) % 24) == TimeAssignmentDefDinner.DinnerDef)
                if (pawn.needs.joy.CurLevel < 0.95f || def.joyKind != JoyKindDefOf.Gluttonous)
                {
                    Job job = TryGiveJobFromJoyGiverDefDirect(def, pawn);
                    if (job != null)
                    {
                        __result = job;
                        return(false);
                    }
                }
                //Log.Message("{0} trygivejoy".Translate(pawn.Label));
                joyGiverChances[def] = 0f;
                num3++;
            }
            __result = null;
            return(false);
        }
コード例 #17
0
            //double pass on trying to give a joyjob. At first, we'll try to give a job, that located outside;
            static bool Prefix(ref Job __result, ref JobCrutch __instance, ref Pawn pawn)
            {
                if (!Settings.fulfill_outdoors || !__instance.CanDoDuringMedicalRestCrutch() && pawn.InBed() && HealthAIUtility.ShouldSeekMedicalRest(pawn) ||
                    pawn.needs.outdoors == null || pawn.needs.outdoors.CurLevel >= 0.4f)
                {
                    return(true);
                }

                List <JoyGiverDef>          allDefsListForReading = DefDatabase <JoyGiverDef> .AllDefsListForReading;
                JoyToleranceSet             tolerances            = pawn.needs.joy.tolerances;
                DefMap <JoyGiverDef, float> joyGiverChances       = new DefMap <JoyGiverDef, float>();

                for (int i = 0; i < allDefsListForReading.Count; i++)
                {
                    JoyGiverDef joyGiverDef = allDefsListForReading[i];
                    joyGiverChances[joyGiverDef] = 0f;
                    if (__instance.JoyGiverAllowedCrutch(joyGiverDef) && !pawn.needs.joy.tolerances.BoredOf(joyGiverDef.joyKind) && joyGiverDef.Worker.MissingRequiredCapacity(pawn) == null)
                    {
                        if (joyGiverDef.pctPawnsEverDo < 1f)
                        {
                            Rand.PushState(pawn.thingIDNumber ^ 0x3C49C49);
                            if (Rand.Value >= joyGiverDef.pctPawnsEverDo)
                            {
                                Rand.PopState();
                                continue;
                            }
                            Rand.PopState();
                        }
                        float num = tolerances[joyGiverDef.joyKind];
                        float b   = Mathf.Pow(1f - num, 5f);
                        b = Mathf.Max(0.001f, b);
                        joyGiverChances[joyGiverDef] = joyGiverDef.Worker.GetChance(pawn) * b;
                    }
                }
                for (int j = 0; j < joyGiverChances.Count; j++)
                {
                    if (!allDefsListForReading.TryRandomElementByWeight((JoyGiverDef d) => joyGiverChances[d], out JoyGiverDef result))
                    {
                        break;
                    }
                    Job job = __instance.TryGiveJobFromJoyGiverDefDirectCrutch(result, pawn);
                    if (job != null && job.targetA != null)
                    {
                        if (job.targetA.Thing != null)
                        {
                            if (job.targetA.Thing.GetRoom() != null && job.targetA.Thing.GetRoom().PsychologicallyOutdoors)
                            {
                                __result = job;
                                return(false);
                            }
                        }
                        else if (job.targetA.Cell != null)
                        {
                            IntVec3 vec3 = (IntVec3)job.targetA;
                            if (job.targetA.Cell.GetRoom(pawn.Map).PsychologicallyOutdoors)
                            {
                                __result = job;
                                return(false);
                            }
                        }
                    }
                    joyGiverChances[result] = 0f;
                }
                return(true);
            }
        public override IEnumerable <FloatMenuOption> GetFloatMenuOptions(Pawn selPawn)
        {
            // do nothing if not of colony
            if (selPawn.Faction != Faction.OfPlayer)
            {
                yield break;
            }

            // base float menus
            foreach (FloatMenuOption fmo in base.GetFloatMenuOptions(selPawn))
            {
                yield return(fmo);
            }

            // do shooting menu
            // ================

            // Check Reachability
            if (!selPawn.CanReserve(this, 1))
            {
                yield return(new FloatMenuOption("CannotUseReserved".Translate(), null));

                yield break;
            }
            if (!selPawn.CanReach(this, PathEndMode.InteractionCell, Danger.Deadly))
            {
                yield return(new FloatMenuOption("CannotUseNoPath".Translate(), null));

                yield break;
            }

            // Check weapon status
            Verb attackVerb = null;

            if (selPawn != null)
            {
                attackVerb = selPawn.TryGetAttackVerb(this, true);
            }

            if (attackVerb != null && attackVerb.verbProps != null && attackVerb.verbProps.IsMeleeAttack)
            {
                Thing       chair;
                JoyGiverDef joyGiverDef = this.GetJoyGiverDef();
                IntVec3     standCell   = Utility_PositionFinder.TryFindWatchBuildingPosition(selPawn, this, this.def.building.watchBuildingStandDistanceRange, joyGiverDef.desireSit, out chair);

                Action action_PracticeMartialArts = delegate
                {
                    selPawn.drafter.Drafted = false;

                    Job job = new Job(this.GetJobDef(), this, standCell, chair);

                    if (job != null)
                    {
                        selPawn.jobs.TryTakeOrderedJob(job);
                    }
                };
                yield return(new FloatMenuOption("TrainingFacility_PracticeMartialArts".Translate(), action_PracticeMartialArts));
            }
            else
            {
                yield return(new FloatMenuOption("TrainingFacility_MeleeWeaponRequired".Translate(), null));
            }
        }
コード例 #19
0
        public IEnumerable <IntVec3> CalculateShootingCells()
        {
            JoyGiverDef joyGiverDef = this.GetJoyGiverDef();

            return(Utility_PositionFinder.FindAllWatchBuildingCells(this, this.def.building.watchBuildingStandDistanceRange));
        }