Add quick slot and consumables (health and mana potions)
This commit is contained in:
@@ -150,6 +150,54 @@ export class GameScene extends Phaser.Scene {
|
||||
this.commitPlayerAction({ type: "wait" });
|
||||
});
|
||||
|
||||
this.events.on("player-search", () => {
|
||||
if (!this.awaitingPlayer) return;
|
||||
if (this.isMenuOpen || this.isInventoryOpen || this.dungeonRenderer.isMinimapVisible()) return;
|
||||
|
||||
console.log("Player searching...");
|
||||
// Search takes a turn (functionally same as wait for now, but semantically distinct)
|
||||
this.commitPlayerAction({ type: "wait" });
|
||||
});
|
||||
|
||||
this.events.on("use-item", (data: { itemId: string }) => {
|
||||
if (!this.awaitingPlayer) return;
|
||||
// Don't block item usage if inventory is open, as we might use it from there or hotbar.
|
||||
// But if we use it from inventory, we might want to close inventory or update it.
|
||||
|
||||
const player = this.world.actors.get(this.playerId) as CombatantActor;
|
||||
if (!player || !player.inventory) return;
|
||||
|
||||
if (data.itemId === "health_potion") {
|
||||
// Heal logic
|
||||
const healAmount = 5;
|
||||
if (player.stats.hp < player.stats.maxHp) {
|
||||
player.stats.hp = Math.min(player.stats.hp + healAmount, player.stats.maxHp);
|
||||
|
||||
// Visuals handled by diff in stats usually? No, we need explicit heal event or simple floating text
|
||||
// commitPlayerAction triggers simulation which might generate events.
|
||||
// But healing from item is instant effect before turn passes?
|
||||
// Or we treat it as an action.
|
||||
|
||||
// Let's remove item first
|
||||
const idx = player.inventory.items.findIndex(it => it.id === "health_potion");
|
||||
if (idx !== -1) {
|
||||
player.inventory.items.splice(idx, 1);
|
||||
|
||||
// Show visual
|
||||
this.dungeonRenderer.showHeal(player.pos.x, player.pos.y, healAmount);
|
||||
|
||||
// Pass turn
|
||||
this.commitPlayerAction({ type: "wait" });
|
||||
this.emitUIUpdate();
|
||||
}
|
||||
} else {
|
||||
console.log("Already at full health");
|
||||
}
|
||||
} else {
|
||||
console.log("Used item:", data.itemId);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
// Zoom Control
|
||||
|
||||
Reference in New Issue
Block a user