增加解锁英雄的gm命令

This commit is contained in:
zhl 2021-01-13 20:26:10 +08:00
parent 97f1760958
commit 7e4918e78f
5 changed files with 40 additions and 2 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"
"info_svr": "http://127.0.0.1:2987/svr"
}

View File

@ -22,4 +22,15 @@ export function getCardGroup(accountid: string, heroid: number, cardgroup: strin
})
}
/**
*
* @param {string} accountid
* @param {number | string} heroid
* @return {Promise<AxiosResponse<any>>}
*/
export function requestUnlockHero(accountid: string, heroid: number | string) {
let data = {"type": 0};
return axios.post(`${config.info_svr}/${accountid}/hero/unlock/${heroid}`, data);
}

View File

@ -28,7 +28,6 @@ initData();
const server = http.createServer(app);
const gameServer = new Server({
server,
// driver: new MongooseDriver('mongodb://127.0.0.1/card-development'),
// driver: new MongooseDriver(config.mongodb),
// presence: new RedisPresence({url: config.redis}),
});

View File

@ -41,6 +41,7 @@ export class GeneralRoom extends Room {
}
onCreate (options: any) {
let cs = new CardGameState();
this.setMetadata({rank: 2});
this.setState(cs);
this.battleMan.init(cs, this);
this.clock.start();

View File

@ -3,6 +3,7 @@ import {CardGameState} from "../schema/CardGameState";
import {Client} from "colyseus";
import {debugRoom, error} from "../../common/Debug";
import {GameResultCommand} from "./GameResultCommand";
import {requestUnlockHero} from "../../common/WebApi";
export class GMCommand extends Command<CardGameState, {client: Client, message: string}> {
@ -35,6 +36,9 @@ export class GMCommand extends Command<CardGameState, {client: Client, message:
case 'changehero':
this.changeHero(arr[1]);
break;
case 'unlockhero':
this.unlockHero(client, arr[1]);
break;
case 'help':
this.sendHelp(client, arr[1]);
break;
@ -54,6 +58,7 @@ export class GMCommand extends Command<CardGameState, {client: Client, message:
str += '生成几张特定效果的卡: addcard:玩家index|效果卡id|数量 例: addcard:0|20011|1\n';
str += '将某一队设为赢家: setwin:队伍index 例: setwin:0\n';
str += '替换一个玩家的英雄: changehero:玩家index|heroid 例: changehero:3|30032\n';
str += '解锁一个英雄: unlockhero:heroid 例: unlockhero:30142\n';
this.room.send(client,'notice_msg', str);
}
@ -69,6 +74,28 @@ export class GMCommand extends Command<CardGameState, {client: Client, message:
this.room.addRobot();
}
}
/**
*
* @param client
* @param {string} msg
*/
unlockHero(client: Client, msg: string) {
let heroId = msg;
let player = this.room.state.players.get(client.id);
requestUnlockHero(player.accountId, heroId)
.then((res) => {
if (res.data.errcode == 0) {
debugRoom(`解锁英雄 ${msg} 成功`);
} else {
error(`解锁英雄 ${msg} 失败`);
}
})
.catch(err=> {
error(err);
})
}
/**
*
* changeeffect:玩家index|id