summaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
authorMike Vink <mike1994vink@gmail.com>2021-07-27 21:40:04 +0200
committerMike Vink <mike1994vink@gmail.com>2021-07-27 21:40:04 +0200
commit4d84c12df52c89abb7d3ba9f565753116b99dbf0 (patch)
treee241b91506738628b919c2af190ed14ac72c3f06 /client
parent019ea5fcefa16c2746fb2c7d6fa4a29d18b8d53b (diff)
feat(): interaction handshaker setup
Diffstat (limited to 'client')
-rw-r--r--client/src/akkamon/client/Client.ts16
-rw-r--r--client/src/akkamon/client/Events.ts50
-rw-r--r--client/src/akkamon/scenes/AkkamonWorldScene.ts8
-rw-r--r--client/src/akkamon/scenes/UIElement.ts2
4 files changed, 47 insertions, 29 deletions
diff --git a/client/src/akkamon/client/Client.ts b/client/src/akkamon/client/Client.ts
index 54a06f1..477ff46 100644
--- a/client/src/akkamon/client/Client.ts
+++ b/client/src/akkamon/client/Client.ts
@@ -24,7 +24,8 @@ import {
HeartBeatReplyEvent,
IncomingEvent,
AkkamonEvent,
- BattleRequestEvent,
+ InteractionRequestEvent,
+ Interaction
} from './Events';
function delay(ms: number) {
@@ -80,8 +81,8 @@ export class Client implements AkkamonClient
this.session.trainerId = event.trainerId;
}
break;
- case EventType.INIT_BATTLE_REPLY:
- console.log("Received battle request reply!");
+ case EventType.INTERACTION_REPLY:
+ console.log("Received an interaction reply!");
console.log(event);
break;
default:
@@ -190,13 +191,14 @@ export class Client implements AkkamonClient
return this.remotePlayerEngine!.getData();
}
- sendBattleChallenge(remotePlayerName: string) {
+ sendInteractionRequest(interaction: Interaction) {
console.log("sent a battle request!");
+ console.log(this.getCurrentSceneKey());
+ console.log(JSON.stringify(interaction));
this.interactionEngine!.setAwaitingResponse();
- this.send(new BattleRequestEvent(
+ this.send(new InteractionRequestEvent(
this.getCurrentSceneKey(),
- this.getSessionTrainerId(),
- remotePlayerName
+ interaction
));
}
diff --git a/client/src/akkamon/client/Events.ts b/client/src/akkamon/client/Events.ts
index f816da8..d6319be 100644
--- a/client/src/akkamon/client/Events.ts
+++ b/client/src/akkamon/client/Events.ts
@@ -1,6 +1,19 @@
import Phaser from 'phaser';
import type { Direction } from '../render/Direction';
+export type TrainerPosition = { x: number, y: number }
+
+export type RemoteMovementQueues = {
+ [trainerId: string]: { value: Array<Direction> }
+}
+
+export type Interaction = {
+ type: string,
+ requestingTrainerId: string,
+ receivingTrainerIds: string[]
+}
+
+
export enum EventType {
HEART_BEAT = "HeartBeat",
TRAINER_REGISTRATION_REQUEST = "TrainerRegistrationRequestEvent",
@@ -8,27 +21,25 @@ export enum EventType {
START_MOVING = "StartMoving",
STOP_MOVING = "StopMoving",
NEW_TILE_POS = "NewTilePos",
- INIT_BATTLE_REQUEST = "InitBattleRequestEvent",
- INIT_BATTLE_REPLY = "InitBattleReplyEvent",
- BATTLE_ABORTED = "BattleAborted"
+ INTERACTION_REQUEST = "InteractionRequestEvent",
+ INTERACTION_REPLY = "InteractionReplyEvent",
+ INTERACTION_ABORTED = "InteractionAbortedEvent"
}
export interface AkkamonEvent {
type: EventType
}
-export type TrainerPosition = { x: number, y: number }
-
-export type RemoteMovementQueues = {
- [trainerId: string]: { value: Array<Direction> }
+export interface InteractionEvent extends AkkamonEvent {
+ interaction: Interaction
}
-// INCOMING EVENTS
export interface IncomingEvent extends AkkamonEvent {
remoteMovementQueues?: RemoteMovementQueues
trainerId?: string
}
+// INCOMING EVENTS
export class HeartBeatReplyEvent implements IncomingEvent {
public type: EventType = EventType.HEART_BEAT;
@@ -46,13 +57,13 @@ export class PlayerRegistrationReplyEvent implements IncomingEvent {
) { }
}
-export class InitBattleReplyEvent implements IncomingEvent {
-
- public type: EventType = EventType.INIT_BATTLE_REPLY;
-
- constructor(
- ) { }
-}
+// export class InitBattleReplyEvent implements IncomingEvent {
+//
+// public type: EventType = EventType.INIT_BATTLE_REPLY;
+//
+// constructor(
+// ) { }
+// }
// OUTGOING EVENTS
export class PlayerRegistrationRequestEvent implements AkkamonEvent {
@@ -95,12 +106,13 @@ export class NewTilePosEvent implements AkkamonEvent {
}
-export class InitBattleRequestEvent implements AkkamonEvent {
- public type: EventType = EventType.INIT_BATTLE_REQUEST;
+export class InteractionRequestEvent implements InteractionEvent {
+
+ public type: EventType = EventType.INTERACTION_REQUEST;
constructor(
- public thisTrainer: string,
- public otherTrainer: string
+ public sceneId: string,
+ public interaction: Interaction,
) { }
}
diff --git a/client/src/akkamon/scenes/AkkamonWorldScene.ts b/client/src/akkamon/scenes/AkkamonWorldScene.ts
index 30af96c..c478757 100644
--- a/client/src/akkamon/scenes/AkkamonWorldScene.ts
+++ b/client/src/akkamon/scenes/AkkamonWorldScene.ts
@@ -113,8 +113,12 @@ export class AkkamonWorldScene extends Phaser.Scene {
}
}
- requestBattleChallenge(remotePlayerName: string): void {
- this.client.sendBattleChallenge(remotePlayerName);
+ requestBattle(remotePlayerName: string | string[]): void {
+ this.client.sendInteractionRequest({
+ type: "battle",
+ requestingTrainerId: this.client.getSessionTrainerId()!,
+ receivingTrainerIds: Array.isArray(remotePlayerName) ? remotePlayerName : [remotePlayerName]
+ });
}
clearMenus() {
diff --git a/client/src/akkamon/scenes/UIElement.ts b/client/src/akkamon/scenes/UIElement.ts
index 08905ef..ec7ffd3 100644
--- a/client/src/akkamon/scenes/UIElement.ts
+++ b/client/src/akkamon/scenes/UIElement.ts
@@ -413,7 +413,7 @@ class ChallengeDialogue extends ConfirmationDialogue implements AkkamonMenu {
confirm() {
if (this.buttons![this.index!].text === "YES") {
- this.akkamonScene.requestBattleChallenge(this.challengedTrainerName);
+ this.akkamonScene.requestBattle(this.challengedTrainerName);
this.akkamonScene.clearMenus();
this.akkamonScene.pushMenu(new WaitingDialogue(this.akkamonScene, new Phaser.GameObjects.Group(this.scene), 20));
} else {