| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591 |
- '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').paodekuai || {};
- 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/VersionConfig').codeVer || {};
- // // console.warn("pdk的table中检查logic版本111 "+JSON.stringify(confCodeVer));
- // if(confCodeVer.pdkLogic){
- // delete require.cache[require.resolve('../config/VersionConfig')];
- // let confCodeVer2 = require('../config/VersionConfig').codeVer || {};
- // // console.warn("pdk的table中检查logic版本222 "+confCodeVer.pdkLogic +" "+ confCodeVer2.pdkLogic);
- // if(confCodeVer.pdkLogic && confCodeVer2.pdkLogic && confCodeVer.pdkLogic != confCodeVer2.pdkLogic){
- // delete require.cache[require.resolve('./logic')];
- // Logic = require('./logic');
- // // console.warn("pdk的table中的logic更新了 ")
- // }
- // }
- }
- // 构造方法
- var Table = function (cPlayerId,cUserId,cName,cHead,game, id, cell, round, type,gameKindTL,playerAllCount,upId,other,agentId,yxndlbTime,yxndlbTip) {
- let str3 = "table构造方法.......id: "+id + " type " + type+" game "+game.id;
- logger.warn(str3);////cssj
- checkVersion();
- this.app = game.app;
- this.gameId = 10008;
- 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;
- var num_cost = 50;
- num_cost =parseInt(COSTS[round]);
- this.other = other;//////TL++2人3人的游戏规则
- // console.warn("222创建房间的other",other,this.other," gameKindTL ",gameKindTL," type " ,type);
- this.isHTSFB = false;//是否红桃十翻倍
- if(this.other & 1){
- this.isHTSFB = true;
- }
- this.isZDBKC = false;//是否炸弹不可拆
- if(this.other & 2){
- this.isZDBKC = true;
- }
- this.isSiDaiEr = false;//是否可四带2
- if(this.other & 4){
- this.isSiDaiEr = true;
- }
- this.isSiDaiSan = false;//是否可四带3
- if(this.other & 32){
- this.isSiDaiSan = true;
- }
- this.cardCount = 15;//张数
- if(this.other & 8){//
- this.cardCount = 15;
- }
- else if(this.other & 16){//
- this.cardCount = 16;
- }
- this.isXSSYP = false;//是否显示剩余牌
- if(this.other & 64){
- this.isXSSYP = true;
- }
- this.isHaveJPQ = false;//是否有记牌器
- if(this.other & 128){
- this.isHaveJPQ = true;
- }
- // this.isYPBC = true;//是否有牌必出(能大过必须出牌大掉)
- // console.warn("是否红桃十翻倍 "+this.isHTSFB)
- // console.warn("是否炸弹不可拆 "+this.isZDBKC)
- // console.warn("是否可四带2 "+this.isSiDaiEr)
- // console.warn("是否可四带3 "+this.isSiDaiSan)
- // console.warn("张数 "+this.cardCount)
- // console.warn("是否显示剩余牌 "+this.isXSSYP)
- // this.isYPBC = true;//是否有牌必出(能大过必须出牌大掉)
- this.isYBQZDCP = true;//是否要不起自动出牌
- 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.users = Array(this.ccount);
- this.chBanker = 0;
- this.bankFlag = 0;
- this.isHTSSC = false;//是否是黑桃三首出
- this.tipInfo = {chairId:-1,tipCards:[]}//出牌提示
- this.lastOut = {chair:-1,type:-1,cards:[]};//上次有效的出牌(要不起出的[]不算有效出牌)
- this.blZDInfo = [[]];//本轮炸弹信息[[chair,card]]
- this.bloutCard = logic.fillDeep(Array(this.ccount),null);;////目前本轮每个玩家的出牌[]表示该玩家过牌,null表示本轮该玩家还未出牌
- this.outCards = logic.fillDeep(Array(this.ccount), []);
- // 标记
- this.outCard = [];//[]表示要不起
- this.outerId = -1;
- this.currentId = -1;
- this.zhaniaoChair = -1;//扎鸟(勾选了红桃十翻倍且拿到红桃十的玩家)玩家id
- this.nextCardCount = this.cardCount;//当前玩家的下家手牌个数,为了判断下家只剩一张牌时出单牌时必须出手牌里最大那张
- this.ksNewLunTimer = null;//开始新一轮定时器
- this.autoOutLastTimer = null;//自动出掉最后一手牌定时器
- this.autoOutTimer = null;//托管自动出牌定时器
- this.autoReadyTimer = null;//托管中自动准备定时器
- this.autoReadyTimer2 = null;//未托管自动准备定时器
- this.everyIsAutoOut = _.fill(Array(this.ccount), 0);
- // 胡牌者
- this.winner = { lead: -1, chs: [] };
- // 底分
- this.cell = cell;
- // 围观者
- this.lookers = [];
- //结束时的继线用户
- this.leaveUsers = [];
- this.leaveUsersBS = [];//比赛中自动准备的断线用户,在自动准备时添加在回到桌子时删除,用于最后一局结束之后让断线玩家退出房间
- //leaveUsersBS是上面leaveUsers这个字段在比赛情况下的补充,因为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.backStartTimer = null;//////重入之后系统会自动准备为了解决可能没牌的问题2秒之后才开始游戏
- this.PaijuHuiFang = [];////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.gameKindTL = gameKindTL || 1;//平搓还是冲刺 = 1代表平搓 = 2代表冲刺
- this.playerAllCount = playerAllCount || 4;//游戏人数 = 2表示2人局 = 3表示3人局 = 4表示4人局
- this.isNeverStart = true;//游戏是否从未开始
- this.sszjDataList = [];//设置实时战绩的数据
- this.isEveryZZ = false;//是否每一个人都做过庄
- this.chairArry = [0,1,2];//
- this.sszjs = [];//ts++实时战绩
- this.LWKF = [10,10,10,10,10];//////TL++礼物扣费
- this.isGameOk=false;//ts++牌局正常结束
- this.agentRebate=0;//ts++本局的返利
- this.yjxrzj = false;
- // delete require.cache[require.resolve('../../share/setReabte')];
- // setReabte = require('../../share/setReabte');
- this.lsetReabte = new setReabte(this.app);
- if(this.lsetReabte.getIsBS(this.agentId,this.ownerName,this.ownerUid)) this.cost = 0;//比赛免费
- };
- // 导出状态
- 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 = "table 局数完成 .......id: "+ this.id + " this.over " + this.over;
- logger.warn(str3);////cssj
- return (this.over >= this.round);
- };
- // 重置本局
- proto.resetRound = function () {
- _.fill(this.handCards, null);
- this.zhaniaoChair = -1;//扎鸟(勾选了红桃十翻倍且拿到红桃十的玩家)玩家id
- this.nextCardCount = this.cardCount;//当前玩家的下家手牌个数,为了判断下家只剩一张牌时出单牌时必须出手牌里最大那张
- if(this.ksNewLunTimer)
- {
- clearTimeout(this.ksNewLunTimer);
- this.ksNewLunTimer = null;
- }
- if(this.autoOutLastTimer)
- {
- clearTimeout(this.autoOutLastTimer);
- this.autoOutLastTimer = null;
- }
- if(this.autoOutTimer)
- {
- clearTimeout(this.autoOutTimer);
- this.autoOutTimer = null;
- }
- if(!this.lsetReabte.getIsBS(this.agentId,this.ownerName,this.ownerUid)) this.everyIsAutoOut = _.fill(Array(this.ccount), 0);
- this.winner.chs = [];
- this.winner.lead = -1;
- this.logic.fillDeep(this.outCards, []);
- this.isHTSSC = false;//是否是黑桃三首出
- this.tipInfo = {chairId:-1,tipCards:[]}//出牌提示
- this.lastOut = {chair:-1,type:-1,cards:[]};//上次有效的出牌(要不起出的[]不算有效出牌)
- this.blZDInfo = [[]];//本轮炸弹信息[[chair,card]]
- this.bloutCard = this.logic.fillDeep(Array(this.ccount),null);;////目前本轮每个玩家的出牌[]表示该玩家过牌,null表示本轮该玩家还未出牌
- this.outCard = [];
- this.outerId = -1;
- this.currentId = -1;
- };
- // 发送消息
- proto.pushMsgAsync = cor(function* (cidOrIds, route, msg) {
- // console.warn("444WWWWWWWTTTTTT",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: [],
- agentId: this.agentId,
- 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,
- bloutCard: this.bloutCard,////目前本轮每个玩家的出牌[]表示该玩家过牌,null表示本轮该玩家还未出牌
- currentId: this.currentId,
- yxndlbTime:this.yxndlbTime,
- yxndlbTip:this.yxndlbTip,
- reqJieSan:this.reqJieSan
- };
- // 正在游戏
- var isPlaying = this.isPlaying();
- if (isPlaying) {
- tableInfo.banker = this.chBanker;
- tableInfo.stime = Date.now() - this.stime;
- tableInfo.lastCount = this.logic.leaveCount();
- tableInfo.nextCardCount = this.nextCardCount;
- //////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) {
- 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 = "table回到桌子.......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;
- if (chairId != -1) {
- // 加入频道
- var connectorId = user.connectorId || '';
- if (connectorId) {
- let channelId = 'xct:' + this.id;
- yield this.app.controllers.push._joinAsync(channelId, user.id, connectorId);
- }
- // 恢复状态
-
- 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, 'paodekuai_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--
- user.state2 = User.STATE.READY;
- yield this.pushMsgAsync(-1, 'paodekuai_event', { type: M.STATE_CHANGE, data: { chairId: String(user.chairId), state: String(user.state2), state2: String(user.state2) } });
-
- if (this.isReady2() && !this.isGameOk)
- {
- if(!this.backStartTimer){
- if(this.autoReadyTimer2)
- {
- clearTimeout(this.autoReadyTimer2);
- this.autoReadyTimer2 = null;
- }
- this.backStartTimer = this.app.timer.setTimeout(() => this.backStartTimeAsync(), 2 * 1000);//延迟2秒开始游戏
- }
- }
- }
- // 取消计时
- if (this.isOnline() && this.endTimer) {
- clearTimeout(this.endTimer);
- this.endTimer = null;
- }
- }
- // 数据处理
- data.fee = this.score.isFeed(user.id) ? '0' : '1';
- data.table = this.getTableInfo();
-
- let isAutoOut = 0;
- if (chairId != -1) {
- isAutoOut = this.everyIsAutoOut[chairId];
- data.table.dczsList = this.logic.getDCZSList(chairId);
- data.table.jpqsysj = this.logic.everyJPQSYSJ[chairId];
- }
- data.table.isAutoOut = isAutoOut;
- let tipInfo = {chairId:-1,tipCards:[]}//出牌提示
- if(this.currentId > -1 && chairId == this.currentId) tipInfo = this.tipInfo;
- data.table.tipInfo = this.logic.deepCloneTL(tipInfo);
- // console.warn("this.leaveUsersBS 用户回到桌子 "+user.id + " " +JSON.stringify(this.leaveUsersBS));
- let bsdxxb = this.leaveUsersBS.indexOf(user.id);
- if(bsdxxb != -1) {
- this.leaveUsersBS.splice(bsdxxb, 1);//只要玩家能回到桌子之前的字段leaveUsers就能节奏处理这个用户了
- // console.warn("this.leaveUsersBS 删除元素 "+user.id + " " +JSON.stringify(this.leaveUsersBS));
- }
- return { code: C.OK, data: data };
- });
- //ts++重入后自动开始
- proto.backStartTimeAsync = cor(function* () {
- 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, 'paodekuai_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, 'paodekuai_event', { type: M.COST_FEE, data: costdata });
- }
- if (this.isHaveJPQ && this.state == STATE.FREE){
- let jpqsysj = 0;//记牌器剩余时间
- let jipaiqi = yield this.app.models.JiPaiQi.findByIdAsync(user.id, 'jpqdqsj');
- if (jipaiqi) {
- let currTime = Date.now();
- if(jipaiqi.jpqdqsj > 0 && jipaiqi.jpqdqsj >= currTime) jpqsysj = jipaiqi.jpqdqsj - currTime;
- }
- let index = -1;
- for (var i = 0; i < this.logic.uidsfydsq.length; i++) {
- if(user.userId == this.logic.uidsfydsq[i][0]){
- index = i;
- break;
- }
- }
- if(index == -1) this.logic.uidsfydsq.push([user.userId,jpqsysj]);
- else this.logic.uidsfydsq[index][1] = jpqsysj;
- }
- // if (this.isReady()) yield this.pushMsgAsync(this.ownerChairid, 'paodekuai_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, 'paodekuai_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, 'paodekuai_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, 'paodekuai_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 < 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, 'paodekuai_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) {
- 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, 'paodekuai_event', { type: M.CHAIR_DALUAN, data: { daluanData:daluanData } });
- }
- }
- for (let i = 0; i < this.users.length; ++i) {
- let user = this.users[i];
- if (user) {
- for (var j = 0; j < this.logic.uidsfydsq.length; j++) {
- if(user.userId == this.logic.uidsfydsq[j][0]){
- this.logic.everyJPQSYSJ[i] = this.logic.uidsfydsq[j][1];
- break
- }
- }
- }
- }
- // console.warn("444在首次游戏开始的时候随机打乱用户的座位",changeResult);
- // this.starTimer = this.app.timer.setTimeout(() => this.startGameAsync(), 500);
- yield this.startGameAsync()/////TL++,在首次游戏的时候随机打乱用户的座位
- });
- // 站起桌子
- proto.standAsync = cor(function* (user) {
- let str3 = "table 站起桌子.......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, 'paodekuai_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, 'paodekuai_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, 'paodekuai_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, 'paodekuai_event', { type: M.COST_FEE, data: costdata });
- }
- }
- else
- {
- // console.warn(" user.cost "+user.cost);
- 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,所以上面那段用不了了
- // console.warn("邀请新人送钻石活动 this.etime "+this.etime);
- 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 = "table 222 站起桌子之后---id:%s"+this.id + " uid"+user.userId+" "+ this.state;
- // logger.info(str4);////cssj
- }
- });
- // 玩家断线
- proto.offlineAsync = cor(function* (user) {
- let str3 = "table 玩家断线.......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, 'paodekuai_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("玩家断线-------定时器启动");
- // 计时结算
- let lxjssj = 600000;//断线解散时间
- if(this.lsetReabte.getIsBS(this.agentId,this.ownerName,this.ownerUid)) lxjssj = 1800000;//比赛的话有托管机制,害怕20分钟完成不了比赛所以延长时间
- if (!this.endTimer) this.endTimer = this.app.timer.setTimeout(() => this.overTimeAsync(ENDMODE.OFFLINEEND),lxjssj);/////断线3分钟自动结算
- // let str4 = "table 玩家断线---id:"+this.id + ",uid"+user.userId+" "+ this.state;
- // logger.info(str4);////cssj
- }
- });
- // 离开桌子
- proto.leaveAsync = cor(function* (user) {
- let str3 = "table 离开桌子.......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, 'paodekuai_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, 'paodekuai_event', { type: M.LEAVE, data: { account: user.account } });
- });
- // 玩家准备
- proto.readyGameAsync = cor(function* (user) {
- let str3 = "table 玩家准备.......id: "+ this.id + " user.chairId: " + user.chairId + " this.over: " + this.over + " user.name: " + user.name ;
- logger.warn(str3);////cssj
- // let str3 = "table 玩家准备---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, 'paodekuai_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, 'paodekuai_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 = "table 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 = "table 开始游戏---id:"+this.id +" ,state "+ this.state +" 当前局 "+ (this.over+1);
- if(this.autoReadyTimer2)
- {
- clearTimeout(this.autoReadyTimer2);
- this.autoReadyTimer2 = null;
- }
- let cd = {id:this.id, agentId:this.agentId}
- this.app.rpc.hall.hallRemote.delTable.toServer("hall-server-1", cd, () => { });
- 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;
- //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++,牌局回放 重置数据
- // 初始信息
- if (this.over <= 0) {///////本房间开始的第一局游戏
- this.stime = Date.now();
- this.chBanker = 0;
- 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++,游戏是否从未开始
- }
- this.gameNeverStart = false;/////TL++,游戏是否从未开始过,用于解散房间判断
-
- // 发手牌 把这句提前是为了洗牌之后能拿到百搭牌在游戏开始的时候给客户端发过去
- var handCards = this.logic.handCards(this.chBanker,this.PJHF,this.over,this.recordid,this.ctime);
- if (this.over <= 0) {///////本房间开始的第一局游戏
- this.chBanker = this.logic.getSCId(handCards);
- }
- this.currentId = this.chBanker;
- //console.warn("ccccccccccccccccccccc当局的currentId ",this.currentId);
- 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),
- stime: String(Date.now() - this.stime),
- 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, 'paodekuai_event', { type: M.START_GAME, data: sttGame });
- this.isHTSSC = (this.over <= 0 && handCards[this.currentId].cards.indexOf(103) != -1);//是否是黑桃三首出
- // console.warn("发牌通知 是否是黑桃三首出 "+this.isHTSSC+" currentId "+this.currentId);
- this.tipInfo.chairId = this.currentId;//出牌提示
- this.tipInfo.tipCards = this.logic.getOutTip(this.currentId,handCards[this.currentId].cards,this.lastOut,this.isHTSSC,this.nextCardCount == 1);
- ////// 发手牌原来在这里
- var lastCount = this.logic.leaveCount();/////TL++
- for (let i = 0; i < handCards.length; ++i) {
- this.handCards[i] = handCards[i].cards;/////TL++zsyl
- let tipInfo = {chairId:-1,tipCards:[]}//出牌提示
- if(i == this.currentId) tipInfo = this.tipInfo;
- let scards = {
- cards: handCards[i].cards,
- currentId: this.currentId,
- tipInfo: this.logic.deepCloneTL(tipInfo),
- lastCount: String(lastCount),
- dczsList: this.logic.getDCZSList(i),
- jpqsysj: this.logic.everyJPQSYSJ[i],
- isAutoOut:this.everyIsAutoOut[i]
- };
- if(this.isHTSFB && handCards[i].cards.indexOf(210) != -1) this.zhaniaoChair = i;
- // 发牌通知
- // console.error("sscc发牌通知 4条应该=================",i,handCards.lengt);
- yield this.pushMsgAsync(i, 'paodekuai_event', { type: M.SEND_CARD, data: scards });
- }
-
- let pjhfsplist = {
- shouPai:this.logic.deepCloneTL(this.handCards),
- currentId: this.currentId,
- // 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('paodekuai_event', { type: M.SEND_CARD, data: { currentId: this.currentId,cardCounts: cardCounts, lastCount: String(lastCount) } });
- let str3 = "table 222开始游戏---id:"+this.id +","+ this.state;
- logger.warn(str3);////cssj
- yield this.autoOutCard(this.currentId);
- return { code: C.OK };
- });
- // 出牌
- proto.outCardAsync = cor(function* (chairId, cards) {
- cards = this.logic.sort(cards)
- let str3 = "table 出牌---id:"+this.id + " ,uid "+chairId+" cards "+cards;
- logger.warn(str3);////cssj
- // if(this.autoOutTimer)
- // {
- // clearTimeout(this.autoOutTimer);
- // this.autoOutTimer = null;
- // }
- // console.warn("出牌出剖出牌",chairId,this.buhuaTimeout);///// 您正在补花,请稍后出牌。/////TL++,正在补花的时候不允许玩家出牌
- // 校验顺序
- if (this.currentId != chairId) {
- return { code: C.FAILD, msg: C.TABLE_TURN_ERROR };
- }
- let ccards = this.logic.deepCloneTL(cards);
- ccards = _.uniq(ccards);
- if(ccards.length != cards.length) return { code: C.FAILD, msg: C.TABLE_CARD_ERROR };//出的牌有重复
- // console.warn("出牌删除手牌之前 "+this.handCards[chairId]);
- if(this.isYBQZDCP){
- }
- if(cards.length == 1 && this.nextCardCount == 1){
- let maxDanList = this.logic.getMaxDanList(this.handCards[chairId]);
- if(maxDanList.indexOf(cards[0]) == -1) {
- // "下家只剩下1张了,如果打单牌请打出最大的单牌!"
- return { code: C.FAILD, msg: C.TYPE_IS_WRONG };
- }
- }
- // 得到出牌牌型
- let type = this.logic.getCardsType(cards,this.lastOut,this.handCards[chairId],this.isHTSSC,this.tipInfo.tipCards);
- // console.warn("得到出牌牌型 "+type + " "+this.logic.styleTL.ERROR+" cards "+cards);
- if(type == this.logic.styleTL.ERROR) return { code: C.FAILD, msg: C.TYPE_IS_WRONG };//牌型不存在
- else if(type == this.logic.styleTL.NULL) return { code: C.FAILD, msg: C.PLAYER_POKE_WRONG };//牌型合法但是大不过
- else if(type == -2) return { code: C.FAILD, msg: C.TABLE_CANOUTMUSTOUT };//自己有能大过上家出牌的牌不能不出牌(出[])
- else if(type == -3) return { code: C.FAILD, msg: C.TABLE_HTSSCMYHTS };//黑桃三首出所出的牌没有黑桃三
- else if(type == -4) return { code: C.FAILD, msg: C.TABLE_ZDBKCSCDPBNYZD };//炸弹不可拆时出的牌不能带炸弹
- // 删除手牌
- if (!this.logic.remove(this.handCards[chairId], cards)) {
- return { code: C.FAILD, msg: C.TABLE_CARD_ERROR };
- }
- //至此所出的牌合法的(要么要不起要么能大过)
- if(this.autoOutTimer)
- {
- clearTimeout(this.autoOutTimer);
- this.autoOutTimer = null;
- }
- this.logic.setDCZSList(cards);
- this.logic.chuPaiTL()////TL++,统计出牌个数,为了判断天胡和地胡
- // console.warn("出牌删除手牌之后 "+this.handCards[chairId]);
- this.outCard = cards;
- this.outerId = chairId;
- this.outCards[chairId].push(cards);
- this.bloutCard[chairId] = cards;
- let scyxcpChair = this.lastOut.chair;
- if(this.isHTSSC) this.isHTSSC = false;
- let isblEnd = false;//本轮是否结束
- let newcu = -10;//新一轮的当前玩家
- if(cards.length > 0){
- this.lastOut = {chair:chairId,type:type,cards:this.logic.deepCloneTL(cards)};//上次有效的出牌(要不起出的[]不算有效出牌)
- if(type == this.logic.styleTL.ZHADAN){
- this.blZDInfo[this.blZDInfo.length-1] = [chairId,this.logic.getValuepx(cards[0])];
- }
- }
- else{
- let byCount = 0;//要不起玩家个数
- let yCount = 0;//要的玩家个数
- for (let i = 0; i < this.bloutCard.length; ++i) {
- if(this.bloutCard[i] == null) break;
- if(this.bloutCard[i].length == 0) byCount++;
- else if(this.bloutCard[i].length > 0){
- yCount++;
- newcu = i;
- }
- }
- if(byCount == this.ccount - 1 && yCount == 1) isblEnd = true;
- else newcu = -10;
- }
- if(isblEnd){
- this.currentId = -1;
- this.lastOut = {chair:-1,type:-1,cards:[]};//上次有效的出牌(要不起出的[]不算有效出牌)
- if(this.blZDInfo[this.blZDInfo.length-1].length > 0){
- //已经有记录到有效的炸弹了
- this.blZDInfo[this.blZDInfo.length] = [];
- }
- }
- else{
- this.currentId = (chairId + 1) % this.ccount;
- this.bloutCard[this.currentId] = null;
- }
- if(this.handCards[chairId].length == 0){
- //有人出完了
- this.winner.chs[0] = chairId;
- isblEnd = true;
- newcu = chairId;
- this.currentId = -1;
- }
- let isMZYBQZDCP = false;//是否满足要不起自动出牌
- if(this.currentId > -1){
- let next = (this.currentId + 1) % this.ccount;
- this.nextCardCount = this.handCards[next].length;
- this.tipInfo.chairId = this.currentId;//出牌提示
- this.tipInfo.tipCards = this.logic.getOutTip(this.currentId,this.handCards[this.currentId],this.lastOut,this.isHTSSC,this.nextCardCount == 1);
- // console.warn("这里获取了出牌提示111 "+this.currentId);
- if(this.isYBQZDCP && this.tipInfo.tipCards.length == 0) isMZYBQZDCP = true;//是否要不起自动出牌
- }
- else{
- this.tipInfo = {chairId:-1,tipCards:[]};
- }
-
- for (let i = 0; i < this.ccount; ++i) {
- let ocard = { //这必须写for循环里面
- chairId: String(chairId),
- currentId: this.currentId,
- isblEnd: false,
- lastChair: scyxcpChair,
- nextCardCount: this.nextCardCount,
- type: String(type),
- outerLast: this.handCards[chairId].length,
- isAutoOut: this.everyIsAutoOut[chairId],
- dczsList: this.logic.getDCZSList(i),
- cards: cards
- };
- let tipInfo = {chairId:-1,tipCards:[]}//出牌提示
- if(i == this.currentId) {
- tipInfo = this.tipInfo;
- // console.warn("是这里发的消息嘛 " + JSON.stringify(tipInfo));
- }
- ocard.tipInfo = this.logic.deepCloneTL(tipInfo);
- yield this.pushMsgAsync(i, 'paodekuai_event', { type: M.OUT_CARD, data: ocard });
- if(i == this.ccount - 1){
- let cocard = this.logic.deepCloneTL(ocard);
- cocard.tipInfo = {chairId:-1,tipCards:[]}//出牌提示
- yield this.lookMsgAsync('paodekuai_event', { type: M.OUT_CARD, data: cocard });
- let pjhfsplist ={
- shouPai:this.logic.deepCloneTL(this.handCards),
- // lastCount:String(this.logic.leaveCount()),
- ocard:this.logic.deepCloneTL(cocard),
- outCards:this.logic.deepCloneTL(this.outCards),
- }
- this.setPaijuHuiFangData(M.OUT_CARD,pjhfsplist);/////TL++ 牌局回放 push出牌数据
- }
- }
-
- let str4 = "table end出牌---id:"+this.id + " ,uid "+chairId +" cards "+cards+" "+isMZYBQZDCP+" "+isblEnd +" "+ newcu;
- logger.warn(str4);////cssj
- // console.warn(" 能否进入下一轮 ",isMZYBQZDCP,isblEnd , newcu);
- if(isMZYBQZDCP || (isblEnd && newcu > -1)){
- // console.warn(" 进入下一轮111 ",isMZYBQZDCP,isblEnd , newcu);
- if(!this.ksNewLunTimer){
- this.ksNewLunTimer = this.app.timer.setTimeout(() =>
- {
- // console.warn(" 进入下一轮222 ",isMZYBQZDCP,isblEnd , newcu);
- let str44 = "table end出牌---进入下一轮222id:"+this.id + " ,uid "+chairId +" cards "+cards+" "+isMZYBQZDCP+" "+isblEnd +" "+ newcu;
- logger.warn(str44);////cssj
- if(this.ksNewLunTimer)
- {
- clearTimeout(this.ksNewLunTimer);
- this.ksNewLunTimer = null;
- }
- let isEnd = false;
- for (let i = 0; i < this.handCards.length; ++i) {
- if(this.handCards[i].length == 0){
- isEnd = true;
- break;
- }
- }
- if(isEnd){
- return this.dyjshs();//调用结束函数
- }
- else{
- if(isMZYBQZDCP){
- if(this.currentId > -1){
- let str5 = "table 要不起在这里自动出牌了---id:"+this.id + " ,uid "+this.currentId ;
- logger.warn(str5);////cssj
- // console.error("要不起在这里自动出牌了");
- this.outCardAsync(this.currentId,[])
- }
- else{
- console.error("要不起自动出牌这里错了");
- let str5 = "table 要不起自动出牌这里错了---id:"+this.id + " ,uid "+this.currentId ;
- logger.warn(str5);////cssj
- }
- return { code: C.OK };
- }
- this.ksNewLunOut(newcu)
- return { code: C.OK };
- }
- }
- , 1000);//各玩家均没有操作的情况下延迟2秒更新杠后两张牌的状态
- }
- }
- else{
- if(this.currentId > -1){
- // console.warn("在这里判断是否可以一把出完了 111 ")
- let outList = this.logic.getCanOutOverList(this.currentId,this.handCards[this.currentId],this.tipInfo,this.lastOut)
- if(outList.length > 0){
- // console.warn("在这里可以一把出完了111 "+JSON.stringify(outList));
- yield this.autoOutLastCard(this.currentId,outList);
- return { code: C.OK };
- }
- else{
- yield this.autoOutCard(this.currentId);
- }
- }
- }
- return { code: C.OK };
- });
- proto.autoOutLastCard = cor(function* (chair,cards) {
- if(!this.autoOutLastTimer){
- this.autoOutLastTimer = this.app.timer.setTimeout(() =>
- {
- // console.warn(" 进入下一轮222 ",isMZYBQZDCP,isblEnd , newcu);
- let str44 = "table 自动出掉最后一手 id:"+this.id + " ,uid "+chair +" cards "+cards;
- logger.warn(str44);////cssj
- if(this.autoOutLastTimer)
- {
- clearTimeout(this.autoOutLastTimer);
- this.autoOutLastTimer = null;
- }
- this.outCardAsync(chair,cards)
- }
- , 100);//最后一手牌可以出完的时候1秒后自动出掉
- }
- return { code: C.OK };
- });
- //调用结算函数,因为定时器里不能yield,所以改成这种方式
- proto.dyjshs = cor(function* () {
- yield this.concludeGameAsync(MODE.NORMAL);
- });
- proto.ksNewLunOut = cor(function* (newcu) {
- this.currentId = newcu;
- this.bloutCard = this.logic.fillDeep(Array(this.ccount),null);;////目前本轮每个玩家的出牌[]表示该玩家过牌,null表示本轮该玩家还未出牌
- if(this.currentId > -1){
- // console.warn("这里获取了出牌提示222 "+this.currentId);
- let next = (this.currentId + 1) % this.ccount;
- this.nextCardCount = this.handCards[next].length;
- this.tipInfo.chairId = this.currentId;//出牌提示
- this.tipInfo.tipCards = this.logic.getOutTip(this.currentId,this.handCards[this.currentId],this.lastOut,this.isHTSSC,this.nextCardCount == 1);
- }
-
- for (let i = 0; i < this.ccount; ++i) {
- let ocard2 = {
- chairId: String(-1),
- currentId: this.currentId,
- isblEnd: true,
- lastChair: this.lastOut.chair,
- nextCardCount: this.nextCardCount,
- type: String(-1),
- cards: []
- };
- let tipInfo = {chairId:-1,tipCards:[]}//出牌提示
- if(i == this.currentId) tipInfo = this.tipInfo;
- ocard2.tipInfo = this.logic.deepCloneTL(tipInfo);
- // console.warn("这里发给前端了 "+JSON.stringify(ocard2.tipInfo));
- yield this.pushMsgAsync(i, 'paodekuai_event', { type: M.OUT_CARD, data: ocard2 });
- if( i == this.ccount -1){
- let cocard2 = this.logic.deepCloneTL(ocard2);
- cocard2.tipInfo = {chairId:-1,tipCards:[]}//出牌提示
- let pjhfsplist2 ={
- shouPai:this.logic.deepCloneTL(this.handCards),
- // lastCount:String(this.logic.leaveCount()),
- ocard:this.logic.deepCloneTL(cocard2),
- outCards:this.logic.deepCloneTL(this.outCards),
- }
- yield this.lookMsgAsync('paodekuai_event', { type: M.OUT_CARD, data: ocard2 });
- this.setPaijuHuiFangData(M.OUT_CARD,pjhfsplist2);/////TL++ 牌局回放 push出牌数据
- }
- }
-
- let str4 = "table 开始新一轮出牌---id:"+this.id + " ,uid -1" +" cards ";
- logger.warn(str4);////cssj
- if(this.currentId > -1){
- // console.warn("在这里判断是否可以一把出完了 222 ")
- let outList = this.logic.getCanOutOverList(this.currentId,this.handCards[this.currentId],this.tipInfo,this.lastOut)
- if(outList.length > 0){
- // console.warn("在这里可以一把出完了222 "+JSON.stringify(outList));
- yield this.autoOutLastCard(this.currentId,outList);
- return { code: C.OK };
- }
- else {
- yield this.autoOutCard(this.currentId);
- return { code: C.OK };
- }
- }
- })
- proto.findAutoCards = cor(function* (currentId,_outIndex) {
- let cards = null;
- let outIndex = _outIndex;
- if(this.tipInfo.chairId == currentId && this.tipInfo.tipCards.length > 0){
- cards = this.logic.deepCloneTL(this.tipInfo.tipCards[outIndex]);
- }
- let cpishf = true;//出牌是否合法
- if(cards && cards.length > 0){
- let cpres = this.outCardAsync(currentId,cards);
- //{"isFulfilled":true,"isRejected":false,"fulfillmentValue":{"code":201,"msg":"332"}}
- _.forEach(cpres, function(value, key) {
- // console.warn("key "+key+" value "+JSON.stringify(value));
- if(key == "_settledValue"){
- // console.warn("_settledValue key "+key+" value "+JSON.stringify(value));
- if(value && value.code && value.code != C.OK){
- cpishf = false;
- // console.error("自动出牌不合法 cpishf "+cpishf);
- }
- return;
- }
- })
- }
- if(!cpishf){
- // console.error("自动出牌失败 id:"+this.id+" currentId "+currentId+" " +JSON.stringify(cards));
- outIndex++;
- this.findAutoCards(currentId,outIndex);
- }
- // else console.warn("自动出牌成功 id: "+this.id+" currentId "+currentId+" "+JSON.stringify(cards));
- })
- proto.autoOutCard = cor(function* (currentId) {
- let cpdjs = -1;//自动出牌倒计时
- if(this.lsetReabte.getIsBS(this.agentId,this.ownerName,this.ownerUid)) {
- //是比赛链接
- cpdjs = 20;//20秒后进入托管
- if(this.everyIsAutoOut[currentId]) cpdjs = 2;//已经是托管的话2秒之后自动出牌
- }
- if(this.autoOutTimer)
- {
- clearTimeout(this.autoOutTimer);
- this.autoOutTimer = null;
- }
- // console.warn("判断是否进入托管 currentId "+currentId+" isauto "+this.everyIsAutoOut[currentId]+" cpdjs "+cpdjs);
- let cards = null;
- let outIndex = 0;
- if(this.tipInfo.chairId == currentId && this.tipInfo.tipCards.length > 0){
- cards = this.logic.deepCloneTL(this.tipInfo.tipCards[0]);
- }
- if(cpdjs > 0 && cards && cards.length > 0){
- this.autoOutTimer = this.app.timer.setTimeout(() =>
- {
- let str44 = "table 自动出掉 id:"+this.id + " ,uid "+currentId +" cpdjs "+cpdjs+" cards "+cards;
- logger.warn(str44);////cssj
- this.everyIsAutoOut[currentId] = 1;
- // 下面是修改之后的
- this.findAutoCards(currentId,0);
-
- // 下面是修改之前的
- // let cpres = this.outCardAsync(currentId,cards);
- // //{"isFulfilled":true,"isRejected":false,"fulfillmentValue":{"code":201,"msg":"332"}}
- // let cpishf = true;//出牌是否合法
- // _.forEach(cpres, function(value, key) {
- // // console.warn("key "+key+" value "+JSON.stringify(value));
- // if(key == "_settledValue"){
- // // console.warn("_settledValue key "+key+" value "+JSON.stringify(value));
- // if(value && value.code && value.code != C.OK){
- // cpishf = false;
- // // console.error("自动出牌不合法 cpishf "+cpishf);
- // }
- // return;
- // }
-
- // });
- // // console.warn("自动出牌返回 "+ typeof(cpres)+" "+JSON.stringify(cpres)+" "+JSON.stringify(cpres.isFulfilled)+" "+JSON.stringify(cpres.fulfillmentValue));
- // if(!cpishf){
- // console.error("自动出牌失败 id:"+this.id+" currentId "+currentId+" " +JSON.stringify(cards));
- // outIndex++;
- // if(this.tipInfo.tipCards[outIndex]){
- // let cpres2 = this.outCardAsync(currentId,this.tipInfo.tipCards[outIndex])
- // }
- // }
- // else console.warn("自动出牌成功 "+JSON.stringify(cards));
- }
- , cpdjs*1000);//最后一手牌可以出完的时候1秒后自动出掉
- }
- return { code: C.OK };
- })
- // 操作是否自动出牌
- proto.autoOutCardAsync = cor(function* (chairId) {
- // console.warn("操作是否自动出牌 "+chairId+" "+ this.everyIsAutoOut[chairId]+" this.currentId "+this.currentId);
- if(this.everyIsAutoOut[chairId]) {
- this.everyIsAutoOut[chairId] = 0;
- // if(this.currentId == chairId && this.autoOutTimer)
- // {
- // clearTimeout(this.autoOutTimer);
- // this.autoOutTimer = null;
- // }
- }
- else {
- //比赛链接目前不允许开启托管
- if(!this.lsetReabte.getIsBS(this.agentId,this.ownerName,this.ownerUid)) {
- this.everyIsAutoOut[chairId] = 1;
- }
- }
- let data = {isAutoOut:this.everyIsAutoOut[chairId]}
- return { code: C.OK, data: data };
- })
- // 结算游戏
- proto.concludeGameAsync = cor(function* (mode) {
- /////增加下面这几行是为了保证每一把只执行一次结算方法
- if(this.isYJJSGL){
- // let strk = "table 结算游戏 id:了保证每一把只执行一次结算方法 "+this.id +"结算模式"+mode
- // logger.info(strk);////cssj
- return;
- }
- this.isYJJSGL = true;
- this.isYJKSGL = false;/////是否已经执行过开始函数了
- // console.warn("结算函数",mode);
- let str1 = "table 结算游戏 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,
- isPoChan: 0,
- cardfen: 0,
- zhadanfen: 0,
- hongshifen: 0,
- shiJiKouFen: 0,
- });
- data.hutype = [];
- let mgrzdgs = [0,0,0]
- for (let i = 0; i < this.blZDInfo.length; ++i) {
- if(this.blZDInfo[i].length > 0){
- mgrzdgs[this.blZDInfo[i][0]]++
- }
- }
- // console.warn("结算分数 炸弹信息 "+JSON.stringify(this.blZDInfo)+" mgrzdgs "+mgrzdgs);
- // 计算输赢
- for (let i = 0; i < wins.length; ++i) {
- if (winner.chs.indexOf(i) != -1) {
- wins.forEach((w, c) => {
- //计算剩余牌分
- let sy = 0;
- if(this.handCards[c].length > 1) sy = this.handCards[c].length * this.cell;
- if (c != i) {
- w.win -= sy;
- wins[i].win += sy;
- w.cardfen -= sy;
- wins[i].cardfen += sy;
- }
- //计算全关翻倍分
- if(this.handCards[c].length == this.cardCount){
- if (c != i) {
- w.win -= sy;
- wins[i].win += sy;
- w.cardfen -= sy;
- wins[i].cardfen += sy;
- }
- }
- });
- //计算扎鸟分(红桃十翻倍)
- wins.forEach((w, c) => {
- let sy = 0;
- if (c == this.zhaniaoChair || i == this.zhaniaoChair) {
- if(this.handCards[c].length > 1) sy = this.handCards[c].length * this.cell
-
- w.win -= sy;
- wins[i].win += sy;
- w.hongshifen -= sy;
- wins[i].hongshifen += sy;
- }
- //计算全关翻倍分
- if(this.handCards[c].length == this.cardCount){
- if (c != i) {
- w.win -= sy;
- wins[i].win += sy;
- w.cardfen -= sy;
- wins[i].cardfen += sy;
- }
- }
- });
- }
- //计算炸弹分
- wins.forEach((w, c) => {
- let sy = 10*mgrzdgs[i];
- if (c != i) {
- w.win -= sy;
- wins[i].win += sy;
- w.zhadanfen -= sy;
- wins[i].zhadanfen += sy;
- }
- });
- // 手牌
- wins[i].handCard = this.logic.deepCloneTL(this.handCards[i]);
- wins[i].isZhaNiao = this.zhaniaoChair == i;
- wins[i].isQuanGuan = this.handCards[i].length == this.cardCount;
- }
- // let str3 = "table 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];
-
- 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) {
- let zhanjiItem = {
- zf: wins[i].win,
- zn: wins[i].isZhaNiao,
- qg: wins[i].isQuanGuan,
- ps: wins[i].handCard.length,
- pf: wins[i].cardfen,
- zdf: wins[i].zhadanfen,
- hsf: wins[i].hongshifen,
- }
- bjsy[i] = zhanjiItem;
- }
- 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] -=200;
- 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 = "table 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});
- // 切换庄家
- this.chBanker = winner.chs[0];
- /////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, 'paodekuai_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, 'paodekuai_event', { type: 100, data: {"pjhfDataList":this.PaijuHuiFang}});//////最终发送给前端的牌局回放
- // let str6 = "table 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, 'paodekuai_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++设置消耗
- // this.score.writeCost(user.id,0, lwcost);
- }
- }
- yield this.pushMsgAsync(-1, 'paodekuai_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) {
- if(this.yjxrzj){
- logger.warn("出错了已经写入过战绩了-------------- " + this.yjxrzj );
- return;
- }
- this.yjxrzj = true;
- yield this.writeResultAsync2(endmode);
- });
- //ts++写分 endtype = { 正常: 0,局数完成: 1, 房主解散: 2, 申请解散: 3 ,超时解散: 4 };
- proto.writeResultAsync2 = 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 -= 200;
- 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
- });
- logger.warn("fhmjtable new--------111 " + this.recordid );
- // 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.warn("战绩写入结束--",this.id);
- // return { code: C.OK };
- });
- // 结束信息 var endtype = { 局数完成: 1, 主动解散: 2, 断线解散: 3 ,超时解散: 4 };
- proto.endResultAsync = cor(function* (endmode) {
- // console.warn("ts++---------记录信息",this.id);
- let str6 = "table 结束信息--id: "+this.id +" ,结算模式 "+endmode;
- logger.warn(str6);////cssj
- if(endmode>ENDMODE.PLAYING)//ts++关闭
- {
- let nowTime = Date.now();
- if(this.state<STATE.END)//ts++防止重复写入
- {
- this.state = STATE.END;
- if (this.endTimer) {
- clearTimeout(this.endTimer);
- this.endTimer = null;
- }
- if (this.overTimer) {
- clearTimeout(this.overTimer);
- this.overTimer = null;
- }
-
-
- // console.warn("ts++---------局数完成",this.over);
- if(this.over>0)
- {
- 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 -= 200;//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, 'paodekuai_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, 'paodekuai_event', { type: M.TABLE_JIESAN });
- }
- // console.warn("调用离开 length ",this.leaveUsers.length+" this.leaveUsers "+JSON.stringify(this.leaveUsers));
- // console.warn("调用离开 BSlength ",this.leaveUsersBS.length+" this.leaveUsersBS "+JSON.stringify(this.leaveUsersBS));
- for (var i = 0; i < this.leaveUsersBS.length; i++) {
- let itemUid = this.leaveUsersBS[i];
- if(this.leaveUsers.indexOf(itemUid) == -1) {
- this.leaveUsers.push(itemUid);
- // console.warn("this.leaveUsers 增加 leaveUsersBS 元素 "+itemUid + " " +JSON.stringify(this.leaveUsers));
- }
- }
- 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 = "table 结束信息22 关闭-id:"+this.id +"结算模式"+endmode;
- // logger.info(str5);////cssj
- }
- else//普通结束
- {
- // let str5 = "table 结束信息 普通结束---id:"+this.id +"结算模式"+endmode
- // logger.info(str5);////cssj
- if(this.lsetReabte.getIsBS(this.agentId,this.ownerName,this.ownerUid)){
- for (let user of this.users) {
- if(user.state2 == User.STATE.OFFLINE && this.leaveUsersBS.indexOf(user.id) == -1) {
- this.leaveUsersBS.push(user.id);
- }
- }
- }
- this.state = STATE.FREE2;
- for (let user of this.users) {
- if (user) user.state2 = User.STATE.FREE;
- }
- if(this.lsetReabte.getIsBS(this.agentId,this.ownerName,this.ownerUid)){
- if(this.everyIsAutoOut.indexOf(1) != -1){
- this.autoReadyTimer = this.app.timer.setTimeout(() => this.autoReadyOnBisai(), 5000);//这个延迟时间不能太短
- }
- if(this.everyIsAutoOut.indexOf(0) != -1){
- this.autoReadyTimer2 = this.app.timer.setTimeout(() => this.autoReadyOnBisai2(), 9000);
- }
- }
- }
-
- let str7 = "table end 结束信息---id:%s "+this.id +" 结算模式 "+endmode;
- logger.warn(str7);////cssj
-
- });
- //比赛房间的话,玩家处于托管状态的时候2秒之后自动准备 因为定时器里不能yield,所以改成这种方式
- proto.autoReadyOnBisai = cor(function* (users) {
- if(this.autoReadyTimer)
- {
- clearTimeout(this.autoReadyTimer);
- this.autoReadyTimer = null;
- }
- for (let user of this.users) {
- // console.warn("玩家处于托管状态的时候2秒之后自动准备--- user.state "+user.state+" user.state2 "+user.state2);
- if(this.everyIsAutoOut[user.chairId] == 1){
- if(user.state2 == User.STATE.FREE || user.state2 == User.STATE.OFFLINE){
- yield this.game.readyGameAsync(user.id);
- }
- }
- }
- });
- //比赛房间的话,玩家不处于托管状态的时候12秒之后自动准备 因为定时器里不能yield,所以改成这种方式
- proto.autoReadyOnBisai2 = cor(function* (users) {
- if(this.autoReadyTimer2)
- {
- clearTimeout(this.autoReadyTimer2);
- this.autoReadyTimer2 = null;
- }
- for (let user of this.users) {
- // console.warn("玩家不处于托管状态的时候12秒之后自动准备--- user.state "+user.state+" user.state2 "+user.state2);
- if(this.everyIsAutoOut[user.chairId] == 0){
- if(user.state2 == User.STATE.FREE || user.state2 == User.STATE.OFFLINE){
- this.everyIsAutoOut[user.chairId] = 1;
- yield this.game.readyGameAsync(user.id);
- }
- }
- }
- });
- //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 = "table 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, 'paodekuai_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, 'paodekuai_event', { type: M.TABLE_JIESAN });
- let str6 = "table 请求结束定时器---id: "+this.id +" ,endmode: "+endmode
- logger.warn(str6);////cssj
- if(this.autoOutTimer)
- {
- clearTimeout(this.autoOutTimer);
- this.autoOutTimer = null;
- }
- if(this.autoReadyTimer)
- {
- clearTimeout(this.autoReadyTimer);
- this.autoReadyTimer = null;
- }
- if(this.autoReadyTimer2)
- {
- clearTimeout(this.autoReadyTimer2);
- this.autoReadyTimer2 = null;
- }
- yield this.endResultAsync(endmode);//ts++ 房主解散 写分
- });
- // 请求结束
- proto.overTableAsync = cor(function* (user) {
- // console.warn("ts+++++请求结束",user.chairId);
- let str3 = "table 请求结束.......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, 'paodekuai_event', { type: M.TABLE_JIESAN });
- // let str5 = "table 房主解散-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, 'paodekuai_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 = "table 拒绝结束.......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, 'paodekuai_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 = "table 同意结束.......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, 'paodekuai_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;
- }
- if(this.autoOutTimer)
- {
- clearTimeout(this.autoOutTimer);
- this.autoOutTimer = null;
- }
- if(this.autoReadyTimer)
- {
- clearTimeout(this.autoReadyTimer);
- this.autoReadyTimer = null;
- }
- if(this.autoReadyTimer2)
- {
- clearTimeout(this.autoReadyTimer2);
- this.autoReadyTimer2 = null;
- }
- yield this.pushMsgAsync(-1, 'paodekuai_event', { type: M.TABLE_JIESAN });
- // let str4 = "table 全部同意结束-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 = "table 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 };
- });
|