diff --git a/1.6/Assemblies/FactionLoadout.dll b/1.6/Assemblies/FactionLoadout.dll index 7380ba1..0a6b3c2 100644 Binary files a/1.6/Assemblies/FactionLoadout.dll and b/1.6/Assemblies/FactionLoadout.dll differ diff --git a/1.6/Source/Patches/ApparelGenPatch.cs b/1.6/Source/Patches/ApparelGenPatch.cs index bf3b9ae..172aff1 100644 --- a/1.6/Source/Patches/ApparelGenPatch.cs +++ b/1.6/Source/Patches/ApparelGenPatch.cs @@ -206,8 +206,37 @@ private static Apparel GenerateNewApparel(Pawn pawn, SpecRequirementEdit spec) if (spec.Style != null) thing.SetStyleDef(spec.Style); - if (spec.Quality != null) - thing.TryGetComp()?.SetQuality(spec.Quality.Value, ArtGenerationContext.Outsider); + CompQuality compQuality = thing.TryGetComp(); + if (compQuality != null) + { + if (spec.Quality != null) + { + compQuality.SetQuality(spec.Quality.Value, ArtGenerationContext.Outsider); + } + else + { + QualityCategory quality = QualityUtility.GenerateQualityGeneratingPawn(pawn.kindDef, thing.def); + if (pawn.royalty != null && pawn.Faction != null) + { + RoyalTitleDef currentTitle = pawn.royalty.GetCurrentTitle(pawn.Faction); + if (currentTitle != null) + { + quality = (QualityCategory)Mathf.Clamp((int)quality, (int)currentTitle.requiredMinimumApparelQuality, 6); + } + } + compQuality.SetQuality(quality, ArtGenerationContext.Outsider); + } + } + + if (thing.def.useHitPoints) + { + float healthFactor = pawn.kindDef.gearHealthRange.RandomInRange; + if (healthFactor < 1f) + { + int hitPoints = Mathf.Max(1, Mathf.RoundToInt(healthFactor * (float)thing.MaxHitPoints)); + thing.HitPoints = hitPoints; + } + } if (spec.Color != default) thing.SetColor(spec.Color, false); diff --git a/1.6/Source/Patches/WeaponGenPatch.cs b/1.6/Source/Patches/WeaponGenPatch.cs index a6dfbc7..823dcdc 100644 --- a/1.6/Source/Patches/WeaponGenPatch.cs +++ b/1.6/Source/Patches/WeaponGenPatch.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using HarmonyLib; using RimWorld; +using UnityEngine; using Verse; namespace FactionLoadout.Patches; @@ -160,8 +161,37 @@ static ThingWithComps GenerateNewWeapon(Pawn pawn, SpecRequirementEdit spec) if (spec.Style != null) thing.SetStyleDef(spec.Style); - if (spec.Quality != null) - thing.TryGetComp()?.SetQuality(spec.Quality.Value, ArtGenerationContext.Outsider); + CompQuality compQuality = thing.TryGetComp(); + if (compQuality != null) + { + if (spec.Quality != null) + { + compQuality.SetQuality(spec.Quality.Value, ArtGenerationContext.Outsider); + } + else + { + QualityCategory quality = QualityUtility.GenerateQualityGeneratingPawn(pawn.kindDef, thing.def); + if (pawn.royalty != null && pawn.Faction != null) + { + RoyalTitleDef currentTitle = pawn.royalty.GetCurrentTitle(pawn.Faction); + if (currentTitle != null) + { + quality = (QualityCategory)Mathf.Clamp((int)quality, (int)currentTitle.requiredMinimumApparelQuality, 6); + } + } + compQuality.SetQuality(quality, ArtGenerationContext.Outsider); + } + } + + if (thing.def.useHitPoints) + { + float healthFactor = pawn.kindDef.gearHealthRange.RandomInRange; + if (healthFactor < 1f) + { + int hitPoints = Mathf.Max(1, Mathf.RoundToInt(healthFactor * (float)thing.MaxHitPoints)); + thing.HitPoints = hitPoints; + } + } if (spec.Color != default) thing.SetColor(spec.Color, false);