import { Player, expToLevel, maxHp, totalDefence, maxVigor } from '../shared/player';
import { clearTravelPlan } from './map';
import { updatePlayer } from './player';
-import { getEquippedItems, updateAp, deleteInventoryItem } from './inventory';
+import { getEquippedItems, updateAp } from './inventory';
import { EquippedItemDetails } from '../shared/equipped';
-import { ArmourEquipmentSlot, EquipmentSlot } from '../shared/inventory';
+import { EquipmentSlot } from '../shared/inventory';
import { MonsterWithFaction, MonsterForFight } from '../shared/monsters';
import { getPlayerSkillsAsObject, updatePlayerSkills } from './skills';
import { SkillID, Skills } from '../shared/skills';
player.vigor = 0;
}
- await updateAp(player.id, 1, equippedItems.map(i => i.item_id));
+ const unequippedItems = await updateAp(player.id, 1, equippedItems.map(i => i.item_id));
await clearFight(player.id);
await updatePlayer(player);
+
+ if(unequippedItems.length) {
+ unequippedItems.forEach(i => {
+ roundData.roundDetails.push(`Your ${i.name} was too damaged and was unequipped!`);
+ });
+ }
+
return { roundData, monsters: potentialMonsters, player };
}
roundData.roundDetails.push(`You were killed by the ${monster.name}`);
await clearFight(player.id);
- await updateAp(player.id, 5, equippedItems.map(i => i.item_id));
+ const unequippedItems = await updateAp(player.id, 5, equippedItems.map(i => i.item_id));
await updatePlayer(player);
await clearTravelPlan(player.id);
+ if(unequippedItems.length) {
+ unequippedItems.forEach(i => {
+ roundData.roundDetails.push(`Your ${i.name} was too damaged and was unequipped!`);
+ });
+ }
+
return { roundData, monsters: [], player};
}
import { v4 as uuid } from 'uuid';
import { db} from './lib/db';
import {EquippedItemDetails} from "../shared/equipped";
+import { unequipItems } from "./equipment";
export async function addInventoryItem(playerId: string, item: ShopEquipment) {
}
export async function updateAp(player_id: string, apDamage: number, itemIds: string[]) {
- return db('inventory').where({
+ const res: {item_id: string, currentAp: number, name: string}[] = await db('inventory').where({
player_id
}).whereIn('item_id', itemIds).update({
'currentAp': db.raw(`GREATEST("currentAp" - ${apDamage}, 0)`)
- });
+ }).returning(['item_id', 'name', 'currentAp']);
+
+ const itemsToUnequip = res.filter(i => i.currentAp <= 0);
+
+ if(itemsToUnequip.length) {
+ await unequipItems(player_id, itemsToUnequip.map(i => i.item_id));
+ }
+
+ return itemsToUnequip;
}
export async function deleteInventoryItem(player_id: string, item_id: string) {