增加填充随从的gm命令

This commit is contained in:
zhl 2021-03-17 12:14:38 +08:00
parent 5dbea00035
commit 4b669725e9
2 changed files with 276 additions and 218 deletions

1
src/global.d.ts vendored
View File

@ -288,6 +288,7 @@ declare module 'colyseus' {
* @param count * @param count
* @param player * @param player
* @param fromplayer * @param fromplayer
* @param options
*/ */
generateCard({ player, count, effectId, fromplayer, options } generateCard({ player, count, effectId, fromplayer, options }
: { : {

View File

@ -1,61 +1,69 @@
import {Command} from "@colyseus/command"; import { Command } from '@colyseus/command'
import {CardGameState} from "../schema/CardGameState"; import { CardGameState } from '../schema/CardGameState'
import {Client} from "colyseus"; import { Client } from 'colyseus'
import {debugRoom, error} from "../../common/Debug"; import { debugRoom, error } from '../../common/Debug'
import {GameResultCommand} from "./GameResultCommand"; import { GameResultCommand } from './GameResultCommand'
import {requestUnlockHero} from "../../common/WebApi"; import { requestUnlockHero } from '../../common/WebApi'
const reply = function (client: Client, data: any) {
client.send('reply', data)
}
export class GMCommand extends Command<CardGameState, {client: Client, message: string}> { export class GMCommand extends Command<CardGameState, { client: Client, message: string }> {
async execute({client, message} = this.payload) { async execute({ client, message } = this.payload) {
let arr = message.split(':'); let arr = message.split(':')
switch (arr[0]) { switch (arr[0]) {
case 'changeeffect': case 'changeeffect':
debugRoom(`receive changeeffect command: ${arr[1]}`); debugRoom(`receive changeeffect command: ${ arr[1] }`)
this.changePlayerCards(arr[1]); this.changePlayerCards(client, arr[1])
break; break
case 'changequeue': case 'changequeue':
this.changeCardQueue(arr[1]); this.changeCardQueue(client, arr[1])
break; break
case 'draw': case 'draw':
this.drawCard(arr[1]); this.drawCard(client, arr[1])
break; break
case 'herohp': case 'herohp':
this.updateHeroHp(arr[1]); this.updateHeroHp(client, arr[1])
break; break
case 'addrobot': case 'addrobot':
this.addRobot(arr[1]); this.addRobot(arr[1])
break; break
case 'addcard': case 'addcard':
this.addCard(arr[1]); this.addCard(client, arr[1])
break; break
case 'setwin': case 'setwin':
this.setWin(arr[1]); this.setWin(client, arr[1])
break; break
case 'changehero': case 'changehero':
this.changeHero(arr[1]); this.changeHero(client, arr[1])
break; break
case 'unlockhero': case 'unlockhero':
this.unlockHero(client, arr[1]); this.unlockHero(client, arr[1])
break; break
case 'addpet':
this.addPet(client, arr[1])
break
case 'help': case 'help':
this.sendHelp(client, arr[1]); this.sendHelp(client, arr[1])
break; break
} }
} }
sendHelp(client: Client, msg: string) { sendHelp(client: Client, msg: string) {
let str = '' let str = ''
str += '将一个玩家的手牌全变成指定的效果卡: changeeffect:玩家index|效果卡id 例: changeeffect:0|20011 \n'; str += '将一个玩家的手牌全变成指定的效果卡: changeeffect:玩家index|效果卡id 例: changeeffect:0|20011 \n'
str += '将牌组中的卡全部变成指定的效果卡: changequeue:效果卡id 例: changequeue: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 += '抽一定数量的卡, 注意类型和效果id的搭配: draw:玩家index|数量|类型|效果id|点数 例: draw:0|3 or draw:0|1|1|20011|2 \n'
str += '更新英雄血量: herohp:玩家index|血量 例: herohp:0|500 \n'; str += '更新英雄血量: herohp:玩家index|血量 例: herohp:0|500 \n'
str += '生成几张特定效果的卡: addcard:玩家index|效果卡id|数量 例: addcard:0|20011|1\n'; str += '生成几张特定效果的卡: addcard:玩家index|效果卡id|数量 例: addcard:0|20011|1\n'
str += '将某一队设为赢家: setwin:队伍index 例: setwin:0\n'; str += '将某一队设为赢家: setwin:队伍index 例: setwin:0\n'
str += '替换一个玩家的英雄: changehero:玩家index|heroid 例: changehero:3|30032\n'; str += '替换一个玩家的英雄: changehero:玩家index|heroid 例: changehero:3|30032\n'
str += '解锁一个英雄: unlockhero:heroid 例: unlockhero:30142\n'; str += '解锁一个英雄: unlockhero:heroid 例: unlockhero:30142\n'
this.room.send(client,'notice_msg', str); str += '给指定玩家填充一个随从: addpet:玩家index|效果卡id|数量 例: addpet:1|22001|1 或 addpet:1 addpet:1|22001\n'
this.room.send(client, 'notice_msg', str)
} }
/** /**
@ -63,11 +71,11 @@ export class GMCommand extends Command<CardGameState, {client: Client, message:
* addrobot:1 * addrobot:1
* @param msg * @param msg
*/ */
addRobot(msg:string) { addRobot(msg: string) {
let count = msg ? parseInt(msg) : 1; let count = msg ? parseInt(msg) : 1
let count2 = this.room.maxClients - this.room.clientCount; let count2 = this.room.maxClients - this.room.clientCount
for (let i = 0; i< Math.min(count, count2); i++) { for (let i = 0; i < Math.min(count, count2); i++) {
this.room.addRobot(); this.room.addRobot()
} }
} }
@ -77,89 +85,115 @@ export class GMCommand extends Command<CardGameState, {client: Client, message:
* @param {string} msg * @param {string} msg
*/ */
unlockHero(client: Client, msg: string) { unlockHero(client: Client, msg: string) {
let heroId = msg; let heroId = msg
let player = this.room.state.players.get(client.id); let player = this.room.state.players.get(client.id)
requestUnlockHero(player.accountId, heroId) requestUnlockHero(player.accountId, heroId)
.then((res) => { .then((res) => {
if (res.data.errcode == 0) { if (res.data.errcode == 0) {
debugRoom(`解锁英雄 ${msg} 成功`); debugRoom(`解锁英雄 ${ msg } 成功`)
reply(client, `SUCCESS: ${msg}`)
} else { } else {
error(`解锁英雄 ${msg} 失败`); error(`解锁英雄 ${ msg } 失败`)
reply(client, `解锁英雄 ${ msg } 失败`)
} }
}) })
.catch(err=> { .catch(err => {
error(err); error(err)
reply(client, `解锁英雄 ${ msg } 失败`)
}) })
} }
/** /**
* *
* changeeffect:玩家index|id * changeeffect:玩家index|id
* changeeffect:0|20011 * changeeffect:0|20011
* @param client
* @param msg * @param msg
*/ */
changePlayerCards(msg: string) { changePlayerCards(client: Client, msg: string) {
if (msg.indexOf('|') < 0) { if (msg.indexOf('|') < 0) {
error(`错误的GM命令格式: ${msg}`); reply(client, `错误的GM命令格式: ${ msg }, 例: changeeffect:玩家index|效果卡id`)
return; return
} }
let arr = msg.split('|'); let arr = msg.split('|')
let playerIdx = parseInt(arr[0]); if (arr.length < 2) {
let effectId = parseInt(arr[1]); reply(client, `错误的GM命令格式: ${ msg }, 例: changeeffect:玩家index|效果卡id`)
let player = this.room.getPlayerByIdx(playerIdx); return
}
let playerIdx = parseInt(arr[0])
let effectId = parseInt(arr[1])
let player = this.room.getPlayerByIdx(playerIdx)
for (let [, card] of player.cards) { for (let [, card] of player.cards) {
card.effect = effectId; card.effect = effectId
} }
let client = this.room.getClient(player.id); reply(client, `SUCCESS: ${msg}`)
this.room.send(client,'sync_card', {}, {afterNextPatch: true}); let target = this.room.getClient(player.id)
this.room.send(target, 'sync_card', {}, { afterNextPatch: true })
} }
/** /**
* *
* changehero:玩家index|heroid * changehero:玩家index|heroid
* changehero:0|30032 * changehero:0|30032
* @param client
* @param msg * @param msg
*/ */
changeHero(msg: string) { changeHero(client: Client, msg: string) {
if (msg.indexOf('|') < 0) { if (msg.indexOf('|') < 0) {
error(`错误的GM命令格式: ${msg}`); reply(client, `错误的GM命令格式: ${ msg }`)
return; return
} }
let arr = msg.split('|'); let arr = msg.split('|')
let playerIdx = parseInt(arr[0]); let playerIdx = parseInt(arr[0])
let heroId = parseInt(arr[1]); let heroId = parseInt(arr[1])
let player = this.room.getPlayerByIdx(playerIdx); let player = this.room.getPlayerByIdx(playerIdx)
player.heroId = heroId; player.heroId = heroId
this.room.battleMan.updatePlayerHero(player); this.room.battleMan.updatePlayerHero(player)
let client = this.room.getClient(player.id); let target = this.room.getClient(player.id)
this.room.send(client,'sync_hero', {playerid: player.id, heroid: heroId}, {afterNextPatch: true}); reply(client, `SUCCESS: ${msg}`)
this.room.send(target, 'sync_hero', {
playerid: player.id,
heroid: heroId
}, { afterNextPatch: true })
} }
/** /**
* *
* changequeue:效果卡id * changequeue:效果卡id
* changequeue:20011 * changequeue:20011
* @param client
* @param msg * @param msg
*/ */
changeCardQueue(msg: string) { changeCardQueue(client: Client, msg: string) {
let effectId = parseInt(msg); let effectId = parseInt(msg)
for (let card of this.state.cardQueue) { for (let card of this.state.cardQueue) {
card.effect = effectId; card.effect = effectId
} }
reply(client, `SUCCESS: ${msg}`)
} }
addCard(msg: string) {
addCard(client: Client, msg: string) {
if (msg.indexOf('|') < 0) { if (msg.indexOf('|') < 0) {
error(`错误的GM命令格式: ${msg}`); error(`错误的GM命令格式: ${ msg }`)
return; return
} }
let arr = msg.split('|'); let arr = msg.split('|')
let playerIdx = parseInt(arr[0]); let playerIdx = parseInt(arr[0])
let effectId = parseInt(arr[1]); let effectId = parseInt(arr[1])
let player = this.room.getPlayerByIdx(playerIdx); let player = this.room.getPlayerByIdx(playerIdx)
let count = parseInt(arr[2]); let count = parseInt(arr[2])
this.room.generateCard({player: player, count, effectId, fromplayer: player}); this.room.generateCard({
let client = this.room.getClient(player.id); player: player,
this.room.send(client,'sync_card', {}, {afterNextPatch: true}); 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:玩家index|||id|
@ -167,32 +201,33 @@ export class GMCommand extends Command<CardGameState, {client: Client, message:
* draw:0|3|1|20011|9 * draw:0|3|1|20011|9
* @param msg * @param msg
*/ */
drawCard(msg: string) { drawCard(client: Client, msg: string) {
if (msg.indexOf('|') < 0) { if (msg.indexOf('|') < 0) {
error(`错误的GM命令格式: ${msg}`); error(`错误的GM命令格式: ${ msg }`)
return; return
} }
let arr = msg.split('|'); let arr = msg.split('|')
let playerIdx = parseInt(arr[0]); let playerIdx = parseInt(arr[0])
let player = this.room.getPlayerByIdx(playerIdx); let player = this.room.getPlayerByIdx(playerIdx)
let count = parseInt(arr[1]); let count = parseInt(arr[1])
let extData; let extData
if (arr.length > 2) { if (arr.length > 2) {
extData = {}; extData = {}
// @ts-ignore // @ts-ignore
extData.type = parseInt(arr[2]); extData.type = parseInt(arr[2])
} }
if (arr.length > 3) { if (arr.length > 3) {
// @ts-ignore // @ts-ignore
extData.effect = parseInt(arr[3]); extData.effect = parseInt(arr[3])
} }
if (arr.length > 4) { if (arr.length > 4) {
// @ts-ignore // @ts-ignore
extData.number = parseInt(arr[4]); extData.number = parseInt(arr[4])
} }
this.room.addCard(player.id, count, 0, 2, null, extData); this.room.addCard(player.id, count, 0, 2, null, extData)
let client = this.room.getClient(player.id); let target = this.room.getClient(player.id)
this.room.send(client,'sync_card', {}, {afterNextPatch: true}); reply(client, `SUCCESS: ${msg}`)
this.room.send(target, 'sync_card', {}, { afterNextPatch: true })
} }
/** /**
@ -201,20 +236,42 @@ export class GMCommand extends Command<CardGameState, {client: Client, message:
* herohp:玩家index| * herohp:玩家index|
* herohp:0|500 * herohp:0|500
*/ */
updateHeroHp(msg: string) { updateHeroHp(client: Client, msg: string) {
let arr = msg.split('|'); let arr = msg.split('|')
let playerIdx = parseInt(arr[0]); let playerIdx = parseInt(arr[0])
let player = this.room.getPlayerByIdx(playerIdx); let player = this.room.getPlayerByIdx(playerIdx)
let count = parseInt(arr[1]); let count = parseInt(arr[1])
this.room.updateHp(player.id, count); reply(client, `SUCCESS: ${msg}`)
this.room.updateHp(player.id, count)
} }
setWin(msg: string) {
let teamId = parseInt(msg); setWin(client: Client, msg: string) {
for (let [,player] of this.state.players) { let teamId = parseInt(msg)
for (let [, player] of this.state.players) {
if (player.team != teamId) { if (player.team != teamId) {
player.hp = 0; player.hp = 0
} }
} }
this.room.dispatcher.dispatch(new GameResultCommand()); 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}`)
} }
} }