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();
|
2023-04-23 12:40:54 +09:00
|
|
|
discarded = new Array();
|
|
|
|
turnOrder;
|
|
|
|
turn = 0;
|
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; }
|
2023-04-23 12:40:54 +09:00
|
|
|
this.turn = 0;
|
|
|
|
this.turnOrder = command.args;
|
2022-11-13 21:30:01 +09:00
|
|
|
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;
|
2023-04-23 12:40:54 +09:00
|
|
|
case commands.worker:
|
|
|
|
if (message.from !== this.hostClientId) { socket.close(); return; }
|
|
|
|
this.cardCommands[command.args[0]](...command.args[1]);
|
|
|
|
break;
|
2022-11-04 22:05:08 +09:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-11-13 21:30:01 +09:00
|
|
|
joinNewPlayer() { }
|
2023-04-23 12:40:54 +09:00
|
|
|
|
|
|
|
cardCommands = {
|
2025-08-31 18:28:13 +09:00
|
|
|
remove: (targetId, card, index, canRecycle) => {
|
|
|
|
const player = this.players.get(targetId);
|
2023-04-23 12:40:54 +09:00
|
|
|
player.cards.splice(index, 1);
|
|
|
|
if (canRecycle)
|
|
|
|
this.discarded.push(new Card(cardTypes[card.cardType.id], card.idIndex));
|
|
|
|
},
|
2025-08-31 18:28:13 +09:00
|
|
|
selectCards: (targetId, targetStockId, count, waitingId) => {
|
|
|
|
/* TODO */
|
|
|
|
console.log(`selectCards,from: ${targetStockId}, count: ${count}, waitingId: ${waitingId}`);
|
|
|
|
},
|
|
|
|
selectedCards: (waitingId, targetStockId, ...cardsIndex) => {
|
|
|
|
new MessageBuilder(this.hostClientId, side.host).game().addCommand(commands.waiting, clientId, "selectedCards", [waitingId, ...cardsIndex]).send();
|
|
|
|
},
|
2023-04-23 12:40:54 +09:00
|
|
|
};
|
2022-11-04 22:05:08 +09:00
|
|
|
}
|