From 20ff488eccdf7d68e70923b1c9af89fd912a2410 Mon Sep 17 00:00:00 2001 From: zhl Date: Wed, 13 Jan 2021 14:03:44 +0800 Subject: [PATCH 1/2] =?UTF-8?q?select=20hero=E5=91=BD=E4=BB=A4=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E5=8D=A1=E7=BB=84id?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/rooms/GeneralRoom.ts | 2 +- src/rooms/commands/SelectHeroCommand.ts | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/rooms/GeneralRoom.ts b/src/rooms/GeneralRoom.ts index cc953f5..cabfbc1 100644 --- a/src/rooms/GeneralRoom.ts +++ b/src/rooms/GeneralRoom.ts @@ -74,7 +74,7 @@ export class GeneralRoom extends Room { this.onMessage("select_hero_c2s", (client, message) => { msgLog('select_hero from ', client.sessionId, JSON.stringify(message)); - this.dispatcher.dispatch(new SelectHeroCommand(), {client, heroId: message.heroId}); + this.dispatcher.dispatch(new SelectHeroCommand(), {client, heroId: message.heroId, cardGroup: message.cardgroup}); }); this.onMessage("gm", (client, message) => { diff --git a/src/rooms/commands/SelectHeroCommand.ts b/src/rooms/commands/SelectHeroCommand.ts index 2dde1f0..f30da47 100644 --- a/src/rooms/commands/SelectHeroCommand.ts +++ b/src/rooms/commands/SelectHeroCommand.ts @@ -11,8 +11,8 @@ import {StateTypeEnum} from "../enums/StateTypeEnum"; /** * 选择英雄 */ -export class SelectHeroCommand extends Command { - execute({client, heroId} = this.payload) { +export class SelectHeroCommand extends Command { + execute({client, heroId, cardGroup} = this.payload) { let player = this.state.players.get(client.sessionId); if (player.state != PlayerStateConst.PLAYER_READY) { return; @@ -48,6 +48,7 @@ export class SelectHeroCommand extends Command Date: Wed, 13 Jan 2021 15:36:20 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E7=8E=A9=E5=AE=B6=E9=80=89=E6=8B=A9?= =?UTF-8?q?=E8=8B=B1=E9=9B=84=E5=90=8E,=20=E6=A0=B9=E6=8D=AE=E5=AE=9E?= =?UTF-8?q?=E9=99=85=E7=9A=84=E5=8D=A1=E7=BB=84id=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E7=9C=9F=E5=AE=9E=E7=9A=84=E5=8D=A1=E7=BB=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/config.json | 2 +- src/common/WebApi.ts | 25 ++++++++++++++++++ src/rooms/commands/GameResultCommand.ts | 2 +- src/rooms/commands/SelectHeroCommand.ts | 35 +++++++++++++++++++------ 4 files changed, 54 insertions(+), 10 deletions(-) create mode 100644 src/common/WebApi.ts diff --git a/config/config.json b/config/config.json index 25c589a..8e21ddb 100644 --- a/config/config.json +++ b/config/config.json @@ -1,5 +1,5 @@ { "redis": "redis://127.0.0.1:6379/15", "mongodb": "mongodb://127.0.0.1/card-development", - "info_svr": "http://127.0.0.1:2987/api/record/save" + "info_svr": "http://127.0.0.1:2987/api" } diff --git a/src/common/WebApi.ts b/src/common/WebApi.ts new file mode 100644 index 0000000..f6b1d48 --- /dev/null +++ b/src/common/WebApi.ts @@ -0,0 +1,25 @@ +import axios from "axios"; +import {Config} from "../cfg/Config"; + +let config: Config = require('../../config/config.json'); + +/** + * 获取卡组详情 + * @param {string} accountid + * @param {number} heroid + * @param {string} cardgroup + * @return {Promise>} + */ +export function getCardGroup(accountid: string, heroid: number, cardgroup: string) { + return axios.get(`${config.info_svr}/${accountid}/group_info/${heroid}/${cardgroup}`, ) + .then(function (response) { + let res = response.data; + if (res.errcode) { + throw new Error(res.errmsg); + } else { + return res.data; + } + }) +} + + diff --git a/src/rooms/commands/GameResultCommand.ts b/src/rooms/commands/GameResultCommand.ts index 82096ba..7a449dc 100644 --- a/src/rooms/commands/GameResultCommand.ts +++ b/src/rooms/commands/GameResultCommand.ts @@ -211,7 +211,7 @@ export class GameResultCommand extends Command { let reqConfig = { method: 'post', - url: config.info_svr, + url: `${config.info_svr}/record/save`, headers: { 'Content-Type': 'application/json', }, diff --git a/src/rooms/commands/SelectHeroCommand.ts b/src/rooms/commands/SelectHeroCommand.ts index f30da47..9ee3c21 100644 --- a/src/rooms/commands/SelectHeroCommand.ts +++ b/src/rooms/commands/SelectHeroCommand.ts @@ -7,12 +7,14 @@ import {BaseConst} from "../../constants/BaseConst"; import {error} from "../../common/Debug"; import {GameEnv} from "../../cfg/GameEnv"; import {StateTypeEnum} from "../enums/StateTypeEnum"; +import {raw} from "express"; +import {getCardGroup} from "../../common/WebApi"; /** * 选择英雄 */ export class SelectHeroCommand extends Command { - execute({client, heroId, cardGroup} = this.payload) { + async execute({client, heroId, cardGroup} = this.payload) { let player = this.state.players.get(client.sessionId); if (player.state != PlayerStateConst.PLAYER_READY) { return; @@ -29,6 +31,9 @@ export class SelectHeroCommand extends Command