when armour is destroyed, it gets removed from your inventory
authorxangelo <git@xangelo.ca>
Fri, 2 Jun 2023 18:39:54 +0000 (14:39 -0400)
committerxangelo <git@xangelo.ca>
Fri, 2 Jun 2023 18:39:54 +0000 (14:39 -0400)
src/server/api.ts
src/server/inventory.ts

index 0e4d905b8848a26477320f50e3ea1fcf4678ca16..d990e1fa6ec7f1c302a4c9ca3328162b4b4979ec 100644 (file)
@@ -11,7 +11,7 @@ import {broadcastMessage, Message} from '../shared/message';
 import {expToLevel, maxHp, Player, professionList} from '../shared/player';
 import {clearFight, createFight, getMonsterList, loadMonster, loadMonsterFromFight, saveFightState} from './monster';
 import {FightRound} from '../shared/fight';
-import {addInventoryItem, getEquippedItems, getInventory, getInventoryItem, updateAp} from './inventory';
+import {addInventoryItem, deleteInventoryItem, getEquippedItems, getInventory, getInventoryItem, updateAp} from './inventory';
 import {Monster, MonsterForList} from '../shared/monsters';
 import {getShopItem, listShopItems} from './shopItem';
 import {equip, unequip} from './equipment';
@@ -467,12 +467,13 @@ io.on('connection', async socket => {
         roundData.roundDetails.push(`Your ${item.name} was destroyed so they hit your directly for ${monster.strength} damage!`);
         player.hp += item.currentAp;
         item.currentAp = 0;
+        await deleteInventoryItem(player.id, item.item_id);
       }
       else {
         roundData.roundDetails.push(`Your ${target} took ${monster.strength} damage!`);
+        await updateAp(player.id, item.item_id, item.currentAp, item.maxAp);
       }
 
-      await updateAp(player.id, item.item_id, item.currentAp, item.maxAp);
     }
     else {
       roundData.roundDetails.push(`The ${monster.name} hit you for ${monster.strength} damage`);
index 9db8fd8ae1ad65e1e64800179d5984af06bd9a32..10456a3e6233785c9835ae002727fa05b9a623cb 100644 (file)
@@ -73,3 +73,15 @@ export async function updateAp(player_id: string, item_id: string, currentAp: nu
     item_id
   })
 }
+
+export async function deleteInventoryItem(player_id: string, item_id: string) {
+  await db('equipped').where({
+    player_id,
+    item_id
+  }).delete();
+
+  await db('inventory').where({
+    player_id,
+    item_id
+  }).delete();
+}