From d91dc012c42d68a637315f6d42c62c125eca0773 Mon Sep 17 00:00:00 2001 From: xangelo Date: Thu, 8 Jun 2023 12:48:17 -0400 Subject: [PATCH] support restoration_magic spells restoration magic heals you. Healing is done after monster damage is applied. You can't heal over max hp. You don't do any damage if you only have healing spells equipped during your casting. --- data/inventory.csv | 3 ++- src/server/api.ts | 36 +++++++++++++++++++++++++++++++++--- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/data/inventory.csv b/data/inventory.csv index 9b5d7d5..a105cca 100644 --- a/data/inventory.csv +++ b/data/inventory.csv @@ -6,4 +6,5 @@ Boots,ARMOUR,LEGS,Wanderer,light_armour_mastery,3,1,0,0,0,0,0,0,0,0,0,20 Short Sword,WEAPON,ANY_HAND,Wanderer,"bladed,one_handed_mastery",5,1,0,0,0,0,0,0,0,0,3,50 Morningstar,WEAPON,TWO_HANDED,Wanderer,"blunt,two_handed_mastery",15,1,5,0,0,0,0,0,0,0,7,70 Firebolt,SPELL,ANY_HAND,Wanderer,destruction_magic,10,1,0,0,0,0,0,0,0,0,5,0 -Icebolt,SPELL,ANY_HAND,Wanderer,destruction_magic,10,1,0,0,0,0,0,0,0,0,5,0 \ No newline at end of file +Icebolt,SPELL,ANY_HAND,Wanderer,destruction_magic,10,1,0,0,0,0,0,0,0,0,5,0 +Restore Health,SPELL,ANY_HAND,Wanderer,restoration_magic,10,1,0,0,0,0,0,0,0,0,5,0 \ No newline at end of file diff --git a/src/server/api.ts b/src/server/api.ts index 9ad397c..7d31d34 100644 --- a/src/server/api.ts +++ b/src/server/api.ts @@ -339,10 +339,12 @@ io.on('connection', async socket => { dexterity: 0, intelligence: 0, damage: 0, + hp: 0, }; const equipment: Map = new Map(); const weapons: EquippedItemDetails[] = []; + let anyDamageSpells: boolean = false; equippedItems.forEach(item => { if(item.type === 'ARMOUR') { equipment.set(item.equipment_slot, item); @@ -351,6 +353,9 @@ io.on('connection', async socket => { weapons.push(item); } else if(item.type === 'SPELL') { + if(item.affectedSkills.includes('destruction_magic')) { + anyDamageSpells = true; + } weapons.push(item); } @@ -358,7 +363,13 @@ io.on('connection', async socket => { boost.constitution += item.boosts.constitution; boost.dexterity += item.boosts.dexterity; boost.intelligence += item.boosts.intelligence; - boost.damage += item.boosts.damage; + + if(item.type === 'SPELL' && item.affectedSkills.includes('restoration_magic')) { + boost.hp += item.boosts.damage; + } + else { + boost.damage += item.boosts.damage; + } }); // if you flee'd, then we want to check your dex vs. the monsters @@ -379,11 +390,21 @@ io.on('connection', async socket => { const playerDamage = Math.floor(((primaryStat + boostStat) * 1.3) + boost.damage); const skillsUsed: Record = {}; + let hpHealAfterMasteries: number = -1; let playerDamageAfterMasteries: number = 0; // apply masteries! weapons.forEach(item => { item.affectedSkills.forEach(id => { - playerDamageAfterMasteries += playerDamage * Skills.get(id).effect(playerSkills.get(id)); + if(id === 'restoration_magic') { + if(hpHealAfterMasteries < 0) { + hpHealAfterMasteries = 0; + } + hpHealAfterMasteries += Skills.get(id).effect(playerSkills.get(id)); + } + else { + playerDamageAfterMasteries += playerDamage * Skills.get(id).effect(playerSkills.get(id)); + } + if(!skillsUsed[id]) { skillsUsed[id] = 0; } @@ -393,7 +414,8 @@ io.on('connection', async socket => { await updatePlayerSkills(player.id, skillsUsed); - const playerFinalDamage = Math.floor(playerDamage + playerDamageAfterMasteries); + const playerFinalDamage = (attackType === 'magical' && !anyDamageSpells) ? 0 : Math.floor(playerDamage + playerDamageAfterMasteries); + const playerFinalHeal = Math.floor(boost.hp + hpHealAfterMasteries); roundData.roundDetails.push(`You targeted the monsters ${data.target.toUpperCase()} with ${attackType} damage!`); if(data.target === 'arms') { @@ -533,6 +555,14 @@ io.on('connection', async socket => { player.hp -= monster.strength; } + if(playerFinalHeal > 0) { + player.hp += playerFinalHeal; + if(player.hp > maxHp(player.constitution, player.level)) { + player.hp = maxHp(player.constitution, player.level); + } + roundData.roundDetails.push(`You healed for ${playerFinalHeal} HP`); + } + // update the players inventory for this item! if(player.hp <= 0) { -- 2.25.1