public override void PrePostIngested(Pawn ingester) { if (!Props.Addictive || !ingester.RaceProps.IsFlesh) { return; } HediffDef addictionHediffDef = Props.chemical.addictionHediff; Hediff_Addiction hediff_Addiction = AddictionUtility.FindAddictionHediff(ingester, Props.chemical); float num = AddictionUtility.FindToleranceHediff(ingester, Props.chemical)?.Severity ?? 0f; if (hediff_Addiction != null) { hediff_Addiction.Severity += Props.existingAddictionSeverityOffset; } else if (Rand.Value < Props.addictiveness && num >= Props.minToleranceToAddict) { ingester.health.AddHediff(addictionHediffDef); if (PawnUtility.ShouldSendNotificationAbout(ingester)) { Find.LetterStack.ReceiveLetter("LetterLabelNewlyAddicted".Translate(Props.chemical.label).CapitalizeFirst(), "LetterNewlyAddicted".Translate(ingester.LabelShort, Props.chemical.label, ingester.Named("PAWN")).AdjustedFor(ingester).CapitalizeFirst(), LetterDefOf.NegativeEvent, ingester); } AddictionUtility.CheckDrugAddictionTeachOpportunity(ingester); } if (addictionHediffDef.causesNeed != null) { Need need = ingester.needs.AllNeeds.Find((Need x) => x.def == addictionHediffDef.causesNeed); if (need != null) { float effect = Props.needLevelOffset; AddictionUtility.ModifyChemicalEffectForToleranceAndBodySize(ingester, Props.chemical, ref effect); need.CurLevel += effect; } } }
public override void PostIngested(Pawn ingester) { if (this.Props.Addictive && ingester.RaceProps.IsFlesh) { HediffDef addictionHediffDef = this.Props.chemical.addictionHediff; Hediff_Addiction hediff_Addiction = AddictionUtility.FindAddictionHediff(ingester, this.Props.chemical); Hediff hediff = AddictionUtility.FindToleranceHediff(ingester, this.Props.chemical); float num = (float)((hediff == null) ? 0.0 : hediff.Severity); if (hediff_Addiction != null) { hediff_Addiction.Severity += this.Props.existingAddictionSeverityOffset; } else if (Rand.Value < this.Props.addictiveness && num >= this.Props.minToleranceToAddict) { ingester.health.AddHediff(addictionHediffDef, null, null); if (PawnUtility.ShouldSendNotificationAbout(ingester)) { Find.LetterStack.ReceiveLetter("LetterLabelNewlyAddicted".Translate(this.Props.chemical.label).CapitalizeFirst(), "LetterNewlyAddicted".Translate(ingester.LabelShort, this.Props.chemical.label).AdjustedFor(ingester).CapitalizeFirst(), LetterDefOf.NegativeEvent, ingester, null); } AddictionUtility.CheckDrugAddictionTeachOpportunity(ingester); } if (addictionHediffDef.causesNeed != null) { Need need = ingester.needs.AllNeeds.Find((Need x) => x.def == addictionHediffDef.causesNeed); if (need != null) { float needLevelOffset = this.Props.needLevelOffset; AddictionUtility.ModifyChemicalEffectForToleranceAndBodySize(ingester, this.Props.chemical, ref needLevelOffset); need.CurLevel += needLevelOffset; } } Hediff firstHediffOfDef = ingester.health.hediffSet.GetFirstHediffOfDef(HediffDefOf.DrugOverdose, false); float num2 = (float)((firstHediffOfDef == null) ? 0.0 : firstHediffOfDef.Severity); if (num2 < 0.89999997615814209 && Rand.Value < this.Props.largeOverdoseChance) { float num3 = Rand.Range(0.85f, 0.99f); HealthUtility.AdjustSeverity(ingester, HediffDefOf.DrugOverdose, num3 - num2); if (ingester.Faction == Faction.OfPlayer) { Messages.Message("MessageAccidentalOverdose".Translate(ingester.LabelIndefinite(), base.parent.LabelNoCount).CapitalizeFirst(), MessageTypeDefOf.NegativeHealthEvent); } } else { float num4 = this.Props.overdoseSeverityOffset.RandomInRange / ingester.BodySize; if (num4 > 0.0) { HealthUtility.AdjustSeverity(ingester, HediffDefOf.DrugOverdose, num4); } } } if (this.Props.isCombatEnhancingDrug && !ingester.Dead) { ingester.mindState.lastTakeCombatEnhancingDrugTick = Find.TickManager.TicksGame; } if (ingester.drugs != null) { ingester.drugs.Notify_DrugIngested(base.parent); } }
public static Hediff_Addiction FindAddictionHediff(Pawn pawn, Thing drug) { if (!drug.def.IsDrug) { return(null); } CompDrug compDrug = drug.TryGetComp <CompDrug>(); if (!compDrug.Props.Addictive) { return(null); } return(AddictionUtility.FindAddictionHediff(pawn, compDrug.Props.chemical)); }
public static Hediff_Addiction FindAddictionHediff(Pawn pawn, Thing drug) { Hediff_Addiction result; if (!drug.def.IsDrug) { result = null; } else { CompDrug compDrug = drug.TryGetComp <CompDrug>(); if (!compDrug.Props.Addictive) { result = null; } else { result = AddictionUtility.FindAddictionHediff(pawn, compDrug.Props.chemical); } } return(result); }
public static bool IsAddicted(Pawn pawn, Thing drug) { return(AddictionUtility.FindAddictionHediff(pawn, drug) != null); }
public static bool IsAddicted(Pawn pawn, ChemicalDef chemical) { return(AddictionUtility.FindAddictionHediff(pawn, chemical) != null); }