ExtinctionOnline/static/js/player-controller.js

30 lines
1.1 KiB
JavaScript
Raw Normal View History

2022-11-13 21:30:01 +09:00
"use strict";
2022-11-04 22:05:08 +09:00
class PlayerController {
hostClientId;
2022-11-13 21:30:01 +09:00
players = new Map();
2022-11-04 22:05:08 +09:00
constructor() {
}
2022-11-13 21:30:01 +09:00
onGameMessage(message) {
message.body.commands.forEach(command => {
switch (command.name) {
case commands.syncRoomData:
if (message.from !== command.args[0]) { socket.close(); return; }
this.hostClientId = command.args[0];
this.players = new Map(command.args[1].map(playerId => [playerId, new Player(playerId)]));
break;
2022-11-04 22:05:08 +09:00
case commands.gameStart:
2022-11-13 21:30:01 +09:00
if (message.from !== this.hostClientId) { socket.close(); return; }
break;
case commands.addCard:
if (message.from !== this.hostClientId) { socket.close(); return; }
if (command.target == clientId && command.args[0] == cardTypes.unknown.id) return;
this.players.get(command.target).cards.push(new Card(cardTypes[command.args[0]], command.args[1]));
2022-11-04 22:05:08 +09:00
break;
}
});
}
2022-11-13 21:30:01 +09:00
joinNewPlayer() { }
2022-11-04 22:05:08 +09:00
}