增加一些状态数据的统计
This commit is contained in:
parent
631d352199
commit
ed2f5795a9
@ -861,3 +861,25 @@ Object.defineProperties(Array.prototype, {
|
|||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
interface Map<K, V> {
|
||||||
|
/**
|
||||||
|
* 只针对V为number的Map, 有值的话, 加上V, 没值则直接set
|
||||||
|
* V为其他类型时, 直接set
|
||||||
|
* @param key
|
||||||
|
* @param value
|
||||||
|
*/
|
||||||
|
inc?(key: K, value: V): this;
|
||||||
|
}
|
||||||
|
|
||||||
|
Object.defineProperties(Map.prototype, {
|
||||||
|
inc: {
|
||||||
|
value: function<K, V> (key: K, value: V) {
|
||||||
|
if (typeof value == 'number') {
|
||||||
|
this.set(key, (this.get(key) || 0) + value );
|
||||||
|
} else {
|
||||||
|
this.set(key, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
@ -6,6 +6,7 @@ import {PetInfo} from "../message/PetInfo";
|
|||||||
import {PlayDeadCommand} from "./commands/PlayDeadCommand";
|
import {PlayDeadCommand} from "./commands/PlayDeadCommand";
|
||||||
import {GameEnv} from "../cfg/GameEnv";
|
import {GameEnv} from "../cfg/GameEnv";
|
||||||
import {Player} from "./schema/Player";
|
import {Player} from "./schema/Player";
|
||||||
|
import {StateTypeEnum} from "./enums/StateTypeEnum";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 一些常用的方法
|
* 一些常用的方法
|
||||||
@ -15,7 +16,7 @@ Object.defineProperties(Room.prototype, {
|
|||||||
value: function (srcplayer: string, dstplayer: string, count: number): number {
|
value: function (srcplayer: string, dstplayer: string, count: number): number {
|
||||||
debugRoom(`玩家 ${srcplayer} 从 ${dstplayer} 偷 ${count} 张卡`);
|
debugRoom(`玩家 ${srcplayer} 从 ${dstplayer} 偷 ${count} 张卡`);
|
||||||
let player1 = this.state.players.get(dstplayer);
|
let player1 = this.state.players.get(dstplayer);
|
||||||
let player0 = this.state.players.get(srcplayer);
|
let player0: Player = this.state.players.get(srcplayer);
|
||||||
/**
|
/**
|
||||||
* 首先取目标玩家手牌数和偷牌数量的最小值
|
* 首先取目标玩家手牌数和偷牌数量的最小值
|
||||||
* 然后取目标玩家的手牌数和配置中玩家手牌数的差值
|
* 然后取目标玩家的手牌数和配置中玩家手牌数的差值
|
||||||
@ -28,6 +29,7 @@ Object.defineProperties(Room.prototype, {
|
|||||||
gameUtil.addCardToPlayer(this, player0, tmpCards, player1);
|
gameUtil.addCardToPlayer(this, player0, tmpCards, player1);
|
||||||
let cardIds = tmpCards.map(card => card.id);
|
let cardIds = tmpCards.map(card => card.id);
|
||||||
let client = this.getClient(player0);
|
let client = this.getClient(player0);
|
||||||
|
player0.statData.inc(StateTypeEnum.SCOUNT, tmpCards.length);
|
||||||
//广播一个偷卡成功信息, 并私信一个偷卡详情给当前玩家
|
//广播一个偷卡成功信息, 并私信一个偷卡详情给当前玩家
|
||||||
let msgData = {
|
let msgData = {
|
||||||
srcplayer,
|
srcplayer,
|
||||||
@ -50,6 +52,10 @@ Object.defineProperties(Room.prototype, {
|
|||||||
let tmpCards = gameUtil.removeCard(player, count);
|
let tmpCards = gameUtil.removeCard(player, count);
|
||||||
let time = this.battleMan.onCardDroped(player, tmpCards);
|
let time = this.battleMan.onCardDroped(player, tmpCards);
|
||||||
debugRoom(`giveUpCard add time: ${time}`);
|
debugRoom(`giveUpCard add time: ${time}`);
|
||||||
|
let fromP = this.state.players.get(fromplayer);
|
||||||
|
if (fromP.id != player.id){
|
||||||
|
fromP.statData.inc(StateTypeEnum.GCOUNT, tmpCards.length);
|
||||||
|
}
|
||||||
let cardIds = tmpCards.map(card => card.id);
|
let cardIds = tmpCards.map(card => card.id);
|
||||||
let msgData = {
|
let msgData = {
|
||||||
player: dstplayer,
|
player: dstplayer,
|
||||||
@ -64,7 +70,7 @@ Object.defineProperties(Room.prototype, {
|
|||||||
* @param dstplayer 目标玩家
|
* @param dstplayer 目标玩家
|
||||||
* @param count 补多少张, 该值和max_count至少一个不为0
|
* @param count 补多少张, 该值和max_count至少一个不为0
|
||||||
* @param max_count 补到多少张, 如果count和max_count都不为0, 则抽 Math.min(count, (max_count - 当前手牌数))
|
* @param max_count 补到多少张, 如果count和max_count都不为0, 则抽 Math.min(count, (max_count - 当前手牌数))
|
||||||
* @param source 0: 正常抽卡, 1: 技能
|
* @param source 0: 正常抽卡, 1: 技能, 9: GM
|
||||||
* @param fromplayer
|
* @param fromplayer
|
||||||
*/
|
*/
|
||||||
addCard: {
|
addCard: {
|
||||||
@ -87,6 +93,9 @@ Object.defineProperties(Room.prototype, {
|
|||||||
}
|
}
|
||||||
let player2 = fromplayer ? this.state.players.get(fromplayer) : null;
|
let player2 = fromplayer ? this.state.players.get(fromplayer) : null;
|
||||||
let cards = gameUtil.drawCard(this, this.state.cardQueue, player, count, player2, extData);
|
let cards = gameUtil.drawCard(this, this.state.cardQueue, player, count, player2, extData);
|
||||||
|
if (source == 2 && player2 && player2.id != player.id) {
|
||||||
|
player2.statData.inc(StateTypeEnum.ACOUNT, cards.length);
|
||||||
|
}
|
||||||
let client = this.getClient(dstplayer);
|
let client = this.getClient(dstplayer);
|
||||||
let sData = {
|
let sData = {
|
||||||
player: dstplayer,
|
player: dstplayer,
|
||||||
@ -115,6 +124,11 @@ Object.defineProperties(Room.prototype, {
|
|||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
let dstHp = player.hp + (hp | 0);
|
let dstHp = player.hp + (hp | 0);
|
||||||
|
let sourceP = this.state.players.get(fromplayer);
|
||||||
|
if (sourceP && hp < 0) {
|
||||||
|
sourceP.statData.inc(StateTypeEnum.DMG, hp);
|
||||||
|
player.statData.inc(StateTypeEnum.TDMG, hp);
|
||||||
|
}
|
||||||
debugRoom(`更新血量: ${player.id} ${player.hp} -> ${hp}, reason: ${reason}`);
|
debugRoom(`更新血量: ${player.id} ${player.hp} -> ${hp}, reason: ${reason}`);
|
||||||
if (dstHp <= 0) {
|
if (dstHp <= 0) {
|
||||||
dstHp = 0;
|
dstHp = 0;
|
||||||
@ -177,7 +191,17 @@ Object.defineProperties(Room.prototype, {
|
|||||||
*/
|
*/
|
||||||
updatePetStat: {
|
updatePetStat: {
|
||||||
value: function (datas: PetInfo[], fromplayer?: string): void {
|
value: function (datas: PetInfo[], fromplayer?: string): void {
|
||||||
|
let player = this.state.players.get(fromplayer);
|
||||||
|
for (let data of datas) {
|
||||||
|
let targetPlayer = this.state.players.get(data.player);
|
||||||
|
let valOld = targetPlayer.petData.get(data.pos) || 0;
|
||||||
|
let valNew = data.ap + data.extAp;
|
||||||
|
targetPlayer.petData.set(data.pos, valNew);
|
||||||
|
if (valNew < valOld) {
|
||||||
|
player.statData.inc(StateTypeEnum.DMG, valOld - valNew);
|
||||||
|
targetPlayer.statData.inc(StateTypeEnum.TDMG, valOld - valNew);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
@ -214,9 +238,13 @@ Object.defineProperties(Room.prototype, {
|
|||||||
let sourcePlayer;
|
let sourcePlayer;
|
||||||
if (typeof fromplayer == 'string') {
|
if (typeof fromplayer == 'string') {
|
||||||
sourcePlayer = this.state.players.get(fromplayer);
|
sourcePlayer = this.state.players.get(fromplayer);
|
||||||
|
if (sourcePlayer.id !== dstplayer.id) {
|
||||||
|
sourcePlayer.statData.inc(StateTypeEnum.CCOUNT, tmpCards.length);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
sourcePlayer = player;
|
sourcePlayer = player;
|
||||||
}
|
}
|
||||||
|
|
||||||
gameUtil.addCardToPlayer(this, dstplayer, tmpCards, sourcePlayer);
|
gameUtil.addCardToPlayer(this, dstplayer, tmpCards, sourcePlayer);
|
||||||
let client = this.getClient(dstplayer);
|
let client = this.getClient(dstplayer);
|
||||||
let sData = {
|
let sData = {
|
||||||
|
@ -10,6 +10,7 @@ import {TurnEndCommand} from "./TurnEndCommand";
|
|||||||
import {Card} from "../schema/Card";
|
import {Card} from "../schema/Card";
|
||||||
import {Wait} from "./Wait";
|
import {Wait} from "./Wait";
|
||||||
import {CardType} from "../../cfg/enums/CardType";
|
import {CardType} from "../../cfg/enums/CardType";
|
||||||
|
import {StateTypeEnum} from "../enums/StateTypeEnum";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 出牌
|
* 出牌
|
||||||
@ -88,6 +89,7 @@ export class DiscardCommand extends Command<CardGameState, { client: Client, car
|
|||||||
let self = this;
|
let self = this;
|
||||||
this.room.send(client,'eat_card_s2c', {player: player.id, errcode: 0, errmsg: ''});
|
this.room.send(client,'eat_card_s2c', {player: player.id, errcode: 0, errmsg: ''});
|
||||||
let delay = this.room.battleMan.onCardLinkOver(player, cardArr);
|
let delay = this.room.battleMan.onCardLinkOver(player, cardArr);
|
||||||
|
player.statData.inc(StateTypeEnum.EATCOUNT, 1);
|
||||||
await this.delay(delay);
|
await this.delay(delay);
|
||||||
let time = new GameEnv().playerActTime * 1000 + player.extraTime;
|
let time = new GameEnv().playerActTime * 1000 + player.extraTime;
|
||||||
this.state.updateGameState(GameStateConst.STATE_PICK_PET);
|
this.state.updateGameState(GameStateConst.STATE_PICK_PET);
|
||||||
|
@ -7,6 +7,7 @@ import {TurnEndCommand} from "./TurnEndCommand";
|
|||||||
import {Player} from "../schema/Player";
|
import {Player} from "../schema/Player";
|
||||||
import {Card} from "../schema/Card";
|
import {Card} from "../schema/Card";
|
||||||
import gameUtil from "../../utils/game.util";
|
import gameUtil from "../../utils/game.util";
|
||||||
|
import {StateTypeEnum} from "../enums/StateTypeEnum";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据条件决定吃牌玩家, 并执行吃牌逻辑
|
* 根据条件决定吃牌玩家, 并执行吃牌逻辑
|
||||||
@ -73,6 +74,7 @@ export class EatConfirmCommand extends Command<CardGameState, { timeUp: boolean
|
|||||||
let currentPlayer = this.state.players.get(this.state.currentTurn);
|
let currentPlayer = this.state.players.get(this.state.currentTurn);
|
||||||
currentPlayer.cardQueue.clear();
|
currentPlayer.cardQueue.clear();
|
||||||
player.cardQueue.clear();
|
player.cardQueue.clear();
|
||||||
|
player.statData.inc(StateTypeEnum.EATCOUNT, 1);
|
||||||
player.cardQueue.push(this.state.cards.values().next().value.clone());
|
player.cardQueue.push(this.state.cards.values().next().value.clone());
|
||||||
for (let id of cards) {
|
for (let id of cards) {
|
||||||
if (!player.cards.has(id + '')) {
|
if (!player.cards.has(id + '')) {
|
||||||
|
@ -8,6 +8,7 @@ import {debugRoom, error} from "../../common/Debug";
|
|||||||
import gameUtil from "../../utils/game.util";
|
import gameUtil from "../../utils/game.util";
|
||||||
import {Card} from "../schema/Card";
|
import {Card} from "../schema/Card";
|
||||||
import {MapSchema, SetSchema} from "@colyseus/schema";
|
import {MapSchema, SetSchema} from "@colyseus/schema";
|
||||||
|
import {StateTypeEnum} from "../enums/StateTypeEnum";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 游戏结束
|
* 游戏结束
|
||||||
@ -20,6 +21,8 @@ export class GameResultCommand extends Command<CardGameState, {}> {
|
|||||||
let hp1 = 0;
|
let hp1 = 0;
|
||||||
let ap0 = 0;
|
let ap0 = 0;
|
||||||
let ap1 = 0;
|
let ap1 = 0;
|
||||||
|
let petAp0 = 0;
|
||||||
|
let petAp1 = 0;
|
||||||
let resultArr = [];
|
let resultArr = [];
|
||||||
for (let [, player] of this.state.players) {
|
for (let [, player] of this.state.players) {
|
||||||
let data = {
|
let data = {
|
||||||
@ -34,29 +37,66 @@ export class GameResultCommand extends Command<CardGameState, {}> {
|
|||||||
hp0 += player.hp;
|
hp0 += player.hp;
|
||||||
if (player.state != PlayerStateConst.PLAYER_DEAD) {
|
if (player.state != PlayerStateConst.PLAYER_DEAD) {
|
||||||
ap0 += data.ap;
|
ap0 += data.ap;
|
||||||
|
for (let [,pet] of player.pets) {
|
||||||
|
petAp0 += (pet.ap + pet.extAp);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (player.team == 1) {
|
if (player.team == 1) {
|
||||||
hp1 += player.hp;
|
hp1 += player.hp;
|
||||||
if (player.state != PlayerStateConst.PLAYER_DEAD) {
|
if (player.state != PlayerStateConst.PLAYER_DEAD) {
|
||||||
ap1 += data.ap;
|
ap1 += data.ap;
|
||||||
|
for (let [,pet] of player.pets) {
|
||||||
|
petAp1 += (pet.ap + pet.extAp);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let winner = 0;
|
let winner = -1; // 平局
|
||||||
if (hp0 > hp1) {
|
if (hp0 > hp1) {
|
||||||
winner = 0;
|
winner = 0;
|
||||||
} else if (hp0 < hp1) {
|
} else if (hp0 < hp1) {
|
||||||
winner = 1;
|
winner = 1;
|
||||||
} else {
|
} else {
|
||||||
if (ap0 >= ap1) {
|
if (ap0 > ap1) {
|
||||||
winner = 0;
|
winner = 0;
|
||||||
} else {
|
} else if (ap0 < ap1){
|
||||||
winner = 1;
|
winner = 1;
|
||||||
|
} else {
|
||||||
|
if (petAp0 > petAp1) {
|
||||||
|
winner = 0;
|
||||||
|
} else if (petAp0 < petAp1) {
|
||||||
|
winner = 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let resultData = {winner: winner, results: resultArr};
|
|
||||||
|
|
||||||
|
let resultData: any = {
|
||||||
|
winner: winner,
|
||||||
|
results: resultArr
|
||||||
|
};
|
||||||
|
let resultMap: Map<StateTypeEnum, [string, number]> = new Map();
|
||||||
|
for (let [, player] of this.state.players) {
|
||||||
|
for (let [type, val] of player.statData) {
|
||||||
|
if (resultMap.has(type)) {
|
||||||
|
let current = resultMap.get(type);
|
||||||
|
if (current[1] < val) {
|
||||||
|
resultMap.set(type, [player.id, val]);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
resultMap.set(type, [player.id, val]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let statics: any = [];
|
||||||
|
for (let [type, val] of resultMap) {
|
||||||
|
statics.push({
|
||||||
|
type,
|
||||||
|
player: val[0],
|
||||||
|
val: val[1]
|
||||||
|
})
|
||||||
|
}
|
||||||
|
resultData[statics] = statics;
|
||||||
this.room.bGameResult(resultData);
|
this.room.bGameResult(resultData);
|
||||||
this.state.updateGameState(GameStateConst.STATE_GAME_OVER);
|
this.state.updateGameState(GameStateConst.STATE_GAME_OVER);
|
||||||
//启动定时, 时间到后, 踢出没离开且没点重玩的玩家, 并将房间设为非private
|
//启动定时, 时间到后, 踢出没离开且没点重玩的玩家, 并将房间设为非private
|
||||||
@ -115,6 +155,8 @@ export class GameResultCommand extends Command<CardGameState, {}> {
|
|||||||
player.cards.clear();
|
player.cards.clear();
|
||||||
player.cards = new MapSchema<Card>()
|
player.cards = new MapSchema<Card>()
|
||||||
player.cardSet.clear();
|
player.cardSet.clear();
|
||||||
|
player.statData.clear();
|
||||||
|
player.petData.clear();
|
||||||
player.cardSet = new SetSchema<string>();
|
player.cardSet = new SetSchema<string>();
|
||||||
player.countTotal = 0;
|
player.countTotal = 0;
|
||||||
player.countPresent = 0;
|
player.countPresent = 0;
|
||||||
|
@ -1,12 +1,9 @@
|
|||||||
import {Command} from "@colyseus/command";
|
import {Command} from "@colyseus/command";
|
||||||
import {CardGameState} from "../schema/CardGameState";
|
import {CardGameState} from "../schema/CardGameState";
|
||||||
import {GameEnv} from "../../cfg/GameEnv";
|
|
||||||
import {PartResultCommand} from "./PartResultCommand";
|
|
||||||
import {NextTurnCommand} from "./NextTurnCommand";
|
import {NextTurnCommand} from "./NextTurnCommand";
|
||||||
import {PlayerStateConst} from "../../constants/PlayerStateConst";
|
|
||||||
import {Wait} from "./Wait";
|
|
||||||
import {GameResultCommand} from "./GameResultCommand";
|
import {GameResultCommand} from "./GameResultCommand";
|
||||||
import gameUtil from "../../utils/game.util";
|
import gameUtil from "../../utils/game.util";
|
||||||
|
import {StateTypeEnum} from "../enums/StateTypeEnum";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 一轮结束
|
* 一轮结束
|
||||||
@ -29,8 +26,21 @@ export class TurnEndCommand extends Command<CardGameState, {}> {
|
|||||||
// return [new PartResultCommand()];
|
// return [new PartResultCommand()];
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
// 判断是否胜利
|
|
||||||
|
|
||||||
|
// 记录pet的maxap(最高ap) 和 maxsap(最高单体ap)
|
||||||
|
for (let [,player] of this.state.players) {
|
||||||
|
let maxAp = player.statData.get(StateTypeEnum.MAXAP) || 0;
|
||||||
|
let maxsAp = player.statData.get(StateTypeEnum.MAXSAP) || 0;
|
||||||
|
let totalAp = 0;
|
||||||
|
for (let [, pet] of player.pets) {
|
||||||
|
totalAp += (pet.ap || 0 + pet.extAp || 0);
|
||||||
|
maxsAp = Math.max(maxsAp, (pet.ap || 0 + pet.extAp || 0));
|
||||||
|
}
|
||||||
|
maxAp = Math.max(maxAp, totalAp);
|
||||||
|
player.statData.set(StateTypeEnum.MAXAP, maxAp);
|
||||||
|
player.statData.set(StateTypeEnum.MAXSAP, maxsAp);
|
||||||
|
}
|
||||||
|
// 判断是否胜利
|
||||||
let result = gameUtil.checkGameEnd(this.state);
|
let result = gameUtil.checkGameEnd(this.state);
|
||||||
if (result) {
|
if (result) {
|
||||||
return [new GameResultCommand()];
|
return [new GameResultCommand()];
|
||||||
|
@ -3,6 +3,7 @@ import {Pet} from "./Pet";
|
|||||||
import {Card} from "./Card";
|
import {Card} from "./Card";
|
||||||
import {GameEnv} from "../../cfg/GameEnv";
|
import {GameEnv} from "../../cfg/GameEnv";
|
||||||
import {PlayerStateConst} from "../../constants/PlayerStateConst";
|
import {PlayerStateConst} from "../../constants/PlayerStateConst";
|
||||||
|
import {StateTypeEnum} from "../enums/StateTypeEnum";
|
||||||
|
|
||||||
|
|
||||||
export class Player extends Schema {
|
export class Player extends Schema {
|
||||||
@ -69,6 +70,14 @@ export class Player extends Schema {
|
|||||||
* 当前累计抽卡
|
* 当前累计抽卡
|
||||||
*/
|
*/
|
||||||
countPresent: number;
|
countPresent: number;
|
||||||
|
/**
|
||||||
|
* 记录当前局内统计数字
|
||||||
|
*/
|
||||||
|
statData: Map<StateTypeEnum, number> = new Map();
|
||||||
|
/**
|
||||||
|
* 用于记录pet值, 用于统计伤害
|
||||||
|
*/
|
||||||
|
petData: Map<number, number> = new Map();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 英雄绑定的卡组, 选好英雄后, 从默认配置或玩家卡组(待实现)中获取
|
* 英雄绑定的卡组, 选好英雄后, 从默认配置或玩家卡组(待实现)中获取
|
||||||
|
Loading…
x
Reference in New Issue
Block a user