增加填充随从的gm命令
This commit is contained in:
parent
5dbea00035
commit
4b669725e9
1
src/global.d.ts
vendored
1
src/global.d.ts
vendored
@ -288,6 +288,7 @@ declare module 'colyseus' {
|
||||
* @param count
|
||||
* @param player
|
||||
* @param fromplayer
|
||||
* @param options
|
||||
*/
|
||||
generateCard({ player, count, effectId, fromplayer, options }
|
||||
: {
|
||||
|
@ -1,220 +1,277 @@
|
||||
import {Command} from "@colyseus/command";
|
||||
import {CardGameState} from "../schema/CardGameState";
|
||||
import {Client} from "colyseus";
|
||||
import {debugRoom, error} from "../../common/Debug";
|
||||
import {GameResultCommand} from "./GameResultCommand";
|
||||
import {requestUnlockHero} from "../../common/WebApi";
|
||||
import { Command } from '@colyseus/command'
|
||||
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}> {
|
||||
|
||||
async execute({client, message} = this.payload) {
|
||||
let arr = message.split(':');
|
||||
switch (arr[0]) {
|
||||
case 'changeeffect':
|
||||
debugRoom(`receive changeeffect command: ${arr[1]}`);
|
||||
this.changePlayerCards(arr[1]);
|
||||
break;
|
||||
case 'changequeue':
|
||||
this.changeCardQueue(arr[1]);
|
||||
break;
|
||||
case 'draw':
|
||||
this.drawCard(arr[1]);
|
||||
break;
|
||||
case 'herohp':
|
||||
this.updateHeroHp(arr[1]);
|
||||
break;
|
||||
case 'addrobot':
|
||||
this.addRobot(arr[1]);
|
||||
break;
|
||||
case 'addcard':
|
||||
this.addCard(arr[1]);
|
||||
break;
|
||||
case 'setwin':
|
||||
this.setWin(arr[1]);
|
||||
break;
|
||||
case 'changehero':
|
||||
this.changeHero(arr[1]);
|
||||
break;
|
||||
case 'unlockhero':
|
||||
this.unlockHero(client, arr[1]);
|
||||
break;
|
||||
case 'help':
|
||||
this.sendHelp(client, arr[1]);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
sendHelp(client: Client, msg: string) {
|
||||
let str = ''
|
||||
str += '将一个玩家的手牌全变成指定的效果卡: changeeffect:玩家index|效果卡id 例: changeeffect:0|20011 \n';
|
||||
str += '将牌组中的卡全部变成指定的效果卡: changequeue:效果卡id 例: changequeue:20011 \n';
|
||||
str += '抽一定数量的卡, 注意类型和效果id的搭配: draw:玩家index|数量|类型|效果id|点数 例: draw:0|3 or draw:0|1|1|20011|2 \n';
|
||||
str += '更新英雄血量: herohp:玩家index|血量 例: herohp:0|500 \n';
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加服务端机器人
|
||||
* addrobot:1
|
||||
* @param msg
|
||||
*/
|
||||
addRobot(msg:string) {
|
||||
let count = msg ? parseInt(msg) : 1;
|
||||
let count2 = this.room.maxClients - this.room.clientCount;
|
||||
for (let i = 0; i< Math.min(count, count2); i++) {
|
||||
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
|
||||
* changeeffect:0|20011
|
||||
* @param msg
|
||||
*/
|
||||
changePlayerCards(msg: string) {
|
||||
if (msg.indexOf('|') < 0) {
|
||||
error(`错误的GM命令格式: ${msg}`);
|
||||
return;
|
||||
}
|
||||
let arr = msg.split('|');
|
||||
let playerIdx = parseInt(arr[0]);
|
||||
let effectId = parseInt(arr[1]);
|
||||
let player = this.room.getPlayerByIdx(playerIdx);
|
||||
for (let [, card] of player.cards) {
|
||||
card.effect = effectId;
|
||||
}
|
||||
let client = this.room.getClient(player.id);
|
||||
this.room.send(client,'sync_card', {}, {afterNextPatch: true});
|
||||
}
|
||||
/**
|
||||
* 将一个玩家的英雄变成指定的英雄
|
||||
* changehero:玩家index|heroid
|
||||
* changehero:0|30032
|
||||
* @param msg
|
||||
*/
|
||||
changeHero(msg: string) {
|
||||
if (msg.indexOf('|') < 0) {
|
||||
error(`错误的GM命令格式: ${msg}`);
|
||||
return;
|
||||
}
|
||||
let arr = msg.split('|');
|
||||
let playerIdx = parseInt(arr[0]);
|
||||
let heroId = parseInt(arr[1]);
|
||||
let player = this.room.getPlayerByIdx(playerIdx);
|
||||
player.heroId = heroId;
|
||||
this.room.battleMan.updatePlayerHero(player);
|
||||
let client = this.room.getClient(player.id);
|
||||
this.room.send(client,'sync_hero', {playerid: player.id, heroid: heroId}, {afterNextPatch: true});
|
||||
}
|
||||
|
||||
/**
|
||||
* 将牌组中的卡全部变成指定的效果卡
|
||||
* changequeue:效果卡id
|
||||
* changequeue:20011
|
||||
* @param msg
|
||||
*/
|
||||
changeCardQueue(msg: string) {
|
||||
let effectId = parseInt(msg);
|
||||
for (let card of this.state.cardQueue) {
|
||||
card.effect = effectId;
|
||||
}
|
||||
}
|
||||
addCard(msg: string) {
|
||||
if (msg.indexOf('|') < 0) {
|
||||
error(`错误的GM命令格式: ${msg}`);
|
||||
return;
|
||||
}
|
||||
let arr = msg.split('|');
|
||||
let playerIdx = parseInt(arr[0]);
|
||||
let effectId = parseInt(arr[1]);
|
||||
let player = this.room.getPlayerByIdx(playerIdx);
|
||||
let count = parseInt(arr[2]);
|
||||
this.room.generateCard({player: player, count, effectId, fromplayer: player});
|
||||
let client = this.room.getClient(player.id);
|
||||
this.room.send(client,'sync_card', {}, {afterNextPatch: true});
|
||||
}
|
||||
/**
|
||||
* 抽一定数量的卡
|
||||
* draw:玩家index|数量|类型|效果id|点数
|
||||
* draw:0|3
|
||||
* draw:0|3|1|20011|9
|
||||
* @param msg
|
||||
*/
|
||||
drawCard(msg: string) {
|
||||
if (msg.indexOf('|') < 0) {
|
||||
error(`错误的GM命令格式: ${msg}`);
|
||||
return;
|
||||
}
|
||||
let arr = msg.split('|');
|
||||
let playerIdx = parseInt(arr[0]);
|
||||
let player = this.room.getPlayerByIdx(playerIdx);
|
||||
let count = parseInt(arr[1]);
|
||||
let extData;
|
||||
if (arr.length > 2) {
|
||||
extData = {};
|
||||
// @ts-ignore
|
||||
extData.type = parseInt(arr[2]);
|
||||
}
|
||||
if (arr.length > 3) {
|
||||
// @ts-ignore
|
||||
extData.effect = parseInt(arr[3]);
|
||||
}
|
||||
if (arr.length > 4) {
|
||||
// @ts-ignore
|
||||
extData.number = parseInt(arr[4]);
|
||||
}
|
||||
this.room.addCard(player.id, count, 0, 2, null, extData);
|
||||
let client = this.room.getClient(player.id);
|
||||
this.room.send(client,'sync_card', {}, {afterNextPatch: true});
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新英雄血量
|
||||
* @param msg
|
||||
* herohp:玩家index|血量
|
||||
* herohp:0|500
|
||||
*/
|
||||
updateHeroHp(msg: string) {
|
||||
let arr = msg.split('|');
|
||||
let playerIdx = parseInt(arr[0]);
|
||||
let player = this.room.getPlayerByIdx(playerIdx);
|
||||
let count = parseInt(arr[1]);
|
||||
this.room.updateHp(player.id, count);
|
||||
}
|
||||
setWin(msg: string) {
|
||||
let teamId = parseInt(msg);
|
||||
for (let [,player] of this.state.players) {
|
||||
if (player.team != teamId) {
|
||||
player.hp = 0;
|
||||
}
|
||||
}
|
||||
this.room.dispatcher.dispatch(new GameResultCommand());
|
||||
}
|
||||
const reply = function (client: Client, data: any) {
|
||||
client.send('reply', data)
|
||||
}
|
||||
|
||||
export class GMCommand extends Command<CardGameState, { client: Client, message: string }> {
|
||||
|
||||
async execute({ client, message } = this.payload) {
|
||||
let arr = message.split(':')
|
||||
switch (arr[0]) {
|
||||
case 'changeeffect':
|
||||
debugRoom(`receive changeeffect command: ${ arr[1] }`)
|
||||
this.changePlayerCards(client, arr[1])
|
||||
break
|
||||
case 'changequeue':
|
||||
this.changeCardQueue(client, arr[1])
|
||||
break
|
||||
case 'draw':
|
||||
this.drawCard(client, arr[1])
|
||||
break
|
||||
case 'herohp':
|
||||
this.updateHeroHp(client, arr[1])
|
||||
break
|
||||
case 'addrobot':
|
||||
this.addRobot(arr[1])
|
||||
break
|
||||
case 'addcard':
|
||||
this.addCard(client, arr[1])
|
||||
break
|
||||
case 'setwin':
|
||||
this.setWin(client, arr[1])
|
||||
break
|
||||
case 'changehero':
|
||||
this.changeHero(client, arr[1])
|
||||
break
|
||||
case 'unlockhero':
|
||||
this.unlockHero(client, arr[1])
|
||||
break
|
||||
case 'addpet':
|
||||
this.addPet(client, arr[1])
|
||||
break
|
||||
case 'help':
|
||||
this.sendHelp(client, arr[1])
|
||||
break
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
sendHelp(client: Client, msg: string) {
|
||||
let str = ''
|
||||
str += '将一个玩家的手牌全变成指定的效果卡: changeeffect:玩家index|效果卡id 例: changeeffect:0|20011 \n'
|
||||
str += '将牌组中的卡全部变成指定的效果卡: changequeue:效果卡id 例: changequeue:20011 \n'
|
||||
str += '抽一定数量的卡, 注意类型和效果id的搭配: draw:玩家index|数量|类型|效果id|点数 例: draw:0|3 or draw:0|1|1|20011|2 \n'
|
||||
str += '更新英雄血量: herohp:玩家index|血量 例: herohp:0|500 \n'
|
||||
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'
|
||||
str += '给指定玩家填充一个随从: addpet:玩家index|效果卡id|数量 例: addpet:1|22001|1 或 addpet:1 addpet:1|22001\n'
|
||||
this.room.send(client, 'notice_msg', str)
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加服务端机器人
|
||||
* addrobot:1
|
||||
* @param msg
|
||||
*/
|
||||
addRobot(msg: string) {
|
||||
let count = msg ? parseInt(msg) : 1
|
||||
let count2 = this.room.maxClients - this.room.clientCount
|
||||
for (let i = 0; i < Math.min(count, count2); i++) {
|
||||
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 } 成功`)
|
||||
reply(client, `SUCCESS: ${msg}`)
|
||||
} else {
|
||||
error(`解锁英雄 ${ msg } 失败`)
|
||||
reply(client, `解锁英雄 ${ msg } 失败`)
|
||||
}
|
||||
|
||||
})
|
||||
.catch(err => {
|
||||
error(err)
|
||||
reply(client, `解锁英雄 ${ msg } 失败`)
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 将一个玩家的手牌全变成指定的效果卡
|
||||
* changeeffect:玩家index|效果卡id
|
||||
* changeeffect:0|20011
|
||||
* @param client
|
||||
* @param msg
|
||||
*/
|
||||
changePlayerCards(client: Client, msg: string) {
|
||||
if (msg.indexOf('|') < 0) {
|
||||
reply(client, `错误的GM命令格式: ${ msg }, 例: changeeffect:玩家index|效果卡id`)
|
||||
return
|
||||
}
|
||||
let arr = msg.split('|')
|
||||
if (arr.length < 2) {
|
||||
reply(client, `错误的GM命令格式: ${ msg }, 例: changeeffect:玩家index|效果卡id`)
|
||||
return
|
||||
}
|
||||
let playerIdx = parseInt(arr[0])
|
||||
let effectId = parseInt(arr[1])
|
||||
let player = this.room.getPlayerByIdx(playerIdx)
|
||||
for (let [, card] of player.cards) {
|
||||
card.effect = effectId
|
||||
}
|
||||
reply(client, `SUCCESS: ${msg}`)
|
||||
let target = this.room.getClient(player.id)
|
||||
this.room.send(target, 'sync_card', {}, { afterNextPatch: true })
|
||||
}
|
||||
|
||||
/**
|
||||
* 将一个玩家的英雄变成指定的英雄
|
||||
* changehero:玩家index|heroid
|
||||
* changehero:0|30032
|
||||
* @param client
|
||||
* @param msg
|
||||
*/
|
||||
changeHero(client: Client, msg: string) {
|
||||
if (msg.indexOf('|') < 0) {
|
||||
reply(client, `错误的GM命令格式: ${ msg }`)
|
||||
return
|
||||
}
|
||||
let arr = msg.split('|')
|
||||
let playerIdx = parseInt(arr[0])
|
||||
let heroId = parseInt(arr[1])
|
||||
let player = this.room.getPlayerByIdx(playerIdx)
|
||||
player.heroId = heroId
|
||||
this.room.battleMan.updatePlayerHero(player)
|
||||
let target = this.room.getClient(player.id)
|
||||
reply(client, `SUCCESS: ${msg}`)
|
||||
this.room.send(target, 'sync_hero', {
|
||||
playerid: player.id,
|
||||
heroid: heroId
|
||||
}, { afterNextPatch: true })
|
||||
}
|
||||
|
||||
/**
|
||||
* 将牌组中的卡全部变成指定的效果卡
|
||||
* changequeue:效果卡id
|
||||
* changequeue:20011
|
||||
* @param client
|
||||
* @param msg
|
||||
*/
|
||||
changeCardQueue(client: Client, msg: string) {
|
||||
let effectId = parseInt(msg)
|
||||
for (let card of this.state.cardQueue) {
|
||||
card.effect = effectId
|
||||
}
|
||||
reply(client, `SUCCESS: ${msg}`)
|
||||
}
|
||||
|
||||
addCard(client: Client, msg: string) {
|
||||
if (msg.indexOf('|') < 0) {
|
||||
error(`错误的GM命令格式: ${ msg }`)
|
||||
return
|
||||
}
|
||||
let arr = msg.split('|')
|
||||
let playerIdx = parseInt(arr[0])
|
||||
let effectId = parseInt(arr[1])
|
||||
let player = this.room.getPlayerByIdx(playerIdx)
|
||||
let count = parseInt(arr[2])
|
||||
this.room.generateCard({
|
||||
player: player,
|
||||
count,
|
||||
effectId,
|
||||
fromplayer: player
|
||||
})
|
||||
reply(client, `SUCCESS: ${msg}`)
|
||||
let target = this.room.getClient(player.id)
|
||||
this.room.send(target, 'sync_card', {}, { afterNextPatch: true })
|
||||
}
|
||||
|
||||
/**
|
||||
* 抽一定数量的卡
|
||||
* draw:玩家index|数量|类型|效果id|点数
|
||||
* draw:0|3
|
||||
* draw:0|3|1|20011|9
|
||||
* @param msg
|
||||
*/
|
||||
drawCard(client: Client, msg: string) {
|
||||
if (msg.indexOf('|') < 0) {
|
||||
error(`错误的GM命令格式: ${ msg }`)
|
||||
return
|
||||
}
|
||||
let arr = msg.split('|')
|
||||
let playerIdx = parseInt(arr[0])
|
||||
let player = this.room.getPlayerByIdx(playerIdx)
|
||||
let count = parseInt(arr[1])
|
||||
let extData
|
||||
if (arr.length > 2) {
|
||||
extData = {}
|
||||
// @ts-ignore
|
||||
extData.type = parseInt(arr[2])
|
||||
}
|
||||
if (arr.length > 3) {
|
||||
// @ts-ignore
|
||||
extData.effect = parseInt(arr[3])
|
||||
}
|
||||
if (arr.length > 4) {
|
||||
// @ts-ignore
|
||||
extData.number = parseInt(arr[4])
|
||||
}
|
||||
this.room.addCard(player.id, count, 0, 2, null, extData)
|
||||
let target = this.room.getClient(player.id)
|
||||
reply(client, `SUCCESS: ${msg}`)
|
||||
this.room.send(target, 'sync_card', {}, { afterNextPatch: true })
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新英雄血量
|
||||
* @param msg
|
||||
* herohp:玩家index|血量
|
||||
* herohp:0|500
|
||||
*/
|
||||
updateHeroHp(client: Client, msg: string) {
|
||||
let arr = msg.split('|')
|
||||
let playerIdx = parseInt(arr[0])
|
||||
let player = this.room.getPlayerByIdx(playerIdx)
|
||||
let count = parseInt(arr[1])
|
||||
reply(client, `SUCCESS: ${msg}`)
|
||||
this.room.updateHp(player.id, count)
|
||||
}
|
||||
|
||||
setWin(client: Client, msg: string) {
|
||||
let teamId = parseInt(msg)
|
||||
for (let [, player] of this.state.players) {
|
||||
if (player.team != teamId) {
|
||||
player.hp = 0
|
||||
}
|
||||
}
|
||||
reply(client, `SUCCESS: ${msg}`)
|
||||
this.room.dispatcher.dispatch(new GameResultCommand())
|
||||
}
|
||||
|
||||
/**
|
||||
* 给指定玩家添加一个随从
|
||||
* @param client
|
||||
* @param {string} msg
|
||||
* addpet:玩家index|随从对应的效果卡id
|
||||
* addpet:1|22001
|
||||
*/
|
||||
addPet(client: Client, msg: string) {
|
||||
let arr = msg.split('|')
|
||||
let playerIdx = parseInt(arr[0])
|
||||
let player = this.room.getPlayerByIdx(playerIdx)
|
||||
let effectid = arr.length > 1 ? parseInt(arr[1]) : 22001
|
||||
let count = arr.length > 2 ? parseInt(arr[2]) : 1
|
||||
for (let i = 0; i < count; i++) {
|
||||
this.room.battleMan.addPet(player, effectid)
|
||||
}
|
||||
reply(client, `SUCCESS: ${msg}`)
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user