public static bool CanBingeOnNow(Pawn pawn, ChemicalDef chemical, DrugCategory drugCategory) { if (!chemical.canBinge) { return(false); } if (!pawn.Spawned) { return(false); } List <Thing> list = pawn.Map.listerThings.ThingsInGroup(ThingRequestGroup.Drug); for (int i = 0; i < list.Count; i++) { if (!list[i].Position.Fogged(list[i].Map) && (drugCategory == DrugCategory.Any || list[i].def.ingestible.drugCategory == drugCategory)) { CompDrug compDrug = list[i].TryGetComp <CompDrug>(); if (compDrug.Props.chemical == chemical && (list[i].Position.Roofed(list[i].Map) || list[i].Position.InHorDistOf(pawn.Position, 45f)) && pawn.CanReach(list[i], PathEndMode.ClosestTouch, Danger.Deadly, false, TraverseMode.ByPawn)) { return(true); } } } return(false); }
protected override Thing BestIngestTarget(Pawn pawn) { ChemicalDef chemical = this.GetChemical(pawn); DrugCategory drugCategory = this.GetDrugCategory(pawn); if (chemical == null) { Log.ErrorOnce("Tried to binge on null chemical.", 1393746152, false); return(null); } Hediff overdose = pawn.health.hediffSet.GetFirstHediffOfDef(HediffDefOf.DrugOverdose, false); Predicate <Thing> predicate = delegate(Thing t) { if (!this.IgnoreForbid(pawn) && t.IsForbidden(pawn)) { return(false); } if (!pawn.CanReserve(t, 1, -1, null, false)) { return(false); } CompDrug compDrug = t.TryGetComp <CompDrug>(); return(compDrug.Props.chemical == chemical && (overdose == null || !compDrug.Props.CanCauseOverdose || overdose.Severity + compDrug.Props.overdoseSeverityOffset.max < 0.786f) && (pawn.Position.InHorDistOf(t.Position, 60f) || t.Position.Roofed(t.Map) || pawn.Map.areaManager.Home[t.Position] || t.GetSlotGroup() != null) && t.def.ingestible.drugCategory.IncludedIn(drugCategory)); }; IntVec3 position = pawn.Position; Map map = pawn.Map; ThingRequest thingReq = ThingRequest.ForGroup(ThingRequestGroup.Drug); PathEndMode peMode = PathEndMode.OnCell; TraverseParms traverseParams = TraverseParms.For(pawn, Danger.Deadly, TraverseMode.ByPawn, false); Predicate <Thing> validator = predicate; return(GenClosest.ClosestThingReachable(position, map, thingReq, peMode, traverseParams, 9999f, validator, null, 0, -1, false, RegionType.Set_Passable, false)); }
private Thing FindCombatEnhancingDrug(Pawn pawn) { for (int i = 0; i < pawn.inventory.innerContainer.Count; i++) { Thing thing = pawn.inventory.innerContainer[i]; CompDrug compDrug = thing.TryGetComp <CompDrug>(); if (compDrug != null && compDrug.Props.isCombatEnhancingDrug) { return(thing); } } return(null); }
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)); }
internal bool <> m__0(Thing t) { if (!this.$this.IgnoreForbid(this.pawn) && t.IsForbidden(this.pawn)) { return(false); } if (!this.pawn.CanReserve(t, 1, -1, null, false)) { return(false); } CompDrug compDrug = t.TryGetComp <CompDrug>(); return(compDrug.Props.chemical == this.chemical && (this.overdose == null || !compDrug.Props.CanCauseOverdose || this.overdose.Severity + compDrug.Props.overdoseSeverityOffset.max < 0.786f) && (this.pawn.Position.InHorDistOf(t.Position, 60f) || t.Position.Roofed(t.Map) || this.pawn.Map.areaManager.Home[t.Position] || t.GetSlotGroup() != null) && t.def.ingestible.drugCategory.IncludedIn(this.drugCategory)); }
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); } } } } }
private bool DrugValidator(Pawn pawn, Hediff_Addiction addiction, Thing drug) { bool result; if (!drug.def.IsDrug) { result = false; } else { if (drug.Spawned) { if (drug.IsForbidden(pawn)) { return(false); } if (!pawn.CanReserve(drug, 1, -1, null, false)) { return(false); } if (!drug.IsSociallyProper(pawn)) { return(false); } } CompDrug compDrug = drug.TryGetComp <CompDrug>(); if (compDrug == null || compDrug.Props.chemical == null) { result = false; } else if (compDrug.Props.chemical.addictionHediff != addiction.def) { result = false; } else { if (pawn.drugs != null && !pawn.drugs.CurrentPolicy[drug.def].allowedForAddiction && pawn.story != null) { int num = pawn.story.traits.DegreeOfTrait(TraitDefOf.DrugDesire); if (num <= 0 && (!pawn.InMentalState || !pawn.MentalStateDef.ignoreDrugPolicy)) { return(false); } } result = true; } } return(result); }
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++; } } } }
protected override Thing BestIngestTarget(Pawn pawn) { ChemicalDef chemical = GetChemical(pawn); DrugCategory drugCategory = GetDrugCategory(pawn); if (chemical == null) { Log.ErrorOnce("Tried to binge on null chemical.", 1393746152); return(null); } Hediff overdose = pawn.health.hediffSet.GetFirstHediffOfDef(HediffDefOf.DrugOverdose); Predicate <Thing> validator = delegate(Thing t) { if (!IgnoreForbid(pawn) && t.IsForbidden(pawn)) { return(false); } if (!pawn.CanReserve(t)) { return(false); } CompDrug compDrug = t.TryGetComp <CompDrug>(); if (compDrug.Props.chemical != chemical) { return(false); } if (overdose != null && compDrug.Props.CanCauseOverdose && overdose.Severity + compDrug.Props.overdoseSeverityOffset.max >= 0.786f) { return(false); } if (!pawn.Position.InHorDistOf(t.Position, 60f) && !t.Position.Roofed(t.Map) && !pawn.Map.areaManager.Home[t.Position] && t.GetSlotGroup() == null) { return(false); } return(t.def.ingestible.drugCategory.IncludedIn(drugCategory) ? true : false); }; return(GenClosest.ClosestThingReachable(pawn.Position, pawn.Map, ThingRequest.ForGroup(ThingRequestGroup.Drug), PathEndMode.OnCell, TraverseParms.For(pawn), 9999f, validator)); }
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); }