修改出牌,吃牌规则, 增加一些注释

This commit is contained in:
zhl 2020-12-02 16:23:27 +08:00
parent 0483e1cb0b
commit c3b189bbdf
15 changed files with 104 additions and 15 deletions

View File

@ -42,7 +42,7 @@ export class GeneralRoom extends Room {
this.onMessage("select_pet_c2s", (client, message) => {
console.log('select_pet from ', client.sessionId, message);
this.dispatcher.dispatch(new SelectPetCommand(), {client, cardId: message.cardId});
this.dispatcher.dispatch(new SelectPetCommand(), {client, cardId: message.cardId, playerId: message.player, pos: message.pos, effCards: message.effCards });
});
this.onMessage("select_hero_c2s", (client, message) => {

View File

@ -6,7 +6,11 @@ import gameUtil from "../../utils/game.util";
import {singleton} from "../../common/Singleton";
import {GameEnv} from "../../cfg/GameEnv";
/**
*
* 1.
* 2. STATE_CHANGE_CARD
*/
export class BeginGameCommand extends Command<CardGameState, {}> {
execute() {

View File

@ -8,6 +8,9 @@ import {singleton} from "../../common/Singleton";
import {GameEnv} from "../../cfg/GameEnv";
import {GameStateConst} from "../../constants/GameStateConst";
/**
*
*/
export class ChangeCardCommand extends Command<CardGameState, { client: Client, cards: [string] }> {
validate({ client, cards } = this.payload) {
const player = this.state.players.get(client.sessionId);

View File

@ -29,11 +29,19 @@ export class DiscardCommand extends Command<CardGameState, { client: Client, car
client.send('discard_card_s2c', {errcode: 3, errmsg: '不是当前轮'});
return;
}
let tmpCards = [];
for (let id of cards) {
tmpCards.push(player.cards.get(id));
}
if (!gameUtil.checkDiscard(tmpCards)) {
client.send('discard_card_s2c', {errcode: 4, errmsg: '出牌不符合规则'});
return;
}
this.state.cards.clear();
for (let id of cards) {
this.state.cards.set(id, this.state.players.get(client.sessionId).cards.get(id));
this.state.players.get(client.sessionId).cards.delete(id);
this.state.players.get(client.sessionId).cardSet.delete(id);
this.state.cards.set(id, player.cards.get(id));
player.cards.delete(id);
player.cardSet.delete(id);
}
/**
* ,

View File

@ -4,6 +4,9 @@ import {singleton} from "../../common/Singleton";
import {GameEnv} from "../../cfg/GameEnv";
import gameUtil from "../../utils/game.util";
/**
*
*/
export class DrawCommand extends Command<CardGameState, {}> {
execute() {
let sessionId = this.state.currentTurn;

View File

@ -3,7 +3,9 @@ import {CardGameState} from "../schema/CardGameState";
import {Client} from "colyseus";
import gameUtil from "../../utils/game.util";
/**
*
*/
export class EatCardCommand extends Command<CardGameState, { client: Client, cards: [string], target: string }> {
execute({ client, cards, target } = this.payload) {
const player = this.state.players.get(client.sessionId);

View File

@ -1,11 +1,15 @@
import { Command } from "@colyseus/command";
import { CardGameState } from "../schema/CardGameState";
import {NextTurnCommand} from "./NextTurnCommand";
import {GameStateConst} from "../../constants/GameStateConst";
/**
*
*/
export class NextSubCommand extends Command<CardGameState, {}> {
execute() {
this.state.gameState = 3;
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]

View File

@ -2,6 +2,9 @@ import {Command} from "@colyseus/command";
import {CardGameState} from "../schema/CardGameState";
import {DrawCommand} from "./DrawCommand";
/**
*
*/
export class NextTurnCommand extends Command<CardGameState, {}> {
execute() {

View File

@ -3,6 +3,9 @@ import {CardGameState} from "../schema/CardGameState";
import {Player} from "../schema/Player";
import {Client} from "colyseus";
/**
*
*/
export class OnJoinCommand extends Command<CardGameState, {
client: Client
}> {

View File

@ -1,14 +1,12 @@
import {Command} from "@colyseus/command";
import {CardGameState} from "../schema/CardGameState";
import {Client} from "colyseus";
import gameUtil from "../../utils/game.util";
import {GeneralRoom} from "../GeneralRoom";
import {singleton} from "../../common/Singleton";
import {GameEnv} from "../../cfg/GameEnv";
import {PlayerStateConst} from "../../constants/PlayerStateConst";
import {GameStateConst} from "../../constants/GameStateConst";
import {PrepareCommand} from "./PrepareCommand";
/**
*
*/
export class PlayReadyCommand extends Command<CardGameState, {
client: Client
}> {

View File

@ -3,7 +3,9 @@ import {CardGameState} from "../schema/CardGameState";
import {GameStateConst} from "../../constants/GameStateConst";
import {BeginGameCommand} from "./BeginGameCommand";
/**
* ,
*/
export class PrepareCommand extends Command<CardGameState, {}> {
execute() {

View File

@ -4,6 +4,9 @@ import {Client} from "colyseus";
import {PlayerStateConst} from "../../constants/PlayerStateConst";
import {BeginGameCommand} from "./BeginGameCommand";
/**
*
*/
export class SelectHeroCommand extends Command<CardGameState, {client: Client, heroId: number}> {
execute({ client, heroId } = this.payload) {
let player = this.state.players.get(client.sessionId);

View File

@ -3,8 +3,16 @@ import { CardGameState } from "../schema/CardGameState";
import {Client} from "colyseus";
import {NextTurnCommand} from "./NextTurnCommand";
export class SelectPetCommand extends Command<CardGameState, {client: Client, cardId: string}> {
execute({client, cardId}: {client: Client, cardId: string}) {
/**
*
*/
export class SelectPetCommand extends Command<CardGameState, {client: Client,
cardId: string,
playerId: string,
pos: number,
effCards: string[]
}> {
execute({client, cardId, playerId, pos, effCards}: {client: Client, cardId: string, playerId: string, pos: number, effCards: string[]}) {
let sessionId = this.state.currentTurn;
let player = this.state.players.get(sessionId);
let ap = 0;

View File

@ -13,6 +13,9 @@ export class Pet extends Schema {
@type("string")
type: string;
@type("string")
id: string;
constructor() {
super();

View File

@ -81,6 +81,51 @@ let gameUtil = {
player.cardSet.add(card.id);
}
return cards;
},
/**
*
* @param cardsLst
*/
checkDiscard(cardsLst: Card[]) {
if (cardsLst.length == 0 || cardsLst.length == 2) {
return false
}
let numSet: number[] = [];
cardsLst.forEach(function (value) {
if (value.number < 11) {
numSet.push(value.number);
}
});
if (numSet.length === 1) {
return true;
}
if (numSet.length < 3) {
return false;
}
numSet.sort((a, b) => {
return a - b;
});
let preNum;
let sequence = true; //是否是顺序
let same = true; //是否是相同
for (let num of numSet) {
if (preNum) {
if (num !== (preNum + 1) && sequence) {
sequence = false;
}
if (num !== preNum && same) {
same = false;
}
if (!sequence && !same) {
return false;
}
}
preNum = num;
}
return true;
}
}
export default gameUtil;