From ffe35fc202dda9a4f256607aa0b5c5340186636b Mon Sep 17 00:00:00 2001 From: xangelo Date: Fri, 2 Jun 2023 14:39:54 -0400 Subject: [PATCH] when armour is destroyed, it gets removed from your inventory --- src/server/api.ts | 5 +++-- src/server/inventory.ts | 12 ++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/server/api.ts b/src/server/api.ts index 0e4d905..d990e1f 100644 --- a/src/server/api.ts +++ b/src/server/api.ts @@ -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`); diff --git a/src/server/inventory.ts b/src/server/inventory.ts index 9db8fd8..10456a3 100644 --- a/src/server/inventory.ts +++ b/src/server/inventory.ts @@ -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(); +} -- 2.25.1