增加出牌和吃牌的超时限制
This commit is contained in:
parent
04b3e87901
commit
a8c44ea05a
5
src/global.d.ts
vendored
5
src/global.d.ts
vendored
@ -18,13 +18,16 @@ import {BattleHandler} from "./rooms/logic/Handler/BattleHandler";
|
||||
import {SkillInfoData, SkillInfoMsg} from "./message/SkillInfo";
|
||||
import {PartResultMsg} from "./message/PartResult";
|
||||
import {RemovePetMsg} from "./message/RemovePetMsg";
|
||||
import {Dispatcher} from "@colyseus/command";
|
||||
import {Delayed} from "@gamestdio/timer/lib/Delayed";
|
||||
/**
|
||||
* GeneralRoom 扩展方法
|
||||
*/
|
||||
declare module "colyseus" {
|
||||
interface Room {
|
||||
battleMan: BattleHandler;
|
||||
|
||||
dispatcher: Dispatcher;
|
||||
mainClock: Delayed;
|
||||
/**
|
||||
* 根据sessionId获取client
|
||||
* @param sessionId
|
||||
|
@ -12,6 +12,7 @@ import {EatCardCommand} from "./commands/EatCardCommand";
|
||||
import {GiveUpCommand} from "./commands/GiveUpCommand";
|
||||
import {BattleHandler} from "./logic/Handler/BattleHandler";
|
||||
import {debugRoom} from "../common/Debug";
|
||||
import {Delayed} from "@gamestdio/timer/lib/Delayed";
|
||||
|
||||
|
||||
export class GeneralRoom extends Room {
|
||||
@ -19,6 +20,8 @@ export class GeneralRoom extends Room {
|
||||
maxClients = 4;
|
||||
clientMap = new Map();
|
||||
battleMan = new BattleHandler();
|
||||
// 用于游戏过程中各种计时器, 使用该计时器的前提是, 只针对当前操作玩家
|
||||
mainClock: Delayed;
|
||||
|
||||
onCreate (options: any) {
|
||||
let cs = new CardGameState();
|
||||
|
@ -4,6 +4,8 @@ import gameUtil from "../../utils/game.util";
|
||||
import {Client} from "colyseus";
|
||||
import {NextSubCommand} from "./NextSubCommand";
|
||||
import {GameStateConst} from "../../constants/GameStateConst";
|
||||
import {singleton} from "../../common/Singleton";
|
||||
import {GameEnv} from "../../cfg/GameEnv";
|
||||
|
||||
/**
|
||||
* 出牌
|
||||
@ -39,6 +41,14 @@ export class DiscardCommand extends Command<CardGameState, { client: Client, car
|
||||
return;
|
||||
}
|
||||
this.state.cards.clear();
|
||||
//停止计时, 并更新player.extraTime;
|
||||
if (this.room.mainClock) {
|
||||
let maxTime = singleton(GameEnv).maxDiscardTime * 1000;
|
||||
let count = this.room.mainClock.elapsedTime - maxTime;
|
||||
let newCount = player.extraTime - count;
|
||||
player.extraTime = Math.max(newCount, 0);
|
||||
this.room.mainClock.clear();
|
||||
}
|
||||
for (let id of cards) {
|
||||
this.state.cards.set(id+'', player.cards.get(id + ''));
|
||||
player.cards.delete(id + '');
|
||||
|
@ -3,7 +3,7 @@ import {CardGameState} from "../schema/CardGameState";
|
||||
import {singleton} from "../../common/Singleton";
|
||||
import {GameEnv} from "../../cfg/GameEnv";
|
||||
import gameUtil from "../../utils/game.util";
|
||||
import {error} from "../../common/Debug";
|
||||
import {debugRoom, error} from "../../common/Debug";
|
||||
import {DiscardCommand} from "./DiscardCommand";
|
||||
|
||||
/**
|
||||
@ -13,14 +13,19 @@ export class DrawCommand extends Command<CardGameState, {}> {
|
||||
async execute() {
|
||||
let sessionId = this.state.currentTurn;
|
||||
this.room.addCard(sessionId, singleton(GameEnv).roundDrawNum, 0);
|
||||
let maxTime = singleton(GameEnv).maxDiscardTime;
|
||||
await this.delay(maxTime * 1000);
|
||||
if (sessionId == this.state.currentTurn) {
|
||||
let client = this.room.getClient(sessionId);
|
||||
error('出牌时间到, 自动出牌');
|
||||
let player = this.state.players.get(sessionId);
|
||||
let card = player.cards.values().next().value;
|
||||
return [new DiscardCommand().setPayload({client, cards: [card.id], dtype: 1})]
|
||||
}
|
||||
let maxTime = singleton(GameEnv).maxDiscardTime * 1000;
|
||||
let player = this.state.players.get(sessionId);
|
||||
let self = this;
|
||||
this.room.mainClock = this.clock.setTimeout(function () {
|
||||
self.room.mainClock.clear();
|
||||
if (sessionId == self.state.currentTurn) {
|
||||
let client = self.room.getClient(sessionId);
|
||||
let card = player.cards.values().next().value;
|
||||
debugRoom('出牌时间到, 自动出牌: ', card.id);
|
||||
self.room.dispatcher.dispatch(new DiscardCommand(), {client, cards: [card.id], dtype: 1});
|
||||
}
|
||||
}, maxTime + player.extraTime)
|
||||
// await this.delay((maxTime + player.extraTime) * 1000);
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -12,6 +12,9 @@ export class GiveUpCommand extends Command<CardGameState, {client: Client}> {
|
||||
this.state.giveUpCount += 1;
|
||||
this.room.broadcast('give_up_eat_s2c', {player: client.sessionId});
|
||||
if (this.state.giveUpCount >= this.room.maxClients - 1) {
|
||||
if (this.room.mainClock) {
|
||||
this.room.mainClock.clear();
|
||||
}
|
||||
return [new TurnEndCommand()];
|
||||
}
|
||||
}
|
||||
|
@ -1,15 +1,25 @@
|
||||
import { Command } from "@colyseus/command";
|
||||
import { CardGameState } from "../schema/CardGameState";
|
||||
import {GameStateConst} from "../../constants/GameStateConst";
|
||||
import {singleton} from "../../common/Singleton";
|
||||
import {GameEnv} from "../../cfg/GameEnv";
|
||||
import {NextTurnCommand} from "./NextTurnCommand";
|
||||
import {TurnEndCommand} from "./TurnEndCommand";
|
||||
|
||||
/**
|
||||
* 下一个吃牌轮
|
||||
*/
|
||||
export class NextSubCommand extends Command<CardGameState, {}> {
|
||||
|
||||
execute() {
|
||||
async execute() {
|
||||
this.state.gameState = GameStateConst.STATE_BEGIN_EAT;
|
||||
this.state.giveUpCount = 0;
|
||||
let time = singleton(GameEnv).maxEatTime * 1000;
|
||||
let self = this;
|
||||
this.room.mainClock = this.clock.setTimeout(function (){
|
||||
self.room.mainClock.clear();
|
||||
self.room.dispatcher.dispatch(new TurnEndCommand());
|
||||
}, time);
|
||||
// const sessionIds = [...this.state.players.keys()];
|
||||
// let nextSubTurn = this.state.subTurn ?
|
||||
// sessionIds[(sessionIds.indexOf(this.state.subTurn) + 1) % sessionIds.length]
|
||||
|
@ -23,6 +23,14 @@ export class NextTurnCommand extends Command<CardGameState, {}> {
|
||||
if (this.state.currentTurn
|
||||
&& sessionIds.indexOf(this.state.currentTurn) == (sessionIds.length - 1)) {
|
||||
this.state.round += 1;
|
||||
// 所有玩家根据配置, 增加5点灵活值
|
||||
if (this.state.round > 0) {
|
||||
let moreRoundTime = singleton(GameEnv).roundExtTime * 1000;
|
||||
let maxTime = 20 * 1000;
|
||||
for (let [key, p] of this.state.players) {
|
||||
p.extraTime = Math.min(p.extraTime + moreRoundTime * 1000, maxTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
this.state.currentTurn = (this.state.currentTurn)
|
||||
? sessionIds[(sessionIds.indexOf(this.state.currentTurn) + 1) % sessionIds.length]
|
||||
|
@ -6,6 +6,8 @@ import {BeginGameCommand} from "./BeginGameCommand";
|
||||
import {BattleHandler} from "../logic/Handler/BattleHandler";
|
||||
import {BaseConst} from "../../constants/BaseConst";
|
||||
import {error} from "../../common/Debug";
|
||||
import {singleton} from "../../common/Singleton";
|
||||
import {GameEnv} from "../../cfg/GameEnv";
|
||||
|
||||
/**
|
||||
* 选择英雄
|
||||
@ -27,6 +29,7 @@ export class SelectHeroCommand extends Command<CardGameState, {client: Client, h
|
||||
}
|
||||
player.state = PlayerStateConst.PLAYER_SELECT_HERO;
|
||||
player.hp = unitData.hero_hp;
|
||||
player.extraTime = singleton(GameEnv).maxExtTime * 1000;
|
||||
let heroPet = player.pets.get('0');
|
||||
heroPet.ap = unitData.powernum;
|
||||
heroPet.state = 1;
|
||||
|
@ -50,6 +50,11 @@ export class Player extends Schema {
|
||||
*/
|
||||
@type("number")
|
||||
team: number;
|
||||
/**
|
||||
* 玩家灵活时限, 客户端每次显示倒计时的时候, 需读取该时间
|
||||
*/
|
||||
@type("number")
|
||||
extraTime: number;
|
||||
/**
|
||||
* 当前游戏总抽卡数量
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user