Merge branch 'second' of http://git.kingsome.cn/node/card_svr into second

This commit is contained in:
yuexin 2021-01-13 15:38:55 +08:00
commit 4b0b8850fd
5 changed files with 56 additions and 11 deletions

View File

@ -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
View 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;
}
})
}

View File

@ -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) => {

View File

@ -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',
},

View File

@ -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 }> {
execute({client, heroId} = this.payload) {
export class SelectHeroCommand extends Command<CardGameState, { client: Client, heroId: number, cardGroup?: string }> {
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,12 +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);
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) {
@ -69,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) {