2024-08-02 14:01:51 +00:00
|
|
|
class OverworldEvent {
|
|
|
|
constructor({map, event}) {
|
|
|
|
this.map = map;
|
|
|
|
this.event = event;
|
|
|
|
}
|
|
|
|
|
|
|
|
stand(resolve) {
|
|
|
|
const who = this.map.gameObjects[ this.event.who ];
|
|
|
|
who.startBehavior({
|
|
|
|
map: this.map
|
|
|
|
}, {
|
|
|
|
type: "stand",
|
|
|
|
direction: this.event.direction,
|
|
|
|
time: this.event.time
|
|
|
|
})
|
|
|
|
|
|
|
|
// handler to complete when correct person is done walking
|
|
|
|
const completeHandler = e => {
|
|
|
|
if (e.detail.whoId === this.event.who) {
|
|
|
|
document.removeEventListener("PersonStandComplete", completeHandler);
|
|
|
|
resolve();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
document.addEventListener("PersonStandComplete", completeHandler)
|
|
|
|
}
|
|
|
|
|
|
|
|
walk(resolve) {
|
|
|
|
const who = this.map.gameObjects[ this.event.who ];
|
|
|
|
who.startBehavior({
|
|
|
|
map: this.map
|
|
|
|
}, {
|
|
|
|
type: "walk",
|
|
|
|
direction: this.event.direction,
|
|
|
|
retry: true
|
|
|
|
})
|
|
|
|
|
|
|
|
// handler to complete when correct person is done walking
|
|
|
|
const completeHandler = e => {
|
|
|
|
if (e.detail.whoId === this.event.who) {
|
|
|
|
document.removeEventListener("PersonWalkingComplete", completeHandler);
|
|
|
|
resolve();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
document.addEventListener("PersonWalkingComplete", completeHandler)
|
|
|
|
}
|
|
|
|
|
2024-08-05 17:36:41 +00:00
|
|
|
textMessage(resolve) {
|
|
|
|
if (this.event.faceHero) {
|
|
|
|
const obj = this.map.gameObjects[this.event.faceHero];
|
|
|
|
obj.direction = utils.oppositeDirection(this.map.gameObjects["hero"].direction);
|
|
|
|
}
|
|
|
|
|
|
|
|
const message = new TextMessage({
|
|
|
|
text: this.event.text,
|
|
|
|
onComplete: () => resolve()
|
|
|
|
})
|
|
|
|
message.init( document.querySelector(".game-container") )
|
|
|
|
}
|
|
|
|
|
|
|
|
changeMap(resolve) {
|
2024-08-06 17:39:18 +00:00
|
|
|
const sceneTransition = new SceneTransition();
|
|
|
|
sceneTransition.init(document.querySelector(".game-container"), () => {
|
|
|
|
this.map.overworld.startMap(window.OverworldMaps[this.event.map]);
|
|
|
|
resolve();
|
|
|
|
|
|
|
|
sceneTransition.fadeOut();
|
|
|
|
});
|
2024-08-05 17:36:41 +00:00
|
|
|
}
|
|
|
|
|
2024-08-02 14:01:51 +00:00
|
|
|
init() {
|
|
|
|
return new Promise(resolve => {
|
|
|
|
this[this.event.type](resolve)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|