Ensure damage can never exceed victim's remaining HP

This commit is contained in:
ceikry
2021-07-05 19:14:42 -05:00
parent 74dadf2c99
commit 4760629f7e
3 changed files with 8 additions and 0 deletions
@@ -86,6 +86,8 @@ open class MagicSwingHandler
if (spell!!.type === SpellType.BLITZ) { if (spell!!.type === SpellType.BLITZ) {
ticks++ ticks++
} }
if(state.estimatedHit > victim.skills.lifepoints) state.estimatedHit = victim.skills.lifepoints
if(state.estimatedHit + state.secondaryHit > victim.skills.lifepoints) state.secondaryHit -= ((state.estimatedHit + state.secondaryHit) - victim.skills.lifepoints)
addExperience(entity, victim, state) addExperience(entity, victim, state)
return ticks return ticks
} }
@@ -75,6 +75,10 @@ open class MeleeSwingHandler
hit = RandomFunction.random(max) hit = RandomFunction.random(max)
} }
state.estimatedHit = hit state.estimatedHit = hit
if(victim != null) {
if (state.estimatedHit > victim.skills.lifepoints) state.estimatedHit = victim.skills.lifepoints
if (state.estimatedHit + state.secondaryHit > victim.skills.lifepoints) state.secondaryHit -= ((state.estimatedHit + state.secondaryHit) - victim.skills.lifepoints)
}
addExperience(entity, victim, state) addExperience(entity, victim, state)
return 1 return 1
} }
@@ -93,6 +93,8 @@ open class RangeSwingHandler
if (entity == null || victim!!.location == null) { if (entity == null || victim!!.location == null) {
return -1 return -1
} }
if(state.estimatedHit > victim.skills.lifepoints) state.estimatedHit = victim.skills.lifepoints
if(state.estimatedHit + state.secondaryHit > victim.skills.lifepoints) state.secondaryHit -= ((state.estimatedHit + state.secondaryHit) - victim.skills.lifepoints)
useAmmo(entity, state, victim.location) useAmmo(entity, state, victim.location)
addExperience(entity, victim, state) addExperience(entity, victim, state)
return 1 + ceil(entity.location.getDistance(victim.location) * 0.3).toInt() return 1 + ceil(entity.location.getDistance(victim.location) * 0.3).toInt()