protected const string MessageTraitLost = "TFFramework_MessageTraitLost"; // {0} lost trait {1} from {2}. protected override bool CheckPartWorker(Pawn pawn, object cause) { if (pawn.story?.traits == null) { return(false); } Trait realTrait = pawn.story.traits.GetTrait(trait); if (realTrait != null) { if (realTrait.Degree == realTrait.NearestPossibleDegreeTo(target, delta, operation)) { return(false); } } else { if ((conflicts == ConflictResolutionMode.Fail) && pawn.story.traits.allTraits.Any(t => trait.ConflictsWith(t))) { return(false); } } return(true); }
protected static void AdjustTrait(Trait realTrait, Pawn pawn, object cause, int target, ref int epsilon, Operation operation, out string report) { int adjustedDegree = realTrait.NearestPossibleDegreeTo(target, epsilon, operation); epsilon -= Math.Abs(realTrait.Degree - adjustedDegree); // If our adjusted degree is zero and no degree data exists at zero, remove the trait. if ((adjustedDegree == 0) && (operation.HasFlag(Operation.RemoveAtZero) || !realTrait.def.degreeDatas.Any(data => data.degree == adjustedDegree))) { report = MessageTraitLost.Translate(pawn.LabelShort, realTrait.Label, ParseCause(cause)); pawn.story.traits.LoseTrait(realTrait); } else { report = MessageTraitChanged.Translate(pawn.LabelShort, realTrait.Label, realTrait.def.DataAtDegree(adjustedDegree).label, ParseCause(cause)); pawn.story.traits.SetDegreeOfTrait(realTrait, adjustedDegree); } }