Ejemplo n.º 1
0
        public override void PrePostIngested(Pawn ingester)
        {
            if (!Props.Addictive || !ingester.RaceProps.IsFlesh)
            {
                return;
            }
            HediffDef        addictionHediffDef = Props.chemical.addictionHediff;
            Hediff_Addiction hediff_Addiction   = AddictionUtility.FindAddictionHediff(ingester, Props.chemical);
            float            num = AddictionUtility.FindToleranceHediff(ingester, Props.chemical)?.Severity ?? 0f;

            if (hediff_Addiction != null)
            {
                hediff_Addiction.Severity += Props.existingAddictionSeverityOffset;
            }
            else if (Rand.Value < Props.addictiveness && num >= Props.minToleranceToAddict)
            {
                ingester.health.AddHediff(addictionHediffDef);
                if (PawnUtility.ShouldSendNotificationAbout(ingester))
                {
                    Find.LetterStack.ReceiveLetter("LetterLabelNewlyAddicted".Translate(Props.chemical.label).CapitalizeFirst(), "LetterNewlyAddicted".Translate(ingester.LabelShort, Props.chemical.label, ingester.Named("PAWN")).AdjustedFor(ingester).CapitalizeFirst(), LetterDefOf.NegativeEvent, ingester);
                }
                AddictionUtility.CheckDrugAddictionTeachOpportunity(ingester);
            }
            if (addictionHediffDef.causesNeed != null)
            {
                Need need = ingester.needs.AllNeeds.Find((Need x) => x.def == addictionHediffDef.causesNeed);
                if (need != null)
                {
                    float effect = Props.needLevelOffset;
                    AddictionUtility.ModifyChemicalEffectForToleranceAndBodySize(ingester, Props.chemical, ref effect);
                    need.CurLevel += effect;
                }
            }
        }
Ejemplo n.º 2
0
 public override void PostIngested(Pawn ingester)
 {
     if (this.Props.Addictive && ingester.RaceProps.IsFlesh)
     {
         HediffDef        addictionHediffDef = this.Props.chemical.addictionHediff;
         Hediff_Addiction hediff_Addiction   = AddictionUtility.FindAddictionHediff(ingester, this.Props.chemical);
         Hediff           hediff             = AddictionUtility.FindToleranceHediff(ingester, this.Props.chemical);
         float            num = (float)((hediff == null) ? 0.0 : hediff.Severity);
         if (hediff_Addiction != null)
         {
             hediff_Addiction.Severity += this.Props.existingAddictionSeverityOffset;
         }
         else if (Rand.Value < this.Props.addictiveness && num >= this.Props.minToleranceToAddict)
         {
             ingester.health.AddHediff(addictionHediffDef, null, null);
             if (PawnUtility.ShouldSendNotificationAbout(ingester))
             {
                 Find.LetterStack.ReceiveLetter("LetterLabelNewlyAddicted".Translate(this.Props.chemical.label).CapitalizeFirst(), "LetterNewlyAddicted".Translate(ingester.LabelShort, this.Props.chemical.label).AdjustedFor(ingester).CapitalizeFirst(), LetterDefOf.NegativeEvent, ingester, null);
             }
             AddictionUtility.CheckDrugAddictionTeachOpportunity(ingester);
         }
         if (addictionHediffDef.causesNeed != null)
         {
             Need need = ingester.needs.AllNeeds.Find((Need x) => x.def == addictionHediffDef.causesNeed);
             if (need != null)
             {
                 float needLevelOffset = this.Props.needLevelOffset;
                 AddictionUtility.ModifyChemicalEffectForToleranceAndBodySize(ingester, this.Props.chemical, ref needLevelOffset);
                 need.CurLevel += needLevelOffset;
             }
         }
         Hediff firstHediffOfDef = ingester.health.hediffSet.GetFirstHediffOfDef(HediffDefOf.DrugOverdose, false);
         float  num2             = (float)((firstHediffOfDef == null) ? 0.0 : firstHediffOfDef.Severity);
         if (num2 < 0.89999997615814209 && Rand.Value < this.Props.largeOverdoseChance)
         {
             float num3 = Rand.Range(0.85f, 0.99f);
             HealthUtility.AdjustSeverity(ingester, HediffDefOf.DrugOverdose, num3 - num2);
             if (ingester.Faction == Faction.OfPlayer)
             {
                 Messages.Message("MessageAccidentalOverdose".Translate(ingester.LabelIndefinite(), base.parent.LabelNoCount).CapitalizeFirst(), MessageTypeDefOf.NegativeHealthEvent);
             }
         }
         else
         {
             float num4 = this.Props.overdoseSeverityOffset.RandomInRange / ingester.BodySize;
             if (num4 > 0.0)
             {
                 HealthUtility.AdjustSeverity(ingester, HediffDefOf.DrugOverdose, num4);
             }
         }
     }
     if (this.Props.isCombatEnhancingDrug && !ingester.Dead)
     {
         ingester.mindState.lastTakeCombatEnhancingDrugTick = Find.TickManager.TicksGame;
     }
     if (ingester.drugs != null)
     {
         ingester.drugs.Notify_DrugIngested(base.parent);
     }
 }
Ejemplo n.º 3
0
        private void CategoryChanged()
        {
            Hediff_Addiction addictionHediff = this.AddictionHediff;

            if (addictionHediff != null)
            {
                addictionHediff.Notify_NeedCategoryChanged();
            }
        }
Ejemplo n.º 4
0
        private Hediff_Addiction FindAddiction(Pawn pawn)
        {
            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 && hediff_Addiction.Visible && hediff_Addiction.def.everCurableByItem)
                {
                    return(hediff_Addiction);
                }
            }
            return(null);
        }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
0
        private Thing FindDrugFor(Pawn pawn, Need_Chemical need)
        {
            Hediff_Addiction addictionHediff = need.AddictionHediff;

            if (addictionHediff == null)
            {
                return(null);
            }
            ThingOwner <Thing> innerContainer = pawn.inventory.innerContainer;

            for (int i = 0; i < innerContainer.Count; i++)
            {
                if (DrugValidator(pawn, addictionHediff, innerContainer[i]))
                {
                    return(innerContainer[i]);
                }
            }
            return(GenClosest.ClosestThingReachable(pawn.Position, pawn.Map, ThingRequest.ForGroup(ThingRequestGroup.Drug), PathEndMode.ClosestTouch, TraverseParms.For(pawn), 9999f, (Thing x) => DrugValidator(pawn, addictionHediff, x)));
        }
        private Thing FindDrugFor(Pawn pawn, Need_Chemical need)
        {
            Hediff_Addiction addictionHediff = need.AddictionHediff;

            if (addictionHediff == null)
            {
                return(null);
            }
            ThingOwner <Thing> innerContainer = pawn.inventory.innerContainer;

            for (int i = 0; i < innerContainer.Count; i++)
            {
                if (this.DrugValidator(pawn, addictionHediff, innerContainer[i]))
                {
                    return(innerContainer[i]);
                }
            }
            return(GenClosest.ClosestThingReachable(pawn.Position, pawn.Map, ThingRequest.ForGroup(ThingRequestGroup.Drug), PathEndMode.ClosestTouch, TraverseParms.For(pawn, Danger.Deadly, TraverseMode.ByPawn, false), 9999f, (Thing x) => this.DrugValidator(pawn, addictionHediff, x), null, 0, -1, false, RegionType.Set_Passable, false));
        }
Ejemplo n.º 8
0
        private static void GiveDrugsIfAddicted(Pawn p)
        {
            if (p.RaceProps.Humanlike)
            {
                IEnumerable <Hediff_Addiction> hediffs = p.health.hediffSet.GetHediffs <Hediff_Addiction>();
                using (IEnumerator <Hediff_Addiction> enumerator = hediffs.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        Hediff_Addiction       addiction = enumerator.Current;
                        IEnumerable <ThingDef> source    = DefDatabase <ThingDef> .AllDefsListForReading.Where(delegate(ThingDef x)
                        {
                            bool result;
                            if (x.category != ThingCategory.Item)
                            {
                                result = false;
                            }
                            else if (p.Faction != null && x.techLevel > p.Faction.def.techLevel)
                            {
                                result = false;
                            }
                            else
                            {
                                CompProperties_Drug compProperties = x.GetCompProperties <CompProperties_Drug>();
                                result = (compProperties != null && compProperties.chemical != null && compProperties.chemical.addictionHediff == addiction.def);
                            }
                            return(result);
                        });

                        ThingDef def;
                        if (source.TryRandomElement(out def))
                        {
                            int   stackCount = Rand.RangeInclusive(2, 5);
                            Thing thing      = ThingMaker.MakeThing(def, null);
                            thing.stackCount = stackCount;
                            p.inventory.TryAddItemNotForSale(thing);
                        }
                    }
                }
            }
        }
Ejemplo n.º 9
0
        public override void DoEffect(Pawn usedBy)
        {
            base.DoEffect(usedBy);
            Hediff hediff = FindLifeThreateningHediff(usedBy);

            if (hediff != null)
            {
                Cure(hediff);
            }
            else
            {
                if (HealthUtility.TicksUntilDeathDueToBloodLoss(usedBy) < 2500)
                {
                    Hediff hediff2 = FindMostBleedingHediff(usedBy);
                    if (hediff2 != null)
                    {
                        Cure(hediff2);
                        return;
                    }
                }
                if (usedBy.health.hediffSet.GetBrain() != null)
                {
                    Hediff_Injury hediff_Injury = FindPermanentInjury(usedBy, Gen.YieldSingle(usedBy.health.hediffSet.GetBrain()));
                    if (hediff_Injury != null)
                    {
                        Cure(hediff_Injury);
                        return;
                    }
                }
                BodyPartRecord bodyPartRecord = FindBiggestMissingBodyPart(usedBy, HandCoverageAbsWithChildren);
                if (bodyPartRecord != null)
                {
                    Cure(bodyPartRecord, usedBy);
                }
                else
                {
                    Hediff_Injury hediff_Injury2 = FindPermanentInjury(usedBy, from x in usedBy.health.hediffSet.GetNotMissingParts()
                                                                       where x.def == BodyPartDefOf.Eye
                                                                       select x);
                    if (hediff_Injury2 != null)
                    {
                        Cure(hediff_Injury2);
                    }
                    else
                    {
                        Hediff hediff3 = FindImmunizableHediffWhichCanKill(usedBy);
                        if (hediff3 != null)
                        {
                            Cure(hediff3);
                        }
                        else
                        {
                            Hediff hediff4 = FindNonInjuryMiscBadHediff(usedBy, onlyIfCanKill: true);
                            if (hediff4 != null)
                            {
                                Cure(hediff4);
                            }
                            else
                            {
                                Hediff hediff5 = FindNonInjuryMiscBadHediff(usedBy, onlyIfCanKill: false);
                                if (hediff5 != null)
                                {
                                    Cure(hediff5);
                                }
                                else
                                {
                                    if (usedBy.health.hediffSet.GetBrain() != null)
                                    {
                                        Hediff_Injury hediff_Injury3 = FindInjury(usedBy, Gen.YieldSingle(usedBy.health.hediffSet.GetBrain()));
                                        if (hediff_Injury3 != null)
                                        {
                                            Cure(hediff_Injury3);
                                            return;
                                        }
                                    }
                                    BodyPartRecord bodyPartRecord2 = FindBiggestMissingBodyPart(usedBy);
                                    if (bodyPartRecord2 != null)
                                    {
                                        Cure(bodyPartRecord2, usedBy);
                                    }
                                    else
                                    {
                                        Hediff_Addiction hediff_Addiction = FindAddiction(usedBy);
                                        if (hediff_Addiction != null)
                                        {
                                            Cure(hediff_Addiction);
                                        }
                                        else
                                        {
                                            Hediff_Injury hediff_Injury4 = FindPermanentInjury(usedBy);
                                            if (hediff_Injury4 != null)
                                            {
                                                Cure(hediff_Injury4);
                                            }
                                            else
                                            {
                                                Hediff_Injury hediff_Injury5 = FindInjury(usedBy);
                                                if (hediff_Injury5 != null)
                                                {
                                                    Cure(hediff_Injury5);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        public override void DoEffect(Pawn usedBy)
        {
            base.DoEffect(usedBy);
            Hediff hediff = this.FindLifeThreateningHediff(usedBy);

            if (hediff != null)
            {
                this.Cure(hediff);
            }
            else
            {
                if (HealthUtility.TicksUntilDeathDueToBloodLoss(usedBy) < 5000)
                {
                    Hediff hediff2 = this.FindMostBleedingHediff(usedBy);
                    if (hediff2 != null)
                    {
                        this.Cure(hediff2);
                        return;
                    }
                }
                Hediff hediff3 = this.FindImmunizableHediffWhichCanKill(usedBy);
                if (hediff3 != null)
                {
                    this.Cure(hediff3);
                }
                else
                {
                    Hediff hediff4 = this.FindCarcinoma(usedBy);
                    if (hediff4 != null)
                    {
                        this.Cure(hediff4);
                    }
                    else
                    {
                        Hediff hediff5 = this.FindNonInjuryMiscBadHediff(usedBy, true);
                        if (hediff5 != null)
                        {
                            this.Cure(hediff5);
                        }
                        else
                        {
                            Hediff hediff6 = this.FindNonInjuryMiscBadHediff(usedBy, false);
                            if (hediff6 != null)
                            {
                                this.Cure(hediff6);
                            }
                            else
                            {
                                BodyPartRecord bodyPartRecord = this.FindBiggestMissingBodyPart(usedBy, 0.01f);
                                if (bodyPartRecord != null)
                                {
                                    this.Cure(bodyPartRecord, usedBy);
                                }
                                else
                                {
                                    Hediff_Injury hediff_Injury = this.FindInjury(usedBy, usedBy.health.hediffSet.GetBrain());
                                    if (hediff_Injury != null)
                                    {
                                        this.Cure(hediff_Injury);
                                    }
                                    else
                                    {
                                        BodyPartRecord bodyPartRecord2 = this.FindBiggestMissingBodyPart(usedBy, 0f);
                                        if (bodyPartRecord2 != null)
                                        {
                                            this.Cure(bodyPartRecord2, usedBy);
                                        }
                                        else
                                        {
                                            Hediff_Addiction hediff_Addiction = this.FindAddiction(usedBy);
                                            if (hediff_Addiction != null)
                                            {
                                                this.Cure(hediff_Addiction);
                                            }
                                            else
                                            {
                                                Hediff_Injury hediff_Injury2 = this.FindOldInjury(usedBy);
                                                if (hediff_Injury2 != null)
                                                {
                                                    this.Cure(hediff_Injury2);
                                                }
                                                else
                                                {
                                                    Hediff_Injury hediff_Injury3 = this.FindInjury(usedBy, null);
                                                    if (hediff_Injury3 != null)
                                                    {
                                                        this.Cure(hediff_Injury3);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }