From: xangelo Date: Thu, 13 Jul 2023 18:26:36 +0000 (-0400) Subject: refactor: simplify player damage to monster workflow X-Git-Tag: v0.2.0~12 X-Git-Url: https://git.xangelo.ca/?a=commitdiff_plain;h=1d9b2bbc75ae3bee1d1da08be42c13281178a41c;p=risinglegends.git refactor: simplify player damage to monster workflow This majorly simplifies the player damage to monster damage workflow. It also identified a couple bugs with how we were calculating damage. --- diff --git a/src/server/api.ts b/src/server/api.ts index 885e49b..5123f19 100644 --- a/src/server/api.ts +++ b/src/server/api.ts @@ -321,77 +321,36 @@ io.on('connection', async socket => { const playerFinalHeal = Math.floor(boost.hp + hpHealAfterMasteries); roundData.roundDetails.push(`You targeted the monsters ${data.target.toUpperCase()} with ${attackType} damage!`); - if(data.target === 'arms') { - if(monster.armsAp > 0) { - monster.armsAp -= playerFinalDamage; - - roundData.roundDetails.push(`You dealt ${playerFinalDamage} damage to their armour`); - if(monster.armsAp < 0) { - - roundData.roundDetails.push(`You destroyed the ${monster.name}'s armour!'`); - roundData.roundDetails.push(`You dealt ${monster.armsAp * -1} damage to their HP`); - monster.hp += monster.armsAp; - monster.armsAp = 0; - } - } - else { - roundData.roundDetails.push(`You hit the ${monster.name} for ${playerFinalDamage} damage.`); - monster.hp -= playerFinalDamage; - } - } - else if (data.target === 'head') { - if(monster.helmAp > 0) { - monster.helmAp -= playerFinalDamage; - - roundData.roundDetails.push(`You dealt ${playerFinalDamage} damage to their armour`); - if(monster.helmAp < 0) { - - roundData.roundDetails.push(`You destroyed the ${monster.name}'s armour!'`); - roundData.roundDetails.push(`You dealt ${monster.armsAp * 1} damage to their HP`); - monster.hp += monster.helmAp; - monster.helmAp = 0; - } - } - else { - roundData.roundDetails.push(`You hit the ${monster.name} for ${playerFinalDamage} damage.`); - monster.hp -= playerFinalDamage; - } + let armourKey: string; + switch(data.target) { + case 'arms': + armourKey = 'armsAp'; + break; + case 'head': + armourKey = 'helmAp'; + break; + case 'legs': + armourKey = 'legsAp'; + break; + case 'body': + armourKey = 'chestAp'; + break; } - else if(data.target === 'legs') { - if(monster.legsAp > 0) { - monster.legsAp -= playerFinalDamage; - roundData.roundDetails.push(`You dealt ${playerFinalDamage} damage to their armour`); - if(monster.legsAp < 0) { + if(monster[armourKey] && monster[armourKey] > 0) { + monster[armourKey] -= playerFinalDamage; - roundData.roundDetails.push(`You destroyed the ${monster.name}'s armour!'`); - roundData.roundDetails.push(`You dealt ${monster.legsAp * 1} damage to their HP`); - monster.hp += monster.legsAp; - monster.legsAp = 0; - } - } - else { - roundData.roundDetails.push(`You hit the ${monster.name} for ${playerFinalDamage} damage.`); - monster.hp -= playerFinalDamage; + roundData.roundDetails.push(`You dealt ${playerFinalDamage} damage to their armour`); + if(monster[armourKey] < 0) { + roundData.roundDetails.push(`You destroyed the ${monster.name}'s armour!'`); + roundData.roundDetails.push(`You dealt ${monster[armourKey] * -1} damage to their HP`); + monster.hp += monster[armourKey]; + monster[armourKey] = 0; } } else { - if(monster.chestAp > 0) { - monster.chestAp -= playerFinalDamage; - - roundData.roundDetails.push(`You dealt ${playerFinalDamage} damage to their armour`); - - if(monster.chestAp < 0) { - roundData.roundDetails.push(`You destroyed the ${monster.name}'s armour!'`); - roundData.roundDetails.push(`You dealt ${monster.chestAp * 1} damage to their HP`); - monster.hp += monster.chestAp; - monster.chestAp = 0; - } - } - else { - roundData.roundDetails.push(`You hit the ${monster.name} for ${playerFinalDamage} damage.`); - monster.hp -= playerFinalDamage; - } + roundData.roundDetails.push(`You hit the ${monster.name} for ${playerFinalDamage} damage.`); + monster.hp -= playerFinalDamage; } if(monster.hp <= 0) {