选择英雄时增加校验
This commit is contained in:
parent
4ce55368de
commit
fc68018a32
15
src/global.d.ts
vendored
15
src/global.d.ts
vendored
@ -12,7 +12,7 @@ declare global {
|
|||||||
/**
|
/**
|
||||||
* GeneralRoom 扩展方法
|
* GeneralRoom 扩展方法
|
||||||
*/
|
*/
|
||||||
import { Room } from "colyseus";
|
import {Client, Room} from "colyseus";
|
||||||
declare module "colyseus" {
|
declare module "colyseus" {
|
||||||
interface Room {
|
interface Room {
|
||||||
/**
|
/**
|
||||||
@ -21,6 +21,19 @@ declare module "colyseus" {
|
|||||||
* @param options
|
* @param options
|
||||||
*/
|
*/
|
||||||
bUserJoin(data?: any, options?: any): void;
|
bUserJoin(data?: any, options?: any): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 给指定用户下发英雄选择结果
|
||||||
|
* @param client
|
||||||
|
* @param data
|
||||||
|
*/
|
||||||
|
sSelectHero(client: Client, data?: any);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 广播英雄选择结果
|
||||||
|
* @param data
|
||||||
|
*/
|
||||||
|
bSelectHero(data?: any);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ export class GeneralRoom extends Room {
|
|||||||
|
|
||||||
this.onMessage("select_hero_c2s", (client, message) => {
|
this.onMessage("select_hero_c2s", (client, message) => {
|
||||||
console.log('select_hero from ', client.sessionId, message);
|
console.log('select_hero from ', client.sessionId, message);
|
||||||
this.dispatcher.dispatch(new SelectHeroCommand(), {client, heroId: message.heroId});
|
this.dispatcher.dispatch(new SelectHeroCommand(), {client, heroId: message.heroId, battle: this.battleMan});
|
||||||
});
|
});
|
||||||
|
|
||||||
this.onMessage("*", (client, type, message) => {
|
this.onMessage("*", (client, type, message) => {
|
||||||
|
@ -6,3 +6,11 @@ room.bUserJoin = function (data, options?: any) {
|
|||||||
this.broadcast("player_join", data, options);
|
this.broadcast("player_join", data, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
room.sSelectHero = function (client, data) {
|
||||||
|
this.send(client, 'select_hero_s2c', data);
|
||||||
|
}
|
||||||
|
|
||||||
|
room.bSelectHero = function(data) {
|
||||||
|
this.broadcast("select_hero_s2c", data);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@ import {Player} from "../schema/Player";
|
|||||||
import {Client} from "colyseus";
|
import {Client} from "colyseus";
|
||||||
import {GameStateConst} from "../../constants/GameStateConst";
|
import {GameStateConst} from "../../constants/GameStateConst";
|
||||||
import { BattleHandler } from "rooms/logic/Handler/BattleHandler";
|
import { BattleHandler } from "rooms/logic/Handler/BattleHandler";
|
||||||
|
import {BaseConst} from "../../constants/BaseConst";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 玩家成功加入房间
|
* 玩家成功加入房间
|
||||||
@ -16,7 +17,6 @@ export class OnJoinCommand extends Command<CardGameState, {
|
|||||||
let team = this.state.players.size / 2 | 0;
|
let team = this.state.players.size / 2 | 0;
|
||||||
let player = new Player(0, team);
|
let player = new Player(0, team);
|
||||||
this.state.players.set(client.sessionId, player);
|
this.state.players.set(client.sessionId, player);
|
||||||
battle.addPlayer(player);
|
|
||||||
if (this.state.players.size >= this.room.maxClients) {
|
if (this.state.players.size >= this.room.maxClients) {
|
||||||
this.room.lock();
|
this.room.lock();
|
||||||
this.state.gameState = GameStateConst.STATE_WAIT_PREPARE;
|
this.state.gameState = GameStateConst.STATE_WAIT_PREPARE;
|
||||||
|
@ -3,16 +3,24 @@ import {CardGameState} from "../schema/CardGameState";
|
|||||||
import {Client} from "colyseus";
|
import {Client} from "colyseus";
|
||||||
import {PlayerStateConst} from "../../constants/PlayerStateConst";
|
import {PlayerStateConst} from "../../constants/PlayerStateConst";
|
||||||
import {BeginGameCommand} from "./BeginGameCommand";
|
import {BeginGameCommand} from "./BeginGameCommand";
|
||||||
|
import {BattleHandler} from "../logic/Handler/BattleHandler";
|
||||||
|
import {BaseConst} from "../../constants/BaseConst";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 选择英雄
|
* 选择英雄
|
||||||
*/
|
*/
|
||||||
export class SelectHeroCommand extends Command<CardGameState, {client: Client, heroId: number}> {
|
export class SelectHeroCommand extends Command<CardGameState, {client: Client, heroId: number, battle: BattleHandler}> {
|
||||||
execute({ client, heroId } = this.payload) {
|
execute({ client, heroId, battle} = this.payload) {
|
||||||
let player = this.state.players.get(client.sessionId);
|
let player = this.state.players.get(client.sessionId);
|
||||||
|
const heroMap = global.$cfg.get(BaseConst.HERO);
|
||||||
|
if (!heroMap || !heroMap.has(heroId)) {
|
||||||
|
this.room.sSelectHero(client, {errcode: 1, errmsg: '无法找到对应英雄的配置'});
|
||||||
|
return;
|
||||||
|
}
|
||||||
player.heroId = heroId;
|
player.heroId = heroId;
|
||||||
player.state = PlayerStateConst.PLAYER_SELECT_HERO;
|
player.state = PlayerStateConst.PLAYER_SELECT_HERO;
|
||||||
this.room.broadcast('select_hero_s2c', {errocode: 0, errmsg: '', player: client.sessionId, heroId: heroId});
|
battle.addPlayer(player);
|
||||||
|
this.room.bSelectHero({errocode: 0, errmsg: '', player: client.sessionId, heroId: heroId});
|
||||||
let readyCount = 0;
|
let readyCount = 0;
|
||||||
for (let [sessionId, player] of this.state.players) {
|
for (let [sessionId, player] of this.state.players) {
|
||||||
if (player.state === PlayerStateConst.PLAYER_SELECT_HERO) {
|
if (player.state === PlayerStateConst.PLAYER_SELECT_HERO) {
|
||||||
|
@ -10,7 +10,7 @@ export class PetHandler {
|
|||||||
private _owner: PlayerHandler;
|
private _owner: PlayerHandler;
|
||||||
_id: number;
|
_id: number;
|
||||||
_cfg: UnitCfg;
|
_cfg: UnitCfg;
|
||||||
_exskills: number[];
|
_exskills: number[] = [];
|
||||||
|
|
||||||
_baseap: number;
|
_baseap: number;
|
||||||
|
|
||||||
|
@ -52,7 +52,7 @@ let gameUtil = {
|
|||||||
for (let data of tmpArr) {
|
for (let data of tmpArr) {
|
||||||
if (data[1] >= num ) {
|
if (data[1] >= num ) {
|
||||||
let count = countMap.has(data[0]) ? countMap.get(data[0]) : 0;
|
let count = countMap.has(data[0]) ? countMap.get(data[0]) : 0;
|
||||||
if (count < effCfgMap.get(data[0]).count) {
|
if (count <= effCfgMap.get(data[0]).count) {
|
||||||
effid = effCfgMap.get(data[0]).id;
|
effid = effCfgMap.get(data[0]).id;
|
||||||
countMap.set(effid, count + 1);
|
countMap.set(effid, count + 1);
|
||||||
break;
|
break;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user