Esempio n. 1
0
        private void RecalculateMorphCount(MorphTracker tracker)
        {
            MorphDef      myMorph       = parent.def.GetMorphOfRace();
            AspectTracker aspectTracker = Pawn.GetAspectTracker();

            if (aspectTracker == null)
            {
                return;
            }
            MorphGroupDef group     = myMorph?.group;
            AspectDef     aspectDef = group?.aspectDef;

            if (aspectDef == null)
            {
                return;
            }

            Aspect aspect = aspectTracker.GetAspect(aspectDef);

            if (aspect == null) //if the hediff is missing for some reason add it again
            {
                aspect = aspectDef.CreateInstance();
                aspectTracker.Add(aspect);
            }

            aspect.StageIndex = tracker.GetGroupCount(group) - 1;
        }
Esempio n. 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);
                    }
                }
            }
        }
Esempio n. 3
0
        private void MorphCountChanged(MorphTracker sender, MorphDef morph)
        {
            MorphDef myMorph = parent.def.GetMorphOfRace();

            if (myMorph?.group == null)
            {
                return;
            }
            if (myMorph.group != morph?.group)
            {
                return;
            }

            var           pawn          = (Pawn)parent;
            AspectTracker aspectTracker = pawn.GetAspectTracker();

            if (aspectTracker == null)
            {
                return;
            }
            AspectDef aspectDef = morph?.group?.aspectDef;

            if (aspectDef == null)
            {
                return;
            }

            Aspect aspect = aspectTracker.GetAspect(aspectDef);

            if (aspect == null) //if the aspect is missing for some reason add it again
            {
                aspect = aspectDef.CreateInstance();
                aspectTracker.Add(aspect);
            }

            var comp = pawn.Map?.GetComponent <MorphTracker>();

            aspect.StageIndex = (comp?.GetGroupCount(morph.group) ?? 0) - 1;
            //stage should always be equal to the number of morphs in the group active in the same map
        }