Exemple #1
0
        protected override Job TryGiveJob(Pawn pawn)
        {
            if (!this.CanDoDuringMedicalRest && pawn.InBed() && HealthAIUtility.ShouldSeekMedicalRest(pawn))
            {
                return(null);
            }
            List <JoyGiverDef> allDefsListForReading = DefDatabase <JoyGiverDef> .AllDefsListForReading;
            JoyToleranceSet    tolerances            = pawn.needs.joy.tolerances;

            for (int i = 0; i < allDefsListForReading.Count; i++)
            {
                JoyGiverDef joyGiverDef = allDefsListForReading[i];
                this.joyGiverChances[joyGiverDef] = 0f;
                if (this.JoyGiverAllowed(joyGiverDef))
                {
                    if (!pawn.needs.joy.tolerances.BoredOf(joyGiverDef.joyKind))
                    {
                        if (joyGiverDef.Worker.MissingRequiredCapacity(pawn) == null)
                        {
                            if (joyGiverDef.pctPawnsEverDo < 1f)
                            {
                                Rand.PushState(pawn.thingIDNumber ^ 63216713);
                                if (Rand.Value >= joyGiverDef.pctPawnsEverDo)
                                {
                                    Rand.PopState();
                                    goto IL_131;
                                }
                                Rand.PopState();
                            }
                            float num  = tolerances[joyGiverDef.joyKind];
                            float num2 = Mathf.Pow(1f - num, 5f);
                            num2 = Mathf.Max(0.001f, num2);
                            this.joyGiverChances[joyGiverDef] = joyGiverDef.Worker.GetChance(pawn) * num2;
                        }
                    }
                }
                IL_131 :;
            }
            for (int j = 0; j < this.joyGiverChances.Count; j++)
            {
                JoyGiverDef def;
                if (!allDefsListForReading.TryRandomElementByWeight((JoyGiverDef d) => this.joyGiverChances[d], out def))
                {
                    break;
                }
                Job job = this.TryGiveJobFromJoyGiverDefDirect(def, pawn);
                if (job != null)
                {
                    return(job);
                }
                this.joyGiverChances[def] = 0f;
            }
            return(null);
        }
        protected override Job TryGiveJob(Pawn pawn)
        {
            if (!CanDoDuringMedicalRest && pawn.InBed() && HealthAIUtility.ShouldSeekMedicalRest(pawn))
            {
                return(null);
            }
            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 (!JoyGiverAllowed(joyGiverDef) || pawn.needs.joy.tolerances.BoredOf(joyGiverDef.joyKind) || !joyGiverDef.Worker.CanBeGivenTo(pawn))
                {
                    continue;
                }
                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 = TryGiveJobFromJoyGiverDefDirect(result, pawn);
                if (job != null)
                {
                    return(job);
                }
                joyGiverChances[result] = 0f;
            }
            return(null);
        }
        protected override Job TryGiveJob(Pawn pawn)
        {
            if (!this.CanDoDuringMedicalRest && pawn.InBed() && HealthAIUtility.ShouldSeekMedicalRest(pawn))
            {
                return(null);
            }
            List <JoyGiverDef> allDefsListForReading = DefDatabase <JoyGiverDef> .AllDefsListForReading;
            JoyToleranceSet    tolerances            = pawn.needs.joy.tolerances;

            for (int i = 0; i < allDefsListForReading.Count; i++)
            {
                JoyGiverDef joyGiverDef = allDefsListForReading[i];
                this.joyGiverChances[joyGiverDef] = 0f;
                if (this.JoyGiverAllowed(joyGiverDef) && joyGiverDef.Worker.MissingRequiredCapacity(pawn) == null)
                {
                    if (joyGiverDef.pctPawnsEverDo < 1.0)
                    {
                        Rand.PushState(pawn.thingIDNumber ^ 63216713);
                        if (Rand.Value >= joyGiverDef.pctPawnsEverDo)
                        {
                            Rand.PopState();
                            continue;
                        }
                        Rand.PopState();
                    }
                    float chance = joyGiverDef.Worker.GetChance(pawn);
                    float num    = (float)(1.0 - tolerances[joyGiverDef.joyKind]);
                    chance *= num * num;
                    this.joyGiverChances[joyGiverDef] = chance;
                }
            }
            int         num2 = 0;
            JoyGiverDef def  = default(JoyGiverDef);

            while (num2 < this.joyGiverChances.Count && ((IEnumerable <JoyGiverDef>)allDefsListForReading).TryRandomElementByWeight <JoyGiverDef>((Func <JoyGiverDef, float>)((JoyGiverDef d) => this.joyGiverChances[d]), out def))
            {
                Job job = this.TryGiveJobFromJoyGiverDefDirect(def, pawn);
                if (job != null)
                {
                    return(job);
                }
                this.joyGiverChances[def] = 0f;
                num2++;
            }
            return(null);
        }