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 void SetGuestStatus(Faction newHost, bool prisoner = false) { if (newHost != null) { Released = false; } if (newHost != HostFaction || prisoner != IsPrisoner) { if (!prisoner && pawn.Faction.HostileTo(newHost)) { Log.Error("Tried to make " + pawn + " a guest of " + newHost + " but their faction " + pawn.Faction + " is hostile to " + newHost); } else if (newHost != null && newHost == pawn.Faction && !prisoner) { Log.Error("Tried to make " + pawn + " a guest of their own faction " + pawn.Faction); } else { bool flag = prisoner && (!IsPrisoner || HostFaction != newHost); isPrisonerInt = prisoner; hostFactionInt = newHost; pawn.ClearMind(); if (flag) { pawn.DropAndForbidEverything(); pawn.GetLord()?.Notify_PawnLost(pawn, PawnLostCondition.MadePrisoner); if (newHost == Faction.OfPlayer) { Find.StoryWatcher.watcherPopAdaptation.Notify_PawnEvent(pawn, PopAdaptationEvent.GainedPrisoner); } if (pawn.Drafted) { pawn.drafter.Drafted = false; } float x = pawn.RecruitDifficulty(Faction.OfPlayer); resistance = StartingResistancePerRecruitDifficultyCurve.Evaluate(x); resistance *= StartingResistanceFactorFromPopulationIntentCurve.Evaluate(StorytellerUtilityPopulation.PopulationIntent); resistance *= StartingResistanceRandomFactorRange.RandomInRange; resistance = (float)GenMath.RoundRandom(resistance); } PawnComponentsUtility.AddAndRemoveDynamicComponents(pawn); pawn.health.surgeryBills.Clear(); if (pawn.ownership != null) { pawn.ownership.Notify_ChangedGuestStatus(); } ReachabilityUtility.ClearCacheFor(pawn); if (pawn.Spawned) { pawn.Map.mapPawns.UpdateRegistryForPawn(pawn); pawn.Map.attackTargetsCache.UpdateTarget(pawn); } AddictionUtility.CheckDrugAddictionTeachOpportunity(pawn); if (prisoner && pawn.playerSettings != null) { pawn.playerSettings.Notify_MadePrisoner(); } } } }
public void SetGuestStatus(Faction newHost, bool prisoner = false) { if (newHost != null) { this.Released = false; } if (newHost == this.HostFaction && prisoner == this.IsPrisoner) { return; } if (!prisoner && this.pawn.Faction.HostileTo(newHost)) { Log.Error("Tried to make " + this.pawn + " a guest of " + newHost + " but their faction " + this.pawn.Faction + " is hostile to " + newHost); } else if (newHost != null && newHost == this.pawn.Faction && !prisoner) { Log.Error("Tried to make " + this.pawn + " a guest of their own faction " + this.pawn.Faction); } else { bool flag = prisoner && (!this.IsPrisoner || this.HostFaction != newHost); this.isPrisonerInt = prisoner; this.hostFactionInt = newHost; this.pawn.ClearMind(false); if (flag) { this.pawn.DropAndForbidEverything(false); Lord lord = this.pawn.GetLord(); if (lord != null) { lord.Notify_PawnLost(this.pawn, PawnLostCondition.MadePrisoner); } if (this.pawn.Drafted) { this.pawn.drafter.Drafted = false; } } PawnComponentsUtility.AddAndRemoveDynamicComponents(this.pawn, false); this.pawn.health.surgeryBills.Clear(); if (this.pawn.ownership != null) { this.pawn.ownership.Notify_ChangedGuestStatus(); } ReachabilityUtility.ClearCache(); if (this.pawn.Spawned) { this.pawn.Map.mapPawns.UpdateRegistryForPawn(this.pawn); this.pawn.Map.attackTargetsCache.UpdateTarget(this.pawn); } AddictionUtility.CheckDrugAddictionTeachOpportunity(this.pawn); if (prisoner && this.pawn.playerSettings != null) { this.pawn.playerSettings.Notify_MadePrisoner(); } } }
protected override void DoIngestionOutcomeSpecial(Pawn pawn, Thing ingested) { Hediff hediff = HediffMaker.MakeHediff(this.hediffDef, pawn, null); float num = (!(this.severity > 0.0)) ? this.hediffDef.initialSeverity : this.severity; if (this.divideByBodySize) { num /= pawn.BodySize; } AddictionUtility.ModifyChemicalEffectForToleranceAndBodySize(pawn, this.toleranceChemical, ref num); hediff.Severity = num; pawn.health.AddHediff(hediff, null, null); }
public static void CheckDrugAddictionTeachOpportunity(Pawn pawn) { if (pawn.RaceProps.IsFlesh && pawn.Spawned) { if (pawn.Faction == Faction.OfPlayer || pawn.HostFaction == Faction.OfPlayer) { if (AddictionUtility.AddictedToAnything(pawn)) { LessonAutoActivator.TeachOpportunity(ConceptDefOf.DrugAddiction, pawn, OpportunityType.Important); } } } }
protected override void DoIngestionOutcomeSpecial(Pawn pawn, Thing ingested) { Hediff hediff = HediffMaker.MakeHediff(hediffDef, pawn); float effect = (!(severity > 0f)) ? hediffDef.initialSeverity : severity; if (divideByBodySize) { effect /= pawn.BodySize; } AddictionUtility.ModifyChemicalEffectForToleranceAndBodySize(pawn, toleranceChemical, ref effect); hediff.Severity = effect; pawn.health.AddHediff(hediff); }
protected override void DoIngestionOutcomeSpecial(Pawn pawn, Thing ingested) { if (pawn.needs != null) { Need need = pawn.needs.TryGetNeed(this.need); if (need != null) { float effect = offset; AddictionUtility.ModifyChemicalEffectForToleranceAndBodySize(pawn, toleranceChemical, ref effect); need.CurLevel += effect; } } }
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)); }
protected override void DoIngestionOutcomeSpecial(Pawn pawn, Thing ingested) { if (pawn.needs == null) { return; } Need need = pawn.needs.TryGetNeed(this.need); if (need == null) { return; } float num = this.offset; AddictionUtility.ModifyChemicalEffectForToleranceAndBodySize(pawn, this.toleranceChemical, ref num); need.CurLevel += num; }
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 void SetGuestStatus(Faction newHost, bool prisoner = false) { if (newHost != null) { this.Released = false; } if (newHost == this.HostFaction && prisoner == this.IsPrisoner) { return; } if (!prisoner && this.pawn.Faction.HostileTo(newHost)) { Log.Error(string.Concat(new object[] { "Tried to make ", this.pawn, " a guest of ", newHost, " but their faction ", this.pawn.Faction, " is hostile to ", newHost }), false); return; } if (newHost != null && newHost == this.pawn.Faction && !prisoner) { Log.Error(string.Concat(new object[] { "Tried to make ", this.pawn, " a guest of their own faction ", this.pawn.Faction }), false); return; } bool flag = prisoner && (!this.IsPrisoner || this.HostFaction != newHost); this.isPrisonerInt = prisoner; this.hostFactionInt = newHost; this.pawn.ClearMind(false); if (flag) { this.pawn.DropAndForbidEverything(false); Lord lord = this.pawn.GetLord(); if (lord != null) { lord.Notify_PawnLost(this.pawn, PawnLostCondition.MadePrisoner, null); } if (newHost == Faction.OfPlayer) { Find.StoryWatcher.watcherPopAdaptation.Notify_PawnEvent(this.pawn, PopAdaptationEvent.GainedPrisoner); } if (this.pawn.Drafted) { this.pawn.drafter.Drafted = false; } float x = this.pawn.RecruitDifficulty(Faction.OfPlayer); this.resistance = Pawn_GuestTracker.StartingResistancePerRecruitDifficultyCurve.Evaluate(x); this.resistance *= Pawn_GuestTracker.StartingResistanceFactorFromPopulationIntentCurve.Evaluate(StorytellerUtilityPopulation.PopulationIntent); this.resistance *= Pawn_GuestTracker.StartingResistanceRandomFactorRange.RandomInRange; this.resistance = (float)GenMath.RoundRandom(this.resistance); } PawnComponentsUtility.AddAndRemoveDynamicComponents(this.pawn, false); this.pawn.health.surgeryBills.Clear(); if (this.pawn.ownership != null) { this.pawn.ownership.Notify_ChangedGuestStatus(); } ReachabilityUtility.ClearCacheFor(this.pawn); if (this.pawn.Spawned) { this.pawn.Map.mapPawns.UpdateRegistryForPawn(this.pawn); this.pawn.Map.attackTargetsCache.UpdateTarget(this.pawn); } AddictionUtility.CheckDrugAddictionTeachOpportunity(this.pawn); if (prisoner && this.pawn.playerSettings != null) { this.pawn.playerSettings.Notify_MadePrisoner(); } }
public static void GenerateAddictionsAndTolerancesFor(Pawn pawn) { if (pawn.RaceProps.IsFlesh && pawn.RaceProps.Humanlike && !pawn.IsTeetotaler()) { allDrugs.Clear(); for (int i = 0; i < 3; i++) { if (Rand.Value >= pawn.kindDef.chemicalAddictionChance) { break; } if (!allDrugs.Any()) { allDrugs.AddRange(from x in DefDatabase <ThingDef> .AllDefsListForReading where x.category == ThingCategory.Item && x.GetCompProperties <CompProperties_Drug>() != null select x); } IEnumerable <ChemicalDef> source = from x in DefDatabase <ChemicalDef> .AllDefsListForReading where PossibleWithTechLevel(x, pawn.Faction) && !AddictionUtility.IsAddicted(pawn, x) select x; if (!source.TryRandomElement(out ChemicalDef result)) { break; } Hediff hediff = HediffMaker.MakeHediff(result.addictionHediff, pawn); hediff.Severity = GeneratedAddictionSeverityRange.RandomInRange; pawn.health.AddHediff(hediff); if (result.toleranceHediff != null && Rand.Value < result.onGeneratedAddictedToleranceChance) { Hediff hediff2 = HediffMaker.MakeHediff(result.toleranceHediff, pawn); hediff2.Severity = GeneratedToleranceSeverityRange.RandomInRange; pawn.health.AddHediff(hediff2); } if (result.onGeneratedAddictedEvents != null) { foreach (HediffGiver_Event onGeneratedAddictedEvent in result.onGeneratedAddictedEvents) { onGeneratedAddictedEvent.EventOccurred(pawn); } } DoIngestionOutcomeDoers(pawn, result); } } }
public static void GenerateAddictionsAndTolerancesFor(Pawn pawn) { if (!pawn.RaceProps.IsFlesh || !pawn.RaceProps.Humanlike) { return; } if (pawn.IsTeetotaler()) { return; } PawnAddictionHediffsGenerator.allDrugs.Clear(); int i = 0; while (i < 3) { if (Rand.Value < pawn.kindDef.chemicalAddictionChance) { if (!PawnAddictionHediffsGenerator.allDrugs.Any <ThingDef>()) { PawnAddictionHediffsGenerator.allDrugs.AddRange(from x in DefDatabase <ThingDef> .AllDefsListForReading where x.category == ThingCategory.Item && x.GetCompProperties <CompProperties_Drug>() != null select x); } IEnumerable <ChemicalDef> source = from x in DefDatabase <ChemicalDef> .AllDefsListForReading where PawnAddictionHediffsGenerator.PossibleWithTechLevel(x, pawn.Faction) && !AddictionUtility.IsAddicted(pawn, x) select x; ChemicalDef chemicalDef; if (source.TryRandomElement(out chemicalDef)) { Hediff hediff = HediffMaker.MakeHediff(chemicalDef.addictionHediff, pawn, null); hediff.Severity = PawnAddictionHediffsGenerator.GeneratedAddictionSeverityRange.RandomInRange; pawn.health.AddHediff(hediff, null, null); if (chemicalDef.toleranceHediff != null && Rand.Value < chemicalDef.onGeneratedAddictedToleranceChance) { Hediff hediff2 = HediffMaker.MakeHediff(chemicalDef.toleranceHediff, pawn, null); hediff2.Severity = PawnAddictionHediffsGenerator.GeneratedToleranceSeverityRange.RandomInRange; pawn.health.AddHediff(hediff2, null, null); } if (chemicalDef.onGeneratedAddictedEvents != null) { foreach (HediffGiver_Event current in chemicalDef.onGeneratedAddictedEvents) { current.EventOccurred(pawn); } } PawnAddictionHediffsGenerator.DoIngestionOutcomeDoers(pawn, chemicalDef); i++; continue; } } return; } }
protected override Job TryGiveJob(Pawn pawn) { if (pawn.inventory == null) { return(null); } if (!pawn.Map.areaManager.Home[pawn.Position]) { return(null); } if (pawn.Faction != Faction.OfPlayer) { return(null); } if (Find.TickManager.TicksGame > pawn.mindState.lastInventoryRawFoodUseTick + 150000) { for (int num = pawn.inventory.innerContainer.Count - 1; num >= 0; num--) { Thing thing = pawn.inventory.innerContainer[num]; if (thing.def.IsIngestible && !thing.def.IsDrug && (int)thing.def.ingestible.preferability <= 5) { Drop(pawn, thing); } } } for (int num2 = pawn.inventory.innerContainer.Count - 1; num2 >= 0; num2--) { Thing thing2 = pawn.inventory.innerContainer[num2]; if (thing2.def.IsDrug && pawn.drugs != null && !pawn.drugs.AllowedToTakeScheduledEver(thing2.def) && pawn.drugs.HasEverTaken(thing2.def) && !AddictionUtility.IsAddicted(pawn, thing2)) { Drop(pawn, thing2); } } return(null); }
public void SetGuestStatus(Faction newHost, bool prisoner = false) { if (newHost != null) { Released = false; } if (newHost == HostFaction && prisoner == IsPrisoner) { return; } if (!prisoner && pawn.Faction.HostileTo(newHost)) { Log.Error("Tried to make " + pawn + " a guest of " + newHost + " but their faction " + pawn.Faction + " is hostile to " + newHost); return; } if (newHost != null && newHost == pawn.Faction && !prisoner) { Log.Error("Tried to make " + pawn + " a guest of their own faction " + pawn.Faction); return; } bool num = prisoner && (!IsPrisoner || HostFaction != newHost); isPrisonerInt = prisoner; Faction faction = hostFactionInt; hostFactionInt = newHost; Pawn obj = pawn; bool clearMentalState = prisoner; obj.ClearMind(newHost != null, clearInspiration: false, clearMentalState); if (num) { pawn.DropAndForbidEverything(); pawn.GetLord()?.Notify_PawnLost(pawn, PawnLostCondition.MadePrisoner); if (pawn.Drafted) { pawn.drafter.Drafted = false; } float x = pawn.RecruitDifficulty(Faction.OfPlayer); resistance = StartingResistancePerRecruitDifficultyCurve.Evaluate(x); resistance *= StartingResistanceFactorFromPopulationIntentCurve.Evaluate(StorytellerUtilityPopulation.PopulationIntent); resistance *= StartingResistanceRandomFactorRange.RandomInRange; if (pawn.royalty != null) { RoyalTitle mostSeniorTitle = pawn.royalty.MostSeniorTitle; if (mostSeniorTitle != null) { resistance *= mostSeniorTitle.def.recruitmentResistanceFactor; resistance += mostSeniorTitle.def.recruitmentResistanceOffset; } } resistance = GenMath.RoundRandom(resistance); } PawnComponentsUtility.AddAndRemoveDynamicComponents(pawn); pawn.health.surgeryBills.Clear(); if (pawn.ownership != null) { pawn.ownership.Notify_ChangedGuestStatus(); } ReachabilityUtility.ClearCacheFor(pawn); if (pawn.Spawned) { pawn.Map.mapPawns.UpdateRegistryForPawn(pawn); pawn.Map.attackTargetsCache.UpdateTarget(pawn); } AddictionUtility.CheckDrugAddictionTeachOpportunity(pawn); if (prisoner && pawn.playerSettings != null) { pawn.playerSettings.Notify_MadePrisoner(); } if (faction != hostFactionInt) { QuestUtility.SendQuestTargetSignals(pawn.questTags, "ChangedHostFaction", pawn.Named("SUBJECT"), hostFactionInt.Named("FACTION")); } }
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); }
internal bool <> m__0(ChemicalDef x) { return(PawnAddictionHediffsGenerator.PossibleWithTechLevel(x, this.pawn.Faction) && !AddictionUtility.IsAddicted(this.pawn, x)); }
protected override Job TryGiveJob(Pawn pawn) { Job result; if (pawn.inventory == null) { result = null; } else if (!pawn.Map.areaManager.Home[pawn.Position]) { result = null; } else if (pawn.Faction != Faction.OfPlayer) { result = null; } else { if (Find.TickManager.TicksGame > pawn.mindState.lastInventoryRawFoodUseTick + 150000) { for (int i = pawn.inventory.innerContainer.Count - 1; i >= 0; i--) { Thing thing = pawn.inventory.innerContainer[i]; if (thing.def.IsIngestible && !thing.def.IsDrug && thing.def.ingestible.preferability <= FoodPreferability.RawTasty) { this.Drop(pawn, thing); } } } for (int j = pawn.inventory.innerContainer.Count - 1; j >= 0; j--) { Thing thing2 = pawn.inventory.innerContainer[j]; if (thing2.def.IsDrug && pawn.drugs != null && !pawn.drugs.AllowedToTakeScheduledEver(thing2.def) && pawn.drugs.HasEverTaken(thing2.def) && !AddictionUtility.IsAddicted(pawn, thing2)) { this.Drop(pawn, thing2); } } result = null; } return(result); }