noyciy7037
8136e91a0f
Some checks failed
Extinction Online CI / build (false, 6.0.x, linux-x64) (push) Failing after 3s
Extinction Online CI / build (false, 6.0.x, osx-x64) (push) Failing after 0s
Extinction Online CI / build (false, 6.0.x, win-x64) (push) Failing after 1s
Extinction Online CI / build (true, 6.0.x, linux-x64) (push) Failing after 1s
Extinction Online CI / build (true, 6.0.x, osx-x64) (push) Failing after 1s
Extinction Online CI / build (true, 6.0.x, win-x64) (push) Failing after 1s
117 lines
4.1 KiB
JavaScript
117 lines
4.1 KiB
JavaScript
"use strict";
|
|
const firstCardCount = 5;
|
|
|
|
class HostController {
|
|
playerController = null;
|
|
deck = new Array();
|
|
discarded = new Array();
|
|
players = new Map();
|
|
turnOrder;
|
|
turn = -1;
|
|
latestWaitingId = 0;
|
|
waiting = new Map();
|
|
|
|
constructor() {
|
|
this.playerController = new PlayerController();
|
|
}
|
|
|
|
async gameStart() {
|
|
// ターンを決定
|
|
this.turnOrder = EXOUtils.shuffleArray([...this.players.keys()]);
|
|
|
|
// ゲームを開始
|
|
let startMessage = new MessageBuilder().game();
|
|
startMessage.addCommand(commands.gameStart, null, ...this.turnOrder).send();
|
|
|
|
// すべてのカードを生成
|
|
Object.keys(cardTypes).forEach(key => {
|
|
for (let i = 0; i < cardTypes[key].count; ++i)
|
|
this.deck.push(new Card(cardTypes[key], i + 1));
|
|
});
|
|
|
|
// 山札をシャッフル
|
|
EXOUtils.shuffleArray(this.deck);
|
|
|
|
await this.distributionCards();
|
|
this.nextTurn();
|
|
}
|
|
|
|
async distributionCards() {
|
|
for (let i = 0; i < firstCardCount; ++i) {
|
|
for (const player of this.players) {
|
|
await player[1].addCard(this.deck[0]);
|
|
this.deck.splice(0, 1);
|
|
await new Promise(resolve => setTimeout(resolve, 700));
|
|
}
|
|
}
|
|
/*
|
|
// プレイヤーに5枚ずつ配布
|
|
for (const player of this.players) {
|
|
// 本人通達用
|
|
let messageBuilder = new MessageBuilder(player[0]).game();
|
|
// 他人通達用
|
|
let messageBuilderForRoom = new MessageBuilder().game();
|
|
for (let j = 0; j < firstCardCount; ++j) {
|
|
player[1].cards.push(this.deck[0]);
|
|
messageBuilder.addCommand(commands.addCard, player[0], this.deck[0].cardType.id, this.deck[0].idIndex);
|
|
messageBuilderForRoom.addCommand(commands.addCard, player[0], cardTypes.unknown.id, -1)
|
|
this.deck.splice(0, 1);
|
|
|
|
}
|
|
messageBuilder.send();
|
|
messageBuilderForRoom.send();
|
|
}*/
|
|
}
|
|
|
|
async nextTurn() {
|
|
// ターンを進める
|
|
++this.turn;
|
|
if (this.turnOrder.length >= this.turn) this.turn = 0;
|
|
|
|
const turnPlayer = players[this.turnOrder[this.turn]];
|
|
// カードを一枚引く
|
|
await turnPlayer.addCard(this.deck[0]);
|
|
this.deck.splice(0, 1);
|
|
await new Promise(resolve => setTimeout(resolve, 700));
|
|
|
|
// 操作待ち
|
|
}
|
|
|
|
onGameMessage(message) {
|
|
if (message.body.side != side.host)
|
|
this.playerController.onGameMessage(message);
|
|
}
|
|
|
|
joinNewPlayer(obj) {
|
|
this.players.set(obj.from, new Player(obj.from));
|
|
let messageBuilder = new MessageBuilder().game();
|
|
messageBuilder.addCommand(commands.syncRoomData, null, clientId, [...this.players.keys()]);
|
|
messageBuilder.send();
|
|
}
|
|
|
|
clientOperations = {
|
|
selectedCards: () => { }
|
|
}
|
|
|
|
cardCommands = {
|
|
remove: (target, card, index, canRecycle) => {
|
|
const player = controller.players.get(target);
|
|
index = player.cards.findIndex(it => it.id == card.id && it.cardType.id == card.cardType.id);
|
|
card = player.cards[index];
|
|
if (canRecycle)
|
|
this.discarded.push(...player.cards.splice(index, 1));
|
|
else
|
|
this.cardCommands.backIntoDeck(card);
|
|
new MessageBuilder().game().addCommand(commands.worker, target, "remove", [target, { cardType: { id: card.cardType.id }, idIndex: card.idIndex }, index, canRecycle]).send();
|
|
},
|
|
backIntoDeck: (card) => {
|
|
this.deck.splice(Math.floor(Math.random() * (this.deck.length + 1)), 0, card);
|
|
},
|
|
selectCard: (target, count, waitingId) => {
|
|
const player = controller.players.get(target);
|
|
waitingId = ++this.latestWaitingId;
|
|
this.waiting.set(waitingId, this.clientOperations.selectedCards);
|
|
new MessageBuilder(target).game().addCommand(commands.worker, target, "selectCard", [target, count, waitingId]).send();
|
|
},
|
|
};
|
|
} |