Example #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;
                }
            }
        }
Example #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);
     }
 }
Example #3
0
 public void SetGuestStatus(Faction newHost, bool prisoner = false)
 {
     if (newHost != null)
     {
         Released = false;
     }
     if (newHost != HostFaction || prisoner != IsPrisoner)
     {
         if (!prisoner && pawn.Faction.HostileTo(newHost))
         {
             Log.Error("Tried to make " + pawn + " a guest of " + newHost + " but their faction " + pawn.Faction + " is hostile to " + newHost);
         }
         else if (newHost != null && newHost == pawn.Faction && !prisoner)
         {
             Log.Error("Tried to make " + pawn + " a guest of their own faction " + pawn.Faction);
         }
         else
         {
             bool flag = prisoner && (!IsPrisoner || HostFaction != newHost);
             isPrisonerInt  = prisoner;
             hostFactionInt = newHost;
             pawn.ClearMind();
             if (flag)
             {
                 pawn.DropAndForbidEverything();
                 pawn.GetLord()?.Notify_PawnLost(pawn, PawnLostCondition.MadePrisoner);
                 if (newHost == Faction.OfPlayer)
                 {
                     Find.StoryWatcher.watcherPopAdaptation.Notify_PawnEvent(pawn, PopAdaptationEvent.GainedPrisoner);
                 }
                 if (pawn.Drafted)
                 {
                     pawn.drafter.Drafted = false;
                 }
                 float x = pawn.RecruitDifficulty(Faction.OfPlayer);
                 resistance  = StartingResistancePerRecruitDifficultyCurve.Evaluate(x);
                 resistance *= StartingResistanceFactorFromPopulationIntentCurve.Evaluate(StorytellerUtilityPopulation.PopulationIntent);
                 resistance *= StartingResistanceRandomFactorRange.RandomInRange;
                 resistance  = (float)GenMath.RoundRandom(resistance);
             }
             PawnComponentsUtility.AddAndRemoveDynamicComponents(pawn);
             pawn.health.surgeryBills.Clear();
             if (pawn.ownership != null)
             {
                 pawn.ownership.Notify_ChangedGuestStatus();
             }
             ReachabilityUtility.ClearCacheFor(pawn);
             if (pawn.Spawned)
             {
                 pawn.Map.mapPawns.UpdateRegistryForPawn(pawn);
                 pawn.Map.attackTargetsCache.UpdateTarget(pawn);
             }
             AddictionUtility.CheckDrugAddictionTeachOpportunity(pawn);
             if (prisoner && pawn.playerSettings != null)
             {
                 pawn.playerSettings.Notify_MadePrisoner();
             }
         }
     }
 }
 public void SetGuestStatus(Faction newHost, bool prisoner = false)
 {
     if (newHost != null)
     {
         this.Released = false;
     }
     if (newHost == this.HostFaction && prisoner == this.IsPrisoner)
     {
         return;
     }
     if (!prisoner && this.pawn.Faction.HostileTo(newHost))
     {
         Log.Error("Tried to make " + this.pawn + " a guest of " + newHost + " but their faction " + this.pawn.Faction + " is hostile to " + newHost);
     }
     else if (newHost != null && newHost == this.pawn.Faction && !prisoner)
     {
         Log.Error("Tried to make " + this.pawn + " a guest of their own faction " + this.pawn.Faction);
     }
     else
     {
         bool flag = prisoner && (!this.IsPrisoner || this.HostFaction != newHost);
         this.isPrisonerInt  = prisoner;
         this.hostFactionInt = newHost;
         this.pawn.ClearMind(false);
         if (flag)
         {
             this.pawn.DropAndForbidEverything(false);
             Lord lord = this.pawn.GetLord();
             if (lord != null)
             {
                 lord.Notify_PawnLost(this.pawn, PawnLostCondition.MadePrisoner);
             }
             if (this.pawn.Drafted)
             {
                 this.pawn.drafter.Drafted = false;
             }
         }
         PawnComponentsUtility.AddAndRemoveDynamicComponents(this.pawn, false);
         this.pawn.health.surgeryBills.Clear();
         if (this.pawn.ownership != null)
         {
             this.pawn.ownership.Notify_ChangedGuestStatus();
         }
         ReachabilityUtility.ClearCache();
         if (this.pawn.Spawned)
         {
             this.pawn.Map.mapPawns.UpdateRegistryForPawn(this.pawn);
             this.pawn.Map.attackTargetsCache.UpdateTarget(this.pawn);
         }
         AddictionUtility.CheckDrugAddictionTeachOpportunity(this.pawn);
         if (prisoner && this.pawn.playerSettings != null)
         {
             this.pawn.playerSettings.Notify_MadePrisoner();
         }
     }
 }
        public void SetGuestStatus(Faction newHost, bool prisoner = false)
        {
            if (newHost != null)
            {
                this.Released = false;
            }
            if (newHost == this.HostFaction && prisoner == this.IsPrisoner)
            {
                return;
            }
            if (!prisoner && this.pawn.Faction.HostileTo(newHost))
            {
                Log.Error(string.Concat(new object[]
                {
                    "Tried to make ",
                    this.pawn,
                    " a guest of ",
                    newHost,
                    " but their faction ",
                    this.pawn.Faction,
                    " is hostile to ",
                    newHost
                }), false);
                return;
            }
            if (newHost != null && newHost == this.pawn.Faction && !prisoner)
            {
                Log.Error(string.Concat(new object[]
                {
                    "Tried to make ",
                    this.pawn,
                    " a guest of their own faction ",
                    this.pawn.Faction
                }), false);
                return;
            }
            bool flag = prisoner && (!this.IsPrisoner || this.HostFaction != newHost);

            this.isPrisonerInt  = prisoner;
            this.hostFactionInt = newHost;
            this.pawn.ClearMind(false);
            if (flag)
            {
                this.pawn.DropAndForbidEverything(false);
                Lord lord = this.pawn.GetLord();
                if (lord != null)
                {
                    lord.Notify_PawnLost(this.pawn, PawnLostCondition.MadePrisoner, null);
                }
                if (newHost == Faction.OfPlayer)
                {
                    Find.StoryWatcher.watcherPopAdaptation.Notify_PawnEvent(this.pawn, PopAdaptationEvent.GainedPrisoner);
                }
                if (this.pawn.Drafted)
                {
                    this.pawn.drafter.Drafted = false;
                }
                float x = this.pawn.RecruitDifficulty(Faction.OfPlayer);
                this.resistance  = Pawn_GuestTracker.StartingResistancePerRecruitDifficultyCurve.Evaluate(x);
                this.resistance *= Pawn_GuestTracker.StartingResistanceFactorFromPopulationIntentCurve.Evaluate(StorytellerUtilityPopulation.PopulationIntent);
                this.resistance *= Pawn_GuestTracker.StartingResistanceRandomFactorRange.RandomInRange;
                this.resistance  = (float)GenMath.RoundRandom(this.resistance);
            }
            PawnComponentsUtility.AddAndRemoveDynamicComponents(this.pawn, false);
            this.pawn.health.surgeryBills.Clear();
            if (this.pawn.ownership != null)
            {
                this.pawn.ownership.Notify_ChangedGuestStatus();
            }
            ReachabilityUtility.ClearCacheFor(this.pawn);
            if (this.pawn.Spawned)
            {
                this.pawn.Map.mapPawns.UpdateRegistryForPawn(this.pawn);
                this.pawn.Map.attackTargetsCache.UpdateTarget(this.pawn);
            }
            AddictionUtility.CheckDrugAddictionTeachOpportunity(this.pawn);
            if (prisoner && this.pawn.playerSettings != null)
            {
                this.pawn.playerSettings.Notify_MadePrisoner();
            }
        }
Example #6
0
        public void SetGuestStatus(Faction newHost, bool prisoner = false)
        {
            if (newHost != null)
            {
                Released = false;
            }
            if (newHost == HostFaction && prisoner == IsPrisoner)
            {
                return;
            }
            if (!prisoner && pawn.Faction.HostileTo(newHost))
            {
                Log.Error("Tried to make " + pawn + " a guest of " + newHost + " but their faction " + pawn.Faction + " is hostile to " + newHost);
                return;
            }
            if (newHost != null && newHost == pawn.Faction && !prisoner)
            {
                Log.Error("Tried to make " + pawn + " a guest of their own faction " + pawn.Faction);
                return;
            }
            bool num = prisoner && (!IsPrisoner || HostFaction != newHost);

            isPrisonerInt = prisoner;
            Faction faction = hostFactionInt;

            hostFactionInt = newHost;
            Pawn obj = pawn;
            bool clearMentalState = prisoner;

            obj.ClearMind(newHost != null, clearInspiration: false, clearMentalState);
            if (num)
            {
                pawn.DropAndForbidEverything();
                pawn.GetLord()?.Notify_PawnLost(pawn, PawnLostCondition.MadePrisoner);
                if (pawn.Drafted)
                {
                    pawn.drafter.Drafted = false;
                }
                float x = pawn.RecruitDifficulty(Faction.OfPlayer);
                resistance  = StartingResistancePerRecruitDifficultyCurve.Evaluate(x);
                resistance *= StartingResistanceFactorFromPopulationIntentCurve.Evaluate(StorytellerUtilityPopulation.PopulationIntent);
                resistance *= StartingResistanceRandomFactorRange.RandomInRange;
                if (pawn.royalty != null)
                {
                    RoyalTitle mostSeniorTitle = pawn.royalty.MostSeniorTitle;
                    if (mostSeniorTitle != null)
                    {
                        resistance *= mostSeniorTitle.def.recruitmentResistanceFactor;
                        resistance += mostSeniorTitle.def.recruitmentResistanceOffset;
                    }
                }
                resistance = GenMath.RoundRandom(resistance);
            }
            PawnComponentsUtility.AddAndRemoveDynamicComponents(pawn);
            pawn.health.surgeryBills.Clear();
            if (pawn.ownership != null)
            {
                pawn.ownership.Notify_ChangedGuestStatus();
            }
            ReachabilityUtility.ClearCacheFor(pawn);
            if (pawn.Spawned)
            {
                pawn.Map.mapPawns.UpdateRegistryForPawn(pawn);
                pawn.Map.attackTargetsCache.UpdateTarget(pawn);
            }
            AddictionUtility.CheckDrugAddictionTeachOpportunity(pawn);
            if (prisoner && pawn.playerSettings != null)
            {
                pawn.playerSettings.Notify_MadePrisoner();
            }
            if (faction != hostFactionInt)
            {
                QuestUtility.SendQuestTargetSignals(pawn.questTags, "ChangedHostFaction", pawn.Named("SUBJECT"), hostFactionInt.Named("FACTION"));
            }
        }