Skip to content

Commit

Permalink
Merge pull request #3408 from Tostov/Ambient-Default-Pen
Browse files Browse the repository at this point in the history
Ambient Armor Penetration
  • Loading branch information
N7Huntsman authored Sep 24, 2024
2 parents a29620a + 15b6004 commit aaf1976
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 20 deletions.
2 changes: 1 addition & 1 deletion Defs/Stats/Stats_Apparel.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<StatDef ParentName="ArmorRatingBase">
<defName>ArmorRating_Electric</defName>
<label>Armor - Electric</label>
<description>Percentage reduction of damage from electricity such as EMP pulses and the EMP part of EMP and ion projectiles.\n\nHaving a value of 100% or above makes the creature immune to all electrical damage in that body region.</description>
<description>Percentage reduction of damage from electricity such as EMP pulses and the EMP part of EMP and ion projectiles.\n\nThe total across all sources of this armor is added for a protected part, then reduced by the armor reduction value of the incoming attack. If the resulting value is 100% or greater, protected parts of the pawn will be immune to the incoming attack's electrical damage in that body region.</description>
<displayPriorityInCategory>39</displayPriorityInCategory>
<parts>
<li Class="StatPart_Stuff">
Expand Down
1 change: 1 addition & 0 deletions Languages/English/Keyed/Descriptions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<CE_DescArmorPenetration>Armor penetration</CE_DescArmorPenetration>
<CE_DescSharpPenetration>Sharp penetration</CE_DescSharpPenetration>
<CE_DescBluntPenetration>Blunt penetration</CE_DescBluntPenetration>
<CE_DescAmbientPenetration>Armor reduction</CE_DescAmbientPenetration>
<CE_DescPelletCount>Pellet count</CE_DescPelletCount>
<CE_DescSpreadMult>Spread factor</CE_DescSpreadMult>
<CE_DescFragments>Fragments</CE_DescFragments>
Expand Down
2 changes: 1 addition & 1 deletion Patches/Core/Stats/Stats.xml
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
<Operation Class="PatchOperationReplace">
<xpath>Defs/StatDef[defName="ArmorRating_Heat"]/description</xpath>
<value>
<description>Percentage reduction of attack damage from extreme heat or cold, such as fire, incendiary explosions, or frostbite-inflicting attacks.\n\nThis value is reduced by the Heat armor penetration value of the incoming attack. If the resulting value is 100% or greater, protected parts of the pawn will be immune to the incoming attack's hot or cold damage.</description>
<description>Percentage reduction of attack damage from extreme heat or cold, such as fire, incendiary explosions, or frostbite-inflicting attacks.\n\nThe total across all sources of this armor is added for a protected part, then reduced by the armor reduction value of the incoming attack. If the resulting value is 100% or greater, protected parts of the pawn will be immune to the incoming attack's hot or cold damage.</description>
</value>
</Operation>

Expand Down
30 changes: 18 additions & 12 deletions Source/CombatExtended/CombatExtended/AmmoUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,23 +51,29 @@ public static string GetProjectileReadout(this ThingDef projectileDef, Thing wea
{
stringBuilder.AppendLine(" " + "CE_DescExplosionRadius".Translate() + ": " + props.explosionRadius.ToStringByStyle(ToStringStyle.FloatOne));
}

// Thermal/Electric Penetration
if ((props.damageDef.armorCategory == CE_DamageArmorCategoryDefOf.Heat
|| props.damageDef.armorCategory == CE_DamageArmorCategoryDefOf.Electric) && props.damageDef.defaultArmorPenetration > 0f)
{
stringBuilder.AppendLine(" " + "CE_DescAmbientPenetration".Translate() + ": " + (props.damageDef.defaultArmorPenetration).ToStringByStyle(ToStringStyle.PercentZero));
}
// Sharp / blunt AP
if (props.explosionRadius > 0)
if (props.damageDef.armorCategory != CE_DamageArmorCategoryDefOf.Heat
&& props.damageDef.armorCategory != CE_DamageArmorCategoryDefOf.Electric
&& props.damageDef != DamageDefOf.Stun
&& props.damageDef != DamageDefOf.Extinguish
&& props.damageDef != DamageDefOf.Smoke
&& props.GetDamageAmount(weapon) != 0)
{
if (props.damageDef.armorCategory != CE_DamageArmorCategoryDefOf.Heat
&& props.damageDef.armorCategory != CE_DamageArmorCategoryDefOf.Electric
&& props.damageDef != DamageDefOf.Stun
&& props.damageDef != DamageDefOf.Extinguish
&& props.damageDef != DamageDefOf.Smoke)
if (props.explosionRadius > 0)
{
stringBuilder.AppendLine(" " + "CE_DescBluntPenetration".Translate() + ": " + props.GetExplosionArmorPenetration() + " " + "CE_MPa".Translate());
}
}
else
{
stringBuilder.AppendLine(" " + "CE_DescSharpPenetration".Translate() + ": " + (props.armorPenetrationSharp * multiplier).ToStringByStyle(ToStringStyle.FloatTwo) + " " + "CE_mmRHA".Translate());
stringBuilder.AppendLine(" " + "CE_DescBluntPenetration".Translate() + ": " + (props.armorPenetrationBlunt * multiplier).ToStringByStyle(ToStringStyle.FloatTwo) + " " + "CE_MPa".Translate());
else
{
stringBuilder.AppendLine(" " + "CE_DescSharpPenetration".Translate() + ": " + (props.armorPenetrationSharp * multiplier).ToStringByStyle(ToStringStyle.FloatTwo) + " " + "CE_mmRHA".Translate());
stringBuilder.AppendLine(" " + "CE_DescBluntPenetration".Translate() + ": " + (props.armorPenetrationBlunt * multiplier).ToStringByStyle(ToStringStyle.FloatTwo) + " " + "CE_MPa".Translate());
}
}

// Secondary explosion
Expand Down
20 changes: 14 additions & 6 deletions Source/CombatExtended/CombatExtended/ArmorUtilityCE.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,15 @@ public static DamageInfo GetAfterArmorDamage(DamageInfo originalDinfo, Pawn pawn

var dinfo = new DamageInfo(originalDinfo);
var dmgAmount = dinfo.Amount;
var penAmount = dinfo.ArmorPenetrationInt; //GetPenetrationValue(originalDinfo);
var involveArmor = dinfo.Def.harmAllLayersUntilOutside || hitPart.depth == BodyPartDepth.Outside;
bool isAmbientDamage = dinfo.IsAmbientDamage();

// In case of ambient damage (fire, electricity) we apply a percentage reduction formula based on the sum of all applicable armor
// In case of ambient damage (fire, electricity) we apply a percentage reduction formula based on the sum of all applicable armor, using the penetration from the type of damagedef
if (isAmbientDamage)
{
dinfo.SetAmount(Mathf.CeilToInt(GetAmbientPostArmorDamage(dmgAmount, originalDinfo.Def.armorCategory.armorRatingStat, pawn, hitPart)));
penAmount = dinfo.defInt.defaultArmorPenetration;
dinfo.SetAmount(Mathf.CeilToInt(GetAmbientPostArmorDamage(dmgAmount, penAmount, originalDinfo.Def.armorCategory.armorRatingStat, pawn, hitPart)));
armorDeflected = dinfo.Amount <= 0;
return dinfo;
}
Expand All @@ -73,7 +75,6 @@ public static DamageInfo GetAfterArmorDamage(DamageInfo originalDinfo, Pawn pawn
deflectionComp.deflectedSharp = false;
}

var penAmount = originalDinfo.ArmorPenetrationInt; //GetPenetrationValue(originalDinfo);

// Apply worn armor
if (involveArmor && pawn.apparel != null && !pawn.apparel.WornApparel.NullOrEmpty())
Expand Down Expand Up @@ -419,9 +420,13 @@ private static bool TryDamageArmor(DamageDef def, float penAmount, float armorAm
/// <param name="pawn">The damaged pawn</param>
/// <param name="part">The body part affected</param>
/// <returns>The post-armor damage ranging from 0 to the original amount</returns>
private static float GetAmbientPostArmorDamage(float dmgAmount, StatDef armorRatingStat, Pawn pawn, BodyPartRecord part)
private static float GetAmbientPostArmorDamage(float dmgAmount, float penAmount, StatDef armorRatingStat, Pawn pawn, BodyPartRecord part)
{
var dmgMult = 1f;
if (penAmount < 0f)
{
penAmount = 0f;
}
var dmgMult = 1f + penAmount;
if (part.IsInGroup(CE_BodyPartGroupDefOf.CoveredByNaturalArmor))
{
dmgMult -= pawn.GetStatValue(armorRatingStat);
Expand All @@ -447,7 +452,10 @@ private static float GetAmbientPostArmorDamage(float dmgAmount, StatDef armorRat
}
}
}

if (dmgMult > 1f)
{
dmgMult = 1f;
}
var deflectionComp = pawn.TryGetComp<Comp_BurnDamageCalc>();
if (deflectionComp != null)
{
Expand Down

0 comments on commit aaf1976

Please sign in to comment.