feat: Add new inventory items and enhance NPC item drop logic with texture validation and notifications

This commit is contained in:
Z. Cliffe Schreuders
2026-02-15 00:49:02 +00:00
parent a6458a9ff2
commit 6500354400
3 changed files with 51 additions and 2 deletions

View File

@@ -97,6 +97,8 @@ export function preload() {
this.load.image('fingerprint', 'objects/fingerprint_small.png');
this.load.image('lockpick', 'objects/lockpick.png');
this.load.image('spoofing_kit', 'objects/office-misc-headphones.png');
this.load.image('id_badge', 'objects/id_badge.png');
this.load.image('text_file', 'objects/text_file.png');
this.load.image('keyway', 'icons/keyway.png');
this.load.image('password', 'icons/password.png');
this.load.image('pin', 'icons/pin.png');

View File

@@ -330,7 +330,30 @@ export async function addToInventory(sprite) {
});
if (isAlreadyInInventory) {
console.log(`Item ${itemIdentifier} (id: ${itemData.id || itemData.key_id || 'none'}) is already in inventory - skipping duplicate`);
console.log(`Item ${itemIdentifier} (id: ${itemData.id || itemData.key_id || 'none'}) is already in inventory - removing from environment`);
// Remove from environment even if already in inventory
if (window.currentPlayerRoom && rooms[window.currentPlayerRoom] && rooms[window.currentPlayerRoom].objects) {
if (rooms[window.currentPlayerRoom].objects[sprite.objectId]) {
const roomObj = rooms[window.currentPlayerRoom].objects[sprite.objectId];
if (roomObj.setVisible) {
roomObj.setVisible(false);
}
roomObj.active = false;
console.log(`Removed duplicate object ${sprite.objectId} from room`);
}
}
// Hide the sprite if it has setVisible method
if (sprite.setVisible && typeof sprite.setVisible === 'function') {
sprite.setVisible(false);
}
// Show notification to player
if (window.gameAlert) {
window.gameAlert('Already in inventory', 'info', itemData.name || 'Item', 2000);
}
return false;
}

View File

@@ -230,7 +230,19 @@ function dropNPCItems(npcId) {
const spawnY = Math.round(sprite.y);
// Create actual Phaser sprite for the dropped item
const texture = item.texture || item.type || 'key';
// Try item.texture, then item.type, with fallback to 'key' if texture doesn't exist
let texture = item.texture || item.type || 'key';
console.log(`💧 Attempting to drop item: type="${item.type}", name="${item.name}", texture="${texture}"`);
// Safety check: verify texture exists, fallback to 'key' if not
if (!gameRef.textures.exists(texture)) {
console.warn(`⚠️ Texture '${texture}' not found for dropped item '${item.name}', using fallback 'key'`);
texture = 'key';
} else {
console.log(`✅ Texture '${texture}' exists for dropped item '${item.name}'`);
}
const spriteObj = gameRef.add.sprite(spawnX, spawnY, texture);
// Set origin to match standard object creation
@@ -271,6 +283,18 @@ function dropNPCItems(npcId) {
spriteObj[key] = droppedItemData[key];
});
// IMPORTANT: Preserve texture information for inventory display
// Phaser sprites have a complex texture object, but inventory expects
// a simple object with a 'key' property (matching npc-game-bridge pattern)
// Store both the original texture reference and a simple texture key object
const phaserTexture = spriteObj.texture; // Preserve Phaser's texture object
spriteObj.texture = {
key: texture, // Use the resolved texture name for inventory
_phaserTexture: phaserTexture // Keep reference to original Phaser texture
};
console.log(`💧 Dropped item sprite texture set: key="${spriteObj.texture.key}", name="${spriteObj.name}"`);
// Make the sprite interactive
spriteObj.setInteractive({ useHandCursor: true });