194 lines
5.2 KiB
JavaScript
194 lines
5.2 KiB
JavaScript
/**
|
|
* MOUNT SYSTEM
|
|
* Handles rideable animals (Donkey, Horse, etc.)
|
|
*/
|
|
class MountSystem {
|
|
constructor(scene, player) {
|
|
this.scene = scene;
|
|
this.player = player;
|
|
this.currentMount = null;
|
|
this.isMounted = false;
|
|
|
|
// Mount definitions
|
|
this.mountData = {
|
|
'donkey': {
|
|
name: 'Donkey',
|
|
speed: 200, // Movement speed when mounted
|
|
texture: 'donkey',
|
|
inventorySlots: 10, // Extra inventory from saddlebags
|
|
color: 0x8B7355 // Brown
|
|
},
|
|
'horse': {
|
|
name: 'Horse',
|
|
speed: 300,
|
|
texture: 'horse',
|
|
inventorySlots: 5,
|
|
color: 0x654321
|
|
}
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Spawn a mount in the world
|
|
*/
|
|
spawnMount(gridX, gridY, type) {
|
|
if (!this.mountData[type]) {
|
|
console.error('Unknown mount type:', type);
|
|
return null;
|
|
}
|
|
|
|
const data = this.mountData[type];
|
|
const screenPos = this.scene.iso.toScreen(gridX, gridY);
|
|
|
|
const mount = {
|
|
type,
|
|
gridX,
|
|
gridY,
|
|
sprite: null,
|
|
inventory: [], // Saddlebag storage
|
|
tamed: true
|
|
};
|
|
|
|
// Create sprite
|
|
mount.sprite = this.scene.add.sprite(
|
|
screenPos.x + this.scene.terrainOffsetX,
|
|
screenPos.y + this.scene.terrainOffsetY,
|
|
data.texture || 'npc_zombie' // Fallback
|
|
);
|
|
mount.sprite.setOrigin(0.5, 1);
|
|
mount.sprite.setScale(0.4);
|
|
mount.sprite.setTint(data.color);
|
|
mount.sprite.setDepth(this.scene.iso.getDepth(gridX, gridY, this.scene.iso.LAYER_OBJECTS));
|
|
|
|
mount.sprite.setInteractive({ useHandCursor: true });
|
|
mount.sprite.on('pointerdown', () => {
|
|
this.mountUp(mount);
|
|
});
|
|
|
|
console.log(`🐴 Spawned ${data.name} at ${gridX},${gridY}`);
|
|
return mount;
|
|
}
|
|
|
|
/**
|
|
* Mount up on a donkey/horse
|
|
*/
|
|
mountUp(mount) {
|
|
if (this.isMounted) {
|
|
console.log('Already mounted!');
|
|
return;
|
|
}
|
|
|
|
this.currentMount = mount;
|
|
this.isMounted = true;
|
|
|
|
const data = this.mountData[mount.type];
|
|
|
|
// Hide mount sprite
|
|
mount.sprite.setVisible(false);
|
|
|
|
// Increase player speed
|
|
if (this.player) {
|
|
this.player.originalSpeed = this.player.speed || 100;
|
|
this.player.speed = data.speed;
|
|
}
|
|
|
|
// Visual feedback
|
|
this.scene.events.emit('show-floating-text', {
|
|
x: this.player.sprite.x,
|
|
y: this.player.sprite.y - 40,
|
|
text: `🐴 Mounted ${data.name}!`,
|
|
color: '#ffaa00'
|
|
});
|
|
|
|
console.log(`🐴 Mounted on ${data.name}! Speed: ${data.speed}`);
|
|
}
|
|
|
|
/**
|
|
* Dismount
|
|
*/
|
|
dismount() {
|
|
if (!this.isMounted || !this.currentMount) {
|
|
return;
|
|
}
|
|
|
|
const mount = this.currentMount;
|
|
const data = this.mountData[mount.type];
|
|
|
|
// Restore player speed
|
|
if (this.player && this.player.originalSpeed) {
|
|
this.player.speed = this.player.originalSpeed;
|
|
}
|
|
|
|
// Place mount at player location
|
|
const playerPos = this.player.getPosition();
|
|
mount.gridX = Math.round(playerPos.x);
|
|
mount.gridY = Math.round(playerPos.y);
|
|
|
|
const screenPos = this.scene.iso.toScreen(mount.gridX, mount.gridY);
|
|
mount.sprite.setPosition(
|
|
screenPos.x + this.scene.terrainOffsetX,
|
|
screenPos.y + this.scene.terrainOffsetY
|
|
);
|
|
mount.sprite.setVisible(true);
|
|
|
|
// Visual feedback
|
|
this.scene.events.emit('show-floating-text', {
|
|
x: this.player.sprite.x,
|
|
y: this.player.sprite.y - 40,
|
|
text: `Dismounted`,
|
|
color: '#888888'
|
|
});
|
|
|
|
this.currentMount = null;
|
|
this.isMounted = false;
|
|
|
|
console.log(`🐴 Dismounted from ${data.name}`);
|
|
}
|
|
|
|
/**
|
|
* Toggle mount/dismount (E key)
|
|
*/
|
|
toggleMount() {
|
|
if (this.isMounted) {
|
|
this.dismount();
|
|
} else {
|
|
// Try to find nearby mount
|
|
const nearbyMount = this.findNearbyMount();
|
|
if (nearbyMount) {
|
|
this.mountUp(nearbyMount);
|
|
}
|
|
}
|
|
}
|
|
|
|
findNearbyMount() {
|
|
// TODO: Search for mounts near player
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* Access saddlebag inventory
|
|
*/
|
|
openSaddlebag() {
|
|
if (!this.isMounted || !this.currentMount) {
|
|
return null;
|
|
}
|
|
|
|
const data = this.mountData[this.currentMount.type];
|
|
console.log(`🎒 Opening saddlebag (${data.inventorySlots} slots)`);
|
|
return this.currentMount.inventory;
|
|
}
|
|
|
|
update(delta) {
|
|
// Update mount position if mounted
|
|
if (this.isMounted && this.currentMount && this.player) {
|
|
const playerPos = this.player.getPosition();
|
|
this.currentMount.gridX = Math.round(playerPos.x);
|
|
this.currentMount.gridY = Math.round(playerPos.y);
|
|
}
|
|
}
|
|
|
|
isMountedOnAnything() {
|
|
return this.isMounted;
|
|
}
|
|
}
|