Add ammo counter for ranged items in quickslot
This commit is contained in:
@@ -37,12 +37,18 @@ export class ItemManager {
|
||||
spawnItem(item: Item, pos: Vec2): void {
|
||||
if (!this.world || !this.entityManager) return;
|
||||
|
||||
// Deep clone item (crucial for items with mutable stats like ammo)
|
||||
const clonedItem = { ...item } as Item;
|
||||
if ('stats' in clonedItem && clonedItem.stats) {
|
||||
(clonedItem as any).stats = { ...clonedItem.stats };
|
||||
}
|
||||
|
||||
const id = this.entityManager.getNextId();
|
||||
const drop: ItemDropActor = {
|
||||
id,
|
||||
pos: { x: pos.x, y: pos.y },
|
||||
category: "item_drop",
|
||||
item: { ...item } // Clone item
|
||||
item: clonedItem
|
||||
};
|
||||
|
||||
this.entityManager.addActor(drop);
|
||||
@@ -61,7 +67,20 @@ export class ItemManager {
|
||||
if (itemActor) {
|
||||
const item = itemActor.item;
|
||||
|
||||
// Stacking Logic
|
||||
if (item.stackable) {
|
||||
const existingItem = player.inventory.items.find(it => it.id === item.id);
|
||||
if (existingItem) {
|
||||
existingItem.quantity = (existingItem.quantity || 1) + (item.quantity || 1);
|
||||
console.log(`Stacked ${item.name}. New quantity: ${existingItem.quantity}`);
|
||||
|
||||
this.entityManager.removeActor(itemActor.id);
|
||||
return existingItem;
|
||||
}
|
||||
}
|
||||
|
||||
// Add to inventory
|
||||
item.quantity = item.quantity || 1;
|
||||
player.inventory.items.push(item);
|
||||
|
||||
// Remove from world
|
||||
@@ -91,7 +110,7 @@ export class ItemManager {
|
||||
const item = player.inventory.items[itemIdx];
|
||||
|
||||
// Check if item is a healing consumable
|
||||
if (item.stats && item.stats.hp && item.stats.hp > 0) {
|
||||
if (item.type === "Consumable" && item.stats?.hp) {
|
||||
const healAmount = item.stats.hp;
|
||||
|
||||
if (player.stats.hp >= player.stats.maxHp) {
|
||||
@@ -100,8 +119,12 @@ export class ItemManager {
|
||||
|
||||
player.stats.hp = Math.min(player.stats.hp + healAmount, player.stats.maxHp);
|
||||
|
||||
// Remove item after use
|
||||
player.inventory.items.splice(itemIdx, 1);
|
||||
// Consume item (check stack)
|
||||
if (item.quantity && item.quantity > 1) {
|
||||
item.quantity--;
|
||||
} else {
|
||||
player.inventory.items.splice(itemIdx, 1);
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
@@ -110,8 +133,8 @@ export class ItemManager {
|
||||
};
|
||||
}
|
||||
|
||||
// Throwable items are handled by TargetingSystem, not here
|
||||
if (item.throwable) {
|
||||
// Throwable items
|
||||
if (item.type === "Consumable" && item.throwable) {
|
||||
return {
|
||||
success: true,
|
||||
consumed: false,
|
||||
|
||||
Reference in New Issue
Block a user