'use strict'; var quick = require('quick-pomelo'); var P = quick.Promise; var C = require('../../share/constant'); var logger = quick.logger.getLogger('score', __filename); // 构造方法 var Score = function (table) { this.table = table; this.app = table.game.app; this.scores = {}; }; // 导出类 module.exports = Score; // 原型对象 var proto = Score.prototype; // 获取分数 proto.getScore = function (playerId) { var scorer = this.scores[playerId]; if (!scorer) { return 0; } return scorer.score; }; // 设置分数 proto.writeScore = function (playerId, score, over) { // console.warn("设置分数 writeScore+++++",playerId, score, over) var scorer = this.scores[playerId]; if (scorer) { scorer.score += score; scorer.over += over; } }; //ts++ 设置钻石消耗 proto.writeCost = function (playerId, gameCost, giftCost) { var scorer = this.scores[playerId]; if (scorer) { scorer.gameCost += gameCost; scorer.giftCost += giftCost; } }; // 消费玩家 proto.addUser = function (playerId,chairId,userId, name, sex, headurl,diamond,gameKindTL) { let scoreTL = 0; // if(gameKindTL == 2) scoreTL = 200;/////冲刺最多输200 var scorer = this.scores[playerId]; if (!scorer) { // console.warn("消费玩家++++++new:",chairId,diamond,agentId) agentId: agentId, scorer = { playerId:playerId,chairId:chairId,userId: userId, name: name, sex: sex, headurl: headurl, over: 0, score: scoreTL,diamond:diamond,gameCost: 0,giftCost: 0 }; this.scores[playerId] = scorer; } else { // console.warn("消费玩家+++++upd",diamond) scorer.chairId = chairId; scorer.score = scoreTL; scorer.diamond = diamond; scorer.gameCost = 0; scorer.giftCost = 0; } return scorer; }; // tl++,设置玩家chairID proto.setUserChair = function (playerId,chairId) { if (this.scores[playerId]) { this.scores[playerId].chairId = chairId; } }; // 删除玩家 proto.delUser = function (playerId) { if (this.scores[playerId]) { delete this.scores[playerId]; } }; // 是否消费 proto.isFeed = function (playerId) { return !!this.scores[playerId]; }; // 获得玩家 sort proto.getUsers = function () { var scorers = []; for (let id in this.scores) { let scorer = this.scores[id]; if (scorer.over > 0) {//ts-- scorers.push(scorer); } } return scorers; }; // 获得玩家 proto.getUser = function (playerId) { var scorer = this.scores[playerId]; if (scorer) return scorer; }