support restoration_magic spells
authorxangelo <git@xangelo.ca>
Thu, 8 Jun 2023 16:48:17 +0000 (12:48 -0400)
committerxangelo <git@xangelo.ca>
Thu, 8 Jun 2023 19:22:32 +0000 (15:22 -0400)
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
src/server/api.ts

index 9b5d7d5776a703cc06f38605f65ce64f0a3ccac4..a105cca7c9ec0e47a98809e442450f482fbe40cd 100644 (file)
@@ -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
index 9ad397c52fe28079b511104f82f44df5060fb0d3..7d31d3431b5d156102c97534f2b9ee9679f1978b 100644 (file)
@@ -339,10 +339,12 @@ io.on('connection', async socket => {
       dexterity: 0,
       intelligence: 0,
       damage: 0,
+      hp: 0,
     };
 
     const equipment: Map<EquipmentSlot, EquippedItemDetails> = new Map<EquipmentSlot, EquippedItemDetails>();
     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<SkillID | any, number> = {};
+    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) {