玩家死亡后, 将手牌交给队友
This commit is contained in:
parent
a0c87cd98f
commit
eede6b0eeb
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
24
src/rooms/commands/PlayDeadCommand.ts
Normal file
24
src/rooms/commands/PlayDeadCommand.ts
Normal file
@ -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<CardGameState, {player: Player}> {
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user