Пример #1
0
        public override void Apply()
        {
            IngestionOutcomeDoer_GiveHediff giveHediff = (IngestionOutcomeDoer_GiveHediff)ThingDef.Named("PsychiteTea").ingestible.outcomeDoers.FirstOrDefault(x => x is IngestionOutcomeDoer_GiveHediff);

            if (giveHediff != null)
            {
                giveHediff.severity = 1f;
            }

            this.Active = true;
        }
Пример #2
0
        public static List <Drug> Get()
        {
            var rows  = new List <Drug>();
            var drugs = from d in DefDatabase <Verse.ThingDef> .AllDefs where d.IsDrug select d;

            foreach (var d in drugs)
            {
                rows.Add(MakeRow(d));
                var doers = GetValidNarcoDoers(d);
                if (doers == null)
                {
                    continue;
                }

                // get BEFORE tolerance heddif for detect he in 'doers' iterate
                var toleranceHeddif = GetToleranceDef(doers);
#if DEBUG
                Log.Warning($"def: {d.LabelCap}, GetValidNarcoDoers = {doers.ToList().Count}");
#endif

                IngestionOutcomeDoer_GiveHediff doerForAddiction = null;
                foreach (var doer in doers.OrEmptyIfNull())
                {
                    bool isToleranceHeddif = toleranceHeddif != null && doer.hediffDef == toleranceHeddif;
                    if (isToleranceHeddif)
                    {
                        rows.Add(GetFromHeddifTolerance(d, doer.hediffDef, doer.severity,
                                                        d.GetCompProperties <CompProperties_Drug>()?.minToleranceToAddict));
                    }
                    else
                    {
                        var thought = DefDatabase <RimWorld.ThoughtDef> .AllDefs.Where(t => t.hediff == doer.hediffDef)
                                      .FirstOrDefault();

                        rows.AddRange(GetFromHeddifStages(d, doer.hediffDef, doer.severity, thought));
                        doerForAddiction = doer;
                    }
                }

                //get addictionHeddif
                var addictionHeddif = GetAddictionDef(doers);
                if (addictionHeddif != null)
                {
                    var addictionThought = DefDatabase <RimWorld.ThoughtDef> .AllDefs.Where(t => t.hediff == addictionHeddif).FirstOrDefault();

                    rows.Add(GetFromHeddifAddiction(d, addictionHeddif, doerForAddiction?.hediffDef.initialSeverity ?? 0f, addictionThought));
                }
            }

            return(rows);
        }
Пример #3
0
        public static IEnumerable <StatDrawEntry> BasicDrugStats(CompProperties_Drug comp, StatRequest req, int displayOffset = 0)
        {
            ThingDef thingDef = (ThingDef)req.Def;
            var      category = DefDatabase <StatCategoryDef> .GetNamed("Drug");

            HediffDef toleranceHediff = comp.chemical?.toleranceHediff;
            IngestionOutcomeDoer_GiveHediff highOutcomeDoer = null;

            highOutcomeDoer = (IngestionOutcomeDoer_GiveHediff)thingDef.ingestible.outcomeDoers.FirstOrFallback(
                iod => iod is IngestionOutcomeDoer_GiveHediff iod_gh &&
                iod_gh.hediffDef != null && (toleranceHediff == null || iod_gh.hediffDef != toleranceHediff) &&
                iod_gh.severity > 0
                );
            if (highOutcomeDoer != null)
            {
                yield return(FindHediffRisks(highOutcomeDoer.hediffDef, "HighBenefitsRisks", category, displayOffset));
            }

            // Drug category
            yield return(new StatDrawEntry(
                             category:    category,
                             label:       "Stat_Thing_Drug_Category_Name".Translate(),
                             reportText:  "Stat_Thing_Drug_Category_Desc".Translate(),
                             valueString: ("DrugCategory_" + thingDef.ingestible.drugCategory).Translate(),
                             displayPriorityWithinCategory: displayOffset + 100
                             ));


            // Chemical
            yield return(new StatDrawEntry(
                             category:    category,
                             label:       "Stat_Thing_Drug_Chemical_Name".Translate(),
                             reportText:  "Stat_Thing_Drug_Chemical_Desc".Translate(),
                             valueString: comp.chemical != null ? comp.chemical.LabelCap : "None".Translate(),
                             displayPriorityWithinCategory: displayOffset + 99
                             ));

            // Combat enhancing drug
            yield return(new StatDrawEntry(
                             category:    category,
                             label:       "Stat_Thing_Drug_CombatEnhancingDrug_Name".Translate(),
                             reportText:  "Stat_Thing_Drug_CombatEnhancingDrug_Desc".Translate(),
                             valueString: comp.isCombatEnhancingDrug.ToStringYesNo(),
                             displayPriorityWithinCategory: displayOffset + 60
                             ));
        }
Пример #4
0
        private static void Postfix(IngestionOutcomeDoer_GiveHediff __instance, Pawn pawn, Thing ingested)
        {
            ThoughtStage ts = new ThoughtStage()
            {
                label          = "took antidepressants",
                description    = "I feel calm. LOL",
                baseMoodEffect = -50,
            };
            ThoughtDef td = new ThoughtDef()
            {
                defName      = "AteAntiDepressant",
                durationDays = 0.5f,
                stackLimit   = 1,
                stages       = new List <ThoughtStage>()
                {
                    ts
                },
            };

            pawn.needs.mood.thoughts.memories.TryGainMemory(td, null);
            Debug.Log("debug : " + ingested.def.defName + " " + pawn.Name);
        }
Пример #5
0
        public static IEnumerable <StatDrawEntry> DrugToleranceStats(CompProperties_Drug comp, StatRequest req, int displayOffset = 0)
        {
            ThingDef thingDef = (ThingDef)req.Def;
            var      category = DefDatabase <StatCategoryDef> .GetNamed("DrugTolerance");

            HediffDef toleranceHediff = comp.chemical?.toleranceHediff;
            IngestionOutcomeDoer_GiveHediff     toleranceOutcomeDoer  = null;
            HediffCompProperties_SeverityPerDay toleranceSeverityComp = null;

            if (toleranceHediff != null)
            {
                toleranceOutcomeDoer = (IngestionOutcomeDoer_GiveHediff)thingDef.ingestible.outcomeDoers.FirstOrFallback(
                    iod => iod is IngestionOutcomeDoer_GiveHediff iod_gh &&
                    iod_gh.hediffDef != null && iod_gh.hediffDef == toleranceHediff
                    );
                toleranceSeverityComp = (HediffCompProperties_SeverityPerDay)toleranceHediff.CompPropsFor(typeof(HediffComp_SeverityPerDay));

                yield return(FindHediffRisks(toleranceHediff, "ToleranceRisks", category, displayOffset));
            }

            if (toleranceOutcomeDoer != null)
            {
                // Tolerance for using
                yield return(new StatDrawEntry(
                                 category:    category,
                                 label:       "Stat_Thing_Drug_ToleranceForUsing_Name".Translate(),
                                 reportText:  "Stat_Thing_Drug_ToleranceForUsing_Desc".Translate(),
                                 valueString: toleranceOutcomeDoer.severity.ToStringPercent(),
                                 displayPriorityWithinCategory: displayOffset + 98
                                 ));

                // [Reflection] toleranceOutcomeDoer.divideByBodySize
                FieldInfo divideByBodySizeField = AccessTools.Field(typeof(IngestionOutcomeDoer_GiveHediff), "divideByBodySize");
                bool      divideByBodySize      = (bool)divideByBodySizeField.GetValue(toleranceOutcomeDoer);

                // Severity affected by body size
                yield return(new StatDrawEntry(
                                 category:    category,
                                 label:       "Stat_Thing_Drug_SeverityUsesBodySize_Name".Translate(),
                                 reportText:  "Stat_Thing_Drug_SeverityUsesBodySize_Desc".Translate(),
                                 valueString: divideByBodySize.ToStringYesNo(),
                                 displayPriorityWithinCategory: displayOffset + 97
                                 ));
            }

            // Minimum tolerance to addict
            yield return(new StatDrawEntry(
                             category:    category,
                             label:       "Stat_Thing_Drug_MinToleranceToAddict_Name".Translate(),
                             reportText:  "Stat_Thing_Drug_MinToleranceToAddict_Desc".Translate(),
                             valueString: comp.minToleranceToAddict.ToStringPercent(),
                             displayPriorityWithinCategory: displayOffset + 96
                             ));

            if (comp.minToleranceToAddict == 0f)
            {
                drugNotSafe = true;
            }

            // Tolerance decay per day
            if (toleranceSeverityComp != null)
            {
                yield return(new StatDrawEntry(
                                 category:    category,
                                 label:       "Stat_Thing_Drug_ToleranceDecay_Name".Translate(),
                                 reportText:  "Stat_Thing_Drug_ToleranceDecay_Desc".Translate(),
                                 valueString: toleranceSeverityComp.severityPerDay.ToStringPercent(),
                                 displayPriorityWithinCategory: displayOffset + 95
                                 ));
            }

            // Doses before addiction
            if (toleranceOutcomeDoer != null)
            {
                float dosesBeforeAddiction = comp.minToleranceToAddict / toleranceOutcomeDoer.severity;
                if (dosesBeforeAddiction <= 1f)
                {
                    dosesBeforeAddiction = 0;                              // cannot take partial doses
                }
                drugNotSafe = drugNotSafe != null ?
                              ((bool)drugNotSafe || dosesBeforeAddiction == 0f) :
                              dosesBeforeAddiction == 0f
                ;

                yield return(new StatDrawEntry(
                                 category:    category,
                                 label:       "Stat_Thing_Drug_DosagesBeforeAddiction_Name".Translate(),
                                 reportText:  "Stat_Thing_Drug_DosagesBeforeAddiction_Desc".Translate(),
                                 valueString: dosesBeforeAddiction.ToStringDecimalIfSmall(),
                                 displayPriorityWithinCategory: displayOffset + 94
                                 ));

                if (toleranceSeverityComp != null)
                {
                    daysPerSafeDoseAddiction = toleranceOutcomeDoer.severity / toleranceSeverityComp.severityPerDay * -1;
                }
            }
        }
Пример #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);
        }