player增加一个用于标记座次号的字段
This commit is contained in:
parent
6901d22c52
commit
7c5a74762f
7
src/global.d.ts
vendored
7
src/global.d.ts
vendored
@ -282,6 +282,13 @@ declare module "colyseus" {
|
|||||||
* @param srcPlayer
|
* @param srcPlayer
|
||||||
*/
|
*/
|
||||||
getOppositePlayer(srcPlayer: string|Player): Player;
|
getOppositePlayer(srcPlayer: string|Player): Player;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据index获取玩家
|
||||||
|
* @param {number} idx
|
||||||
|
* @return {Player}
|
||||||
|
*/
|
||||||
|
getPlayerByIdx(idx: number): Player;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -257,7 +257,17 @@ export class GeneralRoom extends Room {
|
|||||||
getAssistClient(sessionId: string): RobotClient {
|
getAssistClient(sessionId: string): RobotClient {
|
||||||
return this.assistMap.get(sessionId);
|
return this.assistMap.get(sessionId);
|
||||||
}
|
}
|
||||||
|
getPlayerByIdx(idx: number) {
|
||||||
|
for (let [, player] of this.state.players) {
|
||||||
|
if (player.idx == idx) {
|
||||||
|
return player;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 获取对位玩家
|
||||||
|
* @param srcPlayer
|
||||||
|
*/
|
||||||
getOppositePlayer(srcPlayer: string | Player): Player {
|
getOppositePlayer(srcPlayer: string | Player): Player {
|
||||||
let playerId;
|
let playerId;
|
||||||
if (typeof srcPlayer === 'string') {
|
if (typeof srcPlayer === 'string') {
|
||||||
@ -268,9 +278,8 @@ export class GeneralRoom extends Room {
|
|||||||
if (!this.state.players.has(playerId)) {
|
if (!this.state.players.has(playerId)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
const sessionIds = [...this.state.players.keys()];
|
let idx = this.state.players.get(playerId).idx;
|
||||||
let idx = sessionIds.indexOf(playerId);
|
let opposIdx = (2 + idx) % 4;
|
||||||
let playerId2 = sessionIds[(2 + idx) % 4];
|
return this.getPlayerByIdx(opposIdx);
|
||||||
return this.state.players.get(playerId2);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,9 @@ export class EatConfirmCommand extends Command<CardGameState, { timeUp: boolean
|
|||||||
async execute({timeUp} = this.payload) {
|
async execute({timeUp} = this.payload) {
|
||||||
let giveUpCount = 0;
|
let giveUpCount = 0;
|
||||||
const playerCount = this.room.maxClients - 1;
|
const playerCount = this.room.maxClients - 1;
|
||||||
const sessionIds = [...this.state.players.keys()];
|
const players = [...this.state.players.values()];
|
||||||
|
players.sort((a, b) => a.idx - b.idx);
|
||||||
|
const sessionIds = players.map(p => p.id);
|
||||||
// 将当前轮玩家移至第一位
|
// 将当前轮玩家移至第一位
|
||||||
let pids: string[] = sessionIds.moveElement(-sessionIds.indexOf(this.state.currentTurn));
|
let pids: string[] = sessionIds.moveElement(-sessionIds.indexOf(this.state.currentTurn));
|
||||||
|
|
||||||
|
@ -45,10 +45,6 @@ export class GMCommand extends Command<CardGameState, {client: Client, message:
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
getPlayerByIdx(idx: number) {
|
|
||||||
let players = [...this.state.players.values()];
|
|
||||||
return players[idx];
|
|
||||||
}
|
|
||||||
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';
|
||||||
@ -110,7 +106,7 @@ export class GMCommand extends Command<CardGameState, {client: Client, message:
|
|||||||
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.getPlayerByIdx(playerIdx);
|
let player = this.room.getPlayerByIdx(playerIdx);
|
||||||
for (let [, card] of player.cards) {
|
for (let [, card] of player.cards) {
|
||||||
card.effect = effectId;
|
card.effect = effectId;
|
||||||
}
|
}
|
||||||
@ -131,7 +127,7 @@ export class GMCommand extends Command<CardGameState, {client: Client, message:
|
|||||||
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.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 client = this.room.getClient(player.id);
|
||||||
@ -158,7 +154,7 @@ export class GMCommand extends Command<CardGameState, {client: Client, message:
|
|||||||
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.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({player: player, count, effectId, fromplayer: player});
|
||||||
let client = this.room.getClient(player.id);
|
let client = this.room.getClient(player.id);
|
||||||
@ -178,7 +174,7 @@ export class GMCommand extends Command<CardGameState, {client: Client, message:
|
|||||||
}
|
}
|
||||||
let arr = msg.split('|');
|
let arr = msg.split('|');
|
||||||
let playerIdx = parseInt(arr[0]);
|
let playerIdx = parseInt(arr[0]);
|
||||||
let player = this.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) {
|
||||||
@ -208,7 +204,7 @@ export class GMCommand extends Command<CardGameState, {client: Client, message:
|
|||||||
updateHeroHp(msg: string) {
|
updateHeroHp(msg: string) {
|
||||||
let arr = msg.split('|');
|
let arr = msg.split('|');
|
||||||
let playerIdx = parseInt(arr[0]);
|
let playerIdx = parseInt(arr[0]);
|
||||||
let player = this.getPlayerByIdx(playerIdx);
|
let player = this.room.getPlayerByIdx(playerIdx);
|
||||||
let count = parseInt(arr[1]);
|
let count = parseInt(arr[1]);
|
||||||
this.room.updateHp(player.id, count);
|
this.room.updateHp(player.id, count);
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,9 @@ export class NextTurnCommand extends Command<CardGameState, {}> {
|
|||||||
|
|
||||||
async execute(){
|
async execute(){
|
||||||
this.state.updateGameState(GameStateConst.STATE_BEGIN_DRAW);
|
this.state.updateGameState(GameStateConst.STATE_BEGIN_DRAW);
|
||||||
const sessionIds = [...this.state.players.keys()];
|
const players = [...this.state.players.values()];
|
||||||
|
players.sort((a, b) => a.idx - b.idx);
|
||||||
|
const sessionIds = players.map(p => p.id);
|
||||||
if (!this.state.currentTurn) {
|
if (!this.state.currentTurn) {
|
||||||
this.state.round = 0;
|
this.state.round = 0;
|
||||||
}
|
}
|
||||||
|
@ -13,9 +13,9 @@ export class OnJoinCommand extends Command<CardGameState, {
|
|||||||
accountId: string
|
accountId: string
|
||||||
}> {
|
}> {
|
||||||
execute({client, accountId} = this.payload) {
|
execute({client, accountId} = this.payload) {
|
||||||
let team = (this.state.players.size == 1 || this.state.players.size == 2)? 1 : 0;
|
let count = this.state.players.size;
|
||||||
// 实际的team会在PlayReadyCommand中设置
|
let team = (count == 1 || count == 2)? 1 : 0;
|
||||||
let player = new Player(client.sessionId, 0, team);
|
let player = new Player(client.sessionId, count, team);
|
||||||
if (accountId && accountId == 'robot') {
|
if (accountId && accountId == 'robot') {
|
||||||
accountId = `robot_${client.sessionId}`;
|
accountId = `robot_${client.sessionId}`;
|
||||||
} else if (!accountId) {
|
} else if (!accountId) {
|
||||||
|
@ -30,11 +30,11 @@ export class PlayReadyCommand extends Command<CardGameState, {
|
|||||||
this.room.stopSchedule('waiting_player');
|
this.room.stopSchedule('waiting_player');
|
||||||
// 比大小, 确定先手
|
// 比大小, 确定先手
|
||||||
// return [new PrepareCommand()];
|
// return [new PrepareCommand()];
|
||||||
let i = 0;
|
// let i = 0;
|
||||||
for (let [,player] of this.state.players) {
|
// for (let [,player] of this.state.players) {
|
||||||
player.team = (i == 1 || i == 2) ? 1 : 0;
|
// player.team = (i == 1 || i == 2) ? 1 : 0;
|
||||||
i += 1;
|
// i += 1;
|
||||||
}
|
// }
|
||||||
await this.room.setPrivate(true);
|
await this.room.setPrivate(true);
|
||||||
this.room.state.updateGameState(GameStateConst.CHANGE_HERO);
|
this.room.state.updateGameState(GameStateConst.CHANGE_HERO);
|
||||||
let self = this;
|
let self = this;
|
||||||
|
@ -7,7 +7,6 @@ import {BaseConst} from "../../constants/BaseConst";
|
|||||||
import {error} from "../../common/Debug";
|
import {error} from "../../common/Debug";
|
||||||
import {GameEnv} from "../../cfg/GameEnv";
|
import {GameEnv} from "../../cfg/GameEnv";
|
||||||
import {StateTypeEnum} from "../enums/StateTypeEnum";
|
import {StateTypeEnum} from "../enums/StateTypeEnum";
|
||||||
import {raw} from "express";
|
|
||||||
import {getCardGroup} from "../../common/WebApi";
|
import {getCardGroup} from "../../common/WebApi";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -59,6 +59,9 @@ export class Player extends Schema {
|
|||||||
*/
|
*/
|
||||||
@type("number")
|
@type("number")
|
||||||
team: number;
|
team: number;
|
||||||
|
|
||||||
|
@type("number")
|
||||||
|
idx: number;
|
||||||
/**
|
/**
|
||||||
* 玩家灵活时限, 客户端每次显示倒计时的时候, 需读取该时间
|
* 玩家灵活时限, 客户端每次显示倒计时的时候, 需读取该时间
|
||||||
*/
|
*/
|
||||||
@ -89,12 +92,13 @@ export class Player extends Schema {
|
|||||||
@type({ map: "number" })
|
@type({ map: "number" })
|
||||||
unitCfgs = new MapSchema<number>();
|
unitCfgs = new MapSchema<number>();
|
||||||
|
|
||||||
constructor(id: string, heroId: number, team: number) {
|
constructor(id: string, idx: number, team: number) {
|
||||||
super();
|
super();
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.state = PlayerStateConst.PLAYER_NORMAL;
|
this.state = PlayerStateConst.PLAYER_NORMAL;
|
||||||
this.hp = 0;
|
this.hp = 0;
|
||||||
this.heroId = heroId;
|
this.idx = idx;
|
||||||
|
this.heroId = 0;
|
||||||
this.team = team;
|
this.team = team;
|
||||||
this.countTotal = 0;
|
this.countTotal = 0;
|
||||||
this.countPresent = 0;
|
this.countPresent = 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user