增加填充随从的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 count
|
||||||
* @param player
|
* @param player
|
||||||
* @param fromplayer
|
* @param fromplayer
|
||||||
|
* @param options
|
||||||
*/
|
*/
|
||||||
generateCard({ player, count, effectId, fromplayer, options }
|
generateCard({ player, count, effectId, fromplayer, options }
|
||||||
: {
|
: {
|
||||||
|
@ -1,220 +1,277 @@
|
|||||||
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) {
|
||||||
export class GMCommand extends Command<CardGameState, {client: Client, message: string}> {
|
client.send('reply', data)
|
||||||
|
}
|
||||||
async execute({client, message} = this.payload) {
|
|
||||||
let arr = message.split(':');
|
export class GMCommand extends Command<CardGameState, { client: Client, message: string }> {
|
||||||
switch (arr[0]) {
|
|
||||||
case 'changeeffect':
|
async execute({ client, message } = this.payload) {
|
||||||
debugRoom(`receive changeeffect command: ${arr[1]}`);
|
let arr = message.split(':')
|
||||||
this.changePlayerCards(arr[1]);
|
switch (arr[0]) {
|
||||||
break;
|
case 'changeeffect':
|
||||||
case 'changequeue':
|
debugRoom(`receive changeeffect command: ${ arr[1] }`)
|
||||||
this.changeCardQueue(arr[1]);
|
this.changePlayerCards(client, arr[1])
|
||||||
break;
|
break
|
||||||
case 'draw':
|
case 'changequeue':
|
||||||
this.drawCard(arr[1]);
|
this.changeCardQueue(client, arr[1])
|
||||||
break;
|
break
|
||||||
case 'herohp':
|
case 'draw':
|
||||||
this.updateHeroHp(arr[1]);
|
this.drawCard(client, arr[1])
|
||||||
break;
|
break
|
||||||
case 'addrobot':
|
case 'herohp':
|
||||||
this.addRobot(arr[1]);
|
this.updateHeroHp(client, arr[1])
|
||||||
break;
|
break
|
||||||
case 'addcard':
|
case 'addrobot':
|
||||||
this.addCard(arr[1]);
|
this.addRobot(arr[1])
|
||||||
break;
|
break
|
||||||
case 'setwin':
|
case 'addcard':
|
||||||
this.setWin(arr[1]);
|
this.addCard(client, arr[1])
|
||||||
break;
|
break
|
||||||
case 'changehero':
|
case 'setwin':
|
||||||
this.changeHero(arr[1]);
|
this.setWin(client, arr[1])
|
||||||
break;
|
break
|
||||||
case 'unlockhero':
|
case 'changehero':
|
||||||
this.unlockHero(client, arr[1]);
|
this.changeHero(client, arr[1])
|
||||||
break;
|
break
|
||||||
case 'help':
|
case 'unlockhero':
|
||||||
this.sendHelp(client, arr[1]);
|
this.unlockHero(client, arr[1])
|
||||||
break;
|
break
|
||||||
}
|
case 'addpet':
|
||||||
|
this.addPet(client, arr[1])
|
||||||
}
|
break
|
||||||
sendHelp(client: Client, msg: string) {
|
case 'help':
|
||||||
let str = ''
|
this.sendHelp(client, arr[1])
|
||||||
str += '将一个玩家的手牌全变成指定的效果卡: changeeffect:玩家index|效果卡id 例: changeeffect:0|20011 \n';
|
break
|
||||||
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';
|
sendHelp(client: Client, msg: string) {
|
||||||
str += '替换一个玩家的英雄: changehero:玩家index|heroid 例: changehero:3|30032\n';
|
let str = ''
|
||||||
str += '解锁一个英雄: unlockhero:heroid 例: unlockhero:30142\n';
|
str += '将一个玩家的手牌全变成指定的效果卡: changeeffect:玩家index|效果卡id 例: changeeffect:0|20011 \n'
|
||||||
this.room.send(client,'notice_msg', str);
|
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'
|
||||||
* addrobot:1
|
str += '替换一个玩家的英雄: changehero:玩家index|heroid 例: changehero:3|30032\n'
|
||||||
* @param msg
|
str += '解锁一个英雄: unlockhero:heroid 例: unlockhero:30142\n'
|
||||||
*/
|
str += '给指定玩家填充一个随从: addpet:玩家index|效果卡id|数量 例: addpet:1|22001|1 或 addpet:1 addpet:1|22001\n'
|
||||||
addRobot(msg:string) {
|
this.room.send(client, 'notice_msg', str)
|
||||||
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();
|
* 添加服务端机器人
|
||||||
}
|
* addrobot:1
|
||||||
}
|
* @param msg
|
||||||
|
*/
|
||||||
/**
|
addRobot(msg: string) {
|
||||||
* 解锁英雄
|
let count = msg ? parseInt(msg) : 1
|
||||||
* @param client
|
let count2 = this.room.maxClients - this.room.clientCount
|
||||||
* @param {string} msg
|
for (let i = 0; i < Math.min(count, count2); i++) {
|
||||||
*/
|
this.room.addRobot()
|
||||||
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) {
|
* @param client
|
||||||
debugRoom(`解锁英雄 ${msg} 成功`);
|
* @param {string} msg
|
||||||
} else {
|
*/
|
||||||
error(`解锁英雄 ${msg} 失败`);
|
unlockHero(client: Client, msg: string) {
|
||||||
}
|
let heroId = msg
|
||||||
|
let player = this.room.state.players.get(client.id)
|
||||||
})
|
requestUnlockHero(player.accountId, heroId)
|
||||||
.catch(err=> {
|
.then((res) => {
|
||||||
error(err);
|
if (res.data.errcode == 0) {
|
||||||
})
|
debugRoom(`解锁英雄 ${ msg } 成功`)
|
||||||
}
|
reply(client, `SUCCESS: ${msg}`)
|
||||||
/**
|
} else {
|
||||||
* 将一个玩家的手牌全变成指定的效果卡
|
error(`解锁英雄 ${ msg } 失败`)
|
||||||
* changeeffect:玩家index|效果卡id
|
reply(client, `解锁英雄 ${ msg } 失败`)
|
||||||
* changeeffect:0|20011
|
}
|
||||||
* @param msg
|
|
||||||
*/
|
})
|
||||||
changePlayerCards(msg: string) {
|
.catch(err => {
|
||||||
if (msg.indexOf('|') < 0) {
|
error(err)
|
||||||
error(`错误的GM命令格式: ${msg}`);
|
reply(client, `解锁英雄 ${ msg } 失败`)
|
||||||
return;
|
})
|
||||||
}
|
}
|
||||||
let arr = msg.split('|');
|
|
||||||
let playerIdx = parseInt(arr[0]);
|
/**
|
||||||
let effectId = parseInt(arr[1]);
|
* 将一个玩家的手牌全变成指定的效果卡
|
||||||
let player = this.room.getPlayerByIdx(playerIdx);
|
* changeeffect:玩家index|效果卡id
|
||||||
for (let [, card] of player.cards) {
|
* changeeffect:0|20011
|
||||||
card.effect = effectId;
|
* @param client
|
||||||
}
|
* @param msg
|
||||||
let client = this.room.getClient(player.id);
|
*/
|
||||||
this.room.send(client,'sync_card', {}, {afterNextPatch: true});
|
changePlayerCards(client: Client, msg: string) {
|
||||||
}
|
if (msg.indexOf('|') < 0) {
|
||||||
/**
|
reply(client, `错误的GM命令格式: ${ msg }, 例: changeeffect:玩家index|效果卡id`)
|
||||||
* 将一个玩家的英雄变成指定的英雄
|
return
|
||||||
* changehero:玩家index|heroid
|
}
|
||||||
* changehero:0|30032
|
let arr = msg.split('|')
|
||||||
* @param msg
|
if (arr.length < 2) {
|
||||||
*/
|
reply(client, `错误的GM命令格式: ${ msg }, 例: changeeffect:玩家index|效果卡id`)
|
||||||
changeHero(msg: string) {
|
return
|
||||||
if (msg.indexOf('|') < 0) {
|
}
|
||||||
error(`错误的GM命令格式: ${msg}`);
|
let playerIdx = parseInt(arr[0])
|
||||||
return;
|
let effectId = parseInt(arr[1])
|
||||||
}
|
let player = this.room.getPlayerByIdx(playerIdx)
|
||||||
let arr = msg.split('|');
|
for (let [, card] of player.cards) {
|
||||||
let playerIdx = parseInt(arr[0]);
|
card.effect = effectId
|
||||||
let heroId = parseInt(arr[1]);
|
}
|
||||||
let player = this.room.getPlayerByIdx(playerIdx);
|
reply(client, `SUCCESS: ${msg}`)
|
||||||
player.heroId = heroId;
|
let target = this.room.getClient(player.id)
|
||||||
this.room.battleMan.updatePlayerHero(player);
|
this.room.send(target, 'sync_card', {}, { afterNextPatch: true })
|
||||||
let client = this.room.getClient(player.id);
|
}
|
||||||
this.room.send(client,'sync_hero', {playerid: player.id, heroid: heroId}, {afterNextPatch: true});
|
|
||||||
}
|
/**
|
||||||
|
* 将一个玩家的英雄变成指定的英雄
|
||||||
/**
|
* changehero:玩家index|heroid
|
||||||
* 将牌组中的卡全部变成指定的效果卡
|
* changehero:0|30032
|
||||||
* changequeue:效果卡id
|
* @param client
|
||||||
* changequeue:20011
|
* @param msg
|
||||||
* @param msg
|
*/
|
||||||
*/
|
changeHero(client: Client, msg: string) {
|
||||||
changeCardQueue(msg: string) {
|
if (msg.indexOf('|') < 0) {
|
||||||
let effectId = parseInt(msg);
|
reply(client, `错误的GM命令格式: ${ msg }`)
|
||||||
for (let card of this.state.cardQueue) {
|
return
|
||||||
card.effect = effectId;
|
}
|
||||||
}
|
let arr = msg.split('|')
|
||||||
}
|
let playerIdx = parseInt(arr[0])
|
||||||
addCard(msg: string) {
|
let heroId = parseInt(arr[1])
|
||||||
if (msg.indexOf('|') < 0) {
|
let player = this.room.getPlayerByIdx(playerIdx)
|
||||||
error(`错误的GM命令格式: ${msg}`);
|
player.heroId = heroId
|
||||||
return;
|
this.room.battleMan.updatePlayerHero(player)
|
||||||
}
|
let target = this.room.getClient(player.id)
|
||||||
let arr = msg.split('|');
|
reply(client, `SUCCESS: ${msg}`)
|
||||||
let playerIdx = parseInt(arr[0]);
|
this.room.send(target, 'sync_hero', {
|
||||||
let effectId = parseInt(arr[1]);
|
playerid: player.id,
|
||||||
let player = this.room.getPlayerByIdx(playerIdx);
|
heroid: heroId
|
||||||
let count = parseInt(arr[2]);
|
}, { afterNextPatch: true })
|
||||||
this.room.generateCard({player: player, count, effectId, fromplayer: player});
|
}
|
||||||
let client = this.room.getClient(player.id);
|
|
||||||
this.room.send(client,'sync_card', {}, {afterNextPatch: true});
|
/**
|
||||||
}
|
* 将牌组中的卡全部变成指定的效果卡
|
||||||
/**
|
* changequeue:效果卡id
|
||||||
* 抽一定数量的卡
|
* changequeue:20011
|
||||||
* draw:玩家index|数量|类型|效果id|点数
|
* @param client
|
||||||
* draw:0|3
|
* @param msg
|
||||||
* draw:0|3|1|20011|9
|
*/
|
||||||
* @param msg
|
changeCardQueue(client: Client, msg: string) {
|
||||||
*/
|
let effectId = parseInt(msg)
|
||||||
drawCard(msg: string) {
|
for (let card of this.state.cardQueue) {
|
||||||
if (msg.indexOf('|') < 0) {
|
card.effect = effectId
|
||||||
error(`错误的GM命令格式: ${msg}`);
|
}
|
||||||
return;
|
reply(client, `SUCCESS: ${msg}`)
|
||||||
}
|
}
|
||||||
let arr = msg.split('|');
|
|
||||||
let playerIdx = parseInt(arr[0]);
|
addCard(client: Client, msg: string) {
|
||||||
let player = this.room.getPlayerByIdx(playerIdx);
|
if (msg.indexOf('|') < 0) {
|
||||||
let count = parseInt(arr[1]);
|
error(`错误的GM命令格式: ${ msg }`)
|
||||||
let extData;
|
return
|
||||||
if (arr.length > 2) {
|
}
|
||||||
extData = {};
|
let arr = msg.split('|')
|
||||||
// @ts-ignore
|
let playerIdx = parseInt(arr[0])
|
||||||
extData.type = parseInt(arr[2]);
|
let effectId = parseInt(arr[1])
|
||||||
}
|
let player = this.room.getPlayerByIdx(playerIdx)
|
||||||
if (arr.length > 3) {
|
let count = parseInt(arr[2])
|
||||||
// @ts-ignore
|
this.room.generateCard({
|
||||||
extData.effect = parseInt(arr[3]);
|
player: player,
|
||||||
}
|
count,
|
||||||
if (arr.length > 4) {
|
effectId,
|
||||||
// @ts-ignore
|
fromplayer: player
|
||||||
extData.number = parseInt(arr[4]);
|
})
|
||||||
}
|
reply(client, `SUCCESS: ${msg}`)
|
||||||
this.room.addCard(player.id, count, 0, 2, null, extData);
|
let target = this.room.getClient(player.id)
|
||||||
let client = this.room.getClient(player.id);
|
this.room.send(target, 'sync_card', {}, { afterNextPatch: true })
|
||||||
this.room.send(client,'sync_card', {}, {afterNextPatch: true});
|
}
|
||||||
}
|
|
||||||
|
/**
|
||||||
/**
|
* 抽一定数量的卡
|
||||||
* 更新英雄血量
|
* draw:玩家index|数量|类型|效果id|点数
|
||||||
* @param msg
|
* draw:0|3
|
||||||
* herohp:玩家index|血量
|
* draw:0|3|1|20011|9
|
||||||
* herohp:0|500
|
* @param msg
|
||||||
*/
|
*/
|
||||||
updateHeroHp(msg: string) {
|
drawCard(client: Client, msg: string) {
|
||||||
let arr = msg.split('|');
|
if (msg.indexOf('|') < 0) {
|
||||||
let playerIdx = parseInt(arr[0]);
|
error(`错误的GM命令格式: ${ msg }`)
|
||||||
let player = this.room.getPlayerByIdx(playerIdx);
|
return
|
||||||
let count = parseInt(arr[1]);
|
}
|
||||||
this.room.updateHp(player.id, count);
|
let arr = msg.split('|')
|
||||||
}
|
let playerIdx = parseInt(arr[0])
|
||||||
setWin(msg: string) {
|
let player = this.room.getPlayerByIdx(playerIdx)
|
||||||
let teamId = parseInt(msg);
|
let count = parseInt(arr[1])
|
||||||
for (let [,player] of this.state.players) {
|
let extData
|
||||||
if (player.team != teamId) {
|
if (arr.length > 2) {
|
||||||
player.hp = 0;
|
extData = {}
|
||||||
}
|
// @ts-ignore
|
||||||
}
|
extData.type = parseInt(arr[2])
|
||||||
this.room.dispatcher.dispatch(new GameResultCommand());
|
}
|
||||||
}
|
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