| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126 |
- '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').sxjiang || {};
- 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 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
- this.app = game.app;
- this.gameId = 10007;
- 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;
- // if(gameKindTL == 2){
- // //num_cost = 50;//////冲刺扣50
- // num_cost =parseInt(COSTS[1]);
- // }
- // else
- // {
- num_cost =parseInt(COSTS[round]);
- // }
- this.other = other;//////TL++2人3人的游戏规则
- // console.warn("222创建房间的other",other,this.other," gameKindTL ",gameKindTL," type " ,type);
- this.jiangmaType = -1;////奖码类型:-1:不奖码,1:159奖码,2:摸几奖几,3:一码全中
- this.jiangmaCount = -1;////奖码张数
- if(this.other & 1){
- this.jiangmaType = 1;
- if(this.other & 8) this.jiangmaCount = 2;
- else if(this.other & 16) this.jiangmaCount = 4;
- else if(this.other & 32) this.jiangmaCount = 6;
- }
- else if(this.other & 2){
- this.jiangmaType = 2;
- this.jiangmaCount = 0;
- }
- else if(this.other & 4){
- this.jiangmaType = 3;
- this.jiangmaCount = 1;
- }
- this.hzCount = 0;/////红中个数
- if(this.other & 64) this.hzCount = 4;
- else if(this.other & 1024) this.hzCount = 6;
- else if(this.other & 2048) this.hzCount = 8;
- this.isQGHJM = false;/////是否抢杠胡奖码
- if(this.other & 128) this.isQGHJM = true;
- this.isHZHG = false;/////是否荒庄荒杠
- if(this.other & 256) this.isHZHG = true;
- this.isWGHZJYM = false;/////无红中胡加一码
- if(this.other & 512) this.isWGHZJYM = true;
- this.isZNZM = this.type == 2;/////是否只能自摸,拉杠情况可以胡
- // console.warn("奖码类型:-1:不奖码,1:159奖码,2:摸几奖几,3:一码全中 "+this.jiangmaType)
- // console.warn("奖码张数 "+this.jiangmaCount)
- // console.warn("红中个数 "+this.hzCount)
- // console.warn("是否抢杠胡奖码 "+this.isQGHJM)
- // console.warn("是否荒庄荒杠 "+this.isHZHG)
- // console.warn("无红中胡加一码 "+this.isWGHZJYM)
- // console.warn("是否只能自摸 "+this.isZNZM)
- this.cost = num_cost;
- this.over = 0;
- this.round = round;
- this.stime = 0;
- this.ctime = Date.now();
- this.etime = 0;
- this.lconfigCommon = null;
- // 人数
- this.ccount = playerAllCount;//Logic.CHAIR_COUNT;
- this.mcount = Logic.CARDS_COUNT;
- // 房主
- this.ownerChairId = -1;//房主的chairid
- this.ownerId = cPlayerId;//房主Id
- this.ownerUid = cUserId;//房主的userID
- this.ownerName = cName;
- this.ownerHeadUrl = cHead;
- // 数据
- var logic = new Logic(type,gameKindTL,playerAllCount,other);
- this.logic = logic;
- this.score = new Score(this);
- this.handCards = Array(this.ccount);
- this.huCards = logic.fillDeep(Array(this.ccount), []);
- this.users = Array(this.ccount);
- this.chBanker = 0;
- this.quFeng = 0;
- this.bankFlag = 0;
- this.outCards = logic.fillDeep(Array(this.ccount), []);
- // 标记
- this.isDihus = _.fill(Array(this.ccount), true);
- this.isTianhu = true;
- this.outCard = 0;
- this.outerId = -1;
- this.disCards = [];
- this.currentId = -1;
- // 包含字,总杠次,保留量
- // this.hasWords = !(type & 2);/////TL++zs
- // this.hasWords = true;/////是否含有字牌/////TL++
- this.gonCount = 0;
- // this.disCounts = [26, 14, 16, 26];/////TL++zs
- // this.disCounts = [1,1,1,1,];
- // 允许吃牌
- this.hasEat = false;//!!(type & 4);////是否可吃牌
- // 允许点炮
- this.hasEHu = true;///!!(type & 8);
- // 一炮多响
- this.isMHu = true;//!!(type & 16);
- // 允许杠胡
- this.hasGHu = true;///!!(type & 32);
- // 点炮出钱
- this.isWOne = true;//!!(type & 64);
- // 权限:16-胡,8-杠,4-碰,2-吃,1-等待,0-无
- this.masks = _.fill(Array(this.ccount), 0);
- this.excepts = logic.fillDeep(Array(this.ccount), {});
- // 等待杠类型,1-普通杠, 2-暗杠, 3-自摸明杠
- this.gangType = 0;
- this.gangCard = 0;
- // 抢杠胡、被杠玩家
- this.isGangHu = false;
- this.gangOuter = -1;
- // 等待吃类型,1-@**左吃, 2-*@*中吃, 3-@**右吃
- this._eatType = 0;
- this.autoOutTimer = null;
- this.everyIsAutoOut = _.fill(Array(this.ccount), 0);
- // 胡牌者
- this.anams = Array(this.ccount);
- this.huRes = Array(this.ccount);
- this.winner = { lead: -1, chs: [] };
- // 底分
- this.cell = cell;
- // 围观者
- this.lookers = [];
- //结束时的继线用户
- this.leaveUsers = [];
- // 状态
- this.state = STATE.FREE;
- // 申请结束标记
- this.overFlag = 0;
- this.overTimer = null;
- this.endTableTime = 60;//////TL++,申请解散房间之后60秒之后不操作则认为同意解散
- this.reqJieSan = [-1,-1,-1,-1];/////解散桌子数据,前面为chirid后面为情况-1:未操作 0:拒绝 1:同意 2为解散发起
- //断线 结束定时器
- this.endTimer = null;
- //////以下全为TL++
- /////TL++,补花定时器,防止连续补花太快
- this.PJHF = new paiJuHuiFang();
- // this.buhuaTimeout = null;
- this.backStartTimer = null;//////重入之后系统会自动准备为了解决可能没牌的问题2秒之后才开始游戏
- this.PaijuHuiFang = [];////TL++,牌局回放
- // this.zhyzfgs = [-2,null,null];/////TL++,由于最后一张牌的摸牌被打断所以 用来记录最后一张牌的发牌函数的参数
- // this.isLianGang = [-1,false,-1];/////TL++,连杠的玩家座位号,是否连杠 杠的牌
-
- this.isYJJSGL = false;/////是否已经执行过结算函数了
- this.isYJKSGL = false;/////是否已经执行过开始函数了
- this.JSFJTimeout = null;//解散房间倒计时
- this.JSFJTime = 60;//解散房间倒计时60秒
- this.SQJSTime = null;//申请解散房间的时间,用于计算解散房间倒计时所剩的时间
- this.gameNeverStart = true;//游戏是否从未开始过,用于解散房间判断
- this.pjhffileName = [];//用于记录玩家牌局回放的json文件名
- this.playerPosList = [[],[],[],[]];//记录玩家的位置信息数组
- this.gameKindTL = gameKindTL || 1;//平搓还是冲刺 = 1代表平搓 = 2代表冲刺
- this.playerAllCount = playerAllCount || 4;//游戏人数 = 2表示2人局 = 3表示3人局 = 4表示4人局
- this.isNeverStart = true;//游戏是否从未开始
- this.sszjDataList = [];//设置实时战绩的数据
- this.isEveryZZ = false;//是否每一个人都做过庄
- // this.isZJYG = false;////本局庄家是否有杠
- this.chairArry = [0,1,2,3];//
- // this.isNeverTounchHU = false;/////是否从未点击过胡按钮
- this.sszjs = [];//ts++实时战绩
- this.LWKF = [10,10,10,10,10];//////TL++礼物扣费
- this.isGameOk=false;//ts++牌局正常结束
- this.agentRebate=0;//ts++本局的返利
- // delete require.cache[require.resolve('../../share/setReabte')];
- // setReabte = require('../../share/setReabte');
- this.lsetReabte = new setReabte(this.app);
- };
- // 导出状态
- Table.STATE = STATE;
- //ts++ 结束模式
- Table.ENDMODE = ENDMODE;
- // 导出类
- module.exports = Table;
- // 原型对象
- var proto = Table.prototype;
- // 是否站满
- proto.isFull = function () {
- return (this.lookers.length >= 5);
- };
- // 是否准备
- proto.isReady = function () {
- for (let user of this.users) {
- if (!user || !user.isReady()) return false;
- }
- return true;
- };
- // ts++是否二次准备
- proto.isReady2 = function () {
- for (let user of this.users) {
- if (!user || !user.isReady2()) return false;
- }
- return true;
- };
- // 是否游戏中
- proto.isPlaying = function () {
- return this.state > STATE.FREE;
- };
- // 是否全在线
- proto.isOnline = function () {
- for (let user of this.users) {
- if (user && user.isOffline()) return false;
- }
- return true;
- };
- // 是否全断线
- proto.isOffline = function () {
- for (let user of this.users) {
- if (!user || !user.isOffline()) return false;
- }
- return true;
- };
- // 是否空桌
- proto.isEmpty = function () {
- if (this.lookers.length > 0) return false;
- for (let i = 0; i < this.users.length; ++i) {
- if (this.users[i]) return false;
- }
- return true;
- };
- // 局数完成
- proto.isGameOver = function () {
- let str3 = "table 局数完成 .......id: "+ this.id + " this.over " + this.over;
- logger.warn(str3);////cssj
- return (this.over >= this.round);
- };
- // 重置本局
- proto.resetRound = function () {
- _.fill(this.handCards, null);
- _.fill(this.isDihus, true);
- this.isTianhu = true;
- _.fill(this.masks, 0);
- if(this.autoOutTimer)
- {
- clearTimeout(this.autoOutTimer);
- this.autoOutTimer = null;
- }
- this.everyIsAutoOut = _.fill(Array(this.ccount), 0);
- this.logic.fillDeep(this.excepts, {});
- _.fill(this.huRes, null);
- this.gonCount = 0;
- this.winner.chs = [];
- this.winner.lead = -1;
- this.logic.fillDeep(this.huCards, []);
- this.logic.fillDeep(this.outCards, []);
- this.outCard = 0;
- this.outerId = -1;
- this.currentId = -1;
- this._eatType = 0;
- this.gangType = 0;
- this.gangCard = 0;
- this.isGangHu = false;
- this.gangOuter = -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: [],
- ownerId: -1,//this.ownerChairid
- ownerUserId: this.ownerUid,////TL++,房主的userID
- ownerName: this.ownerName,//////TL++,房主的昵称
- ownerHeadUrl: this.ownerHeadUrl,//////TL++,房主的头像地址
- gameKindTL: this.gameKindTL,////平搓还是冲刺 = 1代表平搓 = 2代表冲刺
- playerAllCount: this.playerAllCount,////游戏人数 = 2表示2人局 = 3表示3人局 = 4表示4人局
- other: this.other,
- creatTime : this.ctime,
- nowTime : Date.now(),
- state: this.state,
- sszjDataList: this.sszjDataList,////TL++,设置实时战绩的数据
- isZHYZ: this.logic.isZHYZ, /////TL++,是否最后一张
- playerPosList: this.playerPosList,/////TL++玩家位置数据
- chairArry: this.chairArry,/////TL++
- isNeverStart: this.isNeverStart,/////TL++,游戏是否从未开始
- overFlag:this.overFlag,//ts++房间解散标识
- endTableTime:endTableTime,
- recordid:this.recordid,
- yxndlbTime:this.yxndlbTime,
- yxndlbTip:this.yxndlbTip,
- reqJieSan:this.reqJieSan
- };
- // 正在游戏
- var isPlaying = this.isPlaying();
- if (isPlaying) {
- tableInfo.qFeng = this.quFeng;
- tableInfo.banker = this.chBanker;
- tableInfo.stime = Date.now() - this.stime;
- tableInfo.currentId = this.currentId;
- tableInfo.disCards = this.disCards;
- tableInfo.lastCount = this.logic.leaveCount();
- tableInfo.isGangHu = this.isGangHu;
- tableInfo.gangCard = this.gangCard;
- //////TL++,游戏过程中重入
- tableInfo.baiDaCard = String(this.logic.baiDaCard);//////TL++,本局百搭牌
- tableInfo.everyFllowerCardList = [[],[],[],[]]; /////每个人手上的花牌
- //////TL++ end,游戏过程中重入
- }
- // 桌上玩家
- for (let i = 0; i < this.users.length; ++i) {
- let user = this.users[i];
- if (user) {
- let score = this.score.getScore(user.id);
- let uinfo = {
- account: user.account, name: user.name, sex: user.sex, headurl: user.headurl,
- state: user.state2, score: score, chairId: user.chairId
- };
- if (isPlaying) {
- let huCards = [];
- for (let huCard of this.huCards[i]) {
- huCards.push({ style: huCard.style, type: huCard.type, card: huCard.cards[0], origin: huCard.origin });
- }
- uinfo.huCards = huCards;
- uinfo.outCards = this.outCards[i];
- let handCard = this.handCards[i] || [];
- uinfo.handCount = handCard.length;
- }
- tableInfo.users.push(uinfo);
- }
- }
- // 围观玩家
- for (let i = 0; i < this.lookers.length; ++i) {
- let user = this.lookers[i];
- if (user) {
- tableInfo.lookers.push({ account: user.account, name: user.name, sex: user.sex, headurl: user.headurl });
- }
- }
- return tableInfo;
- };
- // 回到桌子
- proto.backAsync = cor(function* (user) {
- let str3 = "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;
- let isGuoHuList = [[false,0],[false,0],[false,0],[false,0],];
- 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, 'sxjiang_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, 'sxjiang_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){
- this.backStartTimer = this.app.timer.setTimeout(() => this.backStartTimeAsync(), 2 * 1000);//延迟2秒开始游戏
- }
- }
- }
- // 取消计时
- if (this.isOnline() && this.endTimer) {
- clearTimeout(this.endTimer);
- this.endTimer = null;
- }
- isGuoHuList[chairId] = this.logic.isGuoHuList[chairId];
- }
- // 数据处理
- data.fee = this.score.isFeed(user.id) ? '0' : '1';
- data.table = this.getTableInfo();
- let hutipdata = {
- renyi:0,//////是否可胡任意牌,0表示不满足1表示满足
- kehuData:[]/////对象数组,分别表示打哪张可胡哪几张数据
- };
- if(chairId == this.currentId){
- let tipres = this.logic.hutip(this.currentId,this.handCards[this.currentId],this.huCards[this.currentId],this.huCards,this.outCards);////重入时调用胡牌提示
- data.table.hutipdata = tipres;
- }
- else{
- data.table.hutipdata = hutipdata;
- }
- let isAutoOut = 0;
- if (chairId != -1) {
- isAutoOut = this.everyIsAutoOut[chairId];
- }
- data.table.isAutoOut = isAutoOut;
- data.table.isGuoHuList = isGuoHuList;
- 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, 'sxjiang_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, 'sxjiang_event', { type: M.COST_FEE, data: costdata });
- }
-
- // if (this.isReady()) yield this.pushMsgAsync(this.ownerChairid, 'sxjiang_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, 'sxjiang_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, 'sxjiang_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, 'sxjiang_event', {///////发送坐下
- type: M.SEAT, data: {
- account: user.account,
- name: user.name,
- sex: user.sex,
- headurl: user.headurl,
- state: String(user.state),
- score: String(score),
- chairId: String(user.chairId),
- userId: String(user.userId),
- playerPosList: this.playerPosList, /////TL++记录玩家的位置信息数组
- }
- });
-
- });
- //////TL++,在首次游戏开始的时候随机打乱用户的座位
- proto.randomChangeChairTL = cor(function* () {
- // console.warn("111在首次游戏开始的时候随机打乱用户的座位",this.users[0].name,this.users[1].name,this.users[2].name,this.users[3].name);
- // console.warn("1在首次游戏开始的时候随机打乱用户的座位",this.users[0].chairId,this.users[1].chairId,this.users[2].chairId,this.users[3].chairId);
- if(this.playerAllCount > 2){
- let changeResult = [];
- if (this.over <= 0) {///////本房间开始的第一局游戏
- // for (let i = 0; i < this.ccount; i++) {/////这种随机4次可能会导致4次随机之后和打乱之前的顺序一样所以弃用
- for (let i = 0; i < 1; i++) {
- let oldchaieID = i;
- let olduser = this.users[i];
- let newchaieID = Math.floor(Math.random()*this.playerAllCount);////// 区间[0,3]取整数
- while (newchaieID == oldchaieID) {
- newchaieID = Math.floor(Math.random()*this.playerAllCount);////// 区间[0,3]取整数
- }
- let newuser = this.users[newchaieID];
- // console.warn("222在首次游戏开始的时候随机打乱用户的座位",oldchaieID,newchaieID);
- // console.warn("xxxxxxxxx删除有没有用啊",this.users.length);
- delete this.users[newchaieID];
- delete this.users[oldchaieID];
- // console.warn("xxxxxxxxx22删除有没有用啊",this.users.length);
- this.users[newchaieID] = olduser;
- this.users[newchaieID].chairId = newchaieID;
- // this.users[newchaieID].id = newuser.id;
- this.users[oldchaieID] = newuser;
- this.users[oldchaieID].chairId = oldchaieID;
- // this.users[oldchaieID].id = olduser.id;
- changeResult.push([oldchaieID,newchaieID])
- }
-
- // console.warn("333在首次游戏开始的时候随机打乱用户的座位",this.users[0].name,this.users[1].name,this.users[2].name,this.users[3].name);
- // console.warn("3在首次游戏开始的时候随机打乱用户的座位",this.users[0].chairId,this.users[1].chairId,this.users[2].chairId,this.users[3].chairId);
- // console.warn("3在首次游戏开始的时候随机打乱用户的座位",this.users[0].id,this.users[1].id,this.users[2].id,this.users[3].id);
- // console.warn("3在首次游戏开始的",this.users[0]);
- ////// this.users 发送给前端会代码报错
- // yield this.pushMsgAsync(-1, 'sxjiang_event', { type: M.CHAIR_DALUAN, data: { changeResult:changeResult } });
- /////TL++
- for (let i = 0; i < this.users.length; ++i) {
- this.score.setUserChair(this.users[i].id,this.users[i].chairId)
- }
- let daluanData = [];
- var isPlaying = this.isPlaying();
- for (let i = 0; i < this.users.length; ++i) {
- let user = this.users[i];
- if (user) {
- let score = this.score.getScore(user.id);
- let uinfo = {
- account: user.account, name: user.name, sex: user.sex, headurl: user.headurl,
- state: user.state, score: score, chairId: user.chairId
- };
- if (isPlaying) {
- let huCards = [];
- for (let huCard of this.huCards[i]) {
- huCards.push({ style: huCard.style, type: huCard.type, card: huCard.cards[0], origin: huCard.origin });
- }
- uinfo.huCards = huCards;
- uinfo.outCards = this.outCards[i];
- let handCard = this.handCards[i] || [];
- uinfo.handCount = handCard.length;
- }
- daluanData.push(uinfo);
- }
- }
- // this.score.delUser(user.id);
- yield this.pushMsgAsync(-1, 'sxjiang_event', { type: M.CHAIR_DALUAN, data: { daluanData:daluanData } });
- }
- }
- // console.warn("444在首次游戏开始的时候随机打乱用户的座位",changeResult);
- // this.starTimer = this.app.timer.setTimeout(() => this.startGameAsync(), 500);
- yield this.startGameAsync()/////TL++,在首次游戏的时候随机打乱用户的座位
- });
- // 站起桌子
- proto.standAsync = cor(function* (user) {
- let str3 = "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, 'sxjiang_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, 'sxjiang_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, 'sxjiang_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, 'sxjiang_event', { type: M.COST_FEE, data: costdata });
- }
- }
- else
- {
- if(user.cost==0 && user.spreadId)//ts++推荐人奖励
- {
- // let spreader = yield this.app.models.Player.findByIdAsync(user.spreadId, 'spreadCount spreadRebate');
- // if (spreader) {
- // spreader.spreadCount += 1;
- // spreader.spreadRebate += 100;
- // yield spreader.saveAsync();
- // }
- ////20200928因为现在的spreadId存的是userId,所以上面那段用不了了
- if(!this.lconfigCommon) {
- // console.warn("邀请新人送钻石活动 this.lconfigCommon 不存在 "+this.etime);
- this.lconfigCommon = new configCommon(this.app);
- }
- let yxhdxx = this.lconfigCommon.getActiveOpenTime(1);//邀请新人送钻石活动是否开启和开始结束时间的信息
- let isKQ = false;//邀请新人送钻石活动是否开启
- if(yxhdxx && yxhdxx.open && yxhdxx.startTime && yxhdxx.endTime) isKQ = true;
- // console.warn("获取配置信息 yxhdxx "+JSON.stringify(yxhdxx));
- if(isKQ && this.etime >= yxhdxx.startTime && this.etime < yxhdxx.endTime){
- var cpopts = {};
- cpopts['userId'] = parseInt(user.spreadId);
- let spreadList = yield this.app.models.Player.findMongoAsync(cpopts, 'spreadCount spreadRebate', { sort: { stime: 1 } });//
- if(spreadList.length == 1){
- spreadList[0].spreadCount += 1;
- spreadList[0].spreadRebate += 100;
- yield spreadList[0].saveAsync();
- }
- }
- }
- yield this.lsetReabte.updateDaterebateRecord(this.agentId,this.etime);
- // if(this.agentId) //正常结束的才能算
- // {
- // if(this.agentRebate>0)
- // {
- // //console.warn("代理返利写分+++++");
- // let gameCost2=this.agentRebate;//游戏消耗
- // let agentRebate2=parseInt(this.agentRebate*this.rEBATERATE);
- // this.agentRebate=0;
-
- // var today = new Date();
- // today.setHours(0);
- // today.setMinutes(0);
- // today.setSeconds(0);
- // today.setMilliseconds(0);
- // let nowverifyDate=today.getTime();
-
- // var agenter = yield this.app.models.Agenter.findByIdAsync(this.agentId,'rebateOther rebateCount rebateAll rebateNow rebateOut verifyDate verifyRebate agentRate');
- // if (agenter)
- // {
- // //日结算
- // let verifyBool=false;
- // let verifyDate=0;
- // let verifyRebate=0;
- // //日奖励
- // let dateAgentRate=0;
- // let dateRebate=0;
- // if(agenter.verifyRebate>0 && agenter.verifyDate!=nowverifyDate)
- // {
- // verifyBool=true;
- // verifyDate=agenter.verifyDate;
- // verifyRebate=agenter.verifyRebate;
- // dateAgentRate=agenter.agentRate;
-
- // agenter.rebateNow += verifyRebate;
- // agenter.rebateNow += dateRebate;
- // agenter.rebateOther += dateRebate;
- // agenter.rebateCount += dateRebate;
- // agenter.verifyRebate=0;
- // }
- // //修改代理数据
- // agenter.rebateCount += agentRebate2;
- // agenter.rebateAll += agentRebate2;
- // agenter.verifyDate=nowverifyDate;
- // agenter.verifyRebate+= agentRebate2;
- // let rCount=agenter.rebateCount;
- // let rOther=agenter.rebateOther;
- // let rAll=agenter.rebateAll;
- // let rNow=agenter.rebateNow;
- // let rOut=agenter.rebateOut;
- // let rVerifyDate=agenter.verifyDate;
- // let rVerifyRebate=agenter.verifyRebate;
- // yield agenter.saveAsync();
- // // console.warn("代理返利写分+++++agenter.saveAsync()");
-
- // // 锁定返利记录
- // if(verifyBool && verifyRebate>0)
- // {
- // var verifyrebateRecord = new this.app.models.RebateRecord({
- // _id: uuid.v1(),
- // agentId:this.agentId,
- // tableId: '',
- // rType: 3,
- // rCount: rCount- agentRebate2,
- // rOther: rOther,
- // rAll: rAll- agentRebate2,
- // rNow: rNow,
- // rOut: rOut,
- // rSwap: verifyRebate,
- // rDateSwap: dateRebate,
- // rVerifyDate: verifyDate,
- // rVerifyRebate: 0
- // });
- // yield verifyrebateRecord.saveAsync();
- // var daterebateRecord = new this.app.models.DateRebateRecord({
- // _id: uuid.v1(),
- // agentId:this.agentId,
- // verifyDate: verifyDate,
- // verifyRebate: verifyRebate,
- // dateAgentRate: dateAgentRate,
- // dateRebate: dateRebate
- // });
- // yield daterebateRecord.saveAsync();
- // }
- // // 返利记录
- // var rebateRecord = new this.app.models.RebateRecord({
- // _id: uuid.v1(),
- // agentId:this.agentId,
- // tableId: this.recordid,
- // rType: 1,
- // rCount: rCount,
- // rOther: rOther,
- // rAll: rAll,
- // rNow: rNow,
- // rOut: rOut,
- // rSwap: agentRebate2,
- // rDateSwap: 0,
- // rVerifyDate: rVerifyDate,
- // rVerifyRebate: rVerifyRebate
- // });
- // yield rebateRecord.saveAsync();
- // // console.warn("返利记录+++++rebateRecord.saveAsync()");
- // }
- // }
- // let gameRebate=0;
- // if(this.isGameOk)
- // {
- // gameRebate=parseInt(this.cost*this.rEBATERATE);
- // }
- // var today = new Date();
- // today.setHours(0);
- // today.setMinutes(0);
- // today.setSeconds(0);
- // today.setMilliseconds(0);
- // let date=today.getTime();
- // let countid=this.agentId+'-'+user.userId+'-'+date;
- // var playercount = yield this.app.models.PlayerCount.findByIdAsync(countid,'gameCount gameCost agentRebate time');
- // if (playercount)
- // {
- // playercount.gameCount+=1;
- // playercount.gameCost+=this.cost;
- // playercount.agentRebate+=gameRebate;
- // playercount.time=Date.now();
- // }
- // else
- // {
- // playercount = new this.app.models.PlayerCount({
- // _id: countid,
- // agentId:this.agentId,
- // playerId: user.id,
- // userId: user.userId,
- // name: user.name,
- // date: date,
- // gameCount: 1,
- // gameCost: this.cost,
- // agentRebate: gameRebate,
- // time:Date.now()
- // });
- // }
- // yield playercount.saveAsync();
-
- // }
- // console.warn("活动奖励 下面开始进行判断 ",user.spreadId,user.registerTime,user.lastLoginTime);
- // let str11 = "hdjl xmksjxpd "+ this.id + " isGameOk: " + this.isGameOk + " userId: " + user.userId + " spreadId: " + user.spreadId + " registerTime: " + user.registerTime + " lastLoginTime: " + user.lastLoginTime ;
- // logger.warn(str11);////cssj
- // if(this.isGameOk && this.ccount == 4 && user.spreadId)//活动奖励
- // {
- // // console.warn("活动奖励 至此是游戏正常结束而且玩家有推荐id",user.spreadId,user.registerTime,user.lastLoginTime);
- // ////正常结束而且该玩家有推荐人id
- // let acSTime = 1601481600000;////20201001零点的时间戳,活动开始时间
- // let acETime = acSTime + 86400000*8;////20201008这天截止的时间戳 活动结束时间
- // let xzsjc = Date.now();
- // let str12 = "hdjl zcyxszcjseqwjytjr "+this.id + " userId: " + user.userId +" xzsjc: "+xzsjc;
- // logger.warn(str12);////cssj
- // if(xzsjc >= acSTime && xzsjc < acETime){
- // if((user.registerTime >= acSTime && user.registerTime < acETime) || user.lastLoginTime < 1598889600000){
- // // console.warn("活动奖励 至此该玩家是新用户",user.spreadId,user.registerTime,user.lastLoginTime);
- // let str13 = "hdjl zcgwjsxyh "+this.id + " userId: " + user.userId;
- // logger.warn(str13);////cssj
- // ////活动期间注册或者9月1号10月1日之间未登陆过的玩家
- // var todayTL = new Date();
- // todayTL.setHours(0);
- // todayTL.setMinutes(0);
- // todayTL.setSeconds(0);
- // todayTL.setMilliseconds(0);
- // let jrldsjc=todayTL.getTime();////今日零点时间戳
- // let jrjssjc=jrldsjc + 86400000;////今日结束时间戳
- // var opts = { stime: { $gte: jrldsjc, $lt: jrjssjc },type: { $gte: 1, $lt: 2 }};
- // opts['sid'] = user.id;
- // let acrlist = yield this.app.models.ActiveRewardRecord.findMongoAsync(opts, '_id rewardtype totalfee type sid rid gameCount stime succtime succState', { sort: { stime: 1 } });//
- // if(acrlist.length == 0){
- // // console.warn("活动奖励 活动期间今日该玩家产生新的记录",user.spreadId,user.registerTime,user.lastLoginTime);
- // let str14 = "hdjl hdqjjrgwjcsxdjl "+this.id + " userId: " + user.userId;
- // logger.warn(str14);////cssj
- // ////活动期间今日该玩家产生新的记录
- // var activerewardrec = new this.app.models.ActiveRewardRecord({
- // _id: uuid.v1(), // UUID
- // rewardtype: 0, // 奖励类型,0红包
- // totalfee: 0, // 产生金额,红包为分
- // type:1, //活动类型:1国庆签到2国庆邀请
- // sid: user.id, // 产生奖励的玩家id
- // sname:user.name, // 产生奖励的玩家name
- // suid:user.userId, // 产生奖励的玩家userId
- // rid: user.id, // 此条奖励的受益玩家
- // gameCount: 1, // 游戏局数
- // stime: xzsjc, // 记录产生时间
- // succtime: 0, // 任务完成时间,任务未完成的时候这里是0
- // succState: 0 // 任务是否完成的状态,0:未完成1:已达成
- // });
- // yield activerewardrec.saveAsync();
- // }
- // else{
- // let str15 = "hdjl hdqjjrgwjyjcsgjl "+this.id + " userId: " + user.userId;
- // logger.warn(str15);////cssj
- // ////活动期间更新今日该玩家已经产生的记录
- // let newre = acrlist[0];
- // newre.gameCount++;
- // if(newre.gameCount >= 2){
- // // console.warn("活动奖励 活动期间更新今日该玩家已经产生的记录",user.spreadId,user.registerTime,user.lastLoginTime);
- // let str16 = "hdjl hdqjgxjrgwjyjcsdjl "+this.id + " userId: " + user.userId + " gameCount: " + newre.gameCount;
- // logger.warn(str16);////cssj
- // ////完成为解散2局,该玩家完成了签到的任务了
- // if(newre.gameCount == 2){
- // newre.totalfee = 500;
- // newre.succtime = xzsjc;
- // newre.succState = 1;
- // }
- // yield newre.saveAsync();
- // }
- // if(newre.gameCount == 2){
- // var opts2 = { stime: { $gte: acSTime, $lt: acETime },type: { $gte: 2, $lt: 3 }};
- // opts2['sid'] = user.id;
- // let acrlist2 = yield this.app.models.ActiveRewardRecord.findMongoAsync(opts2, 'rid', { sort: { stime: 1 } });//
- // let isneedcj = false;////是否需要创建邀请奖励产生记录
- // if(acrlist2.length == 0){
- // isneedcj = true;
- // // if(parseInt(acrlist2[0].rid) && parseInt(acrlist2[0].rid) == user.spreadId) isneedcj = true;
- // }
- // // console.warn("活动奖励 完成未解散2局,该玩家的推荐人完成了邀请的任务了",user.spreadId,user.registerTime,user.lastLoginTime);
- // let str17 = "hdjl csgwjdyqjl "+this.id + " userId: " + user.userId + " isneedcj: " + isneedcj;
- // logger.warn(str17);////cssj
- // if(isneedcj){
- // ////完成为解散2局,该玩家的推荐人完成了邀请的任务了
- // var activerewardrec = new this.app.models.ActiveRewardRecord({
- // _id: uuid.v1(), // UUID
- // rewardtype: 0, // 奖励类型,0红包
- // totalfee: 500, // 产生金额,红包为分
- // type:2, //活动类型:1国庆签到2国庆邀请
- // sid: user.id, // 产生奖励的玩家id
- // suid:user.userId, // 产生奖励的玩家userId
- // sname:user.name, // 产生奖励的玩家name
- // rid: user.spreadId,// 此条奖励的受益玩家
- // gameCount: newre.gameCount, // 游戏局数
- // stime: xzsjc, // 记录产生时间
- // succtime: xzsjc, // 任务完成时间,任务未完成的时候这里是0
- // succState: 1 // 任务是否完成的状态,0:未完成1:已达成
- // });
- // yield activerewardrec.saveAsync();
- // }
- // }
- // }
- // }
- // }
- // }
- // let str4 = "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, 'sxjiang_event', { type: M.STATE_CHANGE, data: { chairId: String(user.chairId), state: String(user.state2), state2: String(user.state2) } });
- // 无人在线
- // console.warn("提前结算666");
- //if (this.isOffline()) return this.overTimeAsync(MODE.OFFLINE);
- // console.warn("玩家断线-------定时器启动");
- // 计时结算
- if (!this.endTimer) this.endTimer = this.app.timer.setTimeout(() => this.overTimeAsync(ENDMODE.OFFLINEEND),600000);/////断线10分钟自动结算
- // let str4 = "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, 'sxjiang_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, 'sxjiang_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, 'sxjiang_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, 'sxjiang_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);
- logger.warn(str4);////cssj
- if(this.isYJKSGL){
- return;
- }
- this.isYJKSGL = true;/////是否已经执行过开始函数了
- this.isYJJSGL = false;/////是否已经执行过结算函数了
- if(this.backStartTimer)
- {
- clearTimeout(this.backStartTimer);
- this.backStartTimer = null;
- }
- // 状态设置
- this.state = STATE.PLAYING;
- //this.setUserState(-1, User.STATE.PLAYING);//ts--
- //ts++设置为游戏状态
- for (let user of this.users)
- {
- if (user) {
- if(user.state == User.STATE.PLAYING)//ts++已经开始
- {
- if(user.state2 == User.STATE.READY)
- {
- user.state2 = User.STATE.PLAYING
- user.offlinetime = 0;
- }
- }
- else//ts++第一次开始
- {
- user.state = User.STATE.PLAYING
- user.state2 = User.STATE.PLAYING
- user.offlinetime = 0;
- }
- }
- }
- //ts++end
- let whdata = yield this.app.models.WHstate.findByIdReadOnlyAsync('wh', 'rebaterate yxndlbTime yxndlbTip');
- // console.warn("22检查是否维护状态",whdata);
- if (whdata) {
- if(whdata.yxndlbTime) this.yxndlbTime = whdata.yxndlbTime;
- if(whdata.yxndlbTip) this.yxndlbTip = whdata.yxndlbTip;
- }
- this.PaijuHuiFang = [];////TL++,牌局回放 重置数据
- this.lgkhCount = 0;/////TL++拉杠可胡玩家的数量
- this.logic.isZHYZ = false;/////是不是最后1张
- // this.logic.isNeedBuHua = false/////TL++在游戏开始的时候初始化是否需要补花
- // this.isLianGang = [-1,false,-1];/////TL++,连杠的玩家座位号,是否连杠 在游戏开始的时候清空
- // 初始信息
- if (this.over <= 0) {///////本房间开始的第一局游戏
- this.stime = Date.now();
- // this.chBanker = this.ownerChairid;///////TL++zsyl
- this.chBanker = 0;
- //this.game.cancelDelete(this.id);//////TL++游戏第一次开始时候关闭房间20分钟未开始删除桌子
- this.pjhffileName[this.pjhffileName.length] = this.PJHF.getjsonFileName(0,this.recordid,this.ctime);/////TL++,用于记录玩家牌局回放的json文件名
- // console.error("000HHHHHHHHHHHHHHHHHHHHHH",this.pjhffileName.length,this.pjhffileName);
- this.PJHF.writePJHFJson(this.getTableInfo(),0,this.id);////在开始第一局的时候将桌子信息写入本地的json文件
- this.isNeverStart = false;/////TL++,游戏是否从未开始
- // yield this.randomChangeChairTL()/////TL++,在首次游戏的时候随机打乱用户的座位
- }
- this.gameNeverStart = false;/////TL++,游戏是否从未开始过,用于解散房间判断
- this.currentId = this.chBanker;
- this.isDihus[this.chBanker] = false;
- // 发手牌 把这句提前是为了洗牌之后能拿到百搭牌在游戏开始的时候给客户端发过去
- let dice1 = this.logic.dice();/////骰子1的点数
- let dice2 = this.logic.dice();/////骰子2的点数
- var handCards = this.logic.handCards(this.chBanker,this.PJHF,this.over,this.recordid,this.ctime);
- if(this.playerAllCount == 4){
- if(this.chBanker == 0) this.logic.isMZWF = [0,1,2,3];/////是不是满足位风
- else if(this.chBanker == 1) this.logic.isMZWF = [3,0,1,2];/////是不是满足位风
- else if(this.chBanker == 2) this.logic.isMZWF = [2,3,0,1];/////是不是满足位风
- else if(this.chBanker == 3) this.logic.isMZWF = [1,2,3,0];/////是不是满足位风
- }
- // }
- else if(this.playerAllCount == 3){
- if(this.chBanker == 0) this.logic.isMZWF = [0,1,2,8];/////是不是满足位风
- else if(this.chBanker == 1) this.logic.isMZWF = [3,0,1,8];/////是不是满足位风
- else if(this.chBanker == 2) this.logic.isMZWF = [2,3,0,8];/////是不是满足位风
- }
- else if(this.playerAllCount == 2){
- if(this.chBanker == 0) this.logic.isMZWF = [0,2,8,8];/////是不是满足位风
- else if(this.chBanker == 1) this.logic.isMZWF = [2,0,8,8];/////是不是满足位风
- }
-
- //console.warn("ccccccccccccccccccccc当局的圈风",this.logic.fengQuan,this.chBanker);
- let scoreListTL = []
- for (let i = 0; i < this.users.length; ++i) {
- let user = this.users[i];
- if (user) {
- let score = this.score.getScore(user.id);
- scoreListTL[i] = score
- }
- }
- // 掷骰子
- var sttGame = {
- banker: String(this.chBanker),
- qFeng: String(this.quFeng),
- stime: String(Date.now() - this.stime),
- baiDaCard: String(this.logic.baiDaCard),//////TL++,本局百搭牌
- startNum1: String(dice1),////骰子点数
- startNum2: String(dice2),////骰子点数
- setCardFileName: String(this.logic.setCardFileName),////TL++设置手牌的文件名
- scoreListTL:scoreListTL,/////TL++,每个玩家当前的分数列表
- yxndlbTime:this.yxndlbTime,
- yxndlbTip:this.yxndlbTip,
- };
- // console.warn("游侠开始*******************this.chBanker",this.chBanker);
- this.setPaijuHuiFangData(M.START_GAME,sttGame);/////TL++ 牌局回放 push游戏开始
- // 开始通知
- yield this.pushMsgAsync(-1, 'sxjiang_event', { type: M.START_GAME, data: sttGame });
-
- ////// 发手牌原来在这里
- var lastCount = this.logic.leaveCount();/////TL++
- for (let i = 0; i < handCards.length; ++i) {
- this.handCards[i] = handCards[i].cards;/////TL++zsyl
- if (i == this.chBanker) {
- let __isHu = false;
- let length = this.handCards[i].length;
- this.logic.isLaGang = false;//////TL++,是否刚刚被拉杠用于判断是否被拉杠胡
- // this.logic.chengBaoTL = [[],[],[],[]];
- // console.error("sscc3333胡牌分析 游戏开始i",i);
- let huRes = this.logic.huAnalyze(i,this.handCards[i], this.handCards[i][length - 1], this.huCards[i], true);
- // console.error("ssccDDD胡牌分析 huRes",huRes);
- if (huRes) {
- // let str3a = "table fpphcg:"+this.id + ",uid"+this.handCards[i];
- // logger.info(str3a);////cssj
- __isHu = true;
- this.huRes[i] = huRes;
- }
- let res = this.logic.anGangAnalyze(this.handCards[i]);
- let isGang = (res.length > 0);
- if (isGang) this.masks[i] |= 8;
- if (__isHu) this.masks[i] |= 16;
- }
- let scards = {
- mask: String(this.masks[i]),
- cards: handCards[i].cards,
- lastCount: String(lastCount)
- };
- ////发牌的胡牌提示
- if (i == this.chBanker) {
- ////游戏开始时候的庄家的胡牌提示
- scards.hutipdata = this.logic.hutip(this.chBanker,handCards[i].cards,this.huCards[i],this.huCards,this.outCards);////起手发牌调用胡牌提示
- }
- else{
- ////游戏开始时候的闲家的胡牌提示
- scards.hutipdata = {
- renyi:0,//////是否可胡任意牌,0表示不满足1表示满足
- kehuData:[]/////对象数组,分别表示打哪张可胡哪几张数据
- };
- }
- // 发牌通知
- // console.error("sscc发牌通知 4条应该=================",i,handCards.lengt);
- yield this.pushMsgAsync(i, 'sxjiang_event', { type: M.SEND_CARD, data: scards });
- }
-
- let pjhfsplist = {
- shouPai:this.logic.deepCloneTL(this.handCards),
- maskList:this.logic.deepCloneTL(this.masks),/////TL++,10月28号,为了实现能看到每个玩家的操作
- lastCount:String(this.logic.leaveCount())
- }
- this.setPaijuHuiFangData(M.SEND_CARD,pjhfsplist);/////TL++ 牌局回放 push发牌数据
- // 围观通知
- var cardCounts = _.fill(Array(this.ccount), 0);
- for (let i = 0; i < cardCounts.length; ++i) {
- cardCounts[i] = this.handCards[i].length;
- }
- yield this.lookMsgAsync('sxjiang_event', { type: M.SEND_CARD, data: { cardCounts: cardCounts, lastCount: String(lastCount) } });
- let str3 = "table 222开始游戏---id:"+this.id +","+ this.state;
- logger.warn(str3);////cssj
- return { code: C.OK };
- });
- // 出牌
- proto.outCardAsync = cor(function* (chairId, card) {
- let str3 = "table 出牌---id:"+this.id + " ,uid "+chairId+" this.masks "+ this.masks +" card "+card;
- logger.warn(str3);////cssj
- // console.warn("出牌出剖出牌",chairId,this.buhuaTimeout);///// 您正在补花,请稍后出牌。/////TL++,正在补花的时候不允许玩家出牌
- // if(this.buhuaTimeout) return { code: C.FAILD, msg: C.GAME_BUHUA_ING };
- // 校验顺序
- if (this.currentId != chairId) {
- return { code: C.FAILD, msg: C.TABLE_TURN_ERROR };
- }
- if(this.autoOutTimer)
- {
- clearTimeout(this.autoOutTimer);
- this.autoOutTimer = null;
- }
- this.logic.chuPaiTL()////TL++,统计出牌个数,为了判断天胡和地胡
- // 吃椪杠胡
- var pos = _.findIndex(this.masks, (m, i) => (i != chairId && m > 0));
- if (pos != -1) {
- return { code: C.FAILD, msg: C.TABLE_TURN_ERROR };
- }
- // 删除手牌
- if (!this.logic.remove(this.handCards[chairId], card)) {
- return { code: C.FAILD, msg: C.TABLE_CARD_ERROR };
- }
- if (this.masks[chairId] & 16){
- this.logic.isGuoHuList[chairId][0] = true;/////TL++,设置过胡玩家的是否点击过胡为true 出牌
- let guohudataTL = {
- chairId:chairId,
- msg: "下次摸牌之前将不能胡牌", /////过胡通知
- }
- let isGuoHuList = [[false,0],[false,0],[false,0],[false,0],];
- isGuoHuList[chairId] = this.logic.isGuoHuList[chairId];
- guohudataTL.isGuoHuList = isGuoHuList;
- ////过胡通知
- yield this.pushMsgAsync(chairId, 'sxjiang_event', { type: M.FHGUOHUTIP, data: guohudataTL });
- this.logic.isLaGang = false;//////TL++,是否刚刚被拉杠用于判断是否被拉杠胡
- }
- // 置空权限
- if (this.masks[chairId] > 0) this.masks[chairId] = 0;
- // 置灰的牌
- this.disCards = [];
- // 调整手牌
- this.logic.adjust(this.handCards[chairId]);
- this.outCard = card;
- this.outerId = chairId;
- this.outCards[chairId].push(card);
- // 天胡地胡
- if (this.isTianhu) this.isTianhu = false;
- if (this.isDihus[chairId]) this.isDihus[chairId] = false;
- // 忽略牌
- this.excepts[chairId] = {};
- let sfyrkh = false;//////TL++,是否有人可胡,没有的话海底捞月之后直接结算
- let pjhfsplist = {};
- // 吃碰杠胡
- for (let i = 0; i < this.ccount; ++i) {
- let ocard = { chairId: String(chairId), card: String(card) };
- // 排除自己
- if (i != chairId) {
- ocard.isGuoHuList = [[false,0],[false,0],[false,0],[false,0],]
- let _isChi = false;
- let isPeng = false;
- let isGang = false;
- let __isHu = false;
- do {
- // 检测吃牌
- if (this.hasEat && i == (chairId + 1) % this.ccount && (!this.isZNZM)) {//// 以前是否可吃为可选项 只能自摸情况下不能吃
- let ress = this.logic.chiAnalyze(this.handCards[i], card);
- _isChi = (ress.length > 0);
- }
- // 忽略牌
- if (this.excepts[i][card]) break;/////TL++zsyl.同一圈过碰之后不能再次碰的
- // 检测碰牌
- isPeng = this.logic.isPeng(this.handCards[i], card);
- // 忽略牌
- // if (this.excepts[i][card]) break;/////TL++.为了解决同一圈过碰之后不能再次碰的问题
- let res = this.logic.gangAnalyze(this.handCards[i], card);
- isGang = !!res;
- this.logic.isLaGang = false;//////TL++,是否刚刚被拉杠用于判断是否被拉杠胡
- let huRes = (!this.isZNZM) ? this.logic.huAnalyze(i,this.handCards[i], card, this.huCards[i]) : undefined;
- // console.error("ssccAAA胡牌分析 huRes",huRes);
- if (huRes) {
- // let str3a = "table cpphcg:"+this.id + ",uid"+this.handCards[i];
- // logger.info(str3a);////cssj
- __isHu = true;
- this.huRes[i] = huRes;
- }
- } while (0);
- /////TL++,整个if
- if(this.logic.leaveCount() == 0 && this.logic.isZHYZ){
- if (_isChi) _isChi = false;
- if (isPeng) isPeng = false;
- if (isGang) isGang = false;
- if(__isHu) sfyrkh = true
- }
- // 权限掩码
- if (_isChi) this.masks[i] |= 2;
- if (isPeng) this.masks[i] |= 4;
- if (isGang) this.masks[i] |= 8;
- if (__isHu) this.masks[i] |= 16;
- }
- else{
- let isGuoHuList = [[false,0],[false,0],[false,0],[false,0],];
- isGuoHuList[chairId] = this.logic.isGuoHuList[chairId];
- ocard.isGuoHuList = isGuoHuList;
- }
- ocard.mask = String(this.masks[i]);
- // 出牌通知
- yield this.pushMsgAsync(i, 'sxjiang_event', { type: M.OUT_CARD, data: ocard });
- if (i == chairId) {
- // let pjhfcp = ocard
- // pjhfcp.allMask = this.masks;
- pjhfsplist = {
- shouPai:this.logic.deepCloneTL(this.handCards),
- lastCount:String(this.logic.leaveCount()),
- ocard:this.logic.deepCloneTL(ocard),
- outCards:this.logic.deepCloneTL(this.outCards),
- isGuoHuList:this.logic.deepCloneTL(this.logic.isGuoHuList)
- }
- }
- if(i == (this.ccount - 1)){/////TL++if条件判断,10月28号,为了实现能看到每个玩家的操作
- pjhfsplist.maskList = this.logic.deepCloneTL(this.masks);/////TL++,10月28号,为了实现能看到每个玩家的操作
- this.setPaijuHuiFangData(M.OUT_CARD,pjhfsplist);/////TL++ 牌局回放 push出牌数据
- }
- }
- // 被杠玩家
- this.gangOuter = -1;
- // 围观通知
- yield this.lookMsgAsync('sxjiang_event', { type: M.OUT_CARD, data: { chairId: String(chairId), card: String(card) } });
- // 全无权限
- for (let i = 0; i < this.ccount; ++i) {
- if (this.masks[i] != 0) break;
- // 切换用户
- if (i == this.ccount - 1) {
- // 下家摸牌
- let nextId = (chairId + 1) % this.ccount;
- ///////TL++,整个if,因为海底捞月需要玩家自己去判断要不要摸牌
- // console.warn("000 声剩余声剩余声剩");
- let lastCount = this.logic.leaveCount();/////TL++xg
- this.touchCardAsync(nextId); ///////出牌摸牌
- }
- }
- let str4 = "table end出牌---id:"+this.id + " ,uid "+chairId+" this.masks "+ this.masks +" card "+card;
- logger.warn(str4);////cssj
- return { code: C.OK };
- });
- proto.autoOutCard = cor(function* (moCard) {
- if(this.masks[this.currentId] == 0 && this.everyIsAutoOut[this.currentId] && moCard != this.logic.baiDaCard) {
- //杠后或者选择了自动出牌
- if(!this.autoOutTimer){
- this.autoOutTimer = this.app.timer.setTimeout(() =>
- {
- // console.error("开始定时器=====111 moCard "+moCard);
- if(this.autoOutTimer)
- {
- clearTimeout(this.autoOutTimer);
- this.autoOutTimer = null;
- }
-
- this.outCardAsync(this.currentId,moCard);
-
- }
- , 1100);//各玩家均没有操作的情况下延迟2秒更新杠后两张牌的状态
- }
- }
- return;
- })
- ///////摸牌函数 参数ifGang是否因为杠而摸牌 TL++ 参数isBHMP 是否补花摸牌,为了判断是否花杠杠开 是否最后一张的海底捞月
- proto.touchCardAsync = cor(function* (chairId,ifGang,isBHMP,ishdly) {
- // console.warn("这不会死循环吧",chairId,isBHMP,this.buhuaTimeout);
- // if(this.buhuaTimeout) {
- // clearTimeout(this.buhuaTimeout);
- // this.buhuaTimeout = null;
- // }
-
- // 状态校验
- if (this.state != STATE.PLAYING) return;
- if (this.winner.chs.length > 0 || !this.users[chairId]) return;
- if(this.logic.isGuoHuList[chairId][0]) this.logic.isGuoHuList[chairId][0] = false;/////TL++,设置过胡玩家的是否点击过胡为false; 摸牌
- // 当前顺序
- this.currentId = chairId;
- // 摸牌
- // var moCard = this.logic.moCard();TL++zsyl
- ////TL++
- var moCard = { card: 0 };
- // if(isBHMP) moCard.card = this.logic.buHuaMoDePai;//////TL++,补花摸上的牌
- // else {
- let isG = (ifGang && (ifGang == 1) || (ifGang == 2) || (ifGang == 3))
- // console.warn("<<<<<<<<<",isG,ifGang)
- moCard = this.logic.moCard(isG);
- this.logic.moPaiTL();
- // }
- let moPaiIsCanHu = false;//////TL++,摸牌的人是否可以胡牌
- // 是否流局
- if (moCard.card <= 0) {
- // console.warn("提前结算888");
- yield this.concludeGameAsync(MODE.NOCARD);
- return { code: C.OK };
- }
- let lastCount22 = this.logic.leaveCount();/////TL++xg
- let pjhfsplist = {};
- for (let i = 0; i < this.ccount; ++i) {
- let touchCard = { currentId: String(chairId), touch: '0',lastCount : '0' };
- // console.warn("1111WWWWWWWTTTTTT",i,chairId,moCard.card);
- if (i == chairId) {
- touchCard.touch = String(moCard.card);
- // this.handCards[i].push(moCard.card);/////TL++zsyl
- if(!isBHMP) this.handCards[i].push(moCard.card);/////TL++,因为在补花的时候已经将新发的牌放进手牌里了所以这里不用push
- let __isHu = false;
-
- // console.error("sscc111胡牌分析 摸牌 i",i);
- this.logic.isLaGang = false;//////TL++,是否刚刚被拉杠用于判断是否被拉杠胡
- // this.logic.chengBaoTL = [[],[],[],[]];////别人放弃拉杠之后还没想好要怎么清空,因为不清空也行
- // console.warn("222摸牌的时候设置刚才是否有杠",i,ifGang,this.logic.isGGMG,this.logic.isGGAG,this.logic.isGGFXG);
- let huRes = this.logic.huAnalyze(i,this.handCards[i], moCard.card, this.huCards[i], true);
- // console.error("ssccBBB胡牌分析 huRes",huRes);
- if (huRes) {
- // let str3a = "table mpphcg:"+this.id + ",uid"+this.handCards[i];
- // logger.info(str3a);////cssj
- __isHu = true;
- moPaiIsCanHu = true;/////TL++
- this.huRes[i] = huRes;
- }
- let res = this.logic.anGangAnalyze(this.handCards[i]);
- let isGang = (res.length > 0);
- if (!isGang) {
- res = this.logic.zmGangAnalyze(this.handCards[i], this.huCards[i]);
- isGang = (res.length > 0);
- }
- if (isGang) this.masks[i] |= 8;
- if (__isHu) this.masks[i] |= 16;
- ////摸排时候的摸排玩家的胡牌提示
- let hutipdataTL = this.logic.hutip(i,this.handCards[i],this.huCards[i],this.huCards,this.outCards);////摸牌时调用胡牌提示
- touchCard.hutipdata = hutipdataTL;
- let isGuoHuList = [[false,0],[false,0],[false,0],[false,0],];
- isGuoHuList[chairId] = this.logic.isGuoHuList[chairId];
- touchCard.isGuoHuList = isGuoHuList;
- }
- else {
- this.masks[i] = 0;
- touchCard.hutipdata = {
- renyi:0,//////是否可胡任意牌,0表示不满足1表示满足
- kehuData:[]/////对象数组,分别表示打哪张可胡哪几张数据
- };
- touchCard.isGuoHuList = [[false,0],[false,0],[false,0],[false,0],]
- }
- touchCard.mask = String(this.masks[i]);
- touchCard.lastCount = String(lastCount22);
- this.logic.lastMoPaiChairID = this.currentId;
- // 摸牌通知
- // console.warn("222WWWWWWWTTTTTT",i,chairId,moCard.card);
- yield this.pushMsgAsync(i, 'sxjiang_event', { type: M.TOUCH_CARD, data: touchCard});
-
- if (i == chairId) {
- pjhfsplist = {
- shouPai:this.logic.deepCloneTL(this.handCards),
- lastCount:String(this.logic.leaveCount()),
- touchCard:this.logic.deepCloneTL(touchCard),
- outCards:this.logic.deepCloneTL(this.outCards),
- isGuoHuList:this.logic.deepCloneTL(this.logic.isGuoHuList)
- }
- }
- if(i == (this.ccount - 1)){/////TL++if条件判断,10月28号,为了实现能看到每个玩家的操作
- pjhfsplist.maskList = this.logic.deepCloneTL(this.masks);/////TL++,10月28号,为了实现能看到每个玩家的操作
- this.setPaijuHuiFangData(M.TOUCH_CARD,pjhfsplist);/////TL++ 牌局回放 push摸牌数据
- }
- }
-
- let str3 = "table 摸牌函数id:"+this.id + " ,uid "+chairId+" ,this.masks "+ this.masks +" card "+moCard.card;
- logger.warn(str3);////cssj
- // 围观通知
- yield this.lookMsgAsync('sxjiang_event', { type: M.TOUCH_CARD, data: { currentId: String(chairId),lastCount:String(lastCount22)} });
- yield this.autoOutCard(moCard.card);
- return { code: C.OK };
- });
- // 放弃操作
- proto.giveUpAsync = cor(function* (chairId) {
- let str3 = "table 放弃操作id: "+this.id + " ,uid "+chairId+", this.masks "+ this.masks;
- logger.warn(str3);////cssj
- // 权限掩码
- var mask = this.masks[chairId];
- if (mask <= 0) {
- return { code: C.FAILD, msg: C.TABLE_MASK_ERROR };
- }
- // console.warn("111放弃操作放弃操作放弃操作放弃操作放弃操作chairId,this.masks",chairId,this.masks,(mask & 16));
- if (mask & 16) {////mask = 16~31时结果=16这个if能进去 0~15或者32~47之间结果=0这个if进不去
- // console.warn("放弃操作里设置过胡为true",chairId, this.logic.isLaGang,this.logic.isGuoHuList,this.logic.everyAllTaiShu);
- this.logic.isGuoHuList[chairId][0] = true;/////TL++,设置过胡玩家的是否点击过胡为true 点击过按钮
- let guohudataTL = {
- chairId:chairId,
- msg: "下次摸牌之前将不能胡牌", /////过胡通知
- }
- let isGuoHuList = [[false,0],[false,0],[false,0],[false,0],];
- isGuoHuList[chairId] = this.logic.isGuoHuList[chairId];
- guohudataTL.isGuoHuList = isGuoHuList;
- //////过胡通知
- yield this.pushMsgAsync(chairId, 'sxjiang_event', { type: M.FHGUOHUTIP, data: guohudataTL });
- if(this.logic.leaveCount() > 0){/////TL++
- this.lgkhCount -= 1;/////TL++拉杠可胡玩家的数量
- }
- // console.warn("666拉杠胡%%%%%%%%%%%%%%%%%%%%%%",this.logic.isLaGang);
- }
- // 删除权限
- this.masks[chairId] = 0;
- // 是否自摸
- if (this.currentId == chairId) {
- return { code: C.OK };
- }
- // 忽略牌
- if (this.outCard) {
- let except = this.excepts[chairId];
- except[this.outCard] = this.outCard;
- }
- // 放弃胡牌
- if (mask & 16) {////mask = 16~31时结果=16这个if能进去 0~15或者32~47之间结果=0这个if进不去
- this.logic.isGuoHuList[chairId][0] = true;/////TL++,设置过胡玩家的是否点击过胡为true 点击过按钮(这句没啥用,在这个函数开始的时候设置过了)
- // console.warn("放弃操作里设置过胡为true",chairId, this.isGangHu,this.logic.isGuoHuList);
- let winner = this.winner;
- do {
- // 一炮多响
- if (this.isMHu) {
- let __cHu = _.findIndex(this.masks, (m) => (m & 16));//////
- // console.warn("允许一炮多想 放弃操作放弃操作放弃操作this.isMHu,__cHu",this.isGangHu,this.isMHu,__cHu);
- if (__cHu != -1) break;
- // 有人胡牌
- if (winner.chs.length > 0) {
- // console.warn("允许一炮多想 操作放弃操作放弃操作winner.chs",winner.chs);
- yield this.pushMsgAsync(-1, 'sxjiang_event', { type: M.HU, data: { lead: String(winner.lead), chairIds: winner.chs } });
- // console.warn("提前结算1111");
- yield this.concludeGameAsync(MODE.NORMAL).then(() => ({ code: C.OK }));/////结算游戏
- return { code: C.OK };
- }
- } else {///// 没炮多响
- // console.warn("没炮多想 放弃操作放弃操作放弃操作winner.chs",this.isGangHu,winner.chs);
- // 有人胡牌
- if (winner.chs.length > 0) {
- let dist = (winner.chs[0] - winner.lead + this.ccount) % this.ccount;
- // let __cHu = _.findIndex(this.masks, (m, i) => (m & 16 && (i - winner.lead + this.ccount) % this.ccount < dist));////TL++,zsyl,
- let __cHu = _.findIndex(this.masks, (m, i) => (m & 16));///TL++,以前是上面那句写法,有个问题:0打牌后1,2,3号玩家都能胡,1点胡2点过,3就没有机会选择是否胡牌
- // console.warn("111没炮多想 放弃操作放弃操作放弃操作__cHu",__cHu);
- if (__cHu != -1) break;
- yield this.pushMsgAsync(-1, 'sxjiang_event', { type: M.HU, data: { lead: String(winner.lead), chairIds: winner.chs } });
- // console.warn("提前结算2222");
- yield this.concludeGameAsync(MODE.NORMAL).then(() => ({ code: C.OK }));/////结算游戏
- return { code: C.OK };
- } else {
- let __cHu = _.findIndex(this.masks, (m) => (m & 16));
- // console.warn("111没炮多想 放弃操作放弃操作放弃操作__cHu",__cHu);
- if (__cHu != -1) break;
- }
- }
- // 查找等待
- let cGang = -1
- let cPeng = -1;
- let _cChi = -1;
- // console.warn("这里是啥情况啊",this.masks);
- for (let i = 0; i < this.masks.length; ++i) {
- // if (i == this.currentId || i == chairId) continue;///////TL++zsyl 这种写法会导致拉杠胡的玩家点击过胡之后被拉杠胡的玩家杠不出来的问题
- if (i == chairId) continue;//////TL++,为了解决拉杠胡的玩家点击过胡之后被拉杠胡的玩家杠不出来的问题
- if (this.masks[i] == 9) {
- cGang = i;
- continue;
- }
- if (this.masks[i] == 5) {
- cPeng = i;
- continue;
- }
- if (this.masks[i] == 3) {
- _cChi = i;
- continue;
- }
- }
- // console.warn("2222情况啊",cGang, this.gangType,this.gangCard);
- // 杠碰吃
- if (cGang != -1 && this.gangType > 0 && this.gangCard > 0) {
- // console.warn("这里是放弃操作再次调用 杠 次");
- return this.gangCardAsync(cGang, this.gangCard, this.gangType).then(() => ({ code: C.OK }));
- } else if (cPeng != -1) {
- return this.pengCardAsync(cPeng, this.outCard).then(() => ({ code: C.OK }));
- } else if (_cChi != -1 && this._eatType > 0) {
- return this.eatCardAsync(_cChi, this.outCard, this._eatType).then(() => ({ code: C.OK }));
- }
- } while (0);
- }
- // 放弃杠碰
- if ((mask & 8) || (mask & 4)) {
- let __cHu = _.findIndex(this.masks, (m) => (m & 16));
- if (__cHu == -1) {
- let _cChi = _.findIndex(this.masks, (m) => (m & 3));
- if (_cChi != -1 && this._eatType > 0) {
- return this.eatCardAsync(_cChi, this.outCard, this._eatType).then(() => ({ code: C.OK }));
- }
- }
- }
- // 全无权限
- for (let i = 0; i < this.ccount; ++i) {
- if (this.masks[i] != 0) break;
- // 切换用户
- if (i == this.ccount - 1) {
- // 下家摸牌
- let nextId = (this.currentId + 1) % this.ccount;
- // return this.touchCardAsync(nextId).then(() => ({ code: C.OK }));//////放弃操作引起的摸牌 /////TL++zs
- ///////TL++,整个if,因为海底捞月需要玩家自己去判断要不要摸牌
- // console.warn("222 声剩余声剩余声剩");
- let lastCount = this.logic.leaveCount();/////TL++xg
- return this.touchCardAsync(nextId).then(() => ({ code: C.OK }));//////放弃操作引起的摸牌
- }
- }
- return { code: C.OK };
- });
- // /////TL++,是否进行海底捞月的操作 处理前端海底捞月函数
- proto.haiDiLaoYue = cor(function* (chairId,data) {
- // console.warn("海底捞月海底捞月");
- return { code: C.OK };
- });
- // 杠牌,1-普通杠, 2-暗杠, 3-自摸明杠
- proto.gangCardAsync = cor(function* (chairId, card, type) {
- let str3 = "table 杠牌,id: "+this.id + " ,uid "+chairId+", this.masks "+ this.masks +" ,card "+card;
- logger.warn(str3);////cssj
- // 参数校验
- if (!type && (type < 1 || type > 3)) {
- return { code: C.FAILD, msg: C.GAME_PARAM_ERROR };
- }
- if (type == 1 && card != this.outCard) {
- return { code: C.FAILD, msg: C.GAME_PARAM_ERROR };
- }
- if (type > 1 && this.currentId != chairId) {
- return { code: C.FAILD, msg: C.GAME_PARAM_ERROR };
- }
- if (!(this.masks[chairId] & 8)) {
- return { code: C.FAILD, msg: C.TABLE_MASK_ERROR };
- }
- if(!this.logic.isCanCPB(this.handCards[chairId],Logic.STYLE.GANG,type)){
- return { code: C.FAILD, msg: C.TABLE_NOTONLYBD };
- }
- // 他人可胡
- let __cHu = (type == 2) ? -1 : _.findIndex(this.masks, (m) => ((m & 16) && !(m & 8)));
- // console.warn("111拉杠胡%%%%%%%%%%%%%%%%%%%%%%",__cHu,type);
- if (__cHu == -1) {
- let res = null;
- if (type == 1 || type == 2) {
- res = this.logic.gang(chairId,this.handCards[chairId], card, type);
- } else if (type == 3) {
- res = this.logic.zmGang(chairId,this.handCards[chairId], this.huCards[chairId], card);
- }
- if (!res) {
- return { code: C.FAILD, msg: C.TABLE_GANG_ERROR };
- }
- /////TL++7月17日,这整个if的内容 和else的判断
- let winner = this.winner;
- if (winner.chs.length > 0) {
- yield this.pushMsgAsync(-1, 'sxjiang_event', { type: M.HU, data: { lead: String(winner.lead), chairIds: winner.chs } });
- this.setPaijuHuiFangData(M.HU,{ lead: String(winner.lead), chairIds: winner.chs });/////TL++ 牌局回放 push吃胡牌数据
- // console.warn("提前结算BBB");
- yield this.concludeGameAsync(MODE.NORMAL);
- }
- else{
- // 记录杠牌
- if (type == 1) {
- // 被杠玩家
- this.gangOuter = this.outerId;
- res.origin = this.outerId;
- this.outCards[this.outerId].pop();
- this.huCards[chairId].push(res);
- this.logic.remove(this.handCards[chairId], res.cards);
- } else if (type == 2) {
- // 被杠玩家
- this.gangOuter = -1;
- this.huCards[chairId].push(res);
- this.logic.remove(this.handCards[chairId], [card, card, card, card]);
- this.logic.adjust(this.handCards[chairId]);
- } else if (type == 3) {
- // console.warn("333拉杠胡%%%%%%%%%%%%%%%%%%%%%%",this.logic.isLaGang,this.isGangHu);
- let huCard = _.find(this.huCards[chairId], (o) => {
- return (o.style == Logic.STYLE.PENG && o.cards[0] == card);
- });
- if (!huCard) {
- return { code: C.FAILD, msg: C.TABLE_GANG_ERROR };
- }
- // 被杠玩家
- this.gangOuter = -1;
- // console.warn("拉杠胡%%%%%%%%%%%%%%%%%%%%%%" ,this.isGangHu);
- // 抢杠胡
- if (!this.isGangHu) {
- this.lgkhCount = 0;/////TL++拉杠可胡玩家的数量
- let allowIds = [], otherIds = [];
- for (let i = 0; i < this.ccount; ++i) {
- // 排除自己
- if (i != chairId) {
- this.logic.isLaGang = true;//////TL++,是否刚刚被拉杠用于判断是否被拉杠胡
- // console.error("sscc222胡牌分析 杠牌i",i,this.logic.isLaGang);
- let huRes = this.logic.huAnalyze(i,this.handCards[i], card, this.huCards[i]);
- // console.error("ssccCCC胡牌分析 huRes",huRes);
- // let lg2 = false;///TL++
- if (huRes) {
- // let str3a = "table lgphcg:"+this.id + ",uid"+this.handCards[i];
- // logger.info(str3a);////cssj
- if (!this.isGangHu) this.isGangHu = true;
- //////////TL++,为了记录承包情况,第一个元素表示承包原因 1:海底捞月打出去被胡 2:被人拉杠胡 第二个元素承包的玩家座位号
- // this.logic.chengBaoTL[chairId][this.logic.chengBaoTL[chairId].length] = [2,this.currentId];
- // lg2 = true//////TL++
- this.huRes[i] = huRes;
- this.masks[i] |= 16;
- this.lgkhCount += 1;/////TL++拉杠可胡玩家的数量
- allowIds.push(this.users[i].id); continue;
- }
- }
- // 其他玩家
- otherIds.push(this.users[i].id);
- }
- // 有人可胡
- if (allowIds.length > 0) {
- // 置于等待
- this.masks[chairId] = 9;
- this.gangType = type;
- this.gangCard = card;
- // 抢杠通知
- yield this.pushMsgAsync(otherIds, 'sxjiang_event', { type: M.MASK_HU, data: { mask: '0', card: String(card) } });
- yield this.pushMsgAsync(allowIds, 'sxjiang_event', { type: M.MASK_HU, data: { mask: '16', card: String(card) } });
- // console.warn("抢杠胡同盟会告知",allowIds);
- return { code: C.OK };
- }
- }
- huCard.style = Logic.STYLE.ZMGANG;
- // console.warn("55拉杠胡%%%%%%%%%%%%%%%%%%%%%%",this.logic.isLaGang,this.gangType,this.gangCard = 0);
- this.isGangHu = false;/////TL++,8月28日晚上,为了解决过胡拉杠之后就算自己已经摸牌也不能再次拉杠的问题
- this.logic.remove(this.handCards[chairId], card);
- this.logic.adjust(this.handCards[chairId]);
- }
- // if(this.chBanker == chairId) this.isZJYG = true;////本局庄家是否有杠
- // 清空权限
- this._eatType = 0;
- this.gangType = 0;
- this.gangCard = 0;
- _.fill(this.masks, 0);
- // 总杠次
- this.gonCount += 1;
- // 发送通知
- // console.warn("333 声剩余声剩余声剩");
- let lastCount = this.logic.leaveCount();/////TL++xg
- let pjhfsplist = {
- shouPai:this.logic.deepCloneTL(this.handCards),
- lastCount:lastCount,
- outCards:this.logic.deepCloneTL(this.outCards),
- opData:{ chairId: String(chairId), type: String(type), card: String(card), lastCount: String(lastCount) }
- }
- this.setPaijuHuiFangData(M.GANG,pjhfsplist);/////TL++ 牌局回放 push杠操作数据
- yield this.pushMsgAsync(-1, 'sxjiang_event', { type: M.GANG, data: { chairId: String(chairId), type: String(type), card: String(card), lastCount: String(lastCount) } });
- yield this.touchCardAsync(chairId, type); ///////杠牌摸牌
- }
- } else {
- // 置于等待
- this.masks[chairId] = 9;
- this.gangType = type;
- this.gangCard = card;
- }
- // let str4 = "table222 杠牌,id:"+this.id + ",uid"+chairId+","+ this.state +",card "+card;
- // logger.info(str4);////cssj
- return { code: C.OK };
- });
- // 碰牌
- proto.pengCardAsync = cor(function* (chairId, card) {
- let str3 = "table 碰牌id:%s "+this.id + " ,uid "+chairId+" ,this.masks "+ this.masks +" ,card "+card;
- logger.warn(str3);////cssj
- // 参数校验
- if (card != this.outCard || this.currentId == chairId) {
- return { code: C.FAILD, msg: C.GAME_PARAM_ERROR };
- }
- // 权限校验
- if (!(this.masks[chairId] & 4)) {
- return { code: C.FAILD, msg: C.TABLE_MASK_ERROR };
- }
- if(!this.logic.isCanCPB(this.handCards[chairId],Logic.STYLE.PENG,0)){
- return { code: C.FAILD, msg: C.TABLE_NOTONLYBD };
- }
- // 他人可胡杠
- var cHuGang = _.findIndex(this.masks, (m) => (((m & 16) || (m & 8)) && !(m & 4)));
- // console.warn("碰牌按钮被点击了 他人可胡杠",cHuGang,this.masks);
- if (cHuGang == -1) {
- let res = this.logic.peng(chairId,this.handCards[chairId], card);
- if (!res) {
- return { code: C.FAILD, msg: C.TABLE_PENG_ERROR };
- }
- /////TL++7月17日,这整个if的内容 和else的判断
- let winner = this.winner;
- if (winner.chs.length > 0) {
- yield this.pushMsgAsync(-1, 'sxjiang_event', { type: M.HU, data: { lead: String(winner.lead), chairIds: winner.chs } });
- this.setPaijuHuiFangData(M.HU,{ lead: String(winner.lead), chairIds: winner.chs });/////TL++ 牌局回放 push吃胡牌数据
- // console.warn("提前结算AAA");
- yield this.concludeGameAsync(MODE.NORMAL);
- }
- else{
-
- // 记录碰牌
- res.origin = this.outerId;
- this.outCards[this.outerId].pop();
- this.huCards[chairId].push(res);
- this.logic.remove(this.handCards[chairId], [card, card]);
- // 清空权限
- this._eatType = 0;
- this.gangType = 0;
- this.gangCard = 0;
- _.fill(this.masks, 0);
- // 用户顺序
- this.currentId = chairId;
- for (let i = 0; i < this.ccount; ++i) {
- let pengdata = {////这种一定要声明在for循环里面
- chairId: String(chairId),
- card: String(card)
- }
- if(i == chairId){
- let hutipdataTL = this.logic.hutip(i,this.handCards[i],this.huCards[i],this.huCards,this.outCards);////碰牌调用胡牌提示
- pengdata.hutipdata = hutipdataTL;
- }
- else{
- pengdata.hutipdata = {
- renyi:0,//////是否可胡任意牌,0表示不满足1表示满足
- kehuData:[]/////对象数组,分别表示打哪张可胡哪几张数据
- };
- }
- yield this.pushMsgAsync(i, 'sxjiang_event', { type: M.PENG, data: pengdata });
- }
- let pengdatapg = {////碰的旁观数据
- chairId: String(chairId),
- card: String(card)
- }
- pengdatapg.hutipdata = {
- renyi:0,//////是否可胡任意牌,0表示不满足1表示满足
- kehuData:[]/////对象数组,分别表示打哪张可胡哪几张数据
- };
- yield this.lookMsgAsync('sxjiang_event', { type: M.PENG, data: pengdatapg });////TL++
- ////20200831增加胡牌提示的时候把下面这句换成了上面那一段
- // yield this.pushMsgAsync(-1, 'sxjiang_event', { type: M.PENG, data: { chairId: String(chairId), card: String(card) } });
- let pjhfsplist = {
- shouPai:this.logic.deepCloneTL(this.handCards),
- lastCount:String(this.logic.leaveCount()),
- outCards:this.logic.deepCloneTL(this.outCards),
- opData:{ chairId: String(chairId), card: String(card) }
- }
- this.setPaijuHuiFangData(M.PENG,pjhfsplist);/////TL++ 牌局回放 push碰操作数据
-
- }
- } else {
- // 置于等待
- this.masks[chairId] = 5;
- // 查找等待 TL++下面这一段,为了解决A打出一张牌之后B可吃胡C可碰情况下 C先点碰B点吃会死掉的问题 这是原始代码的重大天然Bug
- let cGang = -1
- let cPeng = -1;
- let _cChi = -1;
- // console.warn("这里是啥情况啊",this.masks);
- for (let i = 0; i < this.masks.length; ++i) {
- // if (i == this.currentId || i == chairId) continue;///////TL++zsyl 这种写法会导致拉杠胡的玩家点击过胡之后被拉杠胡的玩家杠不出来的问题
- if (i == chairId) continue;//////TL++,为了解决拉杠胡的玩家点击过胡之后被拉杠胡的玩家杠不出来的问题
- if (this.masks[i] == 9) {
- cGang = i;
- continue;
- }
- if (this.masks[i] == 5) {
- cPeng = i;
- continue;
- }
- if (this.masks[i] == 3) {
- _cChi = i;
- continue;
- }
- }
- // console.warn("ppppppppppp444 ",chairId,cGang,cPeng,_cChi);
- // console.warn("2222情况啊",cGang, this.gangType,this.gangCard);
- // 杠
- if (cGang != -1 && this.gangType > 0 && this.gangCard > 0) {
- return this.gangCardAsync(cGang, this.gangCard, this.gangType).then(() => ({ code: C.OK }));
- }
- }
- // let str4 = "table 碰牌id:%s"+this.id + ",uid"+chairId+","+ this.state +" card "+card;
- // logger.info(str4);////cssj
- return { code: C.OK };
- });
- // 吃牌,1-@**左吃, 2-*@*中吃, 3-@**右吃
- proto.eatCardAsync = cor(function* (chairId, card, type) {
- let str3 = "table 吃牌id:%s "+this.id + " ,uid "+chairId+" ,this.masks "+ this.masks +",card "+card;
- logger.warn(str3);////cssj
- // 参数校验
- if (!type && (type < 1 || type > 3)) {
- return { code: C.FAILD, msg: C.GAME_PARAM_ERROR };
- }
- if (card != this.outCard) {
- return { code: C.FAILD, msg: C.GAME_PARAM_ERROR };
- }
- // 权限校验
- if (!(this.masks[chairId] & 2)) {
- return { code: C.FAILD, msg: C.TABLE_MASK_ERROR };
- }
- if(!this.logic.isCanCPB(this.handCards[chairId],Logic.STYLE.CHI,type)){
- return { code: C.FAILD, msg: C.TABLE_NOTONLYBD };
- }
- // if(this.logic.isGuoHuList[chairId][0]) this.logic.isGuoHuList[chairId][0] = false;/////TL++,吃牌设置过胡玩家的是否点击过胡为false;
- // 他人可胡杠碰
- var cHuGangPeng = _.findIndex(this.masks, (m) => (((m & 16) || (m & 8) || (m & 4)) && !(m & 2)));
- // console.warn("111他人可胡杠碰",cHuGangPeng);
- if (cHuGangPeng == -1) {
- let res = this.logic.chi(this.handCards[chairId], card, type);
- if (!res) {
- return { code: C.FAILD, msg: C.TABLE_PENG_ERROR };
- }
- /////TL++7月17日,这整个if的内容 和else的判断
- let winner = this.winner;
- // console.warn("222他人可胡杠碰",winner.chs.length);
- if (winner.chs.length > 0) {
- yield this.pushMsgAsync(-1, 'sxjiang_event', { type: M.HU, data: { lead: String(winner.lead), chairIds: winner.chs } });
- this.setPaijuHuiFangData(M.HU,{ lead: String(winner.lead), chairIds: winner.chs });/////TL++ 牌局回放 push吃胡牌数据
- // console.warn("提前结算aaa");
- yield this.concludeGameAsync(MODE.NORMAL);
- }
- else{
- // 记录吃牌
- res.origin = this.outerId;
- this.outCards[this.outerId].pop();
- this.huCards[chairId].push(res);
- if (type == 1) {
- this.logic.remove(this.handCards[chairId], [card + 1, card + 2]);
- } else if (type == 2) {
- this.logic.remove(this.handCards[chairId], [card - 1, card + 1]);
- } else {
- this.logic.remove(this.handCards[chairId], [card - 2, card - 1]);
- }
- // 清空权限
- this._eatType = 0;
- this.gangType = 0;
- this.gangCard = 0;
- _.fill(this.masks, 0);
- // 用户顺序
- this.currentId = chairId;
- // 发送通知
- for (let i = 0; i < this.ccount; ++i) {
- let chidata = {
- chairId: String(chairId),
- type: String(type),
- card: String(card)
- }
- if(i == chairId){
- let hutipdataTL = this.logic.hutip(i,this.handCards[i],this.huCards[i],this.huCards,this.outCards);////吃牌调用胡牌提示
- chidata.hutipdata = hutipdataTL;
- }
- else{
- chidata.hutipdata = {
- renyi:0,//////是否可胡任意牌,0表示不满足1表示满足
- kehuData:[]/////对象数组,分别表示打哪张可胡哪几张数据
- };
- }
- yield this.pushMsgAsync(i, 'sxjiang_event', { type: M.CHI, data: chidata });
- }
- let chidatapg = { ////TL++吃牌旁观数据
- chairId: String(chairId),
- type: String(type),
- card: String(card)
- }
- chidatapg.hutipdata = {
- renyi:0,//////是否可胡任意牌,0表示不满足1表示满足
- kehuData:[]/////对象数组,分别表示打哪张可胡哪几张数据
- };
- yield this.lookMsgAsync('sxjiang_event', { type: M.CHI, data: chidatapg });////TL++吃牌旁观消息
- ////20200901为了增加胡牌提示把下面这一段换成了上面那一段
- // yield this.pushMsgAsync(-1, 'sxjiang_event', { type: M.CHI, data: { chairId: String(chairId), type: String(type), card: String(card) } });
- let pjhfsplist = {
- shouPai:this.logic.deepCloneTL(this.handCards),
- lastCount:String(this.logic.leaveCount()),
- outCards:this.logic.deepCloneTL(this.outCards),
- opData:{ chairId: String(chairId), type: String(type), card: String(card) }
- }
- this.setPaijuHuiFangData(M.CHI,pjhfsplist);/////TL++ 牌局回放 push吃操作数据
-
- }
- } else {
- // 置于等待
- this.masks[chairId] = 3;
- this._eatType = type;
- // 查找等待 TL++下面这一段,为了解决A打出一张牌之后B可吃胡C可碰情况下 C先点碰B点吃会死掉的问题 这是原始代码的重大天然Bug
- let cGang = -1
- let cPeng = -1;
- let _cChi = -1;
- // console.warn("这里是啥情况啊",this.masks);
- for (let i = 0; i < this.masks.length; ++i) {
- // if (i == this.currentId || i == chairId) continue;///////TL++zsyl 这种写法会导致拉杠胡的玩家点击过胡之后被拉杠胡的玩家杠不出来的问题
- if (i == chairId) continue;//////TL++,为了解决拉杠胡的玩家点击过胡之后被拉杠胡的玩家杠不出来的问题
- if (this.masks[i] == 9) {
- cGang = i;
- continue;
- }
- if (this.masks[i] == 5) {
- cPeng = i;
- continue;
- }
- if (this.masks[i] == 3) {
- _cChi = i;
- continue;
- }
- }
- // console.warn("2222情况啊",cGang, this.gangType,this.gangCard);
- // 杠碰吃
- if (cGang != -1 && this.gangType > 0 && this.gangCard > 0) {
- return this.gangCardAsync(cGang, this.gangCard, this.gangType).then(() => ({ code: C.OK }));
- } else if (cPeng != -1) {
- return this.pengCardAsync(cPeng, this.outCard).then(() => ({ code: C.OK }));
- } else if (_cChi != -1 && this._eatType > 0) {
- return this.eatCardAsync(_cChi, this.outCard, this._eatType).then(() => ({ code: C.OK }));
- }
- }
- // let str4 = "table 吃牌id:"+this.id + ",uid"+chairId+","+ this.state +",card "+card;
- // logger.info(str4);////cssj
- return { code: C.OK };
- });
- // 操作是否自动出牌
- proto.autoOutCardAsync = cor(function* (chairId) {
- // console.warn("操作是否自动出牌 "+chairId);
- if(this.everyIsAutoOut[chairId]) this.everyIsAutoOut[chairId] = 0;
- else this.everyIsAutoOut[chairId] = 1;
- return { code: C.OK,isAutoOut:this.everyIsAutoOut[chairId]};
- })
- // 胡牌 处理前端
- proto.succCardAsync = cor(function* (chairId) {
- let str3 = "table 胡牌:%s "+this.id + " ,uid "+chairId+" ,this.masks "+ this.masks;
- logger.warn(str3);////cssj
- // 权限校验
- if (!(this.masks[chairId] & 16)) {
- return { code: C.FAILD, msg: C.TABLE_MASK_ERROR };
- }
- // 删除权限
- this.masks[chairId] = 0;
- // 是否自摸
- let winner = this.winner;
- var isMoHu = (this.currentId == chairId);
- if (isMoHu) {
- winner.chs[0] = chairId;
- yield this.pushMsgAsync(-1, 'sxjiang_event', { type: M.HU, data: { lead: String(winner.lead), chairIds: winner.chs } });
- this.setPaijuHuiFangData(M.HU,{ lead: String(winner.lead), chairIds: winner.chs });/////TL++ 牌局回放 push摸胡牌数据
- // console.warn("提前结算444");
- yield this.concludeGameAsync(MODE.NORMAL);
- } else {
- // 抢杠胡
- if (this.isGangHu) {
- winner.lead = this.currentId;
- // 抢杠牌
- if (this.gangType > 0 && this.gangCard > 0) {
- this.logic.remove(this.handCards[this.currentId], this.gangCard);
- this.masks[this.currentId] = 0;
- this.gangType = 0; this.gangCard = 0;
- }
- } else {
- // 点炮
- winner.lead = this.outerId;
- }
- // 一炮多响
- let __cHu = -1;
- if (this.isMHu) {
- // 胡牌者
- winner.chs.push(chairId);
- // 他人可胡
- __cHu = _.findIndex(this.masks, (m) => ((m & 16)));
- } else {
- // 胡牌者
- if (winner.chs.length <= 0) winner.chs[0] = chairId;
- else {
- let hutype = [];//this.logic.getReasultTypeTL(winner.chs[0],this.huCards[winner.chs[0]],false)
- let hutypenew = []//this.logic.getReasultTypeTL(chairId,this.huCards[chairId],false)
- winner.chs[0] = chairId;
- }
- // 他人可胡
- __cHu = _.findIndex(this.masks, (m, i) => ((m & 16)))
- }
- // console.warn("22局部变量改变全局变量??",winner ,this.winner);
- // console.warn("点击胡按钮",__cHu,this.masks);
- if (__cHu == -1) {
- yield this.pushMsgAsync(-1, 'sxjiang_event', { type: M.HU, data: { lead: String(winner.lead), chairIds: winner.chs } });
- this.setPaijuHuiFangData(M.HU,{ lead: String(winner.lead), chairIds: winner.chs });/////TL++ 牌局回放 push吃胡牌数据
- // console.warn("提前结算555");
- yield this.concludeGameAsync(MODE.NORMAL);
- }
- }
- return { code: C.OK };
- });
- // 结算游戏
- 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;/////是否已经执行过开始函数了
- this.everyIsAutoOut = _.fill(Array(this.ccount), 0);
- // 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,
- trans: 0,//明杠个数
- dark: 0,//暗杠个数
- penggang: 0,//碰杠个数
- isPoChan: 0,
- shiJiKouFen: 0,
- gangfen: 0,
- cardfen: 0,
- jiangma: 0,
- });
- data.hutype = [];//this.logic.getReasultTypeTL(winner.chs[0],this.huCards[winner.chs[0]],true)///////TL++胡牌牌型 胡牌人的chairID
- data.banker = this.chBanker;/////TL++
- data.chengbao = [];
- let isMZJYM = false;//是否满足无红中加一码
- if(winner.chs.length == 1 && this.jiangmaType == 1 && this.hzCount > 0 && this.isWGHZJYM){
- //无红中加1码,规则只能在红中个数大于0而且是159奖码情况下才能勾选
- if(this.handCards[winner.chs[0]].indexOf(51) == -1){
- //有多个赢家的时候无红中加一码不生效
- isMZJYM = true;
- }
- }
- let jiangmaInfo = this.logic.getJiangmaInfo(isMZJYM);
- data.jiangmaList = jiangmaInfo.jiangmaList;
- let jiangmaFen = jiangmaInfo.mafen;
- let yjgs = 0;//赢家个数
- // 计算输赢
- for (let i = 0; i < wins.length; ++i) {
- // 自摸
- let isMoHu = winner.lead == -1;
- // 胡牌者
- if (winner.chs.indexOf(i) != -1) {
- yjgs++;
- // console.warn("结算承包数据",this.logic.chengBaoTL,isMoHu,cbqk);
- if(this.logic.isLaGang){
- //抢杠胡:被抢者替每家输2分
- let lead = winner.lead;
- let sy = 2 * this.cell
- wins.forEach((w, c) => {
- if (c != i) {
- wins[lead].win -= sy;
- wins[i].win += sy;
- wins[lead].cardfen -= sy;
- wins[i].cardfen += sy;
- }
- });
- ////下面这段是计算奖码的分数
- wins.forEach((w, c) => {
- if (c != i) {
- if(c == lead){//////点炮玩家
- wins[lead].win -= jiangmaFen;
- wins[i].win += jiangmaFen;
- wins[lead].jiangma -= jiangmaFen;
- wins[i].jiangma += jiangmaFen;
- }
- }
- });
- }
- else{
- //不是抢杠胡
- if (isMoHu) {
- //自摸每家输2分
- let sy = 2 * this.cell
- wins.forEach((w, c) => {
- if (c != i) {
- w.win -= sy;
- wins[i].win += sy;
- w.cardfen -= sy;
- wins[i].cardfen += sy;
- }
- });
- ////下面这段是计算奖码的分数
- wins.forEach((w, c) => {
- if (c != i) {
- w.win -= jiangmaFen;
- wins[i].win += jiangmaFen;
- w.jiangma -= jiangmaFen;
- wins[i].jiangma += jiangmaFen;
- }
- });
- }
- else {
- //点炮者:给赢家输1分,其他人不输分
- let lead = winner.lead;
- // 点炮出钱
- // if (this.isWOne) {/////TL++zsyl,次判断方式适用于点炮出钱
- let hutype = [];
- let sy = this.cell
- wins.forEach((w, c) => {
- if (c != i) {
- if(c == lead){//////点炮玩家
- w.win -= sy;
- wins[i].win += sy;
- w.cardfen -= sy;
- wins[i].cardfen += sy;
- }
- }
- });
- ////下面这段是计算奖码的分数
- wins.forEach((w, c) => {
- if (c != i) {
- if(c == lead){//////点炮玩家
- wins[lead].win -= jiangmaFen;
- wins[i].win += jiangmaFen;
- wins[lead].jiangma -= jiangmaFen;
- wins[i].jiangma += jiangmaFen;
- }
- }
- });
- }
- }
-
- wins[i].lucky = 1;
- }
- // let str2 = "table 222结算函数---id:"+this.id +"结算模式"+mode
- // logger.info(str2);////cssj
-
- if(!(mode != MODE.NORMAL && this.isHZHG)) {
- // 杠牌 流局了而且勾选荒庄荒杠 的话则不计算杠分
- let gangMul = 0;
- for (let huCard of this.huCards[i]) {
- if (huCard.style == Logic.STYLE.ZMGANG) {
- gangMul += 1;
- wins[i].penggang += 1;
- } else if (huCard.style == Logic.STYLE.ANGANG) {
- gangMul += 2;
- wins[i].dark += 1;
- } else if (huCard.style == Logic.STYLE.GANG){
- //明杠谁点的杠谁付3分
- wins[i].trans += 1;
- wins[huCard.origin].win -= 3 * this.cell;
- wins[i].win += 3 * this.cell;
- wins[huCard.origin].gangfen -= 3 * this.cell;
- wins[i].gangfen += 3 * this.cell;
- }
- }
- if (gangMul > 0) {
- wins.forEach((w, c) => {
- if (c != i) {
- w.win -= gangMul * this.cell;
- wins[i].win += gangMul * this.cell;
- w.gangfen -= gangMul * this.cell;
- wins[i].gangfen += gangMul * this.cell;
- }
- });/////TL++杠牌有赢
- }
- }
- // 手牌
- let cards = { card: 0, groups: [], hands: [] };
- if (wins[i].lucky) {
- cards.card = this.huRes[i].card;
- }
- for (let huCard of this.huCards[i]) {
- cards.groups.push({ style: huCard.style, card: huCard.cards[0] });
- }
- let handCard = this.handCards[i] || [];
- let count = this.mcount - this.huCards[i].length * 3;
- cards.hands = handCard.slice(0, count);
- wins[i].cards = cards;
- }
- // 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];
- else if(this.playerAllCount == 4) shiJiKouFen = [wins[0].win,wins[1].win,wins[2].win,wins[3].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) {
- bjsy[i] = wins[i].win;
- }
- this.sszjDataList[this.sszjDataList.length] = bjsy;
- this.over += 1;// 局数+1
- //ts++
-
- let sszjScore = [];//ts++实时本局成绩
- let sszjAllScore = [];//ts++实时总成绩
- // 记录分数
- for (let i = 0; i < this.ccount; ++i) {
- let user = this.users[i];
- if (user)
- {
- sszjScore[i] = shiJiKouFen[i];
- this.score.writeScore(user.id,shiJiKouFen[i], 1);//设置分数
- sszjAllScore[i] = this.score.getScore(user.id);
- // if(this.gameKindTL == 2) sszjAllScore[i] -=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});
- /////固定庄家,不固定的话解除下面这一段的注释
- // 切换庄家
- if(yjgs == 0){
- //没有赢家,流局了,最后一个摸牌的人坐庄
- this.chBanker = this.logic.lastMoPaiChairID;
- }
- else if(yjgs == 1){
- //只有一个人赢了,谁赢谁做庄
- this.chBanker = winner.chs[0];
-
- }
- else if(yjgs > 1) {
- //一炮多响,放炮的人坐庄
- this.chBanker = winner.lead
- }
- /////TL++,10月9号,为了解决冲刺时前端的玩家分数偶尔会显示负数的bug
- data.playNowScore = [];
- for (let i = 0; i < this.ccount; ++i) {
- let user = this.users[i];
- if (user)
- {
- data.playNowScore[i] = this.score.getScore(user.id);
- }
- }
- // 重置本局
- this.resetRound();
- // 结算通知
- yield this.pushMsgAsync(-1, 'sxjiang_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, 'sxjiang_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, 'sxjiang_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, 'sxjiang_event', { type: M.FEE_CHAT, data: { cost: String(lwcost),schairId: String(schairId), dchairId: String(dchairId), msg: msg } });
- return { code: C.OK };
- });
- //ts++写分 endtype = { 正常: 0,局数完成: 1, 房主解散: 2, 申请解散: 3 ,超时解散: 4 };
- proto.writeResultAsync = cor(function* (endmode) {
- logger.warn("牌局写入-------------- " + this.id );
- // console.warn("ts++---------牌局写入writeResultAsync",this.id);
- let gameCost=0;//游戏消耗
- let giftCost = 0;////道具消耗
- this.etime = Date.now();
- let users = [];
- let localUsers = [];
- var scorers = this.score.getUsers();
- if (scorers.length > 0)
- {
- var scorersSort = _.sortBy(scorers, (i) => i.chairId);
- for (let scorer of scorersSort) {
- gameCost+=this.cost;
- giftCost+=scorer.giftCost;
- let userscore=scorer.score;
- // if(this.gameKindTL == 2) userscore -= 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
- });
- // console.warn("fhmjtable new",fhmjtable);
- yield fhmjtable.saveAsync();
- //下面是记录返利相关的
- if(this.agentId && this.agentRebate>0){
- yield this.lsetReabte.writeReabteInfo(this.agentId,this.etime,this.agentRebate,gameCost,giftCost,this.recordid,localUsers,this.gameId);
- // yield this.lsetReabte.writePlayerCountInfo(this.agentId,this.etime,users,this.cost,this.isGameOk,this.gameId);
- }
- //下面是记录邀请新人按比例送钻这个活动的数据
- if(!this.lconfigCommon) {
- // console.warn("邀请新人送钻石活动 this.lconfigCommon 不存在 "+this.etime);
- this.lconfigCommon = new configCommon(this.app);
- }
- yield this.lconfigCommon.yxActivityAsync(scorers,this.etime);
- // logger.info("战绩写入fhmjtable.saveAsync()--------------",this.id);
- });
- // 结束信息 var endtype = { 局数完成: 1, 主动解散: 2, 断线解散: 3 ,超时解散: 4 };
- proto.endResultAsync = cor(function* (endmode) {
- // console.warn("ts++---------记录信息",this.id);
- let str6 = "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, 'sxjiang_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, 'sxjiang_event', { type: M.TABLE_JIESAN });
- }
-
- if(this.leaveUsers.length>0)
- {
- this.app.timer.setTimeout(() => this.leaveUserTimeAsync(), 100);
- }
- // var gametable = yield this.app.models.GameTable.findByIdAsync(this.recordid, '_id tableNo agentId endMode');
- // if(gametable){
- // gametable.endMode = 1;
- // yield gametable.saveAsync();
- // }
- this.game.deleteTable(this.id);//ts++删除房间
- // let str5 = "table 结束信息22 关闭-id:"+this.id +"结算模式"+endmode;
- // logger.info(str5);////cssj
- }
- else//普通结束
- {
- // let str5 = "table 结束信息 普通结束---id:"+this.id +"结算模式"+endmode
- // logger.info(str5);////cssj
- this.state = STATE.FREE2;
- for (let user of this.users) {
- if (user) user.state2 = User.STATE.FREE;
- }
- }
-
- let str7 = "table end 结束信息---id:%s "+this.id +" 结算模式 "+endmode;
- logger.warn(str7);////cssj
-
- });
- //ts++离开用户退出定时器
- proto.leaveUserTimeAsync = cor(function* () {
- // console.warn("离开用户退出定时器,离开用户数==%d",this.leaveUsers.length);////cssj
- if(this.leaveUsers.length>0)
- {
- let userid = this.leaveUsers[0];
- this.leaveUsers.splice(0, 1);
- let str7 = "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, 'sxjiang_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, 'sxjiang_event', { type: M.TABLE_JIESAN });
- let str6 = "table 请求结束定时器---id: "+this.id +" ,endmode: "+endmode
- logger.warn(str6);////cssj
- yield this.endResultAsync(endmode);//ts++ 房主解散 写分
- });
- // 请求结束
- proto.overTableAsync = cor(function* (user) {
- // console.warn("ts+++++请求结束",user.chairId);
- let str3 = "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, 'sxjiang_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, 'sxjiang_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, 'sxjiang_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, 'sxjiang_event', { type: M.AGREE_END, data: { chairId: String(chairId),time: this.JSFJTime,jsdata:jsdata} });
- let jsFlag = 0;
- for (let i = 0; i < 4; ++i)
- {
- if(this.reqJieSan[i] >=1 )
- {
- jsFlag+=1;
- }
- }
-
- if(jsFlag>=this.ccount || this.JSFJTime<=0)
- {
- if(this.backStartTimer)
- {
- clearTimeout(this.backStartTimer);
- this.backStartTimer = null;
- }
- yield this.pushMsgAsync(-1, 'sxjiang_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 };
- });
|