玩家选择英雄后, 根据实际的卡组id获取真实的卡组
This commit is contained in:
parent
c17e5556cc
commit
f70c63f8ec
@ -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"
|
||||
}
|
||||
|
25
src/common/WebApi.ts
Normal file
25
src/common/WebApi.ts
Normal file
@ -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<AxiosResponse<any>>}
|
||||
*/
|
||||
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;
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -211,7 +211,7 @@ export class GameResultCommand extends Command<CardGameState, {}> {
|
||||
|
||||
let reqConfig = {
|
||||
method: 'post',
|
||||
url: config.info_svr,
|
||||
url: `${config.info_svr}/record/save`,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
|
@ -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<CardGameState, { client: Client, heroId: number, cardGroup?: string }> {
|
||||
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<CardGameState, { client: Client,
|
||||
if (!unitData) {
|
||||
error(`未找到英雄的Unit配置: ${heroId}`);
|
||||
}
|
||||
/**
|
||||
* 初始化统计数据的值
|
||||
*/
|
||||
for (let key in StateTypeEnum) {
|
||||
if (!isNaN(Number(key))) {
|
||||
// @ts-ignore
|
||||
@ -48,13 +53,27 @@ export class SelectHeroCommand extends Command<CardGameState, { client: Client,
|
||||
if (unitData.base_skill2id) heroPet.skills.push(unitData.base_skill2id);
|
||||
if (unitData.base_skill3id) heroPet.skills.push(unitData.base_skill3id);
|
||||
const effectMap = global.$cfg.get(BaseConst.EFFECTCARD);
|
||||
// TODO: // 根据传入的卡组id去设置英雄可用的unit
|
||||
for (let i = 1; i < 10; i++) {
|
||||
if (!heroData[`follower${i}id`]) {
|
||||
break;
|
||||
// 根据传入的卡组id去设置英雄可用的unit
|
||||
let units: number[] = [];
|
||||
if (cardGroup) {
|
||||
try {
|
||||
let data = await getCardGroup(player.accountId, heroId, cardGroup);
|
||||
for (let unit of data.cards) {
|
||||
units.push(unit.cardid);
|
||||
}
|
||||
} catch(err) {
|
||||
error(`error get cardgroup`)
|
||||
}
|
||||
let unitId = heroData[`follower${i}id`];
|
||||
|
||||
}
|
||||
if (units.length == 0) {
|
||||
for (let i = 1; i < 10; i++) {
|
||||
if (!heroData[`follower${i}id`]) {
|
||||
break;
|
||||
}
|
||||
units.push(heroData[`follower${i}id`]);
|
||||
}
|
||||
}
|
||||
for (let unitId of units) {
|
||||
let weight = 0;
|
||||
let effectId;
|
||||
for (let [,eff] of effectMap) {
|
||||
@ -70,7 +89,7 @@ export class SelectHeroCommand extends Command<CardGameState, { client: Client,
|
||||
player.unitCfgs.set(effectId+'', weight);
|
||||
}
|
||||
this.room.battleMan.updatePlayer(player.id, player);
|
||||
this.room.bSelectHero({errocode: 0, errmsg: '', player: client.sessionId, heroId: heroId});
|
||||
this.room.bSelectHero({errocode: 0, errmsg: '', player: client.sessionId, heroId: heroId, cards: units});
|
||||
let readyCount = 0;
|
||||
for (let [, player] of this.state.players) {
|
||||
if (player.state === PlayerStateConst.PLAYER_SELECT_HERO) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user