[1.5.5] Damage Penetration code is incorrect
Posted: Tue Jun 20, 2017 12:32 pm
Here is the code with correction:
The else clause covers the case where the shield is entirely used up by the damge, it expires. The current code takes the adjusted_value (the bit that hits the shield) and subtracts the shield value. But this doesn't then include the portion of the damage that "penetrated" and so bypassed the shield. So the correct amount of damage is actually the original damage amount (= value) minus the bit the shield soaked up.
For example, let's say the damage is 100 with 25% damage penetration. This means 25 damage bypasses the shield and 75 hits the shield. Let's say then the shield is 60. The current code says that after the shield is used up the damage remaining is 15 (75 - 60). But this omits the 25 which bypasses, so the total damage remaining is 40 (25 + 15). Which is simply the original damage value minus the shield.
I studied this for about 2 hours using the log, to finally work out why the numbers never made sense.
So I'm fairly confident my proposal is the correct one. (But happy to be corrected if I'm wrong, too!).
Code: Select all
local adjusted_value = value
if src and src.attr and src:attr("damage_shield_penetrate") then
adjusted_value = value * (1 - (util.bound(src.damage_shield_penetrate, 0, 100) / 100))
end
...
if adjusted_value <= self.damage_shield_absorb then
self.damage_shield_absorb = self.damage_shield_absorb - adjusted_value
if reflection > 0 then reflect_damage = adjusted_value end
value = value - adjusted_value
else
if reflection > 0 then reflect_damage = self.damage_shield_absorb end
--- value = adjusted_value - self.damage_shield_absorb
+++ value = value - self.damage_shield_absorb
adjusted_value = self.damage_shield_absorb
self.damage_shield_absorb = 0
end
For example, let's say the damage is 100 with 25% damage penetration. This means 25 damage bypasses the shield and 75 hits the shield. Let's say then the shield is 60. The current code says that after the shield is used up the damage remaining is 15 (75 - 60). But this omits the 25 which bypasses, so the total damage remaining is 40 (25 + 15). Which is simply the original damage value minus the shield.
I studied this for about 2 hours using the log, to finally work out why the numbers never made sense.
So I'm fairly confident my proposal is the correct one. (But happy to be corrected if I'm wrong, too!).