Exemplo n.º 1
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));
 }