Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
        private void TryAddMemory(Pawn pawn, ThoughtDef memory)
        {
            ThoughtHandler thoughts = pawn.needs?.mood?.thoughts;

            if (thoughts == null)
            {
                return;
            }

            if (!ThoughtUtility.CanGetThought(pawn, memory))
            {
                return;
            }

            var counter = 0;
            int max     = PMUtilities.GetSettings().maxMutationThoughts;

            if (!ignoreThoughtLimit)
            {
                foreach (Thought_Memory thought in thoughts.memories.Memories)
                {
                    if (MutationUtilities.AllMutationMemories.Contains(thought.def))
                    {
                        counter++;
                    }

                    counter++;
                    if (counter >= max)
                    {
                        return;                 //make sure to only add so many thoughts at once
                    }
                }
            }

            pawn.TryGainMemory(memory);
        }