Skip to content

Commit

Permalink
Stats cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Safairette committed Dec 4, 2024
1 parent 56cb6f1 commit f949019
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 49 deletions.
4 changes: 2 additions & 2 deletions Defs/Stats/Stats_NightVision.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@

<StatDef ParentName="EquipmentNightVisionBase">
<defName>NightVisionEfficiency_Weapon</defName>
<label>night vision efficiency</label>
<label>weapon night vision efficiency</label>
<description>The effect of a weapon's optics on the wielder's ability to overcome the effects of darkness for the purpose of firing accurately.</description>
<category>Weapon</category>
<parts>
Expand All @@ -76,7 +76,7 @@

<StatDef ParentName="EquipmentNightVisionBase">
<defName>NightVisionEfficiency_Apparel</defName>
<label>night vision efficiency</label>
<label>apparel night vision efficiency</label>
<description>The effect of apparel items on a creature's ability to overcome the effects of darkness for the purpose of making ranged attacks.</description>
<category>Apparel</category>
</StatDef>
Expand Down
2 changes: 2 additions & 0 deletions Defs/Stats/Stats_Weapons_Ranged.xml
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@
<parts>
<li Class="CombatExtended.StatPart_Attachments" />
</parts>
<alwaysHide>True</alwaysHide>
</StatDef>

<StatDef>
Expand All @@ -165,6 +166,7 @@
<parts>
<li Class="CombatExtended.StatPart_Attachments" />
</parts>
<alwaysHide>True</alwaysHide>
</StatDef>

<StatDef>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Apparel> 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;
}
Expand Down
105 changes: 68 additions & 37 deletions Source/CombatExtended/CombatExtended/StatParts/StatPart_Bipod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,42 +17,57 @@ public class Bipod_Recoil_StatPart : StatPart
{
public override void TransformValue(StatRequest req, ref float val)
{
var varA = req.Thing.TryGetComp<BipodComp>();
if (Controller.settings.BipodMechanics)
{
if (varA != null)
if (req.HasThing)
{
if (varA.IsSetUpRn == true)
var varA = req.Thing.TryGetComp<BipodComp>();
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<CompProperties_BipodComp>();
val *= bipodProps?.recoilMulton ?? 1f;
}
}

}

public override string ExplanationPart(StatRequest req)
{
var varA = req.Thing.TryGetComp<BipodComp>();
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<BipodComp>();
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<CompProperties_BipodComp>();
if (bipodProps != null) return "Bipod IS set up -" + " x".Colorize(ColorLibrary.Green) + bipodProps.recoilMulton.ToString().Colorize(ColorLibrary.Green);

Check failure on line 67 in Source/CombatExtended/CombatExtended/StatParts/StatPart_Bipod.cs

View workflow job for this annotation

GitHub Actions / build

Add braces to 'if' statement.
}
}
else
{
return "";
}
return null;
}
}

Expand All @@ -61,42 +76,58 @@ public class Bipod_Sway_StatPart : StatPart
{
public override void TransformValue(StatRequest req, ref float val)
{
var varA = req.Thing.TryGetComp<BipodComp>();
if (Controller.settings.BipodMechanics)
{
if (varA != null)
if (req.HasThing)
{
if (varA.IsSetUpRn == true)
var varA = req.Thing.TryGetComp<BipodComp>();
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<CompProperties_BipodComp>();
val *= bipodProps?.swayMult ?? 1f;
}
}

}

public override string ExplanationPart(StatRequest req)
{
var varA = req.Thing.TryGetComp<BipodComp>();
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<BipodComp>();
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<CompProperties_BipodComp>();
if (bipodProps != null) return "Bipod IS set up -" + " x".Colorize(ColorLibrary.Green) + bipodProps.swayPenalty.ToString().Colorize(ColorLibrary.Green);

Check failure on line 127 in Source/CombatExtended/CombatExtended/StatParts/StatPart_Bipod.cs

View workflow job for this annotation

GitHub Actions / build

Add braces to 'if' statement.
}
}
else
{
return "";
}
return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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);

Expand Down Expand Up @@ -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";

Expand All @@ -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";

Expand Down

0 comments on commit f949019

Please sign in to comment.