private static void GiveDrugsIfAddicted(Pawn p) { if (p.RaceProps.Humanlike) { foreach (Hediff_Addiction addiction in p.health.hediffSet.GetHediffs <Hediff_Addiction>()) { if (DefDatabase <ThingDef> .AllDefsListForReading.Where(delegate(ThingDef x) { if (x.category != ThingCategory.Item) { return(false); } if (p.Faction != null && (int)x.techLevel > (int)p.Faction.def.techLevel) { return(false); } CompProperties_Drug compProperties = x.GetCompProperties <CompProperties_Drug>(); return(compProperties != null && compProperties.chemical != null && compProperties.chemical.addictionHediff == addiction.def); }).TryRandomElement(out ThingDef result)) { int stackCount = Rand.RangeInclusive(2, 5); Thing thing = ThingMaker.MakeThing(result); thing.stackCount = stackCount; p.inventory.TryAddItemNotForSale(thing); } } } }
private bool CanCauseOverdose(ThingDef drug) { CompProperties_Drug compProperties = drug.GetCompProperties <CompProperties_Drug>(); if (compProperties == null) { return(false); } return(compProperties.CanCauseOverdose); }
private static void GiveCombatEnhancingDrugs(Pawn pawn) { if (Rand.Value < pawn.kindDef.combatEnhancingDrugsChance) { if (!pawn.IsTeetotaler()) { for (int i = 0; i < pawn.inventory.innerContainer.Count; i++) { CompDrug compDrug = pawn.inventory.innerContainer[i].TryGetComp <CompDrug>(); if (compDrug != null && compDrug.Props.isCombatEnhancingDrug) { return; } } int randomInRange = pawn.kindDef.combatEnhancingDrugsCount.RandomInRange; if (randomInRange > 0) { IEnumerable <ThingDef> source = DefDatabase <ThingDef> .AllDefsListForReading.Where(delegate(ThingDef x) { bool result; if (x.category != ThingCategory.Item) { result = false; } else if (pawn.Faction != null && x.techLevel > pawn.Faction.def.techLevel) { result = false; } else { CompProperties_Drug compProperties = x.GetCompProperties <CompProperties_Drug>(); result = (compProperties != null && compProperties.isCombatEnhancingDrug); } return(result); }); for (int j = 0; j < randomInRange; j++) { ThingDef def; if (!source.TryRandomElement(out def)) { break; } pawn.inventory.innerContainer.TryAdd(ThingMaker.MakeThing(def, null), true); } } } } }
public static float GetSafeDoseInterval(ThingDef d) { CompProperties_Drug drugComp = GetDrugComp(d); if (drugComp == null || !drugComp.Addictive) { return(0f); } if (drugComp.addictiveness >= 1f || GetToleranceGiver(d) == null) { return(-1f); } float num = Mathf.Abs(GetToleranceOffsetPerDay(d)); return(Mathf.Max(drugComp.overdoseSeverityOffset.TrueMax, (num > 0f) ? (GetToleranceGiver(d).severity / num) : (-1f))); }
private static void DoIngestionOutcomeDoers(Pawn pawn, ChemicalDef chemical) { for (int i = 0; i < allDrugs.Count; i++) { CompProperties_Drug compProperties = allDrugs[i].GetCompProperties <CompProperties_Drug>(); if (compProperties.chemical == chemical) { List <IngestionOutcomeDoer> outcomeDoers = allDrugs[i].ingestible.outcomeDoers; for (int j = 0; j < outcomeDoers.Count; j++) { if (outcomeDoers[j].doToGeneratedPawnIfAddicted) { outcomeDoers[j].DoIngestionOutcome(pawn, null); } } } } }
private static void GiveCombatEnhancingDrugs(Pawn pawn) { if (!(Rand.Value >= pawn.kindDef.combatEnhancingDrugsChance) && !pawn.IsTeetotaler()) { for (int i = 0; i < pawn.inventory.innerContainer.Count; i++) { CompDrug compDrug = pawn.inventory.innerContainer[i].TryGetComp <CompDrug>(); if (compDrug != null && compDrug.Props.isCombatEnhancingDrug) { return; } } int randomInRange = pawn.kindDef.combatEnhancingDrugsCount.RandomInRange; if (randomInRange > 0) { IEnumerable <ThingDef> source = DefDatabase <ThingDef> .AllDefsListForReading.Where(delegate(ThingDef x) { if (x.category != ThingCategory.Item) { return(false); } if (pawn.Faction != null && (int)x.techLevel > (int)pawn.Faction.def.techLevel) { return(false); } CompProperties_Drug compProperties = x.GetCompProperties <CompProperties_Drug>(); if (compProperties != null && compProperties.isCombatEnhancingDrug) { return(true); } return(false); }); int num = 0; ThingDef def = default(ThingDef); while (num < randomInRange && source.TryRandomElement <ThingDef>(out def)) { pawn.inventory.innerContainer.TryAdd(ThingMaker.MakeThing(def, null), true); num++; } } } }
private static void GiveDrugsIfAddicted(Pawn p) { if (p.RaceProps.Humanlike) { IEnumerable <Hediff_Addiction> hediffs = p.health.hediffSet.GetHediffs <Hediff_Addiction>(); using (IEnumerator <Hediff_Addiction> enumerator = hediffs.GetEnumerator()) { while (enumerator.MoveNext()) { Hediff_Addiction addiction = enumerator.Current; IEnumerable <ThingDef> source = DefDatabase <ThingDef> .AllDefsListForReading.Where(delegate(ThingDef x) { bool result; if (x.category != ThingCategory.Item) { result = false; } else if (p.Faction != null && x.techLevel > p.Faction.def.techLevel) { result = false; } else { CompProperties_Drug compProperties = x.GetCompProperties <CompProperties_Drug>(); result = (compProperties != null && compProperties.chemical != null && compProperties.chemical.addictionHediff == addiction.def); } return(result); }); ThingDef def; if (source.TryRandomElement(out def)) { int stackCount = Rand.RangeInclusive(2, 5); Thing thing = ThingMaker.MakeThing(def, null); thing.stackCount = stackCount; p.inventory.TryAddItemNotForSale(thing); } } } } }
public override bool IsViolationOnPawn(Pawn pawn, BodyPartRecord part, Faction billDoerFaction) { if (pawn.Faction == billDoerFaction) { return(false); } ThingDef thingDef = recipe.ingredients[0].filter.AllowedThingDefs.First(); if (thingDef.IsNonMedicalDrug) { foreach (CompProperties comp in thingDef.comps) { CompProperties_Drug compProperties_Drug = comp as CompProperties_Drug; if (compProperties_Drug != null && compProperties_Drug.chemical != null && compProperties_Drug.chemical.addictionHediff != null && pawn.health.hediffSet.HasHediff(compProperties_Drug.chemical.addictionHediff)) { return(false); } } } return(thingDef.IsNonMedicalDrug); }
private bool CanCauseOverdose(ThingDef drug) { CompProperties_Drug compProperties = drug.GetCompProperties <CompProperties_Drug>(); return(compProperties != null && compProperties.CanCauseOverdose); }
public static IEnumerable <StatDrawEntry> SpecialDisplayStats(ThingDef def) { CompProperties_Drug drugComp = GetDrugComp(def); if (drugComp == null) { yield break; } IngestionOutcomeDoer_GiveHediff highGiver = GetDrugHighGiver(def); if (highGiver != null) { yield return(new StatDrawEntry(StatCategoryDefOf.Drug, "HighGain".Translate(), highGiver.severity.ToStringPercent(), "Stat_Thing_Drug_HighGainPerDose_Desc".Translate(), 2480)); float highFall = Mathf.Abs(GetHighOffsetPerDay(def)); if (highFall > 0f) { yield return(new StatDrawEntry(StatCategoryDefOf.Drug, "HighFallRate".Translate(), "PerDay".Translate(highFall.ToStringPercent()), "Stat_Thing_Drug_HighFallPerDay_Desc".Translate(), 2470)); yield return(new StatDrawEntry(StatCategoryDefOf.Drug, "HighDuration".Translate(), "PeriodDays".Translate((highGiver.severity / highFall).ToString("F1")), "Stat_Thing_Drug_HighDurationPerDose_Desc".Translate(), 2460)); } } if (GetTolerance(def) != null) { float toleranceGain = GetToleranceGain(def); if (toleranceGain > 0f) { yield return(new StatDrawEntry(StatCategoryDefOf.Drug, "ToleranceGain".Translate(), toleranceGain.ToStringPercent(), "Stat_Thing_Drug_ToleranceGainPerDose_Desc".Translate(), 2450)); } float num = Mathf.Abs(GetToleranceOffsetPerDay(def)); if (num > 0f) { yield return(new StatDrawEntry(StatCategoryDefOf.Drug, "ToleranceFallRate".Translate(), "PerDay".Translate(num.ToStringPercent()), "Stat_Thing_Drug_ToleranceFallPerDay_Desc".Translate(), 2440)); } } if (drugComp.Addictive) { HediffDef addictionHediff = GetChemical(def)?.addictionHediff; if (addictionHediff != null) { float num2 = Mathf.Abs(GetAddictionOffsetPerDay(def)); if (num2 > 0f) { yield return(new StatDrawEntry(valueString: "PeriodDays".Translate((addictionHediff.initialSeverity / num2).ToString("F1")), category: StatCategoryDefOf.DrugAddiction, label: "AddictionRecoveryTime".Translate(), reportText: "Stat_Thing_Drug_AddictionRecoveryTime_Desc".Translate(), displayPriorityWithinCategory: 2395)); } yield return(new StatDrawEntry(StatCategoryDefOf.DrugAddiction, "AddictionSeverityInitial".Translate(), addictionHediff.initialSeverity.ToStringPercent(), "Stat_Thing_Drug_AddictionSeverityInitial_Desc".Translate(), 2427)); } yield return(new StatDrawEntry(StatCategoryDefOf.DrugAddiction, "AddictionNeedFallRate".Translate(), "PerDay".Translate(GetNeed(def).fallPerDay.ToStringPercent()), "Stat_Thing_Drug_AddictionNeedFallRate_Desc".Translate(), 2410)); yield return(new StatDrawEntry(StatCategoryDefOf.DrugAddiction, "AddictionCost".Translate(), "PerDay".Translate(GetAddictionNeedCostPerDay(def).ToStringMoney()), "Stat_Thing_Drug_AddictionCost_Desc".Translate(), 2390)); yield return(new StatDrawEntry(StatCategoryDefOf.DrugAddiction, "AddictionNeedDoseInterval".Translate(), "PeriodDays".Translate((drugComp.needLevelOffset / GetNeed(def).fallPerDay).ToString("F1")), "Stat_Thing_Drug_AddictionNeedDoseInterval_Desc".Translate(), 2400)); if (drugComp.chemical != null) { yield return(new StatDrawEntry(StatCategoryDefOf.Drug, "Chemical".Translate(), drugComp.chemical.LabelCap, "Stat_Thing_Drug_Chemical_Desc".Translate(), 2490)); } yield return(new StatDrawEntry(StatCategoryDefOf.DrugAddiction, "Addictiveness".Translate(), drugComp.addictiveness.ToStringPercent(), "Stat_Thing_Drug_Addictiveness_Desc".Translate(), 2428)); yield return(new StatDrawEntry(StatCategoryDefOf.DrugAddiction, "AddictionNeedOffset".Translate(), drugComp.needLevelOffset.ToStringPercent(), "Stat_Thing_Drug_AddictionNeedOffset_Desc".Translate(), 2420)); yield return(new StatDrawEntry(StatCategoryDefOf.DrugAddiction, "MinimumToleranceForAddiction".Translate(), drugComp.minToleranceToAddict.ToStringPercent(), "Stat_Thing_Drug_MinToleranceForAddiction_Desc".Translate(), 2437)); yield return(new StatDrawEntry(StatCategoryDefOf.DrugAddiction, "AddictionSeverityPerDose".Translate(), drugComp.existingAddictionSeverityOffset.ToStringPercent(), "Stat_Thing_Drug_AddictionSeverityPerDose_Desc".Translate(), 2424)); } yield return(new StatDrawEntry(StatCategoryDefOf.Drug, "RandomODChance".Translate(), drugComp.largeOverdoseChance.ToStringPercent(), "Stat_Thing_Drug_RandomODChance_Desc".Translate(), 2380)); yield return(new StatDrawEntry(StatCategoryDefOf.Drug, "SafeDoseInterval".Translate(), GetSafeDoseIntervalReadout(def), "Stat_Thing_Drug_SafeDoseInterval_Desc".Translate(), 2435)); }