public override void ModifyChemicalEffect(ChemicalDef chem, ref float effect) { for (int i = 0; i < this.comps.Count; i++) { this.comps[i].CompModifyChemicalEffect(chem, ref effect); } }
public override void ModifyChemicalEffect(ChemicalDef chem, ref float effect) { foreach (var diff in comps) { diff.CompModifyChemicalEffect(chem, ref effect); } }
public override void CompModifyChemicalEffect(ChemicalDef chem, ref float effect) { if (Props.chemical == chem) { effect *= CurrentFactor; } }
public bool CanBingeOnNow(Pawn pawn, ChemicalDef chemical, DrugCategory drugCategory) { List <Thing> thingList = pawn.Map.listerThings.ThingsInGroup(ThingRequestGroup.Drug); for (int index = 0; index < thingList.Count; ++index) { if (!thingList[index].Position.Fogged(thingList[index].Map) && (drugCategory == DrugCategory.Any || thingList[index].def.ingestible.drugCategory == drugCategory) && thingList[index].TryGetComp <CompDrug>().Props.chemical == chemical && (thingList[index].Position.Roofed(thingList[index].Map) || thingList[index].Position.InHorDistOf(pawn.Position, 45f)) && pawn.CanReach((LocalTargetInfo)thingList[index], PathEndMode.ClosestTouch, Danger.Deadly, false, TraverseMode.ByPawn)) { return(true); } } return(false); }
public static bool CanEat(ThingDef food, ThingDef race) { if (foodRestrictionDict.TryGetValue(food, out List <ThingDef_AlienRace> races) || ((race as ThingDef_AlienRace)?.alienRace.raceRestriction.onlyEatRaceRestrictedFood ?? false)) { if (!(races?.Contains(race as ThingDef_AlienRace) ?? false) && (!foodWhiteDict.TryGetValue(food, out races) || !races.Contains(race as ThingDef_AlienRace))) { return(false); } } ChemicalDef chemical = food.GetCompProperties <CompProperties_Drug>()?.chemical; return(chemical == null || ((race as ThingDef_AlienRace)?.alienRace.generalSettings.chemicalSettings?.TrueForAll(match: c => c.ingestible || c.chemical != chemical) ?? true)); }
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); } var 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)); }
private void ChooseRandomChemical() { addictions.Clear(); List <Hediff> hediffs = pawn.health.hediffSet.hediffs; for (int i = 0; i < hediffs.Count; i++) { Hediff_Addiction hediff_Addiction = hediffs[i] as Hediff_Addiction; if (hediff_Addiction != null && AddictionUtility.CanBingeOnNow(pawn, hediff_Addiction.Chemical, DrugCategory.Any)) { addictions.Add(hediff_Addiction.Chemical); } } if (addictions.Count > 0) { chemical = addictions.RandomElement(); drugCategory = DrugCategory.Any; addictions.Clear(); } else { chemical = (from x in DefDatabase <ChemicalDef> .AllDefsListForReading where AddictionUtility.CanBingeOnNow(pawn, x, def.drugCategory) select x).RandomElementWithFallback(); if (chemical != null) { drugCategory = def.drugCategory; } else { chemical = (from x in DefDatabase <ChemicalDef> .AllDefsListForReading where AddictionUtility.CanBingeOnNow(pawn, x, DrugCategory.Any) select x).RandomElementWithFallback(); if (chemical != null) { drugCategory = DrugCategory.Any; } else { chemical = DefDatabase <ChemicalDef> .AllDefsListForReading.RandomElement(); drugCategory = DrugCategory.Any; } } } }
private void ChooseRandomChemical() { MentalState_BingingDrug.addictions.Clear(); List <Hediff> hediffs = this.pawn.health.hediffSet.hediffs; for (int i = 0; i < hediffs.Count; i++) { Hediff_Addiction hediff_Addiction = hediffs[i] as Hediff_Addiction; if (hediff_Addiction != null && AddictionUtility.CanBingeOnNow(this.pawn, hediff_Addiction.Chemical, DrugCategory.Any)) { MentalState_BingingDrug.addictions.Add(hediff_Addiction.Chemical); } } if (MentalState_BingingDrug.addictions.Count > 0) { this.chemical = MentalState_BingingDrug.addictions.RandomElement <ChemicalDef>(); this.drugCategory = DrugCategory.Any; MentalState_BingingDrug.addictions.Clear(); } else { this.chemical = (from x in DefDatabase <ChemicalDef> .AllDefsListForReading where AddictionUtility.CanBingeOnNow(this.pawn, x, this.def.drugCategory) select x).RandomElementWithFallback(null); if (this.chemical != null) { this.drugCategory = this.def.drugCategory; } else { this.chemical = (from x in DefDatabase <ChemicalDef> .AllDefsListForReading where AddictionUtility.CanBingeOnNow(this.pawn, x, DrugCategory.Any) select x).RandomElementWithFallback(null); if (this.chemical != null) { this.drugCategory = DrugCategory.Any; } else { this.chemical = DefDatabase <ChemicalDef> .AllDefsListForReading.RandomElement <ChemicalDef>(); this.drugCategory = DrugCategory.Any; } } } }
private void ChooseRandomChemical() { addictions.Clear(); List <Hediff> hediffs = pawn.health.hediffSet.hediffs; for (var i = 0; i < hediffs.Count; i++) { var hediff_Addiction = hediffs[i] as Hediff_Addiction; if (hediff_Addiction != null && AddictionUtility.CanBingeOnNow(pawn, hediff_Addiction.Chemical, DrugCategory.Any)) { addictions.Add(hediff_Addiction.Chemical); } } if (addictions.Count > 0) { chemical = addictions.RandomElement(); drugCategory = DrugCategory.Any; addictions.Clear(); return; } chemical = DefDatabase <ChemicalDef> .AllDefsListForReading.Where(IsValidChemical).RandomElementWithFallback(); if (chemical != null) { drugCategory = def.drugCategory; return; } chemical = DefDatabase <ChemicalDef> .AllDefsListForReading.Where(IsValidChemical).RandomElementWithFallback(); if (chemical != null) { drugCategory = DrugCategory.Any; return; } chemical = DefDatabase <ChemicalDef> .AllDefsListForReading.RandomElement(); drugCategory = DrugCategory.Any; }
protected virtual void DoIngestionOutcomeSpecial(Pawn pawn, Thing ingested) { if (!AddictionUtility.AddictedToAnything(pawn)) { return; } using (IEnumerator <ChemicalDef> enumerator = DefDatabase <ChemicalDef> .get_AllDefs().GetEnumerator()) { while (((IEnumerator)enumerator).MoveNext()) { ChemicalDef current = enumerator.Current; if (AddictionUtility.IsAddicted(pawn, current)) { Hediff addictionHediff = (Hediff)AddictionUtility.FindAddictionHediff(pawn, current); Hediff toleranceHediff = AddictionUtility.FindToleranceHediff(pawn, current); ((Pawn_HealthTracker)pawn.health).RemoveHediff(addictionHediff); if (toleranceHediff != null) { ((Pawn_HealthTracker)pawn.health).RemoveHediff(toleranceHediff); } } } } using (IEnumerator <HediffDef> enumerator = this.BeneficialAddictiveDrugHediffs.GetEnumerator()) { while (((IEnumerator)enumerator).MoveNext()) { HediffDef current = enumerator.Current; Hediff firstHediffOfDef = ((HediffSet)((Pawn_HealthTracker)pawn.health).hediffSet).GetFirstHediffOfDef(current, false); if (firstHediffOfDef != null) { ((Pawn_HealthTracker)pawn.health).RemoveHediff(firstHediffOfDef); } } } }
public virtual void ModifyChemicalEffect(ChemicalDef chem, ref float effect) { }
private bool <ChooseRandomChemical> m__1(ChemicalDef x) { return(AddictionUtility.CanBingeOnNow(this.pawn, x, DrugCategory.Any)); }
private bool IsValidChemical(ChemicalDef cDef) { return(cDef.GetModExtension <MutagenicDrug>() != null); }
// drug resistance public static void ModifyChemicalEffectForToleranceAndBodySize_Postfix(Pawn pawn, ChemicalDef chemicalDef, ref float effect) { if (chemicalDef != null) { if (pawn.kindDef.race.defName == "Ant_AntiniumRace" && chemicalDef.defName != "Luciferium") { effect *= .6f; } } }