mirror of
				https://github.com/vegapnk/RJW-Genes.git
				synced 2024-08-15 00:23:31 +00:00 
			
		
		
		
	Add a helper that removes all hediffs associated with rjw sex changes
This commit is contained in:
		
							parent
							
								
									8605a09941
								
							
						
					
					
						commit
						8c51c3fa59
					
				
					 1 changed files with 26 additions and 1 deletions
				
			
		| 
						 | 
					@ -1,9 +1,10 @@
 | 
				
			||||||
using Verse;
 | 
					using Verse;
 | 
				
			||||||
using rjw;
 | 
					using rjw;
 | 
				
			||||||
using RimWorld;
 | 
					using RimWorld;
 | 
				
			||||||
using System.Collections;
 | 
					 | 
				
			||||||
using System.Linq;
 | 
					using System.Linq;
 | 
				
			||||||
using System;
 | 
					using System;
 | 
				
			||||||
 | 
					using System.Collections.Generic;
 | 
				
			||||||
 | 
					using HarmonyLib;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace RJW_Genes
 | 
					namespace RJW_Genes
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
| 
						 | 
					@ -69,5 +70,29 @@ namespace RJW_Genes
 | 
				
			||||||
            // Force Redraw at the spot
 | 
					            // Force Redraw at the spot
 | 
				
			||||||
            pawn.Drawer.renderer.graphics.SetAllGraphicsDirty();
 | 
					            pawn.Drawer.renderer.graphics.SetAllGraphicsDirty();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Fetch these once at load time because they don't change inside RJW
 | 
				
			||||||
 | 
					        private static readonly List<HediffDef> wasSexThoughts = Traverse.Create(typeof(GenderHelper)).Field("old_sex_list").GetValue<List<HediffDef>>();
 | 
				
			||||||
 | 
					        private static readonly List<HediffDef> sexChangeThoughts = Traverse.Create(typeof(GenderHelper)).Field("SexChangeThoughts").GetValue<List<HediffDef>>();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        public static void RemoveAllSexChangeThoughts(Pawn pawn)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            // Shouldn't ever be true in the normal case, but this stops someone from calling this with an incorrect setup
 | 
				
			||||||
 | 
					            if (pawn?.health == null)
 | 
				
			||||||
 | 
					                return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            if(wasSexThoughts == null || sexChangeThoughts == null || !wasSexThoughts.Any() || !sexChangeThoughts.Any())
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                Log.Error($"Couldn't get values from RJW.\nold_sex_list: {wasSexThoughts.ToStringSafeEnumerable()}\nSexChangeThoughts: {sexChangeThoughts.ToStringSafeEnumerable()}");
 | 
				
			||||||
 | 
					                return;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            foreach(var def in wasSexThoughts.Concat(sexChangeThoughts))
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                var hediff = pawn.health.hediffSet.GetFirstHediffOfDef(def);
 | 
				
			||||||
 | 
					                if (hediff != null)
 | 
				
			||||||
 | 
					                    pawn.health.RemoveHediff(hediff);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue