增加施法的消息
This commit is contained in:
parent
570eb8a214
commit
d15c07eadc
65
package-lock.json
generated
65
package-lock.json
generated
@ -221,6 +221,11 @@
|
||||
"@types/express": "*"
|
||||
}
|
||||
},
|
||||
"@types/debug": {
|
||||
"version": "4.1.5",
|
||||
"resolved": "https://registry.npmjs.org/@types/debug/-/debug-4.1.5.tgz",
|
||||
"integrity": "sha512-Q1y515GcOdTHgagaVFhHnIFQ38ygs/kmxdNpvpou+raI9UO3YZcHDngBSYKQklcKlvA7iuQlmIKbzvmxcOE9CQ=="
|
||||
},
|
||||
"@types/express": {
|
||||
"version": "4.17.9",
|
||||
"resolved": "https://registry.npmjs.org/@types/express/-/express-4.17.9.tgz",
|
||||
@ -490,6 +495,16 @@
|
||||
"qs": "6.7.0",
|
||||
"raw-body": "2.4.0",
|
||||
"type-is": "~1.6.17"
|
||||
},
|
||||
"dependencies": {
|
||||
"debug": {
|
||||
"version": "2.6.9",
|
||||
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
|
||||
"integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
|
||||
"requires": {
|
||||
"ms": "2.0.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"brace-expansion": {
|
||||
@ -716,11 +731,18 @@
|
||||
}
|
||||
},
|
||||
"debug": {
|
||||
"version": "2.6.9",
|
||||
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
|
||||
"integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
|
||||
"version": "4.3.1",
|
||||
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.1.tgz",
|
||||
"integrity": "sha512-doEwdvm4PCeK4K3RQN2ZC2BYUBaxwLARCqZmMjtF8a51J2Rb0xpVloFRnCODwqjpwnAoao4pelN8l3RJdv3gRQ==",
|
||||
"requires": {
|
||||
"ms": "2.0.0"
|
||||
"ms": "2.1.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"ms": {
|
||||
"version": "2.1.2",
|
||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
|
||||
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
|
||||
}
|
||||
}
|
||||
},
|
||||
"decamelize": {
|
||||
@ -882,6 +904,16 @@
|
||||
"type-is": "~1.6.18",
|
||||
"utils-merge": "1.0.1",
|
||||
"vary": "~1.1.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"debug": {
|
||||
"version": "2.6.9",
|
||||
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
|
||||
"integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
|
||||
"requires": {
|
||||
"ms": "2.0.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"express-jwt": {
|
||||
@ -956,6 +988,16 @@
|
||||
"parseurl": "~1.3.3",
|
||||
"statuses": "~1.5.0",
|
||||
"unpipe": "~1.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"debug": {
|
||||
"version": "2.6.9",
|
||||
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
|
||||
"integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
|
||||
"requires": {
|
||||
"ms": "2.0.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"find-up": {
|
||||
@ -2113,6 +2155,21 @@
|
||||
"statuses": "~1.5.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"debug": {
|
||||
"version": "2.6.9",
|
||||
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
|
||||
"integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
|
||||
"requires": {
|
||||
"ms": "2.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"ms": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
|
||||
"integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g="
|
||||
}
|
||||
}
|
||||
},
|
||||
"ms": {
|
||||
"version": "2.1.1",
|
||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.1.tgz",
|
||||
|
@ -7,6 +7,7 @@
|
||||
"scripts": {
|
||||
"start": "ts-node-dev --inspect --files src/index.ts",
|
||||
"debug": "node --require ts-node/register --inspect src/index.ts",
|
||||
"dev": "DEBUG=colyseus:*,jc:* node --require ts-node/register --inspect src/index.ts",
|
||||
"loadtest": "colyseus-loadtest loadtest/example.ts --room my_room --numClients 3",
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
@ -17,7 +18,8 @@
|
||||
"@types/express": "^4.17.1",
|
||||
"ts-node": "^8.1.0",
|
||||
"ts-node-dev": "^1.0.0-pre.63",
|
||||
"typescript": "^3.4.5"
|
||||
"typescript": "^3.4.5",
|
||||
"@types/debug": "^4.1.5"
|
||||
},
|
||||
"dependencies": {
|
||||
"@colyseus/command": "^0.1.6",
|
||||
@ -25,6 +27,7 @@
|
||||
"@colyseus/social": "^0.10.9",
|
||||
"colyseus": "^0.14.0",
|
||||
"cors": "^2.8.5",
|
||||
"debug": "^4.3.1",
|
||||
"express": "^4.16.4",
|
||||
"express-jwt": "^5.3.1",
|
||||
"fs-jetpack": "^4.1.0"
|
||||
|
@ -2,6 +2,7 @@ import * as jetpack from "fs-jetpack";
|
||||
import {singleton} from "./Singleton";
|
||||
import {GameEnv} from "../cfg/GameEnv";
|
||||
import {BaseConst} from "../constants/BaseConst";
|
||||
import {error} from "./Debug";
|
||||
|
||||
const $cfg = new Map();
|
||||
const jsonPath = 'configs';
|
||||
@ -17,13 +18,13 @@ export var DataParser = (function (){
|
||||
for (let i = 0, len = data.length; i < len; i++) {
|
||||
let obj = data[i];
|
||||
if (!obj[idkey]) {
|
||||
console.warn(`配置${key}的数据有误,唯一标识 ${idkey} 值为0或者没有${idkey}`);
|
||||
error(`配置${key}的数据有误,唯一标识 ${idkey} 值为0或者没有${idkey}`);
|
||||
continue;
|
||||
}
|
||||
let to = new CfgCreator();
|
||||
to.decode(obj);
|
||||
if (dict.has(to.id)) {
|
||||
console.warn(`配置${key}的数据有误,唯一标识 id 有重复值:${to.id}`)
|
||||
error(`配置${key}的数据有误,唯一标识 id 有重复值:${to.id}`)
|
||||
process.abort();
|
||||
}
|
||||
dict.set(to.id, to);
|
||||
|
5
src/common/Debug.ts
Normal file
5
src/common/Debug.ts
Normal file
@ -0,0 +1,5 @@
|
||||
import debug from 'debug';
|
||||
|
||||
export const debugRoom = debug('jc:room');
|
||||
|
||||
export const error = debug('jc:error');
|
7
src/global.d.ts
vendored
7
src/global.d.ts
vendored
@ -17,6 +17,7 @@ declare global {
|
||||
import {Client, Room} from "colyseus";
|
||||
import {PetInfoMsg} from "./message/PetInfo";
|
||||
import {BattleHandler} from "./rooms/logic/Handler/BattleHandler";
|
||||
import {SkillInfoData, SkillInfoMsg} from "./message/SkillInfo";
|
||||
declare module "colyseus" {
|
||||
interface Room {
|
||||
battleMan: BattleHandler;
|
||||
@ -59,6 +60,11 @@ declare module "colyseus" {
|
||||
*/
|
||||
bAddPet(data?: PetInfoMsg): void;
|
||||
|
||||
/**
|
||||
* 施放一个技能
|
||||
* @param data
|
||||
*/
|
||||
bCastSkill(data?: SkillInfoMsg): void;
|
||||
/**
|
||||
* 发送给个人的消息列表
|
||||
* @param client
|
||||
@ -77,6 +83,7 @@ declare module "colyseus" {
|
||||
* @param options
|
||||
*/
|
||||
bMsgQueue(datas: IMsg[], options?: any): void;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
53
src/message/SkillInfo.ts
Normal file
53
src/message/SkillInfo.ts
Normal file
@ -0,0 +1,53 @@
|
||||
import {IMsg} from "./IMsg";
|
||||
|
||||
/**
|
||||
* 技能消息
|
||||
*/
|
||||
export class SKillEffectData {
|
||||
/**
|
||||
* 目标玩家
|
||||
*/
|
||||
player: string;
|
||||
/**
|
||||
* 目标随从
|
||||
* 英雄单位也作为一个随从, pos = 0;
|
||||
* 其他随从的位置从1开始计
|
||||
*/
|
||||
pos: number;
|
||||
/**
|
||||
* 效果id
|
||||
*/
|
||||
effect_id: number;
|
||||
/**
|
||||
* 效果值
|
||||
*/
|
||||
val: number;
|
||||
}
|
||||
|
||||
export class SkillInfoData {
|
||||
/**
|
||||
* 技能id
|
||||
* */
|
||||
skill_id: number;
|
||||
/**
|
||||
* 施法玩家
|
||||
*/
|
||||
player: string;
|
||||
/**
|
||||
* 施法随从
|
||||
* 英雄单位也作为一个随从, pos = 0;
|
||||
* 其他随从的位置从1开始计
|
||||
*/
|
||||
pos: number;
|
||||
datas: SKillEffectData[]
|
||||
}
|
||||
export class SkillInfoMsg implements IMsg {
|
||||
data?: any;
|
||||
errcode: number;
|
||||
errmsg: string;
|
||||
|
||||
constructor(data?: SkillInfoData) {
|
||||
this.errcode = 0;
|
||||
this.data = data;
|
||||
}
|
||||
}
|
@ -11,6 +11,7 @@ import {SelectHeroCommand} from "./commands/SelectHeroCommand";
|
||||
import {EatCardCommand} from "./commands/EatCardCommand";
|
||||
import {GiveUpCommand} from "./commands/GiveUpCommand";
|
||||
import {BattleHandler} from "./logic/Handler/BattleHandler";
|
||||
import {debugRoom} from "../common/Debug";
|
||||
|
||||
|
||||
export class GeneralRoom extends Room {
|
||||
@ -26,35 +27,35 @@ export class GeneralRoom extends Room {
|
||||
this.clock.start();
|
||||
this.state.gameSate = 0;
|
||||
this.onMessage("play_ready_c2s", (client, message) => {
|
||||
console.log('play_ready from ', client.sessionId, message);
|
||||
debugRoom('play_ready from ', client.sessionId, message);
|
||||
this.dispatcher.dispatch(new PlayReadyCommand(), {client});
|
||||
});
|
||||
this.onMessage("change_card_c2s", (client, message) => {
|
||||
console.log('change_card from ', client.sessionId, message);
|
||||
debugRoom('change_card from ', client.sessionId, message);
|
||||
this.dispatcher.dispatch(new ChangeCardCommand(), {client, cards: message.cards});
|
||||
});
|
||||
this.onMessage("discard_card_c2s", (client, message) => {
|
||||
console.log('discard_card from ', client.sessionId, message);
|
||||
debugRoom('discard_card from ', client.sessionId, message);
|
||||
this.dispatcher.dispatch(new DiscardCommand(), {client, cards: message.cards});
|
||||
});
|
||||
this.onMessage("eat_card_c2s", (client, message) => {
|
||||
console.log('eat_card from ', client.sessionId, message);
|
||||
debugRoom('eat_card from ', client.sessionId, message);
|
||||
this.dispatcher.dispatch(new EatCardCommand(), {client, cards: message.cards, target: message.target});
|
||||
});
|
||||
|
||||
this.onMessage("give_up_eat_c2s", (client, message) => {
|
||||
console.log('give_up_take from ', client.sessionId, message);
|
||||
debugRoom('give_up_take from ', client.sessionId, message);
|
||||
this.dispatcher.dispatch(new GiveUpCommand(), {client});
|
||||
});
|
||||
|
||||
this.onMessage("select_pet_c2s", (client, message) => {
|
||||
console.log('select_pet from ', client.sessionId, message);
|
||||
debugRoom('select_pet from ', client.sessionId, message);
|
||||
this.dispatcher.dispatch(new SelectPetCommand(), {client, cardId: message.card, playerId: message.player, pos: message.pos, effCards: message.effCards });
|
||||
});
|
||||
|
||||
this.onMessage("select_hero_c2s", (client, message) => {
|
||||
console.log('select_hero from ', client.sessionId, message);
|
||||
this.dispatcher.dispatch(new SelectHeroCommand(), {client, heroId: message.heroId, battle: this.battleMan});
|
||||
debugRoom('select_hero from ', client.sessionId, message);
|
||||
this.dispatcher.dispatch(new SelectHeroCommand(), {client, heroId: message.heroId});
|
||||
});
|
||||
|
||||
this.onMessage("*", (client, type, message) => {
|
||||
@ -62,15 +63,14 @@ export class GeneralRoom extends Room {
|
||||
// Triggers when any other type of message is sent,
|
||||
// excluding "action", which has its own specific handler defined above.
|
||||
//
|
||||
console.log(client.sessionId, "sent", type, message);
|
||||
debugRoom(client.sessionId, "sent", type, message);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
onJoin (client: Client, options: any) {
|
||||
this.dispatcher.dispatch(new OnJoinCommand(), {
|
||||
client: client,
|
||||
battle: this.battleMan,
|
||||
client: client
|
||||
});
|
||||
this.clientMap.set(client.sessionId, client);
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
import {Client, Room} from "colyseus";
|
||||
import {IMsg} from "../message/IMsg";
|
||||
import {PetInfoMsg} from "../message/PetInfo";
|
||||
import {SkillInfoMsg} from "../message/SkillInfo";
|
||||
|
||||
|
||||
Object.defineProperties(Room.prototype, {
|
||||
@ -49,6 +50,13 @@ Object.defineProperties(Room.prototype, {
|
||||
value: function (datas?: PetInfoMsg, options?: any) {
|
||||
this.broadcast("msg_queue_s2c", datas, options);
|
||||
}
|
||||
},
|
||||
|
||||
bCastSkill: {
|
||||
value: function (data?: SkillInfoMsg) {
|
||||
this.broadcast("cast_skill_s2c", data);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
|
@ -10,10 +10,9 @@ import {BaseConst} from "../../constants/BaseConst";
|
||||
* 玩家成功加入房间
|
||||
*/
|
||||
export class OnJoinCommand extends Command<CardGameState, {
|
||||
client: Client, battle: BattleHandler
|
||||
client: Client
|
||||
}> {
|
||||
|
||||
execute({client, battle}: { client: Client, battle: BattleHandler }) {
|
||||
execute({client} = this.payload) {
|
||||
let team = this.state.players.size / 2 | 0;
|
||||
let player = new Player(0, team);
|
||||
this.state.players.set(client.sessionId, player);
|
||||
|
@ -9,8 +9,8 @@ import {BaseConst} from "../../constants/BaseConst";
|
||||
/**
|
||||
* 选择英雄
|
||||
*/
|
||||
export class SelectHeroCommand extends Command<CardGameState, {client: Client, heroId: number, battle: BattleHandler}> {
|
||||
execute({ client, heroId, battle} = this.payload) {
|
||||
export class SelectHeroCommand extends Command<CardGameState, {client: Client, heroId: number}> {
|
||||
execute({ client, heroId} = this.payload) {
|
||||
let player = this.state.players.get(client.sessionId);
|
||||
const heroMap = global.$cfg.get(BaseConst.HERO);
|
||||
if (!heroMap || !heroMap.has(heroId)) {
|
||||
@ -19,7 +19,7 @@ export class SelectHeroCommand extends Command<CardGameState, {client: Client, h
|
||||
}
|
||||
player.heroId = heroId;
|
||||
player.state = PlayerStateConst.PLAYER_SELECT_HERO;
|
||||
battle.addPlayer(player);
|
||||
this.room.battleMan.addPlayer(player);
|
||||
this.room.bSelectHero({errocode: 0, errmsg: '', player: client.sessionId, heroId: heroId});
|
||||
let readyCount = 0;
|
||||
for (let [sessionId, player] of this.state.players) {
|
||||
|
@ -5,6 +5,7 @@ import {Player} from "../rooms/schema/Player";
|
||||
import {BaseConst} from "../constants/BaseConst";
|
||||
import {SystemCardCfg} from "../cfg/parsers/SystemCardCfg";
|
||||
import {EffectCardCfg} from "../cfg/parsers/EffectCardCfg";
|
||||
import {error} from "../common/Debug";
|
||||
|
||||
let gameUtil = {
|
||||
/**
|
||||
@ -47,7 +48,7 @@ let gameUtil = {
|
||||
total += data[1];
|
||||
tmpArr.push([data[0], total]);
|
||||
}
|
||||
let num = Math.random() * total; //TODO:: fix bug!
|
||||
let num = Math.random() * total;
|
||||
let effid;
|
||||
for (let data of tmpArr) {
|
||||
if (data[1] >= num ) {
|
||||
@ -69,7 +70,7 @@ let gameUtil = {
|
||||
}
|
||||
}
|
||||
if (!effid) {
|
||||
console.warn('生成卡组时, 无法匹配效果卡, 请确认效果卡的最大数量是否等于点数卡总数')
|
||||
error('生成卡组时, 无法匹配效果卡, 请确认效果卡的最大数量是否等于点数卡总数')
|
||||
}
|
||||
return effid;
|
||||
},
|
||||
|
Loading…
x
Reference in New Issue
Block a user