/// <summary>
        /// Determines whether the specified tracker has a conflicting aspect.
        /// </summary>
        /// <param name="tracker">The tracker.</param>
        /// <param name="testAspect">The test aspect.</param>
        /// <returns>
        ///   <c>true</c> if the specified tracker has conflicting aspect ; otherwise, <c>false</c>.
        /// </returns>
        protected bool HasConflictingAspect([NotNull] AspectTracker tracker, [NotNull] AspectDef testAspect)
        {
            foreach (AspectDef conflict in testAspect.conflictingAspects)
            {
                if (tracker.Contains(conflict))
                {
                    return(true);
                }
            }

            return(false);
        }
Example #2
0
        /// <summary>
        ///     Transfers all transferable aspects from pawn1 to pawn2
        /// </summary>
        /// <param name="pawn1">The source pawn.</param>
        /// <param name="pawn2">The destination pawn.</param>
        public static void TransferAspects([NotNull] Pawn pawn1, [NotNull] Pawn pawn2)
        {
            AspectTracker originalTracker = pawn1.GetAspectTracker();
            AspectTracker animalTracker   = pawn2.GetAspectTracker();

            if (originalTracker == null)
            {
                return;
            }
            if (animalTracker == null)
            {
                Log.Warning($"pawn {pawn2.Name},{pawn2.def.defName} does not have an aspect tracker");
                return;
            }


            foreach (Aspect aspect in originalTracker)
            {
                if (animalTracker.Contains(aspect.def, aspect.StageIndex))
                {
                    aspect.PostTransfer(animalTracker.GetAspect(aspect.def));
                    continue;
                }


                if (aspect.def.transferToAnimal)
                {
                    int    stageIndex = aspect.StageIndex;
                    Aspect aAspect    = animalTracker.GetAspect(aspect.def);
                    if (aAspect != null)
                    {
                        aAspect.StageIndex = stageIndex; //set the stage but do not re add it
                        aspect.PostTransfer(aAspect);
                    }
                    else
                    {
                        Aspect newAspect = aspect.def.CreateInstance();
                        animalTracker.Add(newAspect, stageIndex); //add it if the animal does not have the aspect
                        aspect.PostTransfer(newAspect);
                    }
                }
            }
        }