diff --git a/Assemblies/0KillfaceTools.dll b/Assemblies/0KillfaceTools.dll index 7fbbd46..fb4ee06 100644 Binary files a/Assemblies/0KillfaceTools.dll and b/Assemblies/0KillfaceTools.dll differ diff --git a/Assemblies/Outfitter.dll b/Assemblies/Outfitter.dll index 7b0ffd8..5193a00 100644 Binary files a/Assemblies/Outfitter.dll and b/Assemblies/Outfitter.dll differ diff --git a/Source/Outfitter/ApparelEntry.cs b/Source/Outfitter/ApparelEntry.cs index e90c77b..05f5ab5 100644 --- a/Source/Outfitter/ApparelEntry.cs +++ b/Source/Outfitter/ApparelEntry.cs @@ -1,24 +1,21 @@ // ReSharper disable StyleCop.SA1307 +using System.Collections.Generic; +using RimWorld; + namespace Outfitter { - using System.Collections.Generic; - - using RimWorld; - public class ApparelEntry { - public HashSet equippedOffsets; - - public HashSet infusedOffsets; - - public HashSet statBases; + public HashSet EquippedOffsets; + public HashSet InfusedOffsets; + public HashSet StatBases; public ApparelEntry() { - this.equippedOffsets = new HashSet(); - this.infusedOffsets = new HashSet(); - this.statBases = new HashSet(); + this.EquippedOffsets = new HashSet(); + this.InfusedOffsets = new HashSet(); + this.StatBases = new HashSet(); } } } \ No newline at end of file diff --git a/Source/Outfitter/ApparelStatCache.cs b/Source/Outfitter/ApparelStatCache.cs index d95d2d8..869513f 100644 --- a/Source/Outfitter/ApparelStatCache.cs +++ b/Source/Outfitter/ApparelStatCache.cs @@ -4,23 +4,17 @@ // // Created 2016-01-02 13:58 +using System; +using System.Collections.Generic; +using System.Linq; +using JetBrains.Annotations; +using Outfitter.Enums; +using RimWorld; +using UnityEngine; +using Verse; + namespace Outfitter { - using System; - using System.Collections.Generic; - using System.Linq; - - using JetBrains.Annotations; - - using Outfitter.Enums; - using Outfitter.Textures; - - using RimWorld; - - using UnityEngine; - - using Verse; - public class ApparelStatCache { public const float MaxValue = 2.5f; @@ -30,15 +24,15 @@ public class ApparelStatCache public Dictionary ToDropList = new Dictionary(); - private readonly Pawn pawn; + private readonly Pawn _pawn; - private readonly SaveablePawn pawnSave; + private readonly SaveablePawn _pawnSave; - private int lastStatUpdate; + private int _lastStatUpdate; - private int lastTempUpdate; + private int _lastTempUpdate; - private int lastWeightUpdate; + private int _lastWeightUpdate; public ApparelStatCache(Pawn pawn) : this(pawn.GetSaveablePawn()) @@ -48,15 +42,15 @@ public ApparelStatCache(Pawn pawn) // public NeededWarmth neededWarmth; public ApparelStatCache([NotNull] SaveablePawn saveablePawn) { - this.pawn = saveablePawn.Pawn; - this.pawnSave = this.pawn.GetSaveablePawn(); + this._pawn = saveablePawn.Pawn; + this._pawnSave = this._pawn.GetSaveablePawn(); this.Cache = new List(); - this.lastStatUpdate = -5000; - this.lastTempUpdate = -5000; - this.lastWeightUpdate = -5000; + this._lastStatUpdate = -5000; + this._lastTempUpdate = -5000; + this._lastWeightUpdate = -5000; } - public delegate void ApparelScoreRawIgnored_WTHandlers(ref List statDef); + public delegate void ApparelScoreRawIgnored_WtHandlers(ref List statDef); public delegate void ApparelScoreRawInfusionHandlers( [NotNull] Apparel apparel, @@ -65,11 +59,11 @@ public delegate void ApparelScoreRawInfusionHandlers( public delegate void ApparelScoreRawStatsHandler(Apparel apparel, StatDef statDef, out float num); - public static event ApparelScoreRawInfusionHandlers ApparelScoreRaw_FillInfusedStat; + public static event ApparelScoreRawInfusionHandlers ApparelScoreRawFillInfusedStat; - public static event ApparelScoreRawStatsHandler ApparelScoreRaw_PawnStatsHandlers; + public static event ApparelScoreRawStatsHandler ApparelScoreRawPawnStatsHandlers; - public static event ApparelScoreRawIgnored_WTHandlers Ignored_WTHandlers; + public static event ApparelScoreRawIgnored_WtHandlers IgnoredWtHandlers; [NotNull] public List StatCache @@ -77,20 +71,20 @@ public List StatCache get { // update auto stat priorities roughly between every vanilla gear check cycle - if (Find.TickManager.TicksGame - this.lastStatUpdate - > JobGiver_OutfitterOptimizeApparel.ApparelStatCheck || this.pawnSave.ForceStatUpdate) + if (Find.TickManager.TicksGame - this._lastStatUpdate + > JobGiver_OutfitterOptimizeApparel.ApparelStatCheck || this._pawnSave.ForceStatUpdate) { // list of auto stats - if (this.Cache.Count < 1 && this.pawnSave.Stats.Count > 0) + if (this.Cache.Count < 1 && this._pawnSave.Stats.Count > 0) { - foreach (Saveable_Pawn_StatDef statDef in this.pawnSave.Stats) + foreach (Saveable_Pawn_StatDef statDef in this._pawnSave.Stats) { this.Cache.Add(new StatPriority(statDef.Stat, statDef.Weight, statDef.Assignment)); } } this.RawScoreDict.Clear(); - this.pawnSave.Stats.Clear(); + this._pawnSave.Stats.Clear(); // clear auto priorities this.Cache.RemoveAll(stat => stat.Assignment == StatAssignment.Automatic); @@ -98,8 +92,8 @@ public List StatCache // loop over each (new) stat // Armor only used by the Battle beacon, no relevance to jobs etc. - Pawn thisPawn = this.pawn; - if (this.pawnSave.armorOnly) + Pawn thisPawn = this._pawn; + if (this._pawnSave.ArmorOnly) { Dictionary updateArmorStats = thisPawn.GetWeightedApparelArmorStats(); foreach (KeyValuePair pair in updateArmorStats) @@ -170,16 +164,16 @@ public List StatCache } // update our time check. - this.lastStatUpdate = Find.TickManager.TicksGame; - this.pawnSave.ForceStatUpdate = false; - this.pawnSave.armorOnly = false; + this._lastStatUpdate = Find.TickManager.TicksGame; + this._pawnSave.ForceStatUpdate = false; + this._pawnSave.ArmorOnly = false; foreach (StatPriority statPriority in this.Cache.Where( statPriority => statPriority.Assignment != StatAssignment.Automatic && statPriority.Assignment != StatAssignment.Individual)) { bool exists = false; - foreach (Saveable_Pawn_StatDef stat in this.pawnSave.Stats.Where( + foreach (Saveable_Pawn_StatDef stat in this._pawnSave.Stats.Where( stat => stat.Stat.Equals(statPriority.Stat))) { stat.Weight = statPriority.Weight; @@ -199,7 +193,7 @@ public List StatCache Assignment = statPriority.Assignment, Weight = statPriority.Weight }; - this.pawnSave.Stats.Add(stats); + this._pawnSave.Stats.Add(stats); } } @@ -212,13 +206,13 @@ public FloatRange TargetTemperatures get { this.UpdateTemperatureIfNecessary(); - return this.pawnSave.TargetTemperatures; + return this._pawnSave.TargetTemperatures; } set { - this.pawnSave.TargetTemperatures = value; - this.pawnSave.TargetTemperaturesOverride = true; + this._pawnSave.TargetTemperatures = value; + this._pawnSave.TargetTemperaturesOverride = true; } } @@ -227,16 +221,16 @@ private FloatRange TemperatureWeight get { this.UpdateTemperatureIfNecessary(false, true); - return this.pawnSave.Temperatureweight; + return this._pawnSave.Temperatureweight; } } - public static List specialStats = + public static List SpecialStats = new List { StatDefOf.MentalBreakThreshold, StatDefOf.PsychicSensitivity, - StatDefOf.ToxicSensitivity, + StatDefOf.ToxicSensitivity }; public static float ApparelScoreRaw_ProtectionBaseStat(Apparel ap) @@ -253,14 +247,14 @@ public static void DoApparelScoreRaw_PawnStatsHandlers( out float num) { num = 0f; - ApparelScoreRaw_PawnStatsHandlers?.Invoke(apparel, statDef, out num); + ApparelScoreRawPawnStatsHandlers?.Invoke(apparel, statDef, out num); } public static void FillIgnoredInfused_PawnStatsHandlers(ref List allApparelStats) { - Ignored_WTHandlers?.Invoke(ref allApparelStats); + IgnoredWtHandlers?.Invoke(ref allApparelStats); } public float ApparelScoreRaw([NotNull] Apparel ap) @@ -271,7 +265,7 @@ public float ApparelScoreRaw([NotNull] Apparel ap) } // only allow shields to be considered if a primary weapon is equipped and is melee - Pawn thisPawn = this.pawn; + Pawn thisPawn = this._pawn; if (ap.def.thingClass == typeof(ShieldBelt) && thisPawn.equipment.Primary?.def.IsRangedWeapon == true) { @@ -295,9 +289,9 @@ public float ApparelScoreRaw([NotNull] Apparel ap) // relevant apparel stats ApparelEntry entry = this.GetAllOffsets(ap); - HashSet statBases = entry.statBases; - HashSet equippedOffsets = entry.equippedOffsets; - HashSet infusedOffsets = entry.infusedOffsets; + HashSet statBases = entry.StatBases; + HashSet equippedOffsets = entry.EquippedOffsets; + HashSet infusedOffsets = entry.InfusedOffsets; // start score at 1 float score = 1; @@ -313,7 +307,7 @@ public float ApparelScoreRaw([NotNull] Apparel ap) { float apStat = ap.GetStatValue(stat); - if (specialStats.Contains(stat)) + if (SpecialStats.Contains(stat)) { CalculateScoreForSpecialStats(ap, statPriority, thisPawn, apStat, ref score); } @@ -329,9 +323,9 @@ public float ApparelScoreRaw([NotNull] Apparel ap) // equipped offsets, e.g. movement speeds if (equippedOffsets.Contains(stat)) { - float apStat = ap.GetEquippedStatValue(this.pawn, stat); + float apStat = ap.GetEquippedStatValue(this._pawn, stat); - if (specialStats.Contains(stat)) + if (SpecialStats.Contains(stat)) { CalculateScoreForSpecialStats(ap, statPriority, thisPawn, apStat, ref score); } @@ -352,7 +346,7 @@ public float ApparelScoreRaw([NotNull] Apparel ap) // float statInfused = StatInfused(infusionSet, statPriority, ref dontcare); DoApparelScoreRaw_PawnStatsHandlers(ap, stat, out float statInfused); - if (specialStats.Contains(stat)) + if (SpecialStats.Contains(stat)) { CalculateScoreForSpecialStats(ap, statPriority, thisPawn, statInfused, ref score); @@ -411,7 +405,7 @@ public float ApparelScoreRaw([NotNull] Apparel ap) score *= this.ApparelScoreRaw_Temperature(ap); - RawScoreDict.Add(ap, score); + this.RawScoreDict.Add(ap, score); return score; } @@ -460,8 +454,8 @@ public static void CalculateScoreForSpecialStats(Apparel ap, StatPriority statPr } } - private static readonly SimpleCurve curve = - new SimpleCurve { new CurvePoint(-5f, 0.1f), new CurvePoint(0f, 1f), new CurvePoint(100f, 2.5f) }; + private static readonly SimpleCurve Curve = + new SimpleCurve { new CurvePoint(-5f, 0.1f), new CurvePoint(0f, 1f), new CurvePoint(100f, 4f) }; public Dictionary RawScoreDict = new Dictionary(); @@ -469,14 +463,14 @@ public float ApparelScoreRaw_Temperature([NotNull] Apparel apparel) { // float minComfyTemperature = pawnSave.RealComfyTemperatures.min; // float maxComfyTemperature = pawnSave.RealComfyTemperatures.max; - Pawn thisPawn = this.pawn; + Pawn thisPawn = this._pawn; float minComfyTemperature = thisPawn.ComfortableTemperatureRange().min; float maxComfyTemperature = thisPawn.ComfortableTemperatureRange().max; // temperature FloatRange targetTemperatures = this.TargetTemperatures; - GetInsulationStats(apparel, out float insulationCold, out float insulationHeat); + this.GetInsulationStats(apparel, out float insulationCold, out float insulationHeat); string log = apparel.LabelCap + " - InsCold: " + insulationCold + " - InsHeat: " + insulationHeat + " - TargTemp: " + targetTemperatures + "\nMinComfy: " + minComfyTemperature + " - MaxComfy: " @@ -500,7 +494,7 @@ public float ApparelScoreRaw_Temperature([NotNull] Apparel apparel) Apparel wornAp = wornApparel[index]; if (!ApparelUtility.CanWearTogether(wornAp.def, apparel.def, thisPawn.RaceProps.body)) { - GetInsulationStats(wornAp, out float insulationColdWorn, out float insulationHeatWorn); + this.GetInsulationStats(wornAp, out float insulationColdWorn, out float insulationHeatWorn); minComfyTemperature -= insulationColdWorn; maxComfyTemperature -= insulationHeatWorn; @@ -517,22 +511,22 @@ public float ApparelScoreRaw_Temperature([NotNull] Apparel apparel) FloatRange temperatureScoreOffset = new FloatRange(0f, 0f); // isolation_cold is given as negative numbers < 0 means we're underdressed - float neededInsulation_Cold = targetTemperatures.min - minComfyTemperature; + float neededInsulationCold = targetTemperatures.min - minComfyTemperature; // isolation_warm is given as positive numbers. - float neededInsulation_Warmth = targetTemperatures.max - maxComfyTemperature; + float neededInsulationWarmth = targetTemperatures.max - maxComfyTemperature; FloatRange tempWeight = this.TemperatureWeight; - log += "\nWeight: " + tempWeight + " - NeedInsCold: " + neededInsulation_Cold + " - NeedInsWarmth: " - + neededInsulation_Warmth; + log += "\nWeight: " + tempWeight + " - NeedInsCold: " + neededInsulationCold + " - NeedInsWarmth: " + + neededInsulationWarmth; - if (neededInsulation_Cold < 0) + if (neededInsulationCold < 0) { // currently too cold // caps ap to only consider the needed temp and don't give extra points - if (neededInsulation_Cold > insulationCold) + if (neededInsulationCold > insulationCold) { - temperatureScoreOffset.min += neededInsulation_Cold; + temperatureScoreOffset.min += neededInsulationCold; } else { @@ -542,23 +536,23 @@ public float ApparelScoreRaw_Temperature([NotNull] Apparel apparel) else { // currently warm enough - if (insulationCold > neededInsulation_Cold) + if (insulationCold > neededInsulationCold) { // this gear would make us too cold - temperatureScoreOffset.min += insulationCold - neededInsulation_Cold; + temperatureScoreOffset.min += insulationCold - neededInsulationCold; } } // invert for scoring temperatureScoreOffset.min *= -1; - if (neededInsulation_Warmth > 0) + if (neededInsulationWarmth > 0) { // currently too warm // caps ap to only consider the needed temp and don't give extra points - if (neededInsulation_Warmth < insulationHeat) + if (neededInsulationWarmth < insulationHeat) { - temperatureScoreOffset.max += neededInsulation_Warmth; + temperatureScoreOffset.max += neededInsulationWarmth; } else { @@ -568,10 +562,10 @@ public float ApparelScoreRaw_Temperature([NotNull] Apparel apparel) else { // currently cool enough - if (insulationHeat < neededInsulation_Warmth) + if (insulationHeat < neededInsulationWarmth) { // this gear would make us too warm - temperatureScoreOffset.max += insulationHeat - neededInsulation_Warmth; + temperatureScoreOffset.max += insulationHeat - neededInsulationWarmth; } } @@ -582,8 +576,8 @@ public float ApparelScoreRaw_Temperature([NotNull] Apparel apparel) // New log += "\nPre-Evaluate: " + temperatureScoreOffset.min + " / " + temperatureScoreOffset.max; - temperatureScoreOffset.min = curve.Evaluate(temperatureScoreOffset.min * tempWeight.min); - temperatureScoreOffset.max = curve.Evaluate(temperatureScoreOffset.max * tempWeight.max); + temperatureScoreOffset.min = Curve.Evaluate(temperatureScoreOffset.min * tempWeight.min); + temperatureScoreOffset.max = Curve.Evaluate(temperatureScoreOffset.max * tempWeight.max); log += "\nScoreOffsetMin: " + temperatureScoreOffset.min + " - ScoreOffsetMax: " + temperatureScoreOffset.max + " *= " + (temperatureScoreOffset.min * temperatureScoreOffset.max); @@ -627,8 +621,8 @@ public ApparelEntry GetAllOffsets([NotNull] Apparel ap) } ApparelEntry entry = new ApparelEntry(); - this.GetStatsOfApparel(ap, ref entry.equippedOffsets, ref entry.statBases); - this.GetStatsOfApparelInfused(ap, ref entry.infusedOffsets); + this.GetStatsOfApparel(ap, ref entry.EquippedOffsets, ref entry.StatBases); + this.GetStatsOfApparelInfused(ap, ref entry.InfusedOffsets); Outfitter.Cache.ApparelEntries.Add(ap, entry); return entry; @@ -636,13 +630,13 @@ public ApparelEntry GetAllOffsets([NotNull] Apparel ap) public void UpdateTemperatureIfNecessary(bool force = false, bool forceweight = false) { - Pawn thisPawn = this.pawn; + Pawn thisPawn = this._pawn; - if (Find.TickManager.TicksGame - this.lastTempUpdate > JobGiver_OutfitterOptimizeApparel.ApparelStatCheck + if (Find.TickManager.TicksGame - this._lastTempUpdate > JobGiver_OutfitterOptimizeApparel.ApparelStatCheck || force) { // get desired temperatures - if (!this.pawnSave.TargetTemperaturesOverride) + if (!this._pawnSave.TargetTemperaturesOverride) { // float temp = GenTemperature.GetTemperatureAtTile(thisPawn.Map.Tile); @@ -650,15 +644,15 @@ public void UpdateTemperatureIfNecessary(bool force = false, bool forceweight = float highest = this.HighestTemperatureComing(thisPawn.Map); // float minTemp = Mathf.Min(lowest - 5f, temp - 15f); - this.pawnSave.TargetTemperatures = new FloatRange(Mathf.Min(12, lowest - 10f), Mathf.Max(32, highest + 10f)); + this._pawnSave.TargetTemperatures = new FloatRange(Mathf.Min(12, lowest - 10f), Mathf.Max(32, highest + 10f)); WorkTypeDef cooking = DefDatabase.GetNamed("Cooking"); if (thisPawn.workSettings.WorkIsActive(cooking) && thisPawn.workSettings.GetPriority(cooking) < 3) { - this.pawnSave.TargetTemperatures.min = Mathf.Min(this.pawnSave.TargetTemperatures.min, -3); + this._pawnSave.TargetTemperatures.min = Mathf.Min(this._pawnSave.TargetTemperatures.min, -3); } - this.lastTempUpdate = Find.TickManager.TicksGame; + this._lastTempUpdate = Find.TickManager.TicksGame; } } @@ -666,23 +660,23 @@ public void UpdateTemperatureIfNecessary(bool force = false, bool forceweight = float min = thisPawn.def.statBases.GetStatValueFromList(StatDefOf.ComfyTemperatureMin, StatDefOf.ComfyTemperatureMin.defaultBaseValue); float max = thisPawn.def.statBases.GetStatValueFromList(StatDefOf.ComfyTemperatureMax, StatDefOf.ComfyTemperatureMax.defaultBaseValue); - if (Find.TickManager.TicksGame - this.lastWeightUpdate > JobGiver_OutfitterOptimizeApparel.ApparelStatCheck + if (Find.TickManager.TicksGame - this._lastWeightUpdate > JobGiver_OutfitterOptimizeApparel.ApparelStatCheck || forceweight) { FloatRange weight = new FloatRange(1f, 1f); - if (this.pawnSave.TargetTemperatures.min < min) + if (this._pawnSave.TargetTemperatures.min < min) { - weight.min += Math.Abs((this.pawnSave.TargetTemperatures.min - min) / 10); + weight.min += Math.Abs((this._pawnSave.TargetTemperatures.min - min) / 10); } - if (this.pawnSave.TargetTemperatures.max > max) + if (this._pawnSave.TargetTemperatures.max > max) { - weight.max += Math.Abs((this.pawnSave.TargetTemperatures.max - max) / 10); + weight.max += Math.Abs((this._pawnSave.TargetTemperatures.max - max) / 10); } - this.pawnSave.Temperatureweight = weight; - this.lastWeightUpdate = Find.TickManager.TicksGame; + this._pawnSave.Temperatureweight = weight; + this._lastWeightUpdate = Find.TickManager.TicksGame; } } @@ -691,7 +685,7 @@ private static void FillInfusionHashset_PawnStatsHandlers( StatDef parentStat, ref HashSet infusedOffsets) { - ApparelScoreRaw_FillInfusedStat?.Invoke(apparel, parentStat, ref infusedOffsets); + ApparelScoreRawFillInfusedStat?.Invoke(apparel, parentStat, ref infusedOffsets); } private void GetStatsOfApparel( @@ -718,7 +712,7 @@ private void GetStatsOfApparel( private void GetStatsOfApparelInfused(Apparel ap, ref HashSet infusedOffsets) { - foreach (StatPriority statPriority in this.pawn.GetApparelStatCache().StatCache) + foreach (StatPriority statPriority in this._pawn.GetApparelStatCache().StatCache) { FillInfusionHashset_PawnStatsHandlers(ap, statPriority.Stat, ref infusedOffsets); } diff --git a/Source/Outfitter/ApparelStatsHelper.cs b/Source/Outfitter/ApparelStatsHelper.cs index 1656b5e..1a425bd 100644 --- a/Source/Outfitter/ApparelStatsHelper.cs +++ b/Source/Outfitter/ApparelStatsHelper.cs @@ -4,54 +4,49 @@ // // Created 2015-12-31 14:34 +using System; +using System.Collections.Generic; +using System.Linq; +using JetBrains.Annotations; +using Outfitter.Enums; +using Outfitter.WorkType; +using RimWorld; +using UnityEngine; +using Verse; + namespace Outfitter { - using System; - using System.Collections.Generic; - using System.Linq; - - using JetBrains.Annotations; - - using Outfitter.Enums; - using Outfitter.WorkType; - - using RimWorld; - - using UnityEngine; - - using Verse; - public static class ApparelStatsHelper { #region Public Fields // New curve public static readonly SimpleCurve HitPointsPercentScoreFactorCurve = new SimpleCurve - { - new CurvePoint( - 0f, - 0f), - new CurvePoint( - 0.2f, - 0.15f), - new CurvePoint( - 0.25f, - 0.3f), - new CurvePoint( - 0.5f, - 0.4f), - new CurvePoint( - 0.6f, - 0.85f), - new CurvePoint( - 1f, - 1f) - - // new CurvePoint( 0.0f, 0.0f ), - // new CurvePoint( 0.25f, 0.15f ), - // new CurvePoint( 0.5f, 0.7f ), - // new CurvePoint( 1f, 1f ) - }; + { + new CurvePoint( + 0f, + 0f), + new CurvePoint( + 0.2f, + 0.15f), + new CurvePoint( + 0.25f, + 0.3f), + new CurvePoint( + 0.5f, + 0.4f), + new CurvePoint( + 0.6f, + 0.85f), + new CurvePoint( + 1f, + 1f) + + // new CurvePoint( 0.0f, 0.0f ), + // new CurvePoint( 0.25f, 0.15f ), + // new CurvePoint( 0.5f, 0.7f ), + // new CurvePoint( 1f, 1f ) + }; #endregion Public Fields @@ -59,53 +54,52 @@ public static class ApparelStatsHelper private const float ScoreFactorIfNotReplacing = 10f; - [NotNull] - private static readonly List IgnoredWorktypeDefs = + [NotNull] private static readonly List IgnoredWorktypeDefs = new List - { - "Firefighter", - "Patient", - "PatientBedRest", - "Flicker", - "HaulingUrgent", - "FinishingOff", - "Feeding", - "FSFRearming", - "Rearming", // Splitter - "FSFRefueling", - "Refueling", // Splitter - "FSFLoading", - "Loading", // Splitter - "FSFCremating", - "FSFDeconstruct", - "Demolition", // Splitter - "Nursing", // Splitter - "Mortician", // Splitter - "Preparing", // Splitter - "Therapist" - }; + { + "Firefighter", + "Patient", + "PatientBedRest", + "Flicker", + "HaulingUrgent", + "FinishingOff", + "Feeding", + "FSFRearming", + "Rearming", // Splitter + "FSFRefueling", + "Refueling", // Splitter + "FSFLoading", + "Loading", // Splitter + "FSFCremating", + "FSFDeconstruct", + "Demolition", // Splitter + "Nursing", // Splitter + "Mortician", // Splitter + "Preparing", // Splitter + "Therapist" + }; private static readonly Dictionary PawnApparelStatCaches = new Dictionary(); - private static List allApparelStats; - - private static List IgnoredStatsList = new List - { - StatDefOf.ComfyTemperatureMin, - StatDefOf.ComfyTemperatureMax, - StatDefOf.MarketValue, - StatDefOf.MaxHitPoints, - StatDefOf.SellPriceFactor, - StatDefOf.Beauty, - StatDefOf.DeteriorationRate, - StatDefOf.Flammability, - StatDefOf.Insulation_Cold, - StatDefOf.Insulation_Heat, - StatDefOf.Mass, - StatDefOf.WorkToMake, - StatDefOf.MedicalPotency, - }; + private static List _allApparelStats; + + private static readonly List _ignoredStatsList = new List + { + StatDefOf.ComfyTemperatureMin, + StatDefOf.ComfyTemperatureMax, + StatDefOf.MarketValue, + StatDefOf.MaxHitPoints, + StatDefOf.SellPriceFactor, + StatDefOf.Beauty, + StatDefOf.DeteriorationRate, + StatDefOf.Flammability, + StatDefOf.Insulation_Cold, + StatDefOf.Insulation_Heat, + StatDefOf.Mass, + StatDefOf.WorkToMake, + StatDefOf.MedicalPotency + }; #endregion Private Fields @@ -121,9 +115,9 @@ public static List AllStatDefsModifiedByAnyApparel { get { - if (allApparelStats.NullOrEmpty()) + if (_allApparelStats.NullOrEmpty()) { - allApparelStats = new List(); + _allApparelStats = new List(); // add all stat modifiers from all apparels foreach (ThingDef apparel in DefDatabase.AllDefsListForReading.Where(td => td.IsApparel)) @@ -134,22 +128,27 @@ public static List AllStatDefsModifiedByAnyApparel } foreach (StatModifier modifier in apparel.statBases.Where( - modifier => !allApparelStats.Contains(modifier.stat))) + modifier => + !_allApparelStats + .Contains(modifier.stat))) { - allApparelStats.Add(modifier.stat); + _allApparelStats.Add(modifier.stat); } foreach (StatModifier modifier in apparel.equippedStatOffsets.Where( - modifier => !allApparelStats.Contains(modifier.stat))) + modifier => + !_allApparelStats + .Contains(modifier + .stat))) { - allApparelStats.Add(modifier.stat); + _allApparelStats.Add(modifier.stat); } } - ApparelStatCache.FillIgnoredInfused_PawnStatsHandlers(ref allApparelStats); + ApparelStatCache.FillIgnoredInfused_PawnStatsHandlers(ref _allApparelStats); } - return allApparelStats; + return _allApparelStats; } } @@ -158,7 +157,8 @@ public static List AllStatDefsModifiedByAnyApparel #region Public Methods // ReSharper disable once UnusedMember.Global - public static float ApparelScoreGain([NotNull] this Pawn pawn, [NotNull] Apparel newAp, List wornApparel = null) + public static float ApparelScoreGain([NotNull] this Pawn pawn, [NotNull] Apparel newAp, + List wornApparel = null) { ApparelStatCache conf = pawn.GetApparelStatCache(); @@ -176,23 +176,25 @@ public static float ApparelScoreGain([NotNull] this Pawn pawn, [NotNull] Apparel bool willReplace = false; // check if the candidate will replace existing gear - for (int index = 0; index < wornApparel.Count; index++) - { - Apparel wornAp = wornApparel[index]; - if (ApparelUtility.CanWearTogether(wornAp.def, newAp.def, pawn.RaceProps.body)) - { - continue; - } - // can't drop forced gear - if (!pawn.outfits.forcedHandler.AllowedToAutomaticallyDrop(wornAp)) + if (wornApparel != null) + for (int index = 0; index < wornApparel.Count; index++) { - return -1000f; - } + Apparel wornAp = wornApparel[index]; + if (ApparelUtility.CanWearTogether(wornAp.def, newAp.def, pawn.RaceProps.body)) + { + continue; + } - // if replaces, score is difference of the two pieces of gear + penalty - candidateScore -= conf.ApparelScoreRaw(wornAp); - willReplace = true; - } + // can't drop forced gear + if (!pawn.outfits.forcedHandler.AllowedToAutomaticallyDrop(wornAp)) + { + return -1000f; + } + + // if replaces, score is difference of the two pieces of gear + penalty + candidateScore -= conf.ApparelScoreRaw(wornAp); + willReplace = true; + } // increase score if this piece can be worn without replacing existing gear. if (!willReplace) @@ -255,8 +257,8 @@ public static Dictionary GetWeightedApparelArmorStats([NotNull] [NotNull] public static Dictionary GetWeightedApparelIndividualStats(this Pawn pawn) { - Dictionary dict = new Dictionary(); - SaveablePawn pawnSave = pawn.GetSaveablePawn(); + Dictionary dict = new Dictionary(); + SaveablePawn pawnSave = pawn.GetSaveablePawn(); // dict.Add(StatDefOf.ArmorRating_Blunt, 0.25f); // dict.Add(StatDefOf.ArmorRating_Sharp, 0.25f); @@ -269,12 +271,11 @@ public static Dictionary GetWeightedApparelIndividualStats(this // PsychicSensitivity -2 = dull => not affected case -2: break; default: - { - AddStatToDict(StatDefOf.PsychicSensitivity, 0.1f, ref dict); - break; - } + { + AddStatToDict(StatDefOf.PsychicSensitivity, 0.1f, ref dict); + break; + } } - } foreach (GameCondition activeCondition in pawn.Map.GameConditionManager.ActiveConditions) @@ -284,16 +285,16 @@ public static Dictionary GetWeightedApparelIndividualStats(this if (activeCondition.def == GameConditionDefOf.PsychicSoothe) { if (activeCondition is GameCondition_PsychicEmanation - && (activeCondition as GameCondition_PsychicEmanation).gender == pawn.gender) + && (activeCondition as GameCondition_PsychicEmanation).gender == pawn.gender) { switch (pawn.story.traits.DegreeOfTrait(TraitDefOf.PsychicSensitivity)) { case -2: break; default: - { - AddStatToDict(StatDefOf.PsychicSensitivity, 2f, ref dict); - break; - } + { + AddStatToDict(StatDefOf.PsychicSensitivity, 2f, ref dict); + break; + } } } } @@ -304,17 +305,17 @@ public static Dictionary GetWeightedApparelIndividualStats(this if (activeCondition.def == GameConditionDefOf.PsychicDrone) { if (activeCondition is GameCondition_PsychicEmanation - && (activeCondition as GameCondition_PsychicEmanation).gender == pawn.gender - && activeCondition.def.droneLevel > PsychicDroneLevel.None) + && (activeCondition as GameCondition_PsychicEmanation).gender == pawn.gender + && activeCondition.def.droneLevel > PsychicDroneLevel.None) { switch (pawn.story.traits.DegreeOfTrait(TraitDefOf.PsychicSensitivity)) { case -2: break; default: - { - AddStatToDict(StatDefOf.PsychicSensitivity, 0.1f, ref dict); - break; - } + { + AddStatToDict(StatDefOf.PsychicSensitivity, 0.1f, ref dict); + break; + } } } } @@ -328,32 +329,34 @@ public static Dictionary GetWeightedApparelIndividualStats(this // Immunity gain if (pawn.health.hediffSet.hediffs.Any( - x => - { - if (!x.Visible) - { - return false; - } - - if (!(x is HediffWithComps hediffWithComps)) - { - return false; - } - - HediffComp_Immunizable immunizable = hediffWithComps.TryGetComp(); - if (immunizable != null) - { - return !immunizable.FullyImmune; - } - - return false; - })) + x => + { + if (!x.Visible) + { + return false; + } + + if (!(x is HediffWithComps hediffWithComps)) + { + return false; + } + + HediffComp_Immunizable immunizable = + hediffWithComps.TryGetComp(); + if (immunizable != null) + { + return !immunizable.FullyImmune; + } + + return false; + })) { AddStatToDict(StatDefOf.ImmunityGainSpeed, 1.5f, ref dict); } + { float defaultStat = pawn.def.GetStatValueAbstract(StatDefOf.MentalBreakThreshold); - float pawnStat = defaultStat; + float pawnStat = defaultStat; if (pawn.story != null) { for (int k = 0; k < pawn.story.traits.allTraits.Count; k++) @@ -398,8 +401,8 @@ public static Dictionary GetWeightedApparelIndividualStats(this [NotNull] public static Dictionary GetWeightedApparelStats(this Pawn pawn) { - Dictionary dict = new Dictionary(); - SaveablePawn pawnSave = pawn.GetSaveablePawn(); + Dictionary dict = new Dictionary(); + SaveablePawn pawnSave = pawn.GetSaveablePawn(); // dict.Add(StatDefOf.ArmorRating_Blunt, 0.25f); // dict.Add(StatDefOf.ArmorRating_Sharp, 0.25f); @@ -409,69 +412,78 @@ public static Dictionary GetWeightedApparelStats(this Pawn pawn) { // add weights for all worktypes, multiplied by job priority List workTypes = DefDatabase.AllDefsListForReading - .Where(def => pawn.workSettings.WorkIsActive(def) && !IgnoredWorktypeDefs.Contains(def.defName)).ToList(); + .Where(def => pawn.workSettings.WorkIsActive(def) && !IgnoredWorktypeDefs.Contains(def.defName)) + .ToList(); + if (!workTypes.NullOrEmpty()) + { + int maxPriority = workTypes.Aggregate( + 1, + (current, workType) => + Mathf.Max(current, pawn.GetWorkPriority(workType))); - int maxPriority = workTypes.Aggregate( - 1, - (current, workType) => Mathf.Max(current, pawn.GetWorkPriority(workType))); + int minPriority = workTypes.Aggregate( + 1, + (current, workType) => + Mathf.Min(current, pawn.GetWorkPriority(workType))); - int minPriority = workTypes.Aggregate( - 1, - (current, workType) => Mathf.Min(current, pawn.GetWorkPriority(workType))); + string log = "Outfitter Priorities, Pawn: " + pawn + " - Max: " + minPriority + "/" + maxPriority; - string log = "Outfitter Priorities, Pawn: " + pawn + " - Max: " + minPriority + "/" + maxPriority; + for (int index = 0; index < workTypes.Count; index++) + { + WorkTypeDef workType = workTypes[index]; - for (int index = 0; index < workTypes.Count; index++) - { - WorkTypeDef workType = workTypes[index]; + List> + statsOfWorkType = GetStatsOfWorkType(pawn, workType).ToList(); - List> statsOfWorkType = GetStatsOfWorkType(pawn, workType).ToList(); + for (int k = 0; k < statsOfWorkType.Count; k++) + { + KeyValuePair stats = statsOfWorkType[k]; + StatDef stat = stats.Key; - for (int k = 0; k < statsOfWorkType.Count; k++) - { - KeyValuePair stats = statsOfWorkType[k]; - StatDef stat = stats.Key; + if (!AllStatDefsModifiedByAnyApparel.Contains(stat)) + { + continue; + } - if (!AllStatDefsModifiedByAnyApparel.Contains(stat)) - { - continue; - } - if (IgnoredStatsList.Contains(stat)) - { - continue; - } - int priority = Find.PlaySettings.useWorkPriorities ? pawn.GetWorkPriority(workType) : 3; + if (_ignoredStatsList.Contains(stat)) + { + continue; + } - float priorityAdjust = 1f / priority / maxPriority; + int priority = Find.PlaySettings.useWorkPriorities ? pawn.GetWorkPriority(workType) : 3; - if (pawnSave.AddPersonalStats) - { - for (int i = 0; i < workType.relevantSkills.Count; i++) + float priorityAdjust = 1f / priority / maxPriority; + + if (pawnSave.AddPersonalStats) { - SkillDef relSkill = workType.relevantSkills[i]; - SkillRecord record = pawn.skills.GetSkill(relSkill); - float skillMod = 1 + (2f * record.Level / 20); - switch (record.passion) + for (int i = 0; i < workType.relevantSkills.Count; i++) { - case Passion.None: break; - case Passion.Minor: - skillMod *= 2f; - break; + SkillDef relSkill = workType.relevantSkills[i]; + SkillRecord record = pawn.skills.GetSkill(relSkill); + float skillMod = 1 + (2f * record.Level / 20); + switch (record.passion) + { + case Passion.None: break; + case Passion.Minor: + skillMod *= 2f; + break; - case Passion.Major: - skillMod *= 3f; - break; + case Passion.Major: + skillMod *= 3f; + break; + } + + priorityAdjust *= skillMod; } - priorityAdjust *= skillMod; } - } - float value = stats.Value; - float weight = value * priorityAdjust; + float value = stats.Value; + float weight = value * priorityAdjust; - AddStatToDict(stat, weight, ref dict); + AddStatToDict(stat, weight, ref dict); - log += "\n" + workType.defName + " - priority " + "-" + priority + " - adjusted " + weight; + log += "\n" + workType.defName + " - priority " + "-" + priority + " - adjusted " + weight; + } } } @@ -484,7 +496,8 @@ public static Dictionary GetWeightedApparelStats(this Pawn pawn) float num = ApparelStatCache.MaxValue / 8 * 5; // =>1.56 if (dict.Count > 0) { - Dictionary filter = dict.Where(x => x.Key != StatDefOf.WorkSpeedGlobal).ToDictionary(x => x.Key, y => y.Value); + Dictionary filter = dict.Where(x => x.Key != StatDefOf.WorkSpeedGlobal) + .ToDictionary(x => x.Key, y => y.Value); // normalize weights float max = filter.Values.Select(Math.Abs).Max(); foreach (StatDef key in new List(dict.Keys)) @@ -510,7 +523,7 @@ public static int GetWorkPriority(this Pawn pawn, WorkTypeDef workType) public static List NotYetAssignedStatDefs([NotNull] this Pawn pawn) { return AllStatDefsModifiedByAnyApparel - .Except(pawn.GetApparelStatCache().StatCache.Select(prio => prio.Stat)).ToList(); + .Except(pawn.GetApparelStatCache().StatCache.Select(prio => prio.Stat)).ToList(); } #endregion Public Methods @@ -518,8 +531,8 @@ public static List NotYetAssignedStatDefs([NotNull] this Pawn pawn) #region Private Methods private static void AddStatToDict( - [NotNull] StatDef stat, - float weight, + [NotNull] StatDef stat, + float weight, [NotNull] ref Dictionary dict) { if (dict.ContainsKey(stat)) @@ -580,144 +593,147 @@ private static void AdjustStatsForTraits(Pawn pawn, [NotNull] ref Dictionary> GetStatsOfArmorMelee() { - yield return new KeyValuePair(StatDefOf.MoveSpeed, 1f); - yield return new KeyValuePair(StatDefOf.MeleeDodgeChance, 3f); - yield return new KeyValuePair(StatDefOf.AccuracyTouch, 1.8f); - yield return new KeyValuePair(StatDefOf.MeleeHitChance, 3f); - yield return new KeyValuePair(StatDefOf.MeleeDPS, 2.4f); + yield return new KeyValuePair(StatDefOf.MoveSpeed, 1f); + yield return new KeyValuePair(StatDefOf.MeleeDodgeChance, 3f); + yield return new KeyValuePair(StatDefOf.AccuracyTouch, 1.8f); + yield return new KeyValuePair(StatDefOf.MeleeHitChance, 3f); + yield return new KeyValuePair(StatDefOf.MeleeDPS, 2.4f); yield return new KeyValuePair(StatDefOf.MeleeWeapon_CooldownMultiplier, -2.4f); - yield return new KeyValuePair(StatDefOf.MeleeWeapon_DamageMultiplier, 1.2f); - yield return new KeyValuePair(StatDefOf.ArmorRating_Blunt, 2.5f); - yield return new KeyValuePair(StatDefOf.ArmorRating_Sharp, 2.5f); - yield return new KeyValuePair(StatDefOf.ArmorRating_Heat, 1.5f); - yield return new KeyValuePair(StatDefOf.ArmorRating_Electric, 1.5f); - yield return new KeyValuePair(StatDefOf.ShootingAccuracy, 0f); - yield return new KeyValuePair(StatDefOf.AimingDelayFactor, -3f); - yield return new KeyValuePair(StatDefOf.RangedWeapon_Cooldown, 0f); - yield return new KeyValuePair(StatDefOf.AccuracyShort, 0f); - yield return new KeyValuePair(StatDefOf.AccuracyMedium, 0f); - yield return new KeyValuePair(StatDefOf.AccuracyLong, 0f); - yield return new KeyValuePair(StatDefOf.PainShockThreshold, PosMax()); + yield return new KeyValuePair(StatDefOf.MeleeWeapon_DamageMultiplier, 1.2f); + yield return new KeyValuePair(StatDefOf.ArmorRating_Blunt, 2.5f); + yield return new KeyValuePair(StatDefOf.ArmorRating_Sharp, 2.5f); + yield return new KeyValuePair(StatDefOf.ArmorRating_Heat, 1.5f); + yield return new KeyValuePair(StatDefOf.ArmorRating_Electric, 1.5f); + yield return new KeyValuePair(StatDefOf.ShootingAccuracy, 0f); + yield return new KeyValuePair(StatDefOf.AimingDelayFactor, -3f); + yield return new KeyValuePair(StatDefOf.RangedWeapon_Cooldown, 0f); + yield return new KeyValuePair(StatDefOf.AccuracyShort, 0f); + yield return new KeyValuePair(StatDefOf.AccuracyMedium, 0f); + yield return new KeyValuePair(StatDefOf.AccuracyLong, 0f); + yield return new KeyValuePair(StatDefOf.PainShockThreshold, PosMax()); } private static IEnumerable> GetStatsOfArmorRanged() { - yield return new KeyValuePair(StatDefOf.MoveSpeed, 1f); - yield return new KeyValuePair(StatDefOf.MeleeDodgeChance, 0.5f); - yield return new KeyValuePair(StatDefOf.ShootingAccuracy, 3f); - yield return new KeyValuePair(StatDefOf.AimingDelayFactor, -3f); - yield return new KeyValuePair(StatDefOf.RangedWeapon_Cooldown, -3f); - yield return new KeyValuePair(StatDefOf.AccuracyTouch, 0f); - yield return new KeyValuePair(StatDefOf.AccuracyShort, 1.8f); - yield return new KeyValuePair(StatDefOf.AccuracyMedium, 1.8f); - yield return new KeyValuePair(StatDefOf.AccuracyLong, 1.8f); - yield return new KeyValuePair(StatDefOf.MeleeHitChance, 1.8f); - yield return new KeyValuePair(StatDefOf.MeleeDPS, 1f); + yield return new KeyValuePair(StatDefOf.MoveSpeed, 1f); + yield return new KeyValuePair(StatDefOf.MeleeDodgeChance, 0.5f); + yield return new KeyValuePair(StatDefOf.ShootingAccuracy, 3f); + yield return new KeyValuePair(StatDefOf.AimingDelayFactor, -3f); + yield return new KeyValuePair(StatDefOf.RangedWeapon_Cooldown, -3f); + yield return new KeyValuePair(StatDefOf.AccuracyTouch, 0f); + yield return new KeyValuePair(StatDefOf.AccuracyShort, 1.8f); + yield return new KeyValuePair(StatDefOf.AccuracyMedium, 1.8f); + yield return new KeyValuePair(StatDefOf.AccuracyLong, 1.8f); + yield return new KeyValuePair(StatDefOf.MeleeHitChance, 1.8f); + yield return new KeyValuePair(StatDefOf.MeleeDPS, 1f); yield return new KeyValuePair(StatDefOf.MeleeWeapon_CooldownMultiplier, -1f); - yield return new KeyValuePair(StatDefOf.MeleeWeapon_DamageMultiplier, 1f); - yield return new KeyValuePair(StatDefOf.ArmorRating_Blunt, 2.5f); - yield return new KeyValuePair(StatDefOf.ArmorRating_Sharp, 2.5f); - yield return new KeyValuePair(StatDefOf.ArmorRating_Heat, 1.5f); - yield return new KeyValuePair(StatDefOf.ArmorRating_Electric, 1.5f); - yield return new KeyValuePair(StatDefOf.PainShockThreshold, PosMax()); + yield return new KeyValuePair(StatDefOf.MeleeWeapon_DamageMultiplier, 1f); + yield return new KeyValuePair(StatDefOf.ArmorRating_Blunt, 2.5f); + yield return new KeyValuePair(StatDefOf.ArmorRating_Sharp, 2.5f); + yield return new KeyValuePair(StatDefOf.ArmorRating_Heat, 1.5f); + yield return new KeyValuePair(StatDefOf.ArmorRating_Electric, 1.5f); + yield return new KeyValuePair(StatDefOf.PainShockThreshold, PosMax()); } - private static IEnumerable> GetStatsOfWorkType([NotNull] this Pawn pawn, - [NotNull] WorkTypeDef worktype) + private static IEnumerable> GetStatsOfWorkType([NotNull] this Pawn pawn, + [NotNull] WorkTypeDef worktype) { SaveablePawn pawnSave = pawn.GetSaveablePawn(); - bool mainJob = false; - if (pawnSave.mainJob == MainJob.Soldier00Close_Combat) + bool mainJob = false; + if (pawnSave.MainJob == MainJob.Soldier00CloseCombat) { // mainJob = true; - yield return new KeyValuePair(StatDefOf.MoveSpeed, PosMax(mainJob)); - yield return new KeyValuePair(StatDefOf.AimingDelayFactor, NegMax(mainJob)); - yield return new KeyValuePair(StatDefOf.MeleeDPS, PosMax(mainJob)); - yield return new KeyValuePair(StatDefOf.MeleeHitChance, PosMax(mainJob)); - yield return new KeyValuePair(StatDefOf.MeleeDodgeChance, PosMax(mainJob)); - yield return new KeyValuePair(StatDefOf.ArmorRating_Blunt, PosMed(mainJob)); - yield return new KeyValuePair(StatDefOf.ArmorRating_Sharp, PosMax()); - yield return new KeyValuePair(StatDefOf.AccuracyTouch, PosMax(mainJob)); + yield return new KeyValuePair(StatDefOf.MoveSpeed, PosMax(mainJob)); + yield return new KeyValuePair(StatDefOf.AimingDelayFactor, NegMax(mainJob)); + yield return new KeyValuePair(StatDefOf.MeleeDPS, PosMax(mainJob)); + yield return new KeyValuePair(StatDefOf.MeleeHitChance, PosMax(mainJob)); + yield return new KeyValuePair(StatDefOf.MeleeDodgeChance, PosMax(mainJob)); + yield return new KeyValuePair(StatDefOf.ArmorRating_Blunt, PosMed(mainJob)); + yield return new KeyValuePair(StatDefOf.ArmorRating_Sharp, PosMax()); + yield return new KeyValuePair(StatDefOf.AccuracyTouch, PosMax(mainJob)); yield return new KeyValuePair(StatDefOf.MeleeWeapon_DamageMultiplier, PosMed(mainJob)); - yield return new KeyValuePair(StatDefOf.MeleeWeapon_CooldownMultiplier, NegMax(mainJob)); - yield return new KeyValuePair(StatDefOf.PainShockThreshold, PosMax(mainJob)); + yield return + new KeyValuePair(StatDefOf.MeleeWeapon_CooldownMultiplier, NegMax(mainJob)); + yield return new KeyValuePair(StatDefOf.PainShockThreshold, PosMax(mainJob)); yield break; } - if (pawnSave.mainJob == MainJob.Soldier00Ranged_Combat) + if (pawnSave.MainJob == MainJob.Soldier00RangedCombat) { // mainJob = true; - yield return new KeyValuePair(StatDefOf.ShootingAccuracy, PosMax(mainJob)); - yield return new KeyValuePair(StatDefOf.AccuracyShort, PosMed(mainJob)); - yield return new KeyValuePair(StatDefOf.AccuracyMedium, PosMed(mainJob)); - yield return new KeyValuePair(StatDefOf.AccuracyLong, PosMed(mainJob)); - yield return new KeyValuePair(StatDefOf.MoveSpeed, PosMed(mainJob)); - yield return new KeyValuePair(StatDefOf.ArmorRating_Blunt, PosMin(mainJob)); - yield return new KeyValuePair(StatDefOf.ArmorRating_Sharp, PosMed(mainJob)); - yield return new KeyValuePair(StatDefOf.MeleeDodgeChance, PosMin()); - yield return new KeyValuePair(StatDefOf.AimingDelayFactor, NegMax(mainJob)); + yield return new KeyValuePair(StatDefOf.ShootingAccuracy, PosMax(mainJob)); + yield return new KeyValuePair(StatDefOf.AccuracyShort, PosMed(mainJob)); + yield return new KeyValuePair(StatDefOf.AccuracyMedium, PosMed(mainJob)); + yield return new KeyValuePair(StatDefOf.AccuracyLong, PosMed(mainJob)); + yield return new KeyValuePair(StatDefOf.MoveSpeed, PosMed(mainJob)); + yield return new KeyValuePair(StatDefOf.ArmorRating_Blunt, PosMin(mainJob)); + yield return new KeyValuePair(StatDefOf.ArmorRating_Sharp, PosMed(mainJob)); + yield return new KeyValuePair(StatDefOf.MeleeDodgeChance, PosMin()); + yield return new KeyValuePair(StatDefOf.AimingDelayFactor, NegMax(mainJob)); yield return new KeyValuePair(StatDefOf.RangedWeapon_Cooldown, NegMax(mainJob)); - yield return new KeyValuePair(StatDefOf.PainShockThreshold, PosMax(mainJob)); + yield return new KeyValuePair(StatDefOf.PainShockThreshold, PosMax(mainJob)); yield break; } switch (worktype.defName) { case Vanilla.Doctor: - if (pawnSave.mainJob == MainJob.Doctor) + if (pawnSave.MainJob == MainJob.Doctor) { mainJob = true; } if (!DefDatabase.AllDefsListForReading.Any( - x => x.defName == FSF.Surgeon || x.defName == Splitter.Surgeon)) + x => x.defName == FSF.Surgeon || + x.defName == Splitter.Surgeon)) { yield return new KeyValuePair( - StatDefOf.MedicalSurgerySuccessChance, - PosMax(mainJob)); + StatDefOf.MedicalSurgerySuccessChance, + PosMax(mainJob)); yield return new KeyValuePair( - StatDefOf2.MedicalOperationSpeed, - PosMax(mainJob)); + StatDefOf2.MedicalOperationSpeed, + PosMax(mainJob)); } yield return new KeyValuePair(StatDefOf.MedicalTendQuality, PosMax(mainJob)); - yield return new KeyValuePair(StatDefOf.MedicalTendSpeed, PosMed(mainJob)); + yield return new KeyValuePair(StatDefOf.MedicalTendSpeed, PosMed(mainJob)); yield break; case Vanilla.Warden: - if (pawnSave.mainJob == MainJob.Warden) + if (pawnSave.MainJob == MainJob.Warden) { mainJob = true; } yield return new KeyValuePair(StatDefOf.RecruitPrisonerChance, PosMax(mainJob)); - yield return new KeyValuePair(StatDefOf.SocialImpact, PosMed(mainJob)); + yield return new KeyValuePair(StatDefOf.SocialImpact, PosMed(mainJob)); yield return new KeyValuePair(StatDefOf.TradePriceImprovement, PosMax(mainJob)); yield break; case Vanilla.Handling: - if (pawnSave.mainJob == MainJob.Handler) + if (pawnSave.MainJob == MainJob.Handler) { mainJob = true; } if (!DefDatabase.AllDefsListForReading.Any( - x => x.defName == FSF.Training || x.defName == Splitter.Training)) + x => x.defName == FSF.Training || + x.defName == Splitter.Training)) { yield return new KeyValuePair(StatDefOf.TrainAnimalChance, PosMax(mainJob)); - yield return new KeyValuePair(StatDefOf.TameAnimalChance, PosMax(mainJob)); + yield return new KeyValuePair(StatDefOf.TameAnimalChance, PosMax(mainJob)); yield return new KeyValuePair(StatDefOf.ArmorRating_Sharp, PosMin(mainJob)); - yield return new KeyValuePair(StatDefOf.MeleeDodgeChance, PosMed(mainJob)); - yield return new KeyValuePair(StatDefOf.MeleeHitChance, PosMin(mainJob)); - yield return new KeyValuePair(StatDefOf.MoveSpeed, PosMin(mainJob)); - yield return new KeyValuePair(StatDefOf.MeleeDPS, PosMin(mainJob)); - yield return new KeyValuePair(StatDefOf.AccuracyTouch, PosMin(mainJob)); + yield return new KeyValuePair(StatDefOf.MeleeDodgeChance, PosMed(mainJob)); + yield return new KeyValuePair(StatDefOf.MeleeHitChance, PosMin(mainJob)); + yield return new KeyValuePair(StatDefOf.MoveSpeed, PosMin(mainJob)); + yield return new KeyValuePair(StatDefOf.MeleeDPS, PosMin(mainJob)); + yield return new KeyValuePair(StatDefOf.AccuracyTouch, PosMin(mainJob)); yield return new KeyValuePair( - StatDefOf.MeleeWeapon_CooldownMultiplier, - NegMin(mainJob)); + StatDefOf.MeleeWeapon_CooldownMultiplier, + NegMin(mainJob)); yield return new KeyValuePair( - StatDefOf.MeleeWeapon_DamageMultiplier, - PosMin(mainJob)); + StatDefOf.MeleeWeapon_DamageMultiplier, + PosMin(mainJob)); yield return new KeyValuePair(StatDefOf.PainShockThreshold, PosMax(mainJob)); } @@ -727,7 +743,7 @@ private static IEnumerable> GetStatsOfWorkType([Not // yield return new KeyValuePair(StatDefOf.CarryingCapacity, PosMin(mainJob)); case Vanilla.Cooking: - if (pawnSave.mainJob == MainJob.Cook) + if (pawnSave.MainJob == MainJob.Cook) { mainJob = true; } @@ -735,71 +751,74 @@ private static IEnumerable> GetStatsOfWorkType([Not // yield return new KeyValuePair(StatDefOf.MoveSpeed, 0.05f); // yield return new KeyValuePair(StatDefOf.WorkSpeedGlobal, 0.2f); if (!DefDatabase.AllDefsListForReading.Any( - x => x.defName == FSF.Brewing || x.defName == Splitter.Brewing)) + x => x.defName == FSF.Brewing || + x.defName == Splitter.Brewing)) { yield return new KeyValuePair(StatDefOf2.BrewingSpeed, PosMax(mainJob)); } if (!DefDatabase.AllDefsListForReading.Any( - x => x.defName == FSF.Butcher || x.defName == Splitter.Butcher)) + x => x.defName == FSF.Butcher || + x.defName == Splitter.Butcher)) { yield return new KeyValuePair(StatDefOf2.ButcheryFleshSpeed, PosMax(mainJob)); yield return new KeyValuePair( - StatDefOf2.ButcheryFleshEfficiency, - PosMax(mainJob)); + StatDefOf2.ButcheryFleshEfficiency, + PosMax(mainJob)); } - yield return new KeyValuePair(StatDefOf2.CookSpeed, PosMax(mainJob)); - yield return new KeyValuePair(StatDefOf.WorkSpeedGlobal, PosMin(mainJob)); - yield return new KeyValuePair(StatDefOf.MoveSpeed, PosMin(mainJob)); + yield return new KeyValuePair(StatDefOf2.CookSpeed, PosMax(mainJob)); + yield return new KeyValuePair(StatDefOf.WorkSpeedGlobal, PosMin(mainJob)); + yield return new KeyValuePair(StatDefOf.MoveSpeed, PosMin(mainJob)); yield return new KeyValuePair(StatDefOf.FoodPoisonChance, NegMax(mainJob)); yield break; case Vanilla.Hunting: - if (pawnSave.mainJob == MainJob.Hunter) + if (pawnSave.MainJob == MainJob.Hunter) { mainJob = true; } - yield return new KeyValuePair(StatDefOf.ShootingAccuracy, PosMax(mainJob)); - yield return new KeyValuePair(StatDefOf.MoveSpeed, PosMed(mainJob)); - yield return new KeyValuePair(StatDefOf.AccuracyShort, PosMed(mainJob)); - yield return new KeyValuePair(StatDefOf.AccuracyMedium, PosMed(mainJob)); - yield return new KeyValuePair(StatDefOf.AccuracyLong, PosMed(mainJob)); - yield return new KeyValuePair(StatDefOf.MeleeDPS, PosMin(mainJob)); - yield return new KeyValuePair(StatDefOf.MeleeHitChance, PosMin(mainJob)); - yield return new KeyValuePair(StatDefOf.ArmorRating_Blunt, PosMin(mainJob)); - yield return new KeyValuePair(StatDefOf.ArmorRating_Sharp, PosMin(mainJob)); + yield return new KeyValuePair(StatDefOf.ShootingAccuracy, PosMax(mainJob)); + yield return new KeyValuePair(StatDefOf.MoveSpeed, PosMed(mainJob)); + yield return new KeyValuePair(StatDefOf.AccuracyShort, PosMed(mainJob)); + yield return new KeyValuePair(StatDefOf.AccuracyMedium, PosMed(mainJob)); + yield return new KeyValuePair(StatDefOf.AccuracyLong, PosMed(mainJob)); + yield return new KeyValuePair(StatDefOf.MeleeDPS, PosMin(mainJob)); + yield return new KeyValuePair(StatDefOf.MeleeHitChance, PosMin(mainJob)); + yield return new KeyValuePair(StatDefOf.ArmorRating_Blunt, PosMin(mainJob)); + yield return new KeyValuePair(StatDefOf.ArmorRating_Sharp, PosMin(mainJob)); yield return new KeyValuePair(StatDefOf.RangedWeapon_Cooldown, NegMax(mainJob)); - yield return new KeyValuePair(StatDefOf.AimingDelayFactor, NegMax(mainJob)); - yield return new KeyValuePair(StatDefOf.PainShockThreshold, PosMax(mainJob)); + yield return new KeyValuePair(StatDefOf.AimingDelayFactor, NegMax(mainJob)); + yield return new KeyValuePair(StatDefOf.PainShockThreshold, PosMax(mainJob)); yield break; case Vanilla.Construction: - if (pawnSave.mainJob == MainJob.Constructor) + if (pawnSave.MainJob == MainJob.Constructor) { mainJob = true; } if (!DefDatabase.AllDefsListForReading.Any( - x => x.defName == FSF.Repair || x.defName == Splitter.Repair)) + x => x.defName == FSF.Repair || + x.defName == Splitter.Repair)) { yield return new KeyValuePair( - StatDefOf.FixBrokenDownBuildingSuccessChance, - PosMax(mainJob)); + StatDefOf.FixBrokenDownBuildingSuccessChance, + PosMax(mainJob)); } - yield return new KeyValuePair(StatDefOf.ConstructionSpeed, PosMax(mainJob)); + yield return new KeyValuePair(StatDefOf.ConstructionSpeed, PosMax(mainJob)); yield return new KeyValuePair(StatDefOf.ConstructSuccessChance, PosMax(mainJob)); - yield return new KeyValuePair(StatDefOf.SmoothingSpeed, PosMax(mainJob)); + yield return new KeyValuePair(StatDefOf.SmoothingSpeed, PosMax(mainJob)); // yield return new KeyValuePair(StatDefOf.CarryingCapacity, PosMin(mainJob)); - yield return new KeyValuePair(StatDefOf.MoveSpeed, PosMin(mainJob)); + yield return new KeyValuePair(StatDefOf.MoveSpeed, PosMin(mainJob)); yield return new KeyValuePair(StatDefOf.WorkSpeedGlobal, PosMin(mainJob)); yield break; case Vanilla.Growing: - if (pawnSave.mainJob == MainJob.Grower) + if (pawnSave.MainJob == MainJob.Grower) { mainJob = true; } @@ -809,23 +828,23 @@ private static IEnumerable> GetStatsOfWorkType([Not yield return new KeyValuePair(StatDefOf.PlantHarvestYield, PosMax(mainJob)); } - yield return new KeyValuePair(StatDefOf.PlantWorkSpeed, PosMax(mainJob)); - yield return new KeyValuePair(StatDefOf.MoveSpeed, PosMin(mainJob)); + yield return new KeyValuePair(StatDefOf.PlantWorkSpeed, PosMax(mainJob)); + yield return new KeyValuePair(StatDefOf.MoveSpeed, PosMin(mainJob)); yield return new KeyValuePair(StatDefOf.WorkSpeedGlobal, PosMin(mainJob)); yield break; case Splitter.Harvesting: - if (pawnSave.mainJob == MainJob.Grower) + if (pawnSave.MainJob == MainJob.Grower) { mainJob = true; } yield return new KeyValuePair(StatDefOf.PlantHarvestYield, PosMax(mainJob)); - yield return new KeyValuePair(StatDefOf.WorkSpeedGlobal, PosMin(mainJob)); + yield return new KeyValuePair(StatDefOf.WorkSpeedGlobal, PosMin(mainJob)); yield break; case Vanilla.Mining: - if (pawnSave.mainJob == MainJob.Miner) + if (pawnSave.MainJob == MainJob.Miner) { mainJob = true; } @@ -835,7 +854,7 @@ private static IEnumerable> GetStatsOfWorkType([Not // yield return new KeyValuePair(StatDefOf.CarryingCapacity, PosMin(mainJob)); yield return new KeyValuePair(StatDefOf.WorkSpeedGlobal, PosMin(mainJob)); - yield return new KeyValuePair(StatDefOf.MoveSpeed, PosMin(mainJob)); + yield return new KeyValuePair(StatDefOf.MoveSpeed, PosMin(mainJob)); yield break; case Vanilla.PlantCutting: @@ -845,17 +864,17 @@ private static IEnumerable> GetStatsOfWorkType([Not yield break; case Vanilla.Smithing: - if (pawnSave.mainJob == MainJob.Smith) + if (pawnSave.MainJob == MainJob.Smith) { mainJob = true; } - yield return new KeyValuePair(StatDefOf2.SmithingSpeed, PosMax(mainJob)); + yield return new KeyValuePair(StatDefOf2.SmithingSpeed, PosMax(mainJob)); yield return new KeyValuePair(StatDefOf.WorkSpeedGlobal, PosMin(mainJob)); yield break; case Vanilla.Tailoring: - if (pawnSave.mainJob == MainJob.Tailor) + if (pawnSave.MainJob == MainJob.Tailor) { mainJob = true; } @@ -865,7 +884,7 @@ private static IEnumerable> GetStatsOfWorkType([Not yield break; case Vanilla.Art: - if (pawnSave.mainJob == MainJob.Artist) + if (pawnSave.MainJob == MainJob.Artist) { mainJob = true; } @@ -875,7 +894,7 @@ private static IEnumerable> GetStatsOfWorkType([Not yield break; case Vanilla.Crafting: - if (pawnSave.mainJob == MainJob.Crafter) + if (pawnSave.MainJob == MainJob.Crafter) { mainJob = true; } @@ -885,15 +904,15 @@ private static IEnumerable> GetStatsOfWorkType([Not yield return new KeyValuePair(StatDefOf2.SmeltingSpeed, PosMax(mainJob)); } - yield return new KeyValuePair(StatDefOf.WorkSpeedGlobal, PosMin(mainJob)); + yield return new KeyValuePair(StatDefOf.WorkSpeedGlobal, PosMin(mainJob)); yield return new KeyValuePair(StatDefOf2.ButcheryMechanoidSpeed, PosMed(mainJob)); yield return new KeyValuePair( - StatDefOf2.ButcheryMechanoidEfficiency, - PosMed(mainJob)); + StatDefOf2.ButcheryMechanoidEfficiency, + PosMed(mainJob)); yield break; case Splitter.Stonecutting: - if (pawnSave.mainJob == MainJob.Crafter) + if (pawnSave.MainJob == MainJob.Crafter) { mainJob = true; } @@ -902,32 +921,32 @@ private static IEnumerable> GetStatsOfWorkType([Not yield break; case Splitter.Smelting: - yield return new KeyValuePair(StatDefOf2.SmeltingSpeed, PosMax(mainJob)); + yield return new KeyValuePair(StatDefOf2.SmeltingSpeed, PosMax(mainJob)); yield return new KeyValuePair(StatDefOf.WorkSpeedGlobal, PosMin(mainJob)); yield break; case Vanilla.Hauling: - if (pawnSave.mainJob == MainJob.Hauler) + if (pawnSave.MainJob == MainJob.Hauler) { mainJob = true; } - yield return new KeyValuePair(StatDefOf.MoveSpeed, PosMax(mainJob)); + yield return new KeyValuePair(StatDefOf.MoveSpeed, PosMax(mainJob)); yield return new KeyValuePair(StatDefOf.CarryingCapacity, PosMin(mainJob)); yield break; case Vanilla.Cleaning: - yield return new KeyValuePair(StatDefOf.MoveSpeed, PosMax(mainJob)); + yield return new KeyValuePair(StatDefOf.MoveSpeed, PosMax(mainJob)); yield return new KeyValuePair(StatDefOf.WorkSpeedGlobal, PosMin(mainJob)); yield break; case Vanilla.Research: - if (pawnSave.mainJob == MainJob.Researcher) + if (pawnSave.MainJob == MainJob.Researcher) { mainJob = true; } - yield return new KeyValuePair(StatDefOf.ResearchSpeed, PosMax(mainJob)); + yield return new KeyValuePair(StatDefOf.ResearchSpeed, PosMax(mainJob)); yield return new KeyValuePair(StatDefOf.WorkSpeedGlobal, PosMin(mainJob)); yield break; @@ -941,7 +960,7 @@ private static IEnumerable> GetStatsOfWorkType([Not // Hospitality case Other.HospitalityDiplomat: - yield return new KeyValuePair(StatDefOf.SocialImpact, PosMed(mainJob)); + yield return new KeyValuePair(StatDefOf.SocialImpact, PosMed(mainJob)); yield return new KeyValuePair(StatDefOf.DiplomacyPower, PosMax(mainJob)); yield break; @@ -949,31 +968,31 @@ private static IEnumerable> GetStatsOfWorkType([Not // Job Mods case FSF.Training: - if (pawnSave.mainJob == MainJob.Handler) + if (pawnSave.MainJob == MainJob.Handler) { mainJob = true; } yield return new KeyValuePair(StatDefOf.TrainAnimalChance, PosMax(mainJob)); - yield return new KeyValuePair(StatDefOf.TameAnimalChance, PosMax(mainJob)); + yield return new KeyValuePair(StatDefOf.TameAnimalChance, PosMax(mainJob)); yield return new KeyValuePair(StatDefOf.ArmorRating_Sharp, PosMin(mainJob)); - yield return new KeyValuePair(StatDefOf.MeleeDodgeChance, PosMed(mainJob)); - yield return new KeyValuePair(StatDefOf.MeleeHitChance, PosMin(mainJob)); - yield return new KeyValuePair(StatDefOf.MoveSpeed, PosMin(mainJob)); - yield return new KeyValuePair(StatDefOf.MeleeDPS, PosMin(mainJob)); - yield return new KeyValuePair(StatDefOf.AccuracyTouch, PosMin(mainJob)); + yield return new KeyValuePair(StatDefOf.MeleeDodgeChance, PosMed(mainJob)); + yield return new KeyValuePair(StatDefOf.MeleeHitChance, PosMin(mainJob)); + yield return new KeyValuePair(StatDefOf.MoveSpeed, PosMin(mainJob)); + yield return new KeyValuePair(StatDefOf.MeleeDPS, PosMin(mainJob)); + yield return new KeyValuePair(StatDefOf.AccuracyTouch, PosMin(mainJob)); yield return new KeyValuePair( - StatDefOf.MeleeWeapon_CooldownMultiplier, - NegMin(mainJob)); + StatDefOf.MeleeWeapon_CooldownMultiplier, + NegMin(mainJob)); yield return new KeyValuePair( - StatDefOf.MeleeWeapon_DamageMultiplier, - PosMin(mainJob)); + StatDefOf.MeleeWeapon_DamageMultiplier, + PosMin(mainJob)); yield return new KeyValuePair(StatDefOf.PainShockThreshold, PosMax(mainJob)); yield break; case Splitter.Training: - if (pawnSave.mainJob == MainJob.Handler) + if (pawnSave.MainJob == MainJob.Handler) { mainJob = true; } @@ -982,42 +1001,42 @@ private static IEnumerable> GetStatsOfWorkType([Not yield break; case Splitter.Taming: - if (pawnSave.mainJob == MainJob.Handler) + if (pawnSave.MainJob == MainJob.Handler) { mainJob = true; } - yield return new KeyValuePair(StatDefOf.TameAnimalChance, PosMax(mainJob)); + yield return new KeyValuePair(StatDefOf.TameAnimalChance, PosMax(mainJob)); yield return new KeyValuePair(StatDefOf.ArmorRating_Blunt, PosMin(mainJob)); yield return new KeyValuePair(StatDefOf.ArmorRating_Sharp, PosMin(mainJob)); - yield return new KeyValuePair(StatDefOf.MeleeDodgeChance, PosMed(mainJob)); - yield return new KeyValuePair(StatDefOf.MeleeHitChance, PosMin(mainJob)); - yield return new KeyValuePair(StatDefOf.MoveSpeed, PosMin(mainJob)); - yield return new KeyValuePair(StatDefOf.MeleeDPS, PosMin(mainJob)); - yield return new KeyValuePair(StatDefOf.AccuracyTouch, PosMin(mainJob)); + yield return new KeyValuePair(StatDefOf.MeleeDodgeChance, PosMed(mainJob)); + yield return new KeyValuePair(StatDefOf.MeleeHitChance, PosMin(mainJob)); + yield return new KeyValuePair(StatDefOf.MoveSpeed, PosMin(mainJob)); + yield return new KeyValuePair(StatDefOf.MeleeDPS, PosMin(mainJob)); + yield return new KeyValuePair(StatDefOf.AccuracyTouch, PosMin(mainJob)); yield return new KeyValuePair( - StatDefOf.MeleeWeapon_CooldownMultiplier, - NegMin(mainJob)); + StatDefOf.MeleeWeapon_CooldownMultiplier, + NegMin(mainJob)); yield return new KeyValuePair( - StatDefOf.MeleeWeapon_DamageMultiplier, - PosMin(mainJob)); + StatDefOf.MeleeWeapon_DamageMultiplier, + PosMin(mainJob)); yield break; case Splitter.Butcher: case FSF.Butcher: - if (pawnSave.mainJob == MainJob.Cook) + if (pawnSave.MainJob == MainJob.Cook) { mainJob = true; } - yield return new KeyValuePair(StatDefOf2.ButcheryFleshSpeed, PosMax(mainJob)); + yield return new KeyValuePair(StatDefOf2.ButcheryFleshSpeed, PosMax(mainJob)); yield return new KeyValuePair(StatDefOf2.ButcheryFleshEfficiency, PosMax(mainJob)); yield break; case Splitter.Brewing: case FSF.Brewing: - if (pawnSave.mainJob == MainJob.Cook) + if (pawnSave.MainJob == MainJob.Cook) { mainJob = true; } @@ -1027,19 +1046,19 @@ private static IEnumerable> GetStatsOfWorkType([Not case Splitter.Repair: case FSF.Repair: - if (pawnSave.mainJob == MainJob.Constructor) + if (pawnSave.MainJob == MainJob.Constructor) { mainJob = true; } yield return new KeyValuePair( - StatDefOf.FixBrokenDownBuildingSuccessChance, - PosMax(mainJob)); + StatDefOf.FixBrokenDownBuildingSuccessChance, + PosMax(mainJob)); yield break; case Splitter.Drilling: case FSF.Drilling: - if (pawnSave.mainJob == MainJob.Miner) + if (pawnSave.MainJob == MainJob.Miner) { mainJob = true; } @@ -1065,14 +1084,14 @@ private static IEnumerable> GetStatsOfWorkType([Not case Splitter.Surgeon: case FSF.Surgeon: - if (pawnSave.mainJob == MainJob.Doctor) + if (pawnSave.MainJob == MainJob.Doctor) { mainJob = true; } yield return new KeyValuePair( - StatDefOf.MedicalSurgerySuccessChance, - PosMax(mainJob)); + StatDefOf.MedicalSurgerySuccessChance, + PosMax(mainJob)); yield return new KeyValuePair(StatDefOf2.MedicalOperationSpeed, PosMax(mainJob)); yield break; @@ -1080,8 +1099,8 @@ private static IEnumerable> GetStatsOfWorkType([Not if (!IgnoredWorktypeDefs.Contains(worktype.defName)) { Log.Warning( - "Outfitter: WorkTypeDef " + worktype.defName - + " not handled. \nThis is not a bug, just a notice for the mod author."); + "Outfitter: WorkTypeDef " + worktype.defName + + " not handled. \nThis is not a bug, just a notice for the mod author."); IgnoredWorktypeDefs.Add(worktype.defName); } diff --git a/Source/Outfitter/Cache.cs b/Source/Outfitter/Cache.cs index e181526..7031fe2 100644 --- a/Source/Outfitter/Cache.cs +++ b/Source/Outfitter/Cache.cs @@ -1,15 +1,12 @@ -namespace Outfitter -{ - using System; - using System.Collections.Generic; - using System.Linq; - - using JetBrains.Annotations; - - using RimWorld; - - using Verse; +using System; +using System.Collections.Generic; +using System.Linq; +using JetBrains.Annotations; +using RimWorld; +using Verse; +namespace Outfitter +{ public static class Cache { // ReSharper disable once FieldCanBeMadeReadOnly.Global @@ -22,7 +19,7 @@ public static float GetEquippedStatValue([NotNull] this Apparel apparel, Pawn pa float baseStat = pawn.def.statBases.GetStatValueFromList(stat, stat.defaultBaseValue); float equippedStatValue = apparel.def.equippedStatOffsets.GetStatOffsetFromList(stat); - if (!ApparelStatCache.specialStats.Contains(stat) && Math.Abs(baseStat) > 0f) + if (!ApparelStatCache.SpecialStats.Contains(stat) && Math.Abs(baseStat) > 0f) { return ((baseStat + equippedStatValue) / baseStat) - 1; } diff --git a/Source/Outfitter/Controller.cs b/Source/Outfitter/Controller.cs index 34b6627..879818d 100644 --- a/Source/Outfitter/Controller.cs +++ b/Source/Outfitter/Controller.cs @@ -1,31 +1,24 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; +using System.Linq; +using JetBrains.Annotations; +using RimWorld; +using UnityEngine; +using Verse; namespace Outfitter { - using JetBrains.Annotations; - - using RimWorld; - - using UnityEngine; - - using Verse; - class Controller : Mod { public Controller(ModContentPack content) : base(content) { - settings = this.GetSettings(); + Settings = this.GetSettings(); } - public static Settings settings; + public static Settings Settings; public override void DoSettingsWindowContents(Rect inRect) { - settings.DoWindowContents(inRect); + Settings.DoWindowContents(inRect); } [NotNull] @@ -37,7 +30,7 @@ public override string SettingsCategory() public override void WriteSettings() { base.WriteSettings(); - settings.Write(); + Settings.Write(); if (Current.ProgramState == ProgramState.Playing) { @@ -61,7 +54,7 @@ public override void WriteSettings() BodyPartRecord rightEye = head.parts.FirstOrDefault(x => x.def == BodyPartDefOf.RightEye); BodyPartRecord jaw = head.parts.FirstOrDefault(x => x.def == BodyPartDefOf.Jaw); - if (settings.UseEyes) + if (Settings.UseEyes) { leftEye?.groups.Remove(BodyPartGroupDefOf.FullHead); rightEye?.groups.Remove(BodyPartGroupDefOf.FullHead); diff --git a/Source/Outfitter/Enums/MainJob.cs b/Source/Outfitter/Enums/MainJob.cs index df60d94..da5b605 100644 --- a/Source/Outfitter/Enums/MainJob.cs +++ b/Source/Outfitter/Enums/MainJob.cs @@ -4,9 +4,9 @@ public enum MainJob { Anything, - Soldier00Close_Combat, + Soldier00CloseCombat, - Soldier00Ranged_Combat, + Soldier00RangedCombat, Artist, diff --git a/Source/Outfitter/Filter/SpecialThingFilterWorker_DeadmansApparel.cs b/Source/Outfitter/Filter/SpecialThingFilterWorker_DeadmansApparel.cs index 6a128ea..0cf4113 100644 --- a/Source/Outfitter/Filter/SpecialThingFilterWorker_DeadmansApparel.cs +++ b/Source/Outfitter/Filter/SpecialThingFilterWorker_DeadmansApparel.cs @@ -1,9 +1,8 @@ -namespace Outfitter.Filter -{ - using RimWorld; - - using Verse; +using RimWorld; +using Verse; +namespace Outfitter.Filter +{ public class SpecialThingFilterWorker_DeadmansApparel : SpecialThingFilterWorker { public override bool CanEverMatch(ThingDef def) diff --git a/Source/Outfitter/GameComponent_Outfitter.cs b/Source/Outfitter/GameComponent_Outfitter.cs index c5d39c2..18f52ca 100644 --- a/Source/Outfitter/GameComponent_Outfitter.cs +++ b/Source/Outfitter/GameComponent_Outfitter.cs @@ -1,17 +1,15 @@ -namespace Outfitter -{ - using System; - using System.Collections.Generic; - using System.Linq; - - using JetBrains.Annotations; - - using RimWorld; - - using Verse; +using System.Collections.Generic; +using System.Linq; +using JetBrains.Annotations; +using RimWorld; +using Verse; +namespace Outfitter +{ public class GameComponent_Outfitter : GameComponent { + private readonly Game _game; + [NotNull] public List PawnCache = new List(); @@ -22,7 +20,8 @@ public GameComponent_Outfitter() // ReSharper disable once UnusedMember.Global public GameComponent_Outfitter(Game game) { - if (Controller.settings.UseEyes) + this._game = game; + if (Controller.Settings.UseEyes) { foreach (BodyDef bodyDef in DefDatabase.AllDefsListForReading) { @@ -56,23 +55,27 @@ public GameComponent_Outfitter(Game game) foreach (ThingDef def in DefDatabase.AllDefsListForReading.Where( td => td.category == ThingCategory.Pawn && td.race.Humanlike)) { - if (def.inspectorTabs == null) + // if (def.inspectorTabs == null) + // { + // def.inspectorTabs = new List(); + // } + // + // if (def.inspectorTabsResolved == null) + // { + // def.inspectorTabsResolved = new List(); + // } + if (def.inspectorTabs == null || def.inspectorTabsResolved == null) { - def.inspectorTabs = new List(); - } - - if (def.inspectorTabsResolved == null) - { - def.inspectorTabsResolved = new List(); + return; } - if (def.inspectorTabs.Contains(typeof(ITab_Pawn_Outfitter))) + if (def.inspectorTabs.Contains(typeof(Tab_Pawn_Outfitter))) { return; } - def.inspectorTabs.Add(typeof(ITab_Pawn_Outfitter)); - def.inspectorTabsResolved.Add(InspectTabManager.GetSharedInstance(typeof(ITab_Pawn_Outfitter))); + def.inspectorTabs.Add(typeof(Tab_Pawn_Outfitter)); + def.inspectorTabsResolved.Add(InspectTabManager.GetSharedInstance(typeof(Tab_Pawn_Outfitter))); } } diff --git a/Source/Outfitter/HarmonyPatches.cs b/Source/Outfitter/HarmonyPatches.cs index 6f71847..f6ab15a 100644 --- a/Source/Outfitter/HarmonyPatches.cs +++ b/Source/Outfitter/HarmonyPatches.cs @@ -5,19 +5,15 @@ // public override string ModIdentifier { get { return "Outfitter"; } } // } -using System.Collections.Generic; using System.Linq; using System.Reflection; - using Harmony; - using Outfitter; using Outfitter.TabPatch; - using RimWorld; - using Verse; -using Verse.AI; + +// ReSharper disable InconsistentNaming [StaticConstructorOnStartup] internal static class HarmonyPatches @@ -30,8 +26,7 @@ static HarmonyPatches() harmony.Patch( AccessTools.Method(typeof(PawnGraphicSet), nameof(PawnGraphicSet.ResolveApparelGraphics)), null, - new HarmonyMethod(typeof(HarmonyPatches), nameof(ResolveApparelGraphics_Postfix)), - null); + new HarmonyMethod(typeof(HarmonyPatches), nameof(ResolveApparelGraphics_Postfix))); // harmony.Patch( // AccessTools.Method(typeof(InspectPaneUtility), "DoTabs"), @@ -57,12 +52,12 @@ static HarmonyPatches() harmony.Patch( AccessTools.Method(typeof(ITab_Bills), "FillTab"), - new HarmonyMethod(typeof(ITab_Bills_Patch), nameof(ITab_Bills_Patch.FillTab_Prefix)), + new HarmonyMethod(typeof(Tab_Bills_Patch), nameof(Tab_Bills_Patch.FillTab_Prefix)), null); harmony.Patch( AccessTools.Method(typeof(ITab_Bills), "TabUpdate"), - new HarmonyMethod(typeof(ITab_Bills_Patch), nameof(ITab_Bills_Patch.TabUpdate_Prefix)), + new HarmonyMethod(typeof(Tab_Bills_Patch), nameof(Tab_Bills_Patch.TabUpdate_Prefix)), null); // harmony.Patch( @@ -80,18 +75,6 @@ static HarmonyPatches() "Outfitter successfully completed " + harmony.GetPatchedMethods().Count() + " patches with harmony."); } - private static void LogJobActivities( - ThinkNode_JobGiver __instance, - ThinkResult __result, - Pawn pawn, - JobIssueParams jobParams) - { - // if (__result.Job.def.driverClass.) - // { - // __result.Job. - // } - } - private static void ResolveApparelGraphics_Postfix(PawnGraphicSet __instance) { __instance.apparelGraphics = __instance.apparelGraphics @@ -103,6 +86,9 @@ private static void UpdatePriorities(Pawn_WorkSettings __instance) FieldInfo fieldInfo = typeof(Pawn_WorkSettings).GetField("pawn", BindingFlags.NonPublic | BindingFlags.Instance); Pawn pawn = (Pawn)fieldInfo?.GetValue(__instance); - pawn.GetSaveablePawn().ForceStatUpdate = true; + if (pawn != null) + { + pawn.GetSaveablePawn().ForceStatUpdate = true; + } } } \ No newline at end of file diff --git a/Source/Outfitter/JobGiver_OutfitterOptimizeApparel.cs b/Source/Outfitter/JobGiver_OutfitterOptimizeApparel.cs index 2275c22..49449d7 100644 --- a/Source/Outfitter/JobGiver_OutfitterOptimizeApparel.cs +++ b/Source/Outfitter/JobGiver_OutfitterOptimizeApparel.cs @@ -1,32 +1,37 @@ -namespace Outfitter +using System.Collections.Generic; +using System.Linq; +using System.Text; +using JetBrains.Annotations; +using RimWorld; +using UnityEngine; +using Verse; +using Verse.AI; + +namespace Outfitter { - using System.Collections.Generic; - using System.Linq; - using System.Text; - - using JetBrains.Annotations; - - using RimWorld; - - using UnityEngine; - - using Verse; - using Verse.AI; - public static class JobGiver_OutfitterOptimizeApparel { - public const int ApparelStatCheck = 3750; - - private const int ApparelOptimizeCheckIntervalMin = 6000; + #region Public Fields - private const int ApparelOptimizeCheckIntervalMax = 9000; + public const int ApparelStatCheck = 3750; // private const int ApparelOptimizeCheckIntervalMin = 9000; // private const int ApparelOptimizeCheckIntervalMax = 12000; public const float MinScoreGainToCare = 0.09f; + #endregion Public Fields + + #region Private Fields + + private const int ApparelOptimizeCheckIntervalMax = 9000; + private const int ApparelOptimizeCheckIntervalMin = 6000; + // private const float MinScoreGainToCare = 0.15f; - private static StringBuilder debugSb; + private static StringBuilder _debugSb; + + #endregion Private Fields + + #region Public Methods // private static Apparel lastItem; public static void SetNextOptimizeTick([NotNull] Pawn pawn) @@ -42,7 +47,8 @@ public static void SetNextOptimizeTick([NotNull] Pawn pawn) } // private static NeededWarmth neededWarmth; - public static bool TryGiveJob_Prefix(ref Job __result, Pawn pawn) + // ReSharper disable once InconsistentNaming + public static bool TryGiveJob_Prefix([CanBeNull] ref Job __result, Pawn pawn) { __result = null; if (pawn.outfits == null) @@ -68,8 +74,8 @@ public static bool TryGiveJob_Prefix(ref Job __result, Pawn pawn) } else { - debugSb = new StringBuilder(); - debugSb.AppendLine(string.Concat("Outfiter scanning for ", pawn, " at ", pawn.Position)); + _debugSb = new StringBuilder(); + _debugSb.AppendLine(string.Concat("Outfiter scanning for ", pawn, " at ", pawn.Position)); } Outfit currentOutfit = pawn.outfits.CurrentOutfit; @@ -145,8 +151,9 @@ public static bool TryGiveJob_Prefix(ref Job __result, Pawn pawn) // } if (DebugViewSettings.debugApparelOptimize) { - debugSb.AppendLine(apparel.LabelCap + ": " + gain.ToString("F2")); + _debugSb.AppendLine(apparel.LabelCap + ": " + gain.ToString("F2")); } + // float otherGain = 0f; // Pawn otherPawn = null; // foreach (Pawn otherP in pawn.Map.mapPawns.FreeColonistsSpawned.ToList()) @@ -174,7 +181,7 @@ public static bool TryGiveJob_Prefix(ref Job __result, Pawn pawn) { if (ApparelUtility.HasPartsToWear(pawn, apparel.def)) { - if (pawn.CanReserveAndReach(apparel, PathEndMode.OnCell, pawn.NormalMaxDanger(), 1)) + if (pawn.CanReserveAndReach(apparel, PathEndMode.OnCell, pawn.NormalMaxDanger())) { thing = apparel; score = gain; @@ -185,9 +192,9 @@ public static bool TryGiveJob_Prefix(ref Job __result, Pawn pawn) if (DebugViewSettings.debugApparelOptimize) { - debugSb.AppendLine("BEST: " + thing); - Log.Message(debugSb.ToString()); - debugSb = null; + _debugSb.AppendLine("BEST: " + thing); + Log.Message(_debugSb.ToString()); + _debugSb = null; } // New stuff @@ -237,5 +244,7 @@ public static bool TryGiveJob_Prefix(ref Job __result, Pawn pawn) pawn.Reserve(thing, __result, 1, 1); return false; } + + #endregion Public Methods } } \ No newline at end of file diff --git a/Source/Outfitter/Optional/Class1.cs b/Source/Outfitter/Optional/Class1.cs index b8a0275..5814d4b 100644 --- a/Source/Outfitter/Optional/Class1.cs +++ b/Source/Outfitter/Optional/Class1.cs @@ -1,29 +1,27 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; +using Harmony; +using ImprovedWorkbenches; +using Outfitter.TabPatch; +using Verse; namespace Outfitter.Optional { - using Harmony; - - using Outfitter.TabPatch; - - using Verse; - - public class PatchBW : GameComponent + public class PatchBw : GameComponent { - public PatchBW(Game game) + private readonly Game _game; + + public PatchBw(Game game) { + this._game = game; try { ((Action)(() => { if (AccessTools.Method( - typeof(ImprovedWorkbenches.BillStack_DoListing_Detour), - nameof(ImprovedWorkbenches.BillStack_DoListing_Detour.Postfix)) != null) + typeof(BillStack_DoListing_Detour), + nameof(BillStack_DoListing_Detour.Postfix)) != null) { - ITab_Bills_Patch.DoBWMPostfix += ImprovedWorkbenches.BillStack_DoListing_Detour.Postfix; + Tab_Bills_Patch.DoBwmPostfix += BillStack_DoListing_Detour.Postfix; } }))(); } diff --git a/Source/Outfitter/Outfitter.csproj b/Source/Outfitter/Outfitter.csproj index fe62915..930d115 100644 --- a/Source/Outfitter/Outfitter.csproj +++ b/Source/Outfitter/Outfitter.csproj @@ -62,6 +62,10 @@ ..\..\..\..\..\..\workshop\content\294100\935982361\Assemblies\ImprovedWorkbenches.dll False + + ..\..\..\..\..\..\workshop\content\294100\731287727\Assemblies\Infused.dll + False + diff --git a/Source/Outfitter/Saveables/Saveable_Pawn.cs b/Source/Outfitter/Saveables/Saveable_Pawn.cs index f12b8f3..1b5e01f 100644 --- a/Source/Outfitter/Saveables/Saveable_Pawn.cs +++ b/Source/Outfitter/Saveables/Saveable_Pawn.cs @@ -1,43 +1,40 @@ -namespace Outfitter -{ - using System.Collections.Generic; - - using Outfitter.Enums; - - using RimWorld; - - using Verse; +using System.Collections.Generic; +using Outfitter.Enums; +using RimWorld; +using Verse; +namespace Outfitter +{ public class SaveablePawn : IExposable { public List ApparelStats = new List(); - public List toWear = new List(); + public List ToWear = new List(); - public List toDrop = new List(); + public List ToDrop = new List(); - public bool armorOnly; + public bool ArmorOnly; public bool AutoEquipWeapon; // public FloatRange RealComfyTemperatures; - private bool forceStatUpdate; + private bool _forceStatUpdate; public bool ForceStatUpdate { get { - return this.forceStatUpdate; + return this._forceStatUpdate; } set { - this.forceStatUpdate = value; + this._forceStatUpdate = value; } } - public MainJob mainJob; + public MainJob MainJob; // Exposed members public Pawn Pawn; @@ -50,35 +47,35 @@ public bool ForceStatUpdate public FloatRange Temperatureweight; - private bool addIndividualStats = true; - private bool addPersonalStats = true; + private bool _addIndividualStats = true; + private bool _addPersonalStats = true; - private bool addWorkStats = true; + private bool _addWorkStats = true; public bool AddIndividualStats { - get => this.addIndividualStats; + get => this._addIndividualStats; set { - this.addIndividualStats = value; + this._addIndividualStats = value; } } public bool AddPersonalStats { - get => this.addPersonalStats; + get => this._addPersonalStats; set { - this.addPersonalStats = value; + this._addPersonalStats = value; } } public bool AddWorkStats { - get => this.addWorkStats; + get => this._addWorkStats; set { - this.addWorkStats = value; + this._addWorkStats = value; } } @@ -100,10 +97,10 @@ public void ExposeData() // todo: rename with next big version Scribe_Collections.Look(ref this.ApparelStats, "WeaponStats", LookMode.Deep); - Scribe_Values.Look(ref this.addWorkStats, "AddWorkStats", true); - Scribe_Values.Look(ref this.addIndividualStats, "AddIndividualStats", true); - Scribe_Values.Look(ref this.addPersonalStats, "addPersonalStats", true); - Scribe_Values.Look(ref this.mainJob, "mainJob"); + Scribe_Values.Look(ref this._addWorkStats, "AddWorkStats", true); + Scribe_Values.Look(ref this._addIndividualStats, "AddIndividualStats", true); + Scribe_Values.Look(ref this._addPersonalStats, "addPersonalStats", true); + Scribe_Values.Look(ref this.MainJob, "mainJob"); } } } \ No newline at end of file diff --git a/Source/Outfitter/Saveables/Saveable_Pawn_StatDef.cs b/Source/Outfitter/Saveables/Saveable_Pawn_StatDef.cs index 1aa717a..bf7df90 100644 --- a/Source/Outfitter/Saveables/Saveable_Pawn_StatDef.cs +++ b/Source/Outfitter/Saveables/Saveable_Pawn_StatDef.cs @@ -1,35 +1,33 @@ -namespace Outfitter -{ - using Outfitter.Enums; - - using RimWorld; - - using Verse; +using Outfitter.Enums; +using RimWorld; +using Verse; +namespace Outfitter +{ public class Saveable_Pawn_StatDef : IExposable { - private StatAssignment assignment; + private StatAssignment _assignment; - private StatDef stat; + private StatDef _stat; - private float weight; + private float _weight; public StatAssignment Assignment { - get => this.assignment; - set => this.assignment = value; + get => this._assignment; + set => this._assignment = value; } public StatDef Stat { - get => this.stat; - set => this.stat = value; + get => this._stat; + set => this._stat = value; } public float Weight { - get => this.weight; - set => this.weight = value; + get => this._weight; + set => this._weight = value; } /* @@ -49,9 +47,9 @@ public Saveable_Pawn_StatDef(KeyValuePair statDefWeightPair, Sta */ public void ExposeData() { - Scribe_Defs.Look(ref this.stat, "Stat"); - Scribe_Values.Look(ref this.assignment, "Assignment"); - Scribe_Values.Look(ref this.weight, "Weight"); + Scribe_Defs.Look(ref this._stat, "Stat"); + Scribe_Values.Look(ref this._assignment, "Assignment"); + Scribe_Values.Look(ref this._weight, "Weight"); } } } \ No newline at end of file diff --git a/Source/Outfitter/Settings.cs b/Source/Outfitter/Settings.cs index 0836743..54e9d1d 100644 --- a/Source/Outfitter/Settings.cs +++ b/Source/Outfitter/Settings.cs @@ -1,17 +1,12 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; +using UnityEngine; +using Verse; namespace Outfitter { - using UnityEngine; - - using Verse; public class Settings : ModSettings { - public bool UseEyes => this.useEyes; - private bool useEyes; + public bool UseEyes => this._useEyes; + private bool _useEyes; public void DoWindowContents(Rect inRect) { Listing_Standard list = new Listing_Standard { ColumnWidth = inRect.width / 2 }; @@ -21,7 +16,7 @@ public void DoWindowContents(Rect inRect) list.CheckboxLabeled( "Settings.UseEyes".Translate(), - ref this.useEyes, + ref this._useEyes, "Settings.UseEyesTooltip".Translate()); list.End(); @@ -56,7 +51,7 @@ public void DoWindowContents(Rect inRect) public override void ExposeData() { base.ExposeData(); - Scribe_Values.Look(ref this.useEyes, "useEyes", false, true); + Scribe_Values.Look(ref this._useEyes, "useEyes", false, true); } } } diff --git a/Source/Outfitter/Stats/StatDefOf2.cs b/Source/Outfitter/Stats/StatDefOf2.cs index 015f199..8d8580c 100644 --- a/Source/Outfitter/Stats/StatDefOf2.cs +++ b/Source/Outfitter/Stats/StatDefOf2.cs @@ -1,7 +1,7 @@ -namespace Outfitter -{ - using RimWorld; +using RimWorld; +namespace Outfitter +{ // Not covered by vanilla [DefOf] public static class StatDefOf2 diff --git a/Source/Outfitter/Stats/StatPriority.cs b/Source/Outfitter/Stats/StatPriority.cs index ed60df8..fe86ffb 100644 --- a/Source/Outfitter/Stats/StatPriority.cs +++ b/Source/Outfitter/Stats/StatPriority.cs @@ -4,18 +4,14 @@ // // Created 2016-01-02 13:58 +using System.Collections.Generic; +using JetBrains.Annotations; +using Outfitter.Enums; +using RimWorld; +using Verse; + namespace Outfitter { - using System.Collections.Generic; - - using JetBrains.Annotations; - - using Outfitter.Enums; - - using RimWorld; - - using Verse; - public class StatPriority { public StatPriority(StatDef stat, float priority, StatAssignment assignment = StatAssignment.Automatic) diff --git a/Source/Outfitter/TabPatch/ITab_Bills_Patch.cs b/Source/Outfitter/TabPatch/ITab_Bills_Patch.cs index 27776e0..857c2e9 100644 --- a/Source/Outfitter/TabPatch/ITab_Bills_Patch.cs +++ b/Source/Outfitter/TabPatch/ITab_Bills_Patch.cs @@ -1,30 +1,26 @@ -namespace Outfitter.TabPatch +using System; +using System.Collections.Generic; +using System.Linq; +using KillfaceTools.FMO; +using RimWorld; +using UnityEngine; +using Verse; + +namespace Outfitter.TabPatch { - using System; - using System.Collections.Generic; - using System.Linq; - - using KillfaceTools.FMO; - - using RimWorld; - - using UnityEngine; - - using Verse; - - public static class ITab_Bills_Patch + public static class Tab_Bills_Patch { private const string Separator = " "; - private const string newLine = "\n-------------------------------"; + private const string NewLine = "\n-------------------------------"; - private static float viewHeight = 1000f; + private static float _viewHeight = 1000f; - private static Vector2 scrollPosition; + private static Vector2 _scrollPosition; private static readonly Vector2 WinSize = new Vector2(420f, 480f); - private static Bill mouseoverBill; + private static Bill _mouseoverBill; // RimWorld.ITab_Bills public static bool FillTab_Prefix() @@ -106,7 +102,7 @@ void Action() (float)(rect.y + (rect.height - 24.0) / 2.0), recipe)); - dictionary.Add(recipe.LabelCap, new List() { floatMenuOption }); + dictionary.Add(recipe.LabelCap, new List { floatMenuOption }); } } @@ -119,7 +115,7 @@ void Action() ThingCountClass recipeProduct = recipe.products.FirstOrDefault(); List colonistsWithThing = new List(); - if (recipeProduct.thingDef.IsApparel) + if (recipeProduct != null && recipeProduct.thingDef.IsApparel) { colonistsWithThing = selTable.Map.mapPawns.FreeColonistsSpawned .Where(p => p.apparel.WornApparel.Any(ap => ap.def == recipeProduct.thingDef)) @@ -143,68 +139,71 @@ void MouseoverGuiAction() tooltip += "\n"; - ThingDef thingDef = recipeProduct.thingDef; - for (int index = 0; index < thingDef.apparel.bodyPartGroups.Count; index++) + if (recipeProduct != null) { - BodyPartGroupDef bpg = thingDef.apparel.bodyPartGroups[index]; - if (index > 0) + ThingDef thingDef = recipeProduct.thingDef; + for (int index = 0; index < thingDef.apparel.bodyPartGroups.Count; index++) { - tooltip += ", "; - } - - tooltip += bpg.LabelCap; - } + BodyPartGroupDef bpg = thingDef.apparel.bodyPartGroups[index]; + if (index > 0) + { + tooltip += ", "; + } - tooltip += "\n"; - for (int index = 0; index < thingDef.apparel.layers.Count; index++) - { - ApparelLayer layer = thingDef.apparel.layers[index]; - if (index > 0) - { - tooltip += ", "; + tooltip += bpg.LabelCap; } - tooltip += layer.ToString(); - } - - List statBases = - thingDef.statBases.Where(bing => bing.stat.category == StatCategoryDefOf.Apparel) - .ToList(); - if (!statBases.NullOrEmpty()) - { - // tooltip = StatCategoryDefOf.Apparel.LabelCap; - // tooltip += "\n-------------------------------"; tooltip += "\n"; - for (int index = 0; index < statBases.Count; index++) + for (int index = 0; index < thingDef.apparel.layers.Count; index++) { - StatModifier statOffset = statBases[index]; + ApparelLayer layer = thingDef.apparel.layers[index]; + if (index > 0) { - // if (index > 0) - tooltip += "\n"; + tooltip += ", "; } - tooltip += statOffset.stat.LabelCap + Separator - + statOffset.ValueToStringAsOffset; + tooltip += layer.ToString(); } - } - if (!thingDef.equippedStatOffsets.NullOrEmpty()) - { - // if (tooltip == string.Empty) - // { - // tooltip = StatCategoryDefOf.EquippedStatOffsets.LabelCap; - // } + List statBases = + thingDef.statBases.Where(bing => bing.stat.category == StatCategoryDefOf.Apparel) + .ToList(); + if (!statBases.NullOrEmpty()) { - // else - tooltip += "\n\n" + StatCategoryDefOf.EquippedStatOffsets.LabelCap; + // tooltip = StatCategoryDefOf.Apparel.LabelCap; + // tooltip += "\n-------------------------------"; + tooltip += "\n"; + for (int index = 0; index < statBases.Count; index++) + { + StatModifier statOffset = statBases[index]; + { + // if (index > 0) + tooltip += "\n"; + } + + tooltip += statOffset.stat.LabelCap + Separator + + statOffset.ValueToStringAsOffset; + } } - tooltip += newLine; - foreach (StatModifier statOffset in thingDef.equippedStatOffsets) + if (!thingDef.equippedStatOffsets.NullOrEmpty()) { - tooltip += "\n"; - tooltip += statOffset.stat.LabelCap + Separator - + statOffset.ValueToStringAsOffset; + // if (tooltip == string.Empty) + // { + // tooltip = StatCategoryDefOf.EquippedStatOffsets.LabelCap; + // } + { + // else + tooltip += "\n\n" + StatCategoryDefOf.EquippedStatOffsets.LabelCap; + } + + tooltip += NewLine; + foreach (StatModifier statOffset in thingDef.equippedStatOffsets) + { + tooltip += "\n"; + tooltip += statOffset.stat.LabelCap + Separator + + statOffset.ValueToStringAsOffset; + } } } @@ -282,30 +281,33 @@ void Action() // for (int j = 0; j < recipe.products.Count; j++) // { - int count = selTable.Map.listerThings.ThingsOfDef(recipeProduct.thingDef).Count; - - int wornCount = colonistsWithThing.Count; - - for (int k = 0; k < recipeProduct.thingDef?.apparel?.bodyPartGroups?.Count; k++) + if (recipeProduct != null) { - BodyPartGroupDef bPart = recipeProduct.thingDef.apparel.bodyPartGroups[k]; + int count = selTable.Map.listerThings.ThingsOfDef(recipeProduct.thingDef).Count; - string key = bPart.LabelCap + Tools.NestedString; + int wornCount = colonistsWithThing.Count; - if (!dictionary.ContainsKey(key)) + for (int k = 0; k < recipeProduct.thingDef?.apparel?.bodyPartGroups?.Count; k++) { - dictionary.Add(key, new List()); - } + BodyPartGroupDef bPart = recipeProduct.thingDef.apparel.bodyPartGroups[k]; - if (k == 0) - { - floatMenuOption.Label += " (" + count + "/" + wornCount + ")"; + string key = bPart.LabelCap + Tools.NestedString; - // + "\n" - // + recipeProduct.thingDef.equippedStatOffsets.ToStringSafeEnumerable(); - } + if (!dictionary.ContainsKey(key)) + { + dictionary.Add(key, new List()); + } - dictionary[key].Add(floatMenuOption); + if (k == 0) + { + floatMenuOption.Label += " (" + count + "/" + wornCount + ")"; + + // + "\n" + // + recipeProduct.thingDef.equippedStatOffsets.ToStringSafeEnumerable(); + } + + dictionary[key].Add(floatMenuOption); + } } } } @@ -314,7 +316,7 @@ void Action() // dictionary2 = dictionary2.OrderByDescending(c => c.Key).ToDictionary(KeyValuePair>); if (!dictionary.Any()) { - dictionary.Add("NoneBrackets".Translate(), new List() { null }); + dictionary.Add("NoneBrackets".Translate(), new List { null }); } // else @@ -332,7 +334,7 @@ void Action() return dictionary; }; - mouseoverBill = DoListing(selTable.BillStack, rect2, labeledSortingActions, ref scrollPosition, ref viewHeight); + _mouseoverBill = DoListing(selTable.BillStack, rect2, labeledSortingActions, ref _scrollPosition, ref _viewHeight); return false; } @@ -346,10 +348,10 @@ public static bool TabUpdate_Prefix() return true; } - if (mouseoverBill != null) + if (_mouseoverBill != null) { - mouseoverBill.TryDrawIngredientSearchRadiusOnMap(Find.Selector.SingleSelectedThing.Position); - mouseoverBill = null; + _mouseoverBill.TryDrawIngredientSearchRadiusOnMap(Find.Selector.SingleSelectedThing.Position); + _mouseoverBill = null; } return false; @@ -409,13 +411,13 @@ public static Bill DoListing(BillStack __instance, Rect rect, Func.Get("add"); diff --git a/Source/Outfitter/Window/Dialog_PawnApparelComparer.cs b/Source/Outfitter/Window/Dialog_PawnApparelComparer.cs index 3b270fb..0b83b00 100644 --- a/Source/Outfitter/Window/Dialog_PawnApparelComparer.cs +++ b/Source/Outfitter/Window/Dialog_PawnApparelComparer.cs @@ -1,25 +1,21 @@ -namespace Outfitter.Window +using System.Collections.Generic; +using System.Linq; +using JetBrains.Annotations; +using RimWorld; +using UnityEngine; +using Verse; + +namespace Outfitter.Window { - using System.Collections.Generic; - using System.Linq; - - using JetBrains.Annotations; - - using RimWorld; - - using UnityEngine; - - using Verse; - - public class Dialog_PawnApparelComparer : Window + public class Dialog_PawnApparelComparer : Verse.Window { [NotNull] - private readonly Apparel apparel; + private readonly Apparel _apparel; [NotNull] - private readonly Pawn pawn; + private readonly Pawn _pawn; - private Vector2 scrollPosition; + private Vector2 _scrollPosition; public Dialog_PawnApparelComparer(Pawn p, Apparel apparel) { @@ -27,28 +23,27 @@ public Dialog_PawnApparelComparer(Pawn p, Apparel apparel) this.closeOnEscapeKey = true; this.doCloseButton = true; - this.pawn = p; - this.apparel = apparel; + this._pawn = p; + this._apparel = apparel; } public override Vector2 InitialSize => new Vector2(500f, 700f); - private Dictionary dict; + private Dictionary _dict; private const float ScoreWidth = 100f; - public override void DoWindowContents(Rect windowRect) + public override void DoWindowContents(Rect inRect) { - ApparelStatCache apparelStatCache = this.pawn.GetApparelStatCache(); - Outfit currentOutfit = pawn.outfits.CurrentOutfit; + ApparelStatCache apparelStatCache = this._pawn.GetApparelStatCache(); + Outfit currentOutfit = this._pawn.outfits.CurrentOutfit; - if (this.dict == null || Find.TickManager.TicksGame % 60 == 0 || GUI.changed) + if (this._dict == null || Find.TickManager.TicksGame % 60 == 0 || GUI.changed) { - List ap = new List( - this.pawn.Map.listerThings.ThingsInGroup(ThingRequestGroup.Apparel).OfType().Where( + List ap = new List(this._pawn.Map.listerThings.ThingsInGroup(ThingRequestGroup.Apparel).OfType().Where( x => x.Map.slotGroupManager.SlotGroupAt(x.Position) != null)); - foreach (Pawn otherPawn in PawnsFinder.AllMaps_FreeColonists.Where(x => x.Map == this.pawn.Map)) + foreach (Pawn otherPawn in PawnsFinder.AllMaps_FreeColonists.Where(x => x.Map == this._pawn.Map)) { foreach (Apparel pawnApparel in otherPawn.apparel.WornApparel) { @@ -60,26 +55,26 @@ public override void DoWindowContents(Rect windowRect) } ap = ap.Where( - i => !ApparelUtility.CanWearTogether(this.apparel.def, i.def, this.pawn.RaceProps.body) + i => !ApparelUtility.CanWearTogether(this._apparel.def, i.def, this._pawn.RaceProps.body) && currentOutfit.filter.Allows(i)).ToList(); ap = ap.OrderByDescending( i => { - float g = this.pawn.ApparelScoreGain(i); + float g = this._pawn.ApparelScoreGain(i); return g; }).ToList(); - this.dict = new Dictionary(); + this._dict = new Dictionary(); foreach (Apparel currentAppel in ap) { - float gain = this.pawn.ApparelScoreGain(currentAppel); - this.dict.Add(currentAppel, gain); + float gain = this._pawn.ApparelScoreGain(currentAppel); + this._dict.Add(currentAppel, gain); } } - Rect groupRect = windowRect.ContractedBy(10f); + Rect groupRect = inRect.ContractedBy(10f); groupRect.height -= 100; GUI.BeginGroup(groupRect); @@ -113,8 +108,7 @@ public override void DoWindowContents(Rect windowRect) Rect viewRect = new Rect( groupRect.xMin, groupRect.yMin, - groupRect.width - 16f, - this.dict.Count * 28f + 16f); + groupRect.width - 16f, this._dict.Count * 28f + 16f); if (viewRect.height < groupRect.height) { groupRect.height = viewRect.height; @@ -122,10 +116,10 @@ public override void DoWindowContents(Rect windowRect) Rect listRect = viewRect.ContractedBy(4f); - Widgets.BeginScrollView(groupRect, ref this.scrollPosition, viewRect); + Widgets.BeginScrollView(groupRect, ref this._scrollPosition, viewRect); - foreach (KeyValuePair kvp in this.dict) + foreach (KeyValuePair kvp in this._dict) { Apparel currentAppel = kvp.Key; float gain = kvp.Value; @@ -140,7 +134,7 @@ public override void DoWindowContents(Rect windowRect) Pawn equipped = currentAppel.Wearer; Pawn target = null; - string gainString = this.pawn.outfits.forcedHandler.AllowedToAutomaticallyDrop(currentAppel) + string gainString = this._pawn.outfits.forcedHandler.AllowedToAutomaticallyDrop(currentAppel) ? gain.ToString("N3") : "No Allow"; @@ -323,8 +317,7 @@ private void DrawLine( Text.Anchor = TextAnchor.UpperLeft; if (Widgets.ButtonInvisible(fieldRect)) { - Find.WindowStack.Add(new Window_Pawn_ApparelDetail(this.pawn, apparelThing)); - return; + Find.WindowStack.Add(new Window_Pawn_ApparelDetail(this._pawn, apparelThing)); } } } diff --git a/Source/Outfitter/Window/ITab_Pawn_Outfitter.cs b/Source/Outfitter/Window/ITab_Pawn_Outfitter.cs index c548c41..055ebac 100644 --- a/Source/Outfitter/Window/ITab_Pawn_Outfitter.cs +++ b/Source/Outfitter/Window/ITab_Pawn_Outfitter.cs @@ -1,53 +1,51 @@ -namespace Outfitter +using JetBrains.Annotations; +using Outfitter.Enums; +using Outfitter.Textures; +using Outfitter.Window; +using RimWorld; +using System; +using System.Collections.Generic; +using System.Linq; +using UnityEngine; +using Verse; +using Verse.AI; +using Verse.Sound; + +namespace Outfitter { - using System; - using System.Collections.Generic; - using System.Linq; - - using JetBrains.Annotations; - - using Outfitter.Enums; - using Outfitter.Textures; - using Outfitter.Window; - - using RimWorld; - - using UnityEngine; - - using Verse; - using Verse.AI; - using Verse.Sound; - - public class ITab_Pawn_Outfitter : ITab + public class Tab_Pawn_Outfitter : ITab { - private const float ButtonHeight = 30f; - - private const float Margin = 10f; - - private const float ThingIconSize = 30f; - - private const float ThingLeftX = 40f; + #region Private Fields + private const float ButtonHeight = 30f; + private const float Margin = 10f; + private const float ThingIconSize = 30f; + private const float ThingLeftX = 40f; private const float ThingRowHeight = 64f; - private static readonly Color HighlightColor = new Color(0.5f, 0.5f, 0.5f, 1f); - + private static readonly Color HighlightColor = new Color(0.5f, 0.5f, 0.5f, 1f); private static readonly Color ThingLabelColor = new Color(0.9f, 0.9f, 0.9f, 1f); - private Vector2 scrollPosition = Vector2.zero; + private Vector2 _scrollPosition = Vector2.zero; + private Vector2 _scrollPosition1 = Vector2.zero; - private Vector2 scrollPosition1 = Vector2.zero; + private float _scrollViewHeight; + private float _scrollViewHeight1; - private float scrollViewHeight; + #endregion Private Fields - private float scrollViewHeight1; + #region Public Constructors - public ITab_Pawn_Outfitter() + public Tab_Pawn_Outfitter() { - this.size = new Vector2(770f, 550f); + this.size = new Vector2(770f, 550f); this.labelKey = "OutfitterTab"; } + #endregion Public Constructors + + #region Public Properties + public override bool IsVisible { get @@ -79,6 +77,10 @@ public override bool IsVisible } } + #endregion Public Properties + + #region Private Properties + private bool CanControl => this.SelPawn.IsColonistPlayerControlled; private Pawn SelPawnForGear @@ -90,8 +92,7 @@ private Pawn SelPawnForGear return this.SelPawn; } - Corpse corpse = this.SelThing as Corpse; - if (corpse != null) + if (this.SelThing is Corpse corpse) { return corpse.InnerPawn; } @@ -100,6 +101,10 @@ private Pawn SelPawnForGear } } + #endregion Private Properties + + #region Protected Methods + protected override void FillTab() { SaveablePawn pawnSave = this.SelPawnForGear.GetSaveablePawn(); @@ -122,9 +127,9 @@ protected override void FillTab() { Outfit localOut = current; options.Add( - new FloatMenuOption( - localOut.label, - delegate { this.SelPawnForGear.outfits.CurrentOutfit = localOut; })); + new FloatMenuOption( + localOut.label, + delegate { this.SelPawnForGear.outfits.CurrentOutfit = localOut; })); } FloatMenu window = new FloatMenu(options, "SelectOutfit".Translate()); @@ -134,38 +139,41 @@ protected override void FillTab() // edit outfit if (Widgets.ButtonText( - outfitEditRect, - "OutfitterEditOutfit".Translate() + " " + this.SelPawnForGear.outfits.CurrentOutfit.label + " ...")) + outfitEditRect, + "OutfitterEditOutfit".Translate() + " " + this.SelPawnForGear.outfits.CurrentOutfit.label + " ...")) { Find.WindowStack.Add(new Dialog_ManageOutfits(this.SelPawnForGear.outfits.CurrentOutfit)); } // job outfit if (Widgets.ButtonText( - outfitJobRect, - pawnSave.mainJob == MainJob.Anything - ? "MainJob".Translate() - : "PreferedGear".Translate() + " " + pawnSave.mainJob.ToString().Replace("00", " - ") - .Replace("_", " "))) + outfitJobRect, + pawnSave.MainJob == MainJob.Anything + ? "MainJob".Translate() + : "PreferedGear".Translate() + " " + pawnSave.MainJob.ToString() + .Replace("00", " - ") + .Replace("_", " "))) { List options = new List(); foreach (MainJob mainJob in Enum.GetValues(typeof(MainJob))) { options.Add( - new FloatMenuOption( - mainJob.ToString().Replace("00", " - ").Replace("_", " "), - delegate - { - pawnSave.mainJob = mainJob; - pawnSave.ForceStatUpdate = true; - - this.SelPawnForGear.mindState.Notify_OutfitChanged(); - if (this.SelPawnForGear.jobs.curJob != null - && this.SelPawnForGear.jobs.IsCurrentJobPlayerInterruptible()) - { - this.SelPawnForGear.jobs.EndCurrentJob(JobCondition.InterruptForced); - } - })); + new FloatMenuOption( + mainJob.ToString().Replace("00", " - ").Replace("_", " "), + delegate + { + pawnSave.MainJob = mainJob; + pawnSave.ForceStatUpdate = true; + + this.SelPawnForGear.mindState.Notify_OutfitChanged(); + + if (this.SelPawnForGear.jobs.curJob != null + && this.SelPawnForGear.jobs.IsCurrentJobPlayerInterruptible()) + { + this.SelPawnForGear.jobs.EndCurrentJob(JobCondition + .InterruptForced); + } + })); } FloatMenu window = new FloatMenu(options, "MainJob".Translate()); @@ -174,27 +182,25 @@ protected override void FillTab() } // Status checkboxes - Rect rectCheckboxes = new Rect(rectStatus.x, rectStatus.yMax + Margin, rectStatus.width, 72f); - Rect check1 = new Rect(rectCheckboxes.x, rectCheckboxes.y, rectCheckboxes.width, 24f); - Rect check2 = new Rect(rectCheckboxes.x, check1.yMax, rectCheckboxes.width, 24f); - Rect check3 = new Rect(rectCheckboxes.x, check2.yMax, rectCheckboxes.width, 24f); + Rect rectCheckboxes = new Rect(rectStatus.x, rectStatus.yMax + Margin, rectStatus.width, 72f); + Rect check1 = new Rect(rectCheckboxes.x, rectCheckboxes.y, rectCheckboxes.width, 24f); + Rect check2 = new Rect(rectCheckboxes.x, check1.yMax, rectCheckboxes.width, 24f); + Rect check3 = new Rect(rectCheckboxes.x, check2.yMax, rectCheckboxes.width, 24f); - bool pawnSaveAddWorkStats = pawnSave.AddWorkStats; + bool pawnSaveAddWorkStats = pawnSave.AddWorkStats; bool pawnSaveAddIndividualStats = pawnSave.AddIndividualStats; - bool pawnSaveAddPersonalStats = pawnSave.AddPersonalStats; - Widgets.CheckboxLabeled(check1, "AddWorkStats".Translate(), ref pawnSaveAddWorkStats); + bool pawnSaveAddPersonalStats = pawnSave.AddPersonalStats; + + Widgets.CheckboxLabeled(check1, "AddWorkStats".Translate(), ref pawnSaveAddWorkStats); Widgets.CheckboxLabeled(check2, "AddIndividualStats".Translate(), ref pawnSaveAddIndividualStats); - Widgets.CheckboxLabeled(check3, "AddPersonalStats".Translate(), ref pawnSaveAddPersonalStats); + Widgets.CheckboxLabeled(check3, "AddPersonalStats".Translate(), ref pawnSaveAddPersonalStats); if (GUI.changed) { - pawnSave.AddWorkStats = pawnSaveAddWorkStats; - + pawnSave.AddWorkStats = pawnSaveAddWorkStats; pawnSave.AddIndividualStats = pawnSaveAddIndividualStats; - - pawnSave.AddPersonalStats = pawnSaveAddPersonalStats; - - pawnSave.ForceStatUpdate = true; + pawnSave.AddPersonalStats = pawnSaveAddPersonalStats; + pawnSave.ForceStatUpdate = true; } // main canvas @@ -210,10 +216,14 @@ protected override void FillTab() this.DrawApparelList(); - GUI.color = Color.white; + GUI.color = Color.white; Text.Anchor = TextAnchor.UpperLeft; } + #endregion Protected Methods + + #region Private Methods + private void DrawApparelList() { // main canvas @@ -224,17 +234,18 @@ private void DrawApparelList() // Rect rect2 = rect.ContractedBy(10f); Rect calcScore = new Rect(rect.x, rect.y, rect.width, rect.height); GUI.BeginGroup(calcScore); - Text.Font = GameFont.Small; - GUI.color = Color.white; - Rect outRect = new Rect(0f, 0f, calcScore.width, calcScore.height); - Rect viewRect1 = outRect; - viewRect1.height = this.scrollViewHeight1; + Text.Font = GameFont.Small; + GUI.color = Color.white; + Rect outRect = new Rect(0f, 0f, calcScore.width, calcScore.height); + Rect viewRect1 = outRect; + viewRect1.height = this._scrollViewHeight1; + if (viewRect1.height > outRect.height) { viewRect1.width -= 20f; } - Widgets.BeginScrollView(outRect, ref this.scrollPosition1, viewRect1); + Widgets.BeginScrollView(outRect, ref this._scrollPosition1, viewRect1); float num = 0f; if (this.SelPawn.apparel != null) @@ -244,7 +255,7 @@ private void DrawApparelList() orderby ap.def.apparel.bodyPartGroups[0].listOrder descending select ap) { - string bp = string.Empty; + string bp = string.Empty; string layer = string.Empty; foreach (ApparelLayer apparelLayer in current2.def.apparel.layers) { @@ -263,7 +274,7 @@ orderby ap.def.apparel.bodyPartGroups[0].listOrder descending if (Event.current.type == EventType.Layout) { - this.scrollViewHeight1 = num + 30f; + this._scrollViewHeight1 = num + 30f; } Widgets.EndScrollView(); @@ -275,9 +286,9 @@ private void DrawApparelStats(Vector2 cur, Rect canvas) { // header Rect statsHeaderRect = new Rect(cur.x, cur.y, canvas.width, 30f); - cur.y += 30f; - Text.Anchor = TextAnchor.LowerLeft; - Text.Font = GameFont.Small; + cur.y += 30f; + Text.Anchor = TextAnchor.LowerLeft; + Text.Font = GameFont.Small; Widgets.Label(statsHeaderRect, "PreferedStats".Translate()); Text.Anchor = TextAnchor.UpperLeft; @@ -288,17 +299,20 @@ private void DrawApparelStats(Vector2 cur, Rect canvas) List options = new List(); foreach (StatDef def in this.SelPawnForGear.NotYetAssignedStatDefs().OrderBy(i => i.label.ToString())) { - options.Add( - new FloatMenuOption( - def.LabelCap, - delegate - { - this.SelPawnForGear.GetApparelStatCache().StatCache.Insert( - 0, - new StatPriority(def, 0f, StatAssignment.Manual)); - - // pawnStatCache.Stats.Insert(0, new Saveable_Pawn_StatDef(def, 0f, StatAssignment.Manual)); - })); + FloatMenuOption option = new FloatMenuOption( + def.LabelCap, + delegate + { + this.SelPawnForGear.GetApparelStatCache().StatCache + .Insert( + 0, + new + StatPriority(def, + 0f, + StatAssignment + .Manual)); + }); + options.Add(option); } Find.WindowStack.Add(new FloatMenu(options)); @@ -316,14 +330,14 @@ private void DrawApparelStats(Vector2 cur, Rect canvas) // main content in scrolling view Rect contentRect = new Rect(cur.x, cur.y, canvas.width, canvas.height - cur.y); - Rect viewRect = contentRect; - viewRect.height = this.scrollViewHeight; + Rect viewRect = contentRect; + viewRect.height = this._scrollViewHeight; if (viewRect.height > contentRect.height) { viewRect.width -= 20f; } - Widgets.BeginScrollView(contentRect, ref this.scrollPosition, viewRect); + Widgets.BeginScrollView(contentRect, ref this._scrollPosition, viewRect); GUI.BeginGroup(viewRect); cur = Vector2.zero; @@ -332,33 +346,33 @@ private void DrawApparelStats(Vector2 cur, Rect canvas) if (!this.SelPawnForGear.GetApparelStatCache().StatCache.Any()) { Rect noneLabel = new Rect(cur.x, cur.y, viewRect.width, 30f); - GUI.color = Color.grey; - Text.Anchor = TextAnchor.MiddleCenter; + GUI.color = Color.grey; + Text.Anchor = TextAnchor.MiddleCenter; Widgets.Label(noneLabel, "None".Translate()); - Text.Anchor = TextAnchor.UpperLeft; - GUI.color = Color.white; - cur.y += 30f; + Text.Anchor = TextAnchor.UpperLeft; + GUI.color = Color.white; + cur.y += 30f; } else { // legend kind of thingy. Rect legendRect = new Rect(cur.x + (viewRect.width - 24) / 2, cur.y, (viewRect.width - 24) / 2, 20f); - Text.Font = GameFont.Tiny; - GUI.color = Color.grey; - Text.Anchor = TextAnchor.LowerLeft; + Text.Font = GameFont.Tiny; + GUI.color = Color.grey; + Text.Anchor = TextAnchor.LowerLeft; Widgets.Label(legendRect, "-" + ApparelStatCache.MaxValue.ToString("N1")); Text.Anchor = TextAnchor.LowerRight; Widgets.Label(legendRect, ApparelStatCache.MaxValue.ToString("N1")); - Text.Anchor = TextAnchor.UpperLeft; - Text.Font = GameFont.Small; - GUI.color = Color.white; - cur.y += 15f; + Text.Anchor = TextAnchor.UpperLeft; + Text.Font = GameFont.Small; + GUI.color = Color.white; + cur.y += 15f; // statPriority weight sliders foreach (StatPriority stat in this.SelPawnForGear.GetApparelStatCache().StatCache) { - DrawStatRow(ref cur, viewRect.width, stat, this.SelPawnForGear, out bool stop_UI); - if (stop_UI) + this.DrawStatRow(ref cur, viewRect.width, stat, this.SelPawnForGear, out bool stopUI); + if (stopUI) { // DrawWApparelStatRow can change the StatCache, invalidating the loop. // So if it does that, stop looping - we'll redraw on the next tick. @@ -371,19 +385,161 @@ private void DrawApparelStats(Vector2 cur, Rect canvas) if (Event.current.type == EventType.Layout) { - this.scrollViewHeight = cur.y + 10f; + this._scrollViewHeight = cur.y + 10f; } GUI.EndGroup(); Widgets.EndScrollView(); } + private void DrawStatRow( + ref Vector2 cur, + float width, + [NotNull] StatPriority statPriority, + Pawn pawn, + out bool stopUI) + { + // sent a signal if the statlist has changed + stopUI = false; + + // set up rects + Rect labelRect = new Rect(cur.x, cur.y, (width - 24) / 2f, 30f); + Rect sliderRect = new Rect(labelRect.xMax + 4f, cur.y + 5f, labelRect.width, 25f); + Rect buttonRect = new Rect(sliderRect.xMax + 4f, cur.y + 3f, 16f, 16f); + + // draw label + Text.Font = Text.CalcHeight(statPriority.Stat.LabelCap, labelRect.width) > labelRect.height + ? GameFont.Tiny + : GameFont.Small; + switch (statPriority.Assignment) + { + case StatAssignment.Automatic: + GUI.color = Color.grey; + break; + + case StatAssignment.Individual: + GUI.color = Color.cyan; + break; + + case StatAssignment.Manual: + GUI.color = Color.white; + break; + + case StatAssignment.Override: + GUI.color = new Color(0.75f, 0.69f, 0.33f); + break; + + default: + GUI.color = Color.white; + break; + } + // if (!ApparelStatsHelper.AllStatDefsModifiedByAnyApparel.Contains(statPriority.Stat)) + // { + // GUI.color *= new Color(0.8f, 0.8f, 0.8f); + // } + + Widgets.Label(labelRect, statPriority.Stat.LabelCap); + Text.Font = GameFont.Small; + + // draw button + // if manually added, delete the priority + string buttonTooltip = string.Empty; + if (statPriority.Assignment == StatAssignment.Manual) + { + buttonTooltip = "StatPriorityDelete".Translate(statPriority.Stat.LabelCap); + if (Widgets.ButtonImage(buttonRect, OutfitterTextures.DeleteButton)) + { + statPriority.Delete(pawn); + stopUI = true; + } + } + + // if overridden auto assignment, reset to auto + if (statPriority.Assignment == StatAssignment.Override) + { + buttonTooltip = "StatPriorityReset".Translate(statPriority.Stat.LabelCap); + if (Widgets.ButtonImage(buttonRect, OutfitterTextures.ResetButton)) + { + statPriority.Reset(pawn); + stopUI = true; + } + } + + // draw line behind slider + GUI.color = new Color(.3f, .3f, .3f); + for (int y = (int) cur.y; y < cur.y + 30; y += 5) + { + Widgets.DrawLineVertical((sliderRect.xMin + sliderRect.xMax) / 2f, y, 3f); + } + + // draw slider + switch (statPriority.Assignment) + { + case StatAssignment.Automatic: + GUI.color = Color.grey; + break; + + case StatAssignment.Individual: + GUI.color = Color.cyan; + break; + + case StatAssignment.Manual: + GUI.color = Color.white; + break; + + case StatAssignment.Override: + GUI.color = new Color(0.75f, 0.69f, 0.33f); + break; + + default: + GUI.color = Color.white; + break; + } + + float weight = GUI.HorizontalSlider( + sliderRect, + statPriority.Weight, + ApparelStatCache.SpecialStats.Contains(statPriority.Stat) + ? 0.01f + : -ApparelStatCache.MaxValue, + ApparelStatCache.MaxValue); + + if (Mathf.Abs(weight - statPriority.Weight) > 1e-4) + { + statPriority.Weight = weight; + if (statPriority.Assignment == StatAssignment.Automatic || + statPriority.Assignment == StatAssignment.Individual) + { + statPriority.Assignment = StatAssignment.Override; + } + } + + if (GUI.changed) + { + pawn.GetApparelStatCache().RawScoreDict.Clear(); + } + + GUI.color = Color.white; + + // tooltips + TooltipHandler.TipRegion(labelRect, statPriority.Stat.LabelCap + "\n\n" + statPriority.Stat.description); + if (buttonTooltip != string.Empty) + { + TooltipHandler.TipRegion(buttonRect, buttonTooltip); + } + + TooltipHandler.TipRegion(sliderRect, statPriority.Weight.ToStringByStyle(ToStringStyle.FloatTwo)); + + // advance row + cur.y += 30f; + } + private void DrawTemperatureStats([NotNull] SaveablePawn pawnSave, ref Vector2 cur, Rect canvas) { // header Rect tempHeaderRect = new Rect(cur.x, cur.y, canvas.width, 30f); - cur.y += 30f; - Text.Anchor = TextAnchor.LowerLeft; + cur.y += 30f; + Text.Anchor = TextAnchor.LowerLeft; Widgets.Label(tempHeaderRect, "PreferedTemperature".Translate()); Text.Anchor = TextAnchor.UpperLeft; @@ -398,24 +554,24 @@ private void DrawTemperatureStats([NotNull] SaveablePawn pawnSave, ref Vector2 c // temperature slider // SaveablePawn pawnStatCache = MapComponent_Outfitter.Get.GetSaveablePawn(SelPawn); ApparelStatCache pawnStatCache = this.SelPawnForGear.GetApparelStatCache(); - FloatRange targetTemps = pawnStatCache.TargetTemperatures; - FloatRange minMaxTemps = ApparelStatsHelper.MinMaxTemperatureRange; - Rect sliderRect = new Rect(cur.x, cur.y, canvas.width - 20f, 40f); - Rect tempResetRect = new Rect(sliderRect.xMax + 4f, cur.y + Margin, 16f, 16f); - cur.y += 40f; // includes padding + FloatRange targetTemps = pawnStatCache.TargetTemperatures; + FloatRange minMaxTemps = ApparelStatsHelper.MinMaxTemperatureRange; + Rect sliderRect = new Rect(cur.x, cur.y, canvas.width - 20f, 40f); + Rect tempResetRect = new Rect(sliderRect.xMax + 4f, cur.y + Margin, 16f, 16f); + cur.y += 40f; // includes padding // current temperature settings GUI.color = pawnSave.TargetTemperaturesOverride ? Color.white : Color.grey; Widgets_FloatRange.FloatRange( - sliderRect, - 123123123, - ref targetTemps, - minMaxTemps, - ToStringStyle.Temperature); + sliderRect, + 123123123, + ref targetTemps, + minMaxTemps, + ToStringStyle.Temperature); GUI.color = Color.white; if (Math.Abs(targetTemps.min - pawnStatCache.TargetTemperatures.min) > 1e-4 - || Math.Abs(targetTemps.max - pawnStatCache.TargetTemperatures.max) > 1e-4) + || Math.Abs(targetTemps.max - pawnStatCache.TargetTemperatures.max) > 1e-4) { pawnStatCache.TargetTemperatures = targetTemps; } @@ -470,37 +626,36 @@ private void DrawThingRowModded(ref float y, float width, Apparel apparel) { List floatOptionList = new List - { - new FloatMenuOption( - "ThingInfo".Translate(), - delegate - { - Find.WindowStack.Add(new Dialog_InfoCard(apparel)); - }) - }; + { + new FloatMenuOption( + "ThingInfo".Translate(), + delegate { Find.WindowStack.Add(new Dialog_InfoCard(apparel)); }) + }; if (this.CanControl) { floatOptionList.Add( - new FloatMenuOption( - "OutfitterComparer".Translate(), - delegate - { - Find.WindowStack.Add( - new Dialog_PawnApparelComparer(this.SelPawnForGear, apparel)); - })); + new FloatMenuOption( + "OutfitterComparer".Translate(), + delegate + { + Find.WindowStack.Add( + new + Dialog_PawnApparelComparer(this.SelPawnForGear, + apparel)); + })); Action dropApparel = delegate - { - SoundDefOf.TickHigh.PlayOneShotOnCamera(); - this.InterfaceDrop(apparel); - }; + { + SoundDefOf.TickHigh.PlayOneShotOnCamera(); + this.InterfaceDrop(apparel); + }; Action dropApparelHaul = delegate - { - SoundDefOf.TickHigh.PlayOneShotOnCamera(); - this.InterfaceDropHaul(apparel); - }; - floatOptionList.Add(new FloatMenuOption("DropThing".Translate(), dropApparel)); + { + SoundDefOf.TickHigh.PlayOneShotOnCamera(); + this.InterfaceDropHaul(apparel); + }; + floatOptionList.Add(new FloatMenuOption("DropThing".Translate(), dropApparel)); floatOptionList.Add(new FloatMenuOption("DropThingHaul".Translate(), dropApparelHaul)); } @@ -514,17 +669,17 @@ private void DrawThingRowModded(ref float y, float width, Apparel apparel) Widgets.ThingIcon(new Rect(4f, y + 5f, ThingIconSize, ThingIconSize), apparel); } - Text.Anchor = TextAnchor.MiddleLeft; - GUI.color = ThingLabelColor; - Rect textRect = new Rect(ThingLeftX, y, width - ThingLeftX, ThingRowHeight - Text.LineHeight); + Text.Anchor = TextAnchor.MiddleLeft; + GUI.color = ThingLabelColor; + Rect textRect = new Rect(ThingLeftX, y, width - ThingLeftX, ThingRowHeight - Text.LineHeight); Rect scoreRect = new Rect(ThingLeftX, textRect.yMax, width - ThingLeftX, Text.LineHeight); - ApparelStatCache conf = this.SelPawn.GetApparelStatCache(); - string text = apparel.LabelCap; - string text_Score = Math.Round(conf.ApparelScoreRaw(apparel), 2).ToString("N2"); + ApparelStatCache conf = this.SelPawn.GetApparelStatCache(); + string text = apparel.LabelCap; + string textScore = Math.Round(conf.ApparelScoreRaw(apparel), 2).ToString("N2"); if (apparel is Apparel && this.SelPawn.outfits != null - && this.SelPawn.outfits.forcedHandler.IsForced(apparel)) + && this.SelPawn.outfits.forcedHandler.IsForced(apparel)) { text = text + ", " + "ApparelForcedLower".Translate(); Widgets.Label(textRect, text); @@ -534,7 +689,7 @@ private void DrawThingRowModded(ref float y, float width, Apparel apparel) GUI.color = new Color(0.75f, 0.75f, 0.75f); if (apparel.def.useHitPoints) { - float x = apparel.HitPoints / (float)apparel.MaxHitPoints; + float x = apparel.HitPoints / (float) apparel.MaxHitPoints; if (x < 0.5f) { GUI.color = Color.yellow; @@ -548,151 +703,12 @@ private void DrawThingRowModded(ref float y, float width, Apparel apparel) Widgets.Label(textRect, text); GUI.color = Color.white; - Widgets.Label(scoreRect, text_Score); + Widgets.Label(scoreRect, textScore); } y += ThingRowHeight; } - private void DrawStatRow( - ref Vector2 cur, - float width, - [NotNull] StatPriority statPriority, - Pawn pawn, - out bool stopUI) - { - // sent a signal if the statlist has changed - stopUI = false; - - // set up rects - Rect labelRect = new Rect(cur.x, cur.y, (width - 24) / 2f, 30f); - Rect sliderRect = new Rect(labelRect.xMax + 4f, cur.y + 5f, labelRect.width, 25f); - Rect buttonRect = new Rect(sliderRect.xMax + 4f, cur.y + 3f, 16f, 16f); - - // draw label - Text.Font = Text.CalcHeight(statPriority.Stat.LabelCap, labelRect.width) > labelRect.height - ? GameFont.Tiny - : GameFont.Small; - switch (statPriority.Assignment) - { - case StatAssignment.Automatic: - GUI.color = Color.grey; - break; - - case StatAssignment.Individual: - GUI.color = Color.cyan; - break; - - case StatAssignment.Manual: - GUI.color = Color.white; - break; - - case StatAssignment.Override: - GUI.color = new Color(0.75f, 0.69f, 0.33f); - break; - - default: - GUI.color = Color.white; - break; - } - // if (!ApparelStatsHelper.AllStatDefsModifiedByAnyApparel.Contains(statPriority.Stat)) - // { - // GUI.color *= new Color(0.8f, 0.8f, 0.8f); - // } - - Widgets.Label(labelRect, statPriority.Stat.LabelCap); - Text.Font = GameFont.Small; - - // draw button - // if manually added, delete the priority - string buttonTooltip = string.Empty; - if (statPriority.Assignment == StatAssignment.Manual) - { - buttonTooltip = "StatPriorityDelete".Translate(statPriority.Stat.LabelCap); - if (Widgets.ButtonImage(buttonRect, OutfitterTextures.DeleteButton)) - { - statPriority.Delete(pawn); - stopUI = true; - } - } - - // if overridden auto assignment, reset to auto - if (statPriority.Assignment == StatAssignment.Override) - { - buttonTooltip = "StatPriorityReset".Translate(statPriority.Stat.LabelCap); - if (Widgets.ButtonImage(buttonRect, OutfitterTextures.ResetButton)) - { - statPriority.Reset(pawn); - stopUI = true; - } - } - - // draw line behind slider - GUI.color = new Color(.3f, .3f, .3f); - for (int y = (int)cur.y; y < cur.y + 30; y += 5) - { - Widgets.DrawLineVertical((sliderRect.xMin + sliderRect.xMax) / 2f, y, 3f); - } - - // draw slider - switch (statPriority.Assignment) - { - case StatAssignment.Automatic: - GUI.color = Color.grey; - break; - - case StatAssignment.Individual: - GUI.color = Color.cyan; - break; - - case StatAssignment.Manual: - GUI.color = Color.white; - break; - - case StatAssignment.Override: - GUI.color = new Color(0.75f, 0.69f, 0.33f); - break; - - default: - GUI.color = Color.white; - break; - } - - float weight = GUI.HorizontalSlider( - sliderRect, - statPriority.Weight, - ApparelStatCache.specialStats.Contains(statPriority.Stat) ? 0.01f : -ApparelStatCache.MaxValue, - ApparelStatCache.MaxValue); - - if (Mathf.Abs(weight - statPriority.Weight) > 1e-4) - { - statPriority.Weight = weight; - if (statPriority.Assignment == StatAssignment.Automatic || statPriority.Assignment == StatAssignment.Individual) - { - statPriority.Assignment = StatAssignment.Override; - } - } - - if (GUI.changed) - { - pawn.GetApparelStatCache().RawScoreDict.Clear(); - } - - GUI.color = Color.white; - - // tooltips - TooltipHandler.TipRegion(labelRect, statPriority.Stat.LabelCap + "\n\n" + statPriority.Stat.description); - if (buttonTooltip != string.Empty) - { - TooltipHandler.TipRegion(buttonRect, buttonTooltip); - } - - TooltipHandler.TipRegion(sliderRect, statPriority.Weight.ToStringByStyle(ToStringStyle.FloatTwo)); - - // advance row - cur.y += 30f; - } - private void DrawThingRowVanilla(ref float y, float width, Thing thing) { Rect rect = new Rect(0f, y, width, 28f); @@ -702,11 +718,11 @@ private void DrawThingRowVanilla(ref float y, float width, Thing thing) GUI.DrawTexture(rect, TexUI.HighlightTex); } - GUI.color = ThingLabelColor; - Rect rect2a = new Rect(rect.width - 24f, y, 24f, 24f); + GUI.color = ThingLabelColor; + Rect rect2A = new Rect(rect.width - 24f, y, 24f, 24f); UIHighlighter.HighlightOpportunity(rect, "InfoCard"); - TooltipHandler.TipRegion(rect2a, "DefInfoTip".Translate()); - if (Widgets.ButtonImage(rect2a, OutfitterTextures.Info)) + TooltipHandler.TipRegion(rect2A, "DefInfoTip".Translate()); + if (Widgets.ButtonImage(rect2A, OutfitterTextures.Info)) { Find.WindowStack.Add(new Dialog_InfoCard(thing)); } @@ -729,12 +745,12 @@ private void DrawThingRowVanilla(ref float y, float width, Thing thing) Widgets.ThingIcon(new Rect(4f, y, 28f, 28f), thing); } - Text.Anchor = TextAnchor.MiddleLeft; - GUI.color = ThingLabelColor; - Rect rect3 = new Rect(ThingLeftX, y, width - ThingLeftX, 28f); - string text = thing.LabelCap; + Text.Anchor = TextAnchor.MiddleLeft; + GUI.color = ThingLabelColor; + Rect rect3 = new Rect(ThingLeftX, y, width - ThingLeftX, 28f); + string text = thing.LabelCap; if (thing is Apparel && this.SelPawn.outfits != null - && this.SelPawn.outfits.forcedHandler.IsForced((Apparel)thing)) + && this.SelPawn.outfits.forcedHandler.IsForced((Apparel) thing)) { text = text + ", " + "ApparelForcedLower".Translate(); } @@ -746,23 +762,22 @@ private void DrawThingRowVanilla(ref float y, float width, Thing thing) private void InterfaceDrop([NotNull] Thing t) { ThingWithComps thingWithComps = t as ThingWithComps; - Apparel apparel = t as Apparel; + Apparel apparel = t as Apparel; if (apparel != null) { Pawn selPawnForGear = this.SelPawn; if (selPawnForGear.jobs.IsCurrentJobPlayerInterruptible()) { - Job job = new Job(JobDefOf.RemoveApparel, apparel) { playerForced = true }; + Job job = new Job(JobDefOf.RemoveApparel, apparel) {playerForced = true}; selPawnForGear.jobs.TryTakeOrderedJob(job); } } else if (thingWithComps != null - && this.SelPawn.equipment.AllEquipmentListForReading.Contains(thingWithComps)) + && this.SelPawn.equipment.AllEquipmentListForReading.Contains(thingWithComps)) { this.SelPawn.equipment.TryDropEquipment( - thingWithComps, - out ThingWithComps thingWithComps2, - this.SelPawn.Position); + thingWithComps, + out ThingWithComps thingWithComps2, this.SelPawn.Position); } else if (!t.def.destroyOnDrop) { @@ -773,24 +788,23 @@ private void InterfaceDrop([NotNull] Thing t) private void InterfaceDropHaul(Thing t) { ThingWithComps thingWithComps = t as ThingWithComps; - Apparel apparel = t as Apparel; + Apparel apparel = t as Apparel; if (apparel != null) { Pawn selPawnForGear = this.SelPawn; if (selPawnForGear.jobs.IsCurrentJobPlayerInterruptible()) { - Job job = - new Job(JobDefOf.RemoveApparel, apparel) { playerForced = true, haulDroppedApparel = true }; + Job job = + new Job(JobDefOf.RemoveApparel, apparel) {playerForced = true, haulDroppedApparel = true}; selPawnForGear.jobs.TryTakeOrderedJob(job); } } else if (thingWithComps != null - && this.SelPawn.equipment.AllEquipmentListForReading.Contains(thingWithComps)) + && this.SelPawn.equipment.AllEquipmentListForReading.Contains(thingWithComps)) { this.SelPawn.equipment.TryDropEquipment( - thingWithComps, - out ThingWithComps thingWithComps2, - this.SelPawn.Position); + thingWithComps, + out ThingWithComps thingWithComps2, this.SelPawn.Position); } else if (!t.def.destroyOnDrop) { @@ -805,18 +819,20 @@ private void TryDrawComfyTemperatureRange(ref float curY, float width) return; } - Rect rect = new Rect(0f, curY, width, 22f); - float statValue = this.SelPawnForGear.GetStatValue(StatDefOf.ComfyTemperatureMin); + Rect rect = new Rect(0f, curY, width, 22f); + float statValue = this.SelPawnForGear.GetStatValue(StatDefOf.ComfyTemperatureMin); float statValue2 = this.SelPawnForGear.GetStatValue(StatDefOf.ComfyTemperatureMax); Widgets.Label( - rect, - string.Concat( - "ComfyTemperatureRange".Translate(), - ": ", - statValue.ToStringTemperature("F0"), - " ~ ", - statValue2.ToStringTemperature("F0"))); + rect, + string.Concat( + "ComfyTemperatureRange".Translate(), + ": ", + statValue.ToStringTemperature("F0"), + " ~ ", + statValue2.ToStringTemperature("F0"))); curY += 22f; } + + #endregion Private Methods } } \ No newline at end of file diff --git a/Source/Outfitter/Window/Widgets_FloatRange.cs b/Source/Outfitter/Window/Widgets_FloatRange.cs index a8b0d86..65f5d04 100644 --- a/Source/Outfitter/Window/Widgets_FloatRange.cs +++ b/Source/Outfitter/Window/Widgets_FloatRange.cs @@ -1,21 +1,19 @@ -namespace Outfitter.Window -{ - using Outfitter.Textures; - - using UnityEngine; - - using Verse; +using Outfitter.Textures; +using UnityEngine; +using Verse; +namespace Outfitter.Window +{ public static class Widgets_FloatRange { - private static Handle draggingHandle; + private static Handle _draggingHandle; - private static int draggingId; + private static int _draggingId; static Widgets_FloatRange() { - draggingHandle = Handle.None; - draggingId = 0; + _draggingHandle = Handle.None; + _draggingId = 0; } public enum Handle @@ -75,38 +73,38 @@ public static void FloatRange( interactionRect.xMin -= 8f; interactionRect.xMax += 8f; bool dragging = false; - if (Mouse.IsOver(interactionRect) || draggingId == id) + if (Mouse.IsOver(interactionRect) || _draggingId == id) { if (Event.current.type == EventType.MouseDown && Event.current.button == 0) { - draggingId = id; + _draggingId = id; float x = Event.current.mousePosition.x; if (x < minHandleRect.xMax) { - draggingHandle = Handle.Min; + _draggingHandle = Handle.Min; } else if (x > maxHandleRect.xMin) { - draggingHandle = Handle.Max; + _draggingHandle = Handle.Max; } else { float distToMin = Mathf.Abs(x - minHandleRect.xMax); float distToMax = Mathf.Abs(x - (maxHandleRect.x - 16f)); - draggingHandle = distToMin >= distToMax ? Handle.Max : Handle.Min; + _draggingHandle = distToMin >= distToMax ? Handle.Max : Handle.Min; } dragging = true; Event.current.Use(); } - if (dragging || draggingHandle != Handle.None && Event.current.type == EventType.MouseDrag) + if (dragging || _draggingHandle != Handle.None && Event.current.type == EventType.MouseDrag) { // NOTE: this deviates from vanilla, vanilla seemed to assume that max == span? float curPosValue = (Event.current.mousePosition.x - canvas.x) / canvas.width * sliderRange.Span + sliderRange.min; curPosValue = Mathf.Clamp(curPosValue, sliderRange.min, sliderRange.max); - if (draggingHandle == Handle.Min) + if (_draggingHandle == Handle.Min) { range.min = curPosValue; if (range.max < range.min) @@ -114,7 +112,7 @@ public static void FloatRange( range.max = range.min; } } - else if (draggingHandle == Handle.Max) + else if (_draggingHandle == Handle.Max) { range.max = curPosValue; if (range.min > range.max) @@ -127,10 +125,10 @@ public static void FloatRange( } } - if (draggingHandle != Handle.None && Event.current.type == EventType.MouseUp) + if (_draggingHandle != Handle.None && Event.current.type == EventType.MouseUp) { - draggingId = 0; - draggingHandle = Handle.None; + _draggingId = 0; + _draggingHandle = Handle.None; Event.current.Use(); } } diff --git a/Source/Outfitter/Window/Window_Pawn_ApparelDetail.cs b/Source/Outfitter/Window/Window_Pawn_ApparelDetail.cs index 64d5418..385c07c 100644 --- a/Source/Outfitter/Window/Window_Pawn_ApparelDetail.cs +++ b/Source/Outfitter/Window/Window_Pawn_ApparelDetail.cs @@ -1,28 +1,22 @@ -using static UnityEngine.GUILayout; +using System; +using System.Collections.Generic; +using System.Linq; +using JetBrains.Annotations; +using Outfitter.Textures; +using RimWorld; +using UnityEngine; +using Verse; +using static UnityEngine.GUILayout; namespace Outfitter { - using System; - using System.Collections.Generic; - using System.Linq; - - using JetBrains.Annotations; - - using Outfitter.Textures; - - using RimWorld; - - using UnityEngine; - - using Verse; - public class Window_Pawn_ApparelDetail : Verse.Window { - private const float baseValue = 85f; + private const float BaseValue = 85f; - private readonly Apparel apparel; + private readonly Apparel _apparel; - private readonly GUIStyle fontBold = + private readonly GUIStyle _fontBold = new GUIStyle { fontStyle = FontStyle.Bold, @@ -32,7 +26,7 @@ public class Window_Pawn_ApparelDetail : Verse.Window padding = new RectOffset(0, 0, 12, 6) }; - private readonly GUIStyle headline = + private readonly GUIStyle _headline = new GUIStyle { fontStyle = FontStyle.Bold, @@ -43,17 +37,17 @@ public class Window_Pawn_ApparelDetail : Verse.Window padding = new RectOffset(0, 0, 12, 6) }; - private readonly GUIStyle hoverBox = new GUIStyle { hover = { background = OutfitterTextures.BgColor } }; + private readonly GUIStyle _hoverBox = new GUIStyle { hover = { background = OutfitterTextures.BgColor } }; - private readonly Pawn pawn; + private readonly Pawn _pawn; - private readonly GUIStyle whiteLine = new GUIStyle { normal = { background = OutfitterTextures.White } }; + private readonly GUIStyle _whiteLine = new GUIStyle { normal = { background = OutfitterTextures.White } }; private Vector2 _scrollPosition; - private Def def; + private Def _def; - private ThingDef stuff; + private ThingDef _stuff; public Window_Pawn_ApparelDetail(Pawn pawn, Apparel apparel) { @@ -62,8 +56,8 @@ public Window_Pawn_ApparelDetail(Pawn pawn, Apparel apparel) this.doCloseButton = true; this.preventCameraMotion = false; - this.pawn = pawn; - this.apparel = apparel; + this._pawn = pawn; + this._apparel = apparel; } public override Vector2 InitialSize => new Vector2(510f, 550f); @@ -73,12 +67,12 @@ private Def Def { get { - if (this.apparel != null) + if (this._apparel != null) { - return this.apparel.def; + return this._apparel.def; } - return this.def; + return this._def; } } @@ -112,7 +106,7 @@ private bool IsVisible public override void DoWindowContents(Rect inRect) { - ApparelStatCache conf = this.pawn.GetApparelStatCache(); + ApparelStatCache conf = this._pawn.GetApparelStatCache(); Rect conRect = new Rect(inRect); @@ -123,23 +117,23 @@ public override void DoWindowContents(Rect inRect) // begin main group BeginVertical(); - Label(this.GetTitle(), this.headline); + Label(this.GetTitle(), this._headline); Text.Font = GameFont.Small; // GUI.BeginGroup(contentRect); - float labelWidth = conRect.width - baseValue - baseValue - baseValue - 48f; + float labelWidth = conRect.width - BaseValue - BaseValue - BaseValue - 48f; - this.DrawLine("Status", labelWidth, "BaseMod", "Strength", "Score", this.fontBold); + this.DrawLine("Status", labelWidth, "BaseMod", "Strength", "Score", this._fontBold); Space(6f); - Label(string.Empty, this.whiteLine, Height(1)); + Label(string.Empty, this._whiteLine, Height(1)); Space(6f); - ApparelEntry apparelEntry = conf.GetAllOffsets(this.apparel); + ApparelEntry apparelEntry = conf.GetAllOffsets(this._apparel); - HashSet equippedOffsets = apparelEntry.equippedOffsets; - HashSet statBases = apparelEntry.statBases; - HashSet infusedOffsets = apparelEntry.infusedOffsets; + HashSet equippedOffsets = apparelEntry.EquippedOffsets; + HashSet statBases = apparelEntry.StatBases; + HashSet infusedOffsets = apparelEntry.InfusedOffsets; this._scrollPosition = BeginScrollView(this._scrollPosition, Width(conRect.width)); @@ -149,7 +143,7 @@ public override void DoWindowContents(Rect inRect) float score = 1; // add values for each statdef modified by the apparel - foreach (StatPriority statPriority in this.pawn.GetApparelStatCache().StatCache + foreach (StatPriority statPriority in this._pawn.GetApparelStatCache().StatCache .OrderBy(i => i.Stat.LabelCap)) { StatDef stat = statPriority.Stat; @@ -160,11 +154,11 @@ public override void DoWindowContents(Rect inRect) // StatCache.DoApparelScoreRaw_PawnStatsHandlers(_pawn, _apparel, statPriority.Stat, ref currentStat); if (statBases.Contains(stat)) { - float statValue = this.apparel.GetStatValue(stat); + float statValue = this._apparel.GetStatValue(stat); float statScore = 0f; - if (ApparelStatCache.specialStats.Contains(stat)) + if (ApparelStatCache.SpecialStats.Contains(stat)) { - ApparelStatCache.CalculateScoreForSpecialStats(this.apparel, statPriority, this.pawn, statValue, ref statScore); + ApparelStatCache.CalculateScoreForSpecialStats(this._apparel, statPriority, this._pawn, statValue, ref statScore); } else { @@ -184,13 +178,13 @@ public override void DoWindowContents(Rect inRect) if (equippedOffsets.Contains(stat)) { - float statValue = this.apparel.GetEquippedStatValue(this.pawn, stat); + float statValue = this._apparel.GetEquippedStatValue(this._pawn, stat); // statValue += StatCache.StatInfused(infusionSet, statPriority, ref equippedInfused); float statScore = 0f; - if (ApparelStatCache.specialStats.Contains(stat)) + if (ApparelStatCache.SpecialStats.Contains(stat)) { - ApparelStatCache.CalculateScoreForSpecialStats(this.apparel, statPriority, this.pawn, statValue, ref statScore); + ApparelStatCache.CalculateScoreForSpecialStats(this._apparel, statPriority, this._pawn, statValue, ref statScore); } else { @@ -212,17 +206,15 @@ public override void DoWindowContents(Rect inRect) GUI.color = Color.green; // new Color(0.5f, 1f, 1f, 1f); // float statInfused = StatCache.StatInfused(infusionSet, statPriority, ref dontcare); - ApparelStatCache.DoApparelScoreRaw_PawnStatsHandlers(this.apparel, stat, out float statValue); + ApparelStatCache.DoApparelScoreRaw_PawnStatsHandlers(this._apparel, stat, out float statValue); bool flag = true; float statScore = 0f; - if (ApparelStatCache.specialStats.Contains(stat)) + if (ApparelStatCache.SpecialStats.Contains(stat)) { - ApparelStatCache.CalculateScoreForSpecialStats( - this.apparel, - statPriority, - this.pawn, + ApparelStatCache.CalculateScoreForSpecialStats(this._apparel, + statPriority, this._pawn, statValue, ref statScore); } @@ -267,13 +259,13 @@ public override void DoWindowContents(Rect inRect) // begin lower group FlexibleSpace(); Space(6f); - Label(string.Empty, this.whiteLine, Height(1)); + Label(string.Empty, this._whiteLine, Height(1)); Space(6f); this.DrawLine(string.Empty, labelWidth, "Modifier", string.Empty, "Subtotal"); this.DrawLine("BasicStatusOfApparel".Translate(), labelWidth, "1.00", "+", score.ToString("N2")); - float special = this.apparel.GetSpecialApparelScoreOffset(); + float special = this._apparel.GetSpecialApparelScoreOffset(); if (Math.Abs(special) > 0f) { score += special; @@ -286,7 +278,7 @@ public override void DoWindowContents(Rect inRect) score.ToString("N2")); } - float armor = ApparelStatCache.ApparelScoreRaw_ProtectionBaseStat(this.apparel); + float armor = ApparelStatCache.ApparelScoreRaw_ProtectionBaseStat(this._apparel); if (Math.Abs(armor) > 0.01f) { @@ -295,10 +287,10 @@ public override void DoWindowContents(Rect inRect) this.DrawLine("OutfitterArmor".Translate(), labelWidth, armor.ToString("N2"), "+", score.ToString("N2")); } - if (this.apparel.def.useHitPoints) + if (this._apparel.def.useHitPoints) { // durability on 0-1 scale - float x = this.apparel.HitPoints / (float)this.apparel.MaxHitPoints; + float x = this._apparel.HitPoints / (float) this._apparel.MaxHitPoints; score *= ApparelStatsHelper.HitPointsPercentScoreFactorCurve.Evaluate(x); this.DrawLine( @@ -311,7 +303,7 @@ public override void DoWindowContents(Rect inRect) GUI.color = Color.white; } - if (this.apparel.WornByCorpse && ThoughtUtility.CanGetThought(this.pawn, ThoughtDefOf.DeadMansApparel)) + if (this._apparel.WornByCorpse && ThoughtUtility.CanGetThought(this._pawn, ThoughtDefOf.DeadMansApparel)) { score -= 0.5f; if (score > 0f) @@ -327,11 +319,9 @@ public override void DoWindowContents(Rect inRect) score.ToString("N2")); } - float mod = 1f; - - if (this.apparel.Stuff == ThingDefOf.Human.race.leatherDef) + if (this._apparel.Stuff == ThingDefOf.Human.race.leatherDef) { - if (ThoughtUtility.CanGetThought(this.pawn, ThoughtDefOf.HumanLeatherApparelSad)) + if (ThoughtUtility.CanGetThought(this._pawn, ThoughtDefOf.HumanLeatherApparelSad)) { score -= 0.5f; if (score > 0f) @@ -340,7 +330,7 @@ public override void DoWindowContents(Rect inRect) } } - if (ThoughtUtility.CanGetThought(this.pawn, ThoughtDefOf.HumanLeatherApparelHappy)) + if (ThoughtUtility.CanGetThought(this._pawn, ThoughtDefOf.HumanLeatherApparelHappy)) { score *= 2f; } @@ -353,7 +343,7 @@ public override void DoWindowContents(Rect inRect) score.ToString("N2")); } - float temperature = conf.ApparelScoreRaw_Temperature(this.apparel); + float temperature = conf.ApparelScoreRaw_Temperature(this._apparel); if (Math.Abs(temperature - 1f) > 0) { @@ -372,7 +362,7 @@ public override void DoWindowContents(Rect inRect) labelWidth, string.Empty, "=", - conf.ApparelScoreRaw(this.apparel).ToString("N2")); + conf.ApparelScoreRaw(this._apparel).ToString("N2")); GUI.color = Color.white; Text.Anchor = TextAnchor.UpperLeft; @@ -395,9 +385,7 @@ protected override void SetInitialSizeAndPosition() MainTabWindow_Inspect inspectWorker = (MainTabWindow_Inspect)MainButtonDefOf.Inspect.TabWindow; this.windowRect = new Rect( 770f, - inspectWorker.PaneTopY - 30f - this.InitialSize.y, - this.InitialSize.x, - this.InitialSize.y).Rounded(); + inspectWorker.PaneTopY - 30f - this.InitialSize.y, this.InitialSize.x, this.InitialSize.y).Rounded(); } private void DrawLine( @@ -414,13 +402,13 @@ private void DrawLine( } else { - BeginHorizontal(this.hoverBox); + BeginHorizontal(this._hoverBox); } Label(statDefLabelText, Width(statDefLabelWidth)); - Label(statDefValueText, Width(baseValue)); - Label(multiplierText, Width(baseValue)); - Label(finalValueText, Width(baseValue)); + Label(statDefValueText, Width(BaseValue)); + Label(multiplierText, Width(BaseValue)); + Label(finalValueText, Width(BaseValue)); EndHorizontal(); // Text.Anchor = TextAnchor.UpperLeft; @@ -439,18 +427,18 @@ private void DrawLine( private string GetTitle() { - if (this.apparel != null) + if (this._apparel != null) { - return this.apparel.LabelCap; + return this._apparel.LabelCap; } ThingDef thingDef = this.Def as ThingDef; if (thingDef != null) { - return GenLabel.ThingLabel(thingDef, this.stuff).CapitalizeFirst(); + return GenLabel.ThingLabel(thingDef, this._stuff).CapitalizeFirst(); } - return this.Def.LabelCap; + return this.Def?.LabelCap; } #pragma warning disable 649 diff --git a/Source/Outfitter/WorkType/Splitter.cs b/Source/Outfitter/WorkType/Splitter.cs index 6b9d3ea..01e679f 100644 --- a/Source/Outfitter/WorkType/Splitter.cs +++ b/Source/Outfitter/WorkType/Splitter.cs @@ -2,31 +2,18 @@ { public static class Splitter { - public const string Butcher = "Butchering"; - public const string Repair = "Repairing"; - public const string Drugs = "Drugs"; - - public const string Brewing = "Brewing"; - - public const string Drilling = "Drilling"; - - - public const string Taming = "Taming"; - - public const string Training = "Training"; - - public const string Refining = "Refining"; - - public const string Surgeon = "Surgeon"; - - public const string Harvesting = "Harvesting"; - - public const string Components = "Assembling"; - + public const string Butcher = "Butchering"; + public const string Repair = "Repairing"; + public const string Drugs = "Drugs"; + public const string Brewing = "Brewing"; + public const string Drilling = "Drilling"; + public const string Taming = "Taming"; + public const string Training = "Training"; + public const string Refining = "Refining"; + public const string Surgeon = "Surgeon"; + public const string Harvesting = "Harvesting"; + public const string Components = "Assembling"; public const string Stonecutting = "Stonecutting"; - - public const string Smelting = "Smelting"; - - + public const string Smelting = "Smelting"; } -} +} \ No newline at end of file diff --git a/Source/Outfitter/WorkType/Vanilla.cs b/Source/Outfitter/WorkType/Vanilla.cs index d840341..051fbb1 100644 --- a/Source/Outfitter/WorkType/Vanilla.cs +++ b/Source/Outfitter/WorkType/Vanilla.cs @@ -2,36 +2,21 @@ { public static class Vanilla { - public const string Doctor = "Doctor"; - - public const string Warden = "Warden"; - - public const string Handling = "Handling"; - - public const string Cooking = "Cooking"; - - public const string Hunting = "Hunting"; - + public const string Doctor = "Doctor"; + public const string Warden = "Warden"; + public const string Handling = "Handling"; + public const string Cooking = "Cooking"; + public const string Hunting = "Hunting"; public const string Construction = "Construction"; - - public const string Growing = "Growing"; - - public const string Mining = "Mining"; - + public const string Growing = "Growing"; + public const string Mining = "Mining"; public const string PlantCutting = "PlantCutting"; - - public const string Smithing = "Smithing"; - - public const string Tailoring = "Tailoring"; - - public const string Art = "Art"; - - public const string Crafting = "Crafting"; - - public const string Hauling = "Hauling"; - - public const string Cleaning = "Cleaning"; - - public const string Research = "Research"; + public const string Smithing = "Smithing"; + public const string Tailoring = "Tailoring"; + public const string Art = "Art"; + public const string Crafting = "Crafting"; + public const string Hauling = "Hauling"; + public const string Cleaning = "Cleaning"; + public const string Research = "Research"; } -} +} \ No newline at end of file diff --git a/Source/Outfitter_Infused/OutfitterInfused.cs b/Source/Outfitter_Infused/OutfitterInfused.cs index c6ad5d0..a67648e 100644 --- a/Source/Outfitter_Infused/OutfitterInfused.cs +++ b/Source/Outfitter_Infused/OutfitterInfused.cs @@ -2,19 +2,16 @@ namespace OutfitterInfused { using System.Collections.Generic; using System.Linq; - using Infused; - using Outfitter; - using RimWorld; - using Verse; - using Def = Infused.Def; public class GameComponent_OutfitterInfused : GameComponent { + private readonly Game _game; + public GameComponent_OutfitterInfused() { // @@ -22,30 +19,29 @@ public GameComponent_OutfitterInfused() public GameComponent_OutfitterInfused(Game game) { + _game = game; Log.Message("Outfitter with Infused Initialized"); - ApparelStatCache.ApparelScoreRaw_PawnStatsHandlers += ApparelScoreRaw_PawnStatsHandlers; - ApparelStatCache.ApparelScoreRaw_FillInfusedStat += ApparelScoreRaw_FillInfusedStat; - ApparelStatCache.Ignored_WTHandlers += Ignored_WTHandlers; + ApparelStatCache.ApparelScoreRawPawnStatsHandlers += ApparelScoreRaw_PawnStatsHandlers; + ApparelStatCache.ApparelScoreRawFillInfusedStat += ApparelScoreRaw_FillInfusedStat; + ApparelStatCache.IgnoredWtHandlers += Ignored_WTHandlers; } private static void ApparelScoreRaw_FillInfusedStat( - Apparel apparel, - StatDef parentStat, + Apparel apparel, + StatDef parentStat, ref HashSet infusedOffsets) { if (apparel.TryGetInfusions(out InfusionSet inf)) { - StatMod mod; - Def prefix = inf.prefix; Def suffix = inf.suffix; - if (prefix != null && prefix.TryGetStatValue(parentStat, out mod)) + if (prefix != null && prefix.TryGetStatValue(parentStat, out _)) { infusedOffsets.Add(parentStat); } - if (suffix != null && suffix.TryGetStatValue(parentStat, out mod)) + if (suffix != null && suffix.TryGetStatValue(parentStat, out _)) { infusedOffsets.Add(parentStat); } @@ -90,7 +86,10 @@ private static void Ignored_WTHandlers(ref List allApparelStats) { // add all stat modifiers from all infusions foreach (KeyValuePair mod in DefDatabase.AllDefsListForReading.SelectMany( - infusion => infusion.stats)) + infusion => + infusion + .stats) + ) { if (!allApparelStats.Contains(mod.Key)) {