Ejemplo n.º 1
0
        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));
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
 private static bool PossibleWithTechLevel(ChemicalDef chemical, Faction faction)
 {
     if (faction == null)
     {
         return(true);
     }
     return(allDrugs.Any((ThingDef x) => x.GetCompProperties <CompProperties_Drug>().chemical == chemical && (int)x.techLevel <= (int)faction.def.techLevel));
 }
Ejemplo n.º 4
0
 public static Hediff FindToleranceHediff(Pawn pawn, ChemicalDef chemical)
 {
     if (chemical.toleranceHediff == null)
     {
         return(null);
     }
     return(pawn.health.hediffSet.hediffs.Find((Hediff x) => x.def == chemical.toleranceHediff));
 }
Ejemplo n.º 5
0
 public static void ModifyChemicalEffectForToleranceAndBodySize(Pawn pawn, ChemicalDef chemicalDef, ref float effect)
 {
     if (chemicalDef != null)
     {
         List <Hediff> hediffs = pawn.health.hediffSet.hediffs;
         for (int i = 0; i < hediffs.Count; i++)
         {
             hediffs[i].ModifyChemicalEffect(chemicalDef, ref effect);
         }
     }
     effect /= pawn.BodySize;
 }
Ejemplo n.º 6
0
        public static Hediff FindToleranceHediff(Pawn pawn, ChemicalDef chemical)
        {
            Hediff result;

            if (chemical.toleranceHediff == null)
            {
                result = null;
            }
            else
            {
                result = pawn.health.hediffSet.hediffs.Find((Hediff x) => x.def == chemical.toleranceHediff);
            }
            return(result);
        }
Ejemplo n.º 7
0
 private static void DoIngestionOutcomeDoers(Pawn pawn, ChemicalDef chemical)
 {
     for (int i = 0; i < allDrugs.Count; i++)
     {
         CompProperties_Drug compProperties = allDrugs[i].GetCompProperties <CompProperties_Drug>();
         if (compProperties.chemical == chemical)
         {
             List <IngestionOutcomeDoer> outcomeDoers = allDrugs[i].ingestible.outcomeDoers;
             for (int j = 0; j < outcomeDoers.Count; j++)
             {
                 if (outcomeDoers[j].doToGeneratedPawnIfAddicted)
                 {
                     outcomeDoers[j].DoIngestionOutcome(pawn, null);
                 }
             }
         }
     }
 }
Ejemplo n.º 8
0
 public static void GenerateAddictionsAndTolerancesFor(Pawn pawn)
 {
     if (pawn.RaceProps.IsFlesh && pawn.RaceProps.Humanlike && !pawn.IsTeetotaler())
     {
         PawnAddictionHediffsGenerator.allDrugs.Clear();
         int num = 0;
         while (num < 3 && !(Rand.Value >= pawn.kindDef.chemicalAddictionChance))
         {
             if (!PawnAddictionHediffsGenerator.allDrugs.Any())
             {
                 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 = default(ChemicalDef);
             if (source.TryRandomElement <ChemicalDef>(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 onGeneratedAddictedEvent in chemicalDef.onGeneratedAddictedEvents)
                     {
                         onGeneratedAddictedEvent.EventOccurred(pawn);
                     }
                 }
                 PawnAddictionHediffsGenerator.DoIngestionOutcomeDoers(pawn, chemicalDef);
                 num++;
                 continue;
             }
             break;
         }
     }
 }
        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));
        }
Ejemplo n.º 10
0
        protected override int IngestInterval(Pawn pawn)
        {
            ChemicalDef chemical = this.GetChemical(pawn);
            int         num      = 600;

            if (chemical == ChemicalDefOf.Alcohol)
            {
                Hediff firstHediffOfDef = pawn.health.hediffSet.GetFirstHediffOfDef(HediffDefOf.AlcoholHigh, false);
                if (firstHediffOfDef != null)
                {
                    num = (int)((float)num * JobGiver_BingeDrug.IngestIntervalFactorCurve_Drunkness.Evaluate(firstHediffOfDef.Severity));
                }
            }
            else
            {
                Hediff firstHediffOfDef2 = pawn.health.hediffSet.GetFirstHediffOfDef(HediffDefOf.DrugOverdose, false);
                if (firstHediffOfDef2 != null)
                {
                    num = (int)((float)num * JobGiver_BingeDrug.IngestIntervalFactorCurve_DrugOverdose.Evaluate(firstHediffOfDef2.Severity));
                }
            }
            return(num);
        }
Ejemplo n.º 11
0
 private static bool PossibleWithTechLevel(ChemicalDef chemical, Faction faction)
 {
     return(faction == null || PawnAddictionHediffsGenerator.allDrugs.Any((ThingDef x) => x.GetCompProperties <CompProperties_Drug>().chemical == chemical && x.techLevel <= faction.def.techLevel));
 }
Ejemplo n.º 12
0
 public static Hediff_Addiction FindAddictionHediff(Pawn pawn, ChemicalDef chemical)
 {
     return((Hediff_Addiction)pawn.health.hediffSet.hediffs.Find((Hediff x) => x.def == chemical.addictionHediff));
 }
Ejemplo n.º 13
0
 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));
 }