Add character overlay, where skills and passives (changing this) can be set

This commit is contained in:
Peter Stockings
2026-01-04 21:12:07 +11:00
parent f67f488764
commit 171abb681a
9 changed files with 321 additions and 20 deletions

View File

@@ -35,6 +35,7 @@ export class GameScene extends Phaser.Scene {
private dungeonRenderer!: DungeonRenderer;
private isMenuOpen = false;
private isInventoryOpen = false;
private isCharacterOpen = false;
constructor() {
super("GameScene");
@@ -67,6 +68,9 @@ export class GameScene extends Phaser.Scene {
this.events.on("inventory-toggled", (isOpen: boolean) => {
this.isInventoryOpen = isOpen;
});
this.events.on("character-toggled", (isOpen: boolean) => {
this.isCharacterOpen = isOpen;
});
// Load initial floor
this.loadFloor(1);
@@ -97,6 +101,9 @@ export class GameScene extends Phaser.Scene {
// Toggle inventory
this.events.emit("toggle-inventory");
});
this.input.keyboard?.on("keydown-C", () => {
this.events.emit("toggle-character");
});
this.input.keyboard?.on("keydown-SPACE", () => {
if (!this.awaitingPlayer) return;
@@ -119,6 +126,14 @@ export class GameScene extends Phaser.Scene {
this.restartGame();
});
this.events.on("allocate-stat", (statName: string) => {
this.allocateStat(statName);
});
this.events.on("allocate-passive", (nodeId: string) => {
this.allocatePassive(nodeId);
});
// Mouse click -> compute path (only during player turn, and not while menu/minimap is open)
this.input.on("pointerdown", (p: Phaser.Input.Pointer) => {
if (!this.awaitingPlayer) return;
@@ -151,7 +166,7 @@ export class GameScene extends Phaser.Scene {
update() {
if (!this.awaitingPlayer) return;
if (this.isMenuOpen || this.isInventoryOpen || this.dungeonRenderer.isMinimapVisible()) return;
if (this.isMenuOpen || this.isInventoryOpen || this.isCharacterOpen || this.dungeonRenderer.isMinimapVisible()) return;
// Auto-walk one step per turn
if (this.playerPath.length >= 2) {
@@ -339,4 +354,51 @@ export class GameScene extends Phaser.Scene {
player.pos.y * TILE_SIZE + TILE_SIZE / 2
);
}
private allocateStat(statName: string) {
const p = this.world.actors.get(this.playerId);
if (!p || !p.stats || p.stats.statPoints <= 0) return;
p.stats.statPoints--;
if (statName === "strength") {
p.stats.strength++;
p.stats.maxHp += 2;
p.stats.hp += 2;
p.stats.attack += 0.2; // Small boost per Str
} else if (statName === "dexterity") {
p.stats.dexterity++;
p.speed += 1;
} else if (statName === "intelligence") {
p.stats.intelligence++;
// Maybe defense every 5 points?
if (p.stats.intelligence % 5 === 0) {
p.stats.defense++;
}
}
this.emitUIUpdate();
}
private allocatePassive(nodeId: string) {
const p = this.world.actors.get(this.playerId);
if (!p || !p.stats || p.stats.skillPoints <= 0) return;
if (p.stats.passiveNodes.includes(nodeId)) return;
p.stats.skillPoints--;
p.stats.passiveNodes.push(nodeId);
// Apply bonuses
if (nodeId === "off_1") p.stats.attack += 2;
else if (nodeId === "off_2") p.stats.attack += 4;
else if (nodeId === "def_1") {
p.stats.maxHp += 10;
p.stats.hp += 10;
}
else if (nodeId === "def_2") p.stats.defense += 2;
else if (nodeId === "util_1") p.speed += 5;
else if (nodeId === "util_2") p.stats.expToNextLevel = Math.floor(p.stats.expToNextLevel * 0.9);
this.emitUIUpdate();
}
}