Beispiel #1
0
        public static bool IsColdDrink(ThingDef def)
        {
            var ing = def.ingestible;

            if (ing != null)
            {
                if (ing.ingestCommandString != null && ing.ingestCommandString.ToLower().Contains("drink"))
                {
                    return(true);
                }
                if (ing.nurseable == true)
                {
                    return(true);
                }

                FoodTypeFlags ft     = ing.foodType;
                FoodTypeFlags filter = FoodTypeFlags.Liquor | FoodTypeFlags.Fluid;
                if ((ft & filter) != FoodTypeFlags.None)
                {
                    return(true);
                }
                CompProperties_Drug drugCompProp = def.GetCompProperties <CompProperties_Drug>();
                if (drugCompProp != null && (drugCompProp.chemical == ChemicalDefOf.Alcohol || drugCompProp.chemical != DefDatabase <ChemicalDef> .GetNamed("RC2_Caffeine", false)))
                {
                    return(true);
                }
            }
            return(false);
        }
Beispiel #2
0
        public static void UpdateAllChanges()
        {
            // ThingDefOf.SmokeleafJoint.comps.Where(c => c is CompProperties_Drug).FirstOrDefault()
            //HediffDef.Named("SmokeleafHigh").stages.Where((HediffStage stage) => stage.capMods.Any((PawnCapacityModifier mod) => mod.capacity == PawnCapacityDefOf.Consciousness)).First().capMods.Where((PawnCapacityModifier mod) => mod.capacity == PawnCapacityDefOf.Consciousness).First().offset = LLLModSettings.amountPenaltyConsciousness;

            HediffDef.Named("SmokeleafHigh").stages.Where(s => s.capMods.Any(m => m.capacity == PawnCapacityDefOf.Consciousness)).First().capMods.Where(m => m.capacity == PawnCapacityDefOf.Consciousness).First().offset = LLLModSettings.amountPenaltyConsciousness;
            HediffDef.Named("SmokeleafHigh").stages.Where(s => s.capMods.Any(m => m.capacity == PawnCapacityDefOf.Moving)).First().capMods.Where(m => m.capacity == PawnCapacityDefOf.Moving).First().offset = LLLModSettings.amountPenaltyMovement;

            IngestionOutcomeDoer_OffsetNeed restOffset = (IngestionOutcomeDoer_OffsetNeed)ThingDefOf.SmokeleafJoint.ingestible.outcomeDoers.Find(o => o is IngestionOutcomeDoer_OffsetNeed);

            restOffset.offset = LLLModSettings.amountPenaltyRest;

            HediffDef.Named("SmokeleafHigh").stages[0].hungerRateFactorOffset = LLLModSettings.amountHungerRate;

            CompProperties_Drug comDrug = ThingDefOf.SmokeleafJoint.GetCompProperties <CompProperties_Drug>() as CompProperties_Drug;

            comDrug.addictiveness        = LLLModSettings.amountAddictiveness;
            comDrug.minToleranceToAddict = LLLModSettings.amountToleranceToAddict;

            HediffGiver_RandomDrugEffect hediffAsthma = HediffDef.Named("SmokeleafTolerance").hediffGivers[0] as HediffGiver_RandomDrugEffect;
            HediffGiver_RandomDrugEffect hediffCancer = HediffDef.Named("SmokeleafTolerance").hediffGivers[1] as HediffGiver_RandomDrugEffect;

            hediffAsthma.baseMtbDays = LLLModSettings.amountAsthmaDaysChance;
            hediffCancer.baseMtbDays = LLLModSettings.amountCancerDaysChance;

            ThoughtDef.Named("SmokeleafWithdrawal").stages[1].baseMoodEffect = LLLModSettings.amountPenaltyWithdrawal;
        }
Beispiel #3
0
        public static IEnumerable <StatDrawEntry> SpecialDisplayStatsForDrugs(CompProperties_Drug comp, StatRequest req)
        {
            // Variable prep
            ThingDef thingDef   = (ThingDef)req.Def;
            var      categories = new Dictionary <string, StatCategoryDef> {
            };

            foreach (string name in new List <string> {
                "Drug", "DrugTolerance", "DrugAddiction", "DrugOverdose"
            })
            {
                categories.Add(name, DefDatabase <StatCategoryDef> .GetNamed(name));
            }

            // Multiple CompProperties_Drugs might exist, so set up the display priorities properly
            int compIndex     = thingDef.comps.IndexOf(comp);
            int displayOffset = (thingDef.comps.Count - compIndex) * 100;

            // This is probably a mistake, so don't report it.  (CuproPanda's Drinks does this for some reason.)
            if (comp.chemical == null && thingDef.comps.Sum(cp => cp is CompProperties_Drug ? 1 : 0) > 1)
            {
                yield break;
            }

            // Clear these out, just in case they weren't before
            drugNotSafe = null;
            daysPerSafeDoseAddiction = null;
            daysPerSafeDoseOverdose  = null;

            // Basic drug info
            foreach (StatDrawEntry value in BasicDrugStats(comp, req, displayOffset))
            {
                yield return(value);
            }

            // The rest
            if (comp.chemical != null)
            {
                foreach (StatDrawEntry value in DrugToleranceStats(comp, req, displayOffset))
                {
                    yield return(value);
                }
                foreach (StatDrawEntry value in DrugAddictionStats(comp, req, displayOffset))
                {
                    yield return(value);
                }
                foreach (StatDrawEntry value in DrugOverdoseStats(comp, req, displayOffset))
                {
                    yield return(value);
                }
            }

            yield return(CalculateSafeDose(displayOffset));

            // Clear these out before we go
            drugNotSafe = null;
            daysPerSafeDoseAddiction = null;
            daysPerSafeDoseOverdose  = null;
        }
Beispiel #4
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));
            }
        }
 static GMT_Drunken_Master_Helper()
 {
     // Cache a list of alcoholic items so we're not iterating over all thingdefs every time we generate a pawn with this trait.
     // This is cached with the lifespan of the application, but there shouldn't be new defs added except by mods, which require restart.
     if (alcoholic_items == null)
     {
         alcoholic_items = DefDatabase <ThingDef> .AllDefsListForReading.Where(delegate(ThingDef x)
         {
             if (x.category != ThingCategory.Item)
             {
                 return(false);
             }
             CompProperties_Drug compProperties = x.GetCompProperties <CompProperties_Drug>();
             return(compProperties != null && compProperties.chemical == ChemicalDefOf.Alcohol);
         }).ToList();
     }
 }
Beispiel #6
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
                             ));
        }
Beispiel #7
0
        public static bool IsExcluded(ThingDef def)
        {
            if (def.category == ThingCategory.Plant)
            {
                return(true);
            }
            CompProperties_Drug drugCompProp = def.GetCompProperties <CompProperties_Drug>();

            if (drugCompProp != null && (drugCompProp.chemical != ChemicalDefOf.Alcohol &&
                                         drugCompProp.chemical != DefDatabase <ChemicalDef> .GetNamed("RC2_Caffeine", false) &&
                                         drugCompProp.chemical != DefDatabase <ChemicalDef> .GetNamed("RC2_AmbrosiaAlcohol", false)))
            {
                return(true);
            }
            if (def.ingestible.joyKind != null)
            {
                if (def.ingestible.joyKind.defName == "Chemical" && (def.ingestible.foodType & FoodTypeFlags.Fluid) == FoodTypeFlags.None)
                {
                    return(true);
                }
            }
            return(false);
        }
Beispiel #8
0
            static IEnumerable <StatDrawEntry> Postfix(IEnumerable <StatDrawEntry> values, CompProperties_Drug __instance, StatRequest req)
            {
                // Cycle through the entries
                string addictivenessCap = "Addictiveness".Translate().CapitalizeFirst();

                foreach (StatDrawEntry value in values)
                {
                    // Return all of them except for Addictiveness (the one stat CompProperties_Drug adds)
                    if (value.LabelCap != addictivenessCap)
                    {
                        yield return(value);
                    }
                }

                foreach (StatDrawEntry value in Base.SpecialDisplayStatsForDrugs(__instance, req))
                {
                    yield return(value);
                }
            }
Beispiel #9
0
        public static IEnumerable <StatDrawEntry> DrugOverdoseStats(CompProperties_Drug comp, StatRequest req, int displayOffset = 0)
        {
            ThingDef thingDef = (ThingDef)req.Def;
            var      category = DefDatabase <StatCategoryDef> .GetNamed("DrugOverdose");

            // Nothing to report
            if (comp.overdoseSeverityOffset.TrueMax == 0f && comp.largeOverdoseChance == 0f)
            {
                yield break;
            }

            HediffDef overdoseHediff = HediffDefOf.DrugOverdose;

            // NOTE: Some of these are static values to inform the user, and to be consistent with the
            // DrugTolerance layout.

            if (comp.overdoseSeverityOffset.TrueMax > 0f)
            {
                // Overdose severity for using
                yield return(new StatDrawEntry(
                                 category:    category,
                                 label:       "Stat_Thing_Drug_OverdoseForUsing_Name".Translate(),
                                 reportText:  "Stat_Thing_Drug_OverdoseForUsing_Desc".Translate(),
                                 valueString: string.Join(" - ",
                                                          comp.overdoseSeverityOffset.TrueMin.ToStringPercent(),
                                                          comp.overdoseSeverityOffset.TrueMax.ToStringPercent()
                                                          ),
                                 displayPriorityWithinCategory: displayOffset + 99
                                 ));

                // 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: true.ToStringYesNo(),
                                 displayPriorityWithinCategory: displayOffset + 98
                                 ));

                // Overdose severity levels
                yield return(new StatDrawEntry(
                                 category:    category,
                                 label:       "Stat_Thing_Drug_OverdoseSeverityLevels_Name".Translate(),
                                 reportText:  "Stat_Thing_Drug_OverdoseSeverityLevels_Desc".Translate(),
                                 valueString: GenText.ToCommaList(new List <string> {
                    overdoseHediff.stages[1].minSeverity.ToStringPercent(),
                    overdoseHediff.stages[2].minSeverity.ToStringPercent(),
                    overdoseHediff.lethalSeverity.ToStringPercent()
                }),
                                 displayPriorityWithinCategory: displayOffset + 97
                                 ));

                // Overdose decay per day
                yield return(new StatDrawEntry(
                                 category:    category,
                                 label:       "Stat_Thing_Drug_OverdoseDecay_Name".Translate(),
                                 reportText:  "Stat_Thing_Drug_OverdoseDecay_Desc".Translate(),
                                 // XXX: This is documented on the wiki, but I don't know where in the code...
                                 valueString: (-1f).ToStringPercent(),
                                 displayPriorityWithinCategory: displayOffset + 96
                                 ));
            }

            if (comp.largeOverdoseChance > 0f)
            {
                // Large overdose chance
                yield return(new StatDrawEntry(
                                 category:    category,
                                 label:       "Stat_Thing_Drug_LargeOverdoseChance_Name".Translate(),
                                 reportText:  "Stat_Thing_Drug_LargeOverdoseChance_Desc".Translate(),
                                 valueString: comp.largeOverdoseChance.ToStringPercent(),
                                 displayPriorityWithinCategory: displayOffset + 95
                                 ));
            }

            // Doses before overdose
            float dosesBeforeOverdose = overdoseHediff.stages[1].minSeverity / comp.overdoseSeverityOffset.TrueMax;

            if (dosesBeforeOverdose <= 1f)
            {
                dosesBeforeOverdose = 0;                                 // cannot take partial doses
            }
            if (comp.largeOverdoseChance > 0f)
            {
                dosesBeforeOverdose = 0;                                 // cannot be considered safe with a large overdose chance
            }
            drugNotSafe = drugNotSafe != null ?
                          ((bool)drugNotSafe || dosesBeforeOverdose == 0f) :
                          dosesBeforeOverdose == 0f
            ;

            yield return(new StatDrawEntry(
                             category:    category,
                             label:       "Stat_Thing_Drug_DosagesBeforeOverdose_Name".Translate(),
                             reportText:  "Stat_Thing_Drug_DosagesBeforeOverdose_Desc".Translate(),
                             valueString: dosesBeforeOverdose.ToStringDecimalIfSmall(),
                             displayPriorityWithinCategory: displayOffset + 85
                             ));

            daysPerSafeDoseOverdose = comp.overdoseSeverityOffset.TrueMax;

            yield return(FindHediffRisks(overdoseHediff, "OverdoseRisks", category, displayOffset));
        }
Beispiel #10
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;
                }
            }
        }