Esempio n. 1
0
 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);
         }
     }
 }
Esempio n. 2
0
        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;
            }
        }
 internal bool <> m__0(ChemicalDef x)
 {
     return(PawnAddictionHediffsGenerator.PossibleWithTechLevel(x, this.pawn.Faction) && !AddictionUtility.IsAddicted(this.pawn, x));
 }
 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);
 }
        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);
        }