From f70c63f8ec5090c66fc03fd250c51d4066200fae Mon Sep 17 00:00:00 2001 From: zhl Date: Wed, 13 Jan 2021 15:36:20 +0800 Subject: [PATCH] =?UTF-8?q?=E7=8E=A9=E5=AE=B6=E9=80=89=E6=8B=A9=E8=8B=B1?= =?UTF-8?q?=E9=9B=84=E5=90=8E,=20=E6=A0=B9=E6=8D=AE=E5=AE=9E=E9=99=85?= =?UTF-8?q?=E7=9A=84=E5=8D=A1=E7=BB=84id=E8=8E=B7=E5=8F=96=E7=9C=9F?= =?UTF-8?q?=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