完善吃牌逻辑, player增加team

This commit is contained in:
zhl 2020-12-02 17:02:39 +08:00
parent c3b189bbdf
commit 9cec61b712
6 changed files with 50 additions and 17 deletions

View File

@ -37,7 +37,7 @@ export class GeneralRoom extends Room {
this.onMessage("give_up_eat_c2s", (client, message) => {
console.log('give_up_take from ', client.sessionId, message);
this.dispatcher.dispatch(new NextSubCommand(), {});
// this.dispatcher.dispatch(new NextSubCommand(), {});
});
this.onMessage("select_pet_c2s", (client, message) => {

View File

@ -2,7 +2,6 @@ import { Command } from "@colyseus/command";
import { CardGameState } from "../schema/CardGameState";
import gameUtil from "../../utils/game.util";
import {Client} from "colyseus";
import {NextTurnCommand} from "./NextTurnCommand";
import {NextSubCommand} from "./NextSubCommand";
import {GameStateConst} from "../../constants/GameStateConst";

View File

@ -2,6 +2,7 @@ import {Command} from "@colyseus/command";
import {CardGameState} from "../schema/CardGameState";
import {Client} from "colyseus";
import gameUtil from "../../utils/game.util";
import {GameStateConst} from "../../constants/GameStateConst";
/**
*
@ -17,11 +18,35 @@ export class EatCardCommand extends Command<CardGameState, { client: Client, car
client.send('eat_card_s2c', {errcode: 2, errmsg: '要出的牌在手牌中不存在'});
return;
}
if (this.state.subTurn != client.sessionId || this.state.currentTurn == client.sessionId) {
client.send('eat_card_s2c', {errcode: 3, errmsg: '不是自己的吃牌轮'});
if (this.state.currentTurn == client.sessionId) {
client.send('eat_card_s2c', {errcode: 3, errmsg: '不能吃自己的牌'});
return;
}
if (!this.state.cards.has(target)) {
client.send('eat_card_s2c', {errcode: 4, errmsg: '找不到要吃的牌'});
return;
}
let tmpCards = [];
for (let id of cards) {
tmpCards.push(player.cards.get(id));
}
tmpCards.push(this.state.cards.get(target));
if (!gameUtil.checkDiscard(tmpCards)) {
client.send('discard_card_s2c', {errcode: 5, errmsg: '不符合吃牌规则'});
return;
}
if (this.state.gameState !== GameStateConst.STATE_BEGIN_EAT) {
client.send('discard_card_s2c', {errcode: 6, errmsg: '已经被别人吃了'});
return;
}
for (let id of cards) {
this.state.cards.set(id, player.cards.get(id));
player.cards.delete(id);
player.cardSet.delete(id);
}
this.state.gameState = GameStateConst.STATE_PICK_PET;
// 成功后广播吃牌成功消息
this.room.broadcast('eat_card_s2c', {player: client.sessionId, errocode: 0, errmsg: ''})
}
}

View File

@ -10,15 +10,15 @@ export class NextSubCommand extends Command<CardGameState, {}> {
execute() {
this.state.gameState = GameStateConst.STATE_BEGIN_EAT;
const sessionIds = [...this.state.players.keys()];
let nextSubTurn = this.state.subTurn ?
sessionIds[(sessionIds.indexOf(this.state.subTurn) + 1) % sessionIds.length]
: sessionIds[(sessionIds.indexOf(this.state.currentTurn) + 1) % sessionIds.length];
if (nextSubTurn !== this.state.currentTurn) {
this.state.subTurn = nextSubTurn;
} else {
return [new NextTurnCommand()];
}
// const sessionIds = [...this.state.players.keys()];
// let nextSubTurn = this.state.subTurn ?
// sessionIds[(sessionIds.indexOf(this.state.subTurn) + 1) % sessionIds.length]
// : sessionIds[(sessionIds.indexOf(this.state.currentTurn) + 1) % sessionIds.length];
// if (nextSubTurn !== this.state.currentTurn) {
// this.state.subTurn = nextSubTurn;
// } else {
// return [new NextTurnCommand()];
// }
}
}

View File

@ -11,7 +11,8 @@ export class OnJoinCommand extends Command<CardGameState, {
}> {
execute({client}: { client: Client }) {
this.state.players.set(client.sessionId, new Player(0));
let team = this.state.players.size / 2 | 0;
this.state.players.set(client.sessionId, new Player(0, team));
if (this.state.players.size >= this.room.maxClients) {
this.room.lock();
this.state.gameState = 1;

View File

@ -1,6 +1,8 @@
import {MapSchema, SetSchema, Schema, type} from "@colyseus/schema";
import {Pet} from "./Pet";
import {Card} from "./Card";
import {singleton} from "../../common/Singleton";
import {GameEnv} from "../../cfg/GameEnv";
export class Player extends Schema {
@ -39,15 +41,21 @@ export class Player extends Schema {
@type({ map: Pet })
pets = new MapSchema<Pet>();
/**
*
*/
@type("number")
team: number;
//TODO: set hp, ap from cfg
constructor(heroId: number) {
constructor(heroId: number, team: number) {
super();
this.state = 0;
this.hp = 200;
this.ap = 30;
this.heroId = heroId;
for (let i = 0; i < 6; i++) {
for (let i = 0; i < singleton(GameEnv).maxPlayerPetCount; i++) {
this.pets.set(i+'', new Pet());
}
}