diff --git a/src/game/Actor.ts b/src/game/Actor.ts index 9861e0fe..3bbf6f6a 100644 --- a/src/game/Actor.ts +++ b/src/game/Actor.ts @@ -630,6 +630,9 @@ export default class Actor { return; } this.props.bodyIndex = index; + if (this.index === 0) { + this.game.getState().hero.bodyIndex = index; + } this.reloadModel(scene); } @@ -638,6 +641,9 @@ export default class Actor { return; } this.props.animIndex = index; + if (this.index === 0) { + this.game.getState().hero.animIndex = index; + } if (this.animState.onAnimEnd) { this.animState.onAnimEnd(); } diff --git a/src/game/GameState.ts b/src/game/GameState.ts index 34f4350f..e8134d9d 100644 --- a/src/game/GameState.ts +++ b/src/game/GameState.ts @@ -30,6 +30,8 @@ export interface MagicBallState { export interface HeroState { behaviour: number; prevBehaviour: number; + bodyIndex: number; + animIndex: number; usingItemId: number; equippedItemId: number; inventorySlot: number; @@ -74,6 +76,8 @@ export function createGameState(): GameState { hero: { behaviour: 0, prevBehaviour: 0, + bodyIndex: -1, + animIndex: -1, life: INITIAL_LIFE, money: 0, magic: 0, diff --git a/src/game/Scene.ts b/src/game/Scene.ts index be136fc3..533b341b 100644 --- a/src/game/Scene.ts +++ b/src/game/Scene.ts @@ -174,12 +174,15 @@ export default class Scene { return actor; } - const bodyIndex = getBodyFromGameState(game); + let bodyIndex = getBodyFromGameState(game); + if (bodyIndex === -1) { + bodyIndex = game.getState().hero.bodyIndex; + } return { ...actor, entityIndex: game.getState().hero.behaviour, - bodyIndex: bodyIndex !== -1 ? bodyIndex : actor.bodyIndex + bodyIndex: bodyIndex !== -1 ? bodyIndex : actor.bodyIndex, }; }