增加一些流程中对BattleHandler的回调

This commit is contained in:
zhl 2020-12-07 14:33:46 +08:00
parent b130453718
commit 1febf4ee13
6 changed files with 30 additions and 15 deletions

View File

@ -7,6 +7,7 @@ import {PlayerStateConst} from "../../constants/PlayerStateConst";
import {singleton} from "../../common/Singleton"; import {singleton} from "../../common/Singleton";
import {GameEnv} from "../../cfg/GameEnv"; import {GameEnv} from "../../cfg/GameEnv";
import {GameStateConst} from "../../constants/GameStateConst"; import {GameStateConst} from "../../constants/GameStateConst";
import {NextTurnCommand} from "./NextTurnCommand";
/** /**
* *
@ -37,11 +38,9 @@ export class ChangeCardCommand extends Command<CardGameState, { client: Client,
if (finishCount >= this.room.maxClients) { if (finishCount >= this.room.maxClients) {
// TODO:: 延后开始 根据 this.state.firstPlayer确定先手 // TODO:: 延后开始 根据 this.state.firstPlayer确定先手
// 正式开始游戏, 第一个玩家出牌 // 正式开始游戏, 第一个玩家出牌
let curClient = this.room.clients[0];
this.state.currentTurn = curClient.sessionId;
this.state.round = 0;
this.room.addCard(curClient.sessionId, singleton(GameEnv).roundDrawNum, 0);
this.state.gameState = GameStateConst.STATE_BEGIN_DRAW; this.state.gameState = GameStateConst.STATE_BEGIN_DRAW;
return [new NextTurnCommand()];
} }
} }

View File

@ -45,7 +45,13 @@ export class EatCardCommand extends Command<CardGameState, { client: Client, car
player.cardSet.delete(id+''); player.cardSet.delete(id+'');
} }
this.state.gameState = GameStateConst.STATE_PICK_PET; this.state.gameState = GameStateConst.STATE_PICK_PET;
//TODO:: 调用 onCardLinkReady() let fromPlayer = this.state.players.get(this.state.currentTurn);
if (fromPlayer.id !== player.id) {
this.room.battleMan.onCardLinkReady(player, fromPlayer);
} else {
this.room.battleMan.onCardLinkReady(player);
}
// 成功后广播吃牌成功消息 // 成功后广播吃牌成功消息
this.room.broadcast('eat_card_s2c', {player: client.sessionId, errocode: 0, errmsg: ''}) this.room.broadcast('eat_card_s2c', {player: client.sessionId, errocode: 0, errmsg: ''})
} }

View File

@ -14,6 +14,9 @@ export class NextTurnCommand extends Command<CardGameState, {}> {
execute() { execute() {
this.state.gameState = GameStateConst.STATE_BEGIN_DRAW; this.state.gameState = GameStateConst.STATE_BEGIN_DRAW;
const sessionIds = [...this.state.players.keys()]; const sessionIds = [...this.state.players.keys()];
if (!this.state.currentTurn) {
this.state.round = 0;
}
// 如果上一轮是最后一个玩家, 则round + 1; // 如果上一轮是最后一个玩家, 则round + 1;
if (this.state.currentTurn if (this.state.currentTurn
&& sessionIds.indexOf(this.state.currentTurn) == (sessionIds.length - 1)) { && sessionIds.indexOf(this.state.currentTurn) == (sessionIds.length - 1)) {
@ -26,6 +29,7 @@ export class NextTurnCommand extends Command<CardGameState, {}> {
if (!player) { if (!player) {
error('未找到玩家'); error('未找到玩家');
} }
this.room.battleMan.onPlayerRoundStart(player);
if (player.state == PlayerStateConst.PLAYER_DEAD) { if (player.state == PlayerStateConst.PLAYER_DEAD) {
return [new TurnEndCommand()]; return [new TurnEndCommand()];
} else { } else {

View File

@ -14,6 +14,12 @@ export class TurnEndCommand extends Command<CardGameState, {}> {
execute() { execute() {
// @ts-ignore // @ts-ignore
const sessionIds = [...this.state.players.keys()]; const sessionIds = [...this.state.players.keys()];
if (this.state.currentTurn) {
let player = this.state.players.get(this.state.currentTurn);
if (player) {
this.room.battleMan.onPlayerRoundEnd(player);
}
}
if (this.state.currentTurn if (this.state.currentTurn
&& sessionIds.indexOf(this.state.currentTurn) == (sessionIds.length - 1)) { && sessionIds.indexOf(this.state.currentTurn) == (sessionIds.length - 1)) {
// 每n轮结束的时候结算一次 // 每n轮结束的时候结算一次

View File

@ -222,7 +222,7 @@ export class BattleHandler {
}; };
/** /**
* / * /??
* @param aplayer * @param aplayer
* @param linkcards * @param linkcards
*/ */
@ -246,7 +246,7 @@ export class BattleHandler {
}; };
/** /**
* * ??
* @param aplayer * @param aplayer
* @param fromplayer : 谁使玩家弃牌的 * @param fromplayer : 谁使玩家弃牌的
* @param dropcards : 弃掉的牌组 * @param dropcards : 弃掉的牌组
@ -258,7 +258,7 @@ export class BattleHandler {
}; };
/** /**
* * ??
* @param aplayer * @param aplayer
* @param fromplayer : 谁使玩家获得牌的 * @param fromplayer : 谁使玩家获得牌的
* @param dropcards : 获得的牌组 * @param dropcards : 获得的牌组

View File

@ -9,7 +9,7 @@ import { EnhanceEffectType, PowerValueType } from "../skill/SkillConst";
import { PlayerHandler } from "./PlayerHandler"; import { PlayerHandler } from "./PlayerHandler";
import { PetInfoMsg } from "../../../message/PetInfo"; import { PetInfoMsg } from "../../../message/PetInfo";
import { SkillParam } from "../skill/SkillParam"; import { SkillParam } from "../skill/SkillParam";
import { RemovePetMsg } from "message/RemovePetMsg"; import { RemovePetMsg } from "../../../message/RemovePetMsg";
export class PetHandler { export class PetHandler {
_pet: Pet; _pet: Pet;