예제 #1
0
        public static IEnumerable <StatDrawEntry> DrugAddictionStats(CompProperties_Drug comp, StatRequest req, int displayOffset = 0)
        {
            ThingDef thingDef = (ThingDef)req.Def;
            var      category = DefDatabase <StatCategoryDef> .GetNamed("DrugAddiction");

            HediffDef addictionHediff = comp.chemical?.addictionHediff;
            NeedDef   addictionNeed   = addictionHediff?.causesNeed;
            HediffCompProperties_SeverityPerDay addictionSeverityComp =
                (HediffCompProperties_SeverityPerDay)addictionHediff?.CompPropsFor(typeof(HediffComp_SeverityPerDay))
            ;

            // Addictiveness
            yield return(new StatDrawEntry(
                             category:    category,
                             label:       "Addictiveness".Translate(),
                             reportText:  "Stat_Thing_Drug_Addictiveness_Desc".Translate(),
                             valueString: comp.addictiveness.ToStringPercent(),
                             displayPriorityWithinCategory: displayOffset + 99
                             ));

            if (addictionSeverityComp != null)
            {
                // Addiction decay per day
                yield return(new StatDrawEntry(
                                 category:    category,
                                 label:       "Stat_Thing_Drug_AddictionDecay_Name".Translate(),
                                 reportText:  "Stat_Thing_Drug_AddictionDecay_Desc".Translate(),
                                 valueString: addictionSeverityComp.severityPerDay.ToStringPercent(),
                                 displayPriorityWithinCategory: displayOffset + 98
                                 ));

                // Time to shake addiction
                float daysToShakeAddiction = addictionHediff.initialSeverity / addictionSeverityComp.severityPerDay * -1;
                yield return(new StatDrawEntry(
                                 category:    category,
                                 label:       "Stat_Thing_Drug_TimeToShakeAddiction_Name".Translate(),
                                 reportText:  "Stat_Thing_Drug_TimeToShakeAddiction_Desc".Translate(),
                                 valueString: ToStringDaysToPeriod(daysToShakeAddiction),
                                 displayPriorityWithinCategory: displayOffset + 98
                                 ));
            }

            if (addictionHediff != null)
            {
                yield return(FindHediffRisks(addictionHediff, "AddictionRisks", category, displayOffset));
            }
        }
예제 #2
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;
                }
            }
        }