public static MentalStateDef GetMentalState(Pawn pawn, List <PS_Conditioning_Data> conData) { // Check if removed trait has break var breaksFromRemoved = new List <MentalStateDef>(); foreach (var data in conData) { if (data.AlterType == TraitAlterType.Removed) { var orgTrait = new Trait(DefDatabase <TraitDef> .GetNamed(data.OriginalTraitDefName)); var degree = PS_TraitHelper.GetDegreeDate(orgTrait); if (degree != null) { var count = degree.theOnlyAllowedMentalBreaks?.Count ?? 0; if (count > 0) { breaksFromRemoved.AddRange(degree.theOnlyAllowedMentalBreaks.Select(x => x.mentalState)); } } } } if (breaksFromRemoved.Count() > 0) { return(breaksFromRemoved[Rand.Range(0, breaksFromRemoved.Count() - 1)]); } // Check if added trait disallows break var breaksFromAdded = new List <MentalStateDef>(); foreach (var data in conData) { if (data.AlterType == TraitAlterType.Added) { var addTrait = new Trait(DefDatabase <TraitDef> .GetNamed(data.AddedTraitDefName)); var degree = PS_TraitHelper.GetDegreeDate(addTrait); if (degree != null) { var count = degree.disallowedMentalStates?.Count ?? 0; if (count > 0) { breaksFromAdded.AddRange(degree.disallowedMentalStates); } } } } if (breaksFromAdded.Count() > 0) { return(breaksFromAdded[Rand.Range(0, breaksFromAdded.Count() - 1)]); } // Otherwise get all allowable mental traits var naturalTraits = PS_ConditioningHelper.GetNaturalTraits(pawn); var degrees = naturalTraits.SelectMany(x => x.def.degreeDatas).Distinct(); var forbiden = degrees.Where(x => (x.disallowedMentalStates?.Count ?? 0) > 0).SelectMany(x => x.disallowedMentalStates).ToList(); var allowed = DefDatabase <MentalStateDef> .AllDefs.Where(x => !forbiden.Contains(x) && x.colonistsOnly && x.Worker.StateCanOccur(pawn)).ToList(); return(allowed[Rand.Range(0, allowed.Count - 1)]); }
public void UpdateAddableTraits(List <Trait> currentTraits) { var traits = PS_TraitHelper.AllTraitsCompadable(currentTraits, IncludeBlack: CheatMode); var options = traits.Select(trait => new PS_ScrollView <Trait> .ScrollOption <Trait> { Index = 0, Value = trait, Label = trait.LabelCap, ToolTip = trait.TipString(this.Pawn), ButtonText = "PS_Add".Translate(), ButtonAction = delegate { this.AddTrait(trait); } }).ToList(); AddTraitScrollView.TrySetOptions(options); }
public void UpdateCurrentTraits(List <Trait> traits) { var options = traits.Select(trait => { var black = PS_TraitHelper.IsBlacklisted(trait); var wasAdded = StartingConditioning?.Where(x => x.AddedTraitDefName == trait.def.defName).Any() ?? false; var valid = !(black || wasAdded); if (CheatMode) { valid = true; } var opt = new PS_ScrollView <Trait> .ScrollOption <Trait> { Index = 0, Value = trait, Label = trait.LabelCap, ToolTip = trait.TipString(Pawn), HasButton = valid }; if (trait.def.defName == "PS_Trait_BotchedConditioning" && trait.Degree == -1) { opt.ButtonAction = delegate { SetFixingBotch(); }; opt.ButtonText = "PS_Fix".Translate(); opt.HasButton = true; } if (valid && trait.def.degreeDatas.Count < 2) { opt.ButtonAction = delegate { RemoveTrait(trait); }; opt.ButtonText = "PS_Remove".Translate(); } else if (valid) { opt.ButtonAction = delegate { ShowDegreeOptions(trait); }; opt.ButtonText = "PS_Change".Translate(); } return(opt); }).ToList(); CurrentTraitScrollView.TrySetOptions(options); }