private static void Postfix(ref Pawn __result, ref PawnGenerationRequest request) { RaceAddonComp racomp = null; if (__result.def is RaceAddonThingDef thingDef) { // get backstorydef SimpleBackstoryDef simpleBackstoryDef = null; foreach (var backstory in __result.story.AllBackstories) { if (DefDatabase <SimpleBackstoryDef> .AllDefsListForReading.Find(x => x.defName == backstory.identifier) is var def && def != null) { simpleBackstoryDef = def; } } // make default setting racomp = __result.GetComp <RaceAddonComp>(); float maleChance = (simpleBackstoryDef != null && simpleBackstoryDef.maleChance >= 0) ? simpleBackstoryDef.maleChance : thingDef.raceAddonSettings.basicSetting.maleChance; __result.gender = GetGender(maleChance, request.FixedGender); var gender = __result.gender; __result.Name = PawnBioAndNameGenerator.GeneratePawnName(__result, NameStyle.Full, request.FixedLastName); racomp.drawSize = RaceAddonTools.GetPawnDrawSize(__result, thingDef); var drawSize = thingDef.raceAddonSettings.graphicSetting.drawSize[racomp.drawSize]; AppearanceDef appearanceDef = null; var list = (simpleBackstoryDef != null && simpleBackstoryDef.raceAppearances != null) ? simpleBackstoryDef.raceAppearances : thingDef.raceAddonSettings.graphicSetting.raceAppearances; if (drawSize.apparanceOverwrite.FindAll(x => x.gender == Gender.None || x.gender == gender) is var list2 && list2.Count > 0) { appearanceDef = list2.RandomElementByWeight(x => x.weight).appearanceDef; } else if (list.FindAll(x => x.gender == Gender.None || x.gender == gender) is var list3 && list3.Count > 0) { appearanceDef = list3.RandomElementByWeight(x => x.weight).appearanceDef; }
public override void CompTickRare() { base.CompTickRare(); if (Pawn != null && Pawn.Spawned) { // resolve draw size var newDrawSize = RaceAddonTools.GetPawnDrawSize(Pawn, ThingDef); if (drawSize != newDrawSize) { drawSize = newDrawSize; if (ThingDef.raceAddonSettings.graphicSetting.drawSize[drawSize].apparanceOverwrite.FindAll(x => x.gender == Gender.None || x.gender == Pawn.gender) is var overwrite && overwrite.Count > 0) { var appearanceDef = overwrite.RandomElementByWeight(x => x.weight).appearanceDef; HarmonyPathces_PawnGenerator_GeneratePawn.GenerateAppearance(Pawn, appearanceDef); Pawn.Drawer.renderer.graphics.ResolveAllGraphics(); } else { var appearanceDef = ThingDef.raceAddonSettings.graphicSetting.raceAppearances.FindAll(x => x.gender == Gender.None || x.gender == Pawn.gender).RandomElementByWeight(x => x.weight).appearanceDef; HarmonyPathces_PawnGenerator_GeneratePawn.GenerateAppearance(Pawn, appearanceDef); Pawn.Drawer.renderer.graphics.ResolveAllGraphics(); } if (Pawn.IsColonist) { Find.LetterStack.ReceiveLetter("RaceAddon_GrowUp_Label".Translate(Pawn.Name.ToStringShort), "RaceAddon_GrowUp_String".Translate(), LetterDefOf.PositiveEvent); } } foreach (var apparel in Pawn.apparel.WornApparel) { if (!RaceAddonTools.CheckApparel(Pawn, apparel.def)) { Pawn.apparel.TryDrop(apparel); } } HarmonyPatches_ResolveApparelGraphics.ResolveAddonDraw(this, ThingDef, AllAddonGraphicSets, null); }
private static bool Prefix(PawnGraphicSet __instance) { if (__instance.pawn.def is RaceAddonThingDef thingDef) { Pawn pawn = __instance.pawn; RaceAddonComp racomp = pawn.GetComp <RaceAddonComp>(); racomp.drawSize = RaceAddonTools.GetPawnDrawSize(pawn, thingDef); var drawSize = thingDef.raceAddonSettings.graphicSetting.drawSize[racomp.drawSize]; // cleaning __instance.ClearCache(); // resolve mesh set racomp.bodyMeshSet = new GraphicMeshSet(1.5f * drawSize.bodySize.x, 1.5f * drawSize.bodySize.y); racomp.headMeshSet = new GraphicMeshSet(1.5f * drawSize.headSize.x, 1.5f * drawSize.headSize.y); racomp.equipmentMeshSet = new GraphicMeshSet(drawSize.equipmentSize.x, drawSize.equipmentSize.y); // resolve body var bodyDef = racomp.savedBodyData.def; __instance.pawn.story.bodyType = bodyDef.bodyTypeDef; __instance.nakedGraphic = GraphicDatabase.Get <Graphic_Multi> (GetBodyNormalPath(bodyDef), bodyDef.shaderType.Shader, Vector2.one, pawn.story.SkinColor, racomp.savedSkinData.color2); __instance.rottingGraphic = GraphicDatabase.Get <Graphic_Multi> (GetBodyNormalPath(bodyDef), bodyDef.shaderType.Shader, Vector2.one, racomp.savedSkinData.rottingColor); __instance.dessicatedGraphic = GraphicDatabase.Get <Graphic_Multi>(GetBodySkullPath(bodyDef), ShaderDatabase.Cutout); // resolve head var headDef = racomp.savedHeadData.def; __instance.pawn.story.crownType = headDef.crownType; __instance.headGraphic = GraphicDatabase.Get <Graphic_Multi> (headDef.replacedHeadPath, headDef.shaderType.Shader, Vector2.one, pawn.story.SkinColor, racomp.savedSkinData.color2); __instance.desiccatedHeadGraphic = GraphicDatabase.Get <Graphic_Multi> (headDef.replacedHeadPath, headDef.shaderType.Shader, Vector2.one, racomp.savedSkinData.rottingColor); __instance.skullGraphic = GraphicDatabase.Get <Graphic_Multi> (headDef.replacedSkullPath, headDef.shaderType.Shader, Vector2.one, Color.white); // resolve stump __instance.headStumpGraphic = GraphicDatabase.Get <Graphic_Multi> (headDef.replacedStumpPath, headDef.shaderType.Shader, Vector2.one, pawn.story.SkinColor, racomp.savedSkinData.color2); __instance.desiccatedHeadStumpGraphic = GraphicDatabase.Get <Graphic_Multi> (headDef.replacedStumpPath, headDef.shaderType.Shader, Vector2.one, racomp.savedSkinData.rottingColor); // resolve hair HairDef hairDef = pawn.story.hairDef; if (hairDef is ImprovedHairDef advancedHairDef) { __instance.hairGraphic = GraphicDatabase.Get <Graphic_Multi> (advancedHairDef.texPath, advancedHairDef.shaderType.Shader, Vector2.one, pawn.story.hairColor, racomp.savedHairData.color2); if (advancedHairDef.lowerPath != null) { racomp.improvedHairGraphic = GraphicDatabase.Get <Graphic_Multi> (advancedHairDef.lowerPath, advancedHairDef.shaderType.Shader, Vector2.one, pawn.story.hairColor, racomp.savedHairData.color2); } } else { __instance.hairGraphic = GraphicDatabase.Get <Graphic_Multi> (hairDef.texPath, ShaderDatabase.Cutout, Vector2.one, pawn.story.hairColor); racomp.improvedHairGraphic = null; } // resolve upper face if (racomp.savedFaceData != null && racomp.savedFaceData.upperDef != null) { var upperFaceDef = racomp.savedFaceData.upperDef; racomp.upperFaceGraphicSet = new FaceGraphicSet(pawn, racomp.savedFaceData, upperFaceDef, racomp); racomp.upperFaceGraphicSet.ResolveAllGraphics(); } // resolve lower face if (racomp.savedFaceData != null && racomp.savedFaceData.lowerDef != null) { var lowerFaceDef = racomp.savedFaceData.lowerDef; racomp.lowerFaceGraphicSet = new FaceGraphicSet(pawn, racomp.savedFaceData, lowerFaceDef, racomp); racomp.lowerFaceGraphicSet.ResolveAllGraphics(); } // resolve addons if (racomp.savedAddonDatas != null) { racomp.bodyAddonGraphicSets = null; racomp.headAddonGraphicSets = null; foreach (var data in racomp.savedAddonDatas) { if (data.def.drawingToBody) { if (racomp.bodyAddonGraphicSets == null) { racomp.bodyAddonGraphicSets = new List <AddonGraphicSet>(); } var set = new AddonGraphicSet(data); set.ResolveAllGraphics(racomp.savedSkinData.rottingColor, pawn.health.hediffSet); racomp.bodyAddonGraphicSets.Add(set); } else { if (racomp.headAddonGraphicSets == null) { racomp.headAddonGraphicSets = new List <AddonGraphicSet>(); } var set = new AddonGraphicSet(data); set.ResolveAllGraphics(racomp.savedSkinData.rottingColor, pawn.health.hediffSet); racomp.headAddonGraphicSets.Add(set); } } } if (!pawn.Dead) { // resolve eye blinker if (thingDef.raceAddonSettings.graphicSetting.eyeBlink) { racomp.eyeBlinker = new EyeBlinker(); racomp.eyeBlinker.Check(pawn.needs.mood.CurLevel); } // resolve head rotator if (thingDef.raceAddonSettings.graphicSetting.headAnimation) { racomp.headRotator = new HeadRotator(); racomp.headRotator.Check(); } // resolve head targeter if (thingDef.raceAddonSettings.graphicSetting.headTargeting) { racomp.headTargeter = new HeadTargeter(__instance.pawn); racomp.headTargeter.Check(); } } // resolve apparel __instance.ResolveApparelGraphics(); return(false); } return(true); }