/// <summary> /// return the thought state for the given pawn /// </summary> /// <param name="p"></param> /// <returns></returns> protected override ThoughtState CurrentStateInternal(Pawn p) { if (!def.IsValidFor(p)) { return(false); } MutationTracker mutTracker = p.GetMutationTracker(); if (mutTracker == null) { return(false); } if (!mutTracker.AllMutations.Any()) { return(false); } var morph = p.def.GetMorphOfRace(); var influence = morph == null ? MorphUtilities.GetMaxInfluenceOfRace(p.def) : morph.GetMaxInfluenceForBody(p.RaceProps.body); var nInfluence = mutTracker.TotalInfluence / influence; var idx = Mathf.Clamp(nInfluence * def.stages.Count, 0, def.stages.Count - 1); return(ThoughtState.ActiveAtStage(Mathf.FloorToInt(idx))); }
private ThoughtState CalculateAlienBP([NotNull] Pawn pawn, [NotNull] MutationTracker tracker, [NotNull] RaceMutationSettingsExtension raceExt) { float inf = tracker.TotalInfluence; foreach (Hediff_AddedMutation mutation in tracker.AllMutations) { var isNatural = false; foreach (IRaceMutationRetriever retriever in raceExt.mutationRetrievers) { if (retriever.CanGenerate(mutation.Def)) { isNatural = true; break; } } if (isNatural) { inf -= 1; } } float nInf = Mathf.Max(inf, 0) / MorphUtilities.GetMaxInfluenceOfRace(pawn.def); int n = Mathf.FloorToInt(nInf * def.stages.Count); n = Mathf.Clamp(n, 0, def.stages.Count - 1); return(ThoughtState.ActiveAtStage(n)); }
bool UpdateHairColor([NotNull] MutationTracker tracker) { var highestInfluence = Pawn.GetHighestInfluence(); var curMorph = Pawn.def.GetMorphOfRace(); if (highestInfluence == null || highestInfluence == curMorph) { return(false); //if there is not influence or if the highest influence is } //that of their current race do nothing if (GComp == null || InitialGraphics == null || Pawn.story == null) { return(false); } float lerpVal = tracker.GetDirectNormalizedInfluence(highestInfluence); var baseColor = curMorph?.GetHairColorOverride(tracker.Pawn) ?? InitialGraphics.HairColor; var morphColor = highestInfluence.GetHairColorOverride(tracker.Pawn) ?? InitialGraphics.HairColor; if (baseColor == morphColor) { return(false); //if they're the same color don't do anything } var col = Color.Lerp(baseColor, morphColor, lerpVal); //blend the 2 by the normalized colors Pawn.story.hairColor = GComp.ColorChannels["hair"].first = col; return(true); }
/// <summary> /// return the thought state for the given pawn /// </summary> /// <param name="p"></param> /// <returns></returns> protected override ThoughtState CurrentStateInternal(Pawn p) { if (!def.IsValidFor(p)) { return(false); } MutationTracker mutTracker = p.GetMutationTracker(); if (mutTracker == null) { return(false); } if (!mutTracker.AllMutations.Any()) { return(false); } var animalInfluence = mutTracker.TotalNormalizedInfluence; var num = Mathf.FloorToInt(animalInfluence * def.stages.Count); num = Mathf.Clamp(num, 0, def.stages.Count - 1); return(ThoughtState.ActiveAtStage(num)); }
/// <summary> /// return the thought state for the given pawn /// </summary> /// <param name="p"></param> /// <returns></returns> protected override ThoughtState CurrentStateInternal(Pawn p) { if (!def.IsValidFor(p)) { return(false); } MutationTracker mutTracker = p.GetMutationTracker(); if (mutTracker == null) { return(false); } if (!mutTracker.AllMutations.Any()) { return(false); } var animalInfluence = Mathf.FloorToInt(mutTracker.TotalNormalizedInfluence * 100); //var animalInfluence = mutTracker.TotalNormalizedInfluence; //var totalMutatableParts = MutationUtilities.; TODO: find a way to make better calculations with this var stage = 0; if (animalInfluence < 17) { stage = 0; } else if (animalInfluence < 34) { stage = 1; } else if (animalInfluence < 50) { stage = 2; } else if (animalInfluence < 64) { stage = 3; } else if (animalInfluence < 84) { stage = 4; } else { stage = 5; } return(ThoughtState.ActiveAtStage(stage)); /*var num = Mathf.FloorToInt(animalInfluence * def.stages.Count); * num = Mathf.Clamp(num, 0, def.stages.Count - 1); * * return ThoughtState.ActiveAtStage(num); */ }
protected void OnColumnMutated(MutationType type, IFluentBaseColumn column) { MutationTracker.ColumnMutated(type, column); if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs(column.ColumnName)); } }
private void RefreshGraphics([NotNull] MutationTracker sender, [NotNull] Pawn pawn) { bool needsUpdate = UpdateSkinColor(sender); needsUpdate |= UpdateHairColor(sender); if (needsUpdate) //make sure to only refresh the graphics if they've been modified { pawn.RefreshGraphics(); } }
bool UpdateSkinColor([NotNull] MutationTracker tracker, bool force = false) { if (GComp == null || InitialGraphics == null) { return(false); } var colorationAspect = tracker.Pawn.GetAspectTracker()?.GetAspect <Aspects.ColorationAspect>(); if (colorationAspect != null && colorationAspect.IsFullOverride) { var color = colorationAspect.ColorSet.skinColor; if (color.HasValue) { GComp.skinColor = color.Value; return(true); } } var highestInfluence = Pawn.GetHighestInfluence(); var curMorph = Pawn.def.GetMorphOfRace(); if (highestInfluence == null || (!force && highestInfluence == curMorph)) { if (GComp.skinColor == InitialGraphics.SkinColor) { return(false); // If there is not influence or if the highest influence is that of their current race do nothing. } else { GComp.skinColor = InitialGraphics.SkinColor; return(true); } } float lerpVal = tracker.GetDirectNormalizedInfluence(highestInfluence); var baseColor = curMorph?.GetSkinColorOverride(tracker.Pawn) ?? InitialGraphics.SkinColor; var morphColor = highestInfluence.GetSkinColorOverride(tracker.Pawn) ?? InitialGraphics.SkinColor; if (!force && baseColor == morphColor) { return(false); // If they're the same color don't do anything. } var col = Color.Lerp(baseColor, morphColor, Mathf.Sqrt(lerpVal)); // Blend the 2 by the normalized colors. GComp.skinColor = GComp.ColorChannels["skin"].first = col; return(true); }
/// <summary>gets the current state of the thought with regards to the given pawns</summary> /// <param name="p">The pawn that has the thought</param> /// <param name="otherPawn">The pawn the thought is about</param> /// <returns></returns> protected override ThoughtState CurrentSocialStateInternal(Pawn p, Pawn otherPawn) { if (!p.RaceProps.Humanlike) { return(false); } if (!otherPawn.RaceProps.Humanlike) { return(false); //make sure only humanlike pawns are affected by this } if (!p.story.traits.HasTrait(TraitDefOf.BodyPurist)) { return(false); } if (!RelationsUtility.PawnsKnowEachOther(p, otherPawn)) { return(false); //the pawns have to know each other } MutationTracker tracker = otherPawn.GetMutationTracker(); if (tracker == null) { return(false); } if (tracker.MutationsCount == 0) { return(false); } //check for aliens that naturally spawn with parts RaceMutationSettingsExtension raceExt = p.TryGetRaceMutationSettings(); if (raceExt != null) { return(CalculateAlienBP(p, tracker, raceExt)); } int n = Mathf.FloorToInt(tracker.TotalNormalizedInfluence * def.stages.Count); n = Mathf.Clamp(n, 0, def.stages.Count - 1); return(ThoughtState.ActiveAtStage(n)); }
void IMutationEventReceiver.MutationRemoved(Hediff_AddedMutation mutation, MutationTracker tracker) { IsDirty = true; }
void IMutationEventReceiver.MutationAdded(Hediff_AddedPart mutation, MutationTracker tracker) { IsDirty = true; }
void IMutationEventReceiver.MutationRemoved(Hediff_AddedMutation mutation, MutationTracker tracker) { RefreshGraphics(tracker, Pawn); }