| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722 |
- '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').paohuzi || {};
- 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 || {};
- // 构造方法
- 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 = 10004;
- this.game = game;
- this.id = id;
- this.recordid = uuid.v1()+'_'+id;//ts++唯一记录
- this.upId = upId;//ts++上局的ID
- this.type = type;
- this.agentId=agentId;
- this.yxndlbTime = yxndlbTime;
- this.yxndlbTip = yxndlbTip;
- var num_cost = 50;
- num_cost =parseInt(COSTS[round]);
- this.other = other;//////TL++全名堂时可选游戏规则,非全名堂时没有可选规则
- console.warn("222创建房间的other",other,this.other," gameKindTL ",gameKindTL," type " ,type,id);
- this.gameKindTL = gameKindTL || 1;//游戏类型 = 1代表全名堂 = 2代表大小子 = 3表示土跑胡
- let otherstr = ""+other;
- this.fengDingValue = parseInt(otherstr[6])*100;////封顶值:0:不封顶,1:封顶100,2:封顶200,3:封顶300
- this.tunshuValue = parseInt(otherstr[5]);////充囤值:0:不充囤,1:充1囤,2:充2囤,3:充3囤,4:充4囤,5:充5囤
- let kexuanstr = " 可选规则: ";//
- if(this.gameKindTL == 1){
- if(parseInt(otherstr[1]) == 1) kexuanstr += " 点灯 ";//(全名堂)
- if(parseInt(otherstr[3]) == 1) kexuanstr += " 有丁 ";
- if(parseInt(otherstr[4]) == 1) kexuanstr += " 有捉小三 ";
- }
- else if(this.gameKindTL == 2){
- if(parseInt(otherstr[1]) == 1) kexuanstr += " 点灯 ";//(大小子)
- }
- this.chouPaiShu = 0;
- if(playerAllCount == 2) {
- if(parseInt(otherstr[2]) == 1) this.chouPaiShu = 20;////抽牌张数:0:不抽牌,1:抽20张牌
- }
- console.warn("游戏人数 抽牌张数 ",playerAllCount,this.chouPaiShu)
- console.warn("游戏类型 = 1代表全名堂 = 2代表大小子 = 3表示土跑胡 "+this.gameKindTL+kexuanstr)
- console.warn("封顶值 "+this.fengDingValue)
- console.warn("充囤值 "+this.tunshuValue)
- 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.everyCPHX = _.fill(Array(this.ccount), 0);//每个玩家的吃碰胡息
- this.everyDongState = _.fill(Array(this.ccount), 0);//每个玩家的钻洞状态,0正常未钻洞,1本局钻洞了,2处于钻洞状态且非本局进洞的,3出洞了
- //(1,2状态下都是钻洞状态赢了没分,用两个状态仅仅是为了减少判断运算量,赢了没赢分之后状态变为3,状态3的玩家在重置本局数据时改为0)
- this.handHXInfos = Array(this.ccount);//手牌的胡息信息列表
- this.users = Array(this.ccount);
- this.chBanker = 0;
- this.moOrChu = 0;//现在是出牌阶段还是摸牌阶段,0表示都不是,1表示摸2表示出,用于点过之后判断应该是摸牌还是落牌,
- this.luo = false;
- this.outCards = logic.fillDeep(Array(this.ccount), []);
- this.outCard = 0;
- this.outerId = -1;
- this.moCard = 0;//TL++,为了实现可碰别人摸的牌
- this.moChair = -1;//TL++,为了实现判断是否自摸
- this.currentId = -1;
- this.isCanOut = false;//是否允许玩家手动出牌
- this.hutipdata = [{kehuData:[]},{kehuData:[]},{kehuData:[]}]//每个人的胡牌提示
- // 包含字,总杠次,保留量
- // 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.hasEHu = true;///!!(type & 8);
- // 一炮多响
- this.isMHu = false;//!!(type & 16);
- // 允许杠胡
- this.hasGHu = true;///!!(type & 32);
- // 权限:16-胡,8-杠,4-碰,2-吃,1-等待,0-无
- this.masks = _.fill(Array(this.ccount), 0);
- this.chiBiArr = {cdpsszs:-1,chi:[],bi1:[],bi2:[]}; //吃l牌时吃比数据
- //吃自己摸的或者别人打出的牌用上面的变量记录,吃上家摸得牌用下面变量记录
- this.chiBiArrxj = {cdpsszs:-1,chi:[],bi1:[],bi2:[]}; //摸牌者下家吃摸牌者摸的牌时吃比数据
- // 等待杠类型,1-普通杠, 2-暗杠, 3-自摸明杠
- this.gangType = 0;
- this.gangCard = 0;
- this.bjsfyjp = false;//本局是否已进牌(庄家起手亮张已放入手中)
- this.sfwhkhqypkc = false;//偎牌玩家是否偎后可胡且有牌可出
- this.dqkthdwj = -1;//当前可提胡的玩家
- this.everysfdycpdt = [true,true,true];//每个玩家是否第一次判断提
- this.bckycpdp = 0;//本次可以吃碰的牌,为了给下面的everyGDCPP赋值
- //过碰可以吃,过吃不能吃,过碰不能碰,打出不能吃碰 (没有过吃可以碰的情况,因为过吃的时候肯定是过碰的,打出牌也不存在被自己碰的情况)
- this.everyGDCPP = [[],[],[]];//本局每个玩家过的吃碰牌,为了实现本局过掉碰此牌 或滑动打出过的牌 之后不可再次碰该牌
- // everyGDCPP的元素item是个数组(如item = [101,1]),说明:item[0]表示牌值,item[1]表示过掉类型,=1表滑动打出,=2表过吃,=3表过碰,=4表过吃碰
- //改成这种结构是为了实现过碰可以吃
- // 抢杠胡、被杠玩家
- this.isGangHu = false;
- this.paoForm = -1;//提供跑的玩家
- // 等待吃类型,1-@**左吃, 2-*@*中吃, 3-@**右吃
- this._eatType = 0;
- this._bi1Type = 0;
- this._bi2Type = 0;
- this.liangZi = 0;//当前的亮子(亮张,即摸上来的放在桌面上的牌)
- this.autoSysTimer = null;//自动系统操作定时器(比如有提必须提有偎必须偎等等操作自动进行定时器)
- this.autoOutTimer = null;
- this.bakuaiTimer = null;//延迟八块定时器
- this.ycMoTimer = null;//延迟摸牌定时器
-
-
- this.everyIsAutoOut = _.fill(Array(this.ccount), 0);
- // 胡牌者
- this.huRes = Array(this.ccount);
- this.winner = { lead: -1, chs: [] };
- this.paoHuQK = [-1,false,0];//这把跑胡情况,为了处理当前可跑不能胡但是跑完之后能胡的情况[可跑胡玩家,是否是跑胡,跑胡的牌]
- // 底分
- this.cell = cell;
- // 围观者
- this.lookers = [];
- //结束时的继线用户
- this.leaveUsers = [];
- // 状态
- this.state = STATE.FREE;
- // 申请结束标记
- this.overFlag = 0;
- this.overTimer = null;
- this.endTableTime = 60;//////TL++,申请解散房间之后60秒之后不操作则认为同意解散
- this.reqJieSan = [-1,-1,-1,-1];/////解散桌子数据,前面为chirid后面为情况-1:未操作 0:拒绝 1:同意 2为解散发起
- //断线 结束定时器
- this.endTimer = null;
- //////以下全为TL++
- /////TL++,补花定时器,防止连续补花太快
- this.PJHF = new paiJuHuiFang();
- // this.buhuaTimeout = null;
- this.backStartTimer = null;//////重入之后系统会自动准备为了解决可能没牌的问题2秒之后才开始游戏
- this.PaijuHuiFang = [];////TL++,牌局回放
- // this.zhyzfgs = [-2,null,null];/////TL++,由于最后一张牌的摸牌被打断所以 用来记录最后一张牌的发牌函数的参数
- // this.isLianGang = [-1,false,-1];/////TL++,连杠的玩家座位号,是否连杠 杠的牌
-
- this.isYJJSGL = false;/////是否已经执行过结算函数了
- this.isYJKSGL = false;/////是否已经执行过开始函数了
- this.JSFJTimeout = null;//解散房间倒计时
- this.JSFJTime = 60;//解散房间倒计时60秒
- this.SQJSTime = null;//申请解散房间的时间,用于计算解散房间倒计时所剩的时间
- this.gameNeverStart = true;//游戏是否从未开始过,用于解散房间判断
- this.pjhffileName = [];//用于记录玩家牌局回放的json文件名
- this.playerPosList = [[],[],[],[]];//记录玩家的位置信息数组
- this.playerAllCount = playerAllCount || 3;//游戏人数 = 2表示2人局 = 3表示3人局
- 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);
-
- // this.logic.getIsHu([209,209,209,109,109,109,202,207,210,101,102,103,104,108,106,107,204,204,108,108],108)
- // this.logic.getIsHu([101,102,103,104,106,108,106,106,106,108,109,109,109,202,204,204,207,209,209,209,210],108)//测试判胡算法 28544915846122574
- // console.warn("??????????????????111");
- // this.logic.getIsHu([101,102,103,104,106,107,105,105,105,108,109,109,109,202,204,204,207,209,209,209,210],209)//测试判胡算法 28544915846122574 28544915846122574 29389340776254542 28544563753537139
- // console.warn("??????????????????222");
- // this.logic.getIsHu([101,102,103,104,106,107,108,108,108,108,109,109,109,202,204,204,207,209,209,209,210],108)//测试判胡算法
- // let ccc = [101,102,103,104,105,106,107,109,109,109,202,204,204,205,205,207,209,209,209,210];
- // let huRes = this.logic.huAnalyze(0,ccc, 108, [], false,false);
- // console.warn("是否可胡 ",JSON.stringify(huRes));
- // let Cards = [101,102,102,102,103,106,106,106,107,108,201,202,202,203,203,205,205,206,206,207,208]
- // let group1 = _.groupBy(Cards, function (n) { return n })
- // console.warn("?????? group1 ",JSON.stringify(group1));
- // let ccvv = group1['101'];
- // console.warn("?????? ccvv ",JSON.stringify(ccvv),ccvv.length);
- // let xx = [[202,207,210],[202,207,210],[102,107,110],[102,107,110],[206,205,204],[104],[105,105],[106,103]];
- // let yy = [ 206, 207, 205, 105, 105 ];
- // this.logic.removes2(xx,yy)
- // console.warn("<<<<<<<<<<<< ",xx);
- };
- // 导出状态
- 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.handHXInfos, null);
- _.fill(this.masks, 0);
- this.chiBiArr = {cdpsszs:-1,chi:[],bi1:[],bi2:[]}; //吃牌时吃比数据
- this.chiBiArrxj = {cdpsszs:-1,chi:[],bi1:[],bi2:[]}; //摸牌者下家吃摸牌者摸的牌时吃比数据
- this.liangZi = 0;//当前的亮子(亮张,即摸上来的放在桌面上的牌)
- this.moOrChu = 0;//现在是出牌阶段还是摸牌阶段,0表示都不是,1表示摸2表示出3表示吃碰杠之后4表示起手发牌之后出牌之前,用于点过之后判断应该是摸牌还是落牌,
- this.luo = false;
- if (this.autoSysTimer) {
- clearTimeout(this.autoSysTimer);
- this.autoSysTimer = null;
- }
- if(this.autoOutTimer)
- {
- clearTimeout(this.autoOutTimer);
- this.autoOutTimer = null;
- }
- if(this.bakuaiTimer){
- clearTimeout(this.bakuaiTimer);
- this.bakuaiTimer = null;
- }
- if(this.ycMoTimer){
- clearTimeout(this.ycMoTimer);
- this.ycMoTimer = null;
- }
- this.everyIsAutoOut = _.fill(Array(this.ccount), 0);
- _.fill(this.huRes, null);
- // this.gonCount = 0;
- this.winner.chs = [];
- this.winner.lead = -1;
- this.paoHuQK = [-1,false,0];//这把跑胡情况,为了处理当前可跑不能胡但是跑完之后能胡的情况[可跑胡玩家,是否是跑胡]
- this.logic.fillDeep(this.huCards, []);
- this.everyCPHX = _.fill(Array(this.ccount), 0);//每个玩家的吃碰胡息
- for (var i = 0; i < this.everyDongState.length; i++) {
- if(this.everyDongState[i] == 1) this.everyDongState[i] = 2;
- if(this.everyDongState[i] == 3) this.everyDongState[i] = 0;
- }
- this.logic.fillDeep(this.outCards, []);
- this.outCard = 0;
- this.outerId = -1;
- this.moCard = 0;//TL++,为了实现可碰别人摸的牌
- this.currentId = -1;
- this.isCanOut = false;//是否允许玩家手动出牌(重置)
- this.hutipdata = [{kehuData:[]},{kehuData:[]},{kehuData:[]}]//每个人的胡牌提示
- this._eatType = 0;
- this._bi1Type = 0;
- this._bi2Type = 0;
- this.gangType = 0;
- this.gangCard = 0;
- this.bjsfyjp = false;//本局是否已进牌(庄家起手亮张已放入手中)
- this.sfwhkhqypkc = false;//偎牌玩家是否偎后可胡且有牌可出
- this.dqkthdwj = -1;//当前可提胡的玩家
- this.everysfdycpdt = [true,true,true];//每个玩家是否第一次判断提
- this.bckycpdp = 0;//本次可以吃碰的牌,为了给下面的everyGDCPP赋值
- this.everyGDCPP = [[],[],[]];//本局每个玩家过的吃碰牌,为了实现本局过掉吃碰此牌之后不可再次吃碰该牌
- this.isGangHu = false;
-
- };
- // 发送消息
- 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代表大小子 = 3表示土跑胡
- playerAllCount: this.playerAllCount,////游戏人数 = 2表示2人局 = 3表示3人局 = 4表示4人局
- other: this.other,
- creatTime : this.ctime,
- nowTime : Date.now(),
- state: this.state,
- isCanOut: this.isCanOut,//是否允许玩家手动出牌
- everyCPHX: this.everyCPHX,//每个玩家的吃碰胡息
- everyDongState: this.everyDongState,//每个玩家的钻洞状态,0正常未钻洞,1钻洞中赢了没分
- dengshuValue: this.logic.dengshuValue,//-1:未勾选点灯规则,>-1:已勾选点灯规则下剩余的灯数,
- 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) {
- let zjlzsfkbh = false;//庄家起手亮子是否可被胡,用于判断发牌之后重入要不要显示亮张,如果可胡则显示庄家起手亮张否则不显示
- if(this.moOrChu == 4){
- zjlzsfkbh = _.findIndex(this.masks, (m) => (m > 0)) != -1;//庄家是否可提
- }
- tableInfo.banker = this.chBanker;
- tableInfo.stime = Date.now() - this.stime;
- tableInfo.currentId = this.currentId;
- tableInfo.moOrChu = this.moOrChu;//现在是出牌阶段还是摸牌阶段,0表示都不是,1表示摸2表示出,用于点过之后判断应该是摸牌还是落牌,
- tableInfo.zjlzsfkbh = zjlzsfkbh;//庄家起手亮子是否可被胡,用于判断发牌之后重入要不要显示亮张,如果可胡则显示庄家起手亮张否则不显示
- tableInfo.liangZi = this.liangZi;//当前的亮子(亮张,即摸上来的放在桌面上的牌)
- tableInfo.lastCount = this.logic.leaveCount();
- tableInfo.isGangHu = this.isGangHu;
- tableInfo.gangCard = this.gangCard;
- //////TL++,游戏过程中重入
- //////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.card, origin: huCard.origin });
- }
- uinfo.huCards = huCards;
- uinfo.outCards = this.outCards[i];
- let handCard = this.handCards[i] || [];
- uinfo.handCount = this.logic.getSPZS(handCard);
- }
- 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.yGDCPP = this.everyGDCPP[chairId];//已过的吃碰牌
- let chiBiArr = {cdpsszs:-1,chi:[],bi1:[],bi2:[]}; //吃牌时吃比数据
- if (this.masks[chairId] & 2) {
- let mpwjdxj = (this.moChair + 1) % this.ccount;//摸牌玩家的下家
- if(this.moOrChu == 1 && mpwjdxj == chairId) chiBiArr = this.chiBiArrxj;
- else chiBiArr = this.chiBiArr; //吃牌时吃比数据
- }
- data.chiBiArr = chiBiArr;
- data.handCards = this.handCards[chairId];
- // console.warn("handHXInfos ",JSON.stringify(this.handHXInfos));
- let handHXInfo = this.logic.deepCloneTL(this.handHXInfos[chairId]);
- // console.warn("handHXInfo==== ",JSON.stringify(handHXInfo));
- data.handHXInfos = handHXInfo;
- // 状态通知
- yield this.pushMsgAsync(-1, 'paohuzi_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, 'paohuzi_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 = {
- kehuData:[]/////对象数组,分别表示打哪张可胡哪几张数据
- };
- if(chairId != -1){
- data.table.hutipdata = this.hutipdata[chairId]//每个人的胡牌提示
- }
- 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, 'paohuzi_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, 'paohuzi_event', { type: M.COST_FEE, data: costdata });
- }
-
- // if (this.isReady()) yield this.pushMsgAsync(this.ownerChairid, 'paohuzi_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 };
- }
- 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, 'paohuzi_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])
- }
- /////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.card, 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, 'paohuzi_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, 'paohuzi_event', { type: M.STAND, data: { chairId: String(chairId) } });
- /////TL++,作坐下的玩家离开桌子之后将他的位置信息从位置列表里面删除
- if(chairId != -1) this.playerPosList[chairId] = [];
- //是否退费
- // 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();
-
- // 退费 钻石记录
- 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++退分-------------------钻石记录");
- }
- }
- else
- {
- if(user.cost==0 && user.spreadId)//ts++推荐人奖励
- {
- ////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);
- }
- });
- // 玩家断线
- 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, 'paohuzi_event', { type: M.STATE_CHANGE, data: { chairId: String(user.chairId), state: String(user.state2), state2: String(user.state2) } });
- // 计时结算
- 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, 'paohuzi_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, 'paohuzi_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, 'paohuzi_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, 'paohuzi_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张
- // 初始信息
- 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;
- var handCards = this.logic.handCards(this.chBanker,this.PJHF,this.over,this.recordid,this.ctime);
- let scoreListTL = []
- for (let i = 0; i < this.users.length; ++i) {
- let user = this.users[i];
- if (user) {
- let score = this.score.getScore(user.id);
- scoreListTL[i] = score
- }
- }
- // 掷骰子
- var sttGame = {
- banker: String(this.chBanker),
- stime: String(Date.now() - this.stime),
- setCardFileName: String(this.logic.setCardFileName),////TL++设置手牌的文件名
- scoreListTL:scoreListTL,/////TL++,每个玩家当前的分数列表
- everyCPHX: this.everyCPHX,//每个玩家的吃碰胡息
- everyDongState: this.everyDongState,//每个玩家的进洞状态
- dengshuValue: this.logic.dengshuValue,//-1:未勾选点灯规则,>-1:已勾选点灯规则下剩余的灯数,
- yxndlbTime:this.yxndlbTime,
- yxndlbTip:this.yxndlbTip,
- };
- // console.warn("游侠开始*******************this.chBanker",this.chBanker);
- this.setPaijuHuiFangData(M.START_GAME,sttGame);/////TL++ 牌局回放 push游戏开始
- // 开始通知
- yield this.pushMsgAsync(-1, 'paohuzi_event', { type: M.START_GAME, data: sttGame });
- var moCard = { card: 0 };
- moCard = this.logic.moCard();
- this.logic.moPaiTL();
- this.liangZi = moCard.card;
- this.moChair = this.chBanker;//TL++,为了实现判断是否自摸
- var lastCount = this.logic.leaveCount();/////TL++
- let fpssfyrkh = false;//发牌时是否有人可胡
- for (let i = 0; i < handCards.length; ++i) {
- let isTouch = (i == this.chBanker);
- let huRes2 = this.logic.huAnalyze(i,handCards[i].cards, moCard.card, this.huCards[i], isTouch,true);
- // console.warn("发牌时这是判断所有玩家是否能胡=== ",i,huRes2,handCards[i].cards);
- if (!huRes2) {
- //庄家的三提五坎判断要在手牌里加入庄家亮张,闲家的三提五坎的判断不能把庄家亮子算在里面
- huRes2 = this.logic.stwkAnalyze(i,handCards[i].cards, moCard.card, this.huCards[i], isTouch,isTouch);
- }
- if (huRes2) {
- this.huRes[i] = huRes2;
- this.masks[i] |= 16;
- let isstwk = false;
- //下面这个if为了实现三提五坎不允许过胡
- if(this.logic.isFPJD()){
- let addzh = this.logic.arr2ToArr1(handCards[i].cards,false);
- if(isTouch){
- addzh = addzh.concat(moCard.card);/////不是自己抓的就把这张牌拼接进手牌中
- addzh = this.logic.sort(addzh);
- }
- let spcards2 = this.logic.groupCards(addzh);
- // console.warn("MMMMM+++++++++++++= ",spcards2,handCards[i].cards);
- if(this.logic.isSANTIWUKAN(spcards2, this.huCards[i],[],[])){
- isstwk = true;
- }
- }
- // console.warn(">>>>>>>>>>>>>. ",isstwk);
- if(!isstwk) this.masks[i] |= 64;
- fpssfyrkh = true;
- }
- }
- this.isCanOut = false;//是否允许玩家手动出牌(发牌)
- for (let i = 0; i < handCards.length; ++i) {
- this.handCards[i] = handCards[i].cards;/////TL++zsyl
- this.handHXInfos[i] = handCards[i].hxinfo;/////TL++zsyl
- let scards = {
- mask: String(this.masks[i]),
- isCanOut: this.isCanOut,//是否允许玩家手动出牌
- touch: moCard.card,
- cards: this.handCards[i],
- hxInfos: this.handHXInfos[i],
- lastCount: String(lastCount)
- };
- // 发牌通知
- // console.error("sscc发牌通知 4条应该=================",i,handCards.lengt);
- yield this.pushMsgAsync(i, 'paohuzi_event', { type: M.SEND_CARD, data: scards });
- }
-
- let pjhfsplist = {
- shouPai:this.logic.deepCloneTL(this.handCards),
- handHXInfos:this.logic.deepCloneTL(this.handHXInfos),
- touch: moCard.card,
- 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.logic.getSPZS(this.handCards[i]);
- }
- let lookerData = { cardCounts: cardCounts, lastCount: String(lastCount), touch: moCard.card };
- yield this.lookMsgAsync('paohuzi_event', { type: M.SEND_CARD, data: lookerData });
- this.moOrChu = 4;//现在是出牌阶段还是摸牌阶段,0表示都不是,1表示摸2表示出3表示吃碰杠之后4表示起手发牌之后出牌之前,用于点过之后判断应该是摸牌还是落牌,
- let str3 = "table 222开始游戏---id:"+this.id +","+ this.state;
- logger.warn(str3);////cssj
- if(!fpssfyrkh){//发牌时是否有人可胡
- let ycsj = 3500;//开始动画1秒,洗牌动画1秒,手牌上移的发牌动画0.5秒,庄家起手亮张的摸牌动画0.5秒,亮张展示时间0.5秒
- this.app.timer.setTimeout(() => this.jinCardAsync(), ycsj);
- }
- return { code: C.OK };
- });
- // 进牌(发牌时庄家亮的那张牌进到庄家手里,仅在没有人胡那张牌或者弃胡之后才会调用这个)
- //type=1时判断玩家提胡操作,type=2时操作这张牌进入庄家手里或庄家提
- proto.jinCardAsync = cor(function* () {
- this.bjsfyjp = true;//本局是否已进牌(庄家起手亮张已放入手中)
- let str3 = "table 进牌---id:"+this.id + " ,uid "+this.chBanker+" card "+this.liangZi;
- logger.warn(str3);////cssj
- //只有发牌时别人都不能胡时这张牌(card)才能进入庄家手里,
- //其余情况任何人摸得任何牌都不会进入任何人手里(可以进入某人的吃碰跑牌里)
- let res = this.logic.addACardToCards(this.handCards[this.chBanker],this.liangZi);
- this.handCards[this.chBanker] = _.cloneDeep(res.handCards);
- this.handHXInfos[this.chBanker] = _.cloneDeep(res.handHXInfos);
-
- //至此是发牌时没有人能胡,下面是判断庄家是否能提,此时不会形成偎牌,庄家亮的那张牌可以和手牌组成坎
- let bankerGangeRes = [];
- let newCards = this.logic.arr2ToArr1(this.handCards[this.chBanker],true);
- bankerGangeRes = this.logic.anGangAnalyze(newCards);
- // console.warn("庄家起手亮张可提的结果 ",bankerGangeRes);
- let isGang = (bankerGangeRes.length > 0);
- if (isGang) this.masks[this.chBanker] |= 8;
- let zjsfkt = _.findIndex(this.masks, (m) => (m & 8));//庄家是否可提
- if(zjsfkt == -1) this.isCanOut = true;//是否允许玩家手动出牌(发牌)
- for (let i = 0; i < this.handCards.length; ++i) {
- let scards = {
- mask: String(this.masks[i]),
- isCanOut: this.isCanOut,//是否允许玩家手动出牌
- touch: this.liangZi,
- };
- // ////发牌的胡牌提示
- if (i == this.chBanker) {
- scards.cards = this.handCards[i];
- scards.hxInfos = this.handHXInfos[i];
- ////游戏开始时候的庄家的胡牌提示
- this.hutipdata[i] = this.logic.hutip(this.chBanker,this.handCards[i],this.huCards[i],this.huCards,this.outCards);//每个人的胡牌提示
- scards.hutipdata = this.hutipdata[i];//起手发牌调用胡牌提示
- }
- else{
- this.hutipdata[i] = this.logic.hutip2(i,this.handCards[i],this.huCards[i],this.huCards,this.outCards);//每个人的胡牌提示
- scards.hutipdata = this.hutipdata[i];//起手发牌调用胡牌提示
- }
- // 进牌通知
- yield this.pushMsgAsync(i, 'paohuzi_event', { type: M.PAOHUZI_JIN, data: scards });
- }
- // 围观通知
- var cardCounts = _.fill(Array(this.ccount), 0);
- for (let i = 0; i < cardCounts.length; ++i) {
- cardCounts[i] = this.logic.getSPZS(this.handCards[i]);
- }
- let lookerData = { cardCounts: cardCounts, isCanOut: this.isCanOut, touch: this.liangZi };
- yield this.lookMsgAsync('paohuzi_event', { type: M.PAOHUZI_JIN, data: lookerData });
- let pjhfsplist = {
- mask: String(this.masks[this.chBanker]),
- touch: this.liangZi,
- cards:this.handCards[this.chBanker],
- hxInfos:this.handHXInfos[this.chBanker],
- }
- this.setPaijuHuiFangData(M.PAOHUZI_JIN,pjhfsplist);/////TL++ 牌局回放 push发牌数据
- if(zjsfkt != -1){
- let gcard = bankerGangeRes[0].card;//this.liangZi;////暗杠可以不传card
- yield this.autoSysOperate(500,zjsfkt,"ti",gcard,bankerGangeRes[0].type);
- }
- return { code: C.OK };
- });
- // 调整牌
- proto.adjustCardAsync = cor(function* (chairId, isfy,card,oldIndex,newIndex) {
- let str3 = "table 调整牌---id:"+this.id + " ,uid "+chairId+" card "+card+" isfy "+isfy+" oldIndex "+ oldIndex +" newIndex "+ newIndex;
- logger.warn(str3);////cssj
- // 调整手牌
- let ylspcount = this.logic.getSPZS(this.handCards[chairId]);//调整前原来手牌数量
- let res = {};
- if (!isfy){//是否复原形式调整牌,若是则不需要传上面那些参数
- res = this.logic.changeRes(this.handCards[chairId],this.handHXInfos[chairId],card,oldIndex,newIndex);
- }
- else{
- res = this.logic.changeRes2(this.handCards[chairId]);
- }
- let ocard = {
- chairId: String(chairId),
- changeRes: res.changeRes,
- };
- if(res.changeRes == 0){
- let xzspcount = this.logic.getSPZS(this.handCards[chairId]);//调整前原来手牌数量
- if(ylspcount == xzspcount){//加这个if是为了防止上面代码执行中手牌发生比如偎提跑导致改变
- this.handCards[chairId] = _.cloneDeep(res.handCards);
- this.handHXInfos[chairId] = _.cloneDeep(res.handHXInfos);
- }
- ocard.cards = this.handCards[chairId];
- ocard.hxInfos = this.handHXInfos[chairId];
- ocard.hutipdata = this.hutipdata[chairId];
- }
- // console.warn("调整牌之后 返回给前端 ",ocard);
- // 调整牌通知
- yield this.pushMsgAsync(chairId, 'paohuzi_event', { type: M.ADJUST_CARD, data: ocard });
- return { code: C.OK };
- });
- // 获得是否允许手动出牌
- proto.getIsCanOut = cor(function* () {
- console.warn("是否允许手动出牌 ",this.isCanOut);
- return {isCanOut: this.isCanOut};
- });
- // 出牌(这个方法仅仅前端滑动出牌时被调用)
- proto.outCardAsync = cor(function* (chairId, card,oldIndex) {
- let str3 = "table 出牌---id:"+this.id + " ,uid "+chairId+" currentId "+ this.currentId+" masks "+ this.masks +" card "+card+" oldIndex "+oldIndex;
- 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;
- }
- // 吃椪杠胡
- var pos = _.findIndex(this.masks, (m, i) => (i != chairId && m > 0));
- if (pos != -1) {
- return { code: C.FAILD, msg: C.TABLE_TURN_ERROR };
- }
- // 删除手牌之后调整手牌
- let scres = this.logic.removeACardByPos(this.handCards[chairId],this.handHXInfos[chairId],card,oldIndex);
- if(scres.changeRes == 0){
- this.handCards[chairId] = _.cloneDeep(scres.handCards);
- this.handHXInfos[chairId] = _.cloneDeep(scres.handHXInfos);
- }
- else{
- return { code: C.FAILD, msg: C.TABLE_CARD_ERROR, changeRes: scres.changeRes };
- }
- this.luo = false;
- this.moOrChu = 2;//现在是出牌阶段还是摸牌阶段,0表示都不是,1表示摸2表示出,用于点过之后判断应该是摸牌还是落牌,
- this.liangZi = card;
- this.isCanOut = false;//是否允许玩家手动出牌(出牌)
- this.logic.chuPaiTL()////TL++,统计出牌个数,为了判断天胡和地胡
- // 置空权限
- if (this.masks[chairId] > 0) this.masks[chairId] = 0;
-
- this.outCard = card;
- this.outerId = chairId;
- this.dqkthdwj = -1;
-
- // 判断出牌里是否有人可杠
- let sfyrkg = false;//是否有人可杠,有人可杠的话就不用判断其他人的吃碰了
- for (let i = 0; i < this.ccount; ++i) {
- // 排除自己
- if (i == chairId || sfyrkg) continue;
- let isGang = false;
- do {
- let res = this.logic.gangAnalyze(this.handCards[i], card);//处理跑牌情况6
- isGang = !!res;
- if(!isGang) {
- let brnewCards = this.logic.arr2ToArr1(this.handCards[i],true);
- let brres = this.logic.zmGangAnalyze3(brnewCards, this.huCards[i],card);//处理跑牌情况5
- if(brres.length == 1){
- res = brres[0];
- isGang = !!res;
- }
- }
- } while (0);
- if (isGang) sfyrkg = true;
- }
- var kgdr = -1;//可杠的人
- var kglx = -1;//可杠类型
- let chiBiArr = {cdpsszs:-1,chi:[],bi1:[],bi2:[]}; //吃牌时吃比数据
- // 判断出牌里别人吃碰杠
- for (let i = 0; i < this.ccount; ++i) {
- // 排除自己
- if (i == chairId) continue;
- let _isChi = false;
- let isPeng = false;
- let isGang = false;
- do {
- // console.warn("出牌忽略牌 走到这里了 this.everyGDCPP ",this.everyGDCPP);
- let cphsfwpkc = this.logic.getSFWPKC(this.handCards[i],this.handHXInfos[i]);//吃碰之后是否无牌可出
- // 忽略牌
- if (!sfyrkg && !cphsfwpkc){/////TL++zsyl.过吃碰之后不能再次吃碰的
- let gdsfkc = this.logic.getIsCanCP(this.everyGDCPP[i],card,1);//过掉是否可吃
- let gdsfkp = this.logic.getIsCanCP(this.everyGDCPP[i],card,2);//过掉是否可碰
- // 检测吃牌
- if (gdsfkc && i == (chairId + 1) % this.ccount) {
- let ress = this.logic.chiAnalyze(this.handCards[i], card);
- _isChi = (ress.length > 0);
- // console.warn("出牌调用判断吃111 ",card,_isChi,ress);
- }
- // 检测碰牌
- if(gdsfkp && this.logic.isPeng(this.handCards[i], card)){
- isPeng = true;//若碰完无牌可出的话将不能碰
- }
- }
- let res = this.logic.gangAnalyze(this.handCards[i], card);//处理跑牌情况6
- // console.warn("判断跑111 ",i,JSON.stringify(this.handCards[i]), card,res);
- isGang = !!res;
- if(isGang) {
- kgdr = i;
- kglx = 1;
- }
- else{
- let brnewCards = this.logic.arr2ToArr1(this.handCards[i],true);
- let brres = this.logic.zmGangAnalyze3(brnewCards, this.huCards[i],card);//处理跑牌情况5
- // console.warn("到这里了嘛???2222 ",i,brres);
- if(brres.length == 1){
- res = brres[0];
- isGang = !!res;
- if(isGang) {
- kgdr = i;
- kglx = 4;
- }
- }
- }
- } while (0);
- // 权限掩码
- if (_isChi && kgdr == -1) {
- chiBiArr = this.logic.getChiBiArr(this.handCards[i], card);
- // console.warn("出牌调用判断吃222 ",chiBiArr);
- if(chiBiArr.chi.length > 0){
- let cdpsszs = chiBiArr.cdpsszs;//要吃的牌手上张数
- if(cdpsszs == 0) this.masks[i] |= 2;
- else if(cdpsszs == 1 && chiBiArr.bi1.length > 0) this.masks[i] |= 2;
- else if(cdpsszs == 2 && chiBiArr.bi1.length > 0 && chiBiArr.bi2.length > 0) this.masks[i] |= 2;
- }
- if(this.masks[i] & 2) this.chiBiArr = chiBiArr; //吃牌时吃比数据
- }
- if (isPeng) this.masks[i] |= 4;
- if (isGang) this.masks[i] |= 8;
- if(this.masks[i] > 0 && (!(this.masks[i] & 8) && !(this.masks[i] & 32))) this.masks[i] |= 64;
- }
- this.everyGDCPP[chairId].push([card,1]);
- let sfqwqx = _.findIndex(this.masks, (m) => (m > 0)) == -1;//是否全无权限
- this.logic.everyCPGS[chairId]++;
- let pjhfsplist = {};
- // 发送出牌消息
- for (let i = 0; i < this.ccount; ++i) {
- let ocard = { chairId: String(chairId), card: String(card) };
- ocard.isGuoHuList = [[false,0],[false,0],[false,0],[false,0]]
- ocard.chiBiArr = {cdpsszs:-1,chi:[],bi1:[],bi2:[]}; //吃牌时吃比数据
- // 排除自己
- if (i != chairId) {
- if((this.masks[i] & 2)){
- ocard.chiBiArr = chiBiArr
- }
- }
- ocard.cards = this.handCards[chairId];
- ocard.hxInfos = this.handHXInfos[chairId];
- if(i == chairId){
- let hutipItem = {kehuData:[]}//每个人的胡牌提示
- for (var x = 0; x < this.hutipdata[chairId].kehuData.length; x++) {
- if(this.hutipdata[chairId].kehuData[x].canTing == card){
- hutipItem.kehuData[0] = this.hutipdata[chairId].kehuData[x];
- hutipItem.kehuData[0].canTing = 100;
- }
- }
- this.hutipdata[chairId] = hutipItem;
- }
- this.logic.updateSYPS(i,[card],this.handCards[i],this.huCards,this.outCards,this.hutipdata[i]);
- ocard.hutipdata = this.hutipdata[i];
- ocard.isCanOut = this.isCanOut;//是否允许玩家手动出牌
- ocard.mask = String(this.masks[i]);
- ocard.yGDCPP = this.everyGDCPP[i];//已过的吃碰牌
- ocard.chiBiArr = chiBiArr;
- // 出牌通知
- yield this.pushMsgAsync(i, 'paohuzi_event', { type: M.OUT_CARD, data: ocard });
- if (i == chairId) {
- // let pjhfcp = ocard
- // pjhfcp.allMask = this.masks;
- pjhfsplist = {
- shouPai:this.logic.deepCloneTL(this.handCards),
- handHXInfos:this.logic.deepCloneTL(this.handHXInfos),
- 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.bckycpdp = 0;//本次可以吃碰的牌,为了给下面的everyGDCPP赋值
- for (let i = 0; i < this.masks.length; ++i) {
- if ((this.masks[i] & 2) || (this.masks[i] & 4)) {
- this.bckycpdp = card;//本次可以吃碰的牌,为了给下面的everyGDCPP赋值
- break;
- }
- }
- // 围观通知
- yield this.lookMsgAsync('paohuzi_event', { type: M.OUT_CARD, data: { chairId: String(chairId), card: String(card) } });
- let str4 = "table end出牌---id:"+this.id + " ,uid "+chairId+" this.masks "+ this.masks +" card "+card;
- logger.warn(str4);////cssj
- if(sfqwqx) {
- // 下家摸牌
- let nextId = (chairId + 1) % this.ccount;
- // console.warn("出牌函数里 这里摸牌 ",nextId);
- this.outCards[chairId].push(card);
- // console.warn("出牌函数里this.outCards[chairId] ",this.outCards[chairId]);
- this.touchCardAsync(nextId); ///////出牌摸牌
- }
- if(kgdr != -1) this.app.timer.setTimeout(() => this.yanchiAsync(3,kgdr,card,kglx), 600);
- return { code: C.OK };
- });
- //系统自动操作
- proto.autoSysOperate = cor(function* (ycsj,chairId,operate,moCard,type) {
- console.error("系统自动操作=====参数 ",ycsj,chairId,operate,moCard,type);
- if (this.autoSysTimer) {
- clearTimeout(this.autoSysTimer);
- this.autoSysTimer = null;
- }
- if(!this.autoSysTimer){
- this.autoSysTimer = this.app.timer.setTimeout(() =>
- {
- if(this.autoSysTimer)
- {
- clearTimeout(this.autoSysTimer);
- this.autoSysTimer = null;
- }
- console.error("系统自动操作=====2222 ",chairId,operate,moCard,type);
- if(operate == "hu") this.succCardAsync(chairId);
- else if(operate == "ti") this.gangCardAsync(chairId,moCard,type);
- }
- , ycsj);//发牌时能胡自动胡,庄家能提自动提
- }
- return;
- })
- //在庄家打出第一张手牌之后,处理闲家手上的所有提,因为庄家的提在进牌函数中已经处理
- //每个闲家每局最多执行1次,因为只有第一次轮到该玩家行动时手上才可能会有因为发牌形成的多个提
- ///////摸牌函数 参数ifGang是否因为杠而摸牌 TL++ 参数isLuo 是否落牌摸牌,用于判断前端动画
- proto.touchCardAsync = cor(function* (chairId) {
- // 状态校验
- if (this.state != STATE.PLAYING) return;
- if (this.winner.chs.length > 0 || !this.users[chairId]) return;
- if(this.ycMoTimer){
- clearTimeout(this.ycMoTimer);
- this.ycMoTimer = null;
- }
- this.isCanOut = false;//是否允许玩家手动出牌(摸牌)
- if(this.logic.isGuoHuList[chairId][0]) this.logic.isGuoHuList[chairId][0] = false;/////TL++,设置过胡玩家的是否点击过胡为false; 摸牌
- this.dqkthdwj = -1;
- // 当前顺序
- this.currentId = chairId;
- this.moChair = chairId;//TL++,为了实现判断是否自摸
- if(this.everysfdycpdt[chairId]){
- //下面是处理起手时非庄家的提
- let qsCards = this.logic.arr2ToArr1(this.handCards[chairId],true);
- let qstres = this.logic.anGangAnalyze(qsCards);//处理提牌情况1
- if(qstres.length > 0){
- let str11 = "table 摸牌函数里面clqssfzjdt id:"+this.id + " ,uid "+chairId+" ,ggs "+ qstres.length;
- logger.warn(str11);////cssj
- this.masks[chairId] |= 8;
- //庄家打牌之后轮到闲家摸牌,在闲家摸牌之前先提掉该玩家手上所有的提
- // return yield this.gangCardAsync(chairId,qstres[0].card,2);
- this.app.timer.setTimeout(() => this.yanchiAsync(3,chairId,qstres[0].card,2), 600);
- return { code: C.OK };
- }
- //处理起手时非庄家的提结束
- }
- // 摸牌
- var moCard = { card: 0 };
- moCard = this.logic.moCard();
- this.logic.moPaiTL();
- let str1 = "table 摸牌函数id:"+this.id + " ,uid "+chairId+" ,this.masks "+ this.masks +" card "+moCard.card;
- logger.warn(str1);////cssj
- let oldLiangzi = this.liangZi;
- this.moOrChu = 1;//现在是出牌阶段还是摸牌阶段,0表示都不是,1表示摸2表示出,用于点过之后判断应该是摸牌还是落牌,
- this.liangZi = moCard.card;//当前的亮子(亮张,即摸上来的放在桌面上的牌)
- let moPaiIsCanHu = false;//////TL++,摸牌的人是否可以胡牌
- this.moCard = moCard.card;
- // 是否流局
- if (moCard.card <= 0) {
- // console.warn("提前结算888");
- yield this.concludeGameAsync(MODE.NOCARD);
- return { code: C.OK };
- }
- let lastCount22 = this.logic.leaveCount();/////TL++xg
- //下面是判断摸牌者的偎跑提胡权限
- let zzpsfgd = this.logic.getIsGuo(this.everyGDCPP[chairId],moCard.card);//这张牌是否过掉过
- let isWei = this.logic.weiAnalyze(this.handCards[chairId],moCard.card, zzpsfgd);
- let zjisGang = null;
- let brisGang = -1;//别人可杠的chairId
- let zjGangType = 0;//这张牌杠的类型
- let zjGangChair = -1;//这张牌杠的玩家
- if(!isWei){
- let zjnewCards = this.logic.arr2ToArr1(this.handCards[chairId],true);
- zjnewCards.push(moCard.card);
- let zjres = this.logic.anGangAnalyze(zjnewCards);//处理提牌情况2
- // console.warn("摸牌函数 zjres ",chairId,moCard.card,JSON.stringify(zjnewCards),JSON.stringify(zjres),zjres.length);
- zjisGang = (zjres.length > 0);
- if (zjisGang) {
- zjGangType = 2;
- zjGangChair = this.currentId;
- }
- else{
- zjres = this.logic.zmGangAnalyze1(zjnewCards, this.huCards[chairId]);//处理提牌情况3
- zjisGang = (zjres.length > 0);
- if (zjisGang) {
- zjGangType = 5;
- zjGangChair = this.currentId;
- }
- }
- }
- else{
- zjGangChair = this.currentId;
- }
-
- if (isWei) this.masks[chairId] |= 32;
- if (zjisGang) this.masks[chairId] |= 8;
- // let zjisHu = false;//摸牌者是否能胡
- // let mpzhuRes = this.logic.huAnalyze(chairId,this.handCards[chairId], moCard.card, this.huCards[chairId], true,true);
- // if (mpzhuRes) {
- // zjisHu = true;
- // }
- // console.warn("摸牌 走到这里了 isWei zjisGang ",isWei,zjisGang,zjGangType);
- // if (_zjisHu) this.masks[chairId] |= 16;
- this.everysfdycpdt[chairId] = false;
-
- // 判断摸牌里别人吃碰杠
- for (let i = 0; i < this.ccount; ++i) {
- let touchCard = { currentId: String(chairId), touch: String(moCard.card),lastCount : '0' };
- let cphsfwpkc = this.logic.getSFWPKC(this.handCards[i],this.handHXInfos[i]);//吃碰之后是否无牌可出
- let __isHu = false;
- if(!isWei){
- // if(!zjisGang || zjGangType == 5){
- //20250301为了解决自己提情况3时别人可胡的bug,把上面那句改成下面这句了
- if(!zjisGang){
- let isTouch = (i == chairId);
- let huRes = this.logic.huAnalyze(i,this.handCards[i], moCard.card, this.huCards[i], isTouch,true);
- if(this.everyDongState[chairId] == 1) huRes = null;
- let isNeedFJCPP = false;//是否需要放进吃碰牌
- if(huRes && this.logic.getMPSSFNP(moCard.card, this.huCards[i],isTouch)){
- // console.warn("这里面是---------判断要不要把判胡的这张牌放进吃碰牌组成跑牌 ",i,huRes);
- for (var kk = 0; kk < huRes.cards.length; kk++) {
- if(huRes.cards[kk].indexOf(moCard.card) != -1){
- if(huRes.hxInfos.styles[kk] == Logic.STYLE.JIAO){
- isNeedFJCPP = true;//为了实现已碰七自己或别人摸到7时可以和自己手上两个柒组成绞牌这种情况的最优解
- break;
- }
- }
- }
- }
- if(!huRes || isNeedFJCPP){
- //这里面是判断当前可跑不能胡但是跑完之后能胡的情况
- let huResFZH = this.logic.paohuAnalyze(i,this.handCards[i], moCard.card, this.huCards[i], isTouch,false);
- if(huResFZH){
- huRes = huResFZH;
- if(this.everyDongState[chairId] == 1) huRes = null;
- if(huRes) this.paoHuQK = [i,true,moCard.card];//这把跑胡情况,为了处理当前可跑不能胡但是跑完之后能胡的情况[可跑胡玩家,是否是跑胡]
- }
- // console.warn("这里面是判断当前可跑不能胡但是跑完之后能胡的情况 ",i,this.paoHuQK);
- }
- // if(isTouch) console.warn("摸牌里判断可胡=========== ",i,moCard.card,this.handCards[i],huRes);
- if (huRes) {
- // let str3a = "table mpphcg:"+this.id + ",uid"+this.handCards[i];
- // logger.info(str3a);////cssj
- __isHu = true;
- this.huRes[i] = huRes;
- }
- if (__isHu) this.masks[i] |= 16;
- // console.warn("这里面是判断当前可跑不能胡但是跑完之后能胡的情况222 ",i,__isHu);
- }
- if(!zjisGang && (!__isHu)){//下面这段是摸牌者不能偎提其他人不可胡时判断跑,如果有跑会在下面自动跑
- let brnewCards = this.logic.arr2ToArr1(this.handCards[i],true);
- brnewCards.push(moCard.card);
- let brres = this.logic.zmGangAnalyze(brnewCards, this.huCards[i]);//处理跑牌情况2和跑牌情况3
- if(brres.length == 1) {
- zjGangType = 3;
- }
- if(brres.length == 0 && i != chairId){
- //上面是用自己碰牌跑别人和自己摸的牌,下面是用自己偎的牌跑别人摸的牌
- brres = this.logic.zmGangAnalyze2(brnewCards, this.huCards[i]);//处理跑牌情况4
- //下面是用自己手上的坎跑别人摸得牌(防止出现自己摸得牌自己要吃别人要碰结果被自己吃走了)
- if(brres.length == 0){
- let brgres = this.logic.gangAnalyze(this.handCards[i], moCard.card);//处理跑牌情况1
- let gsjsfhf = !!brgres;
- if(gsjsfhf){
- brres.push(brgres);
- zjGangType = 1;
- }
- }
- else{
- if(brres.length == 1) {
- zjGangType = 3;
- }
- }
- }
- // console.warn("到这里了嘛???444 ",i,brres);
- if(brres.length > 0){//跑别人摸的牌
- brisGang = i;
- zjGangChair = i;
- if(this.masks[i] & 16 && i == chairId) this.masks[i] = 0;
- this.masks[i] |= 8;
- }
- }
- if(!isWei && !zjisGang && brisGang == -1 && !cphsfwpkc && i != chairId){
- let gdsfkp = this.logic.getIsCanCP(this.everyGDCPP[i],moCard.card,2);//过掉是否可碰
- if(gdsfkp && this.logic.isPeng(this.handCards[i], moCard.card)){//碰别人摸的牌
- this.masks[i] |= 4;//若碰完无牌可出的话将不能碰
- this.masks[i] |= 64;
- }
- }
- }
- }
- // console.warn("摸牌忽略牌 走到这里了 this.everyGDCPP ",this.everyGDCPP);
- //下面是判断摸牌玩家的吃
- let zjcphsfwpkc = this.logic.getSFWPKC(this.handCards[chairId],this.handHXInfos[chairId]);//吃碰之后是否无牌可出
- let chiBiArr = {cdpsszs:-1,chi:[],bi1:[],bi2:[]}; //吃牌时吃比数据
- let gdsfkc = this.logic.getIsCanCP(this.everyGDCPP[chairId],moCard.card,1);//过掉是否可吃
- // console.warn("//////////////////////////000 ",chairId,zjcphsfwpkc , brisGang ,isWei ,zjisGang , gdsfkc);
- // console.warn("//////////////////////////111 ",chairId,this.masks[chairId],(this.masks[chairId] & 8));
- let mpzsfnp = this.logic.getMPZSFNP(moCard.card, this.huCards[chairId]);//摸牌者是否能跑
- if(!zjcphsfwpkc && brisGang == -1 && !isWei && !zjisGang && gdsfkc && !mpzsfnp){
- // console.warn("//////////////////////////???")
- let _isChi = false;
- let ress = this.logic.chiAnalyze(this.handCards[chairId], moCard.card);
- // console.warn("//////////////////////////??? ",ress)
- _isChi = (ress.length > 0);
- if (_isChi) {
- chiBiArr = this.logic.getChiBiArr(this.handCards[chairId], moCard.card);
- if(chiBiArr.chi.length > 0){
- let cdpsszs = chiBiArr.cdpsszs;//要吃的牌手上张数
- if(cdpsszs == 0) this.masks[chairId] |= 2;
- else if(cdpsszs == 1 && chiBiArr.bi1.length > 0) this.masks[chairId] |= 2;
- else if(cdpsszs == 2 && chiBiArr.bi1.length > 0 && chiBiArr.bi2.length > 0) this.masks[chairId] |= 2;
- }
- if(this.masks[chairId] & 2) this.chiBiArr = chiBiArr; //吃牌时吃比数据
- }
- }
- //下面是判断摸牌玩家下家的吃
- let mpwjdxj = (chairId + 1) % this.ccount;//摸牌玩家的下家
- let cphsfwpkcxj = this.logic.getSFWPKC(this.handCards[mpwjdxj],this.handHXInfos[mpwjdxj]);//吃碰之后是否无牌可出
- let chiBiArrxj = {cdpsszs:-1,chi:[],bi1:[],bi2:[]}; //吃牌时吃比数据
- let gdsfkcxj = this.logic.getIsCanCP(this.everyGDCPP[mpwjdxj],moCard.card,1);//过掉是否可吃
- if(!cphsfwpkcxj && brisGang == -1 && !isWei && !zjisGang && gdsfkcxj){
- let _isChi = false;
- let ress = this.logic.chiAnalyze(this.handCards[mpwjdxj], moCard.card);
- _isChi = (ress.length > 0);
- if (_isChi) {
- chiBiArrxj = this.logic.getChiBiArr(this.handCards[mpwjdxj], moCard.card);
- if(chiBiArrxj.chi.length > 0){
- let cdpsszs = chiBiArrxj.cdpsszs;//要吃的牌手上张数
- if(cdpsszs == 0) this.masks[mpwjdxj] |= 2;
- else if(cdpsszs == 1 && chiBiArrxj.bi1.length > 0) this.masks[mpwjdxj] |= 2;
- else if(cdpsszs == 2 && chiBiArrxj.bi1.length > 0 && chiBiArrxj.bi2.length > 0) this.masks[mpwjdxj] |= 2;
- }
- if(this.masks[mpwjdxj] & 2) this.chiBiArrxj = chiBiArrxj; //吃牌时吃比数据
- }
- }
- let pjhfsplist = {};
- // 发送摸牌消息
- for (let i = 0; i < this.ccount; ++i) {
- let touchCard = { currentId: String(chairId), touch: String(moCard.card),lastCount : '0' };
- let xxchiBiArr = {cdpsszs:-1,chi:[],bi1:[],bi2:[]}; //吃牌时吃比数据
- if (i == chairId && (this.masks[i] & 2)) {
- xxchiBiArr = chiBiArr
- }
- else if (i == mpwjdxj && (this.masks[i] & 2)) {
- xxchiBiArr = chiBiArrxj
- }
- if (isWei && i != chairId && !zzpsfgd) touchCard.touch = "100";//为了实现偎牌闷着摸牌
- if(this.masks[i] > 0 && (!(this.masks[i] & 8) && !(this.masks[i] & 32))) this.masks[i] |= 64;
- if(i != chairId && (this.masks[i] & 16)) this.masks[i] |= 64;
- touchCard.isLuo = this.luo;
- this.logic.updateSYPS(i,[oldLiangzi],this.handCards[i],this.huCards,this.outCards,this.hutipdata[i]);
- touchCard.hutipdata = this.hutipdata[i];
- touchCard.isCanOut = this.isCanOut;//是否允许玩家手动出牌
- touchCard.chiBiArr = xxchiBiArr;
- touchCard.mask = String(this.masks[i]);
- touchCard.yGDCPP = this.everyGDCPP[i];//已过的吃碰牌
- touchCard.lastCount = String(lastCount22);
- this.logic.lastMoPaiChairID = this.currentId;
- // 摸牌通知
- // console.warn("222WWWWWWWTTTTTT",i,chairId,moCard.card);
- yield this.pushMsgAsync(i, 'paohuzi_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:222 "+this.id + " ,uid "+chairId+" ,this.masks "+ this.masks +" card "+moCard.card;
- logger.warn(str3);////cssj
- // 围观通知
- let pgData = { currentId: String(chairId),touch: String(moCard.card), isLuo:this.luo,lastCount:String(lastCount22)}
- yield this.lookMsgAsync('paohuzi_event', { type: M.TOUCH_CARD, data: pgData });
- this.bckycpdp = 0;//本次可以吃碰的牌,为了给下面的everyGDCPP赋值
- for (let i = 0; i < this.masks.length; ++i) {
- if ((this.masks[i] & 2) || (this.masks[i] & 4)) {
- this.bckycpdp = moCard.card;//本次可以吃碰的牌,为了给下面的everyGDCPP赋值
- break;
- }
- }
- this.luo = true;
- let zdType = 0;//自动类型
- // 全无权限
- for (let i = 0; i < this.ccount; ++i) {
- if (this.masks[i] != 0) break;
- if (i == this.ccount - 1){
- zdType = 1;
- //玩家对摸的牌全无权限,接下来应该给下个玩家摸牌
- this.outCards[this.currentId].push(this.liangZi);
- // console.warn("放弃函数里this.outCards[chairId] ",this.outCards[chairId]);
- zjGangChair = (this.currentId + 1) % this.ccount;
- }
- }
- if (isWei) zdType = 2;
- else if (zjisGang) zdType = 3;
- else if (brisGang > -1) zdType = 3;
- // console.warn("mopai gang==============",zdType,isWei,zjisGang,zjGangChair,brisGang,zjGangType);
- this.paoForm = -1;//提供跑的玩家
- if(zdType == 3) this.paoForm = chairId;//提供跑的玩家
- if(zdType) this.app.timer.setTimeout(() => this.yanchiAsync(zdType,zjGangChair,moCard.card,zjGangType), 2100);
- return { code: C.OK };
- });
- //延迟执行,在出牌之后有可跑1时和摸牌之后有人偎提跑时调用
- proto.yanchiAsync = cor(function* (type,chairId,card,zjGangType) {
- if(type == 1) return yield this.touchCardAsync(chairId);
- else if(type == 2) return yield this.weiCardAsync(chairId,card);
- else if(type == 3) return yield this.gangCardAsync(chairId,card,zjGangType);
- });
- // 放弃操作
- 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 };
- }
- if (mask & 2) {
- let mpwjdxj = (this.moChair + 1) % this.ccount;//摸牌玩家的下家
- if(this.moOrChu == 1 && mpwjdxj == chairId){
- this.chiBiArrxj = {cdpsszs:-1,chi:[],bi1:[],bi2:[]}; //摸牌者下家吃摸牌者摸的牌时吃比数据
- }
- else{
- this.chiBiArr = {cdpsszs:-1,chi:[],bi1:[],bi2:[]}; //吃牌时吃比数据
- }
- }
-
- // 删除权限
- this.masks[chairId] = 0;
- // 忽略牌 代表每个玩家本局过吃碰的牌
- if ((mask & 2) && (mask & 4)){
- if(this.bckycpdp) this.everyGDCPP[chairId].push([this.bckycpdp,4]);
- }
- else{
- if ((mask & 2)){
- if(this.bckycpdp) this.everyGDCPP[chairId].push([this.bckycpdp,2]);
- }
- if ((mask & 4)){
- if(this.bckycpdp) this.everyGDCPP[chairId].push([this.bckycpdp,3]);
- }
- }
-
- console.warn("放弃 走到这里了 this.everyGDCPP ",this.everyGDCPP);
- // 放弃胡牌
- if (mask & 16) {////mask = 16~31时结果=16这个if能进去 0~15或者32~47之间结果=0这个if进不去
- this.logic.isGuoHuList[chairId][0] = true;/////TL++,设置过胡玩家的是否点击过胡为true 点击过按钮
- let fqdata = {
- chairId:chairId,
- isGuoHuList: this.logic.isGuoHuList[chairId],
- isCanOut: this.isCanOut,
- }
-
- let pjhfghsj = {
- chairId:chairId,
- isGuoHuList: this.logic.deepCloneTL(this.logic.isGuoHuList),
- isCanOut: this.isCanOut,
- }
- // console.warn("放弃操作里设置过胡为true",chairId, this.isGangHu,this.logic.isGuoHuList);
- let winner = this.winner;
- do {
- if(this.paoHuQK[0] == chairId && this.paoHuQK[1]){
- this.paoHuQK = [-1,false,0];//这把跑胡情况,为了处理当前可跑不能胡但是跑完之后能胡的情况[可跑胡玩家,是否是跑胡]
- }
- //下面这段是摸牌者不能偎提其他人过胡时判断跑,如果有跑会在下面自动跑
- if(this.moOrChu == 1){
- let brnewCards = this.logic.arr2ToArr1(this.handCards[chairId],true);
- brnewCards.push(this.liangZi);
- let brres = this.logic.zmGangAnalyze(brnewCards, this.huCards[chairId]);//处理跑牌情况2和跑牌情况3
- if(brres.length == 1) {
- this.gangType = 3;
- }
- if(brres.length == 0){
- //上面是用自己碰牌跑别人和自己摸的牌,下面是用自己偎的牌跑别人摸的牌
- brres = this.logic.zmGangAnalyze2(brnewCards, this.huCards[chairId]);//处理跑牌情况4
- //下面是用自己手上的坎跑别人摸得牌(防止出现自己摸得牌自己要吃别人要碰结果被自己吃走了)
- if(brres.length == 0){
- let brgres = this.logic.gangAnalyze(this.handCards[chairId], this.liangZi);//处理跑牌情况1
- let gsjsfhf = !!brgres;
- if(gsjsfhf){
- brres.push(brgres);
- this.gangType = 1;
- }
- }
- else{
- if(brres.length == 1) {
- this.gangType = 3;
- }
- }
- }
- if(brres.length > 0){//跑别人摸的牌
- this.masks[chairId] = 9;
- this.gangCard = this.liangZi;
- }
- }
- // 有人胡牌
- 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,
- ///TL++,以前是上面那句写法,有个问题:0打牌后1,2,3号玩家都能胡,1点胡2点过,3就没有机会选择是否胡牌
- let __cHu = _.findIndex(this.masks, (m, i) => (m & 16));
- // console.warn("111没炮多想 放弃操作放弃操作放弃操作__cHu",__cHu);
- if (__cHu != -1) break;
- yield this.pushMsgAsync(-1, 'paohuzi_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;//break之后都后面的代码就不执行了
- }
- // console.warn("这里是啥情况啊---222 ",mask)
- // 查找等待
- 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);
- let sfqsfpjd = this.logic.isFPJD();//是否起手发牌阶段
- // console.warn("放弃操作 sfqsfpjd ",chairId, sfqsfpjd);
- // 杠碰吃
- if (cGang != -1 && this.gangType > 0 && this.gangCard > 0) {
- // console.warn("这里是放弃操作再次调用 杠 次",cGang, this.gangCard, this.gangType);
- return this.gangCardAsync(cGang, this.gangCard, this.gangType).then(() => ({ code: C.OK }));
- } else if (cPeng != -1) {
- // console.warn("到这里了吗???? ",cPeng,this.moOrChu,this.moCard,this.outCard,this.liangZi);
- if(this.moOrChu == 1){
- return this.pengCardAsync(cPeng, this.liangZi).then(() => ({ code: C.OK }));
- }
- return this.pengCardAsync(cPeng, this.outCard).then(() => ({ code: C.OK }));
- } else if (_cChi != -1 && this._eatType > 0) {
- if(this.moOrChu == 1){
- return this.eatCardAsync(_cChi, this.liangZi, this._eatType,this._bi1Type,this._bi2Type).then(() => ({ code: C.OK }));
- }
- return this.eatCardAsync(_cChi, this.outCard, this._eatType,this._bi1Type,this._bi2Type).then(() => ({ code: C.OK }));
- } else if (sfqsfpjd && !this.bjsfyjp){//本局是否已进牌(庄家起手亮张已放入手中)) {
- return this.jinCardAsync().then(() => ({ code: C.OK }));
- }
- else {
- // console.warn("????????????????================= ",this.dqkthdwj);
- if(this.dqkthdwj == chairId) {
- this.isCanOut = true;//是否允许玩家手动出牌(提后可胡点过)
- fqdata.isCanOut = this.isCanOut;
- pjhfghsj.isCanOut = this.isCanOut;
- this.dqkthdwj = -1;
- yield this.pushMsgAsync(chairId, 'paohuzi_event', { type: M.GIVE_UP, data:fqdata });
- this.setPaijuHuiFangData(M.GIVE_UP,pjhfghsj);/////TL++ 牌局回放 push过牌数据
- return { code: C.OK };
- }
- }
- } while (0);
- yield this.pushMsgAsync(chairId, 'paohuzi_event', { type: M.GIVE_UP, data:fqdata });
- this.setPaijuHuiFangData(M.GIVE_UP,pjhfghsj);/////TL++ 牌局回放 push过牌数据
- }
- // 放弃杠碰
- if ((mask & 8) || (mask & 4) || (mask & 2)) {
- 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) {
- if(this.moOrChu == 1){
- return this.eatCardAsync(_cChi, this.liangZi, this._eatType,this._bi1Type,this._bi2Type).then(() => ({ code: C.OK }));
- }
- return this.eatCardAsync(_cChi, this.outCard, this._eatType,this._bi1Type,this._bi2Type).then(() => ({ code: C.OK }));
- }
- }
- }
- // console.warn("table 放弃 到这里了?? ",this.masks,this.moOrChu,this.sfwhkhqypkc);
- // console.warn("table 放弃 到这里了?? ",this.masks,this.moOrChu,this.sfwhkhqypkc);
- // 全无权限
- for (let i = 0; i < this.ccount; ++i) {
- if (this.masks[i] != 0) break;
- // 切换用户
- if (i == this.ccount - 1) {
- if(this.sfwhkhqypkc) {
- this.sfwhkhqypkc = false;//偎牌玩家是否偎后可胡且有牌可出
- return { code: C.OK };
- }
- //玩家对打出的牌点过至全无权限,接下来应该给下个玩家摸牌
- this.outCards[this.currentId].push(this.liangZi);
- // console.warn("放弃函数里this.outCards[chairId] ",this.outCards[chairId]);
- let nextId = (this.currentId + 1) % this.ccount;
- 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-跑1跑6, 2-提牌情况1和2, 3-跑2跑3跑4, 4-跑牌情况5, 5-提牌情况3
- proto.gangCardAsync = cor(function* (chairId, card, type) {
- let str3 = "table 杠牌,id: "+this.id + " ,uid "+chairId+", this.masks "+ this.masks +" ,card "+card+" ,type "+type+" ,currentId "+this.currentId+" ,everysfdycpdt "+this.everysfdycpdt;
- logger.warn(str3);////cssj
- // 参数校验
- if (!type || (type < 1 || type > 5)) {
- 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 == 2) && this.currentId != chairId) {
- return { code: C.FAILD, msg: C.GAME_PARAM_ERROR };
- }
- if (type == 3 && !card) {
- return { code: C.FAILD, msg: C.GAME_PARAM_ERROR };
- }
- if (!(this.masks[chairId] & 8)) {
- return { code: C.FAILD, msg: C.TABLE_MASK_ERROR };
- }
- let sfltlg = false;//是否连提两个,用于判断是否需要进子
- // 他人可胡
- let __cHu = (type == 2) ? -1 : _.findIndex(this.masks, (m) => ((m & 16) && !(m & 8)));
- let gwjsfdyct = this.everysfdycpdt[chairId];//该玩家是否第一次提
- // console.warn("111拉杠胡%%%%%%%%%%%%%%%%%%%%%%",__cHu,type,gwjsfdyct);
- if (__cHu == -1) {
- let res = null;
- if (type == 1 || type == 2 || type == 4 || type == 5) {
- if(this.everysfdycpdt[chairId]){//是否第一次判断提,因为每局没判断过提或者没摸过牌的话第一次判断提可能会有多个提
- res = this.logic.gang2(chairId,this.handCards[chairId],this.huCards[chairId], card, type);
- if(res.length >= 2) sfltlg = true;//是否连提两个,用于判断是否需要进子
- if(res.length == 0) res = null;
- }
- else{
- res = this.logic.gang(chairId,this.handCards[chairId],this.huCards[chairId], card, type);
- }
- } else if (type == 3) {
- let zjnewCards = this.logic.arr2ToArr1(this.handCards[chairId],true);
- zjnewCards.push(card);
- res = this.logic.zmGang(chairId,zjnewCards, this.huCards[chairId], card);
- }
- // console.warn("走到这里了嘛??????????????",res,this.handCards[chairId], this.huCards[chairId]);
- 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) {
- // console.warn("gang ??????????????????111 ",winner);
- yield this.pushMsgAsync(-1, 'paohuzi_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{
- // console.warn("gang ??????????????????222 ",type,this.currentId);
- // 记录杠牌
- if (type == 1) {// 明杠
- res.origin = this.outerId;
- // this.outCards[this.outerId].pop();
- if(this.everysfdycpdt[chairId]){
- this.huCards[chairId].push(res[0]);
- }
- else{
- this.huCards[chairId].push(res);
- }
- let yscdsz = [card, card, card];
- let scspRes = this.logic.removes2(this.handCards[chairId], yscdsz);//删除手牌结果
- this.handCards[chairId] = _.cloneDeep(scspRes.handCards);
- this.handHXInfos[chairId] = _.cloneDeep(scspRes.handHXInfos);
- } else if (type == 2) {// 暗杠
- // console.warn("gang ??????????????????333 ",type);
- if(this.everysfdycpdt[chairId]){
- // console.warn("起手发牌的时候 ",this.logic.moPaiCountTL,res);
- for (var i = 0; i < res.length; i++) {
- this.huCards[chairId].push(res[i]);
- let yscdsz = [res[i].cards[0], res[i].cards[0], res[i].cards[0], res[i].cards[0]];//要删除的数组
- // console.warn("要删除的数组 ",yscdsz);
- let scspRes = this.logic.removes2(this.handCards[chairId], yscdsz);//删除手牌结果
- this.handCards[chairId] = _.cloneDeep(scspRes.handCards);
- this.handHXInfos[chairId] = _.cloneDeep(scspRes.handHXInfos);
- }
-
- }
- else{
- this.huCards[chairId].push(res);
- let yscdsz = [card, card, card];
- let scspRes = this.logic.removes2(this.handCards[chairId], yscdsz);//删除手牌结果
- this.handCards[chairId] = _.cloneDeep(scspRes.handCards);
- this.handHXInfos[chairId] = _.cloneDeep(scspRes.handHXInfos);
- }
-
- // this.logic.remove(this.handCards[chairId], [card, card, card, card]);
- // this.logic.adjust(this.handCards[chairId]);
- } else if (type == 3) {// 自摸明杠 跑牌情况2:当别人从墩上摸得牌,是自己已经碰的牌
- let huCard = _.find(this.huCards[chairId], (o) => {
- return (o.style == Logic.STYLE.PENG && o.cards[0] == card);
- });
- if (!huCard) {
- huCard = _.find(this.huCards[chairId], (o) => {
- return (o.style == Logic.STYLE.WEI && o.cards[0] == card);
- });
- }
- if (!huCard) {
- return { code: C.FAILD, msg: C.TABLE_GANG_ERROR };
- }
- // console.warn("拉杠胡%%%%%%%%%%%%%%%%%%%%%%" ,this.isGangHu);
- huCard.style = Logic.STYLE.ZMGANG;
- if(huCard.cards.length == 3) huCard.cards.push(card);
- this.isGangHu = false;/////TL++,8月28日晚上,为了解决过胡拉杠之后就算自己已经摸牌也不能再次拉杠的问题
- } else if (type == 4) {// 跑牌情况5:当别人滑动手牌打出的牌,是自己已经偎的牌
- let huCard = _.find(this.huCards[chairId], (o) => {
- return (o.style == Logic.STYLE.WEI && o.cards[0] == card);
- });
- if (!huCard) {
- return { code: C.FAILD, msg: C.TABLE_GANG_ERROR };
- }
- huCard.style = Logic.STYLE.ZMGANG;
- if(huCard.cards.length == 3) huCard.cards.push(card);
- } else if (type == 5) {// 提牌情况3:自己摸上来的牌是自己已经“偎牌”的牌
- let huCard = _.find(this.huCards[chairId], (o) => {
- return (o.style == Logic.STYLE.WEI && o.cards[0] == card);
- });
- if (!huCard) {
- return { code: C.FAILD, msg: C.TABLE_GANG_ERROR };
- }
- huCard.style = Logic.STYLE.ANGANG;
- if(huCard.cards.length == 3) huCard.cards.push(card);
- }
- this.everyCPHX[chairId] = this.logic.getCPHX(this.huCards[chairId]);
- // 清空权限
- this._eatType = 0;
- this._bi1Type = 0;
- this._bi2Type = 0;
- this.gangType = 0;
- this.gangCard = 0;
- _.fill(this.masks, 0);
- // 总杠次
- // this.gonCount += 1;
- let otherCards = [];//起手发牌阶段的暗杠可能会有好几个
- if(this.everysfdycpdt[chairId] && res && res.length >= 2){
- for (var i = 0; i < res.length; i++) {
- if(card == res[i].cards[0]) continue;
- otherCards.push(res[i].cards[0]);
- }
- }
- this.currentId = chairId;
- let gwjsfjz = this.logic.isNeedJinZi(this.handCards[chairId],this.huCards[chairId]);//该玩家是否需要进子
- //下面判断&& !this.everysfdycpdt[chairId] 是因为闲家起手两个提,在庄家出牌之后闲家连提2个(八块)之后需要给这个玩家摸牌,
- if(gwjsfjz && !this.logic.isFPJD() && !this.everysfdycpdt[chairId]){//庄家必须出一张牌
- let nextId = (this.currentId + 1) % this.ccount;
- this.currentId = nextId;
- }
- let phktdp = 0;//该玩家跑后可提的牌
- if(type == 1 && this.everysfdycpdt[chairId]){
- //下面是处理起手时非庄家的提
- let qsCards = this.logic.arr2ToArr1(this.handCards[chairId],true);
- let qstres = this.logic.anGangAnalyze(qsCards);
- if(qstres.length > 0){
- this.masks[chairId] |= 8;
- //庄家打牌之后轮到闲家摸牌,在闲家摸牌之前先提掉该玩家手上所有的提
- phktdp = qstres[0].card;
- }
- //处理起手时非庄家的提结束
- }
- this.everysfdycpdt[chairId] = false;//=========
- if(phktdp) this.everysfdycpdt[chairId] = true;
- let huRes = null;
- // console.warn("下面是刚里面判jindong ",chairId,this.everyDongState[chairId]);
- // if(this.everyDongState[chairId] != 1) {
- let isTouch = false;
- if(type == 1) isTouch = false;
- if(type == 2) isTouch = true;
- else isTouch = chairId == this.paoForm;//提供跑的玩家
- //本局钻洞了本局就不能胡了
- // console.warn("下面是刚里面判胡 ",chairId,this.handCards[chairId]);
- huRes = this.logic.huAnalyze(chairId,this.handCards[chairId], card, this.huCards[chairId], isTouch,false);
- if(type == 1 && this.moOrChu == 2) huRes = null;//加这句是为了实现闲家(手牌有208的坎和一对)不能胡发牌后庄家打出的208
- if(type == 4) huRes = null;//加这句是为了实现不能胡别人打出的(比如自己偎102之后不能胡别人打出的102)
- if(this.everyDongState[chairId] == 1) huRes = null;
- // console.warn("加这句是为了防止跑之后还能胡过-------------------- ",type,this.moOrChu);
- //加这句是为了防止可跑可胡时点过胡之后自动跑之后还提示胡过
- if(type == 1 || type == 3) huRes = null;//加这句是为了防止可跑可胡时点过胡之后自动跑之后还提示胡过
- // (type=1时的跑1情况在摸牌函数里进行判胡了,走到这里来是已经在别人摸牌时候点过胡之后开始自动跑完到这里)
- // (type=1时的跑6情况在上面已经判断过了不能胡别人打出的)
- // (type=3表示的跑2跑3跑4和和type=1的跑1情况一样,在摸牌函数里进行的是否可胡判断)
-
- // }
- if (huRes) {
- this.huRes[chairId] = huRes;
- this.masks[chairId] |= 16;
- let isstwk = false;
- if(this.logic.isFPJD()){
- if(this.logic.isSANTIWUKAN(this.handCards[chairId], this.huCards[chairId],[],[])){
- isstwk = true;
- }
- }
- if(!isstwk){
- this.masks[chairId] |= 64;
- if(type == 2 || type == 5) this.dqkthdwj = chairId;
- }
- // yield this.autoSysOperate(600,chairId,"hu",card);
- }
-
- // 发送通知
- // console.warn("gang this.huCards[chairId]",phktdp,this.huCards[chairId]);
- let lastCount = this.logic.leaveCount();/////TL++xg
- this.isCanOut = true;//是否允许玩家手动出牌(杠牌)
- if(phktdp || huRes){//跑后可提胡
- this.isCanOut = false;//是否允许玩家手动出牌(杠牌)
- }
- for (let i = 0; i < this.ccount; ++i) {
- let gangData = {
- chairId: String(chairId),
- currentId: this.currentId,
- mask: String(this.masks[i]),
- isCanOut: this.isCanOut,//是否允许玩家手动出牌
- everyCPHX: this.everyCPHX,//每个玩家的吃碰胡息
- type: String(type),
- card: String(card),
- otherCards: _.cloneDeep(otherCards),
-
- }
- if(i == chairId){
- gangData.cards = this.handCards[chairId];
- gangData.hxInfos = this.handHXInfos[chairId];
- if(this.logic.isXYBCP(this.handCards[i],this.huCards[i])){
- this.hutipdata[i] = this.logic.hutip2(i,this.handCards[i],this.huCards[i],this.huCards,this.outCards);////杠牌调用胡牌提示
- }
- else {
- this.hutipdata[i] = this.logic.hutip(i,this.handCards[i],this.huCards[i],this.huCards,this.outCards);////杠牌调用胡牌提示
- }
- gangData.hutipdata = this.hutipdata[i];
- let pjhfsplist = {
- shouPai:this.logic.deepCloneTL(this.handCards),
- everyCPHX: this.everyCPHX,//每个玩家的吃碰胡息
- handHXInfos:this.logic.deepCloneTL(this.handHXInfos),
- outCards:this.logic.deepCloneTL(this.outCards),
- opData:gangData
- }
- this.setPaijuHuiFangData(M.GANG,pjhfsplist);/////TL++ 牌局回放 push杠操作数据
- }
- else{
- this.logic.updateSYPS(i,[card],this.handCards[i],this.huCards,this.outCards,this.hutipdata[i]);
- gangData.hutipdata = this.hutipdata[i];
- }
- yield this.pushMsgAsync(i, 'paohuzi_event', { type: M.GANG, data: gangData });
- }
- this.moOrChu = 3;
- let gangDatapg = {
- chairId: String(chairId),
- currentId: this.currentId,
- everyCPHX: this.everyCPHX,//每个玩家的吃碰胡息
- type: String(type),
- card: String(card),
- otherCards: _.cloneDeep(otherCards),
- cards: this.handCards[chairId],
- }
- gangDatapg.hutipdata = {
- kehuData:[]/////对象数组,分别表示打哪张可胡哪几张数据
- };
- yield this.lookMsgAsync('paohuzi_event', { type: M.GANG, data: gangDatapg });////TL++
-
- //下面这个if是庄家处理起手的3提五坎
- if(phktdp){//跑后可提
- // console.warn("跑后可提=============this.currentId ",chairId,this.currentId);
- // return yield this.gangCardAsync(chairId,phktdp,2);
- this.app.timer.setTimeout(() => this.yanchiAsync(3,chairId,phktdp,2), 600);
- return { code: C.OK };
- }
- // console.warn("下面这个if是庄家处理起手的3提五坎 ",chairId,this.logic.isFPJD() , res.length);
- if(!huRes && !this.logic.isFPJD()){//庄家必须出一张牌
- let ckspsl = this.logic.getSPZS(this.handCards[chairId]);
- // console.warn("?????????????????============= ",chairId,this.currentId,gwjsfjz,ckspsl,sfltlg);
- if(gwjsfjz){
- // console.warn("111111................111",gwjsfdyct);
- // return this.touchCardAsync(this.currentId).then(() => ({ code: C.OK }));//////2个提的时候不用出牌给下家摸牌
- let sffsbk = true;//是否发送八块
- if(gwjsfdyct) sffsbk = false;
- // console.warn("111111................111",sffsbk,gwjsfdyct);
- return this.yanchiBaKuai(chairId,this.currentId,sffsbk).then(() => ({ code: C.OK }));
- }
- else {
- if(ckspsl%3 == 1){
- let nextId = (this.currentId + 1) % this.ccount;
- // console.warn("111111................222",gwjsfdyct,this.currentId);
- // if(gwjsfdyct) nextId = this.currentId;//编号1 的设置牌会出错故去掉了 去掉之后编号2 的设置牌会出错
- // 为了解决上面的困境把上面的判断修改为了下面这样
- let sffsbk = true;//是否发送八块
- if(gwjsfdyct) {//该玩家是第一次提
- let gwjcppltpgs = this.logic.getCPPLTPGS(this.huCards[chairId]);//该玩家吃碰牌里提跑个数
- // console.warn("-----------------=========--------- ",gwjcppltpgs);
- if(gwjcppltpgs == 1) {
- nextId = this.currentId;
- sffsbk = false;
- }
- }
- // return this.touchCardAsync(nextId).then(() => ({ code: C.OK }));//////没有2个提的时候给摸牌
- return this.yanchiBaKuai(this.currentId,nextId,sffsbk).then(() => ({ code: C.OK }));
- }
- else if(ckspsl%3 == 0){
- // console.warn("111111................333");
- if(sfltlg || this.everyDongState[chairId] == 1){
- let nextId = (this.currentId + 1) % this.ccount;
- // console.warn("111111................444");
- // return this.touchCardAsync(nextId).then(() => ({ code: C.OK }));//////连提2个的时候给下家摸牌
- return this.yanchiBaKuai(this.currentId,nextId,true).then(() => ({ code: C.OK }));
- }
- else{
- let strcc = "table 杠牌出错了,id: "+this.id + " ,uid "+chairId+", ckspsl "+ ckspsl +" ,card "+card+" ,type "+type+" ,everysfdycpdt "+this.everysfdycpdt;
- logger.error(strcc);////cssj
- }
- }
- }
- }
- }
- } 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.weiCardAsync = cor(function* (chairId, card) {
- let str3 = "table 偎牌id:%s "+this.id + " ,uid "+chairId+" ,this.masks "+ this.masks +" ,card "+card;
- logger.warn(str3);////cssj
- // 参数校验
- if (this.currentId != chairId) {
- return { code: C.FAILD, msg: C.GAME_PARAM_ERROR };
- }
- // 权限校验
- if (!(this.masks[chairId] & 32)) {
- return { code: C.FAILD, msg: C.TABLE_MASK_ERROR };
- }
- let zzpsfgd = this.logic.getIsGuo(this.everyGDCPP[chairId],card);//这张牌是否过掉过
- // console.warn("偎牌 zzpsfgd card everyGDCPP ",zzpsfgd,card,this.everyGDCPP[chairId]);
- let res = this.logic.weiAnalyze(this.handCards[chairId], card, zzpsfgd);
- if (!res) {
- return { code: C.FAILD, msg: C.TABLE_PENG_ERROR };
- }
- // 记录偎牌
- res.origin = this.currentId;
- this.huCards[chairId].push(res);
- this.everyCPHX[chairId] = this.logic.getCPHX(this.huCards[chairId]);
- let yscdsz = [res.cards[0], res.cards[0]];//要删除的数组
- let scspRes = this.logic.removes2(this.handCards[chairId], yscdsz);//删除手牌结果
- this.handCards[chairId] = _.cloneDeep(scspRes.handCards);
- this.handHXInfos[chairId] = _.cloneDeep(scspRes.handHXInfos);
- // 清空权限
- _.fill(this.masks, 0);
- // 用户顺序
- this.currentId = chairId;
- let wpwjsfwpkc = this.logic.getSFWPKC2(this.handCards[chairId],this.handHXInfos[chairId]);//偎牌玩家是否无牌可出
- if(this.everyDongState[chairId] != 1 && wpwjsfwpkc){
- let sphxs = _.sum(this.handHXInfos[chairId].hxValues);//手牌胡息数
- let cphx = this.everyCPHX[chairId];
- if(sphxs+cphx < this.logic.khMinHX){
- //至此是偎牌之后息数不够且无牌可出进洞了
- this.everyDongState[chairId] = 1;//本局钻洞了
- }
- // console.warn("这里是偎牌之后无牌可出",this.handHXInfos[chairId].hxValues,sphxs,cphx);
- }
- this.isCanOut = true;//是否允许玩家手动出牌(偎牌)
- if(this.everyDongState[chairId] == 1 || wpwjsfwpkc) this.isCanOut = false;
- for (let i = 0; i < this.ccount; ++i) {
- let weidata = {////这种一定要声明在for循环里面
- chairId: String(chairId),
- isCanOut: this.isCanOut,//是否允许玩家手动出牌
- everyCPHX: this.everyCPHX,//每个玩家的吃碰胡息
- card: String(card),
- type: res.type,
- everyDongState: this.everyDongState,
- }
- if(i == chairId){
- weidata.cards = this.handCards[chairId];
- weidata.hxInfos = this.handHXInfos[chairId];
- if(this.logic.isXYBCP(this.handCards[i],this.huCards[i])){
- this.hutipdata[i] = this.logic.hutip2(i,this.handCards[i],this.huCards[i],this.huCards,this.outCards);////偎牌调用胡牌提示
- }
- else {
- this.hutipdata[i] = this.logic.hutip(i,this.handCards[i],this.huCards[i],this.huCards,this.outCards);////偎牌调用胡牌提示
- }
- weidata.hutipdata = this.hutipdata[i];
- }
- else{
- this.logic.updateSYPS(i,[card],this.handCards[i],this.huCards,this.outCards,this.hutipdata[i]);
- weidata.hutipdata = this.hutipdata[i];
- }
- yield this.pushMsgAsync(i, 'paohuzi_event', { type: M.PAOHUZI_WEI, data: weidata });
- }
- this.moOrChu = 3;
- let weidatapg = {////偎的旁观数据
- chairId: String(chairId),
- everyCPHX: this.everyCPHX,//每个玩家的吃碰胡息
- everyDongState: this.everyDongState,
- card: String(card),
- type: res.type,
- }
- weidatapg.hutipdata = {
- kehuData:[]/////对象数组,分别表示打哪张可胡哪几张数据
- };
- yield this.lookMsgAsync('paohuzi_event', { type: M.PAOHUZI_WEI, data: weidatapg });////TL++
- ////20200831增加胡牌提示的时候把下面这句换成了上面那一段
- let pjhfsplist = {
- shouPai:this.logic.deepCloneTL(this.handCards),
- everyCPHX: this.everyCPHX,//每个玩家的吃碰胡息
- handHXInfos:this.logic.deepCloneTL(this.handHXInfos),
- everyDongState: this.logic.deepCloneTL(this.everyDongState),
- lastCount:String(this.logic.leaveCount()),
- outCards:this.logic.deepCloneTL(this.outCards),
- opData:{ chairId: String(chairId), card: String(card),type: res.type, }
- }
- this.setPaijuHuiFangData(M.PAOHUZI_WEI,pjhfsplist);/////TL++ 牌局回放 push偎操作数据
- if(this.everysfdycpdt[chairId]){
- //下面是处理起手时非庄家的提
- let qsCards = this.logic.arr2ToArr1(this.handCards[chairId],true);
- let qstres = this.logic.anGangAnalyze(qsCards);
- if(qstres.length > 0){
- this.masks[chairId] |= 8;
- //庄家打牌之后轮到闲家摸牌,在闲家摸牌之前先提掉该玩家手上所有的提
- return yield this.gangCardAsync(chairId,qstres[0].card,2);
- }
- //处理起手时非庄家的提结束
- }
- this.sfwhkhqypkc = false;//偎牌玩家是否偎后可胡且有牌可出
- if(this.everyDongState[chairId] != 1){
- let huRes = this.logic.huAnalyze(chairId,this.handCards[chairId], card, this.huCards[chairId],true,false);
- // console.error("ssccAAA胡牌分析 huRes",huRes);
- if (huRes) {
- this.huRes[chairId] = huRes;
- this.masks[chairId] |= 16;
- if(this.logic.getSFWPKC2(this.handCards[chairId],this.handHXInfos[chairId])){
- // 偎牌之后可胡情况下若无牌可出则自动胡牌,
- yield this.autoSysOperate(600,chairId,"hu",card);
- }
- else{
- this.sfwhkhqypkc = true;
- }
- }
- }
- let gwjsfjz = this.logic.isXYBCP(this.handCards[chairId],this.huCards[chairId]);//该玩家是否需要进子
- if(gwjsfjz || this.everyDongState[chairId] == 1){//2个提的时候需要进子不出牌
- let oldCurr = this.currentId;
- let nextId = (this.currentId + 1) % this.ccount;
- this.currentId = nextId;
- // console.warn("????????----???111偎牌 ",chairId);
- // return this.touchCardAsync(this.currentId).then(() => ({ code: C.OK }));//////2个提的时候不用出牌给下家摸牌
- return this.yanchiBaKuai(oldCurr,this.currentId,true).then(() => ({ code: C.OK }));
- }
- if(this.sfwhkhqypkc){
- //偎牌之后可胡情况下若有牌可出则发此消息询问用户是过是胡;
- this.masks[chairId] |= 64;
- // console.warn("????????----???222偎牌 ",chairId);
- yield this.pushMsgAsync(chairId, 'paohuzi_event', { type: M.PAOHUZI_WEIAFTER, data: {mask: String(this.masks[chairId])} });
- }
- 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
- // console.warn("碰牌============== ",card , this.moOrChu,this.moCard,this.outCard,this.currentId);
- // 参数校验
- if(this.moOrChu == 2){//2表示出
- if (card != this.outCard || this.currentId == chairId) {
- return { code: C.FAILD, msg: C.GAME_PARAM_ERROR };
- }
- }
- if(this.moOrChu == 1){//1表示摸
- if (card != this.moCard || 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.masks[chairId] & 16) this.logic.isGuoHuList[chairId][0] = true;
- // 他人可胡杠
- 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, 'paohuzi_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.everyCPHX[chairId] = this.logic.getCPHX(this.huCards[chairId]);
- let scspRes = this.logic.removes2(this.handCards[chairId], [card, card]);//删除手牌结果
- this.handCards[chairId] = _.cloneDeep(scspRes.handCards);
- this.handHXInfos[chairId] = _.cloneDeep(scspRes.handHXInfos);
- // 清空权限
- this._eatType = 0;
- this._bi1Type = 0;
- this._bi2Type = 0;
- this.gangType = 0;
- this.gangCard = 0;
- _.fill(this.masks, 0);
- // 用户顺序
- this.currentId = chairId;
- this.isCanOut = true;//是否允许玩家手动出牌(碰牌)
- for (let i = 0; i < this.ccount; ++i) {
- let pengdata = {////这种一定要声明在for循环里面
- chairId: String(chairId),
- isCanOut: this.isCanOut,//是否允许玩家手动出牌
- everyCPHX: this.everyCPHX,//每个玩家的吃碰胡息
- card: String(card),
- isGuoHuList: this.logic.isGuoHuList[i]
- }
- if(i == chairId){
- pengdata.cards = this.handCards[chairId];
- pengdata.hxInfos = this.handHXInfos[chairId];
- if(this.logic.isXYBCP(this.handCards[i],this.huCards[i])){
- this.hutipdata[i] = this.logic.hutip2(i,this.handCards[i],this.huCards[i],this.huCards,this.outCards);////碰牌调用胡牌提示
- }
- else {
- this.hutipdata[i] = this.logic.hutip(i,this.handCards[i],this.huCards[i],this.huCards,this.outCards);////碰牌调用胡牌提示
- }
- pengdata.hutipdata = this.hutipdata[i];
- }
- else{
- this.logic.updateSYPS(i,[card],this.handCards[i],this.huCards,this.outCards,this.hutipdata[i]);
- pengdata.hutipdata = this.hutipdata[i];
- }
- yield this.pushMsgAsync(i, 'paohuzi_event', { type: M.PENG, data: pengdata });
- }
- this.moOrChu = 3;
- let pengdatapg = {////碰的旁观数据
- chairId: String(chairId),
- everyCPHX: this.everyCPHX,//每个玩家的吃碰胡息
- card: String(card)
- }
- pengdatapg.hutipdata = {
- kehuData:[]/////对象数组,分别表示打哪张可胡哪几张数据
- };
- yield this.lookMsgAsync('paohuzi_event', { type: M.PENG, data: pengdatapg });////TL++
- ////20200831增加胡牌提示的时候把下面这句换成了上面那一段
- // yield this.pushMsgAsync(-1, 'paohuzi_event', { type: M.PENG, data: { chairId: String(chairId), card: String(card) } });
- let pjhfsplist = {
- shouPai:this.logic.deepCloneTL(this.handCards),
- everyCPHX: this.everyCPHX,//每个玩家的吃碰胡息
- handHXInfos:this.logic.deepCloneTL(this.handHXInfos),
- lastCount:String(this.logic.leaveCount()),
- outCards:this.logic.deepCloneTL(this.outCards),
- isGuoHuList: this.logic.deepCloneTL(this.logic.isGuoHuList),
- opData:{ chairId: String(chairId), card: String(card) }
- }
- this.setPaijuHuiFangData(M.PENG,pjhfsplist);/////TL++ 牌局回放 push碰操作数据
- if(this.everysfdycpdt[chairId]){
- //下面是处理起手时非庄家的提
- let qsCards = this.logic.arr2ToArr1(this.handCards[chairId],true);
- let qstres = this.logic.anGangAnalyze(qsCards);
- if(qstres.length > 0){
- this.masks[chairId] |= 8;
- //庄家打牌之后轮到闲家摸牌,在闲家摸牌之前先提掉该玩家手上所有的提
- return yield this.gangCardAsync(chairId,qstres[0].card,2);
- }
- //处理起手时非庄家的提结束
- }
- let gwjsfjz = this.logic.isXYBCP(this.handCards[chairId],this.huCards[chairId]);//该玩家是否需要进子
- if(gwjsfjz){//2个提的时候需要进子不出牌
- let oldCurr = this.currentId;
- let nextId = (this.currentId + 1) % this.ccount;
- this.currentId = nextId;
- // return this.touchCardAsync(this.currentId).then(() => ({ code: C.OK }));//////2个提的时候不用出牌给下家摸牌
- return this.yanchiBaKuai(oldCurr,this.currentId,true).then(() => ({ code: C.OK }));
- }
-
- }
- } 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, bi1Type, bi2Type) {
- let str3 = "table 吃牌id:%s "+this.id + " ,uid "+chairId+" ,this.masks "+ this.masks +",card "+card+",type "+type+",bi1Type "+bi1Type+",bi2Type "+bi2Type;
- logger.warn(str3);////cssj
- // 参数校验
- if (!type && (type < 1 || type > 6)) {
- return { code: C.FAILD, msg: C.GAME_PARAM_ERROR };
- }
- if (this.moOrChu == 2 && 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 };
- }
- let chiBiArr = {cdpsszs:-1,chi:[],bi1:[],bi2:[]}; //吃牌时吃比数据
- if (this.masks[chairId] & 2) {
- let mpwjdxj = (this.moChair + 1) % this.ccount;//摸牌玩家的下家
- if(this.moOrChu == 1 && mpwjdxj == chairId) chiBiArr = this.chiBiArrxj;
- else chiBiArr = this.chiBiArr; //吃牌时吃比数据
- }
- if(!this.logic.checkChiData(type,chiBiArr.cdpsszs,bi1Type,bi2Type)){
- // console.warn("da0ppppppppoooooooooooooo");
- return { code: C.FAILD, msg: C.TABLE_MASK_ERROR };
- }
- if (this.masks[chairId] & 16) this.logic.isGuoHuList[chairId][0] = true;
- // if(this.logic.isGuoHuList[chairId][0]) this.logic.isGuoHuList[chairId][0] = false;/////TL++,吃牌设置过胡玩家的是否点击过胡为false;
- // 他人可胡杠碰
- // 这是麻将的写法,因为麻将里能吃的人只有1个,下面这样判断的目的是排除吃牌者之外的人有没有碰杠胡
- // var cHuGangPeng = _.findIndex(this.masks, (m) => (((m & 16) || (m & 8) || (m & 4)) && !(m & 2)));
- //上面这行不适用吃同时存在,为了解决摸牌者和摸牌者的下家都能吃摸牌者摸到的牌(摸牌者优先)问题把上面这行改为下面这段
- var cHuGangPeng = -1;//除操作吃之外可碰杠胡的玩家
- var qtkcwj = -1;//除操作吃之外可吃的玩家
- for (let i = 0; i < this.masks.length; ++i) {
- if(i == chairId) continue;
- let maskItem = this.masks[i];
- if((maskItem & 16) || (maskItem & 8) || (maskItem & 4)) cHuGangPeng = i;
- if ((maskItem & 2)) qtkcwj = i;
- }
- if (cHuGangPeng == -1 && qtkcwj != -1) {
- //至此是除操作吃牌顽疾之外其他玩家没有可以碰杠胡,且有人可吃
- if(this.moOrChu == 1 && this.moChair == qtkcwj){
- //只有在摸牌阶段才会可以2个人同时吃,且摸牌者优先
- cHuGangPeng = qtkcwj;
- }
- }
- if (cHuGangPeng == -1) {
- let res = this.logic.chi(this.handCards[chairId], card, type, chiBiArr.cdpsszs, bi1Type, bi2Type, this.outerId, chairId);
- if (res.length == 0) {
- return { code: C.FAILD, msg: C.TABLE_CARD_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, 'paohuzi_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{
- // 记录吃牌
- // this.outCards[this.outerId].pop();
- for (var i = 0; i < res.length; i++) {
- this.huCards[chairId].push(res[i]);
- }
- this.everyCPHX[chairId] = this.logic.getCPHX(this.huCards[chairId]);
- // 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]);
- // }
- let needRemoves = this.logic.getChiAllNeedRemoves(card,type, chiBiArr.cdpsszs, bi1Type, bi2Type);
- let scspRes = this.logic.removes2(this.handCards[chairId], needRemoves);//删除手牌结果
- this.handCards[chairId] = _.cloneDeep(scspRes.handCards);
- this.handHXInfos[chairId] = _.cloneDeep(scspRes.handHXInfos);
- // 清空权限
- this._eatType = 0;
- this._bi1Type = 0;
- this._bi2Type = 0;
- this.gangType = 0;
- this.gangCard = 0;
- _.fill(this.masks, 0);
- // 用户顺序
- this.currentId = chairId;
- this.isCanOut = true;//是否允许玩家手动出牌(吃牌)
- // 发送通知
- for (let i = 0; i < this.ccount; ++i) {
- let chidata = {
- chairId: String(chairId),
- isCanOut: this.isCanOut,//是否允许玩家手动出牌
- everyCPHX: this.everyCPHX,//每个玩家的吃碰胡息
- type: String(type),
- bi1Type: String(bi1Type),
- bi2Type: String(bi2Type),
- card: String(card)
- }
- if(i == chairId){
- chidata.cards = this.handCards[chairId];
- chidata.hxInfos = this.handHXInfos[chairId];
- if(this.logic.isXYBCP(this.handCards[i],this.huCards[i])){
- this.hutipdata[i] = this.logic.hutip2(i,this.handCards[i],this.huCards[i],this.huCards,this.outCards);////吃牌调用胡牌提示
- }
- else {
- this.hutipdata[i] = this.logic.hutip(i,this.handCards[i],this.huCards[i],this.huCards,this.outCards);////吃牌调用胡牌提示
- }
- chidata.hutipdata = this.hutipdata[i];
- }
- else{
- this.logic.updateSYPS(i,needRemoves,this.handCards[i],this.huCards,this.outCards,this.hutipdata[i]);
- chidata.hutipdata = this.hutipdata[i];
- }
- yield this.pushMsgAsync(i, 'paohuzi_event', { type: M.CHI, data: chidata });
- }
- // console.warn("MMMMMMMMMMMMMM666 ",this.huCards[chairId]);
- this.moOrChu = 3;
- this.chiBiArr = {cdpsszs:-1,chi:[],bi1:[],bi2:[]}; //吃牌时吃比数据
- this.chiBiArrxj = {cdpsszs:-1,chi:[],bi1:[],bi2:[]}; //摸牌者下家吃摸牌者摸的牌时吃比数据
- let chidatapg = { ////TL++吃牌旁观数据
- chairId: String(chairId),
- everyCPHX: this.everyCPHX,//每个玩家的吃碰胡息
- type: String(type),
- bi1Type: String(bi1Type),
- bi2Type: String(bi2Type),
- card: String(card),
- isGuoHuList: this.logic.isGuoHuList[chairId]
- }
- chidatapg.hutipdata = {
- kehuData:[]/////对象数组,分别表示打哪张可胡哪几张数据
- };
- yield this.lookMsgAsync('paohuzi_event', { type: M.CHI, data: chidatapg });////TL++吃牌旁观消息
- ////20200901为了增加胡牌提示把下面这一段换成了上面那一段
- // yield this.pushMsgAsync(-1, 'paohuzi_event', { type: M.CHI, data: { chairId: String(chairId), type: String(type), card: String(card) } });
- let pjhfsplist = {
- shouPai:this.logic.deepCloneTL(this.handCards),
- everyCPHX: this.everyCPHX,//每个玩家的吃碰胡息
- handHXInfos:this.logic.deepCloneTL(this.handHXInfos),
- lastCount:String(this.logic.leaveCount()),
- outCards:this.logic.deepCloneTL(this.outCards),
- isGuoHuList: this.logic.deepCloneTL(this.logic.isGuoHuList),
- opData:{chairId: String(chairId), type: String(type),bi1Type: String(bi1Type),
- bi2Type: String(bi2Type), card: String(card)}
- }
- this.setPaijuHuiFangData(M.CHI,pjhfsplist);/////TL++ 牌局回放 push吃操作数据
- if(this.everysfdycpdt[chairId]){
- //下面是处理起手时非庄家的提
- let qsCards = this.logic.arr2ToArr1(this.handCards[chairId],true);
- let qstres = this.logic.anGangAnalyze(qsCards);
- if(qstres.length > 0){
- this.masks[chairId] |= 8;
- //庄家打牌之后轮到闲家摸牌,在闲家摸牌之前先提掉该玩家手上所有的提
- return yield this.gangCardAsync(chairId,qstres[0].card,2);
- }
- //处理起手时非庄家的提结束
- }
- let gwjsfjz = this.logic.isXYBCP(this.handCards[chairId],this.huCards[chairId]);//该玩家是否需要进子
- if(gwjsfjz){//2个提的时候需要进子不出牌
- let oldCurr = this.currentId;
- let nextId = (this.currentId + 1) % this.ccount;
- this.currentId = nextId;
- // return this.touchCardAsync(this.currentId).then(() => ({ code: C.OK }));//////2个提的时候不用出牌给下家摸牌
- return this.yanchiBaKuai(oldCurr,this.currentId,true).then(() => ({ code: C.OK }));
- }
- }
- } else {
- // 置于等待
- let old_eatType = this._eatType;
- let old_bi1Type = this._bi1Type;
- let old_bi2Type = this._bi2Type;
- let ddcwj = _.findIndex(this.masks, (m, i) => (m == 3));//等待吃的玩家
- this.masks[chairId] = 3;
- this._eatType = type;
- this._bi1Type = bi1Type;
- this._bi2Type = bi2Type;
- // console.warn("----------================111 ",chairId,ddcwj,this.moChair,this.masks);
- //增加下面这段是为了解决A摸203时AB都可吃C可碰或跑或胡时A点吃之后B点吃C点过之后A玩家持牌错误的bug
- if(this.moOrChu == 1 && ddcwj != -1){
- if(this.moChair == chairId && ddcwj != this.moChair){
- //至此是有非摸牌者等待吃摸牌者摸到的牌,把摸牌时非摸牌者等待吃去掉
- this.masks[ddcwj] = 0;
- }
- if(this.moChair != chairId && ddcwj == this.moChair){
- //至此是有摸牌者等待吃自己摸到的牌,把摸牌时非摸牌者等待吃去掉
- this.masks[chairId] = 0;
- this._eatType = old_eatType;
- this._bi1Type = old_bi1Type;
- this._bi2Type = old_bi2Type;
- }
- }
- // console.warn("----------================222 ",this._eatType,this._bi1Type,this.masks[ddcwj],this.masks);
- // 查找等待 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) {
- if(this.moOrChu == 1){
- return this.pengCardAsync(cPeng, this.liangZi).then(() => ({ code: C.OK }));
- }
- return this.pengCardAsync(cPeng, this.outCard).then(() => ({ code: C.OK }));
- } else if (_cChi != -1 && this._eatType > 0 && cHuGangPeng == -1) {
- //cHuGangPeng == -1是为了解决A摸203时AB都可吃C可碰或跑或胡时AB点碰之后陷入死循环的bug
- if(this.moOrChu == 1){
- return this.eatCardAsync(_cChi, this.liangZi, this._eatType,this._bi1Type,this._bi2Type).then(() => ({ code: C.OK }));
- }
- return this.eatCardAsync(_cChi, this.outCard, this._eatType,this._bi1Type,this._bi2Type).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.yanchiBaKuai = cor(function* (bkchairId,mochairId,isbk) {
- let moycsj = 1000;
- if(isbk) moycsj = 2100;
- if(!this.bakuaiTimer && isbk){
- this.bakuaiTimer = this.app.timer.setTimeout(() => this.sendBaKuai(bkchairId), 1000);
- }
- if(!this.ycMoTimer){
- this.ycMoTimer = this.app.timer.setTimeout(() => this.yanchiTouch(mochairId), moycsj);
- }
- });
- //发生打子(八块)消息,因为有吃碰偎提跑之后是八块的话则不出牌而是给下家摸牌
- proto.sendBaKuai = cor(function* (chairId,isbk) {
- if(this.bakuaiTimer){
- clearTimeout(this.bakuaiTimer);
- this.bakuaiTimer = null;
- }
- return yield this.pushMsgAsync(-1, 'paohuzi_event', { type: M.SEED, data: { chairId: String(chairId)} });
- });
- //延迟执行摸牌函数,用于前端有时间播放”八块”的动画和音效
- proto.yanchiTouch = cor(function* (chairId) {
- if(this.ycMoTimer){
- clearTimeout(this.ycMoTimer);
- this.ycMoTimer = null;
- }
- return yield this.touchCardAsync(chairId);
- });
- // 操作是否自动出牌
- 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);
- var isMoHu = (this.moChair == chairId);
- // console.warn(" 胡牌 处理前端 chairId, currentId, outerId ",chairId,this.currentId,this.outerId);
- // console.warn(" 胡牌 处理前端111 ",isMoHu,winner,this.winner);
- if (isMoHu) {
- winner.chs[0] = chairId;
- yield this.pushMsgAsync(-1, 'paohuzi_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 {
- // 点炮
- // console.warn("outerId ",this.outerId,"moOrChu ",this.moOrChu,"moChair ",this.moChair,"currentId ",this.currentId);
- winner.lead = this.outerId;
- if(this.logic.isFPJD() || this.moOrChu == 1){
- winner.lead = this.currentId;
- }
- }
- // 胡牌者
- if (winner.chs.length <= 0) winner.chs[0] = chairId;
- else {
- /////有多个人点击胡牌的时候,按照打牌顺序找出距离出牌人最近的人设置为这次的赢家
- let dist = (winner.chs[0] - winner.lead + this.ccount) % this.ccount;
- if ((chairId - winner.lead + this.ccount) % this.ccount < dist) winner.chs[0] = chairId;
- }
- // 他人可胡
- let __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, 'paohuzi_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),yjchair:-1, lead: String(winner.lead) };
- var wins = this.logic.fillDeep(Array(this.ccount), {
- win: 0,//总输赢
- isPoChan: 0,
- shiJiKouFen: 0,
- cardfen: 0,
- });
- data.banker = this.chBanker;/////TL++
- let isMZJYM = false;//是否满足无红中加一码
- // console.warn("结算游戏 huRes ",JSON.stringify(this.huRes));
- data.hxInfos = {}
- //ts++胡的人
- let hu=-1;
- if (winner.chs.length >0 && winner.chs[0] >= 0 && winner.chs[0] <= 2)
- {
- hu=winner.chs[0];
- if(this.paoHuQK[0] == hu && this.paoHuQK[1] && this.paoHuQK[2] > 0){
- let kpIndex = -1;
- for (let i = 0; i < this.huCards[hu].length; ++i) {
- if(this.huCards[hu][i].card != this.paoHuQK[2]) continue;
- let stylelx = this.huCards[hu][i].style;
- if (stylelx == Logic.STYLE.PENG || stylelx == Logic.STYLE.WEI) {
- kpIndex = i;
- break;
- }
- }
- if(kpIndex > -1){
- this.huCards[hu][kpIndex].style = Logic.STYLE.ZMGANG;
- this.huCards[hu][kpIndex].cards.push(this.paoHuQK[2]);
- }
- }
- data.hxInfos = this.logic.getWinerHXInfo(this.huRes[hu],this.huCards[hu]);
- }
- // console.warn("???????????????/ ",hu,JSON.stringify(this.huRes));
- // 1 [null,{"zdhx":20,"card":108,"cards":[[201,201]],"hxInfos":{"styles":[0],"hxTypes":[0],"hxValues":[0]}}]
- data.hutype = [];
- data.allFan = 0;
- let typeInfo = {hutype:[],allFan:0}
- if(hu > -1){
- data.yjchair = hu;
- typeInfo = this.logic.isGetCardTypeTL(hu,this.huRes[hu].cards,this.huCards[hu],[],winner.lead == -1,this.huRes[hu].card)
- data.hutype = typeInfo.hutype;
- data.allFan = typeInfo.allFan;
- }
- data.lastCards = this.logic.getSYPaiDui();//剩余牌堆
- let yjgs = 0;//赢家个数
- // 计算输赢
- for (let i = 0; i < wins.length; ++i) {
- // 自摸
- let isMoHu = winner.lead == -1;
- let zdhx = 0;//最大胡息
- let allTun = 0;//总的囤数
- if(this.huRes[i] && this.huRes[i].zdhx){
- zdhx = this.huRes[i].zdhx;
- if(zdhx >= this.logic.khMinHX){
- allTun = this.cell + this.tunshuValue;
- if(isMoHu) allTun += 1;
- allTun += Math.floor((zdhx - this.logic.khMinHX) / 3)
- }
- }
-
- wins[i].zdhx = zdhx;
- wins[i].allTun = allTun;
- // 胡牌者
- if (winner.chs.indexOf(i) != -1) {
- yjgs++;
- let sy = allTun * typeInfo.allFan;
- if(sy > this.fengDingValue && this.fengDingValue > 0) sy = this.fengDingValue;
- let yjdzt = this.everyDongState[i];//本局玩家的钻洞状态
- if(sy > 0 && yjdzt == 1 || yjdzt == 2){
- sy = 0;//钻洞玩家赢了不得分然后出洞
- this.everyDongState[i] = 3;
- }
- wins.forEach((w, c) => {
- if (c != i) {
- w.win -= sy;
- wins[i].win += sy;
- w.cardfen -= sy;
- wins[i].cardfen += sy;
- }
- });
- wins[i].lucky = 1;
- }
- if(hu == -1) data.hxInfos = this.logic.deepCloneTL(this.handHXInfos[i]);
- // 手牌
- 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, type: huCard.type, card: huCard.card });
- }
- // console.warn("----------------------------------?????????????? ",i,this.handCards[i],this.huRes[i].cards);
- cards.hands = this.handCards[i];
- if(hu == i && this.huRes[i] && this.huRes[i].cards){
- cards.hands = this.huRes[i].cards;
- }
- 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;
- data.everyDongState = _.cloneDeep(this.everyDongState);
- let bjsy = [];//本局每个人的输赢
- for (let i = 0; i < this.ccount; ++i) {
- // bjsy[i] = wins[i].win;
- let zhx = 0;//总胡息
- let cdts = 0;//充的囤数
- let iszm = 0;//是否自摸
- let zts = 0;//总囤数
- if(data.yjchair == i){
- zhx = wins[i].zdhx;
- cdts = this.tunshuValue;
- if(data.lead == -1) iszm = 1;
- zts = wins[i].allTun;
- }
- let zhanjiItem = {
- zf: wins[i].win,
- zhx: zhx,
- cdts: cdts,
- iszm: iszm,
- zts: zts,
- }
- bjsy[i] = zhanjiItem;
- }
- this.sszjDataList[this.sszjDataList.length] = bjsy;
- this.over += 1;// 局数+1
- //ts++
-
- let sszjScore = [];//ts++实时本局成绩
- let sszjAllScore = [];//ts++实时总成绩
- // 记录分数
- for (let i = 0; i < this.ccount; ++i) {
- let user = this.users[i];
- if (user)
- {
- sszjScore[i] = shiJiKouFen[i];
- this.score.writeScore(user.id,shiJiKouFen[i], 1);//设置分数
- sszjAllScore[i] = this.score.getScore(user.id);
- // if(this.gameKindTL == 2) sszjAllScore[i] -=200;
- if(this.over == 1)
- {
- this.score.writeCost(user.id,this.cost, 0); //ts++设置消耗
- }
- }
- }
- let endmode=ENDMODE.PLAYING;
- if(this.isGameOver())
- {
- this.isGameOk=true;
- endmode=ENDMODE.NORMALEND;//局数完成--正常结束
- }
- data.isover = this.isGameOk;
- data.nowTime = Date.now();
-
- // let str4 = "table 444结算函数---id:%s"+this.id +"结算模式"+mode
- // logger.info(str4);////cssj
- //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});
- //处理点灯规则的当前剩余灯数
- let otherstr = ""+this.other;
- if(this.gameKindTL == 1 || this.gameKindTL == 2) {
- if(hu == -1) {
- this.logic.dengshuValue++;//流局则灯数+1
- if(this.logic.dengshuValue > 1 && parseInt(otherstr[1]) != 1) this.logic.dengshuValue = 1;//没勾选点灯规则的话灯数不累加
- }
- else if(hu != this.chBanker && this.logic.dengshuValue > 0) this.logic.dengshuValue--;//闲家赢了则灯数不变
- }
- // 切换庄家,谁赢谁做庄,荒庄之后庄家不变
- if(yjgs == 1){
- //只有一个人赢了,谁赢谁做庄
- this.chBanker = winner.chs[0];
- }
- else{
- if(hu == -1) {
- //流局之后 没有黄规则的时候(土跑胡)流局之后切换庄家为庄家的下一家
- if(this.gameKindTL == 3) this.chBanker = (this.chBanker + 1) % this.ccount;
- }
- }
- /////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.setPaijuHuiFangData(M.CONCLUDE,data);/////TL++ 牌局回放 push结算数据
- /////TL++,用于记录玩家牌局回放的json文件名
- this.pjhffileName[this.pjhffileName.length] = this.PJHF.getjsonFileName(this.over,this.recordid,this.ctime);
- // 重置本局
- this.resetRound();
- // 结算通知
- yield this.pushMsgAsync(-1, 'paohuzi_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, 'paohuzi_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, 'paohuzi_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, 'paohuzi_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,//游戏类型 = 1代表全名堂 = 2代表大小子 = 3表示土跑胡
- 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,//游戏类型 = 1代表全名堂 = 2代表大小子 = 3表示土跑胡
- 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, 'paohuzi_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, 'paohuzi_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, 'paohuzi_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, 'paohuzi_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, 'paohuzi_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, 'paohuzi_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, 'paohuzi_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, 'paohuzi_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, 'paohuzi_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 };
- });
|