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";
 | 
					"use strict";
 | 
				
			||||||
 | 
					const AsyncFunction = async function () {}.constructor;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function discard(target, card) {
 | 
					function discard(target, card) {
 | 
				
			||||||
    console.log("DIS!CAR!D!");
 | 
					    console.log("DIS!CAR!D!");
 | 
				
			||||||
    postMessage({ type: "game", game: { command: "discard", target: target, card: card } });
 | 
					    postMessage({ type: "game", game: { command: "discard", target: target, card: card } });
 | 
				
			||||||
@ -16,7 +18,7 @@ onmessage = e => {
 | 
				
			|||||||
    console.log(e);
 | 
					    console.log(e);
 | 
				
			||||||
    switch (e.data.type) {
 | 
					    switch (e.data.type) {
 | 
				
			||||||
        case "run":
 | 
					        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);
 | 
					            fun(e.data.target, e.data.players);
 | 
				
			||||||
            break;
 | 
					            break;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
				
			|||||||
@ -84,7 +84,8 @@ const cardTypes = {
 | 
				
			|||||||
    annihilation: {
 | 
					    annihilation: {
 | 
				
			||||||
        id: "annihilation",
 | 
					        id: "annihilation",
 | 
				
			||||||
        prefix: "I",
 | 
					        prefix: "I",
 | 
				
			||||||
        count: 1
 | 
					        count: 1,
 | 
				
			||||||
 | 
					        onGet: "players.forEach(player => {if(player.cards.length <= 5)player.cards.forEach(card => {discard(player,card);})});"
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    drop: {
 | 
					    drop: {
 | 
				
			||||||
        id: "drop",
 | 
					        id: "drop",
 | 
				
			||||||
 | 
				
			|||||||
@ -147,6 +147,9 @@ class EXOUtils {
 | 
				
			|||||||
                    case "discard":
 | 
					                    case "discard":
 | 
				
			||||||
                        controller.cardCommands.remove(e.data.game.target.clientId, e.data.game.card, null, true);
 | 
					                        controller.cardCommands.remove(e.data.game.target.clientId, e.data.game.card, null, true);
 | 
				
			||||||
                        break;
 | 
					                        break;
 | 
				
			||||||
 | 
					                    case "selectCard":
 | 
				
			||||||
 | 
					                        controller.cardCommands.selectCard(e.data.game.target.clientId, e.data.game.card, null, true);
 | 
				
			||||||
 | 
					                        break;
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                break;
 | 
					                break;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
				
			|||||||
@ -8,12 +8,14 @@ class HostController {
 | 
				
			|||||||
    players = new Map();
 | 
					    players = new Map();
 | 
				
			||||||
    turnOrder;
 | 
					    turnOrder;
 | 
				
			||||||
    turn = -1;
 | 
					    turn = -1;
 | 
				
			||||||
 | 
					    latestWaitingId = 0;
 | 
				
			||||||
 | 
					    waiting = new Map();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    constructor() {
 | 
					    constructor() {
 | 
				
			||||||
        this.playerController = new PlayerController();
 | 
					        this.playerController = new PlayerController();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    gameStart() {
 | 
					    async gameStart() {
 | 
				
			||||||
        // ターンを決定
 | 
					        // ターンを決定
 | 
				
			||||||
        this.turnOrder = EXOUtils.shuffleArray([...this.players.keys()]);
 | 
					        this.turnOrder = EXOUtils.shuffleArray([...this.players.keys()]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -30,7 +32,8 @@ class HostController {
 | 
				
			|||||||
        // 山札をシャッフル
 | 
					        // 山札をシャッフル
 | 
				
			||||||
        EXOUtils.shuffleArray(this.deck);
 | 
					        EXOUtils.shuffleArray(this.deck);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        this.distributionCards();
 | 
					        await this.distributionCards();
 | 
				
			||||||
 | 
					        this.nextTurn();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    async distributionCards() {
 | 
					    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) {
 | 
					    onGameMessage(message) {
 | 
				
			||||||
        if (message.body.side != side.host)
 | 
					        if (message.body.side != side.host)
 | 
				
			||||||
            this.playerController.onGameMessage(message);
 | 
					            this.playerController.onGameMessage(message);
 | 
				
			||||||
@ -72,19 +89,29 @@ class HostController {
 | 
				
			|||||||
        messageBuilder.send();
 | 
					        messageBuilder.send();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    clientOperations = {
 | 
				
			||||||
 | 
					        selectedCards: () => { }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    cardCommands = {
 | 
					    cardCommands = {
 | 
				
			||||||
        remove: (target, card, index, canRecycle) => {
 | 
					        remove: (target, card, index, canRecycle) => {
 | 
				
			||||||
            const player = controller.players.get(target);
 | 
					            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];
 | 
					            card = player.cards[index];
 | 
				
			||||||
            if (canRecycle)
 | 
					            if (canRecycle)
 | 
				
			||||||
                this.discarded.push(...player.cards.splice(index, 1));
 | 
					                this.discarded.push(...player.cards.splice(index, 1));
 | 
				
			||||||
            else
 | 
					            else
 | 
				
			||||||
                this.cardCommands.backIntoDeck(card);
 | 
					                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) => {
 | 
					        backIntoDeck: (card) => {
 | 
				
			||||||
            this.deck.splice(Math.floor(Math.random() * (this.deck.length + 1)), 0, 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…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user