|
|
|
@ -294,8 +294,12 @@ export class GameEngine {
|
|
|
|
this._gameState.hero.position.y = y;
|
|
|
|
this._gameState.hero.position.y = y;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Sync phase from server state string
|
|
|
|
// Sync phase from server state string (never clear Death or active combat)
|
|
|
|
if (state === 'walking' && this._gameState.phase !== GamePhase.Fighting) {
|
|
|
|
if (
|
|
|
|
|
|
|
|
state === 'walking' &&
|
|
|
|
|
|
|
|
this._gameState.phase !== GamePhase.Fighting &&
|
|
|
|
|
|
|
|
this._gameState.phase !== GamePhase.Dead
|
|
|
|
|
|
|
|
) {
|
|
|
|
this._gameState = { ...this._gameState, phase: GamePhase.Walking };
|
|
|
|
this._gameState = { ...this._gameState, phase: GamePhase.Walking };
|
|
|
|
this._thoughtText = null;
|
|
|
|
this._thoughtText = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -312,9 +316,11 @@ export class GameEngine {
|
|
|
|
this._routeWaypoints = waypoints;
|
|
|
|
this._routeWaypoints = waypoints;
|
|
|
|
this._heroSpeed = speed;
|
|
|
|
this._heroSpeed = speed;
|
|
|
|
this._syncWorldTerrainContext();
|
|
|
|
this._syncWorldTerrainContext();
|
|
|
|
|
|
|
|
const hp = this._gameState.hero?.hp ?? 1;
|
|
|
|
|
|
|
|
const phase = hp <= 0 ? GamePhase.Dead : GamePhase.Walking;
|
|
|
|
this._gameState = {
|
|
|
|
this._gameState = {
|
|
|
|
...this._gameState,
|
|
|
|
...this._gameState,
|
|
|
|
phase: GamePhase.Walking,
|
|
|
|
phase,
|
|
|
|
routeWaypoints: waypoints.length >= 2 ? waypoints.map((p) => ({ x: p.x, y: p.y })) : null,
|
|
|
|
routeWaypoints: waypoints.length >= 2 ? waypoints.map((p) => ({ x: p.x, y: p.y })) : null,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
this._thoughtText = null;
|
|
|
|
this._thoughtText = null;
|
|
|
|
@ -371,16 +377,23 @@ export class GameEngine {
|
|
|
|
const newX = hero.position.x || 0;
|
|
|
|
const newX = hero.position.x || 0;
|
|
|
|
const newY = hero.position.y || 0;
|
|
|
|
const newY = hero.position.y || 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const activity = hero.serverActivityState?.toLowerCase();
|
|
|
|
|
|
|
|
const isDead = hero.hp <= 0 || activity === 'dead';
|
|
|
|
|
|
|
|
|
|
|
|
this._gameState = {
|
|
|
|
this._gameState = {
|
|
|
|
...this._gameState,
|
|
|
|
...this._gameState,
|
|
|
|
hero,
|
|
|
|
hero,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const activity = hero.serverActivityState?.toLowerCase();
|
|
|
|
if (isDead) {
|
|
|
|
if (
|
|
|
|
this._gameState = {
|
|
|
|
this._gameState.phase !== GamePhase.Fighting &&
|
|
|
|
...this._gameState,
|
|
|
|
this._gameState.phase !== GamePhase.Dead
|
|
|
|
phase: GamePhase.Dead,
|
|
|
|
) {
|
|
|
|
enemy: null,
|
|
|
|
|
|
|
|
enemyOnScreenRight: undefined,
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
this._thoughtText = null;
|
|
|
|
|
|
|
|
} else if (this._gameState.phase !== GamePhase.Fighting) {
|
|
|
|
if (activity === 'resting') {
|
|
|
|
if (activity === 'resting') {
|
|
|
|
this._gameState = { ...this._gameState, phase: GamePhase.Resting };
|
|
|
|
this._gameState = { ...this._gameState, phase: GamePhase.Resting };
|
|
|
|
if (!this._thoughtText) this._showThought();
|
|
|
|
if (!this._thoughtText) this._showThought();
|
|
|
|
@ -507,9 +520,11 @@ export class GameEngine {
|
|
|
|
* Transitions back to walking phase.
|
|
|
|
* Transitions back to walking phase.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
applyCombatEnd(): void {
|
|
|
|
applyCombatEnd(): void {
|
|
|
|
|
|
|
|
const hp = this._gameState.hero?.hp ?? 0;
|
|
|
|
|
|
|
|
const phase = hp <= 0 ? GamePhase.Dead : GamePhase.Walking;
|
|
|
|
this._gameState = {
|
|
|
|
this._gameState = {
|
|
|
|
...this._gameState,
|
|
|
|
...this._gameState,
|
|
|
|
phase: GamePhase.Walking,
|
|
|
|
phase,
|
|
|
|
enemy: null,
|
|
|
|
enemy: null,
|
|
|
|
enemyOnScreenRight: undefined,
|
|
|
|
enemyOnScreenRight: undefined,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|