// Token: 0x0600007E RID: 126 RVA: 0x00007018 File Offset: 0x00005218
        public static Job DoPainReliefResponse(Pawn pawn)
        {
            if ((pawn?.CurJob) != null && pawn.CurJob.def == JobDefOf.Ingest)
            {
                return(null);
            }
            if (MSPainlessData.GetLastPainReliefTick(pawn) + 2500 * DRSettings.PainReliefWaitPeriod > Find.TickManager.TicksGame)
            {
                return(null);
            }
            ThingDef painDrugDef = MSPainUtility.NeedsPainReliefNow(pawn, out bool highpain);

            if (painDrugDef != null && MSDrugUtility.IsOKtoAdmin(pawn, null, painDrugDef) && !MSDrugUtility.IsViolation(pawn, painDrugDef))
            {
                Thing drug = MSDrugUtility.FindDrugFor(pawn, painDrugDef);
                if (drug != null)
                {
                    if (DRSettings.ShowReliefMsg)
                    {
                        Messages.Message(TranslatorFormattedStringExtensions.Translate("MSPainless.ReliefMsg", GenText.CapitalizeFirst(pawn.LabelShort), GenText.CapitalizeFirst(drug.def.label)), pawn, MessageTypeDefOf.NeutralEvent, false);
                    }
                    Job job = new Job(JobDefOf.Ingest, drug)
                    {
                        count = Mathf.Min(new int[]
                        {
                            drug.stackCount,
                            drug.def.ingestible.maxNumToIngestAtOnce,
                            1
                        })
                    };
                    if (drug.Spawned && pawn.drugs != null && !pawn.inventory.innerContainer.Contains(drug.def))
                    {
                        DrugPolicyEntry drugPolicyEntry = pawn.drugs.CurrentPolicy[drug.def];
                        if (drugPolicyEntry.takeToInventory > 0)
                        {
                            job.takeExtraIngestibles = drugPolicyEntry.takeToInventory;
                        }
                    }
                    if (MSPainResponse.IsUsingPainJob(pawn, highpain) && !pawn.IsPrisoner)
                    {
                        MSPainlessData.MSPainlessDataTickSet(pawn);
                        return(job);
                    }
                    if (MSAddDrugBill.GenDrugResponse(false, pawn, null, painDrugDef, null, null, 1))
                    {
                        MSPainlessData.MSPainlessDataTickSet(pawn);
                        return(null);
                    }
                }
            }
            return(null);
        }
Exemple #2
0
    public static void CheckValues(DrugPolicy DP, DrugPolicyEntry DPE, ThingDef drug,
                                   out DrugPolicyEntry DPEChecked)
    {
        DPEChecked = DPE;
        if (!DrugPolicyUtility.IsAddictive(drug))
        {
            DPEChecked.allowedForAddiction = false;
        }

        if (!drug.IsPleasureDrug)
        {
            DPEChecked.allowedForJoy = false;
        }
    }
Exemple #3
0
            private static DrugPolicyEntry AddDef(ThingDef drugDef, List <DrugPolicyEntry> entriesInt)
            {
                if (drugDef.category == ThingCategory.Item && drugDef.IsDrug)
                {
                    Log.Message("Processed " + drugDef);
                    DrugPolicyEntry drugPolicyEntry = new DrugPolicyEntry {
                        drug = drugDef, allowedForAddiction = true
                    };
                    entriesInt.Add(drugPolicyEntry);
                    entriesInt.SortBy(e => e.drug.GetCompProperties <CompProperties_Drug>().listOrder);

                    return(drugPolicyEntry);
                }
                throw new Exception("DrugDef " + drugDef.LabelCap + " is not a drug or of ThingCategory Item.");
            }
Exemple #4
0
            public static void Postfix(DrugPolicy __instance, ref DrugPolicyEntry __result, ThingDef drugDef)
            {
                var entriesInt = Traverse.Create(__instance).Field("entriesInt").GetValue <List <DrugPolicyEntry> >();

                foreach (DrugPolicyEntry entry in entriesInt)
                {
                    if (entry.drug == drugDef)
                    {
                        __result = entry;
                        return;
                    }
                }
                // Added: Missing def
                __result = AddDef(drugDef, entriesInt);
            }
Exemple #5
0
 // Token: 0x0600004D RID: 77 RVA: 0x00005358 File Offset: 0x00003558
 public static bool DPExists(DrugPolicy policy, ThingDef drugDef)
 {
     if (policy.Count > 0)
     {
         for (int i = 0; i < policy.Count; i++)
         {
             DrugPolicyEntry drugPolicyEntry = policy[i];
             if ((drugPolicyEntry?.drug) == drugDef)
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Exemple #6
0
        public static bool IngestAndTakeToInventoryJob(ref Job __result, Thing drug, Pawn pawn, int maxNumToCarry = 9999)
        {
            Job job = JobMaker.MakeJob(JobDefOf.Ingest, drug);

            job.count = Mathf.Min(drug.stackCount, drug.def.ingestible.maxNumToIngestAtOnce, maxNumToCarry);
            if (pawn.drugs != null && drugPolicyExists(pawn.drugs.CurrentPolicy.entriesInt, drug.def))
            {
                DrugPolicyEntry drugPolicyEntry = pawn.drugs.CurrentPolicy[drug.def];
                int             num             = pawn.inventory.innerContainer.TotalStackCountOfDef(drug.def) - job.count;
                if (drugPolicyEntry.allowScheduled && num <= 0)
                {
                    job.takeExtraIngestibles = drugPolicyEntry.takeToInventory;
                }
            }

            __result = job;
            return(false);
        }
Exemple #7
0
 static void AddDefaults(DrugPolicyEntry dp)
 {
     // I hard code these values here.  I'm sure there's a slicker way to do this using XML etc.
     // But this is way easier and it does what *I* need, at any rate.
     if (dp.drug.defName == "Penoxycyline")
     {
         if (ModLister.HasActiveModWithName("Stronger Penoxycyline (1.0)") ||
             // As of version 1.0, I hate mod names with versions :p  Anyway:
             ModLister.HasActiveModWithName("Stronger Penoxycyline (1.1)"))
         {
             dp.daysFrequency = 30f; // one season apparently
         }
         else
         {
             dp.daysFrequency = 5f; // vanilla
         }
     }
 }
            internal static void Prefix(DrugPolicy __instance, List <DrugPolicyEntry> ___entriesInt)
            {
                if (Scribe.mode != LoadSaveMode.PostLoadInit)
                {
                    return;
                }

                var allDefsListForReading = DefDatabase <ThingDef> .AllDefsListForReading;

                foreach (var t in allDefsListForReading)
                {
                    if (t.category == ThingCategory.Item && t.IsDrug && !___entriesInt.Exists(e => e.drug == t))
                    {
                        DrugPolicyEntry drugPolicyEntry = new DrugPolicyEntry {
                            drug = t, allowedForAddiction = true
                        };
                        ___entriesInt.Add(drugPolicyEntry);
                        Log.Message($"Added {t.label} to drug policy {__instance.label}.");
                    }
                }
                ___entriesInt.SortBy(e => e.drug.GetCompProperties <CompProperties_Drug>().listOrder);
            }
            static bool Prefix(ref bool __result, ref Pawn_DrugPolicyTracker __instance, ref ThingDef thingDef)
            {
                if (!Settings.drugs_use_potential_mood)
                {
                    return(true);
                }
                //i've failed trying to inject "actually changed part" in exact part of a code (result looked too monstrous to me)
                //so I've used a simple solution
                //
                //duplicating initial part
                if (!thingDef.IsIngestible)
                {
                    Log.Error(thingDef + " is not ingestible.");
                    __result = false;
                    return(false);
                }
                if (!thingDef.IsDrug)
                {
                    Log.Error("AllowedToTakeScheduledEver on non-drug " + thingDef);
                    __result = false;
                    return(false);
                }
                if (!__instance.AllowedToTakeScheduledEver(thingDef))
                {
                    __result = false;
                    return(false);
                }
                DrugPolicyEntry drugPolicyEntry = __instance.CurrentPolicy[thingDef];

                //actually changed part
                if (drugPolicyEntry.onlyIfMoodBelow < 1f && __instance.pawn.needs.mood != null &&
                    (__instance.pawn.needs.mood.CurLevelPercentage >= drugPolicyEntry.onlyIfMoodBelow || __instance.pawn.needs.mood.CurInstantLevelPercentage >= drugPolicyEntry.onlyIfMoodBelow))
                {
                    __result = false;
                    return(false);
                }
                return(true);
            }
    public static void AddNewDrugToPolicy(DrugPolicy dp, ThingDef newdrug, DrugCategory DC)
    {
        var drugPolicyEntry = new DrugPolicyEntry
        {
            drug = newdrug, allowedForAddiction = false, allowedForJoy = false, allowScheduled = false
        };

        if (dp.label == "SocialDrugs".Translate())
        {
            if (DC == DrugCategory.Social)
            {
                drugPolicyEntry.allowedForJoy = true;
            }
        }
        else if (dp.label == "Unrestricted".Translate())
        {
            if (newdrug.IsPleasureDrug)
            {
                drugPolicyEntry.allowedForJoy = true;
            }
        }
        else if (dp.label == "OneDrinkPerDay".Translate() &&
                 (DrugPolicyUtility.IsAlcohol(newdrug) || DrugPolicyUtility.IsSmokey(newdrug)) &&
                 newdrug.IsPleasureDrug)
        {
            drugPolicyEntry.allowedForJoy = true;
        }

        if (DrugPolicyUtility.IsAddictive(newdrug))
        {
            drugPolicyEntry.allowedForAddiction = true;
        }

        var list = NonPublicFields.DrugPolicyEntryList(dp);

        list.AddDistinct(drugPolicyEntry);
        NonPublicFields.DrugPolicyEntryList(dp) = list;
    }
Exemple #11
0
        public static bool SavePolicySettings(DrugPolicy policy, FileInfo fi)
        {
            try
            {
                // Write Data
                using (FileStream fileStream = File.Open(fi.FullName, FileMode.Create, FileAccess.Write))
                {
                    using (StreamWriter sw = new StreamWriter(fileStream))
                    {
                        WriteField(sw, "Version", "1");

                        WriteField(sw, "name", policy.label);
                        for (int i = 0; i < policy.Count; ++i)
                        {
                            DrugPolicyEntry e = policy[i];
                            WriteField(sw, "drug", i.ToString());
                            WriteField(sw, "defName", e.drug.defName);
                            WriteField(sw, "allowedForAddiction", e.allowedForAddiction.ToString());
                            WriteField(sw, "allowedForJoy", e.allowedForJoy.ToString());
                            WriteField(sw, "allowScheduled", e.allowScheduled.ToString());
                            WriteField(sw, "daysFrequency", e.daysFrequency.ToString());
                            WriteField(sw, "onlyIfJoyBelow", e.onlyIfJoyBelow.ToString());
                            WriteField(sw, "onlyIfMoodBelow", e.onlyIfMoodBelow.ToString());
                            WriteField(sw, "takeToInventory", e.takeToInventory.ToString());
                            WriteField(sw, "takeToInventoryTempBuffer", e.takeToInventoryTempBuffer);
                            WriteField(sw, BREAK, BREAK);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                LogException("Problem saving storage settings file '" + fi.Name + "'.", e);
                return(false);
            }
            return(true);
        }
Exemple #12
0
 public static void AddNewPolicies()
 {
     if (Current.ProgramState == ProgramState.Playing)
     {
         foreach (DrugPolicy drugPolicy in Current.Game.drugPolicyDatabase.AllPolicies)
         {
             List <DrugPolicyEntry> entriesInt = Traverse.Create(drugPolicy).Field("entriesInt").GetValue <List <DrugPolicyEntry> >();
             if (entriesInt.Find(i => i.drug == CoffeeAndTeaDefOf.SyrCoffee) == null)
             {
                 DrugPolicyEntry drugPolicyEntry = new DrugPolicyEntry();
                 drugPolicyEntry.drug                = CoffeeAndTeaDefOf.SyrCoffee;
                 drugPolicyEntry.allowedForJoy       = true;
                 drugPolicyEntry.allowedForAddiction = true;
                 entriesInt.Add(drugPolicyEntry);
             }
             if (entriesInt.Find(i => i.drug == CoffeeAndTeaDefOf.SyrTea) == null)
             {
                 DrugPolicyEntry drugPolicyEntry = new DrugPolicyEntry();
                 drugPolicyEntry.drug                = CoffeeAndTeaDefOf.SyrTea;
                 drugPolicyEntry.allowedForJoy       = true;
                 drugPolicyEntry.allowedForAddiction = true;
                 entriesInt.Add(drugPolicyEntry);
             }
             if (entriesInt.Find(i => i.drug == CoffeeAndTeaDefOf.SyrHotChocolate) == null)
             {
                 DrugPolicyEntry drugPolicyEntry = new DrugPolicyEntry();
                 drugPolicyEntry.drug          = CoffeeAndTeaDefOf.SyrHotChocolate;
                 drugPolicyEntry.allowedForJoy = true;
                 entriesInt.Add(drugPolicyEntry);
             }
             entriesInt.SortBy((DrugPolicyEntry e) => e.drug.GetCompProperties <CompProperties_Drug>().listOrder);
             Traverse.Create(drugPolicy).Field("entriesInt").SetValue(entriesInt);
             policiesAdded = true;
         }
     }
 }
        // Token: 0x0600006A RID: 106 RVA: 0x000062D4 File Offset: 0x000044D4
        public override void CompTick()
        {
            int responseTicks = 150;

            if (DRSettings.UsePainManagement && MSDrugUtility.IsValidPawnMod(this.Pawn, true) && Gen.IsHashIntervalTick(this.Pawn, responseTicks))
            {
                Pawn pawn = this.Pawn;
                if ((pawn?.Map) != null)
                {
                    Pawn pawn2 = this.Pawn;
                    if ((pawn2?.CurJob) != null && this.Pawn.CurJob.def != JobDefOf.Ingest)
                    {
                        MSPainResponse.CheckPainResponse(this.Pawn);
                    }
                }
                else if (CaravanUtility.IsCaravanMember(this.Pawn))
                {
                    MSPainResponse.CheckCaravanPainResponse(this.Pawn);
                }
            }
            if (DRSettings.UseDrugResponse && MSDrugUtility.IsValidPawnMod(this.Pawn, false) && Gen.IsHashIntervalTick(this.Pawn, responseTicks + 50))
            {
                Pawn pawn3 = this.Pawn;
                if ((pawn3?.Map) != null)
                {
                    Pawn pawn4 = this.Pawn;
                    if ((pawn4?.CurJob) == null || this.Pawn.CurJob.def == JobDefOf.Ingest)
                    {
                        return;
                    }
                    Pawn      pawn5 = this.Pawn;
                    HediffSet hediffSet;
                    if (pawn5 == null)
                    {
                        hediffSet = null;
                    }
                    else
                    {
                        Pawn_HealthTracker health = pawn5.health;
                        hediffSet = (health?.hediffSet);
                    }
                    HediffSet hedSet = hediffSet;
                    if (hedSet == null || hedSet == null || hedSet.hediffs.Count <= 0)
                    {
                        return;
                    }
                    using (List <Hediff> .Enumerator enumerator = hedSet.hediffs.GetEnumerator())
                    {
                        while (enumerator.MoveNext())
                        {
                            Hediff hediff = enumerator.Current;
                            if (hediff.Visible && !MSPainlessData.IsProsthetic(hediff) && MSDRUtility.MaladyUsed(hediff.def.defName))
                            {
                                for (int i = 1; i <= 2; i++)
                                {
                                    if (MSPainlessData.CheckIfResponse(this.Pawn, hediff.def.defName, this.DRResponse, i, out ThingDef drugdef) && MSDrugUtility.IsOKtoAdmin(this.Pawn, hediff.def, drugdef) && !MSDrugUtility.IsViolation(this.Pawn, drugdef))
                                    {
                                        Thing drug = MSDrugUtility.FindDrugFor(this.Pawn, drugdef);
                                        if (drug != null)
                                        {
                                            if ((i < 2 && MSDRUtility.GetValueDRBills(hediff.def.defName, DRSettings.MSDRValues)) || (i > 1 && MSDRUtility.GetValueDRBills(hediff.def.defName, DRSettings.MSDRValues2)) || (this.Pawn.IsPrisoner && DRSettings.DoDRIfPrisoner))
                                            {
                                                if ((i < 2 && MSAddDrugBill.GenDrugResponse(true, this.Pawn, hediff.def, drugdef, null, DRSettings.MSDRValues, i)) || (i > 1 && MSAddDrugBill.GenDrugResponse(true, this.Pawn, hediff.def, drugdef, null, DRSettings.MSDRValues2, i)))
                                                {
                                                    MSPainlessData.SetDRResponseData(this.Pawn, hediff.def.defName, drugdef.defName, Find.TickManager.TicksGame, this.DRResponse, i, out List <string> newDRResponse);
                                                    this.DRResponse = newDRResponse;
                                                    MSPainlessData.DoDRResponseMsg(this.Pawn, hediff.def, drugdef);
                                                }
                                            }
                                            else if (MSPainlessData.IsDRCapable(this.Pawn))
                                            {
                                                Job job = new Job(JobDefOf.Ingest, drug)
                                                {
                                                    count = Mathf.Min(new int[]
                                                    {
                                                        drug.stackCount,
                                                        drug.def.ingestible.maxNumToIngestAtOnce,
                                                        1
                                                    })
                                                };
                                                if (drug.Spawned && this.Pawn.drugs != null && !this.Pawn.inventory.innerContainer.Contains(drug.def))
                                                {
                                                    DrugPolicyEntry drugPolicyEntry = this.Pawn.drugs.CurrentPolicy[drug.def];
                                                    if (drugPolicyEntry.takeToInventory > 0)
                                                    {
                                                        job.takeExtraIngestibles = drugPolicyEntry.takeToInventory;
                                                    }
                                                }
                                                if (this.Pawn.jobs != null && this.Pawn.jobs.curJob != null)
                                                {
                                                    this.Pawn.jobs.EndCurrentJob(JobCondition.InterruptForced, true, true);
                                                    this.Pawn.jobs.ClearQueuedJobs(true);
                                                }
                                                MSPainlessData.SetDRResponseData(this.Pawn, hediff.def.defName, drugdef.defName, Find.TickManager.TicksGame, this.DRResponse, i, out List <string> newDRResponse2);
                                                this.DRResponse = newDRResponse2;
                                                MSPainlessData.DoDRResponseMsg(this.Pawn, hediff.def, drugdef);
                                                this.Pawn.jobs.TryTakeOrderedJob(job, 0);
                                            }
                                        }
                                    }
                                }
                                Pawn_JobTracker jobs = this.Pawn.jobs;
                                if ((jobs?.curJob) != null && this.Pawn.jobs.curJob.def == JobDefOf.Ingest)
                                {
                                    break;
                                }
                            }
                        }
                        return;
                    }
                }
                if (CaravanUtility.IsCaravanMember(this.Pawn))
                {
                    Pawn      pawn6 = this.Pawn;
                    HediffSet hediffSet2;
                    if (pawn6 == null)
                    {
                        hediffSet2 = null;
                    }
                    else
                    {
                        Pawn_HealthTracker health2 = pawn6.health;
                        hediffSet2 = (health2?.hediffSet);
                    }
                    HediffSet hedSet2 = hediffSet2;
                    if (hedSet2 != null && hedSet2 != null && hedSet2.hediffs.Count > 0)
                    {
                        foreach (Hediff hediff2 in hedSet2.hediffs)
                        {
                            if (hediff2.Visible && !MSPainlessData.IsProsthetic(hediff2) && MSDRUtility.MaladyUsed(hediff2.def.defName))
                            {
                                for (int j = 1; j <= 2; j++)
                                {
                                    if (MSPainlessData.CheckIfResponse(this.Pawn, hediff2.def.defName, this.DRResponse, j, out ThingDef drugdef2) && MSDrugUtility.IsOKtoAdmin(this.Pawn, hediff2.def, drugdef2) && !MSDrugUtility.IsViolation(this.Pawn, drugdef2))
                                    {
                                        Caravan car = CaravanUtility.GetCaravan(this.Pawn);
                                        if (car != null && MSCaravanUtility.CaravanHasDrug(car, drugdef2, out Thing drug2, out Pawn owner))
                                        {
                                            MSPainlessData.SetDRResponseData(this.Pawn, hediff2.def.defName, drugdef2.defName, Find.TickManager.TicksGame, this.DRResponse, j, out List <string> newDRResponse3);
                                            this.DRResponse = newDRResponse3;
                                            MSCaravanUtility.PawnOnCaravanTakeDrug(car, this.Pawn, drug2, owner);
                                            MSPainlessData.DoDRResponseMsg(this.Pawn, hediff2.def, drugdef2);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Exemple #14
0
 public static bool Prefix(List <DrugPolicyEntry> ___entriesInt, ThingDef drugDef, ref DrugPolicyEntry __result)
 {
     __result = ___entriesInt.FirstOrFallback(entry => entry.drug == drugDef, new DrugPolicyEntry
     {
         drug                = drugDef,
         allowScheduled      = false,
         allowedForAddiction = false,
         allowedForJoy       = false,
         takeToInventory     = 0
     });
     return(false);
 }
Exemple #15
0
        private static bool TryCreateDrugPolicyEntry(StreamReader sr, out DrugPolicyEntry entry)
        {
            entry = null;
            string[] kv = null;
            try
            {
                while (!sr.EndOfStream)
                {
                    if (ReadField(sr, out kv))
                    {
                        switch (kv[0])
                        {
                        case BREAK:
                            return(true);

                        case "defName":
                            ThingDef def = DefDatabase <ThingDef> .GetNamed(kv[1]);

                            if (def == null)
                            {
                                Log.Warning("Unable to load drug policy with Drug of [" + kv[1] + "]");
                                return(false);
                            }
                            entry      = new DrugPolicyEntry();
                            entry.drug = def;
                            break;

                        case "allowedForAddiction":
                            entry.allowedForAddiction = bool.Parse(kv[1]);
                            break;

                        case "allowedForJoy":
                            entry.allowedForJoy = bool.Parse(kv[1]);
                            break;

                        case "allowScheduled":
                            entry.allowScheduled = bool.Parse(kv[1]);
                            break;

                        case "daysFrequency":
                            entry.daysFrequency = int.Parse(kv[1]);
                            break;

                        case "onlyIfJoyBelow":
                            entry.onlyIfJoyBelow = float.Parse(kv[1]);
                            break;

                        case "onlyIfMoodBelow":
                            entry.onlyIfMoodBelow = float.Parse(kv[1]);
                            break;

                        case "takeToInventory":
                            entry.takeToInventory = int.Parse(kv[1]);
                            break;

                        case "takeToInventoryTempBuffer":
                            entry.takeToInventoryTempBuffer = kv[1];
                            break;
                        }
                    }
                }
            }
            catch
            {
                string error = "";
                if (entry != null && entry.drug != null)
                {
                    error = "Unable to load drug policy [" + entry.drug.defName + "].";
                }
                else
                {
                    error = "Unable to load a drug policy.";
                }

                if (kv == null || kv.Length < 2)
                {
                    error += " Current line: [" + kv[0] + ":" + kv[1] + "]";
                }
                Log.Warning(error);
                entry = null;
                return(false);
            }
            return(true);
        }
Exemple #16
0
        // Token: 0x0600004C RID: 76 RVA: 0x00005168 File Offset: 0x00003368
        public static bool IsOKtoAdmin(Pawn pawn, HediffDef hdef, ThingDef def)
        {
            DrugPolicy drugPolicy;

            if (pawn == null)
            {
                drugPolicy = null;
            }
            else
            {
                Pawn_DrugPolicyTracker drugs = pawn.drugs;
                drugPolicy = (drugs?.CurrentPolicy);
            }
            DrugPolicy policy = drugPolicy;

            if (policy != null)
            {
                if (!MSDrugUtility.DPExists(policy, def))
                {
                    Messages.Message(TranslatorFormattedStringExtensions.Translate("MSPainless.ErrDrugPolicy", pawn?.LabelShort, def?.label), pawn, MessageTypeDefOf.NeutralEvent, false);
                    return(false);
                }
                if (policy[def] != null)
                {
                    DrugPolicyEntry entry = policy[def];
                    if (entry != null && entry.allowScheduled && entry != null && entry.daysFrequency > 0f)
                    {
                        return(false);
                    }
                }
            }
            if (!DRSettings.DoIfImmune && MSDrugUtility.ImmuneNow(pawn, hdef))
            {
                return(false);
            }
            if (hdef != null && hdef.defName == "Anesthetic")
            {
                HediffSet hediffSet;
                if (pawn == null)
                {
                    hediffSet = null;
                }
                else
                {
                    Pawn_HealthTracker health = pawn.health;
                    hediffSet = (health?.hediffSet);
                }
                HediffSet set = hediffSet;
                if (set != null)
                {
                    Hediff Anesthetic = set.GetFirstHediffOfDef(hdef, false);
                    if (Anesthetic != null && Anesthetic.Severity >= 0.8f)
                    {
                        return(false);
                    }
                }
            }
            if (def.IsIngestible)
            {
                List <IngestionOutcomeDoer> ODs = def.ingestible.outcomeDoers;
                if (ODs.Count > 0)
                {
                    bool      toohighsev = false;
                    HediffSet hediffSet2;
                    if (pawn == null)
                    {
                        hediffSet2 = null;
                    }
                    else
                    {
                        Pawn_HealthTracker health2 = pawn.health;
                        hediffSet2 = (health2?.hediffSet);
                    }
                    HediffSet hediffset = hediffSet2;
                    if (hediffset != null)
                    {
                        foreach (IngestionOutcomeDoer OD in ODs)
                        {
                            if (OD is IngestionOutcomeDoer_GiveHediff)
                            {
                                IngestionOutcomeDoer_GiveHediff ingestionOutcomeDoer_GiveHediff = OD as IngestionOutcomeDoer_GiveHediff;
                                HediffDef ODhediffdef = ingestionOutcomeDoer_GiveHediff?.hediffDef;
                                if (ODhediffdef != null)
                                {
                                    float ODSev = (OD as IngestionOutcomeDoer_GiveHediff).severity;
                                    if (ODSev > 0f)
                                    {
                                        Hediff ODhediff = hediffset.GetFirstHediffOfDef(ODhediffdef, false);
                                        if (ODhediff != null && ODhediff.Severity / ODSev > 0.75f)
                                        {
                                            toohighsev = true;
                                        }
                                    }
                                }
                            }
                        }
                        if (toohighsev)
                        {
                            return(false);
                        }
                    }
                }
                return(true);
            }
            return(false);
        }