Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up various stats #3582

Open
wants to merge 3 commits into
base: Development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any reason to specify in the label? I don't believe it's possible for the various types of night vision efficiencies to appear together on the same panel, is it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

The stat explanation for the combined night vision stat now displays all 3 sources. And is also where one of the new translation keys is used. The other is on the currently unused statPart that selects the smallest value that's available instead.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see. Thoughts on changing the format to night vision efficiency (weapon)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if that's an improvement over the current one, it's probably better when viewed side-by-side like in the screenshot, but I dunno if that's the case for individual items.

<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
2 changes: 2 additions & 0 deletions Languages/English/Keyed/Stats.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@
<CE_StatsReport_WeaponToughness_StuffEffect>Additional material toughness multiplier:</CE_StatsReport_WeaponToughness_StuffEffect>
<CE_StatsReport_WeaponToughness_HolderEffect>Wielder skill effect:</CE_StatsReport_WeaponToughness_HolderEffect>
<CE_Long_Range_Radio>Long range radio</CE_Long_Range_Radio>
<CE_StatPart_MinimaExplanation>Picks the lowest value of available</CE_StatPart_MinimaExplanation>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What uses/will use these two Keys?

<CE_StatPart_MaximaExplanation>Picks the highest value of available</CE_StatPart_MaximaExplanation>

</LanguageData>
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); }
}
}
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); }
}
}
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 "CE_StatPart_MaximaExplanation".Translate() + ": \n\n" + base.ExplanationPart(req);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Runtime.CompilerServices;
using RimWorld;
using UnityEngine;
using Verse;

namespace CombatExtended
{
Expand All @@ -12,5 +13,10 @@ protected override float Select(float first, float second)
{
return Mathf.Min(first, second);
}

public override string ExplanationPart(StatRequest req)
{
return "CE_StatPart_MinimaExplanation".Translate() + ": \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
Loading