From f9490195a425c54b421ae7a01ff97f32e9af2457 Mon Sep 17 00:00:00 2001
From: Safairette <71556532+Safairette@users.noreply.github.com>
Date: Thu, 5 Dec 2024 00:07:29 +0200
Subject: [PATCH 1/3] Stats cleanup
---
Defs/Stats/Stats_NightVision.xml | 4 +-
Defs/Stats/Stats_Weapons_Ranged.xml | 2 +
.../StatParts/Base/StatPart_StatSelect.cs | 35 +++++-
.../StatParts/StatPart_Bipod.cs | 105 ++++++++++++------
.../StatParts/StatPart_StatMaxima.cs | 5 +
.../StatParts/StatPart_StatMinima.cs | 5 +
.../StatWorkers/StatWorker_BipodDisplay.cs | 16 +--
7 files changed, 123 insertions(+), 49 deletions(-)
diff --git a/Defs/Stats/Stats_NightVision.xml b/Defs/Stats/Stats_NightVision.xml
index 00fb193594..64675dba1d 100644
--- a/Defs/Stats/Stats_NightVision.xml
+++ b/Defs/Stats/Stats_NightVision.xml
@@ -66,7 +66,7 @@
NightVisionEfficiency_Weapon
-
+
The effect of a weapon's optics on the wielder's ability to overcome the effects of darkness for the purpose of firing accurately.
Weapon
@@ -76,7 +76,7 @@
NightVisionEfficiency_Apparel
-
+
The effect of apparel items on a creature's ability to overcome the effects of darkness for the purpose of making ranged attacks.
Apparel
diff --git a/Defs/Stats/Stats_Weapons_Ranged.xml b/Defs/Stats/Stats_Weapons_Ranged.xml
index 9379e7e4fe..959602c357 100644
--- a/Defs/Stats/Stats_Weapons_Ranged.xml
+++ b/Defs/Stats/Stats_Weapons_Ranged.xml
@@ -152,6 +152,7 @@
+ True
@@ -165,6 +166,7 @@
+ True
diff --git a/Source/CombatExtended/CombatExtended/StatParts/Base/StatPart_StatSelect.cs b/Source/CombatExtended/CombatExtended/StatParts/Base/StatPart_StatSelect.cs
index 4d3f9c60a7..d378bcf61c 100644
--- a/Source/CombatExtended/CombatExtended/StatParts/Base/StatPart_StatSelect.cs
+++ b/Source/CombatExtended/CombatExtended/StatParts/Base/StatPart_StatSelect.cs
@@ -103,9 +103,40 @@ public override void TransformValue(StatRequest req, ref float result)
public override string ExplanationPart(StatRequest req)
{
- if (req.HasThing && req.Pawn != null)
+ if (req.HasThing && req.Thing is Pawn pawn)
{
- return "";
+ string result = "";
+ if (apparelStat != null)
+ {
+ float value = 0;
+ ThingOwner wornApparel = pawn.apparel.wornApparel;
+ if (sumApparelsStat)
+ {
+ for (int i = 0; i < wornApparel.Count; i++)
+ {
+ value += GetEquipmentStat(wornApparel[i], apparelStat);
+ }
+ }
+ else
+ {
+ for (int i = 0; i < wornApparel.Count; i++)
+ {
+ value = Select(value, GetEquipmentStat(wornApparel[i], apparelStat));
+ }
+ }
+ result += apparelStat.LabelCap + ": " + value.ToStringPercent() + "\n";
+ }
+ if (weaponStat != null)
+ {
+ result += weaponStat.LabelCap + ": " + (pawn.equipment.Primary != null
+ ? GetEquipmentStat(pawn.equipment.Primary, weaponStat).ToStringPercent()
+ : "0%") + "\n";
+ }
+ if (implantStat != null)
+ {
+ result += implantStat.LabelCap + ": " + pawn.GetStatValue(implantStat).ToStringPercent() + "\n";
+ }
+ return result;
}
return null;
}
diff --git a/Source/CombatExtended/CombatExtended/StatParts/StatPart_Bipod.cs b/Source/CombatExtended/CombatExtended/StatParts/StatPart_Bipod.cs
index bc09134cc8..56dbca12de 100644
--- a/Source/CombatExtended/CombatExtended/StatParts/StatPart_Bipod.cs
+++ b/Source/CombatExtended/CombatExtended/StatParts/StatPart_Bipod.cs
@@ -17,42 +17,57 @@ public class Bipod_Recoil_StatPart : StatPart
{
public override void TransformValue(StatRequest req, ref float val)
{
- var varA = req.Thing.TryGetComp();
if (Controller.settings.BipodMechanics)
{
- if (varA != null)
+ if (req.HasThing)
{
- if (varA.IsSetUpRn == true)
+ var varA = req.Thing.TryGetComp();
+ if (varA != null)
{
- val *= varA.Props.recoilMulton;
- }
- else
- {
- val *= varA.Props.recoilMultoff;
+ if (varA.IsSetUpRn)
+ {
+ val *= varA.Props.recoilMulton;
+ }
+ else
+ {
+ val *= varA.Props.recoilMultoff;
+ }
}
}
+ else if (req.Def is ThingDef reqDef)
+ {
+ var bipodProps = reqDef.GetCompProperties();
+ val *= bipodProps?.recoilMulton ?? 1f;
+ }
}
-
}
public override string ExplanationPart(StatRequest req)
{
- var varA = req.Thing.TryGetComp();
- if (varA != null)
+ if (Controller.settings.BipodMechanics)
{
- if (varA.IsSetUpRn == true)
+ if (req.HasThing)
{
- return "Bipod IS set up -" + " x".Colorize(Color.green) + varA.Props.recoilMulton.ToString().Colorize(Color.green);
+ var varA = req.Thing.TryGetComp();
+ if (varA != null)
+ {
+ if (varA.IsSetUpRn)
+ {
+ return "Bipod IS set up -" + " x".Colorize(ColorLibrary.Green) + varA.Props.recoilMulton.ToString().Colorize(ColorLibrary.Green);
+ }
+ else
+ {
+ return "Bipod is NOT set up -" + " x".Colorize(ColorLibrary.LogError) + varA.Props.recoilMultoff.ToString().Colorize(ColorLibrary.LogError);
+ }
+ }
}
- else
+ else if (req.Def is ThingDef reqDef)
{
- return "Bipod is NOT set up -" + " x".Colorize(Color.red) + varA.Props.recoilMultoff.ToString().Colorize(Color.red);
+ var bipodProps = reqDef.GetCompProperties();
+ if (bipodProps != null) return "Bipod IS set up -" + " x".Colorize(ColorLibrary.Green) + bipodProps.recoilMulton.ToString().Colorize(ColorLibrary.Green);
}
}
- else
- {
- return "";
- }
+ return null;
}
}
@@ -61,42 +76,58 @@ public class Bipod_Sway_StatPart : StatPart
{
public override void TransformValue(StatRequest req, ref float val)
{
- var varA = req.Thing.TryGetComp();
if (Controller.settings.BipodMechanics)
{
- if (varA != null)
+ if (req.HasThing)
{
- if (varA.IsSetUpRn == true)
+ var varA = req.Thing.TryGetComp();
+ if (varA != null)
{
- val *= varA.Props.swayMult;
- }
- else
- {
- val *= varA.Props.swayPenalty;
+ if (varA.IsSetUpRn)
+ {
+ val *= varA.Props.swayMult;
+ }
+ else
+ {
+ val *= varA.Props.swayPenalty;
+ }
}
}
+ else if (req.Def is ThingDef reqDef)
+ {
+ var bipodProps = reqDef.GetCompProperties();
+ val *= bipodProps?.swayMult ?? 1f;
+ }
}
}
public override string ExplanationPart(StatRequest req)
{
- var varA = req.Thing.TryGetComp();
- if (varA != null)
+ if (Controller.settings.BipodMechanics)
{
- if (varA.IsSetUpRn == true)
+ if (req.HasThing)
{
- return "Bipod IS set up -" + " x".Colorize(Color.green) + varA.Props.swayMult.ToString().Colorize(Color.green);
+ var varA = req.Thing.TryGetComp();
+ if (varA != null)
+ {
+ if (varA.IsSetUpRn)
+ {
+ return "Bipod IS set up -" + " x".Colorize(ColorLibrary.Green) + varA.Props.swayMult.ToString().Colorize(ColorLibrary.Green);
+ }
+ else
+ {
+ return "Bipod is NOT set up -" + " x".Colorize(ColorLibrary.LogError) + varA.Props.swayPenalty.ToString().Colorize(ColorLibrary.LogError);
+ }
+ }
}
- else
+ else if (req.Def is ThingDef reqDef)
{
- return "Bipod is NOT set up - " + "x".Colorize(Color.red) + varA.Props.swayPenalty.ToString().Colorize(Color.red);
+ var bipodProps = reqDef.GetCompProperties();
+ if (bipodProps != null) return "Bipod IS set up -" + " x".Colorize(ColorLibrary.Green) + bipodProps.swayPenalty.ToString().Colorize(ColorLibrary.Green);
}
}
- else
- {
- return "";
- }
+ return null;
}
}
}
diff --git a/Source/CombatExtended/CombatExtended/StatParts/StatPart_StatMaxima.cs b/Source/CombatExtended/CombatExtended/StatParts/StatPart_StatMaxima.cs
index a23789636f..ea29135525 100644
--- a/Source/CombatExtended/CombatExtended/StatParts/StatPart_StatMaxima.cs
+++ b/Source/CombatExtended/CombatExtended/StatParts/StatPart_StatMaxima.cs
@@ -15,5 +15,10 @@ protected override float Select(float first, float second)
{
return Mathf.Max(first, second);
}
+
+ public override string ExplanationPart(StatRequest req)
+ {
+ return "Picks the highest value of available: \n\n" + base.ExplanationPart(req);
+ }
}
}
diff --git a/Source/CombatExtended/CombatExtended/StatParts/StatPart_StatMinima.cs b/Source/CombatExtended/CombatExtended/StatParts/StatPart_StatMinima.cs
index b1db060246..8ec1969d81 100644
--- a/Source/CombatExtended/CombatExtended/StatParts/StatPart_StatMinima.cs
+++ b/Source/CombatExtended/CombatExtended/StatParts/StatPart_StatMinima.cs
@@ -12,5 +12,10 @@ protected override float Select(float first, float second)
{
return Mathf.Min(first, second);
}
+
+ public override string ExplanationPart(StatRequest req)
+ {
+ return "Picks the lowest value of available: \n\n" + base.ExplanationPart(req);
+ }
}
}
diff --git a/Source/CombatExtended/CombatExtended/StatWorkers/StatWorker_BipodDisplay.cs b/Source/CombatExtended/CombatExtended/StatWorkers/StatWorker_BipodDisplay.cs
index 2e77bf605f..06ce191b1e 100644
--- a/Source/CombatExtended/CombatExtended/StatWorkers/StatWorker_BipodDisplay.cs
+++ b/Source/CombatExtended/CombatExtended/StatWorkers/StatWorker_BipodDisplay.cs
@@ -89,7 +89,7 @@ public override string GetExplanationFinalizePart(StatRequest req, ToStringNumbe
}
- result += "\n" + "CE_BipodStatWhenSetUp".Translate().Colorize(Color.green) + "\n";
+ result += "\n" + "CE_BipodStatWhenSetUp".Translate().Colorize(ColorLibrary.Green) + "\n";
result += CE_StatDefOf.Recoil.label + ": " + Math.Round((VerbPropsCE.recoilAmount * BipodCompProps.recoilMulton), 2);
result += "\n";
@@ -103,7 +103,7 @@ public override string GetExplanationFinalizePart(StatRequest req, ToStringNumbe
result += "CE_BipodStatWarmUp".Translate() + ": " + (BipodCompProps.warmupMult * VerbPropsCE.warmupTime);
result += "\n" + "\n";
- result += "CE_BipodStatWhenNotSetUp".Translate().Colorize(Color.red) + "\n";
+ result += "CE_BipodStatWhenNotSetUp".Translate().Colorize(ColorLibrary.LogError) + "\n";
result += CE_StatDefOf.Recoil.label + ": " + Math.Round((VerbPropsCE.recoilAmount * BipodCompProps.recoilMultoff), 2);
@@ -132,13 +132,13 @@ public override string GetExplanationFinalizePart(StatRequest req, ToStringNumbe
return base.GetExplanationFinalizePart(req, numberSense, finalVal);
}
- string result = "CE_BipodSetupTime".Translate() + BipodCompProps.ticksToSetUp + " ticks (" + (BipodCompProps.ticksToSetUp / 60) + "s)" + "\n" + "Stats when set up: ".Colorize(Color.green) + "\n";
+ string result = "CE_BipodSetupTime".Translate() + BipodCompProps.ticksToSetUp + " ticks (" + (BipodCompProps.ticksToSetUp / 60) + "s)" + "\n" + "Stats when set up: ".Colorize(ColorLibrary.Green) + "\n";
- result += CE_StatDefOf.Recoil.label + ": " + (VerbPropsCE.recoilAmount * BipodCompProps.recoilMulton);
+ result += CE_StatDefOf.Recoil.label + ": " + Math.Round((VerbPropsCE.recoilAmount * BipodCompProps.recoilMulton), 2);
result += "\n";
- result += CE_StatDefOf.SwayFactor.label + ": " + (((ThingDef)(req.Def)).statBases.Find(x => x.stat == CE_StatDefOf.SwayFactor).value * BipodCompProps.swayPenalty);
+ result += CE_StatDefOf.SwayFactor.label + ": " + Math.Round((((ThingDef)(req.Def)).statBases.Find(x => x.stat == CE_StatDefOf.SwayFactor).value * BipodCompProps.swayMult), 2);
result += "\n";
@@ -150,13 +150,13 @@ public override string GetExplanationFinalizePart(StatRequest req, ToStringNumbe
result += "\n" + "\n";
- result += "CE_BipodStatWhenNotSetUp".Translate().Colorize(Color.red) + "\n";
+ result += "CE_BipodStatWhenNotSetUp".Translate().Colorize(ColorLibrary.LogError) + "\n";
- result += CE_StatDefOf.Recoil.label + ": " + (VerbPropsCE.recoilAmount * BipodCompProps.recoilMultoff);
+ result += CE_StatDefOf.Recoil.label + ": " + Math.Round((VerbPropsCE.recoilAmount * BipodCompProps.recoilMultoff), 2);
result += "\n";
- result += CE_StatDefOf.SwayFactor.label + ": " + (((ThingDef)(req.Def)).statBases.Find(x => x.stat == CE_StatDefOf.SwayFactor).value * BipodCompProps.swayPenalty);
+ result += CE_StatDefOf.SwayFactor.label + ": " + Math.Round((((ThingDef)(req.Def)).statBases.Find(x => x.stat == CE_StatDefOf.SwayFactor).value * BipodCompProps.swayPenalty), 2);
result += "\n";
From 2e524ef4647046296da18b94e18855ee32f2a655 Mon Sep 17 00:00:00 2001
From: Safairette <71556532+Safairette@users.noreply.github.com>
Date: Thu, 5 Dec 2024 00:33:07 +0200
Subject: [PATCH 2/3] Bite me style checker
---
.../CombatExtended/CombatExtended/StatParts/StatPart_Bipod.cs | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/Source/CombatExtended/CombatExtended/StatParts/StatPart_Bipod.cs b/Source/CombatExtended/CombatExtended/StatParts/StatPart_Bipod.cs
index 56dbca12de..43cea93ecc 100644
--- a/Source/CombatExtended/CombatExtended/StatParts/StatPart_Bipod.cs
+++ b/Source/CombatExtended/CombatExtended/StatParts/StatPart_Bipod.cs
@@ -64,7 +64,7 @@ public override string ExplanationPart(StatRequest req)
else if (req.Def is ThingDef reqDef)
{
var bipodProps = reqDef.GetCompProperties();
- if (bipodProps != null) return "Bipod IS set up -" + " x".Colorize(ColorLibrary.Green) + bipodProps.recoilMulton.ToString().Colorize(ColorLibrary.Green);
+ if (bipodProps != null) { return "Bipod IS set up -" + " x".Colorize(ColorLibrary.Green) + bipodProps.recoilMulton.ToString().Colorize(ColorLibrary.Green); }
}
}
return null;
@@ -124,7 +124,7 @@ public override string ExplanationPart(StatRequest req)
else if (req.Def is ThingDef reqDef)
{
var bipodProps = reqDef.GetCompProperties();
- if (bipodProps != null) return "Bipod IS set up -" + " x".Colorize(ColorLibrary.Green) + bipodProps.swayPenalty.ToString().Colorize(ColorLibrary.Green);
+ if (bipodProps != null) { return "Bipod IS set up -" + " x".Colorize(ColorLibrary.Green) + bipodProps.swayPenalty.ToString().Colorize(ColorLibrary.Green); }
}
}
return null;
From 8f9d2531bf7759feda6f50c3f6901e735cea8c78 Mon Sep 17 00:00:00 2001
From: Safairette <71556532+Safairette@users.noreply.github.com>
Date: Thu, 5 Dec 2024 00:48:05 +0200
Subject: [PATCH 3/3] Move minima/maxima explanations to translate keys
---
Languages/English/Keyed/Stats.xml | 2 ++
.../CombatExtended/StatParts/StatPart_StatMaxima.cs | 2 +-
.../CombatExtended/StatParts/StatPart_StatMinima.cs | 3 ++-
3 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/Languages/English/Keyed/Stats.xml b/Languages/English/Keyed/Stats.xml
index 0fe035aee1..f609818007 100644
--- a/Languages/English/Keyed/Stats.xml
+++ b/Languages/English/Keyed/Stats.xml
@@ -9,5 +9,7 @@
Additional material toughness multiplier:
Wielder skill effect:
Long range radio
+ Picks the lowest value of available
+ Picks the highest value of available
\ No newline at end of file
diff --git a/Source/CombatExtended/CombatExtended/StatParts/StatPart_StatMaxima.cs b/Source/CombatExtended/CombatExtended/StatParts/StatPart_StatMaxima.cs
index ea29135525..7c2aaf45cc 100644
--- a/Source/CombatExtended/CombatExtended/StatParts/StatPart_StatMaxima.cs
+++ b/Source/CombatExtended/CombatExtended/StatParts/StatPart_StatMaxima.cs
@@ -18,7 +18,7 @@ protected override float Select(float first, float second)
public override string ExplanationPart(StatRequest req)
{
- return "Picks the highest value of available: \n\n" + base.ExplanationPart(req);
+ return "CE_StatPart_MaximaExplanation".Translate() + ": \n\n" + base.ExplanationPart(req);
}
}
}
diff --git a/Source/CombatExtended/CombatExtended/StatParts/StatPart_StatMinima.cs b/Source/CombatExtended/CombatExtended/StatParts/StatPart_StatMinima.cs
index 8ec1969d81..bed60969f7 100644
--- a/Source/CombatExtended/CombatExtended/StatParts/StatPart_StatMinima.cs
+++ b/Source/CombatExtended/CombatExtended/StatParts/StatPart_StatMinima.cs
@@ -2,6 +2,7 @@
using System.Runtime.CompilerServices;
using RimWorld;
using UnityEngine;
+using Verse;
namespace CombatExtended
{
@@ -15,7 +16,7 @@ protected override float Select(float first, float second)
public override string ExplanationPart(StatRequest req)
{
- return "Picks the lowest value of available: \n\n" + base.ExplanationPart(req);
+ return "CE_StatPart_MinimaExplanation".Translate() + ": \n\n" + base.ExplanationPart(req);
}
}
}