/// <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); } } } }
private static void TransferTraits([NotNull] IEnumerable <Pawn> originalPawns, [NotNull] Pawn mergedPawn) { TraitSet mTraits = mergedPawn.story?.traits; if (mTraits == null) { return; } var traits = new List <TraitDef>(); foreach (Pawn originalPawn in originalPawns) { List <Trait> pTraits = originalPawn.story?.traits?.allTraits; if (pTraits == null) { continue; } foreach (Trait pTrait in pTraits) { if (traits.Contains(pTrait.def) || !FormerHumanUtilities.MutationTraits.Contains(pTrait.def)) { continue; } traits.Add(pTrait.def); } } //check for split mind if (traits.Contains(PMTraitDefOf.MutationAffinity) && traits.Contains(TraitDefOf.BodyPurist)) { traits.Remove(PMTraitDefOf.MutationAffinity); traits.Remove(TraitDefOf.BodyPurist); AspectTracker at = mergedPawn.GetAspectTracker(); at?.Add(AspectDefOf.SplitMind); } foreach (TraitDef traitDef in traits) { mTraits.GainTrait(new Trait(traitDef, 0, true)); } }
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 }
/// <summary>Does the ingestion outcome special.</summary> /// <param name="pawn">The pawn.</param> /// <param name="ingested">The ingested.</param> protected override void DoIngestionOutcomeSpecial(Pawn pawn, Thing ingested) { var gComp = Find.World.GetComponent <PawnmorphGameComp>(); var status = gComp.GetPawnStatus(pawn); if (status == TransformedStatus.Transformed) { //revert transformations foreach (MutagenDef mutagenDef in DefDatabase <MutagenDef> .AllDefs) { if (blackList.Contains(mutagenDef)) { return; // Make it so this reverted can not revert certain kinds of transformations. } if (mutagenDef.MutagenCached.TryRevert(pawn)) { return; } } } else { //revert mutations TransformerUtility.SetToRaceDefault(pawn); AspectTracker aT = pawn.GetAspectTracker(); if (aT != null) { RemoveAspects(aT); } GraphicsUpdaterComp graphicsComp = pawn.GetComp <GraphicsUpdaterComp>(); if (graphicsComp != null) { graphicsComp.IsDirty = true; } pawn.RefreshGraphics(); } }
private void AspectRemoved(AspectTracker sender, Aspect _) { ResetCaches(); }
private void OnAspectAdded(AspectTracker sender, Aspect _) { ResetCaches(); }