add some communication functions
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
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
This commit is contained in:
parent
704ad00af8
commit
8136e91a0f
@ -1,4 +1,6 @@
|
||||
"use strict";
|
||||
const AsyncFunction = async function () {}.constructor;
|
||||
|
||||
function discard(target, card) {
|
||||
console.log("DIS!CAR!D!");
|
||||
postMessage({ type: "game", game: { command: "discard", target: target, card: card } });
|
||||
@ -16,7 +18,7 @@ onmessage = e => {
|
||||
console.log(e);
|
||||
switch (e.data.type) {
|
||||
case "run":
|
||||
let fun = new Function("target", "players", e.data.function);
|
||||
let fun = new AsyncFunction("target", "players", e.data.function);
|
||||
fun(e.data.target, e.data.players);
|
||||
break;
|
||||
}
|
||||
|
@ -84,7 +84,8 @@ const cardTypes = {
|
||||
annihilation: {
|
||||
id: "annihilation",
|
||||
prefix: "I",
|
||||
count: 1
|
||||
count: 1,
|
||||
onGet: "players.forEach(player => {if(player.cards.length <= 5)player.cards.forEach(card => {discard(player,card);})});"
|
||||
},
|
||||
drop: {
|
||||
id: "drop",
|
||||
|
@ -147,6 +147,9 @@ class EXOUtils {
|
||||
case "discard":
|
||||
controller.cardCommands.remove(e.data.game.target.clientId, e.data.game.card, null, true);
|
||||
break;
|
||||
case "selectCard":
|
||||
controller.cardCommands.selectCard(e.data.game.target.clientId, e.data.game.card, null, true);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -8,12 +8,14 @@ class HostController {
|
||||
players = new Map();
|
||||
turnOrder;
|
||||
turn = -1;
|
||||
latestWaitingId = 0;
|
||||
waiting = new Map();
|
||||
|
||||
constructor() {
|
||||
this.playerController = new PlayerController();
|
||||
}
|
||||
|
||||
gameStart() {
|
||||
async gameStart() {
|
||||
// ターンを決定
|
||||
this.turnOrder = EXOUtils.shuffleArray([...this.players.keys()]);
|
||||
|
||||
@ -30,7 +32,8 @@ class HostController {
|
||||
// 山札をシャッフル
|
||||
EXOUtils.shuffleArray(this.deck);
|
||||
|
||||
this.distributionCards();
|
||||
await this.distributionCards();
|
||||
this.nextTurn();
|
||||
}
|
||||
|
||||
async distributionCards() {
|
||||
@ -60,6 +63,20 @@ class HostController {
|
||||
}*/
|
||||
}
|
||||
|
||||
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);
|
||||
@ -72,19 +89,29 @@ class HostController {
|
||||
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);
|
||||
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, card, index, canRecycle]).send();
|
||||
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();
|
||||
},
|
||||
};
|
||||
}
|
Loading…
Reference in New Issue
Block a user