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; }
/// <summary> /// Applies the aspect to the given pawn /// </summary> /// <param name="pawn">The pawn.</param> /// <param name="aspect">The aspect.</param> /// <param name="stageIndex">Index of the stage.</param> /// <param name="outLst">The out LST.</param> /// <returns> /// if the aspect was successfully added or not /// </returns> protected virtual bool ApplyAspect([NotNull] Pawn pawn, [NotNull] AspectDef aspect, int stageIndex, [CanBeNull] List <Aspect> outLst) { var aspectTracker = pawn.GetAspectTracker(); if (aspectTracker == null) { return(false); } if (HasConflictingAspect(aspectTracker, aspect)) { return(false); } if (aspectTracker.Contains(aspect)) { return(false); //do not add the same aspect multiple times } if (!aspect.IsValidFor(pawn)) { return(false); //check for any other def restrictions } if (pawn.story?.traits != null && !CheckPawnTraits(pawn.story.traits, aspect)) { return(false); //check pawn traits } var aInst = aspect.CreateInstance(); outLst?.Add(aInst); aspectTracker.Add(aInst, stageIndex); return(true); }
/// <summary> Add the given aspect to this pawn at the specified stage index. </summary> public void Add([NotNull] AspectDef def, int startStage = 0) { if (def == null) { throw new ArgumentNullException(nameof(def)); } if (_aspects.Count(a => a.def == def) > 0) { Log.Warning($"trying to add an aspect with def {def.defName} to pawn {Pawn.Name} which already has an aspect of that def"); return; } Add(def.CreateInstance(), startStage); }
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 }