Esempio n. 1
0
        // Token: 0x06000040 RID: 64 RVA: 0x00004AC0 File Offset: 0x00002CC0
        private static bool GenMSRecipe(Pawn pawn, HediffDef hdef, ThingDef drugdef, BodyPartRecord part = null)
        {
            bool result = false;

            if (MSDrugUtility.IsOKtoAdmin(pawn, hdef, drugdef))
            {
                RecipeDef recipeDef = DefDatabase <RecipeDef> .GetNamed("Administer_" + drugdef.defName, true);

                if (recipeDef != null)
                {
                    if (!MSAddDrugBill.IsViolation(pawn, recipeDef, out string reason))
                    {
                        if (!MSAddDrugBill.ChkDuplication(pawn, recipeDef) && MSAddDrugBill.GenAdminOption(pawn, recipeDef, part))
                        {
                            result = true;
                        }
                    }
                    else
                    {
                        Messages.Message(TranslatorFormattedStringExtensions.Translate("MSPainless.ViolationMsg", GenText.CapitalizeFirst(pawn.LabelShort), GenText.CapitalizeFirst(drugdef.label), reason), pawn, MessageTypeDefOf.NeutralEvent, false);
                    }
                }
            }
            return(result);
        }
Esempio n. 2
0
        // 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);
        }
Esempio n. 3
0
        // Token: 0x0600004E RID: 78 RVA: 0x00005398 File Offset: 0x00003598
        public static Thing FindDrugFor(Pawn pawn, ThingDef drugDef)
        {
            ThingOwner <Thing> innerContainer = pawn.inventory.innerContainer;

            for (int i = 0; i < innerContainer.Count; i++)
            {
                if (innerContainer[i].def == drugDef && MSDrugUtility.DrugValidator(pawn, innerContainer[i]))
                {
                    return(innerContainer[i]);
                }
            }
            if (!pawn.IsPrisoner)
            {
                return(GenClosest.ClosestThingReachable(pawn.Position, pawn.Map, ThingRequest.ForDef(drugDef), PathEndMode.ClosestTouch, TraverseParms.For(pawn, Danger.Deadly, 0, false), 9999f, (Thing x) => MSDrugUtility.DrugValidator(pawn, x), null, 0, -1, false, RegionType.Set_Passable, false));
            }
            return(GenClosest.ClosestThingReachable(pawn.Position, pawn.Map, ThingRequest.ForDef(drugDef), PathEndMode.ClosestTouch, TraverseParms.For(TraverseMode.PassDoors, Danger.Deadly, false), 9999f, (Thing x) => MSDrugUtility.DrugValidator(pawn, x), null, 0, -1, false, RegionType.Set_Passable, false));
        }
Esempio n. 4
0
        // Token: 0x0600007D RID: 125 RVA: 0x00006F64 File Offset: 0x00005164
        public static void DoCaravanPainReliefResponse(Caravan car, Pawn pawn)
        {
            if (MSPainlessData.GetLastPainReliefTick(pawn) + 2500 * DRSettings.PainReliefWaitPeriod > Find.TickManager.TicksGame)
            {
                return;
            }
            ThingDef painDrugDef = MSPainUtility.NeedsPainReliefNow(pawn, out bool highpain);

            if (painDrugDef != null && MSDrugUtility.IsOKtoAdmin(pawn, null, painDrugDef) && !MSDrugUtility.IsViolation(pawn, painDrugDef) && MSCaravanUtility.CaravanHasDrug(car, painDrugDef, out Thing drug, out Pawn owner))
            {
                MSPainlessData.MSPainlessDataTickSet(pawn);
                MSCaravanUtility.PawnOnCaravanTakeDrug(car, pawn, drug, owner);
                if (DRSettings.ShowReliefMsg)
                {
                    Messages.Message(TranslatorFormattedStringExtensions.Translate("MSPainless.ReliefMsg", GenText.CapitalizeFirst(pawn.LabelShort), GenText.CapitalizeFirst(drug.def.label)), pawn, MessageTypeDefOf.NeutralEvent, false);
                }
            }
        }
Esempio n. 5
0
        // 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);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Esempio n. 6
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);
        }