'use strict'; var util = require('util'); var quick = require('quick-pomelo'); var P = quick.Promise; var cor = P.coroutine; var _ = require('lodash');/////是一个一致性、模块化、高性能的 JavaScript 实用工具库。 //// 为什么选择 Lodash ? //// Lodash 通过降低 array、number、objects、string 等等的使用难度从而让 JavaScript 变得更简单。 //// Lodash 的模块化方法 非常适用于: //// 遍历 array、object 和 string //// 对值进行操作和检测 //// 创建符合功能的函数 var uuid = require('node-uuid'); var Logic = require('./logic'); var User = require('./user'); var Score = require('./score'); var conf = require('../config/games').csjiang || {}; var M = require('../../share/message'); var C = require('../../share/constant'); var paiJuHuiFang = require('../../share/paiJuHuiFang');//////TL++ 牌局回放 var configCommon = require('../../share/configCommon');//////TL++配置相关的公共方法 var setReabte = require('../../share/setReabte');//////TL++记录返利相关的公共方法 var logger = quick.logger.getLogger('fhmj', __filename); // 桌子状态 var STATE = { FREE: 1, PLAYING: 2, FREE2: 3 , END: 4};//ts++REFREE 二次空闲 END结束 // 结算模式 var MODE = { NORMAL: 1, NOCARD: 2, OFFLINE: 3 }; //ts++结束模式 空闲0,游戏中1, 正常结束3,房主解散3,断线解散4,断线解散5,系统解散6 var ENDMODE = { FREE: 0,PLAYING: 1, OWNEREND: 2,NORMALEND: 3,REGEND: 4, OFFLINEEND: 5, SYSTEMEND: 6 }; // 金币消耗 const COSTS = conf.sit_costs || {}; /////TL++,下面这几行为了记录用户行为 // var log4js2 = require("log4js");////cssj // var log4js_config2 = require("./logConf.json"); // log4js2.configure(log4js_config2); // var LogFile2 = log4js2.getLogger('log_file');////cssj var checkVersion = function () { // let confCodeVer = require('../config/csLogicVer').codeVer || {}; // console.warn("cs的table中检查logic版本111 "+JSON.stringify(confCodeVer)); // if(confCodeVer.csLogic){ // delete require.cache[require.resolve('../config/csLogicVer')]; // let confCodeVer2 = require('../config/csLogicVer').codeVer || {}; // console.warn("cs的table中检查logic版本222 "+confCodeVer.csLogic +" "+ confCodeVer2.csLogic); // if(confCodeVer.csLogic && confCodeVer2.csLogic && confCodeVer.csLogic != confCodeVer2.csLogic){ // delete require.cache[require.resolve('./logic')]; // Logic = require('./logic'); // console.warn("cs的table中的logic更新了 ") // } // } } // 构造方法 var Table = function (cPlayerId,cUserId,cName,cHead,game, id, cell, round, type,gameKindTL,playerAllCount,upId,other,agentId,yxndlbTime,yxndlbTip) { let str3 = "cstable构造方法.......id: "+id + " type " + type+" game "+game.id; // console.warn(str3);////cssj // checkVersion(); this.app = game.app; this.gameId = 10006; this.game = game; this.id = id; this.recordid = uuid.v1()+'_'+id;//ts++唯一记录 this.upId = upId;//ts++上局的ID this.type = type; this.agentId=agentId; this.yxndlbTime = yxndlbTime; this.yxndlbTip = yxndlbTip; this.other = other;//////TL++2人3人的游戏规则 // console.warn("cs222创建房间的other111 ",other,this.other," gameKindTL ",gameKindTL," type " ,type); this.jiangmaCount = 2;////奖码张数(抓鸟张数) this.kexuanList = [0,0,0,0];//可选列表 if(this.other & 1){ this.kexuanList[0] = 1;//中途四喜 } if(this.other & 2){ this.kexuanList[1] = 1;//中途六六顺 } if(this.other & 4){ this.kexuanList[2] = 1;//门清 } if(this.other & 256){ this.kexuanList[3] = 1;//小胡只能自摸 } this.hzCount = 0;/////红中个数 this.fengDingType = 0;/////封顶类型1:不封顶;2:封顶56分;3:封顶112分; if(this.other & 8){ this.fengDingType = 1; } else if(this.other & 16){ this.fengDingType = 2; } else if(this.other & 32){ this.fengDingType = 3; } this.ZNJSType = 0;/////中鸟结算类型1:中鸟相加;2:中鸟相乘; if(this.other & 64){ this.ZNJSType = 1; } else if(this.other & 128){ this.ZNJSType = 2; } this.gameKindTL = 1;//1:传统;2:割索;3:疯狂 if(this.other & 512){ this.gameKindTL = 2; } else if(gameKindTL == 3){ this.gameKindTL = 3;//疯狂 疯狂模式下有红中只能自摸 } if(this.gameKindTL == 3){ // console.warn("这是疯狂"); // delete require.cache[require.resolve('./logicfk')]; Logic = require('./logicfk'); } else{ Logic = require('./logic'); } var num_cost = 50; if(this.gameKindTL == 2){ num_cost =parseInt(COSTS[1]); } else if(this.gameKindTL == 3){ // delete require.cache[require.resolve('../config/games')]; let confcsfk = require('../config/games').csfkjiang || {}; let costscsfk = confcsfk.sit_costs || {}; num_cost =parseInt(costscsfk[round]) console.warn("这是疯狂 num_cost "+num_cost); } else { num_cost =parseInt(COSTS[round]); } // console.warn("玩法类型1:传统;2:割索; "+this.gameKindTL) // console.warn("封顶类型1:不封顶;2:封顶56分;3:封顶112分 "+this.fengDingType) // console.warn("中鸟结算类型1:中鸟相加;2:中鸟相乘 "+this.ZNJSType) // console.warn("可选列表 "+this.kexuanList) this.cost = num_cost; this.over = 0; this.round = round; this.stime = 0; this.ctime = Date.now(); this.etime = 0; this.lconfigCommon = null; // 人数 this.ccount = playerAllCount;//Logic.CHAIR_COUNT; this.mcount = Logic.CARDS_COUNT; // 房主 this.ownerChairId = -1;//房主的chairid this.ownerId = cPlayerId;//房主Id this.ownerUid = cUserId;//房主的userID this.ownerName = cName; this.ownerHeadUrl = cHead; // 数据 var logic = new Logic(type,gameKindTL,playerAllCount,other); this.logic = logic; this.score = new Score(this); this.handCards = Array(this.ccount); this.huCards = logic.fillDeep(Array(this.ccount), []); this.users = Array(this.ccount); this.chBanker = 0; this.quFeng = 0; this.bankFlag = 0; this.outCards = logic.fillDeep(Array(this.ccount), []); // 标记 this.isDihus = _.fill(Array(this.ccount), true); this.isTianhu = true; this.outCard = 0; this.outerId = -1; this.disCards = []; this.currentId = -1; // 包含字,总杠次,保留量 // this.hasWords = !(type & 2);/////TL++zs // this.hasWords = true;/////是否含有字牌/////TL++ // this.gonCount = 0; // this.disCounts = [26, 14, 16, 26];/////TL++zs // this.disCounts = [1,1,1,1,]; // 允许吃牌 this.hasEat = true;//!!(type & 4);////是否可吃牌 // 允许点炮 // this.hasEHu = true;///!!(type & 8);//没有用到 // 一炮多响 this.isMHu = true;//!!(type & 16); // 允许杠胡 this.hasGHu = true;///!!(type & 32); // 点炮出钱 this.isWOne = true;//!!(type & 64); // 权限:16-胡,8-杠,4-碰,2-吃,1-等待,0-无 this.masks = _.fill(Array(this.ccount), 0); this.excepts = logic.fillDeep(Array(this.ccount), {}); // 等待杠类型,1-普通杠, 2-暗杠, 3-自摸明杠 this.gangType = 0; this.gangCard = 0; this.qshType = [0,0,0,0];// this.qshCards = [[],[],[],[]];//起手胡操作的牌 被置于等待时记录玩家起手胡的操作 this.buType = 0; this.buCard = 0; this.pengCard = 0; this.currQSHInfo = [[],[],[],[]];//当前各个玩家展示的起手胡信息 this.keGangInfo = {chairId: -1,data:[]};////可杠信息,因为摸牌之后手上虽然有多个杠,但是没有听牌的话是不能杠的 this.autoOutTimer = null; this.everyIsAutoOut = _.fill(Array(this.ccount), 0); this.updataGangTimer = null;//////杠后两张牌都无权限的时候等一会儿再消失 this.gangAfterData = { chairId: -1, cards: {card1:0,card2:0}, canSelectData: [[],[],[],[]], mask: 0 } this.everyIsGang = [[0,0],[0,0],[0,0],[0,0]];/////每个人是否杠了,可以打的牌,0表示没有限制,如果杠了就只能摸啥打啥了 // 抢杠胡、被杠玩家 this.isGangHu = false; this.isBuHu = false; this.gangOuter = -1; // 等待吃类型,1-@**左吃, 2-*@*中吃, 3-@**右吃 this._eatType = 0; this._eatCard = 0; // 胡牌者 this.anams = Array(this.ccount); this.huRes = Array(this.ccount); this.winner = { lead: -1, chs: [] }; // 底分 this.cell = cell; // 围观者 this.lookers = []; //结束时的继线用户 this.leaveUsers = []; // 状态 this.state = STATE.FREE; // 申请结束标记 this.overFlag = 0; this.overTimer = null; this.endTableTime = 60;//////TL++,申请解散房间之后60秒之后不操作则认为同意解散 this.reqJieSan = [-1,-1,-1,-1];/////解散桌子数据,前面为chirid后面为情况-1:未操作 0:拒绝 1:同意 2为解散发起 //断线 结束定时器 this.endTimer = null; //////以下全为TL++ /////TL++,补花定时器,防止连续补花太快 this.PJHF = new paiJuHuiFang(); // this.buhuaTimeout = null; this.backStartTimer = null;//////重入之后系统会自动准备为了解决可能没牌的问题2秒之后才开始游戏 this.PaijuHuiFang = [];////TL++,牌局回放 // this.zhyzfgs = [-2,null,null];/////TL++,由于最后一张牌的摸牌被打断所以 用来记录最后一张牌的发牌函数的参数 // this.isLianGang = [-1,false,-1];/////TL++,连杠的玩家座位号,是否连杠 杠的牌 this.isYJJSGL = false;/////是否已经执行过结算函数了 this.isYJKSGL = false;/////是否已经执行过开始函数了 this.JSFJTimeout = null;//解散房间倒计时 this.JSFJTime = 60;//解散房间倒计时60秒 this.SQJSTime = null;//申请解散房间的时间,用于计算解散房间倒计时所剩的时间 this.gameNeverStart = true;//游戏是否从未开始过,用于解散房间判断 this.pjhffileName = [];//用于记录玩家牌局回放的json文件名 this.playerPosList = [[],[],[],[]];//记录玩家的位置信息数组 this.playerAllCount = playerAllCount || 4;//游戏人数 = 2表示2人局 = 3表示3人局 = 4表示4人局 this.isNeverStart = true;//游戏是否从未开始 this.sszjDataList = [];//设置实时战绩的数据 this.isEveryZZ = false;//是否每一个人都做过庄 // this.isZJYG = false;////本局庄家是否有杠 this.chairArry = [0,1,2,3];// this.everyHDLY = [-1,-1,-1,-1];//每个玩家海底捞月选择情况,不选择海底不能胡海底 // this.isNeverTounchHU = false;/////是否从未点击过胡按钮 //分别代表补,四喜,板板胡,缺一色,六六顺,中途四喜,中途六六顺满足之后让mask |= maskValeList[i] this.maskValeList = [32,64,128,256,512,1024,2048];//用来计算mask this.sszjs = [];//ts++实时战绩 this.LWKF = [10,10,10,10,10];//////TL++礼物扣费 this.isGameOk=false;//ts++牌局正常结束 this.agentRebate=0;//ts++本局的返利 // delete require.cache[require.resolve('../../share/setReabte')]; // setReabte = require('../../share/setReabte'); this.lsetReabte = new setReabte(this.app); }; // 导出状态 Table.STATE = STATE; //ts++ 结束模式 Table.ENDMODE = ENDMODE; // 导出类 module.exports = Table; // 原型对象 var proto = Table.prototype; // 是否站满 proto.isFull = function () { return (this.lookers.length >= 5); }; // 是否准备 proto.isReady = function () { for (let user of this.users) { if (!user || !user.isReady()) return false; } return true; }; // ts++是否二次准备 proto.isReady2 = function () { for (let user of this.users) { if (!user || !user.isReady2()) return false; } return true; }; // 是否游戏中 proto.isPlaying = function () { return this.state > STATE.FREE; }; // 是否全在线 proto.isOnline = function () { for (let user of this.users) { if (user && user.isOffline()) return false; } return true; }; // 是否全断线 proto.isOffline = function () { for (let user of this.users) { if (!user || !user.isOffline()) return false; } return true; }; // 是否空桌 proto.isEmpty = function () { if (this.lookers.length > 0) return false; for (let i = 0; i < this.users.length; ++i) { if (this.users[i]) return false; } return true; }; // 局数完成 proto.isGameOver = function () { let str3 = "cstable 局数完成 .......id: "+ this.id + " this.over " + this.over; logger.warn(str3);////cssj if(this.gameKindTL == 2){ for (let i = 0; i < this.users.length; ++i) { let user = this.users[i]; if (user) { let score = this.score.getScore(user.id); // console.warn("割索在判断是否可以总结算了 每个人目前的分数",score); if(score <= 0) return true; } } return false; } else { return (this.over >= this.round); } }; // 重置本局 proto.resetRound = function () { _.fill(this.handCards, null); _.fill(this.isDihus, true); this.isTianhu = true; _.fill(this.masks, 0); this.logic.fillDeep(this.excepts, {}); _.fill(this.huRes, null); // this.gonCount = 0; this.winner.chs = []; this.winner.lead = -1; this.logic.fillDeep(this.huCards, []); this.logic.fillDeep(this.outCards, []); this.outCard = 0; this.outerId = -1; this.currentId = -1; this._eatType = 0; this._eatCard = 0; this.gangType = 0; this.gangCard = 0; this.pengCard = 0; this.qshType = [0,0,0,0];// this.qshCards = [[],[],[],[]];//起手胡操作的牌 this.currQSHInfo = [[],[],[],[]];//当前各个玩家展示的起手胡信息 this.keGangInfo = {chairId: -1,data:[]};//可杠信息,因为摸牌之后手上虽然有多个杠,但是没有听牌的话是不能杠的 if(this.autoOutTimer) { clearTimeout(this.autoOutTimer); this.autoOutTimer = null; } this.everyIsAutoOut = _.fill(Array(this.ccount), 0); this.gangAfterData = { chairId: -1, cards: {card1:0,card2:0}, canSelectData: [[],[],[],[]], mask: 0 } this.everyIsGang = [[0,0],[0,0],[0,0],[0,0]];/////每个人是否杠了,如果杠了就只能摸啥打啥了 this.buType = 0; this.buCard = 0; this.isGangHu = false; this.isBuHu = false; this.gangOuter = -1; this.everyHDLY = [-1,-1,-1,-1];//每个玩家海底捞月选择情况,不选择海底不能胡海底 }; // 发送消息 proto.pushMsgAsync = cor(function* (cidOrIds, route, msg) { var playerIds = []; if (Array.isArray(cidOrIds)) playerIds = cidOrIds; else { if (cidOrIds < 0 || cidOrIds >= this.users.length) { for (let user of this.users) { if (user) playerIds.push(user.id); } for (let lker of this.lookers) { playerIds.push(lker.id); } } else { let user = this.users[cidOrIds]; if (user) playerIds.push(user.id); // console.warn("555WWWWWWWTTTTTT",cidOrIds, route, user.name); } } if (playerIds.length > 0) { let channelId = 'xct:' + this.id; // console.warn("666WWWWWWWTTTTTT",cidOrIds, route, playerIds,msg); return this.app.controllers.push._pushAsync(channelId, playerIds, route, msg); } }); // 围观消息 proto.lookMsgAsync = cor(function* (route, msg) { var playerIds = []; for (let lker of this.lookers) { playerIds.push(lker.id); } if (playerIds.length > 0) { let channelId = 'xct:' + this.id; return this.app.controllers.push._pushAsync(channelId, playerIds, route, msg); } }); // 获得桌子信息 proto.getTableInfo = function () { // 桌子信息 let endTableTime = Math.floor((this.SQJSTime - Date.now())/1000); var tableInfo = { id: this.id, gameId: this.gameId, type: this.type, cost: this.cost, over: this.over, round: this.round, users: [], lookers: [], ownerId: -1,//this.ownerChairid ownerUserId: this.ownerUid,////TL++,房主的userID ownerName: this.ownerName,//////TL++,房主的昵称 ownerHeadUrl: this.ownerHeadUrl,//////TL++,房主的头像地址 gameKindTL: this.gameKindTL,////平搓还是冲刺 = 1代表平搓 = 2代表冲刺 playerAllCount: this.playerAllCount,////游戏人数 = 2表示2人局 = 3表示3人局 = 4表示4人局 other: this.other, creatTime : this.ctime, nowTime : Date.now(), state: this.state, sszjDataList: this.sszjDataList,////TL++,设置实时战绩的数据 isZHYZ: this.logic.isZHYZ, /////TL++,是否最后一张 playerPosList: this.playerPosList,/////TL++玩家位置数据 chairArry: this.chairArry,/////TL++ isNeverStart: this.isNeverStart,/////TL++,游戏是否从未开始 overFlag:this.overFlag,//ts++房间解散标识 endTableTime:endTableTime, recordid:this.recordid, yxndlbTime:this.yxndlbTime, yxndlbTip:this.yxndlbTip, reqJieSan:this.reqJieSan }; // 正在游戏 var isPlaying = this.isPlaying(); if (isPlaying) { tableInfo.qFeng = this.quFeng; tableInfo.banker = this.chBanker; tableInfo.stime = Date.now() - this.stime; tableInfo.currentId = this.currentId; tableInfo.disCards = this.disCards; tableInfo.lastCount = this.logic.leaveCount(); tableInfo.isGangHu = this.isGangHu; tableInfo.gangCard = this.gangCard||this.buCard; //////TL++,游戏过程中重入 tableInfo.baiDaCard = String(this.logic.baiDaCard);//////TL++,本局百搭牌 tableInfo.everyFllowerCardList = [[],[],[],[]]; /////每个人手上的花牌 tableInfo.currQSHInfo = this.currQSHInfo; tableInfo.isCanOut = this.logic.getIsCanOut(this.masks); //////TL++ end,游戏过程中重入 } // 桌上玩家 for (let i = 0; i < this.users.length; ++i) { let user = this.users[i]; if (user) { let score = this.score.getScore(user.id); let uinfo = { account: user.account, name: user.name, sex: user.sex, headurl: user.headurl, state: user.state2, score: score, chairId: user.chairId }; if (isPlaying) { let huCards = []; for (let huCard of this.huCards[i]) { huCards.push({ style: huCard.style, type: huCard.type, card: huCard.cards[0], origin: huCard.origin }); } uinfo.huCards = huCards; uinfo.outCards = this.outCards[i]; let handCard = this.handCards[i] || []; uinfo.handCount = handCard.length; } tableInfo.users.push(uinfo); } } // 围观玩家 for (let i = 0; i < this.lookers.length; ++i) { let user = this.lookers[i]; if (user) { tableInfo.lookers.push({ account: user.account, name: user.name, sex: user.sex, headurl: user.headurl }); } } return tableInfo; }; // 回到桌子 proto.backAsync = cor(function* (user) { let str3 = "cstable回到桌子.......id: "+ this.id + " user.chairId: " + user.chairId + " user.name: " + user.name ; logger.warn(str3);////cssj user.offlinetime=0;//ts++ var data = { chairId: String(user.chairId) }; var chairId = user.chairId; let isGuoHuList = [[false,-1],[false,-1],[false,-1],[false,-1]]; if (chairId != -1) { // 加入频道 var connectorId = user.connectorId || ''; if (connectorId) { let channelId = 'xct:' + this.id; yield this.app.controllers.push._joinAsync(channelId, user.id, connectorId); } // 恢复状态 let str2 = "cstable回到桌子111.......id: "+ this.id + " chairId: " + chairId + " state: " + this.state ; logger.warn(str2);////cssj if (this.state == STATE.FREE) { yield this.readyGameAsync(user); } else if (this.state == STATE.PLAYING) { //user.state = User.STATE.PLAYING;//ts-- user.state2 = User.STATE.PLAYING;//ts++ data.mask = String(this.masks[chairId]); data.handCards = this.handCards[chairId]; // 状态通知 yield this.pushMsgAsync(-1, 'csjiang_event', { type: M.STATE_CHANGE, data: { chairId: String(user.chairId), state: String(user.state2), state2: String(user.state2) } }); }else if (this.state == STATE.FREE2) {//ts++二次准备 //user.state = User.STATE.PLAYING;//ts-- let str1 = "cstable回到桌子222.......id: "+ this.id + " chairId: " + chairId; logger.warn(str1);////cssj user.state2 = User.STATE.READY; yield this.pushMsgAsync(-1, 'csjiang_event', { type: M.STATE_CHANGE, data: { chairId: String(user.chairId), state: String(user.state2), state2: String(user.state2) } }); if (this.isReady2() && !this.isGameOk) { let str0 = "cstable回到桌子333.......id: "+ this.id + " chairId: " + chairId; logger.warn(str0);////cssj if(!this.backStartTimer){ let str00 = "cstable回到桌子444.......id: "+ this.id + " chairId: " + chairId; logger.warn(str00);////cssj this.backStartTimer = this.app.timer.setTimeout(() => this.backStartTimeAsync(), 2 * 1000);//延迟2秒开始游戏 } } } // 取消计时 if (this.isOnline() && this.endTimer) { clearTimeout(this.endTimer); this.endTimer = null; } isGuoHuList[chairId] = this.logic.isGuoHuList[chairId]; } // 数据处理 data.fee = this.score.isFeed(user.id) ? '0' : '1'; data.table = this.getTableInfo(); let hutipdata = { renyi:0,//////是否可胡任意牌,0表示不满足1表示满足 kehuData:[]/////对象数组,分别表示打哪张可胡哪几张数据 }; if(chairId == this.currentId){ let tipres = this.logic.hutip(this.currentId,this.handCards[this.currentId],this.huCards[this.currentId],this.huCards,this.outCards);////重入时调用胡牌提示 data.table.hutipdata = tipres; } else{ data.table.hutipdata = hutipdata; } let isAutoOut = 0; if (chairId != -1) { isAutoOut = this.everyIsAutoOut[chairId]; } data.table.isAutoOut = isAutoOut; data.table.isGuoHuList = isGuoHuList; data.table.canSelects = []; data.table.isGangInfo = [0,0];/////每个人是否杠了,如果杠了就只能摸啥打啥了 let keGangInfo = {chairId: -1,data:[]};//可杠信息,因为摸牌之后手上虽然有多个杠,但是没有听牌的话是不能杠的 if(chairId == keGangInfo.chairId) keGangInfo = this.keGangInfo; data.table.keGangInfo = keGangInfo; if (chairId != -1) { data.table.isGangInfo = this.everyIsGang[chairId];/////每个人是否杠了,如果杠了就只能摸啥打啥了 data.table.canSelects = this.logic.canSelects[chairId]; data.table.gangAfterData = { chairId: this.gangAfterData.chairId, cards: this.gangAfterData.cards, canSelectData: this.gangAfterData.canSelectData[chairId], mask: this.gangAfterData.mask } } return { code: C.OK, data: data }; }); //ts++重入后自动开始 proto.backStartTimeAsync = cor(function* () { let str00 = "cstable重入后自动开始..id: "+ this.id; logger.warn(str00);////cssj yield this.startGameAsync(); }); // 加入桌子 proto.joinAsync = cor(function* (user) { // 撤出删除队列 //this.game.cancelDelete(this.id); // 加入桌子之前 yield this.beforeJoinAsync(user); // 加入围观者 this.lookers.push(user); // 加入桌子之后 yield this.afterJoinAsync(user); // 数据返回处理 var data = { chairId: String(user.chairId) }; data.fee = this.score.isFeed(user.id) ? '0' : '1'; data.table = this.getTableInfo(); return { code: C.OK, data: data }; }); // 加入桌子之前 proto.beforeJoinAsync = cor(function* (user) { var connectorId = user.connectorId || ''; if (connectorId) { let channelId = 'xct:' + this.id; return this.app.controllers.push._joinAsync(channelId, user.id, connectorId); } }); // 加入桌子之后 proto.afterJoinAsync = cor(function* (user) { // 加入通知 return this.pushMsgAsync(-1, 'csjiang_event', { type: M.JOIN, data: { account: user.account, userId: user.userId, name: user.name, sex: user.sex, headurl: user.headurl,playerPosList: this.playerPosList } }); }); // 坐下桌子 proto.seatAsync = cor(function* (user, chairId) { // let chairId = this.chairArry[_chairId]; // console.warn("坐下桌子不不vvvvvv",chairId,_chairId,this.chairArry,this.users.length); // 参数校验 if (chairId < 0 || chairId >= this.ccount) { return { code: C.FAILD, msg: C.CHAIR_NOT_FOUND }; } if (this.users[chairId]) { // console.warn("坐下桌子死了vv000",this.users[chairId]); // console.warn("坐下桌子死了vvvvvv",this.users.length,this.users); return { code: C.FAILD, msg: C.CHAIR_HAS_SOMEONE }; } // 查找玩家 var player = yield this.app.models.Player.findByIdAsync(user.id, 'diamond cost'); if (!player) { return { code: C.FAILD, msg: C.PLAYER_NOT_FOUND }; } if (this.users[chairId]) { return { code: C.FAILD, msg: C.CHAIR_HAS_SOMEONE }; } // 调换座位 if (user.chairId != -1) { return this.changeChairAsync(user, chairId); } // 围观玩家 var pos = _.findIndex(this.lookers, (u) => (u.id == user.id)); if (pos == -1) { return { code: C.FAILD, msg: C.TABLE_NOT_USER }; } //ts++ let dSource=player.diamond; let dNow=player.diamond; //坐下花费 var costdata = null; if (!this.score.isFeed(user.id)) { if (player.diamond < this.cost) { return { code: C.FAILD, msg: C.GAME_DIAMOND_LOW }; }//////TL++zsyl 1000局测完之后要放出来的 player.diamond -= this.cost; player.cost = (player.cost || 0) + this.cost; dNow-=this.cost; this.score.addUser(user.id,chairId,user.userId, user.name, user.sex, user.headurl,user.diamond,this.gameKindTL); costdata = { cost: String(this.cost) }; } // 坐下处理 this.lookers.splice(pos, 1); this.users[chairId] = user; user.chairId = chairId; user.state = User.STATE.READY; yield this.afterSeatAsync(user); if (player.isModified()) { yield player.saveAsync();/////只有第一次坐下的时候才会执行 // 钻石记录 var diamondrecord = new this.app.models.DiamondRecord({ _id: uuid.v1(), playerId: user.id, dType: 3,//坐下 dSource: dSource, dSwap: -1*this.cost, dNow: dNow, tableId: this.recordid }); yield diamondrecord.saveAsync(); // console.warn("ts++坐下-------------------钻石记录"); if (costdata) yield this.pushMsgAsync(chairId, 'csjiang_event', { type: M.COST_FEE, data: costdata }); } // if (this.isReady()) yield this.pushMsgAsync(this.ownerChairid, 'csjiang_event', { type: M.START_BUTTON });//////TL++zsyl所有人准备之后通知房主点击开始游戏 if (this.state == STATE.FREE && this.isReady() && !this.isGameOk) { yield this.randomChangeChairTL(); } return { code: C.OK, chairId: String(chairId) }; }); // 调换座位 自己坐下之后点击另外一个位子的时候调用这个方法 这个参数user输出之后相当的长 proto.changeChairAsync = cor(function* (user, chairId) { if (this.state != STATE.FREE) { return { code: C.FAILD, msg: C.TABLE_NOT_FREE }; } if (this.users[chairId]) { return { code: C.FAILD, msg: C.CHAIR_HAS_SOMEONE }; } // var _chairId = user.chairId; // delete this.users[_chairId]; // this.users[chairId] = user; // user.chairId = chairId; // user.state = User.STATE.READY; // yield this.pushMsgAsync(-1, 'csjiang_event', { type: M.CHAIR_CHANGE, data: { oldId: String(_chairId), newId: String(chairId), state: String(user.state), state2: String(user.state2) } }); // // if (this.ownerChairid == _chairId) { // // this.ownerChairid = chairId; // // // 换房主通知 // // yield this.pushMsgAsync(-1, 'csjiang_event', { type: M.OWNER_CHANGE, data: { ownerChairid: String(this.ownerChairid) } }); // // } return { code: C.OK, chairId: String(chairId) }; }); // 坐下桌子之后 proto.afterSeatAsync = cor(function* (user) { let posListTL = { chairId: user.chairId, headurl: user.headurl, longitude: user.longitude, // 经度,浮点数,范围为180 ~ -180。 latitude: user.latitude, // 纬度,浮点数,范围为90 ~ -90 } this.playerPosList[user.chairId] = posListTL/////TL++记录玩家的位置信息数组 // 坐下通知 let score = this.score.getScore(user.id); yield this.pushMsgAsync(-1, 'csjiang_event', {///////发送坐下 type: M.SEAT, data: { account: user.account, name: user.name, sex: user.sex, headurl: user.headurl, state: String(user.state), score: String(score), chairId: String(user.chairId), userId: String(user.userId), playerPosList: this.playerPosList, /////TL++记录玩家的位置信息数组 } }); }); //////TL++,在首次游戏开始的时候随机打乱用户的座位 proto.randomChangeChairTL = cor(function* () { // console.warn("111在首次游戏开始的时候随机打乱用户的座位",this.users[0].name,this.users[1].name,this.users[2].name,this.users[3].name); // console.warn("1在首次游戏开始的时候随机打乱用户的座位",this.users[0].chairId,this.users[1].chairId,this.users[2].chairId,this.users[3].chairId); if(this.playerAllCount > 2){ let changeResult = []; if (this.over <= 0) {///////本房间开始的第一局游戏 // for (let i = 0; i < this.ccount; i++) {/////这种随机4次可能会导致4次随机之后和打乱之前的顺序一样所以弃用 for (let i = 0; i < 1; i++) { let oldchaieID = i; let olduser = this.users[i]; let newchaieID = Math.floor(Math.random()*this.playerAllCount);////// 区间[0,3]取整数 while (newchaieID == oldchaieID) { newchaieID = Math.floor(Math.random()*this.playerAllCount);////// 区间[0,3]取整数 } let newuser = this.users[newchaieID]; // console.warn("222在首次游戏开始的时候随机打乱用户的座位",oldchaieID,newchaieID); // console.warn("xxxxxxxxx删除有没有用啊",this.users.length); delete this.users[newchaieID]; delete this.users[oldchaieID]; // console.warn("xxxxxxxxx22删除有没有用啊",this.users.length); this.users[newchaieID] = olduser; this.users[newchaieID].chairId = newchaieID; // this.users[newchaieID].id = newuser.id; this.users[oldchaieID] = newuser; this.users[oldchaieID].chairId = oldchaieID; // this.users[oldchaieID].id = olduser.id; changeResult.push([oldchaieID,newchaieID]) } // console.warn("333在首次游戏开始的时候随机打乱用户的座位",this.users[0].name,this.users[1].name,this.users[2].name,this.users[3].name); // console.warn("3在首次游戏开始的时候随机打乱用户的座位",this.users[0].chairId,this.users[1].chairId,this.users[2].chairId,this.users[3].chairId); // console.warn("3在首次游戏开始的时候随机打乱用户的座位",this.users[0].id,this.users[1].id,this.users[2].id,this.users[3].id); // console.warn("3在首次游戏开始的",this.users[0]); ////// this.users 发送给前端会代码报错 // yield this.pushMsgAsync(-1, 'csjiang_event', { type: M.CHAIR_DALUAN, data: { changeResult:changeResult } }); /////TL++ for (let i = 0; i < this.users.length; ++i) { this.score.setUserChair(this.users[i].id,this.users[i].chairId) } let daluanData = []; var isPlaying = this.isPlaying(); for (let i = 0; i < this.users.length; ++i) { let user = this.users[i]; if (user) { let score = this.score.getScore(user.id); let uinfo = { account: user.account, name: user.name, sex: user.sex, headurl: user.headurl, state: user.state, score: score, chairId: user.chairId }; if (isPlaying) { let huCards = []; for (let huCard of this.huCards[i]) { huCards.push({ style: huCard.style, type: huCard.type, card: huCard.cards[0], origin: huCard.origin }); } uinfo.huCards = huCards; uinfo.outCards = this.outCards[i]; let handCard = this.handCards[i] || []; uinfo.handCount = handCard.length; } daluanData.push(uinfo); } } // this.score.delUser(user.id); yield this.pushMsgAsync(-1, 'csjiang_event', { type: M.CHAIR_DALUAN, data: { daluanData:daluanData } }); } } // console.warn("444在首次游戏开始的时候随机打乱用户的座位",changeResult); // this.starTimer = this.app.timer.setTimeout(() => this.startGameAsync(), 500); yield this.startGameAsync()/////TL++,在首次游戏的时候随机打乱用户的座位 }); // 站起桌子 proto.standAsync = cor(function* (user) { let str3 = "cstable 站起桌子.......id: "+ this.id + " user.chairId: " + user.chairId + " user.name: " + user.name ; logger.warn(str3);////cssj var chairId = user.chairId; if (chairId != -1) { user.state = User.STATE.FREE; delete this.users[chairId]; delete this.handCards[chairId]; user.chairId = -1; this.lookers.push(user); yield this.afterStandAsync(user, chairId); } return { code: C.OK }; }); // 站起桌子之后 proto.afterStandAsync = cor(function* (user, chairId) { // 站起通知 yield this.pushMsgAsync(-1, 'csjiang_event', { type: M.STAND, data: { chairId: String(chairId) } }); //if (this.ownerChairid == -1) this.ownerChairid = -1;//////TL++,房主坐下之后重置房主chairid /////TL++,作坐下的玩家离开桌子之后将他的位置信息从位置列表里面删除 if(chairId != -1) this.playerPosList[chairId] = []; // 桌主离开 //////TL++zsyl,原先的这个逻辑是房主站起之后会切换房主 // if (chairId == this.ownerChairid) { // let newCid = _.findIndex(this.users, (user) => user); // this.ownerChairid = newCid; // if (newCid != -1) this.ownerUid = this.users[newCid].id; // // 换房主通知 // yield this.pushMsgAsync(-1, 'csjiang_event', { type: M.OWNER_CHANGE, data: { ownerChairid: String(this.ownerChairid) } }); // } //是否退费 // console.warn("ts++++++++站起桌子之后"); var scorer = this.score.getUser(user.id); if (scorer && scorer.over <= 0) { // console.warn("ts++没有开始游戏退分",user.id); this.score.delUser(user.id); let player = yield this.app.models.Player.findByIdAsync(user.id, 'diamond cost'); if (player) { // console.warn("ts++没有开始游戏退分",player.diamond); let dSource=player.diamond; let dNow=player.diamond+this.cost; player.diamond += this.cost; player.cost -= this.cost; yield player.saveAsync(); //return this.app.controllers.player.pushAsync(user.id, 'csjiang_event', { type: M.BACK_FEE, data: { back: String(this.cost) } }); // 退费 钻石记录 var diamondrecord = new this.app.models.DiamondRecord({ _id: uuid.v1(), playerId: user.id, dType: 4,//退费 dSource: dSource, dSwap: this.cost, dNow: dNow, tableId: this.recordid }); yield diamondrecord.saveAsync(); // console.warn("ts++退分-------------------钻石记录"); //var costdata = { cost: String(-1*this.cost) }; //if (costdata) yield this.pushMsgAsync(chairId, 'csjiang_event', { type: M.COST_FEE, data: costdata }); } } else { if(user.cost==0 && user.spreadId)//ts++推荐人奖励 { // let spreader = yield this.app.models.Player.findByIdAsync(user.spreadId, 'spreadCount spreadRebate'); // if (spreader) { // spreader.spreadCount += 1; // spreader.spreadRebate += 100; // yield spreader.saveAsync(); // } ////20200928因为现在的spreadId存的是userId,所以上面那段用不了了 if(!this.lconfigCommon) { // console.warn("邀请新人送钻石活动 this.lconfigCommon 不存在 "+this.etime); this.lconfigCommon = new configCommon(this.app); } let yxhdxx = this.lconfigCommon.getActiveOpenTime(1);//邀请新人送钻石活动是否开启和开始结束时间的信息 let isKQ = false;//邀请新人送钻石活动是否开启 if(yxhdxx && yxhdxx.open && yxhdxx.startTime && yxhdxx.endTime) isKQ = true; // console.warn("获取配置信息 yxhdxx "+JSON.stringify(yxhdxx)); if(isKQ && this.etime >= yxhdxx.startTime && this.etime < yxhdxx.endTime){ var cpopts = {}; cpopts['userId'] = parseInt(user.spreadId); let spreadList = yield this.app.models.Player.findMongoAsync(cpopts, 'spreadCount spreadRebate', { sort: { stime: 1 } });// if(spreadList.length == 1){ spreadList[0].spreadCount += 1; spreadList[0].spreadRebate += 100; yield spreadList[0].saveAsync(); } } } yield this.lsetReabte.updateDaterebateRecord(this.agentId,this.etime); // if(this.agentId) //正常结束的才能算 // { // if(this.agentRebate>0) // { // //console.warn("代理返利写分+++++"); // let gameCost2=this.agentRebate;//游戏消耗 // let agentRebate2=parseInt(this.agentRebate*this.rEBATERATE); // this.agentRebate=0; // var today = new Date(); // today.setHours(0); // today.setMinutes(0); // today.setSeconds(0); // today.setMilliseconds(0); // let nowverifyDate=today.getTime(); // var agenter = yield this.app.models.Agenter.findByIdAsync(this.agentId,'rebateOther rebateCount rebateAll rebateNow rebateOut verifyDate verifyRebate agentRate'); // if (agenter) // { // //日结算 // let verifyBool=false; // let verifyDate=0; // let verifyRebate=0; // //日奖励 // let dateAgentRate=0; // let dateRebate=0; // if(agenter.verifyRebate>0 && agenter.verifyDate!=nowverifyDate) // { // verifyBool=true; // verifyDate=agenter.verifyDate; // verifyRebate=agenter.verifyRebate; // dateAgentRate=agenter.agentRate; // agenter.rebateNow += verifyRebate; // agenter.rebateNow += dateRebate; // agenter.rebateOther += dateRebate; // agenter.rebateCount += dateRebate; // agenter.verifyRebate=0; // } // //修改代理数据 // agenter.rebateCount += agentRebate2; // agenter.rebateAll += agentRebate2; // agenter.verifyDate=nowverifyDate; // agenter.verifyRebate+= agentRebate2; // let rCount=agenter.rebateCount; // let rOther=agenter.rebateOther; // let rAll=agenter.rebateAll; // let rNow=agenter.rebateNow; // let rOut=agenter.rebateOut; // let rVerifyDate=agenter.verifyDate; // let rVerifyRebate=agenter.verifyRebate; // yield agenter.saveAsync(); // // console.warn("代理返利写分+++++agenter.saveAsync()"); // // 锁定返利记录 // if(verifyBool && verifyRebate>0) // { // var verifyrebateRecord = new this.app.models.RebateRecord({ // _id: uuid.v1(), // agentId:this.agentId, // tableId: '', // rType: 3, // rCount: rCount- agentRebate2, // rOther: rOther, // rAll: rAll- agentRebate2, // rNow: rNow, // rOut: rOut, // rSwap: verifyRebate, // rDateSwap: dateRebate, // rVerifyDate: verifyDate, // rVerifyRebate: 0 // }); // yield verifyrebateRecord.saveAsync(); // var daterebateRecord = new this.app.models.DateRebateRecord({ // _id: uuid.v1(), // agentId:this.agentId, // verifyDate: verifyDate, // verifyRebate: verifyRebate, // dateAgentRate: dateAgentRate, // dateRebate: dateRebate // }); // yield daterebateRecord.saveAsync(); // } // // 返利记录 // var rebateRecord = new this.app.models.RebateRecord({ // _id: uuid.v1(), // agentId:this.agentId, // tableId: this.recordid, // rType: 1, // rCount: rCount, // rOther: rOther, // rAll: rAll, // rNow: rNow, // rOut: rOut, // rSwap: agentRebate2, // rDateSwap: 0, // rVerifyDate: rVerifyDate, // rVerifyRebate: rVerifyRebate // }); // yield rebateRecord.saveAsync(); // // console.warn("返利记录+++++rebateRecord.saveAsync()"); // } // } // let gameRebate=0; // if(this.isGameOk) // { // gameRebate=parseInt(this.cost*this.rEBATERATE); // } // var today = new Date(); // today.setHours(0); // today.setMinutes(0); // today.setSeconds(0); // today.setMilliseconds(0); // let date=today.getTime(); // let countid=this.agentId+'-'+user.userId+'-'+date; // var playercount = yield this.app.models.PlayerCount.findByIdAsync(countid,'gameCount gameCost agentRebate time'); // if (playercount) // { // playercount.gameCount+=1; // playercount.gameCost+=this.cost; // playercount.agentRebate+=gameRebate; // playercount.time=Date.now(); // } // else // { // playercount = new this.app.models.PlayerCount({ // _id: countid, // agentId:this.agentId, // playerId: user.id, // userId: user.userId, // name: user.name, // date: date, // gameCount: 1, // gameCost: this.cost, // agentRebate: gameRebate, // time:Date.now() // }); // } // yield playercount.saveAsync(); // } // console.warn("活动奖励 下面开始进行判断 ",user.spreadId,user.registerTime,user.lastLoginTime); // let str11 = "hdjl xmksjxpd "+ this.id + " isGameOk: " + this.isGameOk + " userId: " + user.userId + " spreadId: " + user.spreadId + " registerTime: " + user.registerTime + " lastLoginTime: " + user.lastLoginTime ; // logger.warn(str11);////cssj // if(this.isGameOk && this.ccount == 4 && user.spreadId)//活动奖励 // { // // console.warn("活动奖励 至此是游戏正常结束而且玩家有推荐id",user.spreadId,user.registerTime,user.lastLoginTime); // ////正常结束而且该玩家有推荐人id // let acSTime = 1601481600000;////20201001零点的时间戳,活动开始时间 // let acETime = acSTime + 86400000*8;////20201008这天截止的时间戳 活动结束时间 // let xzsjc = Date.now(); // let str12 = "hdjl zcyxszcjseqwjytjr "+this.id + " userId: " + user.userId +" xzsjc: "+xzsjc; // logger.warn(str12);////cssj // if(xzsjc >= acSTime && xzsjc < acETime){ // if((user.registerTime >= acSTime && user.registerTime < acETime) || user.lastLoginTime < 1598889600000){ // // console.warn("活动奖励 至此该玩家是新用户",user.spreadId,user.registerTime,user.lastLoginTime); // let str13 = "hdjl zcgwjsxyh "+this.id + " userId: " + user.userId; // logger.warn(str13);////cssj // ////活动期间注册或者9月1号10月1日之间未登陆过的玩家 // var todayTL = new Date(); // todayTL.setHours(0); // todayTL.setMinutes(0); // todayTL.setSeconds(0); // todayTL.setMilliseconds(0); // let jrldsjc=todayTL.getTime();////今日零点时间戳 // let jrjssjc=jrldsjc + 86400000;////今日结束时间戳 // var opts = { stime: { $gte: jrldsjc, $lt: jrjssjc },type: { $gte: 1, $lt: 2 }}; // opts['sid'] = user.id; // let acrlist = yield this.app.models.ActiveRewardRecord.findMongoAsync(opts, '_id rewardtype totalfee type sid rid gameCount stime succtime succState', { sort: { stime: 1 } });// // if(acrlist.length == 0){ // // console.warn("活动奖励 活动期间今日该玩家产生新的记录",user.spreadId,user.registerTime,user.lastLoginTime); // let str14 = "hdjl hdqjjrgwjcsxdjl "+this.id + " userId: " + user.userId; // logger.warn(str14);////cssj // ////活动期间今日该玩家产生新的记录 // var activerewardrec = new this.app.models.ActiveRewardRecord({ // _id: uuid.v1(), // UUID // rewardtype: 0, // 奖励类型,0红包 // totalfee: 0, // 产生金额,红包为分 // type:1, //活动类型:1国庆签到2国庆邀请 // sid: user.id, // 产生奖励的玩家id // sname:user.name, // 产生奖励的玩家name // suid:user.userId, // 产生奖励的玩家userId // rid: user.id, // 此条奖励的受益玩家 // gameCount: 1, // 游戏局数 // stime: xzsjc, // 记录产生时间 // succtime: 0, // 任务完成时间,任务未完成的时候这里是0 // succState: 0 // 任务是否完成的状态,0:未完成1:已达成 // }); // yield activerewardrec.saveAsync(); // } // else{ // let str15 = "hdjl hdqjjrgwjyjcsgjl "+this.id + " userId: " + user.userId; // logger.warn(str15);////cssj // ////活动期间更新今日该玩家已经产生的记录 // let newre = acrlist[0]; // newre.gameCount++; // if(newre.gameCount >= 2){ // // console.warn("活动奖励 活动期间更新今日该玩家已经产生的记录",user.spreadId,user.registerTime,user.lastLoginTime); // let str16 = "hdjl hdqjgxjrgwjyjcsdjl "+this.id + " userId: " + user.userId + " gameCount: " + newre.gameCount; // logger.warn(str16);////cssj // ////完成为解散2局,该玩家完成了签到的任务了 // if(newre.gameCount == 2){ // newre.totalfee = 500; // newre.succtime = xzsjc; // newre.succState = 1; // } // yield newre.saveAsync(); // } // if(newre.gameCount == 2){ // var opts2 = { stime: { $gte: acSTime, $lt: acETime },type: { $gte: 2, $lt: 3 }}; // opts2['sid'] = user.id; // let acrlist2 = yield this.app.models.ActiveRewardRecord.findMongoAsync(opts2, 'rid', { sort: { stime: 1 } });// // let isneedcj = false;////是否需要创建邀请奖励产生记录 // if(acrlist2.length == 0){ // isneedcj = true; // // if(parseInt(acrlist2[0].rid) && parseInt(acrlist2[0].rid) == user.spreadId) isneedcj = true; // } // // console.warn("活动奖励 完成未解散2局,该玩家的推荐人完成了邀请的任务了",user.spreadId,user.registerTime,user.lastLoginTime); // let str17 = "hdjl csgwjdyqjl "+this.id + " userId: " + user.userId + " isneedcj: " + isneedcj; // logger.warn(str17);////cssj // if(isneedcj){ // ////完成为解散2局,该玩家的推荐人完成了邀请的任务了 // var activerewardrec = new this.app.models.ActiveRewardRecord({ // _id: uuid.v1(), // UUID // rewardtype: 0, // 奖励类型,0红包 // totalfee: 500, // 产生金额,红包为分 // type:2, //活动类型:1国庆签到2国庆邀请 // sid: user.id, // 产生奖励的玩家id // suid:user.userId, // 产生奖励的玩家userId // sname:user.name, // 产生奖励的玩家name // rid: user.spreadId,// 此条奖励的受益玩家 // gameCount: newre.gameCount, // 游戏局数 // stime: xzsjc, // 记录产生时间 // succtime: xzsjc, // 任务完成时间,任务未完成的时候这里是0 // succState: 1 // 任务是否完成的状态,0:未完成1:已达成 // }); // yield activerewardrec.saveAsync(); // } // } // } // } // } // } // let str4 = "cstable 222 站起桌子之后---id:%s"+this.id + " uid"+user.userId+" "+ this.state; // logger.info(str4);////cssj } }); // 玩家断线 proto.offlineAsync = cor(function* (user) { let str3 = "cstable 玩家断线.......id: "+ this.id + " user.chairId: " + user.chairId + " user.name: " + user.name ; logger.warn(str3);////cssj if (user.chairId != -1) { //user.state = User.STATE.OFFLINE;//ts-- user.state2 = User.STATE.OFFLINE;//ts++ user.offlinetime = Date.now();//ts++断线 var channelId = 'xct:' + this.id; yield this.app.controllers.push._quitAsync(channelId, user.id); yield this.pushMsgAsync(-1, 'csjiang_event', { type: M.STATE_CHANGE, data: { chairId: String(user.chairId), state: String(user.state2), state2: String(user.state2) } }); // 无人在线 // console.warn("提前结算666"); //if (this.isOffline()) return this.overTimeAsync(MODE.OFFLINE); // console.warn("玩家断线-------定时器启动"); // 计时结算 if (!this.endTimer) this.endTimer = this.app.timer.setTimeout(() => this.overTimeAsync(ENDMODE.OFFLINEEND),600000);/////断线10分钟自动结算 // let str4 = "cstable 玩家断线---id:"+this.id + ",uid"+user.userId+" "+ this.state; // logger.info(str4);////cssj } }); // 离开桌子 proto.leaveAsync = cor(function* (user) { let str3 = "cstable 离开桌子.......id: "+ this.id + " user.chairId: " + user.chairId + " user.name: " + user.name ; logger.warn(str3);////cssj // this.leavePlayerID = user.id;//////TL++,旁观为房主的话离开之后由于从观战者列表里面删除了,导致发消息的时候他收不到离开桌子的消息 // console.warn("离开桌子、、、、、、、"); yield this.beforeLeaveAsync(user); var chairId = user.chairId; // yield this.pushMsgAsync(-1, 'csjiang_event', { type: M.LEAVE, data: { account: user.account } });/////TL++zs,原来在下面 if (chairId != -1) { delete this.users[chairId]; delete this.handCards[chairId]; yield this.afterStandAsync(user, chairId); } else { let pos = _.findIndex(this.lookers, (u) => (u.id == user.id)); if (pos != -1) this.lookers.splice(pos, 1); } return this.afterLeaveAsync(user); }); // 离开桌子之前 proto.beforeLeaveAsync = cor(function* (user) { var channelId = 'xct:' + this.id; return this.app.controllers.push._quitAsync(channelId, user.id); }); // 离开桌子之后 proto.afterLeaveAsync = cor(function* (user) { // 离开通知 /////TL++zsyl 在此之前离开玩家已经从玩家列表或者旁观者列表中删除了所以把下面这句提到前面去了 return this.pushMsgAsync(-1, 'csjiang_event', { type: M.LEAVE, data: { account: user.account } }); }); // 玩家准备 proto.readyGameAsync = cor(function* (user) { let str3 = "cstable 玩家准备.......id: "+ this.id + " user.chairId: " + user.chairId + " this.over: " + this.over + " user.name: " + user.name ; logger.warn(str3);////cssj // let str3 = "cstable 玩家准备---id:"+this.id + ",uid"+user.userId+","+ this.state; // logger.info(str3);////cssj if(this.state==STATE.FREE2)//ts++二次空闲 { user.state2 = User.STATE.READY; yield this.pushMsgAsync(-1, 'csjiang_event', { type: M.STATE_CHANGE, data: { chairId: String(user.chairId), state: String(user.state2), state2: String(user.state2) } }); if (this.isReady2() && !this.isGameOk) yield this.startGameAsync(); } else { user.state = User.STATE.READY; user.state2 = User.STATE.READY; yield this.pushMsgAsync(-1, 'csjiang_event', { type: M.STATE_CHANGE, data: { chairId: String(user.chairId), state: String(user.state2), state2: String(user.state2) } }); // console.warn("玩家准备玩家准备玩家准备 ",this.isReady() ,this.isGameOver()); if (this.isReady() && !this.isGameOk) yield this.startGameAsync(); } // let str4 = "cstable 222玩家准备---id:"+this.id + ",uid"+user.userId+","+ this.state; // logger.info(str4);////cssj return { code: C.OK }; }); // 开始游戏 proto.startGameAsync = cor(function* () { //this.backStartTimer = null;//////重入之后系统会自动准备为了解决可能没牌的问题2秒之后才开始游戏 let str4 = "cstable 开始游戏---id:"+this.id +" ,state "+ this.state +" 当前局 "+ (this.over+1); logger.warn(str4);////cssj if(this.isYJKSGL){ return; } this.isYJKSGL = true;/////是否已经执行过开始函数了 this.isYJJSGL = false;/////是否已经执行过结算函数了 if(this.backStartTimer) { clearTimeout(this.backStartTimer); this.backStartTimer = null; } // 状态设置 this.state = STATE.PLAYING; //this.setUserState(-1, User.STATE.PLAYING);//ts-- //ts++设置为游戏状态 for (let user of this.users) { if (user) { if(user.state == User.STATE.PLAYING)//ts++已经开始 { if(user.state2 == User.STATE.READY) { user.state2 = User.STATE.PLAYING user.offlinetime = 0; } } else//ts++第一次开始 { user.state = User.STATE.PLAYING user.state2 = User.STATE.PLAYING user.offlinetime = 0; } } } //ts++end let whdata = yield this.app.models.WHstate.findByIdReadOnlyAsync('wh', 'rebaterate yxndlbTime yxndlbTip'); // console.warn("22检查是否维护状态",whdata); if (whdata) { if(whdata.yxndlbTime) this.yxndlbTime = whdata.yxndlbTime; if(whdata.yxndlbTip) this.yxndlbTip = whdata.yxndlbTip; } this.PaijuHuiFang = [];////TL++,牌局回放 重置数据 this.lgkhCount = 0;/////TL++拉杠可胡玩家的数量 this.logic.isZHYZ = false;/////是不是最后1张 // this.logic.isNeedBuHua = false/////TL++在游戏开始的时候初始化是否需要补花 // this.isLianGang = [-1,false,-1];/////TL++,连杠的玩家座位号,是否连杠 在游戏开始的时候清空 // 初始信息 if (this.over <= 0) {///////本房间开始的第一局游戏 this.stime = Date.now(); // this.chBanker = this.ownerChairid;///////TL++zsyl this.chBanker = 0; //this.game.cancelDelete(this.id);//////TL++游戏第一次开始时候关闭房间20分钟未开始删除桌子 this.pjhffileName[this.pjhffileName.length] = this.PJHF.getjsonFileName(0,this.recordid,this.ctime);/////TL++,用于记录玩家牌局回放的json文件名 // console.error("000HHHHHHHHHHHHHHHHHHHHHH",this.pjhffileName.length,this.pjhffileName); this.PJHF.writePJHFJson(this.getTableInfo(),0,this.id);////在开始第一局的时候将桌子信息写入本地的json文件 this.isNeverStart = false;/////TL++,游戏是否从未开始 // yield this.randomChangeChairTL()/////TL++,在首次游戏的时候随机打乱用户的座位 } this.gameNeverStart = false;/////TL++,游戏是否从未开始过,用于解散房间判断 this.currentId = this.chBanker; this.isDihus[this.chBanker] = false; // 发手牌 把这句提前是为了洗牌之后能拿到百搭牌在游戏开始的时候给客户端发过去 let dice1 = this.logic.dice();/////骰子1的点数 let dice2 = this.logic.dice();/////骰子2的点数 var handCards = this.logic.handCards(this.chBanker,this.PJHF,this.over,this.recordid,this.ctime); if(this.playerAllCount == 4){ if(this.chBanker == 0) this.logic.isMZWF = [0,1,2,3];/////是不是满足位风 else if(this.chBanker == 1) this.logic.isMZWF = [3,0,1,2];/////是不是满足位风 else if(this.chBanker == 2) this.logic.isMZWF = [2,3,0,1];/////是不是满足位风 else if(this.chBanker == 3) this.logic.isMZWF = [1,2,3,0];/////是不是满足位风 } // } else if(this.playerAllCount == 3){ if(this.chBanker == 0) this.logic.isMZWF = [0,1,2,8];/////是不是满足位风 else if(this.chBanker == 1) this.logic.isMZWF = [3,0,1,8];/////是不是满足位风 else if(this.chBanker == 2) this.logic.isMZWF = [2,3,0,8];/////是不是满足位风 } else if(this.playerAllCount == 2){ if(this.chBanker == 0) this.logic.isMZWF = [0,2,8,8];/////是不是满足位风 else if(this.chBanker == 1) this.logic.isMZWF = [2,0,8,8];/////是不是满足位风 } //console.warn("ccccccccccccccccccccc当局的圈风",this.logic.fengQuan,this.chBanker); let scoreListTL = [] for (let i = 0; i < this.users.length; ++i) { let user = this.users[i]; if (user) { let score = this.score.getScore(user.id); scoreListTL[i] = score } } // 掷骰子 var sttGame = { banker: String(this.chBanker), qFeng: String(this.quFeng), stime: String(Date.now() - this.stime), baiDaCard: String(this.logic.baiDaCard),//////TL++,本局百搭牌 startNum1: String(dice1),////骰子点数 startNum2: String(dice2),////骰子点数 setCardFileName: String(this.logic.setCardFileName),////TL++设置手牌的文件名 scoreListTL:scoreListTL,/////TL++,每个玩家当前的分数列表 yxndlbTime:this.yxndlbTime, yxndlbTip:this.yxndlbTip, }; // console.warn("游侠开始*******************this.chBanker",this.chBanker); this.setPaijuHuiFangData(M.START_GAME,sttGame);/////TL++ 牌局回放 push游戏开始 // 开始通知 yield this.pushMsgAsync(-1, 'csjiang_event', { type: M.START_GAME, data: sttGame }); ////// 发手牌原来在这里 var lastCount = this.logic.leaveCount();/////TL++ for (let i = 0; i < handCards.length; ++i) { this.logic.qshuAnalyze(i,handCards[i].cards); // console.warn("发牌判断七首派 i "+i+" " +this.logic.everyQSHType[i]); for (let x = 0; x < this.logic.everyQSHType[i].length; ++x) { if(this.logic.everyQSHType[i][x] == 1){ this.masks[i] |= this.maskValeList[x+1]; } } } let isCanOut = this.logic.getIsCanOut(this.masks); for (let i = 0; i < handCards.length; ++i) { this.handCards[i] = handCards[i].cards;/////TL++zsyl if (i == this.chBanker) { let __isHu = false; let length = this.handCards[i].length; this.logic.isLaGang = false;//////TL++,是否刚刚被拉杠用于判断是否被拉杠胡 // this.logic.chengBaoTL = [[],[],[],[]]; // console.error("sscc3333胡牌分析 游戏开始i",i); let huRes = this.logic.huAnalyze(i,this.handCards[i], this.handCards[i][length - 1], this.huCards[i], true); // console.error("ssccDDD胡牌分析 huRes",huRes); if (huRes) { // let str3a = "cstable fpphcg:"+this.id + ",uid"+this.handCards[i]; // logger.info(str3a);////cssj __isHu = true; this.huRes[i] = huRes; } let res = this.logic.anGangAnalyze(this.handCards[i]); let isGang = (res.length > 0); if (isGang){ for (let x = 0; x < res.length; ++x) { if(this.logic.isCanGang(this.handCards[i],this.huCards[i],2,res[x].card)){ this.masks[i] |= this.maskValeList[0];//能杠肯定就能补 this.masks[i] |= 8; this.keGangInfo.chairId = i; this.keGangInfo.data.push({pos:2,card:res[x].card});////可杠信息,因为摸牌之后手上虽然有多个杠,但是没有听牌的话是不能杠的 } else{ this.masks[i] |= this.maskValeList[0]; } } } // if (isGang) this.masks[i] |= 8; if (__isHu) this.masks[i] |= 16; } let scards = { mask: String(this.masks[i]), canSelects: this.logic.canSelects[i], cards: handCards[i].cards, isCanOut: isCanOut, lastCount: String(lastCount) }; if (i == this.chBanker) scards.keGangInfo = this.keGangInfo; else scards.keGangInfo = {chairId: -1,data:[]}; ////发牌的胡牌提示 if (i == this.chBanker) { ////游戏开始时候的庄家的胡牌提示 scards.hutipdata = this.logic.hutip(this.chBanker,handCards[i].cards,this.huCards[i],this.huCards,this.outCards);////起手发牌调用胡牌提示 } else{ ////游戏开始时候的闲家的胡牌提示 scards.hutipdata = { renyi:0,//////是否可胡任意牌,0表示不满足1表示满足 kehuData:[]/////对象数组,分别表示打哪张可胡哪几张数据 }; } // 发牌通知 // console.error("sscc发牌通知 4条应该=================",i,handCards.lengt); yield this.pushMsgAsync(i, 'csjiang_event', { type: M.SEND_CARD, data: scards }); } let pjhfsplist = { shouPai:this.logic.deepCloneTL(this.handCards), maskList:this.logic.deepCloneTL(this.masks),/////TL++,10月28号,为了实现能看到每个玩家的操作 lastCount:String(this.logic.leaveCount()) } this.setPaijuHuiFangData(M.SEND_CARD,pjhfsplist);/////TL++ 牌局回放 push发牌数据 // 围观通知 var cardCounts = _.fill(Array(this.ccount), 0); for (let i = 0; i < cardCounts.length; ++i) { cardCounts[i] = this.handCards[i].length; } yield this.lookMsgAsync('csjiang_event', { type: M.SEND_CARD, data: { cardCounts: cardCounts, lastCount: String(lastCount) } }); let str3 = "cstable 222开始游戏---id:"+this.id +","+ this.state; logger.warn(str3);////cssj return { code: C.OK }; }); // 出牌 proto.outCardAsync = cor(function* (chairId, card) { let str3 = "cstable 出牌---id:"+this.id + " ,uid "+chairId+" this.masks "+ this.masks +" card "+card; logger.warn(str3);////cssj // console.warn("出牌出剖出牌",chairId,this.buhuaTimeout);///// 您正在补花,请稍后出牌。/////TL++,正在补花的时候不允许玩家出牌 // if(this.buhuaTimeout) return { code: C.FAILD, msg: C.GAME_BUHUA_ING }; // 校验顺序 if (this.currentId != chairId) { return { code: C.FAILD, msg: C.TABLE_TURN_ERROR }; } // 校验出牌 if(this.everyIsGang[chairId][0] && this.everyIsGang[chairId][1] != card) { return { code: C.FAILD, msg: C.TABLE_CARD_ERROR }; } if(this.autoOutTimer) { clearTimeout(this.autoOutTimer); this.autoOutTimer = null; } this.keGangInfo = {chairId: -1,data:[]};//可杠信息,因为摸牌之后手上虽然有多个杠,但是没有听牌的话是不能杠的 this.logic.chuPaiTL()////TL++,统计出牌个数,为了判断天胡和地胡 if(this.everyIsGang[chairId][0]) this.everyIsGang[chairId][1] = 100;//什么都不能出 // 吃椪杠胡 var pos = _.findIndex(this.masks, (m, i) => (i != chairId && m > 0)); if (pos != -1) { return { code: C.FAILD, msg: C.TABLE_TURN_ERROR }; } // 删除手牌 if (!this.logic.remove(this.handCards[chairId], card)) { return { code: C.FAILD, msg: C.TABLE_CARD_ERROR }; } // console.error("cstable 出牌---chairId "+chairId+" this.masks[chairId] "+this.masks[chairId]+" isGuoHuList "+JSON.stringify(this.logic.isGuoHuList)); if (this.masks[chairId] & 16){ this.logic.isGuoHuList[chairId][0] = true;/////TL++,设置过胡玩家的是否点击过胡为true 出牌 let pxgs = 0; for (let x = 0; x < this.logic.everyDAHType[chairId].length; ++x) { if(this.logic.everyDAHType[chairId][x] == 1) pxgs++; } this.logic.isGuoHuList[chairId][1] = pxgs;/////TL++,设置过胡玩家的是否点击过胡为true 出牌 let guohudataTL = { chairId:chairId, msg: "下次摸牌或满足更大牌型之前将不能胡牌", /////过胡通知 } let isGuoHuList = [[false,-1],[false,-1],[false,-1],[false,-1]]; isGuoHuList[chairId] = this.logic.isGuoHuList[chairId]; guohudataTL.isGuoHuList = isGuoHuList; ////过胡通知 yield this.pushMsgAsync(chairId, 'csjiang_event', { type: M.FHGUOHUTIP, data: guohudataTL }); this.logic.isLaGang = false;//////TL++,是否刚刚被拉杠用于判断是否被拉杠胡 } // 置空权限 if (this.masks[chairId] > 0) this.masks[chairId] = 0; // 置灰的牌 this.disCards = []; // 调整手牌 this.logic.adjust(this.handCards[chairId]); this.outCard = card; this.outerId = chairId; this.outCards[chairId].push(card); // 天胡地胡 if (this.isTianhu) this.isTianhu = false; if (this.isDihus[chairId]) this.isDihus[chairId] = false; // 忽略牌 this.excepts[chairId] = {}; let sfyrkh = false;//////TL++,是否有人可胡,没有的话海底捞月之后直接结算 let pjhfsplist = {}; // 吃碰杠胡 for (let i = 0; i < this.ccount; ++i) { let ocard = { chairId: String(chairId), card: String(card) }; // 排除自己 if (i != chairId) { ocard.isGuoHuList = [[false,-1],[false,-1],[false,-1],[false,-1]] let _isChi = false; let isPeng = false; let isGang = false; let __isHu = false; do { if(!this.everyIsGang[i][0]){ // 检测吃牌 if (this.hasEat && i == (chairId + 1) % this.ccount) {//// 以前是否可吃为可选项 let ress = this.logic.chiAnalyze(this.handCards[i], card); _isChi = (ress.length > 0); } // 忽略牌 if (this.excepts[i][card]) break;/////TL++zsyl.同一圈过碰之后不能再次碰的 // 检测碰牌 isPeng = this.logic.isPeng(this.handCards[i], card); // 忽略牌 // if (this.excepts[i][card]) break;/////TL++.为了解决同一圈过碰之后不能再次碰的问题 } let res = this.logic.gangAnalyze(this.handCards[i], card); isGang = !!res; if (isGang){ // console.error("出牌 函数里面 "); if(this.logic.isCanGang(this.handCards[i],this.huCards[i],1,card)){ if(!this.everyIsGang[i][0]){ this.masks[i] |= this.maskValeList[0];//能杠肯定就能补 } this.masks[i] |= 8; } else{ if(!this.everyIsGang[i][0]){ this.masks[i] |= this.maskValeList[0]; } } } this.logic.isLaGang = false;//////TL++,是否刚刚被拉杠用于判断是否被拉杠胡 let isZNZM = false; //疯狂模式下手上有红中只能自摸 if(this.gameKindTL == 3 && this.handCards[i].indexOf(51) != -1) isZNZM = true; let huRes = (!isZNZM) ? this.logic.huAnalyze(i,this.handCards[i], card, this.huCards[i]) : undefined; // console.error("ssccAAA胡牌分析 huRes",huRes); if (huRes) { // let str3a = "cstable cpphcg:"+this.id + ",uid"+this.handCards[i]; // logger.info(str3a);////cssj __isHu = true; this.huRes[i] = huRes; } } while (0); /////TL++,整个if if(this.logic.leaveCount() == 0 && this.logic.isZHYZ){ if (_isChi) _isChi = false; if (isPeng) isPeng = false; if (isGang) isGang = false; if(__isHu) sfyrkh = true } // 权限掩码 if (_isChi) this.masks[i] |= 2; if (isPeng) this.masks[i] |= 4; // if (isGang) this.masks[i] |= 8; if (__isHu) this.masks[i] |= 16; } else{ let isGuoHuList = [[false,-1],[false,-1],[false,-1],[false,-1]]; isGuoHuList[chairId] = this.logic.isGuoHuList[chairId]; ocard.isGuoHuList = isGuoHuList; this.changeCurrQSHInfo(chairId,M.OUT_CARD,0,card); } ocard.mask = String(this.masks[i]); ocard.keGangInfo = this.keGangInfo; // 出牌通知 yield this.pushMsgAsync(i, 'csjiang_event', { type: M.OUT_CARD, data: ocard }); if (i == chairId) { // let pjhfcp = ocard // pjhfcp.allMask = this.masks; pjhfsplist = { shouPai:this.logic.deepCloneTL(this.handCards), lastCount:String(this.logic.leaveCount()), ocard:this.logic.deepCloneTL(ocard), outCards:this.logic.deepCloneTL(this.outCards), isGuoHuList:this.logic.deepCloneTL(this.logic.isGuoHuList) } } if(i == (this.ccount - 1)){/////TL++if条件判断,10月28号,为了实现能看到每个玩家的操作 pjhfsplist.maskList = this.logic.deepCloneTL(this.masks);/////TL++,10月28号,为了实现能看到每个玩家的操作 this.setPaijuHuiFangData(M.OUT_CARD,pjhfsplist);/////TL++ 牌局回放 push出牌数据 } } // 被杠玩家 this.gangOuter = -1; // 围观通知 yield this.lookMsgAsync('csjiang_event', { type: M.OUT_CARD, data: { chairId: String(chairId), card: String(card) } }); // 全无权限 for (let i = 0; i < this.ccount; ++i) { if (this.masks[i] != 0) break; // 切换用户 if (i == this.ccount - 1) { // 下家摸牌 let nextId = (chairId + 1) % this.ccount; ///////TL++,整个if,因为海底捞月需要玩家自己去判断要不要摸牌 // console.warn("000 声剩余声剩余声剩"); let lastCount = this.logic.leaveCount();/////TL++xg yield this.touchCardAsync(nextId); ///////出牌摸牌 } } let str4 = "cstable end出牌---id:"+this.id + " ,uid "+chairId+" this.masks "+ this.masks +" card "+card; logger.warn(str4);////cssj return { code: C.OK }; }); ///////杠后摸牌函数 摸2张,有一张能胡则直接胡不能胡则两张直接打出 参数ifGang是否因为杠而摸牌 proto.touchCardAfterGang = cor(function* (chairId,ifGang) { // 状态校验 if (this.state != STATE.PLAYING) return; if (this.winner.chs.length > 0 || !this.users[chairId]) return; if (this.logic.isGuoHuList[chairId][0]) this.logic.isGuoHuList[chairId] = [false,-1];/////TL++,设置过胡玩家的是否点击过胡为false; 杠后摸牌 // 当前顺序 // this.currentId = chairId; // 摸牌 this.keGangInfo = {chairId: -1,data:[]};////可杠信息,因为摸牌之后手上虽然有多个杠,但是没有听牌的话是不能杠的 let isG = (ifGang && (ifGang == 1) || (ifGang == 2) || (ifGang == 3)) // console.warn("<<<<<<<<< isG,ifGang ",isG,ifGang) var moCard = this.logic.moCard(true); //因为开杠之后要摸2张牌所以要执行两遍下面这个方法 this.logic.moPaiTL(); this.logic.moPaiTL(); let moPaiIsCanHu = false;//////TL++,摸牌的人是否可以胡牌 this.everyIsGang[chairId] = [1,0]; let lastCount22 = this.logic.leaveCount();/////TL++xg this.logic.isLaGang = false;//////TL++,是否刚刚被拉杠用于判断是否被拉杠胡 let pjhfsplist = {}; if(ifGang){ /////杠牌,1-普通杠, 2-暗杠, 3-自摸明杠 if(ifGang == 1) this.logic.isGGMG[chairId] = true;//////TL++,是否刚刚直杠(明杠)用于判断是否是直杠杠开 if(ifGang == 2) this.logic.isGGAG[chairId] = true;//////TL++,是否刚暗杠用于判断是否暗杠杠开 if(ifGang == 3) this.logic.isGGFXG[chairId] = true;//////TL++,是否刚刚风险杠用于判断是否风险杠杠开 } this.keGangInfo = {chairId: -1,data:[]};////可杠信息,因为摸牌之后手上虽然有多个杠,但是没有听牌的话是不能杠的 for (let i = 0; i < this.ccount; ++i) { let __isHu = false; // let handCards1 = this.logic.deepCloneTL(this.handCards[chairId]); // handCards1.push(moCard.card1); let huRes1 = this.logic.huAnalyze(i,this.handCards[i], moCard.card1, this.huCards[i], false);//杠后摸牌判断第1张 // console.error("ssccBBB胡牌分析 huRes1",huRes1); if (huRes1) { // this.handCards[i].push(moCard.card1); __isHu = true; moPaiIsCanHu = true;/////TL++ this.huRes[i] = huRes1; } if (!__isHu){ // let handCards2 = this.logic.deepCloneTL(this.handCards[chairId]); // handCards2.push(moCard.card2); let huRes2 = this.logic.huAnalyze(i,this.handCards[i], moCard.card2, this.huCards[i], false);//杠后摸牌判断第2张 // console.error("ssccBBB胡牌分析 huRes2",huRes2); if (huRes2) { // let str3a = "cstable mpphcg:"+this.id + ",uid"+this.handCards[i]; // logger.info(str3a);////cssj // this.handCards[i].push(moCard.card2); __isHu = true; moPaiIsCanHu = true;/////TL++ this.huRes[i] = huRes2; } } if (__isHu){ this.masks[i] |= 16; } let canSelectData = []; //杠过的人不能吃碰补,可杠可胡 if(!this.everyIsGang[i][0]){ if (this.hasEat && i == (chairId + 1) % this.ccount) {//// 以前是否可吃为可选项 只能自摸情况下不能吃 let canChiList = []; let ress = this.logic.chiAnalyze(this.handCards[i], moCard.card1); let _isChi1 = (ress.length > 0); if(_isChi1) canChiList[canChiList.length] = moCard.card1; let ress2 = this.logic.chiAnalyze(this.handCards[i], moCard.card2); let _isChi2 = (ress2.length > 0); if(_isChi2) canChiList[canChiList.length] = moCard.card2; if(_isChi1 || _isChi2){ this.masks[i] |= 2; canSelectData.push({type:2,cards:canChiList}) } } let canPengList = []; let isPeng1 = this.logic.isPeng(this.handCards[i], moCard.card1); if(isPeng1) canPengList[canPengList.length] = moCard.card1; let isPeng2 = this.logic.isPeng(this.handCards[i], moCard.card2); if(isPeng2) canPengList[canPengList.length] = moCard.card2; if(isPeng1 || isPeng2){ this.masks[i] |= 4; canSelectData.push({type:4,cards:canPengList}) } } let canGangList = []; let canBuList = []; let isGang1 = false; let isBu1 = false; let res = this.logic.gangAnalyze(this.handCards[i], moCard.card1); if(!!res){ if(!this.everyIsGang[i][0]){ isBu1 = true canBuList[canBuList.length] = {pos:1,card:moCard.card1}; } if(this.logic.isCanGang(this.handCards[i],this.huCards[i],1,moCard.card1)){ isGang1 = true; canGangList[canGangList.length] = {pos:1,card:moCard.card1}; } } else{ if(i == chairId){ let handCards1 = this.logic.deepCloneTL(this.handCards[chairId]); handCards1.push(moCard.card1); let res1 = this.logic.zmGangAnalyze(handCards1, this.huCards[i],moCard.card1); // console.warn(">>>>>>>杠后两张牌 res1 "+JSON.stringify(res1)); if((res1.length > 0)){ if(!this.everyIsGang[i][0]){ isBu1 = true canBuList[canBuList.length] = {pos:3,card:moCard.card1}; } if(this.logic.isCanGang(handCards1,this.huCards[i],3,moCard.card1)){ isGang1 = true; canGangList[canGangList.length] = {pos:3,card:moCard.card1}; } } } } let isGang2 = false; let isBu2 = false; let res2 = this.logic.gangAnalyze(this.handCards[i], moCard.card2); if(!!res2){ if(!this.everyIsGang[i][0]){ isBu2 = true canBuList[canBuList.length] = {pos:1,card:moCard.card2}; } if(this.logic.isCanGang(this.handCards[i],this.huCards[i],1,moCard.card2)){ isGang2 = true; canGangList[canGangList.length] = {pos:1,card:moCard.card2}; } } else{ if(i == chairId){ let handCards1 = this.logic.deepCloneTL(this.handCards[chairId]); handCards1.push(moCard.card2); let res3 = this.logic.zmGangAnalyze(handCards1,this.huCards[i],moCard.card2); // console.warn(">>>>>>>杠后两张牌 res3 "+JSON.stringify(res3)); if((res3.length > 0)){ if(!this.everyIsGang[i][0]){ isBu2 = true canBuList[canBuList.length] = {pos:3,card:moCard.card2}; } if(this.logic.isCanGang(handCards1,this.huCards[i],3,moCard.card2)){ isGang2 = true; canGangList[canGangList.length] = {pos:3,card:moCard.card2}; } } } } // console.warn(">>>>>>>杠后两张牌 canGangList "+JSON.stringify(canGangList)); if(isGang1 || isGang2){ this.masks[i] |= 8; canSelectData.push({type:8,cards:canGangList}) } if(isBu1 || isBu2){ this.masks[i] |= this.maskValeList[0]; canSelectData.push({type:this.maskValeList[0],cards:canBuList}) } let data = { chairId: chairId, keGangInfo: this.keGangInfo, cards: moCard, canSelectData: canSelectData, isGangInfo: this.everyIsGang[chairId],/////每个人是否杠了,如果杠了就只能摸啥打啥了 mask: this.masks[i] } // console.warn("杠后两张牌=== ",i,this.masks[i],this.masks); this.gangAfterData.canSelectData[i] = canSelectData; yield this.pushMsgAsync(i, 'csjiang_event', { type: M.GANGAFTER, data: data }); } this.gangAfterData.chairId = chairId; this.gangAfterData.cards = moCard; pjhfsplist = { chairId: chairId, cards: moCard, canSelectData: [], mask: this.masks } this.setPaijuHuiFangData(M.GANGAFTER,pjhfsplist);/////TL++ 牌局回放 push摸牌数据 let str3 = "cstable 杠牌之后 id:"+this.id + " ,uid "+chairId+" ,this.masks "+ this.masks +" card1 "+moCard.card1+" card2 "+moCard.card2; logger.warn(str3);////cssj // 围观通知 let wgdata = { chairId: chairId, cards: moCard, canSelectData: [], mask: 0 } yield this.lookMsgAsync('csjiang_event', { type: M.GANGAFTER, data: wgdata }); let isqwqx = true;//是否全无吃碰胡权限 for (var i = 0; i < this.masks.length; i++) { if(this.masks[i] > 0){ isqwqx = false; break; } } if(isqwqx){ // console.error("开始定时器=====000"); if(!this.updataGangTimer){ this.updataGangTimer = this.app.timer.setTimeout(() => { // console.error("开始定时器=====111"); if(this.updataGangTimer) { clearTimeout(this.updataGangTimer); this.updataGangTimer = null; } let nextId = (this.gangAfterData.chairId + 1) % this.ccount; // console.error("开始定时器=====222 "+nextId); //全无吃碰胡权限,给下家发牌 this.updateGangafterData(chairId,moCard); this.touchCardAsync(nextId); ///////杠后两张牌无权限摸牌 } , 2000);//延迟2秒开始游戏 } } return { code: C.OK }; }); //更新杠后两张牌状态信息 杠后两张牌没有人可以操作或者操作之后清空gangAfterData和每个人的出牌列表 proto.updateGangafterData = cor(function* (chairId,moCard) { // console.error("更新杠后两张牌状态信息 重置了杠后数据 "+chairId); this.gangAfterData = {//清空杠后2张牌信息 chairId: -1, cards: {card1:0,card2:0}, canSelectData: [[],[],[],[]], mask: 0 } this.logic.isGGMG = [false,false,false,false];;//////TL++,是否刚刚直杠(明杠)用于判断是否是直杠杠开 this.logic.isGGAG = [false,false,false,false];//////TL++,是否刚暗杠用于判断是否暗杠杠开 this.logic.isGGFXG = [false,false,false,false];//////TL++,是否刚刚风险杠用于判断是否风险杠杠开 let lastCount22 = this.logic.leaveCount();/////TL++xg let update = { gangAfterData: this.gangAfterData, lastCount: String(lastCount22), addOutCards:{chairId: chairId,addOut: moCard} } let card1 = moCard.card1; let card2 = moCard.card2; if(card1 > 0)this.outCards[chairId].push(card1); if(card2 > 0)this.outCards[chairId].push(card2); let pjhfsplist = this.logic.deepCloneTL(update) pjhfsplist.outCards = this.logic.deepCloneTL(this.outCards); this.setPaijuHuiFangData(M.UPDATEGANGAFTER,pjhfsplist);/////TL++ 牌局回放 push摸牌数据 yield this.pushMsgAsync(-1, 'csjiang_event', { type: M.UPDATEGANGAFTER, data: update }); // yield this.lookMsgAsync('csjiang_event', { type: M.UPDATEGANGAFTER, data: update }); }) proto.autoOutCard = cor(function* (moCard) { let isGangHou = this.everyIsGang[this.currentId][0] && this.everyIsGang[this.currentId][1] > 0 && this.everyIsGang[this.currentId][1] < 60 let str1 = "cstable自动出牌 id:"+this.id +" "+this.currentId+" "+this.everyIsAutoOut+" "+isGangHou+" "+this.masks + " "+moCard; logger.warn(str1);////cssj if(this.masks[this.currentId] == 0 && (isGangHou || this.everyIsAutoOut[this.currentId])) { //杠后或者选择了自动出牌 if(!this.autoOutTimer){ this.autoOutTimer = this.app.timer.setTimeout(() => { // console.error("开始定时器=====111 moCard "+moCard); if(this.autoOutTimer) { let str2 = "cstable删除定时器 id:"+this.id +" moCard "+moCard; logger.warn(str2);////cssj clearTimeout(this.autoOutTimer); this.autoOutTimer = null; } if(isGangHou){ let str3 = "cstable 自动出牌gh id:"+this.id + " ,uid "+this.currentId+" ,this.masks "+ this.masks +" isGangHou "+isGangHou+" card "+this.everyIsGang[this.currentId][1]; logger.warn(str3);////cssj this.outCardAsync(this.currentId,this.everyIsGang[this.currentId][1]); } else{ let str3 = "cstable 自动出牌 id:"+this.id + " ,uid "+this.currentId+" ,this.masks "+ this.masks +" isGangHou "+isGangHou+" card "+moCard; logger.warn(str3);////cssj this.outCardAsync(this.currentId,moCard); } } , 1100);//各玩家均没有操作的情况下延迟2秒更新杠后两张牌的状态 } } return; }) ///////摸牌函数 参数ifGang是否因为杠而摸牌 TL++ ,为了判断是否花杠杠开 是否最后一张的海底捞月 proto.touchCardAsync = cor(function* (chairId,ifGang,ishdly) { // if(this.buhuaTimeout) { // clearTimeout(this.buhuaTimeout); // this.buhuaTimeout = null; // } // 状态校验 if (this.state != STATE.PLAYING) return; if (this.winner.chs.length > 0 || !this.users[chairId]) return; if(this.logic.isGuoHuList[chairId][0]) this.logic.isGuoHuList[chairId] = [false,-1];/////TL++,设置过胡玩家的是否点击过胡为false; 摸牌 this.keGangInfo = {chairId: -1,data:[]};////可杠信息,因为摸牌之后手上虽然有多个杠,但是没有听牌的话是不能杠的 let isyrxzhdly =_.findIndex(this.everyHDLY, (m, i) => (m == 1)) != -1;//是否有人选择海底捞月 if(!isyrxzhdly && this.logic.leaveCount() == 1 ){ // console.warn("判断海底捞月 "); let targetId = -1 let nextId = -1; for (let i = 0; i < this.ccount; ++i) { if(i == 0) nextId = chairId; else nextId = (nextId + 1) % this.ccount; if(this.everyHDLY[nextId] >= 0) continue; // console.warn("开始检查听牌准备海底捞月"); if(this.logic.checkTing(this.handCards[nextId],this.huCards[nextId])){ // console.warn("判断海底捞月222 停牌了 nextId "+nextId); targetId = nextId; break; } } // console.warn("判断海底捞月333 targetId "+targetId); if(targetId >= 0){ let guohudataTL = { chairId:targetId, msg: "是否“海底捞月”?", /////海底捞月通知 } this.logic.isZHYZ = true;/////是不是最后1张 yield this.pushMsgAsync(targetId, 'csjiang_event', { type: M.FHLASTCARDTIP, data: guohudataTL }); //////海底捞月通知 放弃操作中调用摸牌函数 let strx = "cstable 摸 询问海底 id:"+this.id + " ,uid "+targetId+" ,this.masks "+ this.masks; logger.warn(strx);////cssj // this.setPaijuHuiFangData(M.FHLASTCARDTIP,guohudataTL);/////TL++ 牌局回放 push海底捞月数据 放弃操作 return { code: C.OK }; } else{ this.logic.lastMoPaiChairID = chairId;//最后都没有听牌,就流局,按照顺序摸海底的那位玩家当庄家 yield this.concludeGameAsync(MODE.NOCARD); return { code: C.OK }; } } if(this.logic.leaveCount() > 1 ) this.logic.isZHYZ = false; // 当前顺序 this.currentId = chairId; // 摸牌 // var moCard = this.logic.moCard();TL++zsyl ////TL++ var moCard = { card: 0 }; let isG = (ifGang && (ifGang == 1) || (ifGang == 2) || (ifGang == 3)) // console.warn("<<<<<<<<<",isG,ifGang) moCard = this.logic.moCard(); this.logic.moPaiTL(); let moPaiIsCanHu = false;//////TL++,摸牌的人是否可以胡牌 let ischange = false; if(this.gangAfterData.chairId != -1){ let csc = this.logic.deepCloneTL(this.gangAfterData.cards); yield this.updateGangafterData(this.gangAfterData.chairId,csc); } this.logic.isGGMG = [false,false,false,false];//////TL++,是否刚刚直杠(明杠)用于判断是否是直杠杠开 this.logic.isGGAG = [false,false,false,false];//////TL++,是否刚暗杠用于判断是否暗杠杠开 this.logic.isGGFXG = [false,false,false,false];//////TL++,是否刚刚风险杠用于判断是否风险杠杠开 // 是否流局 if (moCard.card <= 0) { // console.warn("提前结算888"); yield this.concludeGameAsync(MODE.NOCARD); return { code: C.OK }; } if(this.everyIsGang[chairId][0]) this.everyIsGang[chairId][1] = moCard.card; let lastCount22 = this.logic.leaveCount();/////TL++xg let pjhfsplist = {}; let __isHu2 = false; for (let i = 0; i < this.ccount; ++i) { let touchCard = { currentId: String(chairId), touch: '0',lastCount : '0' }; // console.warn("1111WWWWWWWTTTTTT",i,chairId,moCard.card); touchCard.isGangInfo = [0,0];/////每个人是否杠了,如果杠了就只能摸啥打啥了 = [0,0]; if (i == chairId) { touchCard.touch = String(moCard.card); touchCard.isGangInfo = this.everyIsGang[chairId];/////每个人是否杠了,如果杠了就只能摸啥打啥了 = this.everyIsGang[chairId]; // this.handCards[i].push(moCard.card);/////TL++zsyl this.handCards[i].push(moCard.card);/////TL++,因为在补花的时候已经将新发的牌放进手牌里了所以这里不用push let __isHu = false; // console.error("sscc111胡牌分析 摸牌 i",i); this.logic.isLaGang = false;//////TL++,是否刚刚被拉杠用于判断是否被拉杠胡 // this.logic.chengBaoTL = [[],[],[],[]];////别人放弃拉杠之后还没想好要怎么清空,因为不清空也行 // console.warn("222摸牌的时候设置刚才是否有杠",i,ifGang,this.logic.isGGMG,this.logic.isGGAG,this.logic.isGGFXG); let huRes = this.logic.huAnalyze(i,this.handCards[i], moCard.card, this.huCards[i], true);//摸牌函数判胡 // console.error("ssccBBB胡牌分析 huRes",huRes); if (huRes) { // let str3a = "cstable mpphcg:"+this.id + ",uid"+this.handCards[i]; // logger.info(str3a);////cssj __isHu = true; if(this.logic.isZHYZ) __isHu2 = true; moPaiIsCanHu = true;/////TL++ this.huRes[i] = huRes; } if(!this.logic.isZHYZ){ let res1 = this.logic.anGangAnalyze(this.handCards[i]); let isGang1 = (res1.length > 0); let res2 = this.logic.zmGangAnalyze(this.handCards[i], this.huCards[i]); let isGang2 = (res2.length > 0); let res = []; let isGang = isGang1 || isGang2; if(isGang1) res = res.concat(res1);//暗杠 if(isGang2) res = res.concat(res2);//自摸杠 if(isGang){ for (let x = 0; x < res.length; ++x) { if(this.logic.isCanGang(this.handCards[i],this.huCards[i],res[x].type,res[x].card)){ if(!this.everyIsGang[i][0]){ this.masks[i] |= this.maskValeList[0];//能杠肯定就能补 } this.masks[i] |= 8; this.keGangInfo.chairId = i; this.keGangInfo.data.push({pos:res[x].type,card:res[x].card});////可杠信息,因为摸牌之后手上虽然有多个杠,但是没有听牌的话是不能杠的 } else{ if(!this.everyIsGang[i][0]){ this.masks[i] |= this.maskValeList[0]; } } } } } if (__isHu) this.masks[i] |= 16; this.logic.qshuAnalyze(i,this.handCards[i]); this.currQSHInfo[chairId] = []//当前各个玩家展示的起手胡信息 // console.warn("摸牌判断小胡 i "+i+" " +this.logic.everyQSHType[i]); for (let x = 0; x < this.logic.everyQSHType[i].length; ++x) { if(this.logic.everyQSHType[i][x] == 1){ this.masks[i] |= this.maskValeList[x+1]; } } ////摸排时候的摸排玩家的胡牌提示 let hutipdataTL = this.logic.hutip(i,this.handCards[i],this.huCards[i],this.huCards,this.outCards);////摸牌时调用胡牌提示 touchCard.hutipdata = hutipdataTL; let isGuoHuList = [[false,-1],[false,-1],[false,-1],[false,-1]]; isGuoHuList[chairId] = this.logic.isGuoHuList[chairId]; touchCard.isGuoHuList = isGuoHuList; touchCard.canSelects = this.logic.canSelects[i] } else { this.masks[i] = 0; touchCard.hutipdata = { renyi:0,//////是否可胡任意牌,0表示不满足1表示满足 kehuData:[]/////对象数组,分别表示打哪张可胡哪几张数据 }; touchCard.isGuoHuList = [[false,-1],[false,-1],[false,-1],[false,-1]] touchCard.canSelects = []; } touchCard.mask = String(this.masks[i]); touchCard.lastCount = String(lastCount22); if (i == chairId) touchCard.keGangInfo = this.keGangInfo; else touchCard.keGangInfo = {chairId: -1,data:[]}; this.logic.lastMoPaiChairID = this.currentId; // 摸牌通知 // console.warn("222WWWWWWWTTTTTT",i,chairId,moCard.card); yield this.pushMsgAsync(i, 'csjiang_event', { type: M.TOUCH_CARD, data: touchCard}); if (i == chairId) { pjhfsplist = { shouPai:this.logic.deepCloneTL(this.handCards), lastCount:String(this.logic.leaveCount()), touchCard:this.logic.deepCloneTL(touchCard), outCards:this.logic.deepCloneTL(this.outCards), canSelects: this.logic.canSelects[i], isGuoHuList:this.logic.deepCloneTL(this.logic.isGuoHuList) } } if(i == (this.ccount - 1)){/////TL++if条件判断,10月28号,为了实现能看到每个玩家的操作 pjhfsplist.maskList = this.logic.deepCloneTL(this.masks);/////TL++,10月28号,为了实现能看到每个玩家的操作 this.setPaijuHuiFangData(M.TOUCH_CARD,pjhfsplist);/////TL++ 牌局回放 push摸牌数据 } } let str3 = "cstable 摸牌函数id:"+this.id + " ,uid "+chairId+" ,this.masks "+ this.masks +" card "+moCard.card; logger.warn(str3);////cssj // 围观通知 // return this.lookMsgAsync('csjiang_event', { type: M.TOUCH_CARD, data: { currentId: String(chairId),lastCount:String(lastCount22)} }); yield this.lookMsgAsync('csjiang_event', { type: M.TOUCH_CARD, data: { currentId: String(chairId),lastCount:String(lastCount22)} }); if(this.logic.isZHYZ){ //如果是海底捞月,能胡直接胡不能胡直接打出 if (__isHu2) return this.succCardAsync(chairId).then(() => ({ code: C.OK })); else return this.outCardAsync(chairId,moCard.card).then(() => ({ code: C.OK })); } yield this.autoOutCard(moCard.card); return { code: C.OK }; }); // 放弃操作 proto.giveUpAsync = cor(function* (chairId) { let str3 = "cstable 放弃操作id: "+this.id + " ,uid "+chairId+", this.masks "+ this.masks; logger.warn(str3);////cssj // 权限掩码 var mask = this.masks[chairId]; if (mask <= 0) { return { code: C.FAILD, msg: C.TABLE_MASK_ERROR }; } if(chairId == this.currentId){ let isGangHou = this.everyIsGang[this.currentId][0] && this.everyIsGang[this.currentId][1] > 0 && this.everyIsGang[this.currentId][1] < 60 if((mask & 16) && isGangHou && this.everyIsGang[this.currentId][1] == 51) { return { code: C.FAILD, msg: C.TABLE_NOTOUTHZGUOSB }; } } if(chairId == this.keGangInfo.chairId){ this.keGangInfo = {chairId: -1,data:[]};////可杠信息,因为摸牌之后手上虽然有多个杠,但是没有听牌的话是不能杠的 } // console.warn("111放弃操作放弃操作放弃操作放弃操作放弃操作chairId,this.masks",chairId,this.masks,(mask & 16)); if (mask & 16) {////mask = 16~31时结果=16这个if能进去 0~15或者32~47之间结果=0这个if进不去 // console.warn("放弃操作里设置过胡为true",chairId, this.logic.isLaGang,this.logic.isGuoHuList,this.logic.everyAllTaiShu); this.logic.isGuoHuList[chairId][0] = true;/////TL++,设置过胡玩家的是否点击过胡为true 点击过按钮 let pxgs = 0; for (let x = 0; x < this.logic.everyDAHType[chairId].length; ++x) { if(this.logic.everyDAHType[chairId][x] == 1) pxgs++; } this.logic.isGuoHuList[chairId][1] = pxgs;/////TL++,设置过胡玩家的是否点击过胡为true 出牌 let guohudataTL = { chairId:chairId, msg: "下次摸牌或满足更大牌型之前将不能胡牌", /////过胡通知 } let isGuoHuList = [[false,-1],[false,-1],[false,-1],[false,-1]]; isGuoHuList[chairId] = this.logic.isGuoHuList[chairId]; guohudataTL.isGuoHuList = isGuoHuList; //////过胡通知 yield this.pushMsgAsync(chairId, 'csjiang_event', { type: M.FHGUOHUTIP, data: guohudataTL }); if(this.logic.leaveCount() > 0){/////TL++ this.lgkhCount -= 1;/////TL++拉杠可胡玩家的数量 } // console.warn("666拉杠胡%%%%%%%%%%%%%%%%%%%%%%",this.logic.isLaGang); } // 删除权限 this.masks[chairId] = 0; // console.warn("放弃操作 "+this.currentId +" "+ chairId+" "+this.masks); // 是否自摸 if (this.currentId == chairId) { let isCanOut = this.logic.getIsCanOut(this.masks); if(isCanOut){ //////麻将过牌通知,用于隐藏手牌遮罩 let fqdata = { isGangInfo: this.everyIsGang[chairId], isCanOut: isCanOut } yield this.pushMsgAsync(this.currentId, 'csjiang_event', { type: M.GIVE_UP, data:fqdata }); } let qtrsfhycz = false;//其他人是否还有操作 for (let i = 0; i < this.masks.length; ++i) { if(this.masks[i] > 0){ qtrsfhycz = true; break; } } if(!qtrsfhycz){ // console.warn("放弃操作 其他人都没有操作了 "); if(this.gangAfterData.chairId != -1){ let nextId = (this.gangAfterData.chairId + 1) % this.ccount; yield this.updateGangafterData(this.gangAfterData.chairId,this.gangAfterData.cards); // console.warn("放弃操作 这里发排列 "); yield this.touchCardAsync(nextId); ///////放弃操作杠后两张牌之后发牌 } return { code: C.OK }; } } // 忽略牌 if (this.outCard) { let except = this.excepts[chairId]; except[this.outCard] = this.outCard; } // console.warn("放弃操作里 mask "+mask + " "+(mask & 16)+" "+this.gangAfterData.chairId); // 放弃胡牌 let isfqhp = false;//是否放弃胡牌 if (mask & 16) isfqhp = true; if(!isfqhp){ for (var x = 1; x < this.maskValeList.length; x++) { if(mask & this.maskValeList[x]){ isfqhp = true; break; } } } if (isfqhp){//(mask & 16) {////mask = 16~31时结果=16这个if能进去 0~15或者32~47之间结果=0这个if进不去 let winner = this.winner; do { // 一炮多响 if (this.isMHu) { let __cHu = _.findIndex(this.masks, (m) => (m & 16));////// // console.warn("?????? "+this.gangAfterData.chairId); // console.warn("允许一炮多想 放弃操作放弃操作放弃操作this.isMHu,__cHu",this.isGangHu,this.isMHu,__cHu); if (__cHu != -1){ let __cHuDengDai = _.findIndex(this.masks, (m) => (m == 17));////// if(__cHuDengDai == -1) { break; } else { // console.warn("放弃这里调用了胡牌",winner.chs.length,__cHuDengDai) return this.succCardAsync(__cHuDengDai).then(() => ({ code: C.OK })); } } // else{ // 有人胡牌 if (winner.chs.length > 0) { // console.warn("允许一炮多想 操作放弃操作放弃操作winner.chs",winner.chs); yield this.pushMsgAsync(-1, 'csjiang_event', { type: M.HU, data: { lead: String(this.logic.getLead(this.gangAfterData.chairId,winner.lead,winner.chs)), chairIds: winner.chs } }); // console.warn("提前结算1111"); yield this.concludeGameAsync(MODE.NORMAL).then(() => ({ code: C.OK }));/////结算游戏 return { code: C.OK }; } // } } else {///// 没炮多响 // console.warn("没炮多想 放弃操作放弃操作放弃操作winner.chs",this.isGangHu,winner.chs); // 有人胡牌 if (winner.chs.length > 0) { let dist = (winner.chs[0] - winner.lead + this.ccount) % this.ccount; // let __cHu = _.findIndex(this.masks, (m, i) => (m & 16 && (i - winner.lead + this.ccount) % this.ccount < dist));////TL++,zsyl, let __cHu = _.findIndex(this.masks, (m, i) => (m & 16));///TL++,以前是上面那句写法,有个问题:0打牌后1,2,3号玩家都能胡,1点胡2点过,3就没有机会选择是否胡牌 // console.warn("111没炮多想 放弃操作放弃操作放弃操作__cHu",__cHu); if (__cHu != -1){ let __cHuDengDai = _.findIndex(this.masks, (m) => (m == 17));////// if(__cHuDengDai == -1) break; else return this.succCardAsync(__cHuDengDai).then(() => ({ code: C.OK })); } yield this.pushMsgAsync(-1, 'csjiang_event', { type: M.HU, data: { lead: String(this.logic.getLead(this.gangAfterData.chairId,winner.lead,winner.chs)), chairIds: winner.chs } }); // console.warn("提前结算2222"); yield this.concludeGameAsync(MODE.NORMAL).then(() => ({ code: C.OK }));/////结算游戏 return { code: C.OK }; } else { let __cHu = _.findIndex(this.masks, (m) => (m & 16)); // console.warn("111没炮多想 放弃操作放弃操作放弃操作__cHu",__cHu); if (__cHu != -1) { let __cHuDengDai = _.findIndex(this.masks, (m) => (m == 17));////// if(__cHuDengDai == -1) break; else return this.succCardAsync(__cHuDengDai).then(() => ({ code: C.OK })); } } } // 查找等待 for (let i = 0; i < this.masks.length; ++i) { let cqsh = -1; // console.warn("处理等待的起手胡111 "+this.masks[i]); // if (i == this.currentId || i == chairId) continue;///////TL++zsyl 这种写法会导致拉杠胡的玩家点击过胡之后被拉杠胡的玩家杠不出来的问题 if (i == chairId) continue;//////TL++,为了解决拉杠胡的玩家点击过胡之后被拉杠胡的玩家杠不出来的问题 if (this.masks[i] == 65 || this.masks[i] == 129 ||this.masks[i] == 257 ||this.masks[i] == 513 ||this.masks[i] == 1025 ||this.masks[i] == 2049) { cqsh = i; } if (cqsh != -1 ) { // console.warn("处理等待的起手胡222 ",cqsh, this.qshType[cqsh], this.qshCards[cqsh]); this.masks[i]--;//mask=129传给前端是不显示按钮的,为了等待在原本的mask上+1了,现在可以操作了所以-1 yield this.qshCardAsync(cqsh, this.qshType[cqsh], this.qshCards[cqsh]).then(() => ({ code: C.OK })); } } let cGang = -1; let cbu = -1; let cPeng = -1; let _cChi = -1; // console.warn("这里是啥情况啊",this.masks); for (let i = 0; i < this.masks.length; ++i) { // if (i == this.currentId || i == chairId) continue;///////TL++zsyl 这种写法会导致拉杠胡的玩家点击过胡之后被拉杠胡的玩家杠不出来的问题 if (i == chairId) continue;//////TL++,为了解决拉杠胡的玩家点击过胡之后被拉杠胡的玩家杠不出来的问题 // if (this.masks[i] == 65 || this.masks[i] & 129 ||this.masks[i] & 257 ||this.masks[i] & 513 ||this.masks[i] & 1025 ||this.masks[i] & 2049) { // cqsh = i; // continue; // } if (this.masks[i] == 9) { cGang = i; continue; } if (this.masks[i] == 33) { cbu = i; continue; } if (this.masks[i] == 5) { cPeng = i; continue; } if (this.masks[i] == 3) { _cChi = i; continue; } } // 杠碰吃 if (cGang != -1 && this.gangType > 0 && this.gangCard > 0) { // console.warn("这里是放弃操作再次调用 杠 次"); return this.gangCardAsync(cGang, this.gangCard, this.gangType).then(() => ({ code: C.OK })); } else if (cbu != -1 && this.buCard > 0) { // console.warn("这里是放弃操作再次调用 杠 次"); return this.buCardAsync(cbu, this.buCard, this.buType).then(() => ({ code: C.OK })); } else if (cPeng != -1) { let cc = this.outCard; if(this.gangAfterData.chairId != -1){ cc = this.pengCard; } if(cc > 0){ return this.pengCardAsync(cPeng, cc).then(() => ({ code: C.OK })); } } else if (_cChi != -1 && this._eatType > 0) { let cc = this.outCard; if(this.gangAfterData.chairId != -1){ cc = this._eatCard; } if(cc > 0){ return this.eatCardAsync(_cChi, cc, this._eatType).then(() => ({ code: C.OK })); } } } while (0); } // 放弃杠补 if ((mask & 8) || (mask & 32)) { // console.warn("下面是放弃杠补"); let __cHu = _.findIndex(this.masks, (m) => (m & 16)); if (__cHu == -1) { // console.warn("放弃杠补 其他人没有胡 "); let cGang = _.findIndex(this.masks, (m) => (m == 9)); if (cGang != -1 && this.gangType > 0 && this.gangCard > 0) { // console.warn("这里是放弃操作再次调用 杠 次"); return this.gangCardAsync(cGang, this.gangCard, this.gangType).then(() => ({ code: C.OK })); } let cbu = _.findIndex(this.masks, (m) => (m == 33)); if (cbu != -1 && this.buCard > 0) { // console.warn("这里是放弃操作再次调用 杠 次"); return this.buCardAsync(cbu, this.buCard, this.buType).then(() => ({ code: C.OK })); } let cPeng = _.findIndex(this.masks, (m) => (m == 5)); // console.warn("放弃杠补 其他人是否有碰 cPeng "+cPeng+" this.pengCard "+this.pengCard); if (cPeng != -1) { let cc = this.outCard; if(this.gangAfterData.chairId != -1){ cc = this.pengCard; } // console.warn("放弃杠补NNNNNNNNN 333 "+cc); if(cc > 0){ return this.pengCardAsync(cPeng, cc).then(() => ({ code: C.OK })); } } let chi = _.findIndex(this.masks, (m) => (m == 3)); // console.warn("放弃杠补 其他人是否有吃 chi "+chi+" this._eatType "+this._eatType); if (chi != -1) { let cc = this.outCard; if(this.gangAfterData.chairId != -1){ cc = this._eatCard; } if(cc > 0){ return this.eatCardAsync(chi, cc, this._eatType).then(() => ({ code: C.OK })); } } } } // 放弃碰 if (mask & 4) { let __cHu = _.findIndex(this.masks, (m) => (m == 16)); if (__cHu == -1) { let cPeng = _.findIndex(this.masks, (m) => (m == 5)); // console.warn("放弃碰 其他人是否有碰 cPeng "+cPeng+" this.pengCard "+this.pengCard); if (cPeng != -1) { let cc = this.outCard; if(this.gangAfterData.chairId != -1){ cc = this.pengCard; } // console.warn("放弃碰NNNNNNNNN 333 "+cc); if(cc > 0){ return this.pengCardAsync(cPeng, cc).then(() => ({ code: C.OK })); } } let _cChi = _.findIndex(this.masks, (m) => (m == 3)); let cc = this.outCard; if(this.gangAfterData.chairId != -1){ cc = this._eatCard; } if (_cChi != -1 && this._eatType > 0 && cc > 0) { return this.eatCardAsync(_cChi, cc, this._eatType).then(() => ({ code: C.OK })); } } } // 全无权限 if(!this.logic.getIsQS()){ for (let i = 0; i < this.ccount; ++i) { if (this.masks[i] != 0) break; // 切换用户 if (i == this.ccount - 1) { // 下家摸牌 let nextId = (this.currentId + 1) % this.ccount; if(this.gangAfterData.chairId != -1){ nextId = (this.gangAfterData.chairId + 1) % this.ccount; yield this.updateGangafterData(this.gangAfterData.chairId,this.gangAfterData.cards); } ///////TL++,整个if,因为海底捞月需要玩家自己去判断要不要摸牌 // console.warn("222 声剩余声剩余声剩 nextId "+nextId+" outCards "+this.outCards[nextId]); let lastCount = this.logic.leaveCount();/////TL++xg return this.touchCardAsync(nextId).then(() => ({ code: C.OK }));//////放弃操作引起的摸牌 } } } let isCanOut = this.logic.getIsCanOut(this.masks); if(isCanOut){ //////麻将过牌通知,用于隐藏手牌遮罩 let fqdata = { isGangInfo: this.everyIsGang[chairId], keGangInfo: this.keGangInfo, isCanOut: isCanOut } yield this.pushMsgAsync(this.currentId, 'csjiang_event', { type: M.GIVE_UP, data:fqdata }); } return { code: C.OK}; }); // /////TL++,是否进行海底捞月的操作 处理前端海底捞月函数 proto.haiDiLaoYue = cor(function* (chairId,data) { let str3 = "cstable 海底,id: "+this.id + " ,uid "+chairId+", this.masks "+ this.masks +" ,type "+data.type; logger.warn(str3);////cssj // console.warn("海底捞月海底捞月 chairId "+chairId+" type "+data.type+" isZHYZ "+this.logic.isZHYZ); if(!this.logic.isZHYZ) return; if(this.everyHDLY[chairId] != -1) return; // // console.warn("海底捞月海底捞月",chairId,data.type); if(data.type && data.type == 1){ this.everyHDLY[chairId] = 1;//每个玩家海底捞月选择情况,不选择海底不能胡海底 yield this.touchCardAsync(chairId).then(() => ({ code: C.OK }));//////海底捞月引起的摸牌 } else if(data.type == 0){ this.everyHDLY[chairId] = 0;//每个玩家海底捞月选择情况,不选择海底不能胡海底 let targetId = -1 let nextId = chairId; for (let i = 0; i < this.ccount; ++i) { nextId = (nextId + 1) % this.ccount; if(this.everyHDLY[nextId] >= 0) continue; // console.warn("海底捞月玩家不要 开始检查下一个人听牌"); if(this.logic.checkTing(this.handCards[nextId],this.huCards[nextId])){ targetId = nextId; break; } } // console.warn("海底捞月海底捞月 拒绝 chairId "+chairId+" targetId "+targetId); if(targetId >= 0){ let guohudataTL = { chairId:targetId, msg: "是否“海底捞月”?", /////海底捞月通知 } this.logic.isZHYZ = true;/////是不是最后1张 yield this.pushMsgAsync(targetId, 'csjiang_event', { type: M.FHLASTCARDTIP, data: guohudataTL }); //////海底捞月通知 放弃操作中调用摸牌函数 let strx = "cstable 海 询问海底 id:"+this.id + " ,uid "+targetId+" ,this.masks "+ this.masks; logger.warn(strx);////cssj // this.setPaijuHuiFangData(M.FHLASTCARDTIP,guohudataTL);/////TL++ 牌局回放 push海底捞月数据 放弃操作 return { code: C.OK }; } else{ yield this.concludeGameAsync(MODE.NOCARD); return { code: C.OK }; } } // console.warn("海底捞月海底捞月"); return { code: C.OK }; }); // 杠牌,1-普通杠, 2-暗杠, 3-自摸明杠 proto.gangCardAsync = cor(function* (chairId, card, type) { let str3 = "cstable 杠牌,id: "+this.id + " ,uid "+chairId+", this.masks "+ this.masks +" ,card "+card +" ,type "+type; logger.warn(str3);////cssj // 参数校验 if (!type && (type < 1 || type > 3)) { return { code: C.FAILD, msg: C.GAME_PARAM_ERROR }; } // console.warn("1-普通杠, 2-暗杠, 3-自摸明杠 "+type+" "+this.gangAfterData.chairId); if(this.gangAfterData.chairId == -1){ if (type == 1 && card != this.outCard) { return { code: C.FAILD, msg: C.GAME_PARAM_ERROR }; } } else{ if (card != this.gangAfterData.cards.card1 && card != this.gangAfterData.cards.card2){ return { code: C.FAILD, msg: C.GAME_PARAM_ERROR }; } } if(this.gangAfterData.chairId == -1){ if (type > 1 && this.currentId != chairId) { return { code: C.FAILD, msg: C.GAME_PARAM_ERROR }; } } if (!(this.masks[chairId] & 8)) { return { code: C.FAILD, msg: C.TABLE_MASK_ERROR }; } // if(!this.logic.isCanCPB(this.handCards[chairId],Logic.STYLE.GANG,type)){ // return { code: C.FAILD, msg: C.TABLE_NOTONLYBD }; // } // 他人可胡 // let __cHu = (type == 2) ? -1 : _.findIndex(this.masks, (m) => ((m & 16) && !(m & 8) && !(m & 32))); let isHveeQSH = false;//是否有起手胡 let tagetChairId = -1; let tagetOP = -1; for (var i = 0; i < this.masks.length; i++) { if(i != chairId){ if(this.masks[i] & 16){ isHveeQSH = true; break; } for (var x = 1; x < this.maskValeList.length; x++) { if(this.masks[i] & this.maskValeList[x]){ isHveeQSH = true; break; } } } } if(!isHveeQSH && this.gangAfterData.chairId != -1){ //只有杠后两张牌的时候杠才会两个人同时出现 //至此没有人可以胡 let otherKG = -1;//除点杠之外可杠或可补的玩家 for (var i = 0; i < this.masks.length; i++) { if(i != chairId && (this.masks[i] & 8 || chairId && this.masks[i] & 32)){ otherKG = i; break; } } if(otherKG >= 0){ let zjjl = 0; if((this.gangAfterData.chairId + 1) % this.ccount == chairId) zjjl = 1; else if((this.gangAfterData.chairId + 2) % this.ccount == chairId) zjjl = 2; else if((this.gangAfterData.chairId + 3) % this.ccount == chairId) zjjl = 3; let qtjl = 0; if((this.gangAfterData.chairId + 1) % this.ccount == otherKG) qtjl = 1; else if((this.gangAfterData.chairId + 2) % this.ccount == otherKG) qtjl = 2; else if((this.gangAfterData.chairId + 3) % this.ccount == otherKG) qtjl = 3; if(zjjl > qtjl){ if(this.masks[otherKG] == 9 || this.masks[otherKG] == 33){ tagetChairId = otherKG; if(this.masks[otherKG] == 33) tagetOP = 32; } else{ isHveeQSH = true; } } } } // console.warn("111拉杠胡%%%%%%%%%%%%%%%%%%%%%%",isHveeQSH ,tagetChairId,tagetOP,this.masks); if (!isHveeQSH){//(__cHu == -1) { let newCh = chairId; let newCa = card; let newTy = type if(tagetChairId > 0){ newCh = tagetChairId;//B玩家点杠或补之后需要等待C玩家点胡,如果C玩家点了杠就让B玩家杠或补 if(tagetOP == 32){ newCa = this.buCard; newTy = this.buType; }else{ newCa = this.gangCard; newTy = this.gangType; } } // console.warn("杠牌===111 chairId "+chairId+" tagetChairId "+tagetChairId+" tagetOP "+tagetOP) // console.warn("杠牌===222 newTy "+newTy+" newCa "+newCa+" this.huCards[newCh] "+JSON.stringify(this.huCards[newCh])+" this.handCards[newCh] "+this.handCards[newCh]) let res = null; if (newTy == 1 || newTy == 2) { res = this.logic.gang(newCh,this.handCards[newCh], newCa, newTy); } else if (newTy == 3) { let handCards1 = this.handCards[newCh]; if(this.gangAfterData.chairId != -1){ handCards1 = this.logic.deepCloneTL(this.handCards[newCh]); handCards1.push(newCa); } res = this.logic.zmGang(newCh,handCards1, this.huCards[newCh], newCa); } if (!res) { return { code: C.FAILD, msg: C.TABLE_GANG_ERROR }; } /////TL++7月17日,这整个if的内容 和else的判断 let winner = this.winner; if (winner.chs.length > 0) { yield this.pushMsgAsync(-1, 'csjiang_event', { type: M.HU, data: { lead: String(this.logic.getLead(this.gangAfterData.chairId,winner.lead,winner.chs)), chairIds: winner.chs } }); this.setPaijuHuiFangData(M.HU,{ lead: String(winner.lead), chairIds: winner.chs });/////TL++ 牌局回放 push吃胡牌数据 // console.warn("提前结算BBB"); yield this.concludeGameAsync(MODE.NORMAL); } else{ // 记录杠牌 if (newTy == 1) { // 被杠玩家 if(this.gangAfterData.chairId == -1){ this.gangOuter = this.outerId; res.origin = this.outerId; this.outCards[this.outerId].pop(); } else{ this.gangOuter = this.gangAfterData.chairId; res.origin = this.gangAfterData.chairId; } this.huCards[newCh].push(res); this.logic.remove(this.handCards[newCh], res.cards); } else if (newTy == 2) { // 被杠玩家 this.gangOuter = -1; this.huCards[newCh].push(res); this.logic.remove(this.handCards[newCh], [newCa, newCa, newCa, newCa]); this.logic.adjust(this.handCards[newCh]); } else if (newTy == 3) { // console.warn("333拉杠胡%%%%%%%%%%%%%%%%%%%%%%",this.logic.isLaGang,this.isGangHu); let huCard = _.find(this.huCards[newCh], (o) => { return (o.style == Logic.STYLE.PENG && o.cards[0] == newCa); }); if (!huCard) { return { code: C.FAILD, msg: C.TABLE_GANG_ERROR }; } // 被杠玩家 this.gangOuter = -1; // console.warn("拉杠胡%%%%%%%%%%%%%%%%%%%%%%" ,this.isGangHu); // 抢杠胡 if (!this.isGangHu) { this.lgkhCount = 0;/////TL++拉杠可胡玩家的数量 let allowIds = [], otherIds = []; for (let i = 0; i < this.ccount; ++i) { // 排除自己 if (i != newCh) { this.logic.isLaGang = true;//////TL++,是否刚刚被拉杠用于判断是否被拉杠胡 // console.error("sscc222胡牌分析 杠牌i",i,this.logic.isLaGang); let huRes = this.logic.huAnalyze(i,this.handCards[i], newCa, this.huCards[i]);//抢杠胡 // console.error("ssccCCC胡牌分析 huRes",huRes); // let lg2 = false;///TL++ if (huRes) { // let str3a = "cstable lgphcg:"+this.id + ",uid"+this.handCards[i]; // logger.info(str3a);////cssj if (!this.isGangHu) this.isGangHu = true; //////////TL++,为了记录承包情况,第一个元素表示承包原因 1:海底捞月打出去被胡 2:被人拉杠胡 第二个元素承包的玩家座位号 // this.logic.chengBaoTL[chairId][this.logic.chengBaoTL[chairId].length] = [2,this.currentId]; // lg2 = true//////TL++ this.huRes[i] = huRes; this.masks[i] |= 16; this.lgkhCount += 1;/////TL++拉杠可胡玩家的数量 allowIds.push(this.users[i].id); continue; } } // 其他玩家 otherIds.push(this.users[i].id); } // 有人可胡 if (allowIds.length > 0) { // 置于等待 this.masks[chairId] = 9; this.gangType = type; this.gangCard = card; // 抢杠通知 yield this.pushMsgAsync(otherIds, 'csjiang_event', { type: M.MASK_HU, data: { mask: '0', card: String(newCa) } }); yield this.pushMsgAsync(allowIds, 'csjiang_event', { type: M.MASK_HU, data: { mask: '16', card: String(newCa) } }); let pjhfsplist2 = { shouPai:this.logic.deepCloneTL(this.handCards), lastCount:this.logic.leaveCount(), outCards:this.logic.deepCloneTL(this.outCards), opData:{ mask: '16', card: String(newCa) } } this.setPaijuHuiFangData(M.MASK_HU,pjhfsplist2);/////TL++ 牌局回放 push杠操作数据 // console.warn("抢杠胡同盟会告知",allowIds); return { code: C.OK }; } } huCard.style = Logic.STYLE.ZMGANG; // console.warn("55拉杠胡%%%%%%%%%%%%%%%%%%%%%%",this.logic.isLaGang,this.gangType,this.gangCard = 0); this.isGangHu = false;/////TL++,8月28日晚上,为了解决过胡拉杠之后就算自己已经摸牌也不能再次拉杠的问题 this.logic.remove(this.handCards[newCh], newCa); this.logic.adjust(this.handCards[newCh]); } // if(this.chBanker == chairId) this.isZJYG = true;////本局庄家是否有杠 // 清空权限 杠牌里面 this._eatType = 0; this._eatCard = 0 this.gangType = 0; this.gangCard = 0; this.pengCard = 0; _.fill(this.masks, 0); // 总杠次 // this.gonCount += 1; // 发送通知 // console.warn("333 声剩余声剩余声剩"); let lastCount = this.logic.leaveCount();/////TL++xg let pjhfsplist = { shouPai:this.logic.deepCloneTL(this.handCards), lastCount:lastCount, outCards:this.logic.deepCloneTL(this.outCards), opData:{ chairId: String(newCh), type: String(newTy), card: String(newCa), lastCount: String(lastCount) } } if(tagetOP == 32){ this.changeCurrQSHInfo(newCh,M.BU,newTy,newCa); this.setPaijuHuiFangData(M.BU,pjhfsplist);/////TL++ 牌局回放 push杠操作数据 yield this.pushMsgAsync(-1, 'csjiang_event', { type: M.BU, data: { chairId: String(newCh), type: String(newTy), card: String(newCa), lastCount: String(lastCount) } }); }else{ this.changeCurrQSHInfo(newCh,M.GANG,newTy,newCa) this.setPaijuHuiFangData(M.GANG,pjhfsplist);/////TL++ 牌局回放 push杠操作数据 yield this.pushMsgAsync(-1, 'csjiang_event', { type: M.GANG, data: { chairId: String(newCh), type: String(newTy), card: String(newCa), lastCount: String(lastCount) } }); } if(this.gangAfterData.chairId != -1){ let gfcards = this.gangAfterData.cards; let xdIndex = 0; if(newCa == gfcards.card1) xdIndex = 1; else if(newCa == gfcards.card2) xdIndex = 2; if(xdIndex > 0){ let cmoCard = {}; if(xdIndex == 1) cmoCard = {card1:0,card2:gfcards.card2} else if(xdIndex == 2) cmoCard = {card1:gfcards.card1,card2:0} yield this.updateGangafterData(this.gangAfterData.chairId,cmoCard); } } if(this.logic.leaveCount() >= 2){ // console.error("杠牌 杠牌摸2张牌",tagetOP); if(tagetOP == 32){ yield this.touchCardAsync(newCh, newTy); ///////杠牌摸牌 } else{ yield this.touchCardAfterGang(newCh, newTy); ///////杠牌摸2张牌 } } else{ //只剩最后一张牌时杠完之后进行海底捞月轮询 // console.error("杠牌 杠牌摸牌"); yield this.touchCardAsync(chairId, type); ///////杠牌摸牌 } } } else { // console.warn("杠牌 置于等待 ???"); let ddcwj = _.findIndex(this.masks, (m, i) => (m == 9));//等待吃的玩家 let gxtype = this.logic.getDDGXType(2,chairId,ddcwj,this.gangAfterData.chairId,this.ccount,this.masks); let old_gangType = this.gangType; let old_gangCard = this.gangCard; // 置于等待 this.masks[chairId] = 9; this.gangType = type; this.gangCard = card; if(gxtype == 1){ this.masks[ddcwj] = 0; } else if(gxtype == 2){ this.masks[chairId] = 0; this.gangType = old_gangType; this.gangCard = old_gangCard; } let __cHuDengDai = _.findIndex(this.masks, (m) => (m == 17));////// if(__cHuDengDai != -1) { // console.warn("杠牌这里调用了胡牌",__cHuDengDai) // 为了解决A玩家杠后2张牌发出来之后,B玩家可吃胡C,D玩家可碰杠补胡,然后几人的操作顺序如果最后一个操作为胡或过的时候正常, // 但是如果最后一个操作为为吃碰杠补时会卡住的bug this.masks[chairId] = 0; return this.succCardAsync(__cHuDengDai).then(() => ({ code: C.OK })); } else{ // 查找起手胡等待 // 为了解决A玩家起手牌可以胡杠补,BC玩家有六六顺时,BC玩家先点六六顺之后A玩家点杠或补会卡住的bug, // (正确应为:BC玩家先点六六顺之后A玩家点杠后应该六六顺和杠或补都生效,若玩家A点胡则胡生效六六顺不生效) for (let i = 0; i < this.masks.length; ++i) { let cqsh = -1; // console.warn("杠牌里处理等待的起手胡111 "+this.masks[i]); // if (i == this.currentId || i == chairId) continue;///////TL++zsyl 这种写法会导致拉杠胡的玩家点击过胡之后被拉杠胡的玩家杠不出来的问题 if (i == chairId) continue;//////TL++,为了解决拉杠胡的玩家点击过胡之后被拉杠胡的玩家杠不出来的问题 if (this.masks[i] == 65 || this.masks[i] == 129 ||this.masks[i] == 257 ||this.masks[i] == 513 ||this.masks[i] == 1025 ||this.masks[i] == 2049) { cqsh = i; } if (cqsh != -1 ) { // console.warn("处理等待的起手胡222 ",cqsh, this.qshType[cqsh], this.qshCards[cqsh]); this.masks[i]--;//mask=129传给前端是不显示按钮的,为了等待在原本的mask上+1了,现在可以操作了所以-1 yield this.qshCardAsync(cqsh, this.qshType[cqsh], this.qshCards[cqsh]).then(() => ({ code: C.OK })); } } } } // let str4 = "cstable222 杠牌,id:"+this.id + ",uid"+chairId+","+ this.state +",card "+card; // logger.info(str4);////cssj return { code: C.OK }; }); // 碰牌 proto.pengCardAsync = cor(function* (chairId, card) { let str3 = "cstable 碰牌id:%s "+this.id + " ,uid "+chairId+" ,this.masks "+ this.masks +" ,card "+card; logger.warn(str3);////cssj // 参数校验 if(this.gangAfterData.chairId == -1){ if (card != this.outCard || this.currentId == chairId) { return { code: C.FAILD, msg: C.GAME_PARAM_ERROR }; } } else{ if (card != this.gangAfterData.cards.card1 && card != this.gangAfterData.cards.card2){ return { code: C.FAILD, msg: C.GAME_PARAM_ERROR }; } } // 权限校验 if (!(this.masks[chairId] & 4)) { return { code: C.FAILD, msg: C.TABLE_MASK_ERROR }; } if(!this.logic.isCanCPB(this.handCards[chairId],Logic.STYLE.PENG,0)){ return { code: C.FAILD, msg: C.TABLE_NOTONLYBD }; } // 他人可胡杠 // var cHuGang = _.findIndex(this.masks, (m) => (((m & 16) || (m & 8) || (m & 32)) && !(m & 4))); let isHaveHuGang = false; let tagetChairId = -1; if(this.gangAfterData.chairId == -1){ //这是普通正常情况 let cHuGang = _.findIndex(this.masks, (m) => (((m & 16) || (m & 8) || (m & 32)) && !(m & 4))); if (cHuGang != -1) isHaveHuGang = true; } else{ //这是有玩家杠牌之后发两张牌的情况 // console.warn("碰牌按钮被点击了 这是有玩家杠牌之后发两张牌的情况 "); for (var i = 0; i < this.masks.length; i++) { if(i != chairId && (this.masks[i] & 16 || this.masks[i] & 8 || this.masks[i] & 32)){ // console.warn("碰牌按钮被点击了 有人可以胡杠补 "); isHaveHuGang = true; break; } } // console.warn("碰牌按钮被点击了 isHaveHuGang ",isHaveHuGang); if(!isHaveHuGang){ //至此没有人可以胡杠补 let otherKP = -1;//除点碰之外可碰的玩家 for (var i = 0; i < this.masks.length; i++) { if(i != chairId && this.masks[i] & 4){ otherKP = i; } } if(otherKP >= 0){ let zjjl = 0; if((this.gangAfterData.chairId + 1) % this.ccount == chairId) zjjl = 1; else if((this.gangAfterData.chairId + 2) % this.ccount == chairId) zjjl = 2; else if((this.gangAfterData.chairId + 3) % this.ccount == chairId) zjjl = 3; let qtjl = 0; if((this.gangAfterData.chairId + 1) % this.ccount == otherKP) qtjl = 1; else if((this.gangAfterData.chairId + 2) % this.ccount == otherKP) qtjl = 2; else if((this.gangAfterData.chairId + 3) % this.ccount == otherKP) qtjl = 3; // console.warn("碰牌按钮被点击了 zjjl ",zjjl," qtjl ",qtjl); // isHaveHuGang = zjjl > qtjl; if(zjjl > qtjl){ if(this.masks[otherKP] == 5){ tagetChairId = otherKP; } else{ isHaveHuGang = true; } } } } } // console.warn("碰牌按钮被点击了 他人可胡杠",isHaveHuGang,this.masks); if (!isHaveHuGang) { let newCh = chairId; let newCa = card; if(tagetChairId > 0){ newCh = tagetChairId;//B玩家点碰之后需要等待C玩家点杠,如果C玩家点了碰就让B玩家碰 newCa = this.pengCard; } let res = this.logic.peng(newCh,this.handCards[newCh], newCa); if (!res) { return { code: C.FAILD, msg: C.TABLE_PENG_ERROR }; } // console.warn("到这里了嘛??? newCh "+newCh+" newCa "+newCa); /////TL++7月17日,这整个if的内容 和else的判断 let winner = this.winner; if (winner.chs.length > 0) { yield this.pushMsgAsync(-1, 'csjiang_event', { type: M.HU, data: { lead: String(this.logic.getLead(this.gangAfterData.chairId,winner.lead,winner.chs)), chairIds: winner.chs } }); this.setPaijuHuiFangData(M.HU,{ lead: String(winner.lead), chairIds: winner.chs });/////TL++ 牌局回放 push吃胡牌数据 // console.warn("提前结算AAA"); yield this.concludeGameAsync(MODE.NORMAL); } else{ // 记录碰牌 if(this.gangAfterData.chairId == -1){ res.origin = this.outerId; this.outCards[this.outerId].pop(); } else{ res.origin = this.gangAfterData.chairId; } this.huCards[newCh].push(res); this.logic.remove(this.handCards[newCh], [newCa, newCa]); // 清空权限 碰牌里面 this._eatType = 0; this._eatCard = 0; this.gangType = 0; this.gangCard = 0; this.pengCard = 0; _.fill(this.masks, 0); // 用户顺序 this.currentId = newCh; //下面是碰后可以直接杠 this.keGangInfo = {chairId: -1,data:[]}; let resx1 = this.logic.anGangAnalyze(this.handCards[this.currentId]); let isGang1 = (resx1.length > 0); let resx2 = this.logic.zmGangAnalyze(this.handCards[this.currentId], this.huCards[this.currentId]); let isGang2 = (resx2.length > 0); let resx = []; let isGang = isGang1 || isGang2; if(isGang1) resx = resx.concat(resx1);//暗杠 if(isGang2) resx = resx.concat(resx2);//自摸杠 if(isGang){ for (let x = 0; x < resx.length; ++x) { if(this.logic.isCanGang(this.handCards[this.currentId],this.huCards[this.currentId],resx[x].type,resx[x].card)){ if(!this.everyIsGang[this.currentId][0]){ this.masks[this.currentId] |= this.maskValeList[0];//能杠肯定就能补 } this.masks[this.currentId] |= 8; this.keGangInfo.chairId = this.currentId; this.keGangInfo.data.push({pos:resx[x].type,card:resx[x].card});////可杠信息,因为碰牌之后手上虽然有多个杠,但是没有听牌的话是不能杠的 } else{ if(!this.everyIsGang[this.currentId][0]){ this.masks[this.currentId] |= this.maskValeList[0]; } } } } for (let i = 0; i < this.ccount; ++i) { let pengdata = {////这种一定要声明在for循环里面 chairId: String(newCh), card: String(newCa) } if(i == newCh){ pengdata.mask = this.masks[i]; pengdata.keGangInfo = this.keGangInfo; let hutipdataTL = this.logic.hutip(i,this.handCards[i],this.huCards[i],this.huCards,this.outCards);////碰牌调用胡牌提示 pengdata.hutipdata = hutipdataTL; this.changeCurrQSHInfo(newCh,M.PENG,0,newCa); } else{ pengdata.mask = 0; pengdata.keGangInfo = {chairId: -1,data:[]}; pengdata.hutipdata = { renyi:0,//////是否可胡任意牌,0表示不满足1表示满足 kehuData:[]/////对象数组,分别表示打哪张可胡哪几张数据 }; } yield this.pushMsgAsync(i, 'csjiang_event', { type: M.PENG, data: pengdata }); } let pengdatapg = {////碰的旁观数据 chairId: String(newCh), card: String(newCa) } pengdatapg.hutipdata = { renyi:0,//////是否可胡任意牌,0表示不满足1表示满足 kehuData:[]/////对象数组,分别表示打哪张可胡哪几张数据 }; yield this.lookMsgAsync('csjiang_event', { type: M.PENG, data: pengdatapg });////TL++ ////20200831增加胡牌提示的时候把下面这句换成了上面那一段 // yield this.pushMsgAsync(-1, 'csjiang_event', { type: M.PENG, data: { chairId: String(chairId), card: String(card) } }); let pjhfsplist = { shouPai:this.logic.deepCloneTL(this.handCards), lastCount:String(this.logic.leaveCount()), outCards:this.logic.deepCloneTL(this.outCards), opData:{ chairId: String(newCh), card: String(newCa) } } this.setPaijuHuiFangData(M.PENG,pjhfsplist);/////TL++ 牌局回放 push碰操作数据 if(this.gangAfterData.chairId != -1){ let gfcards = this.gangAfterData.cards; let xdIndex = 0; if(newCa == gfcards.card1) xdIndex = 1; else if(newCa == gfcards.card2) xdIndex = 2; if(xdIndex > 0){ let cmoCard = {}; if(xdIndex == 1) cmoCard = {card1:0,card2:gfcards.card2} else if(xdIndex == 2) cmoCard = {card1:gfcards.card1,card2:0} yield this.updateGangafterData(this.gangAfterData.chairId,cmoCard); } } } } else { let ddcwj = _.findIndex(this.masks, (m, i) => (m == 5));//等待吃的玩家 let gxtype = this.logic.getDDGXType(1,chairId,ddcwj,this.gangAfterData.chairId,this.ccount,this.masks); let old_pengCard = this.pengCard; // 置于等待 this.masks[chairId] = 5; this.pengCard = card; if(gxtype == 1){ this.masks[ddcwj] = 0; } else if(gxtype == 2){ this.masks[chairId] = 0; this.pengCard = old_pengCard; } let __cHuDengDai = _.findIndex(this.masks, (m) => (m == 17));////// if(__cHuDengDai != -1) { // console.warn("碰牌这里调用了胡牌",__cHuDengDai) // 为了解决A玩家杠后2张牌发出来之后,B玩家可吃胡C,D玩家可碰杠补胡,然后几人的操作顺序如果最后一个操作为胡或过的时候正常, // 但是如果最后一个操作为为吃碰杠补时会卡住的bug this.masks[chairId] = 0; return this.succCardAsync(__cHuDengDai).then(() => ({ code: C.OK })); } // console.warn("碰牌 置于等待 this.pengCard "+this.pengCard); // 查找等待 TL++下面这一段,为了解决A打出一张牌之后B可吃胡C可碰情况下 C先点碰B点吃会死掉的问题 这是原始代码的重大天然Bug let cGang = -1; let cBu = -1; let cPeng = -1; let _cChi = -1; // console.warn("这里是啥情况啊",this.masks); for (let i = 0; i < this.masks.length; ++i) { // if (i == this.currentId || i == chairId) continue;///////TL++zsyl 这种写法会导致拉杠胡的玩家点击过胡之后被拉杠胡的玩家杠不出来的问题 if (i == chairId) continue;//////TL++,为了解决拉杠胡的玩家点击过胡之后被拉杠胡的玩家杠不出来的问题 if (this.masks[i] == 9) { cGang = i; continue; } if (this.masks[i] == 33) { cBu = i; continue; } if (this.masks[i] == 5) { cPeng = i; continue; } if (this.masks[i] == 3) { _cChi = i; continue; } } // console.warn("ppppppppppp444 ",chairId,cGang,cPeng,_cChi); // console.warn("2222情况啊",cGang, this.gangType,this.gangCard); // 杠 if (cGang != -1 && this.gangType > 0 && this.gangCard > 0) { return this.gangCardAsync(cGang, this.gangCard, this.gangType).then(() => ({ code: C.OK })); } else if (cBu != -1 && this.buType > 0 && this.buCard > 0) { return this.buCardAsync(cBu, this.buCard, this.buType).then(() => ({ code: C.OK })); } } // let str4 = "cstable 碰牌id:%s"+this.id + ",uid"+chairId+","+ this.state +" card "+card; // logger.info(str4);////cssj return { code: C.OK }; }); // 吃牌,1-@**左吃, 2-*@*中吃, 3-@**右吃 吃碰完可以直接杠 proto.eatCardAsync = cor(function* (chairId, card, type) { let str3 = "cstable 吃牌id:%s "+this.id + " ,uid "+chairId+" ,this.masks "+ this.masks +",card "+card; logger.warn(str3);////cssj // 参数校验 if (!type && (type < 1 || type > 3)) { return { code: C.FAILD, msg: C.GAME_PARAM_ERROR }; } if(this.gangAfterData.chairId == -1){ if (card != this.outCard) { return { code: C.FAILD, msg: C.GAME_PARAM_ERROR }; } } else{ if (card != this.gangAfterData.cards.card1 && card != this.gangAfterData.cards.card2){ return { code: C.FAILD, msg: C.GAME_PARAM_ERROR }; } } // 权限校验 if (!(this.masks[chairId] & 2)) { return { code: C.FAILD, msg: C.TABLE_MASK_ERROR }; } if(!this.logic.isCanCPB(this.handCards[chairId],Logic.STYLE.CHI,type)){ return { code: C.FAILD, msg: C.TABLE_NOTONLYBD }; } // 他人可胡杠碰 var cHuGangPeng = _.findIndex(this.masks, (m) => (((m & 16) || (m & 8) || (m & 4) || (m & 32)) && !(m & 2))); // console.warn("111他人可胡杠碰",cHuGangPeng); if (cHuGangPeng == -1) { let res = this.logic.chi(this.handCards[chairId], card, type); if (!res) { return { code: C.FAILD, msg: C.TABLE_PENG_ERROR }; } /////TL++7月17日,这整个if的内容 和else的判断 let winner = this.winner; // console.warn("222他人可胡杠碰",winner.chs.length); if (winner.chs.length > 0) { yield this.pushMsgAsync(-1, 'csjiang_event', { type: M.HU, data: { lead: String(this.logic.getLead(this.gangAfterData.chairId,winner.lead,winner.chs)), chairIds: winner.chs } }); this.setPaijuHuiFangData(M.HU,{ lead: String(winner.lead), chairIds: winner.chs });/////TL++ 牌局回放 push吃胡牌数据 // console.warn("提前结算aaa"); yield this.concludeGameAsync(MODE.NORMAL); } else{ // 记录吃牌 if(this.gangAfterData.chairId == -1){ res.origin = this.outerId; this.outCards[this.outerId].pop(); } else{ res.origin = this.gangAfterData.chairId; } this.huCards[chairId].push(res); if (type == 1) { this.logic.remove(this.handCards[chairId], [card + 1, card + 2]); } else if (type == 2) { this.logic.remove(this.handCards[chairId], [card - 1, card + 1]); } else { this.logic.remove(this.handCards[chairId], [card - 2, card - 1]); } // 清空权限 吃牌里面 this._eatType = 0; this._eatCard = 0; this.gangType = 0; this.gangCard = 0; this.pengCard = 0; _.fill(this.masks, 0); // 用户顺序 this.currentId = chairId; //下面是吃后可以直接杠 this.keGangInfo = {chairId: -1,data:[]}; let resx1 = this.logic.anGangAnalyze(this.handCards[chairId]); let isGang1 = (resx1.length > 0); let resx2 = this.logic.zmGangAnalyze(this.handCards[chairId], this.huCards[chairId]); let isGang2 = (resx2.length > 0); let resx = []; let isGang = isGang1 || isGang2; if(isGang1) resx = resx.concat(resx1);//暗杠 if(isGang2) resx = resx.concat(resx2);//自摸杠 if(isGang){ for (let x = 0; x < resx.length; ++x) { if(this.logic.isCanGang(this.handCards[chairId],this.huCards[chairId],resx[x].type,resx[x].card)){ if(!this.everyIsGang[chairId][0]){ this.masks[chairId] |= this.maskValeList[0];//能杠肯定就能补 } this.masks[chairId] |= 8; this.keGangInfo.chairId = chairId; this.keGangInfo.data.push({pos:resx[x].type,card:resx[x].card});////可杠信息,因为吃牌之后手上虽然有多个杠,但是没有听牌的话是不能杠的 } else{ if(!this.everyIsGang[chairId][0]){ this.masks[chairId] |= this.maskValeList[0]; } } } } // 发送通知 for (let i = 0; i < this.ccount; ++i) { let chidata = { chairId: String(chairId), type: String(type), card: String(card) } if(i == chairId){ chidata.mask = this.masks[i]; chidata.keGangInfo = this.keGangInfo; let hutipdataTL = this.logic.hutip(i,this.handCards[i],this.huCards[i],this.huCards,this.outCards);////吃牌调用胡牌提示 chidata.hutipdata = hutipdataTL; this.changeCurrQSHInfo(chairId,M.CHI,type,card); } else{ chidata.mask = 0; chidata.keGangInfo = {chairId: -1,data:[]}; chidata.hutipdata = { renyi:0,//////是否可胡任意牌,0表示不满足1表示满足 kehuData:[]/////对象数组,分别表示打哪张可胡哪几张数据 }; } yield this.pushMsgAsync(i, 'csjiang_event', { type: M.CHI, data: chidata }); } let chidatapg = { ////TL++吃牌旁观数据 chairId: String(chairId), type: String(type), card: String(card) } chidatapg.hutipdata = { renyi:0,//////是否可胡任意牌,0表示不满足1表示满足 kehuData:[]/////对象数组,分别表示打哪张可胡哪几张数据 }; yield this.lookMsgAsync('csjiang_event', { type: M.CHI, data: chidatapg });////TL++吃牌旁观消息 ////20200901为了增加胡牌提示把下面这一段换成了上面那一段 // yield this.pushMsgAsync(-1, 'csjiang_event', { type: M.CHI, data: { chairId: String(chairId), type: String(type), card: String(card) } }); let pjhfsplist = { shouPai:this.logic.deepCloneTL(this.handCards), lastCount:String(this.logic.leaveCount()), outCards:this.logic.deepCloneTL(this.outCards), opData:{ chairId: String(chairId), type: String(type), card: String(card) } } this.setPaijuHuiFangData(M.CHI,pjhfsplist);/////TL++ 牌局回放 push吃操作数据 if(this.gangAfterData.chairId != -1){ let gfcards = this.gangAfterData.cards; let xdIndex = 0; let newCa = card; if(newCa == gfcards.card1) xdIndex = 1; else if(newCa == gfcards.card2) xdIndex = 2; if(xdIndex > 0){ let cmoCard = {}; if(xdIndex == 1) cmoCard = {card1:0,card2:gfcards.card2} else if(xdIndex == 2) cmoCard = {card1:gfcards.card1,card2:0} yield this.updateGangafterData(this.gangAfterData.chairId,cmoCard); } } } } else { // 置于等待 this.masks[chairId] = 3; this._eatType = type; this._eatCard = card; let __cHuDengDai = _.findIndex(this.masks, (m) => (m == 17));////// if(__cHuDengDai != -1) { // console.warn("吃牌这里调用了胡牌",__cHuDengDai) // 为了解决A玩家杠后2张牌发出来之后,B玩家可吃胡C,D玩家可碰杠补胡,然后几人的操作顺序如果最后一个操作为胡或过的时候正常, // 但是如果最后一个操作为为吃碰杠补时会卡住的bug this.masks[chairId] = 0; return this.succCardAsync(__cHuDengDai).then(() => ({ code: C.OK })); } // 查找等待 TL++下面这一段,为了解决A打出一张牌之后B可吃胡C可碰情况下 C先点碰B点吃会死掉的问题 这是原始代码的重大天然Bug let cGang = -1; let cBu = -1; let cPeng = -1; let _cChi = -1; // console.warn("这里是啥情况啊",this.masks); for (let i = 0; i < this.masks.length; ++i) { // if (i == this.currentId || i == chairId) continue;///////TL++zsyl 这种写法会导致拉杠胡的玩家点击过胡之后被拉杠胡的玩家杠不出来的问题 if (i == chairId) continue;//////TL++,为了解决拉杠胡的玩家点击过胡之后被拉杠胡的玩家杠不出来的问题 if (this.masks[i] == 9) { cGang = i; continue; } if (this.masks[i] == 33) { cBu = i; continue; } if (this.masks[i] == 5) { cPeng = i; continue; } if (this.masks[i] == 3) { _cChi = i; continue; } } // console.warn("2222情况啊",cGang, this.gangType,this.gangCard); // 杠碰吃 if (cGang != -1 && this.gangType > 0 && this.gangCard > 0) { return this.gangCardAsync(cGang, this.gangCard, this.gangType).then(() => ({ code: C.OK })); } else if (cBu != -1) { return this.buCardAsync(cBu, this.buCard, this.buType).then(() => ({ code: C.OK })); } else if (cPeng != -1) { let cc = this.outCard; if(this.gangAfterData.chairId != -1){ cc = this.pengCard; } if(cc > 0){ return this.pengCardAsync(cPeng, cc).then(() => ({ code: C.OK })); } } else if (_cChi != -1 && this._eatType > 0) { let cc = this.outCard; if(this.gangAfterData.chairId != -1){ cc = this._eatCard; } if(cc > 0){ return this.eatCardAsync(_cChi, cc, this._eatType).then(() => ({ code: C.OK })); } } } // let str4 = "cstable 吃牌id:"+this.id + ",uid"+chairId+","+ this.state +",card "+card; // logger.info(str4);////cssj return { code: C.OK }; }); // 补牌,1-普通补, 2-暗补, 3-自摸补 proto.buCardAsync = cor(function* (chairId, card, type) { let str3 = "cstable 补牌,id: "+this.id + " ,uid "+chairId+", this.masks "+ this.masks +" ,card "+card; logger.warn(str3);////cssj // 参数校验 if (!type && (type < 1 || type > 3)) { return { code: C.FAILD, msg: C.GAME_PARAM_ERROR }; } if(this.gangAfterData.chairId == -1){ if (type == 1 && card != this.outCard) { return { code: C.FAILD, msg: C.GAME_PARAM_ERROR }; } } else{ if (card != this.gangAfterData.cards.card1 && card != this.gangAfterData.cards.card2){ return { code: C.FAILD, msg: C.GAME_PARAM_ERROR }; } } if(this.gangAfterData.chairId == -1){ if (type > 1 && this.currentId != chairId) { return { code: C.FAILD, msg: C.GAME_PARAM_ERROR }; } } if (!(this.masks[chairId] & 32)) { return { code: C.FAILD, msg: C.TABLE_MASK_ERROR }; } if(!this.logic.isCanCPB(this.handCards[chairId],Logic.STYLE.BU,type)){ return { code: C.FAILD, msg: C.TABLE_NOTONLYBD }; } // 他人可胡 // let __cHu = (type == 2) ? -1 : _.findIndex(this.masks, (m) => ((m & 16) && !(m & 8) && !(m & 32) )); // console.warn("111拉杠胡%%%%%%%%%%%%%%%%%%%%%%",__cHu,type); let isHveeQSH = false;//是否有起手胡 let tagetChairId = -1; let tagetOP = -1; for (var i = 0; i < this.masks.length; i++) { if(i != chairId){ if(this.masks[i] & 16){ isHveeQSH = true; break; } for (var x = 1; x < this.maskValeList.length; x++) { if(this.masks[i] & this.maskValeList[x]){ isHveeQSH = true; break; } } } } if(!isHveeQSH && this.gangAfterData.chairId != -1){ //只有杠后两张牌的时候杠才会两个人同时出现 //至此没有人可以胡 let otherKG = -1;//除点补之外可杠或可补的玩家 for (var i = 0; i < this.masks.length; i++) { if(i != chairId && (this.masks[i] & 8 || chairId && this.masks[i] & 32)){ otherKG = i; break; } } if(otherKG >= 0){ let zjjl = 0; if((this.gangAfterData.chairId + 1) % this.ccount == chairId) zjjl = 1; else if((this.gangAfterData.chairId + 2) % this.ccount == chairId) zjjl = 2; else if((this.gangAfterData.chairId + 3) % this.ccount == chairId) zjjl = 3; let qtjl = 0; if((this.gangAfterData.chairId + 1) % this.ccount == otherKG) qtjl = 1; else if((this.gangAfterData.chairId + 2) % this.ccount == otherKG) qtjl = 2; else if((this.gangAfterData.chairId + 3) % this.ccount == otherKG) qtjl = 3; if(zjjl > qtjl){ if(this.masks[otherKG] == 9 || this.masks[otherKG] == 33){ tagetChairId = otherKG; if(this.masks[otherKG] == 9) tagetOP = 8; } else{ isHveeQSH = true; } } } } if (!isHveeQSH) { //(__cHu == -1) { let newCh = chairId; let newCa = card; let newTy = type if(tagetChairId > 0){ newCh = tagetChairId;//B玩家点杠或补之后需要等待C玩家点胡,如果C玩家点了杠就让B玩家杠或补 if(tagetOP == 8){ newCa = this.gangCard; newTy = this.gangType; }else{ newCa = this.buCard; newTy = this.buType; } } let res = null; if (newTy == 1 || newTy == 2) { res = this.logic.bu(newCh,this.handCards[newCh], newCa, newTy); } else if (newTy == 3) { res = this.logic.zmBu(newCh,this.handCards[newCh], this.huCards[newCh], newCa); } if (!res) { return { code: C.FAILD, msg: C.TABLE_GANG_ERROR }; } /////TL++7月17日,这整个if的内容 和else的判断 let winner = this.winner; if (winner.chs.length > 0) { yield this.pushMsgAsync(-1, 'csjiang_event', { type: M.HU, data: { lead: String(this.logic.getLead(this.gangAfterData.chairId,winner.lead,winner.chs)), chairIds: winner.chs } }); this.setPaijuHuiFangData(M.HU,{ lead: String(winner.lead), chairIds: winner.chs });/////TL++ 牌局回放 push吃胡牌数据 // console.warn("提前结算BBB"); yield this.concludeGameAsync(MODE.NORMAL); } else{ // 记录补牌 if (newTy == 1) { if(this.gangAfterData.chairId == -1){ res.origin = this.outerId; this.outCards[this.outerId].pop(); } else{ res.origin = this.gangAfterData.chairId; } this.huCards[newCh].push(res); this.logic.remove(this.handCards[newCh], res.cards); } else if (newTy == 2) { this.huCards[newCh].push(res); this.logic.remove(this.handCards[newCh], [newCa, newCa, newCa, newCa]); this.logic.adjust(this.handCards[newCh]); } else if (newTy == 3) { // console.warn("333拉杠胡%%%%%%%%%%%%%%%%%%%%%%",this.logic.isLaGang,this.isGangHu); let huCard = _.find(this.huCards[newCh], (o) => { return (o.style == Logic.STYLE.PENG && o.cards[0] == newCa); }); if (!huCard) { return { code: C.FAILD, msg: C.TABLE_GANG_ERROR }; } // console.warn("拉杠胡%%%%%%%%%%%%%%%%%%%%%%" ,this.isGangHu); // 抢杠胡 if (!this.isBuHu) { let allowIds = [], otherIds = []; for (let i = 0; i < this.ccount; ++i) { // 排除自己 if (i != newCh) { let huRes = this.logic.huAnalyze(i,this.handCards[i], newCa, this.huCards[i]); // console.error("ssccCCC胡牌分析 huRes",huRes); // let lg2 = false;///TL++ if (huRes) { if (!this.isBuHu) this.isGangHu = true; this.huRes[i] = huRes; this.masks[i] |= 16; allowIds.push(this.users[i].id); continue; } } // 其他玩家 otherIds.push(this.users[i].id); } // 有人可胡 if (allowIds.length > 0) { // 置于等待 this.masks[chairId] = 33; this.buType = type; this.buCard = card; // 抢补通知 yield this.pushMsgAsync(otherIds, 'csjiang_event', { type: M.MASK_HU, data: { mask: '0', card: String(newCa),isBu: '1' } }); yield this.pushMsgAsync(allowIds, 'csjiang_event', { type: M.MASK_HU, data: { mask: '16', card: String(newCa),isBu: '1' } }); let pjhfsplist2 = { shouPai:this.logic.deepCloneTL(this.handCards), lastCount:this.logic.leaveCount(), outCards:this.logic.deepCloneTL(this.outCards), opData:{ mask: '16', card: String(newCa),isBu: '1' } } this.setPaijuHuiFangData(M.MASK_HU,pjhfsplist2);/////TL++ 牌局回放 push杠操作数据 // console.warn("抢杠胡同盟会告知",allowIds); return { code: C.OK }; } } huCard.style = Logic.STYLE.ZMBU; this.isGangHu = false;/////TL++,修复20250309号bug // console.warn("55拉补胡%%%%%%%%%%%%%%%%%%%%%%",this.logic.isLaGang,this.buType,this.buCard = 0); this.isBuHu = false;/////TL++,8月28日晚上,为了解决过胡拉杠之后就算自己已经摸牌也不能再次拉杠的问题 this.logic.remove(this.handCards[newCh], newCa); this.logic.adjust(this.handCards[newCh]); } // if(this.chBanker == chairId) this.isZJYG = true;////本局庄家是否有杠 // 清空权限 补牌里面 this._eatType = 0; this._eatCard = 0; this.gangType = 0; this.gangCard = 0; this.buType = 0; this.buCard = 0; this.pengCard = 0; _.fill(this.masks, 0); // 总杠次 // this.gonCount += 1; // 发送通知 // console.warn("333 声剩余声剩余声剩"); let lastCount = this.logic.leaveCount();/////TL++xg let pjhfsplist = { shouPai:this.logic.deepCloneTL(this.handCards), lastCount:lastCount, outCards:this.logic.deepCloneTL(this.outCards), opData:{ chairId: String(newCh), type: String(newTy), card: String(newCa), lastCount: String(lastCount) } } if(tagetOP == 8){ // console.warn("走到这里了=== newCh "+newCh); this.changeCurrQSHInfo(newCh,M.GANG,newTy,newCa); this.setPaijuHuiFangData(M.GANG,pjhfsplist);/////TL++ 牌局回放 push杠操作数据 yield this.pushMsgAsync(-1, 'csjiang_event', { type: M.GANG, data: { chairId: String(newCh), type: String(newTy), card: String(newCa), lastCount: String(lastCount) } }); }else { this.changeCurrQSHInfo(newCh,M.BU,newTy,newCa); this.setPaijuHuiFangData(M.BU,pjhfsplist);/////TL++ 牌局回放 push杠操作数据 yield this.pushMsgAsync(-1, 'csjiang_event', { type: M.BU, data: { chairId: String(newCh), type: String(newTy), card: String(newCa), lastCount: String(lastCount) } }); } if(this.gangAfterData.chairId != -1){ let gfcards = this.gangAfterData.cards; let xdIndex = 0; if(newCa == gfcards.card1) xdIndex = 1; else if(newCa == gfcards.card2) xdIndex = 2; if(xdIndex > 0){ let cmoCard = {}; if(xdIndex == 1) cmoCard = {card1:0,card2:gfcards.card2} else if(xdIndex == 2) cmoCard = {card1:gfcards.card1,card2:0} yield this.updateGangafterData(this.gangAfterData.chairId,cmoCard); } } yield this.touchCardAsync(newCh); ///////补牌摸牌 } } else { let ddcwj = _.findIndex(this.masks, (m, i) => (m == 33));//等待吃的玩家 let gxtype = this.logic.getDDGXType(3,chairId,ddcwj,this.gangAfterData.chairId,this.ccount,this.masks); let old_buType = this.buType; let old_buCard = this.buCard; // 置于等待 this.masks[chairId] = 33; this.buType = type; this.buCard = card; if(gxtype == 1){ this.masks[ddcwj] = 0; } else if(gxtype == 2){ this.masks[chairId] = 0; this.buType = old_buType; this.buCard = old_buCard; } let __cHuDengDai = _.findIndex(this.masks, (m) => (m == 17));////// if(__cHuDengDai != -1) { // console.warn("补牌这里调用了胡牌",__cHuDengDai) // 为了解决A玩家杠后2张牌发出来之后,B玩家可吃胡C,D玩家可碰杠补胡,然后几人的操作顺序如果最后一个操作为胡或过的时候正常, // 但是如果最后一个操作为为吃碰杠补时会卡住的bug this.masks[chairId] = 0; return this.succCardAsync(__cHuDengDai).then(() => ({ code: C.OK })); } else{ // 查找起手胡等待 // 为了解决A玩家起手牌可以胡杠补,BC玩家有六六顺时,BC玩家先点六六顺之后A玩家点杠或补会卡住的bug, // (正确应为:BC玩家先点六六顺之后A玩家点杠后应该六六顺和杠或补都生效,若玩家A点胡则胡生效六六顺不生效) for (let i = 0; i < this.masks.length; ++i) { let cqsh = -1; // console.warn("补牌里处理等待的起手胡111 "+this.masks[i]); // if (i == this.currentId || i == chairId) continue;///////TL++zsyl 这种写法会导致拉杠胡的玩家点击过胡之后被拉杠胡的玩家杠不出来的问题 if (i == chairId) continue;//////TL++,为了解决拉杠胡的玩家点击过胡之后被拉杠胡的玩家杠不出来的问题 if (this.masks[i] == 65 || this.masks[i] == 129 ||this.masks[i] == 257 ||this.masks[i] == 513 ||this.masks[i] == 1025 ||this.masks[i] == 2049) { cqsh = i; } if (cqsh != -1 ) { // console.warn("处理等待的起手胡222 ",cqsh, this.qshType[cqsh], this.qshCards[cqsh]); this.masks[i]--;//mask=129传给前端是不显示按钮的,为了等待在原本的mask上+1了,现在可以操作了所以-1 yield this.qshCardAsync(cqsh, this.qshType[cqsh], this.qshCards[cqsh]).then(() => ({ code: C.OK })); } } } } // let str4 = "cstable222 杠牌,id:"+this.id + ",uid"+chairId+","+ this.state +",card "+card; // logger.info(str4);////cssj return { code: C.OK }; }); proto.changeCurrQSHInfo = function (chairId,operate,type,card){ // console.warn("吃碰杠之后修改起手胡需要展示的牌 ",chairId,operate,type,card,this.currQSHInfo[chairId].length); if(this.currQSHInfo[chairId].length == 0) return; let cards = []; if(operate == M.OUT_CARD){ cards = [card]; } else if(operate == M.CHI){ if(type == 1) cards = [card+1,card+2]; else if(type == 2) cards = [card-1,card+1]; else if(type == 3) cards = [card-1,card-2]; } else if(operate == M.PENG){ cards = [card,card]; } else if(operate == M.GANG){ if(type == 1) cards = [card,card,card]; else if(type == 2) cards = [card,card,card,card]; else if(type == 3) cards = [card]; } else if(operate == M.BU){ if(type == 1) cards = [card,card,card]; else if(type == 2) cards = [card,card,card,card]; else if(type == 3) cards = [card]; } let oldCards = this.logic.deepCloneTL(this.currQSHInfo[chairId][0].cards); // console.warn("更新当前起手牌型数据111oldCards ",oldCards) for (let j = 0; j < cards.length; j++) { if(cards[j] == 0) continue; let iscz = false; for (let k = 0; k < oldCards.length; k++) { if(cards[j] == oldCards[k]){ oldCards[k] = -1; iscz = true; break; } } if(!iscz){ for (let k = 0; k < oldCards.length; k++) { if(oldCards[k] == 0){ oldCards[k] = -1; break; } } } } // console.warn("更新当前起手牌型数据222oldCards ",oldCards) let newCards = []; for (let k = 0; k < oldCards.length; k++) { if(oldCards[k] > -1){ newCards[newCards.length] = oldCards[k]; } } // console.warn("更新当前起手牌型数据333newCards ",newCards) this.currQSHInfo[chairId][0].cards = newCards; // console.warn("更新当前起手牌型数据444 .Cards ",this.currQSHInfo[chairId][0].cards) }; // 起手胡 处理前端 proto.qshCardAsync = cor(function* (chairId,_type,_cards) { let str4 = "cstable222 起手胡,id:"+this.id + ",uid"+chairId+" _type "+ _type +",_cards "+_cards; logger.warn(str4);////cssj let msk = this.masks[chairId]; // console.warn("起手胡 chairId " + chairId + " msk "+msk+" _cards "+_cards ); if (!(msk & 64 || msk & 128 || msk & 256 || msk & 512 || msk & 1024 || msk & 2048)) { return { code: C.FAILD, msg: C.TABLE_MASK_ERROR }; } let cards = _cards;//起手牌型需要展示给其他玩家的牌 let cards2 = this.logic.deepCloneTL(_cards); let qshType = _type;//.indexOf(1); if(this.logic.everyQSHType[chairId][qshType] == 0){ return { code: C.FAILD, msg: C.TABLE_MASK_ERROR }; } else{ //起手的六六顺消耗过的牌起手四喜不能再次使用,起手四喜消耗过的牌起手六六顺不能再次使用, // console.warn("起手胡22 qshType " + qshType + " everyXiaoHuList "+this.logic.everyXiaoHuList[chairId]); if(qshType == 0){ if(this.logic.getISBH(this.handCards[chairId],cards) && !this.logic.getISBH(this.logic.everyQSHCZGList[chairId],cards)){ // console.warn("起手牌型参数合法"); if(qshType == 0){ if(this.logic.everyXiaoHuList[chairId].indexOf(1) != -1 || this.logic.everyXiaoHuList[chairId].indexOf(2) != -1){ //起手点了板板胡或者缺一色之后再点大四喜或者六六顺,需要展示全部的牌 cards = this.logic.deepCloneTL(this.handCards[chairId]); } } } else{ return { code: C.FAILD, msg: C.GAME_PARAM_ERROR }; } } else if(qshType == 1 ){ if(this.logic.everyXiaoHuList[chairId].indexOf(qshType) == -1){ // console.warn("起手牌型参数合法"); cards = this.logic.deepCloneTL(this.handCards[chairId]); } else{ return { code: C.FAILD, msg: C.GAME_PARAM_ERROR }; } } else if(qshType == 2){ if(this.logic.everyXiaoHuList[chairId].indexOf(qshType) == -1){ // console.warn("起手牌型参数合法"); cards = this.logic.deepCloneTL(this.handCards[chairId]); } else{ let isqs = this.logic.castCount == this.playerAllCount*this.mcount+1;//是否起手 let shoupai = this.logic.deepCloneTL(this.handCards[chairId]); let ismz = this.logic.isQueYiSe(chairId,shoupai,isqs); //清一色可胡两次缺一色 if(ismz) cards = this.logic.deepCloneTL(this.handCards[chairId]); else return { code: C.FAILD, msg: C.GAME_PARAM_ERROR }; } } else if(qshType == 3 || qshType == 5){ if(this.logic.getISBH(this.handCards[chairId],cards) && !this.logic.getISBH(this.logic.everyQSHCZGList[chairId],cards)){ if(qshType == 3){ if(this.logic.everyXiaoHuList[chairId].indexOf(1) != -1 || this.logic.everyXiaoHuList[chairId].indexOf(2) != -1){ //起手点了板板胡或者缺一色之后再点大四喜或者六六顺,需要展示全部的牌 cards = this.logic.deepCloneTL(this.handCards[chairId]); } } } else{ return { code: C.FAILD, msg: C.GAME_PARAM_ERROR }; } } else if(qshType == 4){ //起手六六顺或者中途六六顺消耗过的牌中途四喜可以再次使用, if(this.logic.getISBH(this.handCards[chairId],cards) && !this.logic.getISBH2(this.logic.everyQSHCZGList2[chairId],cards)){ if(qshType == 3){ if(this.logic.everyXiaoHuList[chairId].indexOf(1) != -1 || this.logic.everyXiaoHuList[chairId].indexOf(2) != -1){ //起手点了板板胡或者缺一色之后再点大四喜或者六六顺,需要展示全部的牌 cards = this.logic.deepCloneTL(this.handCards[chairId]); } } } else{ return { code: C.FAILD, msg: C.GAME_PARAM_ERROR }; } } } let __cHu = -1;//_.findIndex(this.masks, (m) => ((m & 16) )); for (let i = 0; i < this.masks.length; ++i) { if(i != chairId && this.masks[i] & 16){ __cHu = i; break; } } this.qshType[chairId] = 0; this.qshCards[chairId] = []; if (__cHu == -1) { //删除起手胡权限 // console.warn("删除起手胡权限之前"); this.masks[chairId] = this.logic.getNewMask(this.masks[chairId]); if(qshType == 0 || qshType == 4 || qshType == 3 || qshType == 5){ this.logic.everyQSHCZGList[chairId] = this.logic.everyQSHCZGList[chairId].concat(cards2); this.logic.everyQSHCZGList2[chairId].push(cards2); // console.warn("...... everyQSHCZGList "+chairId+" "+JSON.stringify(this.logic.everyQSHCZGList2[chairId])); } this.logic.everyXiaoHuList[chairId].push(qshType); // console.warn("删除起手胡权限 everyXiaoHuList "+this.logic.everyXiaoHuList[chairId]); this.logic.qshuAnalyze(chairId,this.handCards[chairId]); for (let x = 0; x < this.logic.everyQSHType[chairId].length; ++x) { if(this.logic.everyQSHType[chairId][x] == 1){ this.masks[chairId] |= this.maskValeList[x+1]; } } for (let x = 0; x < this.handCards[chairId].length; ++x) { if(x >= cards.length) cards[cards.length] = 0; } _.reverse(cards) let isCanOut = this.logic.getIsCanOut(this.masks); let diceNum1 = this.logic.dice(); let diceNum2 = this.logic.dice(); this.currQSHInfo[chairId][0] = {//当前各个玩家展示的起手胡信息 chairId: chairId, type: qshType, cards: cards, diceNums: [diceNum1,diceNum2] } let qshdata = { chairId: chairId, type: qshType, cards: cards, isCanOut: isCanOut } qshdata.startNum1 = String(diceNum1);////骰子1的点数 qshdata.startNum2 = String(diceNum2);////骰子2的点数 let bcQSHSY = this.logic.getBCQSHSY(chairId,qshType,diceNum1,diceNum2);//本次起手胡各个玩家的输赢 let playNowScore = []; for (let i = 0; i < this.ccount; ++i) { let user = this.users[i]; if (user) { playNowScore[i] = this.score.getScore(user.id) + bcQSHSY[i]; // console.warn("得到分数 i "+i+" get "+this.score.getScore(user.id)+" bcsy "+bcQSHSY[i]+" now "+playNowScore[i]); this.score.writeScore(user.id,bcQSHSY[i], 0);//设置分数 } } qshdata.playNowScore = playNowScore; for (let i = 0; i < this.ccount; ++i) { if(i == chairId){ // console.warn("this.masks[chairId] "+this.masks[chairId]); qshdata.canSelects = this.logic.canSelects[chairId] qshdata.mask = String(this.masks[chairId]); // } else{ qshdata.mask = 0; qshdata.canSelects = {type:-1,cards:[]} } yield this.pushMsgAsync(i, 'csjiang_event', { type: M.QSH, data: qshdata } ); } qshdata.mask = 0; qshdata.canSelects = {type:-1,cards:[]} yield this.lookMsgAsync('csjiang_event', { type: M.QSH, data: qshdata }); qshdata.mask = String(this.masks[chairId]); qshdata.canSelects = this.logic.canSelects[chairId]; this.setPaijuHuiFangData(M.QSH,qshdata); // console.warn("起手胡操作之后的mask "+this.masks); if(_.findIndex(this.masks, (m) => ((m >= 64))) == -1){ //没有玩家有起手胡的时候查找并处理杠补的等待 for (let i = 0; i < this.masks.length; ++i) { let cGang = -1; let cbu = -1; if (this.masks[i] == 9) { cGang = i; } if (this.masks[i] == 33) { cbu = i; } if (cGang != -1 && this.gangType > 0 && this.gangCard > 0) { yield this.gangCardAsync(cGang, this.gangCard, this.gangType).then(() => ({ code: C.OK })); } else if (cbu != -1 && this.buCard > 0) { yield this.buCardAsync(cbu, this.buCard, this.buType).then(() => ({ code: C.OK })); } } } } else { // 置于等待 let ddmskList = [65,129,257,513,1025,2049]; this.masks[chairId] = ddmskList[qshType]; this.qshType[chairId] = qshType; this.qshCards[chairId] = _cards; // console.warn("置于等待 "+this.masks[chairId]); } return { code: C.OK }; }) // 操作是否自动出牌 proto.autoOutCardAsync = cor(function* (chairId) { // console.warn("操作是否自动出牌 "+chairId); if(this.everyIsAutoOut[chairId]) this.everyIsAutoOut[chairId] = 0; else this.everyIsAutoOut[chairId] = 1; return { code: C.OK,isAutoOut:this.everyIsAutoOut[chairId]}; }) // 胡牌 处理前端 proto.succCardAsync = cor(function* (chairId) { let str3 = "cstable 胡牌:%s "+this.id + " ,uid "+chairId+" ,this.masks "+ this.masks; logger.warn(str3);////cssj // 权限校验 if (!(this.masks[chairId] & 16)) { return { code: C.FAILD, msg: C.TABLE_MASK_ERROR }; } // 删除权限 let isCanSCQX = true;//是否可以删除权限 if(this.gangAfterData.chairId != -1){ if(chairId != this.gangAfterData.chairId && this.masks[this.gangAfterData.chairId] & 16) isCanSCQX = false; //1022修复杠后两张牌一炮多响,一人点胡之后另外一个人点过之后卡住(没胡成功也没继续发牌)的bug添加下面这个if if(chairId != this.gangAfterData.chairId && isCanSCQX){ let otherKH = _.findIndex(this.masks, (m, i) => ((m & 16 && m != 17 && i != chairId))) if(otherKH != -1) isCanSCQX = false; } } // console.warn("是否可以删除权限 "+isCanSCQX); if(isCanSCQX){ // console.error("胡牌 处理前端 可以删除权限 "); if(chairId == this.gangAfterData.chairId){ for (let i = 0; i < this.masks.length; ++i) { this.masks[i] = 0; } } else{ this.masks[chairId] = 0; } } else{ this.masks[chairId] = 17;//置于等待 // console.warn("胡牌 处理前端 置于等待"); return { code: C.OK }; } // 是否自摸 let winner = this.winner; var isMoHu = (this.currentId == chairId); // if(this.gangAfterData.chairId != -1 && this.gangAfterData.chairId == chairId) isMoHu = true; //1022修复杠后两张牌一炮多响,两人都点胡只有一个能胡成功的bug把上面的if换成了下面这个if if(this.gangAfterData.chairId != -1){ isMoHu = (this.gangAfterData.chairId == chairId) } // console.warn("胡牌 处理前端 ",this.currentId ,chairId,this.masks,this.gangAfterData.chairId); if (isMoHu) { // console.warn("胡牌 这里是自摸胡 "); winner.chs[0] = chairId; yield this.pushMsgAsync(-1, 'csjiang_event', { type: M.HU, data: { lead: String(this.logic.getLead(this.gangAfterData.chairId,winner.lead,winner.chs)), chairIds: winner.chs } }); this.setPaijuHuiFangData(M.HU,{ lead: String(winner.lead), chairIds: winner.chs });/////TL++ 牌局回放 push摸胡牌数据 // console.warn("提前结算444"); yield this.concludeGameAsync(MODE.NORMAL); } else { // console.warn("胡牌 这里补是自摸胡 isGangHu "+this.isGangHu+" isMHu "+this.isMHu); // 抢杠胡 if (this.isGangHu) { winner.lead = this.currentId; // 抢杠牌 if (this.gangType > 0 && this.gangCard > 0) { this.logic.remove(this.handCards[this.currentId], this.gangCard); this.masks[this.currentId] = 0; this.gangType = 0; this.gangCard = 0; this.buType = 0; this.buCard = 0; this.pengCard = 0; } } else { // 点炮 winner.lead = this.outerId; } // 一炮多响 let __cHu = -1; if (this.isMHu) { // 胡牌者 winner.chs.push(chairId); // 他人可胡 __cHu = _.findIndex(this.masks, (m) => ((m & 16))); } else { // 胡牌者 if (winner.chs.length <= 0) winner.chs[0] = chairId; else { let hutype = [];//this.logic.getReasultTypeTL(winner.chs[0],this.huCards[winner.chs[0]],false) let hutypenew = []//this.logic.getReasultTypeTL(chairId,this.huCards[chairId],false) winner.chs[0] = chairId; } // 他人可胡 __cHu = _.findIndex(this.masks, (m, i) => ((m & 16))) } // console.warn("有一炮多响 __cHu "+__cHu+" gangAfterData.chairId "+this.gangAfterData.chairId); // console.warn("22局部变量改变全局变量??",winner ,this.winner); // console.warn("点击胡按钮",__cHu,this.masks); if (__cHu == -1) { yield this.pushMsgAsync(-1, 'csjiang_event', { type: M.HU, data: { lead: String(this.logic.getLead(this.gangAfterData.chairId,winner.lead,winner.chs)), chairIds: winner.chs } }); this.setPaijuHuiFangData(M.HU,{ lead: String(winner.lead), chairIds: winner.chs });/////TL++ 牌局回放 push吃胡牌数据 // console.warn("提前结算555"); yield this.concludeGameAsync(MODE.NORMAL); } else{ let __cHuDEngDai = _.findIndex(this.masks, (m, i) => ((m == 17))) // console.warn("这里调用的嘛?? __cHuDEngDai "+__cHuDEngDai); if(__cHuDEngDai != -1){ return this.succCardAsync(__cHuDEngDai).then(() => ({ code: C.OK })); } } } return { code: C.OK }; }); // 结算游戏 proto.concludeGameAsync = cor(function* (mode) { /////增加下面这几行是为了保证每一把只执行一次结算方法 if(this.isYJJSGL){ // let strk = "cstable 结算游戏 id:了保证每一把只执行一次结算方法 "+this.id +"结算模式"+mode // logger.info(strk);////cssj return; } this.isYJJSGL = true; this.isYJKSGL = false;/////是否已经执行过开始函数了 this.everyIsAutoOut = _.fill(Array(this.ccount), 0); // console.warn("结算函数",mode); let str1 = "cstable 结算游戏 id: "+this.id +" 结算模式 "+mode logger.warn(str1);////cssj //ts--end // 结算数据 var winner = this.winner; var data = { mode: String(mode), lead: String(winner.lead) }; var wins = this.logic.fillDeep(Array(this.ccount), { win: 0,//总输赢 lucky: 0, trans: 0,//明杠个数 dark: 0,//暗杠个数 penggang: 0,//碰杠个数 isPoChan: 0, shiJiKouFen: 0, gangfen: 0, cardfen: 0, jiangma: 0, }); // data.hutype = [];//this.logic.getReasultTypeTL(winner.chs[0],this.huCards[winner.chs[0]],true)///////TL++胡牌牌型 胡牌人的chairID data.banker = this.chBanker;/////TL++ data.chengbao = []; let jiangmaInfo = this.logic.getJiangmaInfo(); data.jiangmaList = jiangmaInfo.jiangmaList; data.startNum1 = jiangmaInfo.startNum1; data.startNum2 = jiangmaInfo.startNum2; // let jiangmaFen = jiangmaInfo.mafen; let everyIsHLZ = [false,false,false,false]; let everyDaHuType = [[[],[]],[[],[]],[[],[]],[[],[]]]; if(this.gangAfterData.chairId != -1){ // console.warn("如果杠后两张牌都能胡则2张牌都要计算 "+this.gangAfterData.cards.card1+" "+this.gangAfterData.cards.card2); //如果杠后两张牌都能胡则2张牌都要计算 for (let i = 0; i < wins.length; ++i) { if (winner.chs.indexOf(i) == -1) continue; // console.warn("数据会不会变000 "+this.handCards[i]+" huCards "+JSON.stringify(this.huCards[i])); let istouch = false;//this.gangAfterData.chairId == i; let card1 = this.gangAfterData.cards.card1; let huRes1 = this.logic.huAnalyze(i,this.handCards[i], card1, this.huCards[i], istouch);//杠后摸牌判断第1张 // console.warn("数据会不会变111 "+this.handCards[i]+" huCards "+JSON.stringify(this.huCards[i])); if (huRes1) { let dhType = this.logic.deepCloneTL(this.logic.everyDAHType[i]); let card2 = this.gangAfterData.cards.card2; let huRes2 = this.logic.huAnalyze(i,this.handCards[i], card2, this.huCards[i], istouch);//杠后摸牌判断第2张 // console.warn("数据会不会变222 "+this.handCards[i]+" huCards "+JSON.stringify(this.huCards[i])); if (huRes2) { everyIsHLZ[i] = true; everyDaHuType[i][0] = dhType; everyDaHuType[i][1] = this.logic.everyDAHType[i]; } } } } // console.warn("结算函数计算每个人是否胡两张 "+this.gangAfterData.chairId+" everyIsHLZ "+everyIsHLZ+" everyDaHuType "+JSON.stringify(everyDaHuType)); let yjgs = 0;//赢家个数 for (let i = 0; i < wins.length; ++i) { if (winner.chs.indexOf(i) != -1) yjgs++; } // 自摸 let isMoHu = winner.lead == -1; // console.warn("计算是否自摸111 this.gangAfterData.chairId "+this.gangAfterData.chairId+" yjgs "+yjgs+" lead "+winner.lead); if(this.gangAfterData.chairId != -1){ if(yjgs > 1){ isMoHu = false; winner.lead = this.gangAfterData.chairId; } else if(yjgs == 1){ if(winner.chs[0] == this.gangAfterData.chairId){ isMoHu = true; winner.lead = -1; } else{ isMoHu = false; winner.lead = this.gangAfterData.chairId; } } else if(yjgs == 0){ isMoHu = false; winner.lead = -1; } } // console.warn("计算是否自摸222 this.gangAfterData.chairId "+this.gangAfterData.chairId+" yjgs "+yjgs+" lead "+winner.lead); data.lead = String(winner.lead) let znzId = -1;//抓鸟者id if(yjgs == 1) znzId = winner.chs[0]; // else if(yjgs > 1) znzId = this.currentId; //1022修复杠后两张牌一炮多响,2张鸟牌为5,9(开杠者中两鸟)情况下中鸟分计算错误的bug把上面那句else换成下面else else if(yjgs > 1){ if(this.gangAfterData.chairId != -1){ znzId = this.gangAfterData.chairId; } else{ znzId = this.currentId; } } let everyZNGS = this.logic.getBJGWJZBGS(znzId,data.jiangmaList,data.startNum1,data.startNum2,winner.lead,winner.chs); let znfb = [0,1,2];//分别表示中0个1个2个鸟在中鸟相加方式时中鸟额外输赢的分数倍数 if(this.ZNJSType == 2) znfb = [0,1,3];//分别表示中0个1个2个鸟在中鸟相乘方式时中鸟额外输赢的分数倍数 // console.error("这局是否自摸??? "+isMoHu+" lead "+winner.lead); // 计算牌型 for (let i = 0; i < wins.length; ++i) { wins[i].huType = ""; if (winner.chs.indexOf(i) == -1) continue; let typeList = []; if(everyIsHLZ[i]){ for (let x = 0; x < everyDaHuType[i][0].length; ++x) { typeList[x] = 0; if(everyDaHuType[i][0][x] == 1) typeList[x] ++; } for (let x = 0; x < everyDaHuType[i][1].length; ++x) { if(everyDaHuType[i][1][x] == 1) typeList[x] ++; } } else{ // console.warn("计算牌型111 i "+i+" everyDAHType[i] "+this.logic.everyDAHType[i]); for (let x = 0; x < this.logic.everyDAHType[i].length; ++x) { typeList[x] = 0; if(this.logic.everyDAHType[i][x] == 1) typeList[x] ++; } } // console.warn("计算牌型222 i "+i+" typeList "+typeList); for (let x = 0; x < typeList.length; ++x) { let gs = typeList[x]; if(gs == 1){ if(x == 9){ //前端展示大胡牌型的时候用到了大胡牌型的名字,如果“杠开”改为“杠上开花”也要修改前端的大胡展示判断 if(isMoHu) wins[i].huType += "杠开" + ","; else wins[i].huType += "杠炮" + ","; } else{ wins[i].huType += this.logic.dahuTypeTL[x][0] + ","; } } else if(gs > 1){ if(x == 9){ if(isMoHu) wins[i].huType += ("杠开" + ","); else wins[i].huType += ("杠炮" + ","); } else{ wins[i].huType += ("" + gs+this.logic.dahuTypeTL[x][0] + ","); } } } } /////封顶类型1:不封顶;2:封顶56分;3:封顶112分; let max = 1000000; if(this.fengDingType == 1) max = 1000000; else if(this.fengDingType == 2) max = 56; else if(this.fengDingType == 3) max = 112; // 计算输赢 for (let i = 0; i < wins.length; ++i) { // 胡牌者 if (winner.chs.indexOf(i) != -1) { // console.warn("结算承包数据",this.logic.chengBaoTL,isMoHu,cbqk); if(this.logic.isLaGang){ //抢杠胡:只输自己一家 let lead = winner.lead; let sy = this.logic.getDaHuFen(i) * this.cell; wins.forEach((w, c) => { if (c == lead) { wins[lead].cardfen -= sy; wins[i].cardfen += sy; if(sy > max) sy = max; wins[lead].win -= sy; wins[i].win += sy; } }); ////下面这段是计算奖码的分数 wins.forEach((w, c) => { if (c == lead) { if(c == lead){//////点炮玩家 let jiangmaFen = sy*(znfb[everyZNGS[i]+everyZNGS[lead]]); wins[lead].jiangma -= jiangmaFen; wins[i].jiangma += jiangmaFen; if(sy >= max) jiangmaFen = 0; else if((jiangmaFen + sy) > max) jiangmaFen = max - sy wins[lead].win -= jiangmaFen; wins[i].win += jiangmaFen; } } }); } else{ //不是抢杠胡 let sy = 0; if(everyIsHLZ[i]){ let sy1 = this.logic.getDaHuFen2(i,everyDaHuType[i][0]) * this.cell; let sy2 = this.logic.getDaHuFen2(i,everyDaHuType[i][1]) * this.cell; sy = sy1 + sy2 // console.warn("不是抢杠胡算分 可胡两张牌 i "+i+" sy1 "+sy1+" sy2 "+sy2); } else{ sy = this.logic.getDaHuFen(i) * this.cell; // console.warn("不是抢杠胡算分 可胡1张牌 i "+i+" sy "+sy+" everyDAHType[i] "+this.logic.everyDAHType[i]); } // console.warn("不是抢杠胡算分 i "+i+" 是否胡两张 "+everyIsHLZ[i]+" sy "+sy+" 自摸 "+isMoHu); if (isMoHu) { //自摸每家输2分 wins.forEach((w, c) => { if (c != i) { w.cardfen -= sy; wins[i].cardfen += sy; if(sy > max) sy = max; w.win -= sy; wins[i].win += sy; } }); ////下面这段是计算抓鸟的分数 wins.forEach((w, c) => { if (c != i) { // console.warn("不是抢杠胡算分 i "+i+" c "+c + " ") let jiangmaFen = sy*znfb[everyZNGS[i]+everyZNGS[c]]; w.jiangma -= jiangmaFen; wins[i].jiangma += jiangmaFen; if(sy >= max) jiangmaFen = 0; else if((jiangmaFen + sy) > max) jiangmaFen = max - sy w.win -= jiangmaFen; wins[i].win += jiangmaFen; } }); } else { //点炮者:给赢家输2分,其他人不输分 let lead = winner.lead; if(this.gangAfterData.chairId != -1) lead = this.gangAfterData.chairId; // 点炮出钱 wins.forEach((w, c) => { if (c != i) { if(c == lead){//////点炮玩家 w.cardfen -= sy; wins[i].cardfen += sy; if(sy > max) sy = max; w.win -= sy; wins[i].win += sy; } } }); ////下面这段是计算奖码的分数 wins.forEach((w, c) => { if (c != i) { if(c == lead){//////点炮玩家 let jiangmaFen = sy*(znfb[everyZNGS[i]+everyZNGS[lead]]); wins[lead].jiangma -= jiangmaFen; wins[i].jiangma += jiangmaFen; if(sy >= max) jiangmaFen = 0; else if((jiangmaFen + sy) > max) jiangmaFen = max - sy wins[lead].win -= jiangmaFen; wins[i].win += jiangmaFen; } } }); } } wins[i].lucky = 1; } // let str2 = "cstable 222结算函数---id:"+this.id +"结算模式"+mode // logger.info(str2);////cssj // if(!(mode != MODE.NORMAL && this.isHZHG)) { // // 杠牌 流局了而且勾选荒庄荒杠 的话则不计算杠分 // let gangMul = 0; // for (let huCard of this.huCards[i]) { // if (huCard.style == Logic.STYLE.ZMGANG) { // gangMul += 1; // wins[i].penggang += 1; // } else if (huCard.style == Logic.STYLE.ANGANG) { // gangMul += 2; // wins[i].dark += 1; // } else if (huCard.style == Logic.STYLE.GANG){ // //明杠谁点的杠谁付3分 // wins[i].trans += 1; // wins[huCard.origin].win -= 3 * this.cell; // wins[i].win += 3 * this.cell; // wins[huCard.origin].gangfen -= 3 * this.cell; // wins[i].gangfen += 3 * this.cell; // } // } // if (gangMul > 0) { // wins.forEach((w, c) => { // if (c != i) { // w.win -= gangMul * this.cell; // wins[i].win += gangMul * this.cell; // w.gangfen -= gangMul * this.cell; // wins[i].gangfen += gangMul * this.cell; // } // });/////TL++杠牌有赢 // } // } wins.forEach((w, c) => { // console.warn("?????/ "+JSON.stringify(w)); if (c != i) { let qshFen = this.logic.getQSHFen(i) // console.warn("?????----- "+qshFen); // w.win -= qshFen * this.cell; // wins[i].win += qshFen * this.cell; w.gangfen -= qshFen * this.cell; wins[i].gangfen += qshFen * this.cell; } });/////TL++杠牌有赢 // 手牌 let cards = { card: 0, groups: [], hands: [] }; if (wins[i].lucky) { cards.card = this.huRes[i].card; } for (let huCard of this.huCards[i]) { cards.groups.push({ style: huCard.style, card: huCard.cards[0] }); } let handCard = this.handCards[i] || []; let count = this.mcount - this.huCards[i].length * 3; cards.hands = handCard.slice(0, count); if(everyIsHLZ[i]){ cards.card = this.gangAfterData.cards.card1; cards.card2 = this.gangAfterData.cards.card2; } wins[i].cards = cards; } // let str3 = "cstable 333结算函数---id:"+this.id +",结算模式"+mode // logger.info(str3);////cssj //////TL++ let shiJiKouFen = []; if(this.playerAllCount == 2) shiJiKouFen = [wins[0].win,wins[1].win]; else if(this.playerAllCount == 3) shiJiKouFen = [wins[0].win,wins[1].win,wins[2].win]; else if(this.playerAllCount == 4) shiJiKouFen = [wins[0].win,wins[1].win,wins[2].win,wins[3].win]; if(this.gameKindTL == 2){ /////冲刺最多输50 for (let i = 0; i < this.ccount; ++i) { if(i == winner.chs[0]) continue; let user = this.users[i]; if (user){ let oldScore = this.score.getScore(user.id); let newScore = oldScore + shiJiKouFen[i]; if(newScore <= 0) wins[i].isPoChan = 1;/////玩家破产了 if(newScore < 0){/////输家破产了 let ableShu = 0 - newScore; shiJiKouFen[winner.chs[0]] += newScore;/////赢家没赢够 shiJiKouFen[i] = shiJiKouFen[i] - newScore; } } } } // console.warn("实际扣分XXX "+JSON.stringify(shiJiKouFen)); for (let i = 0; i < this.ccount; ++i) { wins[i].shiJiKouFen = shiJiKouFen[i]; } //console.warn("实际扣分XXX",shiJiKouFen,wins[0].win,wins[1].win,wins[2].win,wins[3].win) // 胜负情况 data.wins = wins; let bjsy = [];//本局每个人的输赢 for (let i = 0; i < this.ccount; ++i) { bjsy[i] = wins[i].win; } this.sszjDataList[this.sszjDataList.length] = bjsy; this.over += 1;// 局数+1 //ts++ let sszjScore = [];//ts++实时本局成绩 let sszjAllScore = [];//ts++实时总成绩 // 记录分数 for (let i = 0; i < this.ccount; ++i) { let user = this.users[i]; if (user) { sszjScore[i] = shiJiKouFen[i]; this.score.writeScore(user.id,shiJiKouFen[i], 1);//设置分数 sszjAllScore[i] = this.score.getScore(user.id); if(this.gameKindTL == 2) sszjAllScore[i] -=50; if(this.over == 1) { this.score.writeCost(user.id,this.cost, 0); //ts++设置消耗 } } } let endmode=ENDMODE.PLAYING; if(this.isGameOver()) { this.isGameOk=true; endmode=ENDMODE.NORMALEND;//局数完成--正常结束 } data.isover = this.isGameOk; data.nowTime = Date.now(); this.setPaijuHuiFangData(M.CONCLUDE,data);/////TL++ 牌局回放 push结算数据 /////TL++,用于记录玩家牌局回放的json文件名 this.pjhffileName[this.pjhffileName.length] = this.PJHF.getjsonFileName(this.over,this.recordid,this.ctime); // let str4 = "cstable 444结算函数---id:%s"+this.id +"结算模式"+mode // logger.info(str4);////cssj //ts++胡的人 let hu=-1; if (winner.chs.length >0 && winner.chs[0] >= 0 && winner.chs[0] <= 3) { hu=winner.chs[0]; } //ts++实时战绩 //this.sszjs.push({_id: String(this.over),c0Score:bjsy[0],c1Score:bjsy[1], c2Score:bjsy[2], c3Score:bjsy[3],banker:this.chBanker,hu:hu,pao:winner.lead, fName:jsonFileName}); this.sszjs.push({_id: String(this.over),sszjScore:sszjScore,sszjAllScore:sszjAllScore,banker:this.chBanker,hu:hu,pao:winner.lead}); /////固定庄家,不固定的话解除下面这一段的注释 // 切换庄家 if(yjgs == 0){ //没有赢家,流局了,最后一个摸牌的人坐庄 this.chBanker = this.logic.lastMoPaiChairID; } else if(yjgs == 1){ //只有一个人赢了,谁赢谁做庄 this.chBanker = winner.chs[0]; } else if(yjgs > 1) { //一炮多响,放炮的人坐庄 this.chBanker = winner.lead } /////TL++,10月9号,为了解决冲刺时前端的玩家分数偶尔会显示负数的bug data.playNowScore = []; for (let i = 0; i < this.ccount; ++i) { let user = this.users[i]; if (user) { data.playNowScore[i] = this.score.getScore(user.id); } } // 重置本局 this.resetRound(); // 结算通知 yield this.pushMsgAsync(-1, 'csjiang_event', { type: M.CONCLUDE, data: data }); this.PJHF.writePJHFJson({"pjhfDataList":this.PaijuHuiFang},this.over,this.id) this.logic.isZHYZ = false; /////TL++,是否最后一张 // yield this.pushMsgAsync(-1, 'csjiang_event', { type: 100, data: {"pjhfDataList":this.PaijuHuiFang}});//////最终发送给前端的牌局回放 // let str6 = "cstable end 结算函数-id:"+this.id +"结算模式"+mode // logger.info(str6);////cssj yield this.endResultAsync(endmode); }); // 发送聊天 proto.sendMsgAsync = cor(function* (chairId, msg) { // console.error("sscc发送聊天+++++++++++++++++++++++++++++++++",chairId,msg) yield this.pushMsgAsync(-1, 'csjiang_event', { type: M.CHAT, data: { chairId: String(chairId), msg: msg } }); return { code: C.OK }; }); // 收费聊天 礼物收费 proto.vsendMsgAsync = cor(function* (schairId, dchairId, msg) { if (schairId == dchairId || !this.users[dchairId]) { return { code: C.FAILD, msg: C.GAME_PARAM_ERROR }; } let user = this.users[schairId]; if (!user) { return { code: C.FAILD, msg: C.TABLE_NOT_USER }; } let lwcost = this.LWKF[msg.type];//////TL++礼物扣费 if(lwcost > 0){ var player = yield this.app.models.Player.findByIdAsync(user.id, 'diamond'); if(player) { if (((player.diamond) || 0) < lwcost) { return { code: C.FAILD, msg: C.GAME_DIAMOND_LOW }; } let dSource=player.diamond; let dNow=player.diamond-lwcost; player.diamond -= lwcost; yield player.saveAsync(); // 钻石记录 var diamondrecord = new this.app.models.DiamondRecord({ _id: uuid.v1(), playerId: user.id, dType: 5,//礼物 dSource: dSource, dSwap: -lwcost, dNow: dNow, tableId: this.recordid }); yield diamondrecord.saveAsync(); //ts++设置消耗 20230804取消了礼物扣钻的奖励 // this.score.writeCost(user.id,0, lwcost); } } yield this.pushMsgAsync(-1, 'csjiang_event', { type: M.FEE_CHAT, data: { cost: String(lwcost),schairId: String(schairId), dchairId: String(dchairId), msg: msg } }); return { code: C.OK }; }); //ts++写分 endtype = { 正常: 0,局数完成: 1, 房主解散: 2, 申请解散: 3 ,超时解散: 4 }; proto.writeResultAsync = cor(function* (endmode) { logger.warn("牌局写入-------------- " + this.id ); // console.warn("ts++---------牌局写入writeResultAsync",this.id); let gameCost=0;//游戏消耗 let giftCost = 0;////道具消耗 this.etime = Date.now(); let users = []; let localUsers = []; var scorers = this.score.getUsers(); if (scorers.length > 0) { var scorersSort = _.sortBy(scorers, (i) => i.chairId); for (let scorer of scorersSort) { gameCost+=this.cost; giftCost+=scorer.giftCost; let userscore=scorer.score; if(this.gameKindTL == 2) userscore -= 50; users.push({_id: scorer.playerId,chairId:scorer.chairId,userId: scorer.userId, name: scorer.name, sex: scorer.sex, headurl: scorer.headurl,over: scorer.over, score: userscore}); //, gameCost: scorer.gameCost,giftCost: scorer.giftCost,diamond: scorer.diamond localUsers.push({_id: scorer.playerId,userId: scorer.userId, name: scorer.name, gameCost: scorer.gameCost,giftCost: scorer.giftCost,}); } } // if(this.isGameOk)////以前是解散的不算返利 if(this.over > 0)////改成只要玩家扣钻了就有返利 { // this.agentRebate=gameCost;//parseInt(gameCost*0.5); this.agentRebate=gameCost+giftCost;////礼物也算消耗进行返利 // console.warn("代理返利+++++",this.agentRebate); } else { this.agentRebate=0; } //console.warn("实时战绩",this.sszjs);//ts++ this.PJHF.getTSjsonFileName(100,this.recordid,this.ctime);/////TL++,用于记录玩家牌局回放的json文件名 // console.error("000HHHHHHHHHHHHHHHHHHHHHH",this.pjhffileName.length,this.pjhffileName); let datats = { _id: this.recordid,//记录 gameId: this.gameId, tableNo: this.id, ownerId: this.ownerId, agentId: this.agentId, type: this.type, kind: this.gameKindTL,//玩法 2冲刺 other: this.other,//////TL++2人3人的游戏规则 playerCount: this.playerAllCount,//游戏人数 round: this.round,// over: this.over,//游戏局数 ctime: this.ctime,//创建时间 stime: this.stime,//开始时间 time: this.etime,//结束时间 endMode: endmode,//结束类型 gameCost: gameCost,//游戏消耗 giftCost: giftCost,//礼物消耗 agentRebate: parseInt(this.agentRebate),//代理返利 sszjFile: this.logic.deepCloneTL(this.pjhffileName), sszj: this.logic.deepCloneTL(this.sszjs), users: users } this.PJHF.writeTSJson(datats,100,this.id);////在开始第一局的时候将桌子信息写入本地的json文件 var fhmjtable = new this.app.models.FHMJTables({ _id: this.recordid,//记录 gameId: this.gameId, tableNo: this.id, ownerId: this.ownerId, agentId: this.agentId, type: this.type, kind: this.gameKindTL,//玩法 2冲刺 other: this.other,//////TL++2人3人的游戏规则 playerCount: this.playerAllCount,//游戏人数 round: this.round,// over: this.over,//游戏局数 ctime: this.ctime,//创建时间 stime: this.stime,//开始时间 time: this.etime,//结束时间 endMode: endmode,//结束类型 gameCost: gameCost,//游戏消耗 giftCost: giftCost,//礼物消耗 agentRebate: parseInt(this.agentRebate),//代理返利 sszjFile: this.pjhffileName, sszj: this.sszjs, users: users }); // console.warn("fhmjtable new",fhmjtable); yield fhmjtable.saveAsync(); //下面是记录返利相关的 if(this.agentId && this.agentRebate>0){ yield this.lsetReabte.writeReabteInfo(this.agentId,this.etime,this.agentRebate,gameCost,giftCost,this.recordid,localUsers,this.gameId); // yield this.lsetReabte.writePlayerCountInfo(this.agentId,this.etime,users,this.cost,this.isGameOk,this.gameId); } //下面是记录邀请新人按比例送钻这个活动的数据 if(!this.lconfigCommon) { // console.warn("邀请新人送钻石活动 this.lconfigCommon 不存在 "+this.etime); this.lconfigCommon = new configCommon(this.app); } yield this.lconfigCommon.yxActivityAsync(scorers,this.etime); // logger.info("战绩写入fhmjtable.saveAsync()--------------",this.id); }); // 结束信息 var endtype = { 局数完成: 1, 主动解散: 2, 断线解散: 3 ,超时解散: 4 }; proto.endResultAsync = cor(function* (endmode) { // console.warn("ts++---------记录信息",this.id); let str6 = "cstable 结束信息--id: "+this.id +" ,结算模式 "+endmode; logger.warn(str6);////cssj if(endmode>ENDMODE.PLAYING)//ts++关闭 { let nowTime = Date.now(); if(this.state0) { var scorers = this.score.getUsers(); if (scorers.length > 0) { let data = { _id: this.recordid, gameId: this.gameId, tableNo: this.id, ownerId: this.ownerId, type:String(this.type), kind: String(this.gameKindTL), over: String(this.over), round: String(this.round), time: String(nowTime), ctime: String(this.ctime), keep: String(nowTime - this.stime), other: this.other, playerCount:this.playerAllCount, agentId: this.agentId }; let collects = []; for (let scorer of scorers) { let userscore=scorer.score; if(this.gameKindTL == 2) userscore -= 50;//TL++,因为总的结算界面的每个玩家的分数范围为-200 ~ 600 collects.push({ chairId:scorer.chairId,name: scorer.name, sex: scorer.sex, headurl: scorer.headurl, score: userscore }); } data.users = _.sortBy(collects, (i) => -i.score); //data.sszjFile=this.pjhffileName; data.sszj=this.sszjs; yield this.pushMsgAsync(-1, 'csjiang_event', { type: M.TOTAL_CONCLUDE, data: data });////汇总结算 } //console.warn("ts++---------牌局写入"); yield this.writeResultAsync(endmode); } //console.warn("ts---------牌局结束"); for (let user of this.users) { if (user) { if (user.isOffline()) { user.state = User.STATE.FREE; user.state2 = User.STATE.FREE; this.leaveUsers.push(user.id); ///yield this.game.leaveTableAsync(user.id); } else { user.state = User.STATE.FREE; user.state2 = User.STATE.FREE; } } } } if(endmode==ENDMODE.SYSTEMEND) { yield this.pushMsgAsync(-1, 'csjiang_event', { type: M.TABLE_JIESAN }); } if(this.leaveUsers.length>0) { this.app.timer.setTimeout(() => this.leaveUserTimeAsync(), 100); } // var gametable = yield this.app.models.GameTable.findByIdAsync(this.recordid, '_id tableNo agentId endMode'); // if(gametable){ // gametable.endMode = 1; // yield gametable.saveAsync(); // } this.game.deleteTable(this.id);//ts++删除房间 // let str5 = "cstable 结束信息22 关闭-id:"+this.id +"结算模式"+endmode; // logger.info(str5);////cssj } else//普通结束 { // let str5 = "cstable 结束信息 普通结束---id:"+this.id +"结算模式"+endmode // logger.info(str5);////cssj this.state = STATE.FREE2; for (let user of this.users) { if (user) user.state2 = User.STATE.FREE; } } let str7 = "cstable end 结束信息---id:%s "+this.id +" 结算模式 "+endmode; logger.warn(str7);////cssj }); //ts++离开用户退出定时器 proto.leaveUserTimeAsync = cor(function* () { // console.warn("离开用户退出定时器,离开用户数==%d",this.leaveUsers.length);////cssj if(this.leaveUsers.length>0) { let userid = this.leaveUsers[0]; this.leaveUsers.splice(0, 1); let str7 = "cstable end 离开用户退出定时器---id:%s "+this.id +" userid "+userid; logger.warn(str7);////cssj yield this.game.leaveTableAsync(userid); } if(this.leaveUsers.length>0) { this.app.timer.setTimeout(() => this.leaveUserTimeAsync(), 100); } }); // TL++,得到玩家位置 proto.sendLocationAsync = cor(function* (user,msg) { /////设置玩家的经纬度 user.longitude = msg.longitude; // 经度,浮点数,范围为180 ~ -180。 user.latitude = msg.latitude; // 纬度,浮点数,范围为90 ~ -90 let tempData = { userId: user.userId, account: user.account, longitude: msg.longitude, latitude: msg.latitude } //////向其他玩家广播该玩家位置 yield this.pushMsgAsync(-1, 'csjiang_event', { type: M.COAST_PLAYERLOCATION, data: tempData }); return { code: C.OK, data: tempData }; }); // 玩家信息 proto.roleInfoAsync = cor(function* (chairId) { // console.log("玩家信息玩家信息玩家信息"); var user = this.users[chairId]; if (!user) { return { code: C.FAILD, msg: C.GAME_PARAM_ERROR }; } var data = { userId: '0', ttCount: '0', winCount: '0', noCount: '0', runCount: '0' }; data.userId =user.userId; return { code: C.OK, data: data }; }); //ts++请求结束定时器 proto.overTimeAsync = cor(function* (endmode) { yield this.pushMsgAsync(-1, 'csjiang_event', { type: M.TABLE_JIESAN }); let str6 = "cstable 请求结束定时器---id: "+this.id +" ,endmode: "+endmode logger.warn(str6);////cssj yield this.endResultAsync(endmode);//ts++ 房主解散 写分 }); // 请求结束 proto.overTableAsync = cor(function* (user) { // console.warn("ts+++++请求结束",user.chairId); let str3 = "cstable 请求结束.......id: "+ this.id + " user.chairId: " + user.chairId + " user.name: " + user.name ; logger.warn(str3);////cssj if(this.state == STATE.END) { this.leaveAsync(user); return { code: C.OK, data:{jieSanType: 2}};//离开房间 } if(this.reqJieSan.indexOf(2) != -1) return;/////有发起人的时候 // console.warn("2222请求结束请求结束请求结束",this.reqJieSan); //解散桌子数据,前面为chirid后面为情况-1:未操作 0:拒绝 1:同意 2为解散发起 //jieSanType =1:游戏开始前房主申请解散 =2:游戏开始前非房主玩家退出房间 =3:游戏过程中玩家申请解散 =4游戏过程中是房主但没参与游戏退出房间 =5其他 if(this.gameNeverStart) {//游戏是否从未开始过,用于解散房间判断 if(user.userId == this.ownerUid){ yield this.pushMsgAsync(-1, 'csjiang_event', { type: M.TABLE_JIESAN }); // let str5 = "cstable 房主解散-id:"+this.id+ ",uid"+user.userId; // logger.info(str5);////cssj yield this.endResultAsync(ENDMODE.OWNEREND);//ts++ 房主解散 写分 return { code: C.OK, data:{jieSanType: 1}}; } else{ this.leaveAsync(user); return { code: C.OK, data:{jieSanType: 2}};//离开房间 } } else { let chairId=user.chairId; if(chairId >= 0 && chairId < 4 ) { if(this.overFlag==0)//发起 { this.overFlag = 1; this.reqJieSan[0]=-1; this.reqJieSan[1]=-1; this.reqJieSan[2]=-1; this.reqJieSan[3]=-1; this.reqJieSan[chairId]=2; let jsdata = [];//ts++实时本局成绩 jsdata[0] = this.reqJieSan[0]; jsdata[1] = this.reqJieSan[1]; jsdata[2] = this.reqJieSan[2]; jsdata[3] = this.reqJieSan[3]; this.JSFJTime = 60;//////解散倒计时60秒 this.SQJSTime = Date.now() + this.JSFJTime*1000; if (!this.overTimer) this.overTimer = this.app.timer.setTimeout(() => this.overTimeAsync(ENDMODE.REGEND),this.JSFJTime*1000);//解散倒计时60秒 yield this.pushMsgAsync(-1, 'csjiang_event', { type: M.REQUEST_END, data: { chairId: String(chairId),time: this.JSFJTime,jsdata:jsdata}}); return { code: C.OK, data:{jieSanType: 3}}; } else//同意 { return this.agreeOverAsync(chairId); } } else { return { code: C.FAILD, msg: C.TABLE_ALREADY_SQJS }; } } return { code: C.OK, data:{jieSanType: 5}}; }); // 拒绝结束 proto.refuseOverAsync = cor(function* (user) { let str3 = "cstable 拒绝结束.......id: "+ this.id + " user.chairId: " + user.chairId + " user.name: " + user.name ; logger.warn(str3);////cssj if(this.state == STATE.END) { this.leaveAsync(user); return { code: C.OK, data:{jieSanType: 2}};//离开房间 } if(this.overFlag == 0) //ts++已经拒绝了 { return { code: C.OK }; } this.overFlag = 0; let chairId=user.chairId; // console.error("ts++----------拒绝结束",chairId); this.reqJieSan[chairId]=0;//解散桌子数据,前面为chirid后面为情况-1:未操作 0:拒绝 1:同意 2为解散发起 let jsdata = [];//ts++实时本局成绩 jsdata[0] = this.reqJieSan[0]; jsdata[1] = this.reqJieSan[1]; jsdata[2] = this.reqJieSan[2]; jsdata[3] = this.reqJieSan[3]; if (this.overTimer) { clearTimeout(this.overTimer); this.overTimer = null; } yield this.pushMsgAsync(-1, 'csjiang_event', { type: M.REFUSE_END, data: { chairId: String(chairId),time: 0,jsdata:jsdata} }); //this.reqJieSan = [[-1,-1],[-1,-1],[-1,-1],[-1,-1]];/////解散桌子数据,前面为chirid后面为情况-1:未操作 0:拒绝 1:同意 2为解散发起 this.reqJieSan[0]=-1; this.reqJieSan[1]=-1; this.reqJieSan[2]=-1; this.reqJieSan[3]=-1; return { code: C.OK }; }); // 同意结束 proto.agreeOverAsync = cor(function* (user) { let str3 = "cstable 同意结束.......id: "+ this.id + " user.chairId: " + user.chairId + " user.name: " + user.name ; logger.warn(str3);////cssj if(this.state == STATE.END) { this.leaveAsync(user); return { code: C.OK, data:{jieSanType: 2}};//离开房间 } if(this.overFlag == 0) //ts++已经拒绝了 { return { code: C.OK }; } let chairId=user.chairId; // console.error("ts++----------同意结束",chairId); this.reqJieSan[chairId] = 1;/////解散桌子数据,前面为chirid后面为情况-1:未操作 0:拒绝 1:同意 2为解散发起 let jsdata = [];//ts++实时本局成绩 jsdata[0] = this.reqJieSan[0]; jsdata[1] = this.reqJieSan[1]; jsdata[2] = this.reqJieSan[2]; jsdata[3] = this.reqJieSan[3]; this.JSFJTime = Math.floor((this.SQJSTime - Date.now())/1000); if(this.JSFJTime >= 25)this.JSFJTime -= 20;//////解散房间倒计时60秒 else this.JSFJTime = 10; this.SQJSTime = Date.now() + this.JSFJTime*1000; yield this.pushMsgAsync(-1, 'csjiang_event', { type: M.AGREE_END, data: { chairId: String(chairId),time: this.JSFJTime,jsdata:jsdata} }); let jsFlag = 0; for (let i = 0; i < 4; ++i) { if(this.reqJieSan[i] >=1 ) { jsFlag+=1; } } if(jsFlag>=this.ccount || this.JSFJTime<=0) { if(this.backStartTimer) { clearTimeout(this.backStartTimer); this.backStartTimer = null; } yield this.pushMsgAsync(-1, 'csjiang_event', { type: M.TABLE_JIESAN }); // let str4 = "cstable 全部同意结束-id:%s"+this.id + ",uid"+user.userId+",state"+ this.state; // logger.info(str4);////cssj yield this.endResultAsync(ENDMODE.REGEND);//ts++ 结束 } else { if (this.overTimer) { clearTimeout(this.overTimer); this.overTimer = null; } if (!this.overTimer) this.overTimer = this.app.timer.setTimeout(() => this.overTimeAsync(ENDMODE.REGEND),this.JSFJTime*1000);//解散倒计时60秒 } // let str3 = "cstable end 同意结束-id:"+this.id + ",uid"+user.userId+",state"+ this.state; // logger.info(str3);////cssj return { code: C.OK, data: { chairId: String(chairId),time: this.JSFJTime, jieSanType: 1 }}; }); //////TL++,设置记录游戏过程中的记录数据 proto.setPaijuHuiFangData = function (_operateKind,_data){ let data = this.logic.deepCloneTL(_data); data.operateKind = _operateKind; this.PaijuHuiFang[this.PaijuHuiFang.length] = data; }; // 得到玩家位置 proto.getLocationAsync = cor(function* () { let location = []; // 桌上玩家 for (let i = 0; i < this.users.length; ++i) { let user = this.users[i]; if (user) { location.push({ chairId: user.chairId, longitude: user.longitude, latitude: user.latitude, headurl: user.headurl, name: user.name }); } } // console.warn("ts+++++玩家位置",location); return { code: C.OK, data: location }; });