Beispiel #1
0
        public static void GiveVitaeEffects(Pawn receiver, Pawn donor)
        {
            var pawn = receiver;

            //Give Vitae High Effect
            Hediff vitaeHighHediff = HediffMaker.MakeHediff(VampDefOf.ROMV_VitaeHigh, pawn, null);
            float  numHigh         = 0.75f;

            AddictionUtility.ModifyChemicalEffectForToleranceAndBodySize(pawn, VampDefOf.ROMV_VitaeChemical, ref numHigh);
            vitaeHighHediff.Severity = numHigh;
            pawn.health.AddHediff(vitaeHighHediff, null, null);

            //Give Vitae Tolerance Effect
            Hediff vitaeToleranceHediff = HediffMaker.MakeHediff(VampDefOf.ROMV_VitaeTolerance, pawn, null);
            float  numTol = 0.035f;

            numTol /= receiver.BodySize;
            AddictionUtility.ModifyChemicalEffectForToleranceAndBodySize(pawn, VampDefOf.ROMV_VitaeChemical, ref numTol);
            vitaeToleranceHediff.Severity = numTol;
            pawn.health.AddHediff(vitaeToleranceHediff, null, null);

            const float addictiveness                   = 1.0f;
            const float minToleranceToAddict            = 0.01f;
            const float existingAddictionSeverityOffset = 0.2f;

            var needLevelOffset        = 1f;
            var overdoseSeverityOffset = new FloatRange(0.18f, 0.35f);
            var chemical = VampDefOf.ROMV_VitaeChemical;

            var addictionHediffDef = VampDefOf.ROMV_VitaeAddiction;
            var lookTarget         = receiver;
            var hediff             = AddictionUtility.FindToleranceHediff(lookTarget, VampDefOf.ROMV_VitaeChemical);
            var num             = hediff?.Severity ?? 0f;
            var hediffAddiction = AddictionUtility.FindAddictionHediff(lookTarget, VampDefOf.ROMV_VitaeChemical);

            if (hediffAddiction != null)
            {
                hediffAddiction.Severity += existingAddictionSeverityOffset;
            }
            else if (Rand.Value < addictiveness && num >= minToleranceToAddict)
            {
                lookTarget.health.AddHediff(addictionHediffDef, null, null);
                if (PawnUtility.ShouldSendNotificationAbout(lookTarget))
                {
                    Find.LetterStack.ReceiveLetter("LetterLabelNewlyAddicted".Translate(chemical.label).CapitalizeFirst(),
                                                   "LetterNewlyAddicted".Translate(lookTarget.LabelShort, chemical.label, lookTarget.Named("PAWN"))
                                                   .AdjustedFor(lookTarget, "PAWN").CapitalizeFirst(), LetterDefOf.NegativeEvent, lookTarget, null, null);
                }
                AddictionUtility.CheckDrugAddictionTeachOpportunity(lookTarget);
            }

            if (addictionHediffDef.causesNeed != null)
            {
                var need = lookTarget.needs.AllNeeds.Find((Need x) => x.def == addictionHediffDef.causesNeed);
                if (need != null)
                {
                    AddictionUtility.ModifyChemicalEffectForToleranceAndBodySize(lookTarget, chemical,
                                                                                 ref needLevelOffset);
                    need.CurLevel += needLevelOffset;
                }
            }
//            var firstHediffOfDef = lookTarget.health.hediffSet.GetFirstHediffOfDef(HediffDefOf.DrugOverdose, false);
//            var num2 = firstHediffOfDef?.Severity ?? 0f;
//            if (num2 < 0.9f && Rand.Value < largeOverdoseChance)
//            {
//                var num3 = Rand.Range(0.85f, 0.99f);
//                HealthUtility.AdjustSeverity(lookTarget, HediffDefOf.DrugOverdose, num3 - num2);
//                if (lookTarget.Faction == Faction.OfPlayer)
//                {
//                    Messages.Message("MessageAccidentalOverdose".Translate(new object[]
//                    {
//                        lookTarget.LabelIndefinite(),
//                        chemical.LabelCap
//                    }).CapitalizeFirst(), MessageTypeDefOf.NegativeHealthEvent);
//                }
//            }
//            else
//            {
//                var num4 = overdoseSeverityOffset.RandomInRange / lookTarget.BodySize;
//                if (num4 > 0f)
//                {
//                    HealthUtility.AdjustSeverity(lookTarget, HediffDefOf.DrugOverdose, num4);
//                }
//            }
        }
Beispiel #2
0
        public static void SetFaction(this Pawn pawn, Faction newFaction, Pawn recruiter = null)
        {
            if (newFaction == pawn.Faction)
            {
                Log.Warning(string.Concat(new object[]
                {
                    "Used ChangePawnFactionTo to change ",
                    pawn,
                    " to same faction ",
                    newFaction
                }));
                return;
            }
            if (pawn.guest != null)
            {
                pawn.guest.SetGuestStatus(null, false);
            }
            if (pawn.Spawned)
            {
                pawn.Map.mapPawns.DeRegisterPawn(pawn);
                pawn.Map.pawnDestinationManager.RemovePawnFromSystem(pawn);
                pawn.Map.designationManager.RemoveAllDesignationsOn(pawn, false);
            }
            if (newFaction == Faction.OfPlayer || pawn.Faction == Faction.OfPlayer)
            {
                Find.ColonistBar.MarkColonistsDirty();
            }
            Lord lord = pawn.GetLord();

            if (lord != null)
            {
                lord.Notify_PawnLost(pawn, PawnLostCondition.ChangedFaction);
            }
            if (pawn.Faction != null && pawn.Faction.leader == pawn)
            {
                pawn.Faction.Notify_LeaderLost();
            }
            if (newFaction == Faction.OfPlayer && pawn.RaceProps.Humanlike)
            {
                pawn.kindDef = newFaction.def.basicMemberKind;
            }

            // Call base SetFaction directly - horrible mojo warning
            MethodInfo method = typeof(Thing).GetMethod("SetFaction", BindingFlags.Public | BindingFlags.Instance);
            IntPtr     fptr   = method.MethodHandle.GetFunctionPointer();

            ((Action <Faction, Pawn>)Activator.CreateInstance(typeof(Action <Faction, Pawn>), pawn, fptr))(newFaction, null);

            PawnComponentsUtility.AddAndRemoveDynamicComponents(pawn, false);
            if (pawn.Faction != null && pawn.Faction.IsPlayer)
            {
                if (pawn.workSettings != null)
                {
                    pawn.workSettings.EnableAndInitialize();
                }
                Find.Storyteller.intenderPopulation.Notify_PopulationGained();
            }
            if (pawn.Drafted)
            {
                pawn.drafter.Drafted = false;
            }
            ReachabilityUtility.ClearCache();
            pawn.health.surgeryBills.Clear();
            if (pawn.Spawned)
            {
                pawn.Map.mapPawns.RegisterPawn(pawn);
            }
            pawn.GenerateNecessaryName();
            if (pawn.playerSettings != null)
            {
                Pawn_PlayerSettings_Detour.ResetPPSMedicalCare(pawn.playerSettings, pawn);
            }
            pawn.ClearMind(true);
            if (!pawn.Dead && pawn.needs.mood != null)
            {
                pawn.needs.mood.thoughts.situational.Notify_SituationalThoughtsDirty();
            }
            if (pawn.Spawned)
            {
                pawn.Map.attackTargetsCache.UpdateTarget(pawn);
            }
            Find.GameEnder.CheckGameOver();
            AddictionUtility.CheckDrugAddictionTeachOpportunity(pawn);
            if (pawn.needs != null)
            {
                pawn.needs.AddOrRemoveNeedsAsAppropriate();
            }
            if (pawn.playerSettings != null)
            {
                pawn.playerSettings.Notify_FactionChanged();
            }
        }