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/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/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 2dde1f0..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} = this.payload) { +export class SelectHeroCommand extends Command { + 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