static void Postfix(Pawn_InventoryTracker __instance, ref Thing __result) { Pawn pawn = __instance.pawn; if (pawn?.story?.traits?.HasTrait(GMT_DefOf.GMT_Drunken_Master) ?? false) { for (int i = 0; i < __instance.innerContainer.Count; i++) { Thing thing = __instance.innerContainer[i]; CompDrug compDrug = thing.TryGetComp <CompDrug>(); if (compDrug != null && compDrug.Props.chemical == ChemicalDefOf.Alcohol) { var doer = thing.def.ingestible.outcomeDoers.Find( (IngestionOutcomeDoer x) => ((x as IngestionOutcomeDoer_GiveHediff)?.hediffDef ?? null) == HediffDefOf.AlcoholHigh ) as IngestionOutcomeDoer_GiveHediff; if (doer == null) { continue; } Hediff hediff = HediffMaker.MakeHediff(doer.hediffDef, pawn, null); hediff.Severity = doer.severity; // Only count this as a drug if it won't down the pawn if (!pawn.health.WouldBeDownedAfterAddingHediff(hediff)) { __result = thing; break; } } } } }
public IEnumerable <Thing> GetCombatEnhancingDrugs() { foreach (Thing item in innerContainer) { CompDrug compDrug = item.TryGetComp <CompDrug>(); if (compDrug != null && compDrug.Props.isCombatEnhancingDrug) { yield return(item); } } }
public static bool TryGetDrugToSatisfyChemicalNeed(Caravan caravan, Pawn forPawn, Need_Chemical chemical, out Thing drug, out Pawn owner) { Hediff_Addiction addictionHediff = chemical.AddictionHediff; bool result; if (addictionHediff == null) { drug = null; owner = null; result = false; } else { List <Thing> list = CaravanInventoryUtility.AllInventoryItems(caravan); Thing thing = null; for (int i = 0; i < list.Count; i++) { Thing thing2 = list[i]; if (thing2.IngestibleNow && thing2.def.IsDrug) { CompDrug compDrug = thing2.TryGetComp <CompDrug>(); if (compDrug != null && compDrug.Props.chemical != null) { if (compDrug.Props.chemical.addictionHediff == addictionHediff.def) { if (forPawn.drugs == null || forPawn.drugs.CurrentPolicy[thing2.def].allowedForAddiction || forPawn.story == null || forPawn.story.traits.DegreeOfTrait(TraitDefOf.DrugDesire) > 0) { thing = thing2; break; } } } } } if (thing != null) { drug = thing; owner = CaravanInventoryUtility.GetOwnerOf(caravan, thing); result = true; } else { drug = null; owner = null; result = false; } } return(result); }
// RimWorld.Planet.CaravanInventoryUtility public static bool TryGetBestDrug(Pawn vehicle, Pawn forPawn, Need_Chemical chemical, out Thing drug, out Pawn owner) { Hediff_Addiction addictionHediff = chemical.AddictionHediff; if (addictionHediff == null) { drug = null; owner = null; return(false); } List <Thing> list = vehicle?.inventory?.innerContainer?.InnerListForReading; Thing thing = null; for (int i = 0; i < list.Count; i++) { Thing thing2 = list[i]; if (thing2.IngestibleNow && thing2.def.IsDrug) { CompDrug compDrug = thing2.TryGetComp <CompDrug>(); if (compDrug != null && compDrug.Props.chemical != null) { if (compDrug.Props.chemical.addictionHediff == addictionHediff.def) { if (forPawn.drugs == null || forPawn.drugs.CurrentPolicy[thing2.def].allowedForAddiction || forPawn.story == null || forPawn.story.traits.DegreeOfTrait(TraitDefOf.DrugDesire) > 0) { thing = thing2; break; } } } } } if (thing != null) { drug = thing; owner = forPawn; return(true); } drug = null; owner = null; return(false); }