将扩展的Map.inc方法改为zinc
This commit is contained in:
parent
a45e0665b5
commit
606cf3ae10
@ -888,7 +888,7 @@ interface Map<K, V> {
|
||||
* @param key
|
||||
* @param value
|
||||
*/
|
||||
inc?(key: K, value: V): this;
|
||||
zinc?(key: K, value: V): this;
|
||||
|
||||
/**
|
||||
* 获取Map中第一个值
|
||||
@ -898,7 +898,7 @@ interface Map<K, V> {
|
||||
}
|
||||
|
||||
Object.defineProperties(Map.prototype, {
|
||||
inc: {
|
||||
zinc: {
|
||||
value: function<K, V> (key: K, value: V) {
|
||||
if (typeof value == 'number') {
|
||||
this.set(key, (this.get(key) || 0) + value );
|
||||
|
@ -29,7 +29,7 @@ Object.defineProperties(Room.prototype, {
|
||||
gameUtil.addCardToPlayer(this, player0, tmpCards, player1);
|
||||
let cardIds = tmpCards.map(card => card.id);
|
||||
let client = this.getClient(player0);
|
||||
player0.statData.inc(StateTypeEnum.SCOUNT, tmpCards.length);
|
||||
player0.statData.zinc(StateTypeEnum.SCOUNT, tmpCards.length);
|
||||
//广播一个偷卡成功信息, 并私信一个偷卡详情给当前玩家
|
||||
let msgData = {
|
||||
srcplayer,
|
||||
@ -54,7 +54,7 @@ Object.defineProperties(Room.prototype, {
|
||||
debugRoom(`giveUpCard add time: ${time}`);
|
||||
let fromP = this.state.players.get(fromplayer);
|
||||
if (fromP.id != player.id){
|
||||
fromP.statData.inc(StateTypeEnum.GCOUNT, tmpCards.length);
|
||||
fromP.statData.zinc(StateTypeEnum.GCOUNT, tmpCards.length);
|
||||
}
|
||||
let cardIds = tmpCards.map(card => card.id);
|
||||
let msgData = {
|
||||
@ -98,7 +98,7 @@ Object.defineProperties(Room.prototype, {
|
||||
let player2 = fromplayer ? this.state.players.get(fromplayer) : null;
|
||||
let cards = gameUtil.drawCard(this, this.state.cardQueue, player, count, player2, extData);
|
||||
if (source == 1 && player2 && player2.id != player.id) {
|
||||
player2.statData.inc(StateTypeEnum.ACOUNT, cards.length);
|
||||
player2.statData.zinc(StateTypeEnum.ACOUNT, cards.length);
|
||||
}
|
||||
let client = this.getClient(dstplayer);
|
||||
let sData = {
|
||||
@ -130,8 +130,8 @@ Object.defineProperties(Room.prototype, {
|
||||
let dstHp = player.hp + (hp | 0);
|
||||
let sourceP = this.state.players.get(fromplayer);
|
||||
if (sourceP && hp < 0) {
|
||||
sourceP.statData.inc(StateTypeEnum.DMG, Math.min(-hp, player.hp));
|
||||
player.statData.inc(StateTypeEnum.TDMG, Math.min(-hp, player.hp));
|
||||
sourceP.statData.zinc(StateTypeEnum.DMG, Math.min(-hp, player.hp));
|
||||
player.statData.zinc(StateTypeEnum.TDMG, Math.min(-hp, player.hp));
|
||||
}
|
||||
debugRoom(`更新血量: ${player.id} ${player.hp} -> ${hp}, reason: ${reason}, from: ${fromplayer}`);
|
||||
if (dstHp <= 0) {
|
||||
@ -206,8 +206,8 @@ Object.defineProperties(Room.prototype, {
|
||||
}
|
||||
debugRoom(`updatePetStat, val change, old: ${valOld}, new: ${valNew}`);
|
||||
if (valNew < valOld) {
|
||||
player?.statData.inc(StateTypeEnum.DMG, valOld - valNew);
|
||||
targetPlayer?.statData.inc(StateTypeEnum.TDMG, valOld - valNew);
|
||||
player?.statData.zinc(StateTypeEnum.DMG, valOld - valNew);
|
||||
targetPlayer?.statData.zinc(StateTypeEnum.TDMG, valOld - valNew);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -247,7 +247,7 @@ Object.defineProperties(Room.prototype, {
|
||||
if (typeof fromplayer == 'string') {
|
||||
sourcePlayer = this.state.players.get(fromplayer);
|
||||
if (sourcePlayer.id !== dstplayer.id) {
|
||||
sourcePlayer.statData.inc(StateTypeEnum.CCOUNT, tmpCards.length);
|
||||
sourcePlayer.statData.zinc(StateTypeEnum.CCOUNT, tmpCards.length);
|
||||
}
|
||||
} else {
|
||||
sourcePlayer = player;
|
||||
|
@ -182,7 +182,7 @@ export class DiscardCommand extends Command<CardGameState, { client: Client, car
|
||||
cardMsg.cards = cards
|
||||
this.room.send(client, 'eat_card_s2c', cardMsg)
|
||||
let delay = this.room.battleMan.onCardLinkOver(player, cardArr, targetUser)
|
||||
player.statData.inc(StateTypeEnum.EATCOUNT, 1)
|
||||
player.statData.zinc(StateTypeEnum.EATCOUNT, 1)
|
||||
await this.delay(delay)
|
||||
let time = new GameEnv().playerActTime * 1000 + player.extraTime
|
||||
this.state.updateGameState(GameStateConst.STATE_PICK_PET)
|
||||
|
@ -77,7 +77,7 @@ export class EatConfirmCommand extends Command<CardGameState, { timeUp: boolean
|
||||
let currentPlayer = this.state.players.get(this.state.currentTurn);
|
||||
currentPlayer.cardQueue.clear();
|
||||
player.cardQueue.clear();
|
||||
player.statData.inc(StateTypeEnum.EATCOUNT, 1);
|
||||
player.statData.zinc(StateTypeEnum.EATCOUNT, 1);
|
||||
player.cardQueue.push(this.state.cards.values().next().value.clone());
|
||||
for (let id of cards) {
|
||||
if (!player.cards.has(id + '')) {
|
||||
|
@ -377,7 +377,7 @@ let gameUtil = {
|
||||
let teamMap: Map<number, number> = new Map()
|
||||
for (let [, player] of state.players) {
|
||||
if (player.state != PlayerStateConst.PLAYER_DEAD) {
|
||||
teamMap.inc(player.team, 1)
|
||||
teamMap.zinc(player.team, 1)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user