Exemple #1
0
 /// <summary>
 /// Creates the new thought from the original pawn to transfer to the target pawn.
 /// </summary>
 /// <param name="original">The original.</param>
 /// <param name="target">The target.</param>
 /// <param name="originalThought">The original thought.</param>
 /// <returns></returns>
 public Thought_Memory CreateNewThought(Pawn original, Pawn target, Thought_Memory originalThought)
 {
     if (original == null)
     {
         throw new ArgumentNullException(nameof(original));
     }
     if (target == null)
     {
         throw new ArgumentNullException(nameof(target));
     }
     if (originalThought == null)
     {
         throw new ArgumentNullException(nameof(originalThought));
     }
     try
     {
         var harmonizerThought    = (Thought_PsychicHarmonizer)originalThought;
         var newHarmonizerThought =
             (Thought_PsychicHarmonizer)ThoughtMaker.MakeThought(originalThought.def, originalThought.CurStageIndex);
         newHarmonizerThought.harmonizer = harmonizerThought.harmonizer;
         return(newHarmonizerThought);
     }
     catch (System.Exception e)
     {
         Log.Error($"unable to transfer thought {original?.def?.label} onto {target?.Label}! caught {e.GetType().Name}!");
         throw;
     }
 }
Exemple #2
0
        /// <summary>
        /// add the correct reversion thought at the correct stage
        /// </summary>
        /// <param name="spawned">The spawned.</param>
        private void AddReversionThought(Pawn spawned)
        {
            TraitSet   traits = spawned.story.traits;
            ThoughtDef thoughtDef;
            var        hasPrimalWish = spawned.GetAspectTracker()?.Contains(AspectDefOf.PrimalWish) == true;

            if (hasPrimalWish)
            {
                thoughtDef = def.revertedPrimalWish ?? def.revertedThoughtBad; //substitute with the bad thought if null
            }
            else if (traits.HasTrait(PMTraitDefOf.MutationAffinity))
            {
                thoughtDef = def.revertedThoughtGood;
            }
            else if (traits.HasTrait(TraitDefOf.BodyPurist))
            {
                thoughtDef = def.revertedThoughtBad;
            }
            else
            {
                thoughtDef = Rand.Value > 0.5f ? def.revertedThoughtGood : def.revertedThoughtBad;
            }

            if (thoughtDef != null)
            {
                //TODO fix this with special memory for animalistic pawns
                Thought_Memory mem = ThoughtMaker.MakeThought(thoughtDef, 0);
                spawned.TryGainMemory(mem);
            }
        }
 public static void Postfix(ref Thought_Memory __result, Corpse __instance)
 {
     if (__result != null && PeacekeeperUtility.IsPeacekeeper(__instance.InnerPawn))
     {
         __result = null;
     }
 }
Exemple #4
0
        public static void Postfix(ref Thought_Memory newThought, ref Pawn otherPawn)
        {
            Pawn       pawn             = newThought.pawn;
            ThoughtDef knowColonistDied = ThoughtDefOf.KnowColonistDied;
            ThoughtDef thoughtToGet     = SS_ThoughtDefOf.KnowSlaveDied;

            if (newThought.def == knowColonistDied)
            {
                // Remove colonist death thoughts
                if (SlaveUtility.IsPawnColonySlave(otherPawn) || (SlaveUtility.IsPawnColonySlave(pawn) && !SlaveUtility.IsPawnColonySlave(otherPawn)))
                {
                    pawn.needs.mood.thoughts.memories.RemoveMemoriesOfDefWhereOtherPawnIs(knowColonistDied, otherPawn);
                }
                // Add slave death thoughts
                if (SlaveUtility.IsPawnColonySlave(otherPawn) && pawn.MapHeld == otherPawn.MapHeld)
                {
                    //string thoughtToGet = "KnowSlaveDied";
                    if (SlaveUtility.IsPawnColonySlave(pawn))
                    {
                        thoughtToGet = SS_ThoughtDefOf.KnowFellowSlaveDied;
                    }
                    pawn.needs.mood.thoughts.memories.TryGainMemory(thoughtToGet, otherPawn);
                }
            }
        }
Exemple #5
0
 public static void NotifyPawnGotThought(Pawn pawn, Thought_Memory thought, Pawn otherPawn)
 {
     if (thought.def == ThoughtDefOf.KnowGuestExecuted)
     {
         AddPoints(pawn, PointsTable.FactionExecutedPrisoner, "BadPeople_Log_FactionExecutedPrisoner".Translate());
     }
     else if (thought.def == ThoughtDefOf.KnowColonistDied)
     {
         AddPoints(pawn, PointsTable.WitnessedColonistDeath, "BadPeople_Log_WitnessedColonistDeath".Translate());
     }
     else if (thought.def == ThoughtDefOf.RescuedMe)
     {
         if (pawn.Faction != otherPawn.Faction && !pawn.Faction.HostileTo(otherPawn.Faction))
         {
             AddPoints(otherPawn, PointsTable.RescuedNonColonist, "BadPeople_Log_RescuedNonColonist".Translate());
         }
     }
     else if (thought.def == ThoughtDefOf.MyOrganHarvested)
     {
         AddPoints(pawn, PointsTable.MyOrganHarvested, "BadPeople_Log_MyOrganHarvested".Translate());
     }
     else if (thought.def == ThoughtDefOf.ButcheredHumanlikeCorpse)
     {
         AddPoints(pawn, PointsTable.HumanlikeButchered, "BadPeople_Log_ButcheredHumanlike".Translate());
     }
     else if (thought.def == ThoughtDefOf.KnowButcheredHumanlikeCorpse)
     {
         AddPoints(pawn, PointsTable.KnownHumanlikeButchered, "BadPeople_Log_ButcheredKnownHumanlike".Translate());
     }
 }
            private static bool TryGainMemoryPrefix([NotNull] ref Thought_Memory newThought, Pawn otherPawn,
                                                    [NotNull] MemoryThoughtHandler __instance)
            {
                newThought = newThought.GetSubstitute(__instance.pawn);

                return(true);
            }
        public override void ApplyOnPawn(Pawn pawn, BodyPartRecord part, Pawn billDoer, List <Thing> ingredients)
        {
            if (!CheckTreatmentFail(billDoer, pawn))
            {
                TaleRecorder.RecordTale(taleDef, new object[]
                {
                    billDoer,
                    pawn
                });
                if (PawnUtility.ShouldSendNotificationAbout(pawn) || PawnUtility.ShouldSendNotificationAbout(billDoer))
                {
                    Messages.Message("TreatedTrait".Translate(new object[] { pawn.LabelShort, traitName }), pawn, MessageSound.Benefit);
                }
                Hediff recover = HediffMaker.MakeHediff(hediffDef, pawn, pawn.health.hediffSet.GetBrain());
                recover.Tended(1f);
                pawn.health.AddHediff(recover);
                return;
            }
            ThoughtDef failure = ThoughtDefOfPsychology.TreatmentFailed;

            pawn.needs.mood.thoughts.memories.TryGainMemory(failure);
            Thought_Memory failureThought = (from memory in pawn.needs.mood.thoughts.memories.Memories
                                             where memory.def.workerClass.Name == "Thought_TreatmentFailed"
                                             orderby memory.age ascending
                                             select memory).LastOrDefault();

            if (failureThought != null)
            {
                (failureThought as Thought_TreatmentFailed).traitName = this.traitName;
            }
        }
Exemple #8
0
 private static bool Prefix(MemoryThoughtHandler __instance, ref Thought_Memory newThought, Pawn otherPawn)
 {
     if (__instance.pawn.HasTrait(VTEDefOf.VTE_AnimalHater) && animalThoughtDefs.Contains(newThought.def))
     {
         newThought = (Thought_Memory)ThoughtMaker.MakeThought(inverseAnimalThoughDefs[newThought.def]);
     }
     if (__instance.pawn.HasTrait(VTEDefOf.VTE_Squeamish) && newThought.def == VTEDefOf.ObservedLayingRottingCorpse)
     {
         var comp = Current.Game.GetComponent <TraitsManager>();
         if ((!comp.squeamishWithLastVomitedTick.ContainsKey(__instance.pawn) || GenTicks.TicksAbs >= comp.squeamishWithLastVomitedTick[__instance.pawn] + (30 * 60)) && Rand.Chance(0.5f))
         {
             Job vomit = JobMaker.MakeJob(JobDefOf.Vomit);
             __instance.pawn.jobs.TryTakeOrderedJob(vomit);
             comp.squeamishWithLastVomitedTick[__instance.pawn] = GenTicks.TicksAbs;
         }
     }
     if (__instance.pawn.HasTrait(VTEDefOf.VTE_Desensitized) && horribleThoughts.Contains(newThought.def.defName))
     {
         return(false);
     }
     if (__instance.pawn.HasTrait(VTEDefOf.VTE_ColdInclined) &&
         (newThought.CurStageIndex < 1 && newThought.def == ThoughtDef.Named("EnvironmentCold") ||
          newThought.def == ThoughtDefOf.SleptInCold))
     {
         return(false);
     }
     if (__instance.pawn.HasTrait(VTEDefOf.VTE_HeatInclined) &&
         (newThought.CurStageIndex < 1 && newThought.def == ThoughtDef.Named("EnvironmentHot") ||
          newThought.def == ThoughtDefOf.SleptInHeat))
     {
         return(false);
     }
     if (__instance.pawn.HasTrait(VTEDefOf.VTE_ChildOfMountain) && newThought.def == ThoughtDef.Named("EnvironmentDark"))
     {
         return(false);
     }
     if (__instance.pawn.HasTrait(VTEDefOf.VTE_ChildOfSea) && newThought.def == ThoughtDef.Named("SoakingWet"))
     {
         __instance.pawn.TryGiveThought(VTEDefOf.VTE_SoakingWetChildOfTheSea);
         return(false);
     }
     if (__instance.pawn.HasTrait(VTEDefOf.VTE_HeavySleeper) && newThought.def == ThoughtDefOf.SleepDisturbed)
     {
         return(false);
     }
     if (__instance.pawn.HasTrait(VTEDefOf.VTE_MadSurgeon) &&
         (newThought.def == ThoughtDefOf.KnowColonistOrganHarvested ||
          newThought.def == ThoughtDefOf.KnowGuestOrganHarvested ||
          newThought.def == ThoughtDefOf.ButcheredHumanlikeCorpse ||
          newThought.def == ThoughtDefOf.KnowButcheredHumanlikeCorpse ||
          newThought.def == VTEDefOf.ObservedLayingCorpse ||
          newThought.def == VTEDefOf.ObservedLayingRottingCorpse ||
          newThought.def == ThoughtDefOf.KnowPrisonerDiedInnocent ||
          newThought.def == ThoughtDefOf.KnowColonistExecuted && newThought.CurStageIndex == 3
         ))
     {
         return(false);
     }
     return(true);
 }
        private void ApplyOutcome(LordToil_Disco toil)
        {
            List <Pawn>        ownedPawns = this.lord.ownedPawns;
            LordToilData_Disco data       = (LordToilData_Disco)toil.data;
            int given = 0;

            for (int index = 0; index < ownedPawns.Count; ++index)
            {
                Pawn key  = ownedPawns[index];
                bool flag = key == organizer;
                if (data.wasPresent.Contains(key))
                {
                    if (ownedPawns[index].needs.mood != null)
                    {
                        ThoughtDef     def        = flag ? OrganizerThought : AttendeeThought;
                        Thought_Memory newThought = (Thought_Memory)ThoughtMaker.MakeThought(def);
                        newThought.moodPowerFactor = 1;
                        ownedPawns[index].needs.mood.thoughts.memories.TryGainMemory(newThought);
                        given++;
                    }
                    TaleRecorder.RecordTale(flag ? OrganizerTale : AttendeeTale, ownedPawns[index], organizer);
                }
            }

            Core.Log($"Gave positive vibes to {given} pawns.");
        }
        /// <summary>
        ///     add the correct reversion thought at the correct stage
        /// </summary>
        /// <param name="spawned"></param>
        /// <param name="curStageIndex"></param>
        private void AddReversionThought(Pawn spawned, int curStageIndex)
        {
            TraitSet   traits = spawned.story.traits;
            ThoughtDef thoughtDef;
            var        hasPrimalWish = spawned.GetAspectTracker()?.Contains(AspectDefOf.PrimalWish) == true;

            if (hasPrimalWish)
            {
                thoughtDef = def.revertedPrimalWish ?? def.revertedThoughtBad; //substitute with the bad thought if null
            }
            else if (traits.HasTrait(PMTraitDefOf.MutationAffinity))
            {
                thoughtDef = def.revertedThoughtGood;
            }
            else if (traits.HasTrait(TraitDefOf.BodyPurist))
            {
                thoughtDef = def.revertedThoughtBad;
            }
            else
            {
                thoughtDef = Rand.Value > 0.5f ? def.revertedThoughtGood : def.revertedThoughtBad;
            }

            if (thoughtDef != null)
            {
                curStageIndex = Mathf.Min(curStageIndex, thoughtDef.stages.Count - 1); //avoid index out of bounds issues
                Thought_Memory mem = ThoughtMaker.MakeThought(thoughtDef, curStageIndex);
                spawned.TryGainMemory(mem);
            }
        }
Exemple #11
0
        public static void ThoughtWithStage(Pawn pawn, ThoughtDef thought, int stage)
        {
            Thought_Memory thought1 = (Thought_Memory)ThoughtMaker.MakeThought(thought);

            pawn.needs.mood.thoughts.memories.TryGainMemory(thought1, null);
            pawn.needs.mood.thoughts.memories.OldestMemoryOfDef(thought).SetForcedStage(stage);
        }
Exemple #12
0
        public static Thought_Memory GetSubstitute([NotNull] this Thought_Memory memory, [NotNull] Pawn pawn)
        {
            IEnumerable <ThoughtGroupDefExtension>
            tGroups = memory.def.modExtensions.MakeSafe().OfType <ThoughtGroupDefExtension>();

            foreach (ThoughtDef thoughtDef in tGroups.SelectMany(g => g.thoughts))
            {
                if (ThoughtUtility.CanGetThought(pawn, thoughtDef))
                {
                    int forcedStage = Mathf.Min(memory.CurStageIndex, thoughtDef.stages.Count - 1);

                    if (forcedStage != memory.CurStageIndex)
                    {
                        Log.Warning($"in memory {memory.def.defName}, substituted thought {thoughtDef.defName} does not the same number of stages\noriginal:{memory.def.stages.Count} sub:{thoughtDef.stages.Count}");
                    }

                    Thought_Memory newMemory = ThoughtMaker.MakeThought(thoughtDef, forcedStage);
                    if (newMemory == null)
                    {
                        Log.Error($"in thought {memory.def.defName} group, thought {thoughtDef.defName} is not a memory");
                        continue;
                    }

                    return(newMemory);
                }
            }

            return(memory);
        }
        private void AddNuzzledThought(Pawn initiator, Pawn recipient)
        {
            Thought_Memory newThought = (Thought_Memory)ThoughtMaker.MakeThought(ThoughtDef.Named("AA_BeenPsionicallyNuzzled"));

            recipient.needs.mood.thoughts.memories.TryGainMemory(newThought, null);
            recipient.health.AddHediff(HediffDef.Named("AA_PsionicallyNuzzled"));
        }
Exemple #14
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="initiator"></param>
        /// <param name="recipient"></param>
        /// <returns></returns>
        public override float RandomSelectionWeight(Pawn initiator, Pawn recipient)
        {
            if (!AttractionUtility.QuickCheck(initiator, recipient))
            {
                return(0f);
            }
            EmptyReasons();
            recipientPhysicalAttraction = CalculateAndSort(AttractionFactorCategoryDefOf.Physical, initiator, recipient);
            recipientRomanticAttraction = CalculateAndSort(AttractionFactorCategoryDefOf.Romantic, initiator, recipient);
            recipientSocialAttraction   = CalculateAndSort(AttractionFactorCategoryDefOf.Social, initiator, recipient);
            initiatorCircumstances      = CalculateAndSort(AttractionFactorCategoryDefOf.Circumstance, initiator, recipient);
            //if (intiatorFailureReasons.Count() > 0)
            //{
            //    EmptyReasons();
            //    return 0f;
            //}
            float romanceChance = recipientPhysicalAttraction * recipientRomanticAttraction * recipientRomanticAttraction * initiatorCircumstances;
            float flirtFactor   = 0.5f;

            List <Thought_Memory> memoryList = initiator.needs.mood.thoughts.memories.Memories;

            for (int i = 0; i < memoryList.Count; i++)
            {
                Thought_Memory curMemory = memoryList[i];
                if (curMemory.def == ThoughtDefOfGR.RomanticDisinterest && curMemory.otherPawn == recipient)
                {
                    flirtFactor = flirtFactor * BadFlirtPenalty;
                }
            }
            flirtFactor   = Mathf.Max(flirtFactor, 0.05f);
            lastInitiator = initiator;
            lastRecipient = recipient;
            return(GradualRomanceMod.BaseFlirtChance * romanceChance * flirtFactor * BaseFlirtWeight);
        }
        protected override IEnumerable <Toil> MakeNewToils()
        {
            // TargetIndex.A is the window glower
            // TargetIndex.B is the window

            Building_Window window = TargetB.Thing as Building_Window;

            // Set fail conditions
            this.FailOnDespawnedOrNull(TargetIndex.A);
            this.FailOnDestroyedOrNull(TargetIndex.B);

            // Reserve the window glower
            yield return(Toils_Reserve.Reserve(TargetIndex.A));

            // Go to the window
            yield return(Toils_Goto.GotoCell(TargetIndex.A, PathEndMode.OnCell));

            // Look out the window
            Toil       low     = new Toil();
            JoyKindDef joyKind = LocalDefOf.WIN_LookOutWindow.joyKind;

            low.socialMode = RandomSocialMode.Normal;
            low.initAction = () => {
                low.handlingFacing = true;
            };
            low.tickAction = () => {
                base.WatchTickAction();
                pawn.needs.joy.GainJoy(Mathf.Max(window.WindowViewBeauty, 0.1f) * 0.000576f, joyKind);
                pawn.rotationTracker.FaceCell(TargetB.Cell);
            };
            low.defaultCompleteMode = ToilCompleteMode.Delay;
            low.defaultDuration     = job.def.joyDuration;
            low.AddFinishAction(() => {
                // Create the basic memory
                Thought_Memory thought_Memory = (Thought_Memory)ThoughtMaker.MakeThought(LocalDefOf.WIN_LookedOutWindowRegular);

                // Create a temp list of thoughts the pawn has
                List <Thought> tmpThoughts = new List <Thought>();;
                pawn.needs.mood.thoughts.GetAllMoodThoughts(tmpThoughts);
                // Scan through the thoughts
                for (int t = 0; t < tmpThoughts.Count; t++)
                {
                    // If the pawn has cabin fever, change the memory
                    if (tmpThoughts[t].def.defName == "CabinFever")
                    {
                        thought_Memory = (Thought_Memory)ThoughtMaker.MakeThought(LocalDefOf.WIN_LookedOutWindowCabinFever);
                        // If the pawn has serious cabin fever, give a better memory
                        if (tmpThoughts[t].CurStageIndex == 1)
                        {
                            thought_Memory.moodPowerFactor = 1.5f;
                        }
                    }
                }

                // Try to add the memory
                pawn.needs.mood.thoughts.memories.TryGainMemory(thought_Memory);
            });
            yield return(low);
        }
Exemple #16
0
 public static void Postfix(MemoryThoughtHandler __instance, ref Thought_Memory newThought, Pawn otherPawn)
 {
     if (newThought != null && __instance.pawn.HasTrait(VTEDefOf.VTE_FunLoving) && (newThought.def == ThoughtDefOf.AttendedParty ||
                                                                                    newThought.def.defName == "VFEV_AttendedFeast" || newThought.def.defName == "VFEV_TakingPartInFeast")) // vikings compatibility
     {
         newThought.durationTicksOverride = newThought.def.DurationTicks * 4;
     }
 }
 public static void Listener(Corpse __instance, ref Thought_Memory __result)
 {
     if (__instance.InnerPawn.RaceProps.Humanlike &&
         Utils.ExceptionAndroidList.Contains(__instance.InnerPawn.def.defName))
     {
         __result = null;
     }
 }
Exemple #18
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            IntVec3 cell = RCellFinder.RandomWanderDestFor(pawn, pawn.Position, 5f, null, Danger.Deadly);

            pawn.rotationTracker.Face(cell.ToVector3());

            yield return(Toils_General.ClearTarget(TargetIndex.A));

            yield return(Toils_General.Wait(500));

            yield return(Toils_General.Do(delegate
            {
                //this.ReportStringProcessed("laying egg.");

                Thing egg = GenSpawn.Spawn(ThingDefOf.AvaliEgg, pawn.Position, Map);
                //FilthMaker.MakeFilth(pawn.Position, pawn.Map, ThingDefOf.FilthAmnioticFluid, pawn.LabelIndefinite(), 1);
                egg.SetForbidden(true, true);

                CompHatcherAvali compHatcher = egg.TryGetComp <CompHatcherAvali>();
                if (compHatcher != null)
                {
                    //Log.Message("mother = " + pawn);
                    Hediff hediff_HasEgg = pawn.health.hediffSet.hediffs.Find((Hediff x) => x.def == HediffDefOf.AvaliHasEgg);
                    if (hediff_HasEgg != null)
                    {
                        pawn.health.RemoveHediff(hediff_HasEgg);
                    }
                    //Log.Message(pawn + " removed hediff: " + hediff_HasEgg);

                    Thought_Memory newThought = (Thought_Memory)ThoughtMaker.MakeThought(ThoughtDefOf.AvaliCaresOfEgg);

                    compHatcher.hatcheeFaction = pawn.Faction;
                    compHatcher.hatcheeParent = pawn;
                    pawn.health.AddHediff(HediffDefOf.AvaliCaresOfEgg, null, null);
                    pawn.needs.mood.thoughts.memories.TryGainMemory(newThought, pawn);

                    if (father != null)
                    {
                        compHatcher.otherParent = father;
                        if (!father.Dead)
                        {
                            father.health.AddHediff(HediffDefOf.AvaliCaresOfEgg, null, null);
                            father.needs.mood.thoughts.memories.TryGainMemory(newThought, father);
                        }
                    }

                    //Log.Message(pawn + " egg.hatcheeFaction = " + compHatcher.hatcheeFaction);
                    //Log.Message(pawn + " egg.hatcheeMother = " + pawn);
                    //Log.Message(pawn + " egg.hatcheeFather = " + father);
                }
                else
                {
                    Log.Error(egg + " not have CompHatcherAvali.");
                }
            }));

            yield break;
        }
 public override void Tick()
 {
     if (pawn.IsFighting() && pawn.equipment.AllEquipmentListForReading.Any(t => t.def == RWBYDefOf.RWBY_Crescent_Rose_Rifle || t.def == RWBYDefOf.RWBY_Crescent_Rose_Scythe))
     {
         Thought_Memory thought_Memory = (Thought_Memory)ThoughtMaker.MakeThought(RWBYDefOf.RWBY_RubyUsedCrescentRose);
         pawn.needs.mood.thoughts.memories.TryGainMemory(thought_Memory);
     }
     base.Tick();
 }
 private static void Postfix(MemoryThoughtHandler __instance, Thought_Memory newThought, Pawn otherPawn)
 {
     if (newThought.def == ThoughtDefOf.RebuffedMyRomanceAttempt)
     {
         if (Rand.Chance(0.1f))
         {
             TaleRecorder.RecordTale(VSIE_DefOf.VSIE_RebuffedMe, __instance.pawn, otherPawn);
         }
     }
 }
 static bool GiveObservedThought_Prefix(Corpse __instance, ref Thought_Memory __result)
 {
     if (__instance.IsBurning())
     {
         __result = (Thought_MemoryObservation)ThoughtMaker.MakeThought(ThoughtDef.Named("ObservedBurningCorpse"));
         (__result as Thought_MemoryObservation).Target = __instance;
         Log.Message("Burning Corpse found");
         return(false);
     }
     return(true);
 }
Exemple #22
0
        public static bool TryGainMemory(MemoryThoughtHandler __instance, Thought_Memory newThought, Pawn otherPawn = null)
        {
            if (!ThoughtUtility.CanGetThought_NewTemp(__instance.pawn, newThought.def))
            {
                return(false);
            }

            if (newThought is Thought_MemorySocial && newThought.otherPawn == null && otherPawn == null)
            {
                Log.Error(string.Concat("Can't gain social thought ", newThought.def, " because its otherPawn is null and otherPawn passed to this method is also null. Social thoughts must have otherPawn."));
                return(false);
            }

            newThought.pawn      = __instance.pawn;
            newThought.otherPawn = otherPawn;
            if (!newThought.TryMergeWithExistingMemory(out bool showBubble))
            {
                lock (__instance)
                {
                    List <Thought_Memory> newMemories = new List <Thought_Memory>(__instance.Memories)
                    {
                        newThought
                    };
                    memoriesFieldRef(__instance) = newMemories;
                }
            }

            if (newThought.def.stackLimitForSameOtherPawn >= 0)
            {
                while (__instance.NumMemoriesInGroup(newThought) > newThought.def.stackLimitForSameOtherPawn)
                {
                    __instance.RemoveMemory(__instance.OldestMemoryInGroup(newThought));
                }
            }

            if (newThought.def.stackLimit >= 0)
            {
                while (__instance.NumMemoriesOfDef(newThought.def) > newThought.def.stackLimit)
                {
                    __instance.RemoveMemory(__instance.OldestMemoryOfDef(newThought.def));
                }
            }

            if (newThought.def.thoughtToMake != null)
            {
                __instance.TryGainMemory(newThought.def.thoughtToMake, newThought.otherPawn);
            }

            if (showBubble && newThought.def.showBubble && __instance.pawn.Spawned && PawnUtility.ShouldSendNotificationAbout(__instance.pawn))
            {
                MoteMaker.MakeMoodThoughtBubble(__instance.pawn, newThought);
            }
            return(false);
        }
Exemple #23
0
        /// <summary>
        /// Tries to add a mutation thought.
        /// </summary>
        /// <param name="pawn">The pawn.</param>
        /// <param name="mutationMemory">The mutation memory.</param>
        /// <param name="ignoreLimit">if set to <c>true</c> ignore the mutation memory limit in the mod settings.</param>
        public static void TryAddMutationThought([NotNull] this Pawn pawn, [NotNull] ThoughtDef mutationMemory, bool ignoreLimit = false)
        {
            if (pawn == null)
            {
                throw new ArgumentNullException(nameof(pawn));
            }
            if (mutationMemory == null)
            {
                throw new ArgumentNullException(nameof(mutationMemory));
            }
            var memoryHandler = pawn.needs?.mood?.thoughts?.memories;

            if (memoryHandler == null)
            {
                return;
            }

            if (ignoreLimit || !AllMutationMemories.Contains(mutationMemory))//if the memory isn't a mutation memory just add it
            {
                memoryHandler.TryGainMemory(mutationMemory);
                return;
            }

            int            counter    = 0;
            Thought_Memory firstAdded = null;

            foreach (Thought_Memory memory in memoryHandler.Memories)
            {
                if (!AllMutationMemories.Contains(memory.def))
                {
                    continue;
                }

                counter++;
                if (firstAdded == null || firstAdded.age < memory.age)
                {
                    firstAdded = memory;
                }
            }

            var limit = PMUtilities.GetSettings().maxMutationThoughts;

            if (counter >= limit)
            {
                //if we'er at the limit remove the first thought that was added before adding the new one
                if (firstAdded != null)
                {
                    memoryHandler.RemoveMemory(firstAdded);
                }
            }

            memoryHandler.TryGainMemory(mutationMemory);
        }
Exemple #24
0
 public static bool Listener(Thought_Memory newThought, Pawn otherPawn, MemoryThoughtHandler __instance)
 {
     try
     {
         return(!shouldSkipCurrentMemory(newThought.def, __instance));
     }
     catch (Exception e)
     {
         Log.Message("[ATPP] MemoryThoughtHandler.TryGainMemory : " + e.Message + " - " + e.StackTrace);
         return(true);
     }
 }
Exemple #25
0
        public override void CompTickRare()
        {
            base.CompTickRare();

            //Applying torment
            List <Pawn> affectedPawnList = new List <Pawn> {
            };

            affectedPawnList = ToolsCell.GetPawnsInRadius(
                buildingPos.ToIntVec3(), Range, myMap,
                Props.affectsAnimals, Props.affectsHumanlike, Props.affectsMechanoids,
                Props.affectsColonists, Props.affectsNeutralOrFriends, Props.affectsEnemies,
                prcDebug
                );

            foreach (Pawn curPawn in affectedPawnList)
            {
                // Slugs are immune to this
                if (curPawn.IsSlug())
                {
                    Tools.Warn(curPawn.Label + " is slug, not affected", prcDebug);
                    continue;
                }

                // Add psychicSensitivity * SocialImpact * SocialSkill fight here
                if (ToolsBodyPart.ApplyHediffOnBodyPartTag(curPawn, BodyPartTagDefOf.ConsciousnessSource, hediffDefToApply, prcDebug))
                {
                    if (IsFlaySpot)
                    {
                        Thought_Memory MindFlayed = (Thought_Memory)ThoughtMaker.MakeThought(MyDefs.MindFlayThought);
                        curPawn.needs.mood.thoughts.memories.TryGainMemory(MindFlayed, Initiator);
                    }

                    //GfxEffects.ThrowPsycastAreaMote(curPawn.Position.ToVector3(), myMap);
                    GfxEffects.ThrowMindMote(curPawn.Position.ToVector3(), myMap, spotKind);
                    AffectedPawnsNum++;
                }
            }

            if (IsLimitExceeded)
            {
                Initiator.ApplyTiredness();
            }


            //Checking if Initiator is not mad or downed or sleepin or on fire
            if (Initiator.InMentalState || Initiator.Downed || Initiator.IsSleepingOrOnFire() || AffectedPawnsNum > Props.hediffAppliedLimit)
            {
                GfxEffects.ThrowCoupleMotes(buildingPos, myMap, spotKind);
                building.Destroy();
            }
        }
 public static bool Prefix(Thought_Memory __instance, ref bool __result)
 {
     if (__instance.pawn.HasTrait(VTEDefOf.VTE_FunLoving) && (__instance.def == ThoughtDefOf.AttendedParty ||
                                                              __instance.def.defName == "VFEV_AttendedFeast" || __instance.def.defName == "VFEV_TakingPartInFeast")) // vikings compatibility
     {
         if (__instance.age < (__instance.def.DurationTicks * 4))
         {
             __result = false;
             return(false);
         }
     }
     return(true);
 }
Exemple #27
0
        public override void Interacted(Pawn initiator, Pawn recipient, List <RulePackDef> extraSentencePacks)
        {
            var recruitDef = DefDatabase <ThoughtDef> .GetNamed("CTRL_Recruit_ToLeader");

            Thought_Memory newThought = (Thought_Memory)ThoughtMaker.MakeThought(recruitDef);

            recipient.needs.mood.thoughts.memories.TryGainMemory(newThought, CultManager.Leader);

            var hediff = HediffMaker.MakeHediff(CultManager.CommittedHediffdef, recipient);

            recipient.health.AddHediff(hediff);
            hediff.Severity = 0.05f;
        }
        /// <summary>
        /// Try to give this pawn a new memory. <br />
        /// If pawn does not have needs/mood/thoughts ect this call does nothing.
        /// </summary>
        /// <param name="pawn">The pawn.</param>
        /// <param name="thought">The thought.</param>
        /// <param name="otherPawn">The other pawn.</param>
        /// <param name="respectTraits">if ThoughtUtility.CanGetThought should be checked before giving the thought</param>
        /// <exception cref="ArgumentNullException">pawn</exception>
        public static void TryGainMemory([NotNull] this Pawn pawn, Thought_Memory thought, Pawn otherPawn = null, bool respectTraits = true) //move extension methods elsewhere?
        {
            if (pawn == null)
            {
                throw new ArgumentNullException(nameof(pawn));
            }
            if (respectTraits && !ThoughtUtility.CanGetThought(pawn, thought.def))
            {
                return;
            }


            pawn.needs?.mood?.thoughts?.memories?.TryGainMemory(thought, otherPawn);
        }
Exemple #29
0
 public static Thought_Memory AddDesensitizedChance(Thought_Memory thought_Memory, Pawn pawn)
 {
     if (thought_Memory != null && thought_Memory.def == ThoughtDefOf.ObservedLayingCorpse)
     {
         if (!pawn.story.traits.HasTrait(TraitDefOfPsychology.BleedingHeart) && !pawn.story.traits.HasTrait(TraitDefOf.Psychopath) && !pawn.story.traits.HasTrait(TraitDefOf.Bloodlust) && !pawn.story.traits.HasTrait(TraitDefOfPsychology.Desensitized))
         {
             if (((pawn.GetHashCode() ^ (GenLocalDate.DayOfYear(pawn) + GenLocalDate.Year(pawn) + (int)(GenLocalDate.DayPercent(pawn) * 5) * 60) * 391) % 1000) == 0)
             {
                 pawn.story.traits.GainTrait(new Trait(TraitDefOfPsychology.Desensitized));
                 pawn.needs.mood.thoughts.memories.TryGainMemory(ThoughtDefOfPsychology.RecentlyDesensitized);
             }
         }
     }
     return(thought_Memory);
 }
        private static void Postfix(MemoryThoughtHandler __instance, ref Thought_Memory newThought, Pawn otherPawn)
        {
            var options = newThought.def.GetModExtension <ThoughtExtensions>();

            if (options != null)
            {
                if (options.removeThoughtsWhenAdded != null)
                {
                    foreach (var thoughtDef in options.removeThoughtsWhenAdded)
                    {
                        __instance.pawn.needs.mood.thoughts.memories.RemoveMemoriesOfDef(thoughtDef);
                    }
                }
            }
        }