From eede6b0eeb1b0c6a16a11f277c389fcfc49303b3 Mon Sep 17 00:00:00 2001 From: zhl Date: Wed, 9 Dec 2020 13:08:08 +0800 Subject: [PATCH] =?UTF-8?q?=E7=8E=A9=E5=AE=B6=E6=AD=BB=E4=BA=A1=E5=90=8E,?= =?UTF-8?q?=20=E5=B0=86=E6=89=8B=E7=89=8C=E4=BA=A4=E7=BB=99=E9=98=9F?= =?UTF-8?q?=E5=8F=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/rooms/RoomExtMethod.ts | 4 ++-- src/rooms/commands/PartResultCommand.ts | 7 +++---- src/rooms/commands/PlayDeadCommand.ts | 24 ++++++++++++++++++++++++ 3 files changed, 29 insertions(+), 6 deletions(-) create mode 100644 src/rooms/commands/PlayDeadCommand.ts diff --git a/src/rooms/RoomExtMethod.ts b/src/rooms/RoomExtMethod.ts index c988440..02d44b6 100644 --- a/src/rooms/RoomExtMethod.ts +++ b/src/rooms/RoomExtMethod.ts @@ -3,6 +3,7 @@ import gameUtil from "../utils/game.util"; import {error} from "../common/Debug"; import {PlayerStateConst} from "../constants/PlayerStateConst"; import {PetInfo} from "../message/PetInfo"; +import {PlayDeadCommand} from "./commands/PlayDeadCommand"; /** * 一些常用的方法 @@ -89,8 +90,7 @@ Object.defineProperties(Room.prototype, { let dstHp = player.hp + hp; if (dstHp <= 0) { dstHp = 0; - player.state = PlayerStateConst.PLAYER_DEAD; - this.battleMan.onPlayerDead(player); + this.dispatcher.dispatch(new PlayDeadCommand(), {player: player}); } player.hp = dstHp; } diff --git a/src/rooms/commands/PartResultCommand.ts b/src/rooms/commands/PartResultCommand.ts index 9ca0d2c..fd678ee 100644 --- a/src/rooms/commands/PartResultCommand.ts +++ b/src/rooms/commands/PartResultCommand.ts @@ -11,6 +11,7 @@ import {Player} from "../schema/Player"; import gameUtil from "../../utils/game.util"; import {PartCompare, PartResultMsg} from "../../message/PartResult"; import {Room} from "colyseus"; +import {PlayDeadCommand} from "./PlayDeadCommand"; /** * 游戏中的结算轮 @@ -61,8 +62,7 @@ const comparePlayer = function (room: Room, p0: Player, p1: Player): CompareResu r.val = val; if (p1.hp <= 0) { p1.hp = 0; - p1.state = PlayerStateConst.PLAYER_DEAD; - room.battleMan.onPlayerDead(p1); + room.dispatcher.dispatch(new PlayDeadCommand(), {player: p1}); } else { r.next.set(1, p1); } @@ -74,8 +74,7 @@ const comparePlayer = function (room: Room, p0: Player, p1: Player): CompareResu r.next.set(1, p1); if (p0.hp <= 0) { p0.hp = 0; - p0.state = PlayerStateConst.PLAYER_DEAD; - room.battleMan.onPlayerDead(p0); + room.dispatcher.dispatch(new PlayDeadCommand(), {player: p0}); } else { r.next.set(0, p0); } diff --git a/src/rooms/commands/PlayDeadCommand.ts b/src/rooms/commands/PlayDeadCommand.ts new file mode 100644 index 0000000..583f545 --- /dev/null +++ b/src/rooms/commands/PlayDeadCommand.ts @@ -0,0 +1,24 @@ +import {Command} from "@colyseus/command"; +import {CardGameState} from "../schema/CardGameState"; +import {Player} from "../schema/Player"; +import {PlayerStateConst} from "../../constants/PlayerStateConst"; + +/** + * 玩家死亡 + */ +export class PlayDeadCommand extends Command { + + execute({player} = this.payload) { + player.state = PlayerStateConst.PLAYER_DEAD; + this.room.battleMan.onPlayerDead(player); + for (let [, p] of this.state.players) { + if (p.id !== player.id && p.team == player.team) { + if (p.state !== PlayerStateConst.PLAYER_DEAD) { + let amount = p.cards.size; + this.room.drawCardFromPlayer(p.id, player.id, amount); + } + break; + } + } + } +}