table.js 227 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029
  1. 'use strict';
  2. var util = require('util');
  3. var quick = require('quick-pomelo');
  4. var P = quick.Promise;
  5. var cor = P.coroutine;
  6. var _ = require('lodash');/////是一个一致性、模块化、高性能的 JavaScript 实用工具库。
  7. //// 为什么选择 Lodash ?
  8. //// Lodash 通过降低 array、number、objects、string 等等的使用难度从而让 JavaScript 变得更简单。
  9. //// Lodash 的模块化方法 非常适用于:
  10. //// 遍历 array、object 和 string
  11. //// 对值进行操作和检测
  12. //// 创建符合功能的函数
  13. var uuid = require('node-uuid');
  14. var Logic = require('./logic');
  15. var User = require('./user');
  16. var Score = require('./score');
  17. var conf = require('../config/games').csjiang || {};
  18. var M = require('../../share/message');
  19. var C = require('../../share/constant');
  20. var paiJuHuiFang = require('../../share/paiJuHuiFang');//////TL++ 牌局回放
  21. var configCommon = require('../../share/configCommon');//////TL++配置相关的公共方法
  22. var setReabte = require('../../share/setReabte');//////TL++记录返利相关的公共方法
  23. var logger = quick.logger.getLogger('fhmj', __filename);
  24. // 桌子状态
  25. var STATE = { FREE: 1, PLAYING: 2, FREE2: 3 , END: 4};//ts++REFREE 二次空闲 END结束
  26. // 结算模式
  27. var MODE = { NORMAL: 1, NOCARD: 2, OFFLINE: 3 };
  28. //ts++结束模式 空闲0,游戏中1, 正常结束3,房主解散3,断线解散4,断线解散5,系统解散6
  29. var ENDMODE = { FREE: 0,PLAYING: 1, OWNEREND: 2,NORMALEND: 3,REGEND: 4, OFFLINEEND: 5, SYSTEMEND: 6 };
  30. // 金币消耗
  31. const COSTS = conf.sit_costs || {};
  32. /////TL++,下面这几行为了记录用户行为
  33. // var log4js2 = require("log4js");////cssj
  34. // var log4js_config2 = require("./logConf.json");
  35. // log4js2.configure(log4js_config2);
  36. // var LogFile2 = log4js2.getLogger('log_file');////cssj
  37. var checkVersion = function () {
  38. // let confCodeVer = require('../config/csLogicVer').codeVer || {};
  39. // console.warn("cs的table中检查logic版本111 "+JSON.stringify(confCodeVer));
  40. // if(confCodeVer.csLogic){
  41. // delete require.cache[require.resolve('../config/csLogicVer')];
  42. // let confCodeVer2 = require('../config/csLogicVer').codeVer || {};
  43. // console.warn("cs的table中检查logic版本222 "+confCodeVer.csLogic +" "+ confCodeVer2.csLogic);
  44. // if(confCodeVer.csLogic && confCodeVer2.csLogic && confCodeVer.csLogic != confCodeVer2.csLogic){
  45. // delete require.cache[require.resolve('./logic')];
  46. // Logic = require('./logic');
  47. // console.warn("cs的table中的logic更新了 ")
  48. // }
  49. // }
  50. }
  51. // 构造方法
  52. var Table = function (cPlayerId,cUserId,cName,cHead,game, id, cell, round, type,gameKindTL,playerAllCount,upId,other,agentId,yxndlbTime,yxndlbTip) {
  53. let str3 = "cstable构造方法.......id: "+id + " type " + type+" game "+game.id;
  54. // console.warn(str3);////cssj
  55. // checkVersion();
  56. this.app = game.app;
  57. this.gameId = 10006;
  58. this.game = game;
  59. this.id = id;
  60. this.recordid = uuid.v1()+'_'+id;//ts++唯一记录
  61. this.upId = upId;//ts++上局的ID
  62. this.type = type;
  63. this.agentId=agentId;
  64. this.yxndlbTime = yxndlbTime;
  65. this.yxndlbTip = yxndlbTip;
  66. this.other = other;//////TL++2人3人的游戏规则
  67. // console.warn("cs222创建房间的other111 ",other,this.other," gameKindTL ",gameKindTL," type " ,type);
  68. this.jiangmaCount = 2;////奖码张数(抓鸟张数)
  69. this.kexuanList = [0,0,0,0];//可选列表
  70. if(this.other & 1){
  71. this.kexuanList[0] = 1;//中途四喜
  72. }
  73. if(this.other & 2){
  74. this.kexuanList[1] = 1;//中途六六顺
  75. }
  76. if(this.other & 4){
  77. this.kexuanList[2] = 1;//门清
  78. }
  79. if(this.other & 256){
  80. this.kexuanList[3] = 1;//小胡只能自摸
  81. }
  82. this.hzCount = 0;/////红中个数
  83. this.fengDingType = 0;/////封顶类型1:不封顶;2:封顶56分;3:封顶112分;
  84. if(this.other & 8){
  85. this.fengDingType = 1;
  86. }
  87. else if(this.other & 16){
  88. this.fengDingType = 2;
  89. }
  90. else if(this.other & 32){
  91. this.fengDingType = 3;
  92. }
  93. this.ZNJSType = 0;/////中鸟结算类型1:中鸟相加;2:中鸟相乘;
  94. if(this.other & 64){
  95. this.ZNJSType = 1;
  96. }
  97. else if(this.other & 128){
  98. this.ZNJSType = 2;
  99. }
  100. this.gameKindTL = 1;//1:传统;2:割索;3:疯狂
  101. if(this.other & 512){
  102. this.gameKindTL = 2;
  103. }
  104. else if(gameKindTL == 3){
  105. this.gameKindTL = 3;//疯狂 疯狂模式下有红中只能自摸
  106. }
  107. if(this.gameKindTL == 3){
  108. // console.warn("这是疯狂");
  109. // delete require.cache[require.resolve('./logicfk')];
  110. Logic = require('./logicfk');
  111. }
  112. else{
  113. Logic = require('./logic');
  114. }
  115. var num_cost = 50;
  116. if(this.gameKindTL == 2){
  117. num_cost =parseInt(COSTS[1]);
  118. }
  119. else if(this.gameKindTL == 3){
  120. // delete require.cache[require.resolve('../config/games')];
  121. let confcsfk = require('../config/games').csfkjiang || {};
  122. let costscsfk = confcsfk.sit_costs || {};
  123. num_cost =parseInt(costscsfk[round])
  124. console.warn("这是疯狂 num_cost "+num_cost);
  125. }
  126. else
  127. {
  128. num_cost =parseInt(COSTS[round]);
  129. }
  130. // console.warn("玩法类型1:传统;2:割索; "+this.gameKindTL)
  131. // console.warn("封顶类型1:不封顶;2:封顶56分;3:封顶112分 "+this.fengDingType)
  132. // console.warn("中鸟结算类型1:中鸟相加;2:中鸟相乘 "+this.ZNJSType)
  133. // console.warn("可选列表 "+this.kexuanList)
  134. this.cost = num_cost;
  135. this.over = 0;
  136. this.round = round;
  137. this.stime = 0;
  138. this.ctime = Date.now();
  139. this.etime = 0;
  140. this.lconfigCommon = null;
  141. // 人数
  142. this.ccount = playerAllCount;//Logic.CHAIR_COUNT;
  143. this.mcount = Logic.CARDS_COUNT;
  144. // 房主
  145. this.ownerChairId = -1;//房主的chairid
  146. this.ownerId = cPlayerId;//房主Id
  147. this.ownerUid = cUserId;//房主的userID
  148. this.ownerName = cName;
  149. this.ownerHeadUrl = cHead;
  150. // 数据
  151. var logic = new Logic(type,gameKindTL,playerAllCount,other);
  152. this.logic = logic;
  153. this.score = new Score(this);
  154. this.handCards = Array(this.ccount);
  155. this.huCards = logic.fillDeep(Array(this.ccount), []);
  156. this.users = Array(this.ccount);
  157. this.chBanker = 0;
  158. this.quFeng = 0;
  159. this.bankFlag = 0;
  160. this.outCards = logic.fillDeep(Array(this.ccount), []);
  161. // 标记
  162. this.isDihus = _.fill(Array(this.ccount), true);
  163. this.isTianhu = true;
  164. this.outCard = 0;
  165. this.outerId = -1;
  166. this.disCards = [];
  167. this.currentId = -1;
  168. // 包含字,总杠次,保留量
  169. // this.hasWords = !(type & 2);/////TL++zs
  170. // this.hasWords = true;/////是否含有字牌/////TL++
  171. // this.gonCount = 0;
  172. // this.disCounts = [26, 14, 16, 26];/////TL++zs
  173. // this.disCounts = [1,1,1,1,];
  174. // 允许吃牌
  175. this.hasEat = true;//!!(type & 4);////是否可吃牌
  176. // 允许点炮
  177. // this.hasEHu = true;///!!(type & 8);//没有用到
  178. // 一炮多响
  179. this.isMHu = true;//!!(type & 16);
  180. // 允许杠胡
  181. this.hasGHu = true;///!!(type & 32);
  182. // 点炮出钱
  183. this.isWOne = true;//!!(type & 64);
  184. // 权限:16-胡,8-杠,4-碰,2-吃,1-等待,0-无
  185. this.masks = _.fill(Array(this.ccount), 0);
  186. this.excepts = logic.fillDeep(Array(this.ccount), {});
  187. // 等待杠类型,1-普通杠, 2-暗杠, 3-自摸明杠
  188. this.gangType = 0;
  189. this.gangCard = 0;
  190. this.qshType = [0,0,0,0];//
  191. this.qshCards = [[],[],[],[]];//起手胡操作的牌 被置于等待时记录玩家起手胡的操作
  192. this.buType = 0;
  193. this.buCard = 0;
  194. this.pengCard = 0;
  195. this.currQSHInfo = [[],[],[],[]];//当前各个玩家展示的起手胡信息
  196. this.keGangInfo = {chairId: -1,data:[]};////可杠信息,因为摸牌之后手上虽然有多个杠,但是没有听牌的话是不能杠的
  197. this.autoOutTimer = null;
  198. this.everyIsAutoOut = _.fill(Array(this.ccount), 0);
  199. this.updataGangTimer = null;//////杠后两张牌都无权限的时候等一会儿再消失
  200. this.gangAfterData = {
  201. chairId: -1,
  202. cards: {card1:0,card2:0},
  203. canSelectData: [[],[],[],[]],
  204. mask: 0
  205. }
  206. this.everyIsGang = [[0,0],[0,0],[0,0],[0,0]];/////每个人是否杠了,可以打的牌,0表示没有限制,如果杠了就只能摸啥打啥了
  207. // 抢杠胡、被杠玩家
  208. this.isGangHu = false;
  209. this.isBuHu = false;
  210. this.gangOuter = -1;
  211. // 等待吃类型,1-@**左吃, 2-*@*中吃, 3-@**右吃
  212. this._eatType = 0;
  213. this._eatCard = 0;
  214. // 胡牌者
  215. this.anams = Array(this.ccount);
  216. this.huRes = Array(this.ccount);
  217. this.winner = { lead: -1, chs: [] };
  218. // 底分
  219. this.cell = cell;
  220. // 围观者
  221. this.lookers = [];
  222. //结束时的继线用户
  223. this.leaveUsers = [];
  224. // 状态
  225. this.state = STATE.FREE;
  226. // 申请结束标记
  227. this.overFlag = 0;
  228. this.overTimer = null;
  229. this.endTableTime = 60;//////TL++,申请解散房间之后60秒之后不操作则认为同意解散
  230. this.reqJieSan = [-1,-1,-1,-1];/////解散桌子数据,前面为chirid后面为情况-1:未操作 0:拒绝 1:同意 2为解散发起
  231. //断线 结束定时器
  232. this.endTimer = null;
  233. //////以下全为TL++
  234. /////TL++,补花定时器,防止连续补花太快
  235. this.PJHF = new paiJuHuiFang();
  236. // this.buhuaTimeout = null;
  237. this.backStartTimer = null;//////重入之后系统会自动准备为了解决可能没牌的问题2秒之后才开始游戏
  238. this.PaijuHuiFang = [];////TL++,牌局回放
  239. // this.zhyzfgs = [-2,null,null];/////TL++,由于最后一张牌的摸牌被打断所以 用来记录最后一张牌的发牌函数的参数
  240. // this.isLianGang = [-1,false,-1];/////TL++,连杠的玩家座位号,是否连杠 杠的牌
  241. this.isYJJSGL = false;/////是否已经执行过结算函数了
  242. this.isYJKSGL = false;/////是否已经执行过开始函数了
  243. this.JSFJTimeout = null;//解散房间倒计时
  244. this.JSFJTime = 60;//解散房间倒计时60秒
  245. this.SQJSTime = null;//申请解散房间的时间,用于计算解散房间倒计时所剩的时间
  246. this.gameNeverStart = true;//游戏是否从未开始过,用于解散房间判断
  247. this.pjhffileName = [];//用于记录玩家牌局回放的json文件名
  248. this.playerPosList = [[],[],[],[]];//记录玩家的位置信息数组
  249. this.playerAllCount = playerAllCount || 4;//游戏人数 = 2表示2人局 = 3表示3人局 = 4表示4人局
  250. this.isNeverStart = true;//游戏是否从未开始
  251. this.sszjDataList = [];//设置实时战绩的数据
  252. this.isEveryZZ = false;//是否每一个人都做过庄
  253. // this.isZJYG = false;////本局庄家是否有杠
  254. this.chairArry = [0,1,2,3];//
  255. this.everyHDLY = [-1,-1,-1,-1];//每个玩家海底捞月选择情况,不选择海底不能胡海底
  256. // this.isNeverTounchHU = false;/////是否从未点击过胡按钮
  257. //分别代表补,四喜,板板胡,缺一色,六六顺,中途四喜,中途六六顺满足之后让mask |= maskValeList[i]
  258. this.maskValeList = [32,64,128,256,512,1024,2048];//用来计算mask
  259. this.sszjs = [];//ts++实时战绩
  260. this.LWKF = [10,10,10,10,10];//////TL++礼物扣费
  261. this.isGameOk=false;//ts++牌局正常结束
  262. this.agentRebate=0;//ts++本局的返利
  263. // delete require.cache[require.resolve('../../share/setReabte')];
  264. // setReabte = require('../../share/setReabte');
  265. this.lsetReabte = new setReabte(this.app);
  266. };
  267. // 导出状态
  268. Table.STATE = STATE;
  269. //ts++ 结束模式
  270. Table.ENDMODE = ENDMODE;
  271. // 导出类
  272. module.exports = Table;
  273. // 原型对象
  274. var proto = Table.prototype;
  275. // 是否站满
  276. proto.isFull = function () {
  277. return (this.lookers.length >= 5);
  278. };
  279. // 是否准备
  280. proto.isReady = function () {
  281. for (let user of this.users) {
  282. if (!user || !user.isReady()) return false;
  283. }
  284. return true;
  285. };
  286. // ts++是否二次准备
  287. proto.isReady2 = function () {
  288. for (let user of this.users) {
  289. if (!user || !user.isReady2()) return false;
  290. }
  291. return true;
  292. };
  293. // 是否游戏中
  294. proto.isPlaying = function () {
  295. return this.state > STATE.FREE;
  296. };
  297. // 是否全在线
  298. proto.isOnline = function () {
  299. for (let user of this.users) {
  300. if (user && user.isOffline()) return false;
  301. }
  302. return true;
  303. };
  304. // 是否全断线
  305. proto.isOffline = function () {
  306. for (let user of this.users) {
  307. if (!user || !user.isOffline()) return false;
  308. }
  309. return true;
  310. };
  311. // 是否空桌
  312. proto.isEmpty = function () {
  313. if (this.lookers.length > 0) return false;
  314. for (let i = 0; i < this.users.length; ++i) {
  315. if (this.users[i]) return false;
  316. }
  317. return true;
  318. };
  319. // 局数完成
  320. proto.isGameOver = function () {
  321. let str3 = "cstable 局数完成 .......id: "+ this.id + " this.over " + this.over;
  322. logger.warn(str3);////cssj
  323. if(this.gameKindTL == 2){
  324. for (let i = 0; i < this.users.length; ++i) {
  325. let user = this.users[i];
  326. if (user) {
  327. let score = this.score.getScore(user.id);
  328. // console.warn("割索在判断是否可以总结算了 每个人目前的分数",score);
  329. if(score <= 0) return true;
  330. }
  331. }
  332. return false;
  333. }
  334. else {
  335. return (this.over >= this.round);
  336. }
  337. };
  338. // 重置本局
  339. proto.resetRound = function () {
  340. _.fill(this.handCards, null);
  341. _.fill(this.isDihus, true);
  342. this.isTianhu = true;
  343. _.fill(this.masks, 0);
  344. this.logic.fillDeep(this.excepts, {});
  345. _.fill(this.huRes, null);
  346. // this.gonCount = 0;
  347. this.winner.chs = [];
  348. this.winner.lead = -1;
  349. this.logic.fillDeep(this.huCards, []);
  350. this.logic.fillDeep(this.outCards, []);
  351. this.outCard = 0;
  352. this.outerId = -1;
  353. this.currentId = -1;
  354. this._eatType = 0;
  355. this._eatCard = 0;
  356. this.gangType = 0;
  357. this.gangCard = 0;
  358. this.pengCard = 0;
  359. this.qshType = [0,0,0,0];//
  360. this.qshCards = [[],[],[],[]];//起手胡操作的牌
  361. this.currQSHInfo = [[],[],[],[]];//当前各个玩家展示的起手胡信息
  362. this.keGangInfo = {chairId: -1,data:[]};//可杠信息,因为摸牌之后手上虽然有多个杠,但是没有听牌的话是不能杠的
  363. if(this.autoOutTimer)
  364. {
  365. clearTimeout(this.autoOutTimer);
  366. this.autoOutTimer = null;
  367. }
  368. this.everyIsAutoOut = _.fill(Array(this.ccount), 0);
  369. this.gangAfterData = {
  370. chairId: -1,
  371. cards: {card1:0,card2:0},
  372. canSelectData: [[],[],[],[]],
  373. mask: 0
  374. }
  375. this.everyIsGang = [[0,0],[0,0],[0,0],[0,0]];/////每个人是否杠了,如果杠了就只能摸啥打啥了
  376. this.buType = 0;
  377. this.buCard = 0;
  378. this.isGangHu = false;
  379. this.isBuHu = false;
  380. this.gangOuter = -1;
  381. this.everyHDLY = [-1,-1,-1,-1];//每个玩家海底捞月选择情况,不选择海底不能胡海底
  382. };
  383. // 发送消息
  384. proto.pushMsgAsync = cor(function* (cidOrIds, route, msg) {
  385. var playerIds = [];
  386. if (Array.isArray(cidOrIds)) playerIds = cidOrIds;
  387. else {
  388. if (cidOrIds < 0 || cidOrIds >= this.users.length) {
  389. for (let user of this.users) {
  390. if (user) playerIds.push(user.id);
  391. }
  392. for (let lker of this.lookers) {
  393. playerIds.push(lker.id);
  394. }
  395. } else {
  396. let user = this.users[cidOrIds];
  397. if (user) playerIds.push(user.id);
  398. // console.warn("555WWWWWWWTTTTTT",cidOrIds, route, user.name);
  399. }
  400. }
  401. if (playerIds.length > 0) {
  402. let channelId = 'xct:' + this.id;
  403. // console.warn("666WWWWWWWTTTTTT",cidOrIds, route, playerIds,msg);
  404. return this.app.controllers.push._pushAsync(channelId, playerIds, route, msg);
  405. }
  406. });
  407. // 围观消息
  408. proto.lookMsgAsync = cor(function* (route, msg) {
  409. var playerIds = [];
  410. for (let lker of this.lookers) {
  411. playerIds.push(lker.id);
  412. }
  413. if (playerIds.length > 0) {
  414. let channelId = 'xct:' + this.id;
  415. return this.app.controllers.push._pushAsync(channelId, playerIds, route, msg);
  416. }
  417. });
  418. // 获得桌子信息
  419. proto.getTableInfo = function () {
  420. // 桌子信息
  421. let endTableTime = Math.floor((this.SQJSTime - Date.now())/1000);
  422. var tableInfo = {
  423. id: this.id,
  424. gameId: this.gameId,
  425. type: this.type,
  426. cost: this.cost,
  427. over: this.over,
  428. round: this.round,
  429. users: [],
  430. lookers: [],
  431. ownerId: -1,//this.ownerChairid
  432. ownerUserId: this.ownerUid,////TL++,房主的userID
  433. ownerName: this.ownerName,//////TL++,房主的昵称
  434. ownerHeadUrl: this.ownerHeadUrl,//////TL++,房主的头像地址
  435. gameKindTL: this.gameKindTL,////平搓还是冲刺 = 1代表平搓 = 2代表冲刺
  436. playerAllCount: this.playerAllCount,////游戏人数 = 2表示2人局 = 3表示3人局 = 4表示4人局
  437. other: this.other,
  438. creatTime : this.ctime,
  439. nowTime : Date.now(),
  440. state: this.state,
  441. sszjDataList: this.sszjDataList,////TL++,设置实时战绩的数据
  442. isZHYZ: this.logic.isZHYZ, /////TL++,是否最后一张
  443. playerPosList: this.playerPosList,/////TL++玩家位置数据
  444. chairArry: this.chairArry,/////TL++
  445. isNeverStart: this.isNeverStart,/////TL++,游戏是否从未开始
  446. overFlag:this.overFlag,//ts++房间解散标识
  447. endTableTime:endTableTime,
  448. recordid:this.recordid,
  449. yxndlbTime:this.yxndlbTime,
  450. yxndlbTip:this.yxndlbTip,
  451. reqJieSan:this.reqJieSan
  452. };
  453. // 正在游戏
  454. var isPlaying = this.isPlaying();
  455. if (isPlaying) {
  456. tableInfo.qFeng = this.quFeng;
  457. tableInfo.banker = this.chBanker;
  458. tableInfo.stime = Date.now() - this.stime;
  459. tableInfo.currentId = this.currentId;
  460. tableInfo.disCards = this.disCards;
  461. tableInfo.lastCount = this.logic.leaveCount();
  462. tableInfo.isGangHu = this.isGangHu;
  463. tableInfo.gangCard = this.gangCard||this.buCard;
  464. //////TL++,游戏过程中重入
  465. tableInfo.baiDaCard = String(this.logic.baiDaCard);//////TL++,本局百搭牌
  466. tableInfo.everyFllowerCardList = [[],[],[],[]]; /////每个人手上的花牌
  467. tableInfo.currQSHInfo = this.currQSHInfo;
  468. tableInfo.isCanOut = this.logic.getIsCanOut(this.masks);
  469. //////TL++ end,游戏过程中重入
  470. }
  471. // 桌上玩家
  472. for (let i = 0; i < this.users.length; ++i) {
  473. let user = this.users[i];
  474. if (user) {
  475. let score = this.score.getScore(user.id);
  476. let uinfo = {
  477. account: user.account, name: user.name, sex: user.sex, headurl: user.headurl,
  478. state: user.state2, score: score, chairId: user.chairId
  479. };
  480. if (isPlaying) {
  481. let huCards = [];
  482. for (let huCard of this.huCards[i]) {
  483. huCards.push({ style: huCard.style, type: huCard.type, card: huCard.cards[0], origin: huCard.origin });
  484. }
  485. uinfo.huCards = huCards;
  486. uinfo.outCards = this.outCards[i];
  487. let handCard = this.handCards[i] || [];
  488. uinfo.handCount = handCard.length;
  489. }
  490. tableInfo.users.push(uinfo);
  491. }
  492. }
  493. // 围观玩家
  494. for (let i = 0; i < this.lookers.length; ++i) {
  495. let user = this.lookers[i];
  496. if (user) {
  497. tableInfo.lookers.push({
  498. account: user.account,
  499. name: user.name,
  500. sex: user.sex,
  501. headurl: user.headurl
  502. });
  503. }
  504. }
  505. return tableInfo;
  506. };
  507. // 回到桌子
  508. proto.backAsync = cor(function* (user) {
  509. let str3 = "cstable回到桌子.......id: "+ this.id + " user.chairId: " + user.chairId + " user.name: " + user.name ;
  510. logger.warn(str3);////cssj
  511. user.offlinetime=0;//ts++
  512. var data = { chairId: String(user.chairId) };
  513. var chairId = user.chairId;
  514. let isGuoHuList = [[false,-1],[false,-1],[false,-1],[false,-1]];
  515. if (chairId != -1) {
  516. // 加入频道
  517. var connectorId = user.connectorId || '';
  518. if (connectorId) {
  519. let channelId = 'xct:' + this.id;
  520. yield this.app.controllers.push._joinAsync(channelId, user.id, connectorId);
  521. }
  522. // 恢复状态
  523. let str2 = "cstable回到桌子111.......id: "+ this.id + " chairId: " + chairId + " state: " + this.state ;
  524. logger.warn(str2);////cssj
  525. if (this.state == STATE.FREE) {
  526. yield this.readyGameAsync(user);
  527. } else if (this.state == STATE.PLAYING) {
  528. //user.state = User.STATE.PLAYING;//ts--
  529. user.state2 = User.STATE.PLAYING;//ts++
  530. data.mask = String(this.masks[chairId]);
  531. data.handCards = this.handCards[chairId];
  532. // 状态通知
  533. yield this.pushMsgAsync(-1, 'csjiang_event', { type: M.STATE_CHANGE, data: { chairId: String(user.chairId), state: String(user.state2), state2: String(user.state2) } });
  534. }else if (this.state == STATE.FREE2) {//ts++二次准备
  535. //user.state = User.STATE.PLAYING;//ts--
  536. let str1 = "cstable回到桌子222.......id: "+ this.id + " chairId: " + chairId;
  537. logger.warn(str1);////cssj
  538. user.state2 = User.STATE.READY;
  539. yield this.pushMsgAsync(-1, 'csjiang_event', { type: M.STATE_CHANGE, data: { chairId: String(user.chairId), state: String(user.state2), state2: String(user.state2) } });
  540. if (this.isReady2() && !this.isGameOk)
  541. {
  542. let str0 = "cstable回到桌子333.......id: "+ this.id + " chairId: " + chairId;
  543. logger.warn(str0);////cssj
  544. if(!this.backStartTimer){
  545. let str00 = "cstable回到桌子444.......id: "+ this.id + " chairId: " + chairId;
  546. logger.warn(str00);////cssj
  547. this.backStartTimer = this.app.timer.setTimeout(() => this.backStartTimeAsync(), 2 * 1000);//延迟2秒开始游戏
  548. }
  549. }
  550. }
  551. // 取消计时
  552. if (this.isOnline() && this.endTimer) {
  553. clearTimeout(this.endTimer);
  554. this.endTimer = null;
  555. }
  556. isGuoHuList[chairId] = this.logic.isGuoHuList[chairId];
  557. }
  558. // 数据处理
  559. data.fee = this.score.isFeed(user.id) ? '0' : '1';
  560. data.table = this.getTableInfo();
  561. let hutipdata = {
  562. renyi:0,//////是否可胡任意牌,0表示不满足1表示满足
  563. kehuData:[]/////对象数组,分别表示打哪张可胡哪几张数据
  564. };
  565. if(chairId == this.currentId){
  566. let tipres = this.logic.hutip(this.currentId,this.handCards[this.currentId],this.huCards[this.currentId],this.huCards,this.outCards);////重入时调用胡牌提示
  567. data.table.hutipdata = tipres;
  568. }
  569. else{
  570. data.table.hutipdata = hutipdata;
  571. }
  572. let isAutoOut = 0;
  573. if (chairId != -1) {
  574. isAutoOut = this.everyIsAutoOut[chairId];
  575. }
  576. data.table.isAutoOut = isAutoOut;
  577. data.table.isGuoHuList = isGuoHuList;
  578. data.table.canSelects = [];
  579. data.table.isGangInfo = [0,0];/////每个人是否杠了,如果杠了就只能摸啥打啥了
  580. let keGangInfo = {chairId: -1,data:[]};//可杠信息,因为摸牌之后手上虽然有多个杠,但是没有听牌的话是不能杠的
  581. if(chairId == keGangInfo.chairId) keGangInfo = this.keGangInfo;
  582. data.table.keGangInfo = keGangInfo;
  583. if (chairId != -1) {
  584. data.table.isGangInfo = this.everyIsGang[chairId];/////每个人是否杠了,如果杠了就只能摸啥打啥了
  585. data.table.canSelects = this.logic.canSelects[chairId];
  586. data.table.gangAfterData = {
  587. chairId: this.gangAfterData.chairId,
  588. cards: this.gangAfterData.cards,
  589. canSelectData: this.gangAfterData.canSelectData[chairId],
  590. mask: this.gangAfterData.mask
  591. }
  592. }
  593. return { code: C.OK, data: data };
  594. });
  595. //ts++重入后自动开始
  596. proto.backStartTimeAsync = cor(function* () {
  597. let str00 = "cstable重入后自动开始..id: "+ this.id;
  598. logger.warn(str00);////cssj
  599. yield this.startGameAsync();
  600. });
  601. // 加入桌子
  602. proto.joinAsync = cor(function* (user) {
  603. // 撤出删除队列
  604. //this.game.cancelDelete(this.id);
  605. // 加入桌子之前
  606. yield this.beforeJoinAsync(user);
  607. // 加入围观者
  608. this.lookers.push(user);
  609. // 加入桌子之后
  610. yield this.afterJoinAsync(user);
  611. // 数据返回处理
  612. var data = { chairId: String(user.chairId) };
  613. data.fee = this.score.isFeed(user.id) ? '0' : '1';
  614. data.table = this.getTableInfo();
  615. return { code: C.OK, data: data };
  616. });
  617. // 加入桌子之前
  618. proto.beforeJoinAsync = cor(function* (user) {
  619. var connectorId = user.connectorId || '';
  620. if (connectorId) {
  621. let channelId = 'xct:' + this.id;
  622. return this.app.controllers.push._joinAsync(channelId, user.id, connectorId);
  623. }
  624. });
  625. // 加入桌子之后
  626. proto.afterJoinAsync = cor(function* (user) {
  627. // 加入通知
  628. return this.pushMsgAsync(-1, 'csjiang_event', {
  629. type: M.JOIN, data: { account: user.account, userId: user.userId, name: user.name, sex: user.sex, headurl: user.headurl,playerPosList: this.playerPosList }
  630. });
  631. });
  632. // 坐下桌子
  633. proto.seatAsync = cor(function* (user, chairId) {
  634. // let chairId = this.chairArry[_chairId];
  635. // console.warn("坐下桌子不不vvvvvv",chairId,_chairId,this.chairArry,this.users.length);
  636. // 参数校验
  637. if (chairId < 0 || chairId >= this.ccount) {
  638. return { code: C.FAILD, msg: C.CHAIR_NOT_FOUND };
  639. }
  640. if (this.users[chairId]) {
  641. // console.warn("坐下桌子死了vv000",this.users[chairId]);
  642. // console.warn("坐下桌子死了vvvvvv",this.users.length,this.users);
  643. return { code: C.FAILD, msg: C.CHAIR_HAS_SOMEONE };
  644. }
  645. // 查找玩家
  646. var player = yield this.app.models.Player.findByIdAsync(user.id, 'diamond cost');
  647. if (!player) {
  648. return { code: C.FAILD, msg: C.PLAYER_NOT_FOUND };
  649. }
  650. if (this.users[chairId]) {
  651. return { code: C.FAILD, msg: C.CHAIR_HAS_SOMEONE };
  652. }
  653. // 调换座位
  654. if (user.chairId != -1) {
  655. return this.changeChairAsync(user, chairId);
  656. }
  657. // 围观玩家
  658. var pos = _.findIndex(this.lookers, (u) => (u.id == user.id));
  659. if (pos == -1) {
  660. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  661. }
  662. //ts++
  663. let dSource=player.diamond;
  664. let dNow=player.diamond;
  665. //坐下花费
  666. var costdata = null;
  667. if (!this.score.isFeed(user.id)) {
  668. if (player.diamond < this.cost) {
  669. return { code: C.FAILD, msg: C.GAME_DIAMOND_LOW };
  670. }//////TL++zsyl 1000局测完之后要放出来的
  671. player.diamond -= this.cost;
  672. player.cost = (player.cost || 0) + this.cost;
  673. dNow-=this.cost;
  674. this.score.addUser(user.id,chairId,user.userId, user.name, user.sex, user.headurl,user.diamond,this.gameKindTL);
  675. costdata = { cost: String(this.cost) };
  676. }
  677. // 坐下处理
  678. this.lookers.splice(pos, 1);
  679. this.users[chairId] = user;
  680. user.chairId = chairId;
  681. user.state = User.STATE.READY;
  682. yield this.afterSeatAsync(user);
  683. if (player.isModified())
  684. {
  685. yield player.saveAsync();/////只有第一次坐下的时候才会执行
  686. // 钻石记录
  687. var diamondrecord = new this.app.models.DiamondRecord({
  688. _id: uuid.v1(),
  689. playerId: user.id,
  690. dType: 3,//坐下
  691. dSource: dSource,
  692. dSwap: -1*this.cost,
  693. dNow: dNow,
  694. tableId: this.recordid
  695. });
  696. yield diamondrecord.saveAsync();
  697. // console.warn("ts++坐下-------------------钻石记录");
  698. if (costdata) yield this.pushMsgAsync(chairId, 'csjiang_event', { type: M.COST_FEE, data: costdata });
  699. }
  700. // if (this.isReady()) yield this.pushMsgAsync(this.ownerChairid, 'csjiang_event', { type: M.START_BUTTON });//////TL++zsyl所有人准备之后通知房主点击开始游戏
  701. if (this.state == STATE.FREE && this.isReady() && !this.isGameOk) {
  702. yield this.randomChangeChairTL();
  703. }
  704. return { code: C.OK, chairId: String(chairId) };
  705. });
  706. // 调换座位 自己坐下之后点击另外一个位子的时候调用这个方法 这个参数user输出之后相当的长
  707. proto.changeChairAsync = cor(function* (user, chairId) {
  708. if (this.state != STATE.FREE) {
  709. return { code: C.FAILD, msg: C.TABLE_NOT_FREE };
  710. }
  711. if (this.users[chairId]) {
  712. return { code: C.FAILD, msg: C.CHAIR_HAS_SOMEONE };
  713. }
  714. // var _chairId = user.chairId;
  715. // delete this.users[_chairId];
  716. // this.users[chairId] = user;
  717. // user.chairId = chairId;
  718. // user.state = User.STATE.READY;
  719. // yield this.pushMsgAsync(-1, 'csjiang_event', { type: M.CHAIR_CHANGE, data: { oldId: String(_chairId), newId: String(chairId), state: String(user.state), state2: String(user.state2) } });
  720. // // if (this.ownerChairid == _chairId) {
  721. // // this.ownerChairid = chairId;
  722. // // // 换房主通知
  723. // // yield this.pushMsgAsync(-1, 'csjiang_event', { type: M.OWNER_CHANGE, data: { ownerChairid: String(this.ownerChairid) } });
  724. // // }
  725. return { code: C.OK, chairId: String(chairId) };
  726. });
  727. // 坐下桌子之后
  728. proto.afterSeatAsync = cor(function* (user) {
  729. let posListTL = {
  730. chairId: user.chairId,
  731. headurl: user.headurl,
  732. longitude: user.longitude, // 经度,浮点数,范围为180 ~ -180。
  733. latitude: user.latitude, // 纬度,浮点数,范围为90 ~ -90
  734. }
  735. this.playerPosList[user.chairId] = posListTL/////TL++记录玩家的位置信息数组
  736. // 坐下通知
  737. let score = this.score.getScore(user.id);
  738. yield this.pushMsgAsync(-1, 'csjiang_event', {///////发送坐下
  739. type: M.SEAT, data: {
  740. account: user.account,
  741. name: user.name,
  742. sex: user.sex,
  743. headurl: user.headurl,
  744. state: String(user.state),
  745. score: String(score),
  746. chairId: String(user.chairId),
  747. userId: String(user.userId),
  748. playerPosList: this.playerPosList, /////TL++记录玩家的位置信息数组
  749. }
  750. });
  751. });
  752. //////TL++,在首次游戏开始的时候随机打乱用户的座位
  753. proto.randomChangeChairTL = cor(function* () {
  754. // console.warn("111在首次游戏开始的时候随机打乱用户的座位",this.users[0].name,this.users[1].name,this.users[2].name,this.users[3].name);
  755. // console.warn("1在首次游戏开始的时候随机打乱用户的座位",this.users[0].chairId,this.users[1].chairId,this.users[2].chairId,this.users[3].chairId);
  756. if(this.playerAllCount > 2){
  757. let changeResult = [];
  758. if (this.over <= 0) {///////本房间开始的第一局游戏
  759. // for (let i = 0; i < this.ccount; i++) {/////这种随机4次可能会导致4次随机之后和打乱之前的顺序一样所以弃用
  760. for (let i = 0; i < 1; i++) {
  761. let oldchaieID = i;
  762. let olduser = this.users[i];
  763. let newchaieID = Math.floor(Math.random()*this.playerAllCount);////// 区间[0,3]取整数
  764. while (newchaieID == oldchaieID) {
  765. newchaieID = Math.floor(Math.random()*this.playerAllCount);////// 区间[0,3]取整数
  766. }
  767. let newuser = this.users[newchaieID];
  768. // console.warn("222在首次游戏开始的时候随机打乱用户的座位",oldchaieID,newchaieID);
  769. // console.warn("xxxxxxxxx删除有没有用啊",this.users.length);
  770. delete this.users[newchaieID];
  771. delete this.users[oldchaieID];
  772. // console.warn("xxxxxxxxx22删除有没有用啊",this.users.length);
  773. this.users[newchaieID] = olduser;
  774. this.users[newchaieID].chairId = newchaieID;
  775. // this.users[newchaieID].id = newuser.id;
  776. this.users[oldchaieID] = newuser;
  777. this.users[oldchaieID].chairId = oldchaieID;
  778. // this.users[oldchaieID].id = olduser.id;
  779. changeResult.push([oldchaieID,newchaieID])
  780. }
  781. // console.warn("333在首次游戏开始的时候随机打乱用户的座位",this.users[0].name,this.users[1].name,this.users[2].name,this.users[3].name);
  782. // console.warn("3在首次游戏开始的时候随机打乱用户的座位",this.users[0].chairId,this.users[1].chairId,this.users[2].chairId,this.users[3].chairId);
  783. // console.warn("3在首次游戏开始的时候随机打乱用户的座位",this.users[0].id,this.users[1].id,this.users[2].id,this.users[3].id);
  784. // console.warn("3在首次游戏开始的",this.users[0]);
  785. ////// this.users 发送给前端会代码报错
  786. // yield this.pushMsgAsync(-1, 'csjiang_event', { type: M.CHAIR_DALUAN, data: { changeResult:changeResult } });
  787. /////TL++
  788. for (let i = 0; i < this.users.length; ++i) {
  789. this.score.setUserChair(this.users[i].id,this.users[i].chairId)
  790. }
  791. let daluanData = [];
  792. var isPlaying = this.isPlaying();
  793. for (let i = 0; i < this.users.length; ++i) {
  794. let user = this.users[i];
  795. if (user) {
  796. let score = this.score.getScore(user.id);
  797. let uinfo = {
  798. account: user.account, name: user.name, sex: user.sex, headurl: user.headurl,
  799. state: user.state, score: score, chairId: user.chairId
  800. };
  801. if (isPlaying) {
  802. let huCards = [];
  803. for (let huCard of this.huCards[i]) {
  804. huCards.push({ style: huCard.style, type: huCard.type, card: huCard.cards[0], origin: huCard.origin });
  805. }
  806. uinfo.huCards = huCards;
  807. uinfo.outCards = this.outCards[i];
  808. let handCard = this.handCards[i] || [];
  809. uinfo.handCount = handCard.length;
  810. }
  811. daluanData.push(uinfo);
  812. }
  813. }
  814. // this.score.delUser(user.id);
  815. yield this.pushMsgAsync(-1, 'csjiang_event', { type: M.CHAIR_DALUAN, data: { daluanData:daluanData } });
  816. }
  817. }
  818. // console.warn("444在首次游戏开始的时候随机打乱用户的座位",changeResult);
  819. // this.starTimer = this.app.timer.setTimeout(() => this.startGameAsync(), 500);
  820. yield this.startGameAsync()/////TL++,在首次游戏的时候随机打乱用户的座位
  821. });
  822. // 站起桌子
  823. proto.standAsync = cor(function* (user) {
  824. let str3 = "cstable 站起桌子.......id: "+ this.id + " user.chairId: " + user.chairId + " user.name: " + user.name ;
  825. logger.warn(str3);////cssj
  826. var chairId = user.chairId;
  827. if (chairId != -1) {
  828. user.state = User.STATE.FREE;
  829. delete this.users[chairId];
  830. delete this.handCards[chairId];
  831. user.chairId = -1;
  832. this.lookers.push(user);
  833. yield this.afterStandAsync(user, chairId);
  834. }
  835. return { code: C.OK };
  836. });
  837. // 站起桌子之后
  838. proto.afterStandAsync = cor(function* (user, chairId) {
  839. // 站起通知
  840. yield this.pushMsgAsync(-1, 'csjiang_event', { type: M.STAND, data: { chairId: String(chairId) } });
  841. //if (this.ownerChairid == -1) this.ownerChairid = -1;//////TL++,房主坐下之后重置房主chairid
  842. /////TL++,作坐下的玩家离开桌子之后将他的位置信息从位置列表里面删除
  843. if(chairId != -1) this.playerPosList[chairId] = [];
  844. // 桌主离开
  845. //////TL++zsyl,原先的这个逻辑是房主站起之后会切换房主
  846. // if (chairId == this.ownerChairid) {
  847. // let newCid = _.findIndex(this.users, (user) => user);
  848. // this.ownerChairid = newCid;
  849. // if (newCid != -1) this.ownerUid = this.users[newCid].id;
  850. // // 换房主通知
  851. // yield this.pushMsgAsync(-1, 'csjiang_event', { type: M.OWNER_CHANGE, data: { ownerChairid: String(this.ownerChairid) } });
  852. // }
  853. //是否退费
  854. // console.warn("ts++++++++站起桌子之后");
  855. var scorer = this.score.getUser(user.id);
  856. if (scorer && scorer.over <= 0) {
  857. // console.warn("ts++没有开始游戏退分",user.id);
  858. this.score.delUser(user.id);
  859. let player = yield this.app.models.Player.findByIdAsync(user.id, 'diamond cost');
  860. if (player) {
  861. // console.warn("ts++没有开始游戏退分",player.diamond);
  862. let dSource=player.diamond;
  863. let dNow=player.diamond+this.cost;
  864. player.diamond += this.cost;
  865. player.cost -= this.cost;
  866. yield player.saveAsync();
  867. //return this.app.controllers.player.pushAsync(user.id, 'csjiang_event', { type: M.BACK_FEE, data: { back: String(this.cost) } });
  868. // 退费 钻石记录
  869. var diamondrecord = new this.app.models.DiamondRecord({
  870. _id: uuid.v1(),
  871. playerId: user.id,
  872. dType: 4,//退费
  873. dSource: dSource,
  874. dSwap: this.cost,
  875. dNow: dNow,
  876. tableId: this.recordid
  877. });
  878. yield diamondrecord.saveAsync();
  879. // console.warn("ts++退分-------------------钻石记录");
  880. //var costdata = { cost: String(-1*this.cost) };
  881. //if (costdata) yield this.pushMsgAsync(chairId, 'csjiang_event', { type: M.COST_FEE, data: costdata });
  882. }
  883. }
  884. else
  885. {
  886. if(user.cost==0 && user.spreadId)//ts++推荐人奖励
  887. {
  888. // let spreader = yield this.app.models.Player.findByIdAsync(user.spreadId, 'spreadCount spreadRebate');
  889. // if (spreader) {
  890. // spreader.spreadCount += 1;
  891. // spreader.spreadRebate += 100;
  892. // yield spreader.saveAsync();
  893. // }
  894. ////20200928因为现在的spreadId存的是userId,所以上面那段用不了了
  895. if(!this.lconfigCommon) {
  896. // console.warn("邀请新人送钻石活动 this.lconfigCommon 不存在 "+this.etime);
  897. this.lconfigCommon = new configCommon(this.app);
  898. }
  899. let yxhdxx = this.lconfigCommon.getActiveOpenTime(1);//邀请新人送钻石活动是否开启和开始结束时间的信息
  900. let isKQ = false;//邀请新人送钻石活动是否开启
  901. if(yxhdxx && yxhdxx.open && yxhdxx.startTime && yxhdxx.endTime) isKQ = true;
  902. // console.warn("获取配置信息 yxhdxx "+JSON.stringify(yxhdxx));
  903. if(isKQ && this.etime >= yxhdxx.startTime && this.etime < yxhdxx.endTime){
  904. var cpopts = {};
  905. cpopts['userId'] = parseInt(user.spreadId);
  906. let spreadList = yield this.app.models.Player.findMongoAsync(cpopts, 'spreadCount spreadRebate', { sort: { stime: 1 } });//
  907. if(spreadList.length == 1){
  908. spreadList[0].spreadCount += 1;
  909. spreadList[0].spreadRebate += 100;
  910. yield spreadList[0].saveAsync();
  911. }
  912. }
  913. }
  914. yield this.lsetReabte.updateDaterebateRecord(this.agentId,this.etime);
  915. // if(this.agentId) //正常结束的才能算
  916. // {
  917. // if(this.agentRebate>0)
  918. // {
  919. // //console.warn("代理返利写分+++++");
  920. // let gameCost2=this.agentRebate;//游戏消耗
  921. // let agentRebate2=parseInt(this.agentRebate*this.rEBATERATE);
  922. // this.agentRebate=0;
  923. // var today = new Date();
  924. // today.setHours(0);
  925. // today.setMinutes(0);
  926. // today.setSeconds(0);
  927. // today.setMilliseconds(0);
  928. // let nowverifyDate=today.getTime();
  929. // var agenter = yield this.app.models.Agenter.findByIdAsync(this.agentId,'rebateOther rebateCount rebateAll rebateNow rebateOut verifyDate verifyRebate agentRate');
  930. // if (agenter)
  931. // {
  932. // //日结算
  933. // let verifyBool=false;
  934. // let verifyDate=0;
  935. // let verifyRebate=0;
  936. // //日奖励
  937. // let dateAgentRate=0;
  938. // let dateRebate=0;
  939. // if(agenter.verifyRebate>0 && agenter.verifyDate!=nowverifyDate)
  940. // {
  941. // verifyBool=true;
  942. // verifyDate=agenter.verifyDate;
  943. // verifyRebate=agenter.verifyRebate;
  944. // dateAgentRate=agenter.agentRate;
  945. // agenter.rebateNow += verifyRebate;
  946. // agenter.rebateNow += dateRebate;
  947. // agenter.rebateOther += dateRebate;
  948. // agenter.rebateCount += dateRebate;
  949. // agenter.verifyRebate=0;
  950. // }
  951. // //修改代理数据
  952. // agenter.rebateCount += agentRebate2;
  953. // agenter.rebateAll += agentRebate2;
  954. // agenter.verifyDate=nowverifyDate;
  955. // agenter.verifyRebate+= agentRebate2;
  956. // let rCount=agenter.rebateCount;
  957. // let rOther=agenter.rebateOther;
  958. // let rAll=agenter.rebateAll;
  959. // let rNow=agenter.rebateNow;
  960. // let rOut=agenter.rebateOut;
  961. // let rVerifyDate=agenter.verifyDate;
  962. // let rVerifyRebate=agenter.verifyRebate;
  963. // yield agenter.saveAsync();
  964. // // console.warn("代理返利写分+++++agenter.saveAsync()");
  965. // // 锁定返利记录
  966. // if(verifyBool && verifyRebate>0)
  967. // {
  968. // var verifyrebateRecord = new this.app.models.RebateRecord({
  969. // _id: uuid.v1(),
  970. // agentId:this.agentId,
  971. // tableId: '',
  972. // rType: 3,
  973. // rCount: rCount- agentRebate2,
  974. // rOther: rOther,
  975. // rAll: rAll- agentRebate2,
  976. // rNow: rNow,
  977. // rOut: rOut,
  978. // rSwap: verifyRebate,
  979. // rDateSwap: dateRebate,
  980. // rVerifyDate: verifyDate,
  981. // rVerifyRebate: 0
  982. // });
  983. // yield verifyrebateRecord.saveAsync();
  984. // var daterebateRecord = new this.app.models.DateRebateRecord({
  985. // _id: uuid.v1(),
  986. // agentId:this.agentId,
  987. // verifyDate: verifyDate,
  988. // verifyRebate: verifyRebate,
  989. // dateAgentRate: dateAgentRate,
  990. // dateRebate: dateRebate
  991. // });
  992. // yield daterebateRecord.saveAsync();
  993. // }
  994. // // 返利记录
  995. // var rebateRecord = new this.app.models.RebateRecord({
  996. // _id: uuid.v1(),
  997. // agentId:this.agentId,
  998. // tableId: this.recordid,
  999. // rType: 1,
  1000. // rCount: rCount,
  1001. // rOther: rOther,
  1002. // rAll: rAll,
  1003. // rNow: rNow,
  1004. // rOut: rOut,
  1005. // rSwap: agentRebate2,
  1006. // rDateSwap: 0,
  1007. // rVerifyDate: rVerifyDate,
  1008. // rVerifyRebate: rVerifyRebate
  1009. // });
  1010. // yield rebateRecord.saveAsync();
  1011. // // console.warn("返利记录+++++rebateRecord.saveAsync()");
  1012. // }
  1013. // }
  1014. // let gameRebate=0;
  1015. // if(this.isGameOk)
  1016. // {
  1017. // gameRebate=parseInt(this.cost*this.rEBATERATE);
  1018. // }
  1019. // var today = new Date();
  1020. // today.setHours(0);
  1021. // today.setMinutes(0);
  1022. // today.setSeconds(0);
  1023. // today.setMilliseconds(0);
  1024. // let date=today.getTime();
  1025. // let countid=this.agentId+'-'+user.userId+'-'+date;
  1026. // var playercount = yield this.app.models.PlayerCount.findByIdAsync(countid,'gameCount gameCost agentRebate time');
  1027. // if (playercount)
  1028. // {
  1029. // playercount.gameCount+=1;
  1030. // playercount.gameCost+=this.cost;
  1031. // playercount.agentRebate+=gameRebate;
  1032. // playercount.time=Date.now();
  1033. // }
  1034. // else
  1035. // {
  1036. // playercount = new this.app.models.PlayerCount({
  1037. // _id: countid,
  1038. // agentId:this.agentId,
  1039. // playerId: user.id,
  1040. // userId: user.userId,
  1041. // name: user.name,
  1042. // date: date,
  1043. // gameCount: 1,
  1044. // gameCost: this.cost,
  1045. // agentRebate: gameRebate,
  1046. // time:Date.now()
  1047. // });
  1048. // }
  1049. // yield playercount.saveAsync();
  1050. // }
  1051. // console.warn("活动奖励 下面开始进行判断 ",user.spreadId,user.registerTime,user.lastLoginTime);
  1052. // let str11 = "hdjl xmksjxpd "+ this.id + " isGameOk: " + this.isGameOk + " userId: " + user.userId + " spreadId: " + user.spreadId + " registerTime: " + user.registerTime + " lastLoginTime: " + user.lastLoginTime ;
  1053. // logger.warn(str11);////cssj
  1054. // if(this.isGameOk && this.ccount == 4 && user.spreadId)//活动奖励
  1055. // {
  1056. // // console.warn("活动奖励 至此是游戏正常结束而且玩家有推荐id",user.spreadId,user.registerTime,user.lastLoginTime);
  1057. // ////正常结束而且该玩家有推荐人id
  1058. // let acSTime = 1601481600000;////20201001零点的时间戳,活动开始时间
  1059. // let acETime = acSTime + 86400000*8;////20201008这天截止的时间戳 活动结束时间
  1060. // let xzsjc = Date.now();
  1061. // let str12 = "hdjl zcyxszcjseqwjytjr "+this.id + " userId: " + user.userId +" xzsjc: "+xzsjc;
  1062. // logger.warn(str12);////cssj
  1063. // if(xzsjc >= acSTime && xzsjc < acETime){
  1064. // if((user.registerTime >= acSTime && user.registerTime < acETime) || user.lastLoginTime < 1598889600000){
  1065. // // console.warn("活动奖励 至此该玩家是新用户",user.spreadId,user.registerTime,user.lastLoginTime);
  1066. // let str13 = "hdjl zcgwjsxyh "+this.id + " userId: " + user.userId;
  1067. // logger.warn(str13);////cssj
  1068. // ////活动期间注册或者9月1号10月1日之间未登陆过的玩家
  1069. // var todayTL = new Date();
  1070. // todayTL.setHours(0);
  1071. // todayTL.setMinutes(0);
  1072. // todayTL.setSeconds(0);
  1073. // todayTL.setMilliseconds(0);
  1074. // let jrldsjc=todayTL.getTime();////今日零点时间戳
  1075. // let jrjssjc=jrldsjc + 86400000;////今日结束时间戳
  1076. // var opts = { stime: { $gte: jrldsjc, $lt: jrjssjc },type: { $gte: 1, $lt: 2 }};
  1077. // opts['sid'] = user.id;
  1078. // let acrlist = yield this.app.models.ActiveRewardRecord.findMongoAsync(opts, '_id rewardtype totalfee type sid rid gameCount stime succtime succState', { sort: { stime: 1 } });//
  1079. // if(acrlist.length == 0){
  1080. // // console.warn("活动奖励 活动期间今日该玩家产生新的记录",user.spreadId,user.registerTime,user.lastLoginTime);
  1081. // let str14 = "hdjl hdqjjrgwjcsxdjl "+this.id + " userId: " + user.userId;
  1082. // logger.warn(str14);////cssj
  1083. // ////活动期间今日该玩家产生新的记录
  1084. // var activerewardrec = new this.app.models.ActiveRewardRecord({
  1085. // _id: uuid.v1(), // UUID
  1086. // rewardtype: 0, // 奖励类型,0红包
  1087. // totalfee: 0, // 产生金额,红包为分
  1088. // type:1, //活动类型:1国庆签到2国庆邀请
  1089. // sid: user.id, // 产生奖励的玩家id
  1090. // sname:user.name, // 产生奖励的玩家name
  1091. // suid:user.userId, // 产生奖励的玩家userId
  1092. // rid: user.id, // 此条奖励的受益玩家
  1093. // gameCount: 1, // 游戏局数
  1094. // stime: xzsjc, // 记录产生时间
  1095. // succtime: 0, // 任务完成时间,任务未完成的时候这里是0
  1096. // succState: 0 // 任务是否完成的状态,0:未完成1:已达成
  1097. // });
  1098. // yield activerewardrec.saveAsync();
  1099. // }
  1100. // else{
  1101. // let str15 = "hdjl hdqjjrgwjyjcsgjl "+this.id + " userId: " + user.userId;
  1102. // logger.warn(str15);////cssj
  1103. // ////活动期间更新今日该玩家已经产生的记录
  1104. // let newre = acrlist[0];
  1105. // newre.gameCount++;
  1106. // if(newre.gameCount >= 2){
  1107. // // console.warn("活动奖励 活动期间更新今日该玩家已经产生的记录",user.spreadId,user.registerTime,user.lastLoginTime);
  1108. // let str16 = "hdjl hdqjgxjrgwjyjcsdjl "+this.id + " userId: " + user.userId + " gameCount: " + newre.gameCount;
  1109. // logger.warn(str16);////cssj
  1110. // ////完成为解散2局,该玩家完成了签到的任务了
  1111. // if(newre.gameCount == 2){
  1112. // newre.totalfee = 500;
  1113. // newre.succtime = xzsjc;
  1114. // newre.succState = 1;
  1115. // }
  1116. // yield newre.saveAsync();
  1117. // }
  1118. // if(newre.gameCount == 2){
  1119. // var opts2 = { stime: { $gte: acSTime, $lt: acETime },type: { $gte: 2, $lt: 3 }};
  1120. // opts2['sid'] = user.id;
  1121. // let acrlist2 = yield this.app.models.ActiveRewardRecord.findMongoAsync(opts2, 'rid', { sort: { stime: 1 } });//
  1122. // let isneedcj = false;////是否需要创建邀请奖励产生记录
  1123. // if(acrlist2.length == 0){
  1124. // isneedcj = true;
  1125. // // if(parseInt(acrlist2[0].rid) && parseInt(acrlist2[0].rid) == user.spreadId) isneedcj = true;
  1126. // }
  1127. // // console.warn("活动奖励 完成未解散2局,该玩家的推荐人完成了邀请的任务了",user.spreadId,user.registerTime,user.lastLoginTime);
  1128. // let str17 = "hdjl csgwjdyqjl "+this.id + " userId: " + user.userId + " isneedcj: " + isneedcj;
  1129. // logger.warn(str17);////cssj
  1130. // if(isneedcj){
  1131. // ////完成为解散2局,该玩家的推荐人完成了邀请的任务了
  1132. // var activerewardrec = new this.app.models.ActiveRewardRecord({
  1133. // _id: uuid.v1(), // UUID
  1134. // rewardtype: 0, // 奖励类型,0红包
  1135. // totalfee: 500, // 产生金额,红包为分
  1136. // type:2, //活动类型:1国庆签到2国庆邀请
  1137. // sid: user.id, // 产生奖励的玩家id
  1138. // suid:user.userId, // 产生奖励的玩家userId
  1139. // sname:user.name, // 产生奖励的玩家name
  1140. // rid: user.spreadId,// 此条奖励的受益玩家
  1141. // gameCount: newre.gameCount, // 游戏局数
  1142. // stime: xzsjc, // 记录产生时间
  1143. // succtime: xzsjc, // 任务完成时间,任务未完成的时候这里是0
  1144. // succState: 1 // 任务是否完成的状态,0:未完成1:已达成
  1145. // });
  1146. // yield activerewardrec.saveAsync();
  1147. // }
  1148. // }
  1149. // }
  1150. // }
  1151. // }
  1152. // }
  1153. // let str4 = "cstable 222 站起桌子之后---id:%s"+this.id + " uid"+user.userId+" "+ this.state;
  1154. // logger.info(str4);////cssj
  1155. }
  1156. });
  1157. // 玩家断线
  1158. proto.offlineAsync = cor(function* (user) {
  1159. let str3 = "cstable 玩家断线.......id: "+ this.id + " user.chairId: " + user.chairId + " user.name: " + user.name ;
  1160. logger.warn(str3);////cssj
  1161. if (user.chairId != -1) {
  1162. //user.state = User.STATE.OFFLINE;//ts--
  1163. user.state2 = User.STATE.OFFLINE;//ts++
  1164. user.offlinetime = Date.now();//ts++断线
  1165. var channelId = 'xct:' + this.id;
  1166. yield this.app.controllers.push._quitAsync(channelId, user.id);
  1167. yield this.pushMsgAsync(-1, 'csjiang_event', { type: M.STATE_CHANGE, data: { chairId: String(user.chairId), state: String(user.state2), state2: String(user.state2) } });
  1168. // 无人在线
  1169. // console.warn("提前结算666");
  1170. //if (this.isOffline()) return this.overTimeAsync(MODE.OFFLINE);
  1171. // console.warn("玩家断线-------定时器启动");
  1172. // 计时结算
  1173. if (!this.endTimer) this.endTimer = this.app.timer.setTimeout(() => this.overTimeAsync(ENDMODE.OFFLINEEND),600000);/////断线10分钟自动结算
  1174. // let str4 = "cstable 玩家断线---id:"+this.id + ",uid"+user.userId+" "+ this.state;
  1175. // logger.info(str4);////cssj
  1176. }
  1177. });
  1178. // 离开桌子
  1179. proto.leaveAsync = cor(function* (user) {
  1180. let str3 = "cstable 离开桌子.......id: "+ this.id + " user.chairId: " + user.chairId + " user.name: " + user.name ;
  1181. logger.warn(str3);////cssj
  1182. // this.leavePlayerID = user.id;//////TL++,旁观为房主的话离开之后由于从观战者列表里面删除了,导致发消息的时候他收不到离开桌子的消息
  1183. // console.warn("离开桌子、、、、、、、");
  1184. yield this.beforeLeaveAsync(user);
  1185. var chairId = user.chairId;
  1186. // yield this.pushMsgAsync(-1, 'csjiang_event', { type: M.LEAVE, data: { account: user.account } });/////TL++zs,原来在下面
  1187. if (chairId != -1) {
  1188. delete this.users[chairId];
  1189. delete this.handCards[chairId];
  1190. yield this.afterStandAsync(user, chairId);
  1191. } else {
  1192. let pos = _.findIndex(this.lookers, (u) => (u.id == user.id));
  1193. if (pos != -1) this.lookers.splice(pos, 1);
  1194. }
  1195. return this.afterLeaveAsync(user);
  1196. });
  1197. // 离开桌子之前
  1198. proto.beforeLeaveAsync = cor(function* (user) {
  1199. var channelId = 'xct:' + this.id;
  1200. return this.app.controllers.push._quitAsync(channelId, user.id);
  1201. });
  1202. // 离开桌子之后
  1203. proto.afterLeaveAsync = cor(function* (user) {
  1204. // 离开通知
  1205. /////TL++zsyl 在此之前离开玩家已经从玩家列表或者旁观者列表中删除了所以把下面这句提到前面去了
  1206. return this.pushMsgAsync(-1, 'csjiang_event', { type: M.LEAVE, data: { account: user.account } });
  1207. });
  1208. // 玩家准备
  1209. proto.readyGameAsync = cor(function* (user) {
  1210. let str3 = "cstable 玩家准备.......id: "+ this.id + " user.chairId: " + user.chairId + " this.over: " + this.over + " user.name: " + user.name ;
  1211. logger.warn(str3);////cssj
  1212. // let str3 = "cstable 玩家准备---id:"+this.id + ",uid"+user.userId+","+ this.state;
  1213. // logger.info(str3);////cssj
  1214. if(this.state==STATE.FREE2)//ts++二次空闲
  1215. {
  1216. user.state2 = User.STATE.READY;
  1217. yield this.pushMsgAsync(-1, 'csjiang_event', { type: M.STATE_CHANGE, data: { chairId: String(user.chairId), state: String(user.state2), state2: String(user.state2) } });
  1218. if (this.isReady2() && !this.isGameOk) yield this.startGameAsync();
  1219. }
  1220. else
  1221. {
  1222. user.state = User.STATE.READY;
  1223. user.state2 = User.STATE.READY;
  1224. yield this.pushMsgAsync(-1, 'csjiang_event', { type: M.STATE_CHANGE, data: { chairId: String(user.chairId), state: String(user.state2), state2: String(user.state2) } });
  1225. // console.warn("玩家准备玩家准备玩家准备 ",this.isReady() ,this.isGameOver());
  1226. if (this.isReady() && !this.isGameOk) yield this.startGameAsync();
  1227. }
  1228. // let str4 = "cstable 222玩家准备---id:"+this.id + ",uid"+user.userId+","+ this.state;
  1229. // logger.info(str4);////cssj
  1230. return { code: C.OK };
  1231. });
  1232. // 开始游戏
  1233. proto.startGameAsync = cor(function* () {
  1234. //this.backStartTimer = null;//////重入之后系统会自动准备为了解决可能没牌的问题2秒之后才开始游戏
  1235. let str4 = "cstable 开始游戏---id:"+this.id +" ,state "+ this.state +" 当前局 "+ (this.over+1);
  1236. logger.warn(str4);////cssj
  1237. if(this.isYJKSGL){
  1238. return;
  1239. }
  1240. this.isYJKSGL = true;/////是否已经执行过开始函数了
  1241. this.isYJJSGL = false;/////是否已经执行过结算函数了
  1242. if(this.backStartTimer)
  1243. {
  1244. clearTimeout(this.backStartTimer);
  1245. this.backStartTimer = null;
  1246. }
  1247. // 状态设置
  1248. this.state = STATE.PLAYING;
  1249. //this.setUserState(-1, User.STATE.PLAYING);//ts--
  1250. //ts++设置为游戏状态
  1251. for (let user of this.users)
  1252. {
  1253. if (user) {
  1254. if(user.state == User.STATE.PLAYING)//ts++已经开始
  1255. {
  1256. if(user.state2 == User.STATE.READY)
  1257. {
  1258. user.state2 = User.STATE.PLAYING
  1259. user.offlinetime = 0;
  1260. }
  1261. }
  1262. else//ts++第一次开始
  1263. {
  1264. user.state = User.STATE.PLAYING
  1265. user.state2 = User.STATE.PLAYING
  1266. user.offlinetime = 0;
  1267. }
  1268. }
  1269. }
  1270. //ts++end
  1271. let whdata = yield this.app.models.WHstate.findByIdReadOnlyAsync('wh', 'rebaterate yxndlbTime yxndlbTip');
  1272. // console.warn("22检查是否维护状态",whdata);
  1273. if (whdata) {
  1274. if(whdata.yxndlbTime) this.yxndlbTime = whdata.yxndlbTime;
  1275. if(whdata.yxndlbTip) this.yxndlbTip = whdata.yxndlbTip;
  1276. }
  1277. this.PaijuHuiFang = [];////TL++,牌局回放 重置数据
  1278. this.lgkhCount = 0;/////TL++拉杠可胡玩家的数量
  1279. this.logic.isZHYZ = false;/////是不是最后1张
  1280. // this.logic.isNeedBuHua = false/////TL++在游戏开始的时候初始化是否需要补花
  1281. // this.isLianGang = [-1,false,-1];/////TL++,连杠的玩家座位号,是否连杠 在游戏开始的时候清空
  1282. // 初始信息
  1283. if (this.over <= 0) {///////本房间开始的第一局游戏
  1284. this.stime = Date.now();
  1285. // this.chBanker = this.ownerChairid;///////TL++zsyl
  1286. this.chBanker = 0;
  1287. //this.game.cancelDelete(this.id);//////TL++游戏第一次开始时候关闭房间20分钟未开始删除桌子
  1288. this.pjhffileName[this.pjhffileName.length] = this.PJHF.getjsonFileName(0,this.recordid,this.ctime);/////TL++,用于记录玩家牌局回放的json文件名
  1289. // console.error("000HHHHHHHHHHHHHHHHHHHHHH",this.pjhffileName.length,this.pjhffileName);
  1290. this.PJHF.writePJHFJson(this.getTableInfo(),0,this.id);////在开始第一局的时候将桌子信息写入本地的json文件
  1291. this.isNeverStart = false;/////TL++,游戏是否从未开始
  1292. // yield this.randomChangeChairTL()/////TL++,在首次游戏的时候随机打乱用户的座位
  1293. }
  1294. this.gameNeverStart = false;/////TL++,游戏是否从未开始过,用于解散房间判断
  1295. this.currentId = this.chBanker;
  1296. this.isDihus[this.chBanker] = false;
  1297. // 发手牌 把这句提前是为了洗牌之后能拿到百搭牌在游戏开始的时候给客户端发过去
  1298. let dice1 = this.logic.dice();/////骰子1的点数
  1299. let dice2 = this.logic.dice();/////骰子2的点数
  1300. var handCards = this.logic.handCards(this.chBanker,this.PJHF,this.over,this.recordid,this.ctime);
  1301. if(this.playerAllCount == 4){
  1302. if(this.chBanker == 0) this.logic.isMZWF = [0,1,2,3];/////是不是满足位风
  1303. else if(this.chBanker == 1) this.logic.isMZWF = [3,0,1,2];/////是不是满足位风
  1304. else if(this.chBanker == 2) this.logic.isMZWF = [2,3,0,1];/////是不是满足位风
  1305. else if(this.chBanker == 3) this.logic.isMZWF = [1,2,3,0];/////是不是满足位风
  1306. }
  1307. // }
  1308. else if(this.playerAllCount == 3){
  1309. if(this.chBanker == 0) this.logic.isMZWF = [0,1,2,8];/////是不是满足位风
  1310. else if(this.chBanker == 1) this.logic.isMZWF = [3,0,1,8];/////是不是满足位风
  1311. else if(this.chBanker == 2) this.logic.isMZWF = [2,3,0,8];/////是不是满足位风
  1312. }
  1313. else if(this.playerAllCount == 2){
  1314. if(this.chBanker == 0) this.logic.isMZWF = [0,2,8,8];/////是不是满足位风
  1315. else if(this.chBanker == 1) this.logic.isMZWF = [2,0,8,8];/////是不是满足位风
  1316. }
  1317. //console.warn("ccccccccccccccccccccc当局的圈风",this.logic.fengQuan,this.chBanker);
  1318. let scoreListTL = []
  1319. for (let i = 0; i < this.users.length; ++i) {
  1320. let user = this.users[i];
  1321. if (user) {
  1322. let score = this.score.getScore(user.id);
  1323. scoreListTL[i] = score
  1324. }
  1325. }
  1326. // 掷骰子
  1327. var sttGame = {
  1328. banker: String(this.chBanker),
  1329. qFeng: String(this.quFeng),
  1330. stime: String(Date.now() - this.stime),
  1331. baiDaCard: String(this.logic.baiDaCard),//////TL++,本局百搭牌
  1332. startNum1: String(dice1),////骰子点数
  1333. startNum2: String(dice2),////骰子点数
  1334. setCardFileName: String(this.logic.setCardFileName),////TL++设置手牌的文件名
  1335. scoreListTL:scoreListTL,/////TL++,每个玩家当前的分数列表
  1336. yxndlbTime:this.yxndlbTime,
  1337. yxndlbTip:this.yxndlbTip,
  1338. };
  1339. // console.warn("游侠开始*******************this.chBanker",this.chBanker);
  1340. this.setPaijuHuiFangData(M.START_GAME,sttGame);/////TL++ 牌局回放 push游戏开始
  1341. // 开始通知
  1342. yield this.pushMsgAsync(-1, 'csjiang_event', { type: M.START_GAME, data: sttGame });
  1343. ////// 发手牌原来在这里
  1344. var lastCount = this.logic.leaveCount();/////TL++
  1345. for (let i = 0; i < handCards.length; ++i) {
  1346. this.logic.qshuAnalyze(i,handCards[i].cards);
  1347. // console.warn("发牌判断七首派 i "+i+" " +this.logic.everyQSHType[i]);
  1348. for (let x = 0; x < this.logic.everyQSHType[i].length; ++x) {
  1349. if(this.logic.everyQSHType[i][x] == 1){
  1350. this.masks[i] |= this.maskValeList[x+1];
  1351. }
  1352. }
  1353. }
  1354. let isCanOut = this.logic.getIsCanOut(this.masks);
  1355. for (let i = 0; i < handCards.length; ++i) {
  1356. this.handCards[i] = handCards[i].cards;/////TL++zsyl
  1357. if (i == this.chBanker) {
  1358. let __isHu = false;
  1359. let length = this.handCards[i].length;
  1360. this.logic.isLaGang = false;//////TL++,是否刚刚被拉杠用于判断是否被拉杠胡
  1361. // this.logic.chengBaoTL = [[],[],[],[]];
  1362. // console.error("sscc3333胡牌分析 游戏开始i",i);
  1363. let huRes = this.logic.huAnalyze(i,this.handCards[i], this.handCards[i][length - 1], this.huCards[i], true);
  1364. // console.error("ssccDDD胡牌分析 huRes",huRes);
  1365. if (huRes) {
  1366. // let str3a = "cstable fpphcg:"+this.id + ",uid"+this.handCards[i];
  1367. // logger.info(str3a);////cssj
  1368. __isHu = true;
  1369. this.huRes[i] = huRes;
  1370. }
  1371. let res = this.logic.anGangAnalyze(this.handCards[i]);
  1372. let isGang = (res.length > 0);
  1373. if (isGang){
  1374. for (let x = 0; x < res.length; ++x) {
  1375. if(this.logic.isCanGang(this.handCards[i],this.huCards[i],2,res[x].card)){
  1376. this.masks[i] |= this.maskValeList[0];//能杠肯定就能补
  1377. this.masks[i] |= 8;
  1378. this.keGangInfo.chairId = i;
  1379. this.keGangInfo.data.push({pos:2,card:res[x].card});////可杠信息,因为摸牌之后手上虽然有多个杠,但是没有听牌的话是不能杠的
  1380. }
  1381. else{
  1382. this.masks[i] |= this.maskValeList[0];
  1383. }
  1384. }
  1385. }
  1386. // if (isGang) this.masks[i] |= 8;
  1387. if (__isHu) this.masks[i] |= 16;
  1388. }
  1389. let scards = {
  1390. mask: String(this.masks[i]),
  1391. canSelects: this.logic.canSelects[i],
  1392. cards: handCards[i].cards,
  1393. isCanOut: isCanOut,
  1394. lastCount: String(lastCount)
  1395. };
  1396. if (i == this.chBanker) scards.keGangInfo = this.keGangInfo;
  1397. else scards.keGangInfo = {chairId: -1,data:[]};
  1398. ////发牌的胡牌提示
  1399. if (i == this.chBanker) {
  1400. ////游戏开始时候的庄家的胡牌提示
  1401. scards.hutipdata = this.logic.hutip(this.chBanker,handCards[i].cards,this.huCards[i],this.huCards,this.outCards);////起手发牌调用胡牌提示
  1402. }
  1403. else{
  1404. ////游戏开始时候的闲家的胡牌提示
  1405. scards.hutipdata = {
  1406. renyi:0,//////是否可胡任意牌,0表示不满足1表示满足
  1407. kehuData:[]/////对象数组,分别表示打哪张可胡哪几张数据
  1408. };
  1409. }
  1410. // 发牌通知
  1411. // console.error("sscc发牌通知 4条应该=================",i,handCards.lengt);
  1412. yield this.pushMsgAsync(i, 'csjiang_event', { type: M.SEND_CARD, data: scards });
  1413. }
  1414. let pjhfsplist = {
  1415. shouPai:this.logic.deepCloneTL(this.handCards),
  1416. maskList:this.logic.deepCloneTL(this.masks),/////TL++,10月28号,为了实现能看到每个玩家的操作
  1417. lastCount:String(this.logic.leaveCount())
  1418. }
  1419. this.setPaijuHuiFangData(M.SEND_CARD,pjhfsplist);/////TL++ 牌局回放 push发牌数据
  1420. // 围观通知
  1421. var cardCounts = _.fill(Array(this.ccount), 0);
  1422. for (let i = 0; i < cardCounts.length; ++i) {
  1423. cardCounts[i] = this.handCards[i].length;
  1424. }
  1425. yield this.lookMsgAsync('csjiang_event', { type: M.SEND_CARD, data: { cardCounts: cardCounts, lastCount: String(lastCount) } });
  1426. let str3 = "cstable 222开始游戏---id:"+this.id +","+ this.state;
  1427. logger.warn(str3);////cssj
  1428. return { code: C.OK };
  1429. });
  1430. // 出牌
  1431. proto.outCardAsync = cor(function* (chairId, card) {
  1432. let str3 = "cstable 出牌---id:"+this.id + " ,uid "+chairId+" this.masks "+ this.masks +" card "+card;
  1433. logger.warn(str3);////cssj
  1434. // console.warn("出牌出剖出牌",chairId,this.buhuaTimeout);///// 您正在补花,请稍后出牌。/////TL++,正在补花的时候不允许玩家出牌
  1435. // if(this.buhuaTimeout) return { code: C.FAILD, msg: C.GAME_BUHUA_ING };
  1436. // 校验顺序
  1437. if (this.currentId != chairId) {
  1438. return { code: C.FAILD, msg: C.TABLE_TURN_ERROR };
  1439. }
  1440. // 校验出牌
  1441. if(this.everyIsGang[chairId][0] && this.everyIsGang[chairId][1] != card) {
  1442. return { code: C.FAILD, msg: C.TABLE_CARD_ERROR };
  1443. }
  1444. if(this.autoOutTimer)
  1445. {
  1446. clearTimeout(this.autoOutTimer);
  1447. this.autoOutTimer = null;
  1448. }
  1449. this.keGangInfo = {chairId: -1,data:[]};//可杠信息,因为摸牌之后手上虽然有多个杠,但是没有听牌的话是不能杠的
  1450. this.logic.chuPaiTL()////TL++,统计出牌个数,为了判断天胡和地胡
  1451. if(this.everyIsGang[chairId][0]) this.everyIsGang[chairId][1] = 100;//什么都不能出
  1452. // 吃椪杠胡
  1453. var pos = _.findIndex(this.masks, (m, i) => (i != chairId && m > 0));
  1454. if (pos != -1) {
  1455. return { code: C.FAILD, msg: C.TABLE_TURN_ERROR };
  1456. }
  1457. // 删除手牌
  1458. if (!this.logic.remove(this.handCards[chairId], card)) {
  1459. return { code: C.FAILD, msg: C.TABLE_CARD_ERROR };
  1460. }
  1461. // console.error("cstable 出牌---chairId "+chairId+" this.masks[chairId] "+this.masks[chairId]+" isGuoHuList "+JSON.stringify(this.logic.isGuoHuList));
  1462. if (this.masks[chairId] & 16){
  1463. this.logic.isGuoHuList[chairId][0] = true;/////TL++,设置过胡玩家的是否点击过胡为true 出牌
  1464. let pxgs = 0;
  1465. for (let x = 0; x < this.logic.everyDAHType[chairId].length; ++x) {
  1466. if(this.logic.everyDAHType[chairId][x] == 1) pxgs++;
  1467. }
  1468. this.logic.isGuoHuList[chairId][1] = pxgs;/////TL++,设置过胡玩家的是否点击过胡为true 出牌
  1469. let guohudataTL = {
  1470. chairId:chairId,
  1471. msg: "下次摸牌或满足更大牌型之前将不能胡牌", /////过胡通知
  1472. }
  1473. let isGuoHuList = [[false,-1],[false,-1],[false,-1],[false,-1]];
  1474. isGuoHuList[chairId] = this.logic.isGuoHuList[chairId];
  1475. guohudataTL.isGuoHuList = isGuoHuList;
  1476. ////过胡通知
  1477. yield this.pushMsgAsync(chairId, 'csjiang_event', { type: M.FHGUOHUTIP, data: guohudataTL });
  1478. this.logic.isLaGang = false;//////TL++,是否刚刚被拉杠用于判断是否被拉杠胡
  1479. }
  1480. // 置空权限
  1481. if (this.masks[chairId] > 0) this.masks[chairId] = 0;
  1482. // 置灰的牌
  1483. this.disCards = [];
  1484. // 调整手牌
  1485. this.logic.adjust(this.handCards[chairId]);
  1486. this.outCard = card;
  1487. this.outerId = chairId;
  1488. this.outCards[chairId].push(card);
  1489. // 天胡地胡
  1490. if (this.isTianhu) this.isTianhu = false;
  1491. if (this.isDihus[chairId]) this.isDihus[chairId] = false;
  1492. // 忽略牌
  1493. this.excepts[chairId] = {};
  1494. let sfyrkh = false;//////TL++,是否有人可胡,没有的话海底捞月之后直接结算
  1495. let pjhfsplist = {};
  1496. // 吃碰杠胡
  1497. for (let i = 0; i < this.ccount; ++i) {
  1498. let ocard = { chairId: String(chairId), card: String(card) };
  1499. // 排除自己
  1500. if (i != chairId) {
  1501. ocard.isGuoHuList = [[false,-1],[false,-1],[false,-1],[false,-1]]
  1502. let _isChi = false;
  1503. let isPeng = false;
  1504. let isGang = false;
  1505. let __isHu = false;
  1506. do {
  1507. if(!this.everyIsGang[i][0]){
  1508. // 检测吃牌
  1509. if (this.hasEat && i == (chairId + 1) % this.ccount) {//// 以前是否可吃为可选项
  1510. let ress = this.logic.chiAnalyze(this.handCards[i], card);
  1511. _isChi = (ress.length > 0);
  1512. }
  1513. // 忽略牌
  1514. if (this.excepts[i][card]) break;/////TL++zsyl.同一圈过碰之后不能再次碰的
  1515. // 检测碰牌
  1516. isPeng = this.logic.isPeng(this.handCards[i], card);
  1517. // 忽略牌
  1518. // if (this.excepts[i][card]) break;/////TL++.为了解决同一圈过碰之后不能再次碰的问题
  1519. }
  1520. let res = this.logic.gangAnalyze(this.handCards[i], card);
  1521. isGang = !!res;
  1522. if (isGang){
  1523. // console.error("出牌 函数里面 ");
  1524. if(this.logic.isCanGang(this.handCards[i],this.huCards[i],1,card)){
  1525. if(!this.everyIsGang[i][0]){
  1526. this.masks[i] |= this.maskValeList[0];//能杠肯定就能补
  1527. }
  1528. this.masks[i] |= 8;
  1529. }
  1530. else{
  1531. if(!this.everyIsGang[i][0]){
  1532. this.masks[i] |= this.maskValeList[0];
  1533. }
  1534. }
  1535. }
  1536. this.logic.isLaGang = false;//////TL++,是否刚刚被拉杠用于判断是否被拉杠胡
  1537. let isZNZM = false; //疯狂模式下手上有红中只能自摸
  1538. if(this.gameKindTL == 3 && this.handCards[i].indexOf(51) != -1) isZNZM = true;
  1539. let huRes = (!isZNZM) ? this.logic.huAnalyze(i,this.handCards[i], card, this.huCards[i]) : undefined;
  1540. // console.error("ssccAAA胡牌分析 huRes",huRes);
  1541. if (huRes) {
  1542. // let str3a = "cstable cpphcg:"+this.id + ",uid"+this.handCards[i];
  1543. // logger.info(str3a);////cssj
  1544. __isHu = true;
  1545. this.huRes[i] = huRes;
  1546. }
  1547. } while (0);
  1548. /////TL++,整个if
  1549. if(this.logic.leaveCount() == 0 && this.logic.isZHYZ){
  1550. if (_isChi) _isChi = false;
  1551. if (isPeng) isPeng = false;
  1552. if (isGang) isGang = false;
  1553. if(__isHu) sfyrkh = true
  1554. }
  1555. // 权限掩码
  1556. if (_isChi) this.masks[i] |= 2;
  1557. if (isPeng) this.masks[i] |= 4;
  1558. // if (isGang) this.masks[i] |= 8;
  1559. if (__isHu) this.masks[i] |= 16;
  1560. }
  1561. else{
  1562. let isGuoHuList = [[false,-1],[false,-1],[false,-1],[false,-1]];
  1563. isGuoHuList[chairId] = this.logic.isGuoHuList[chairId];
  1564. ocard.isGuoHuList = isGuoHuList;
  1565. this.changeCurrQSHInfo(chairId,M.OUT_CARD,0,card);
  1566. }
  1567. ocard.mask = String(this.masks[i]);
  1568. ocard.keGangInfo = this.keGangInfo;
  1569. // 出牌通知
  1570. yield this.pushMsgAsync(i, 'csjiang_event', { type: M.OUT_CARD, data: ocard });
  1571. if (i == chairId) {
  1572. // let pjhfcp = ocard
  1573. // pjhfcp.allMask = this.masks;
  1574. pjhfsplist = {
  1575. shouPai:this.logic.deepCloneTL(this.handCards),
  1576. lastCount:String(this.logic.leaveCount()),
  1577. ocard:this.logic.deepCloneTL(ocard),
  1578. outCards:this.logic.deepCloneTL(this.outCards),
  1579. isGuoHuList:this.logic.deepCloneTL(this.logic.isGuoHuList)
  1580. }
  1581. }
  1582. if(i == (this.ccount - 1)){/////TL++if条件判断,10月28号,为了实现能看到每个玩家的操作
  1583. pjhfsplist.maskList = this.logic.deepCloneTL(this.masks);/////TL++,10月28号,为了实现能看到每个玩家的操作
  1584. this.setPaijuHuiFangData(M.OUT_CARD,pjhfsplist);/////TL++ 牌局回放 push出牌数据
  1585. }
  1586. }
  1587. // 被杠玩家
  1588. this.gangOuter = -1;
  1589. // 围观通知
  1590. yield this.lookMsgAsync('csjiang_event', { type: M.OUT_CARD, data: { chairId: String(chairId), card: String(card) } });
  1591. // 全无权限
  1592. for (let i = 0; i < this.ccount; ++i) {
  1593. if (this.masks[i] != 0) break;
  1594. // 切换用户
  1595. if (i == this.ccount - 1) {
  1596. // 下家摸牌
  1597. let nextId = (chairId + 1) % this.ccount;
  1598. ///////TL++,整个if,因为海底捞月需要玩家自己去判断要不要摸牌
  1599. // console.warn("000 声剩余声剩余声剩");
  1600. let lastCount = this.logic.leaveCount();/////TL++xg
  1601. yield this.touchCardAsync(nextId); ///////出牌摸牌
  1602. }
  1603. }
  1604. let str4 = "cstable end出牌---id:"+this.id + " ,uid "+chairId+" this.masks "+ this.masks +" card "+card;
  1605. logger.warn(str4);////cssj
  1606. return { code: C.OK };
  1607. });
  1608. ///////杠后摸牌函数 摸2张,有一张能胡则直接胡不能胡则两张直接打出 参数ifGang是否因为杠而摸牌
  1609. proto.touchCardAfterGang = cor(function* (chairId,ifGang) {
  1610. // 状态校验
  1611. if (this.state != STATE.PLAYING) return;
  1612. if (this.winner.chs.length > 0 || !this.users[chairId]) return;
  1613. if (this.logic.isGuoHuList[chairId][0]) this.logic.isGuoHuList[chairId] = [false,-1];/////TL++,设置过胡玩家的是否点击过胡为false; 杠后摸牌
  1614. // 当前顺序
  1615. // this.currentId = chairId;
  1616. // 摸牌
  1617. this.keGangInfo = {chairId: -1,data:[]};////可杠信息,因为摸牌之后手上虽然有多个杠,但是没有听牌的话是不能杠的
  1618. let isG = (ifGang && (ifGang == 1) || (ifGang == 2) || (ifGang == 3))
  1619. // console.warn("<<<<<<<<< isG,ifGang ",isG,ifGang)
  1620. var moCard = this.logic.moCard(true);
  1621. //因为开杠之后要摸2张牌所以要执行两遍下面这个方法
  1622. this.logic.moPaiTL();
  1623. this.logic.moPaiTL();
  1624. let moPaiIsCanHu = false;//////TL++,摸牌的人是否可以胡牌
  1625. this.everyIsGang[chairId] = [1,0];
  1626. let lastCount22 = this.logic.leaveCount();/////TL++xg
  1627. this.logic.isLaGang = false;//////TL++,是否刚刚被拉杠用于判断是否被拉杠胡
  1628. let pjhfsplist = {};
  1629. if(ifGang){ /////杠牌,1-普通杠, 2-暗杠, 3-自摸明杠
  1630. if(ifGang == 1) this.logic.isGGMG[chairId] = true;//////TL++,是否刚刚直杠(明杠)用于判断是否是直杠杠开
  1631. if(ifGang == 2) this.logic.isGGAG[chairId] = true;//////TL++,是否刚暗杠用于判断是否暗杠杠开
  1632. if(ifGang == 3) this.logic.isGGFXG[chairId] = true;//////TL++,是否刚刚风险杠用于判断是否风险杠杠开
  1633. }
  1634. this.keGangInfo = {chairId: -1,data:[]};////可杠信息,因为摸牌之后手上虽然有多个杠,但是没有听牌的话是不能杠的
  1635. for (let i = 0; i < this.ccount; ++i) {
  1636. let __isHu = false;
  1637. // let handCards1 = this.logic.deepCloneTL(this.handCards[chairId]);
  1638. // handCards1.push(moCard.card1);
  1639. let huRes1 = this.logic.huAnalyze(i,this.handCards[i], moCard.card1, this.huCards[i], false);//杠后摸牌判断第1张
  1640. // console.error("ssccBBB胡牌分析 huRes1",huRes1);
  1641. if (huRes1) {
  1642. // this.handCards[i].push(moCard.card1);
  1643. __isHu = true;
  1644. moPaiIsCanHu = true;/////TL++
  1645. this.huRes[i] = huRes1;
  1646. }
  1647. if (!__isHu){
  1648. // let handCards2 = this.logic.deepCloneTL(this.handCards[chairId]);
  1649. // handCards2.push(moCard.card2);
  1650. let huRes2 = this.logic.huAnalyze(i,this.handCards[i], moCard.card2, this.huCards[i], false);//杠后摸牌判断第2张
  1651. // console.error("ssccBBB胡牌分析 huRes2",huRes2);
  1652. if (huRes2) {
  1653. // let str3a = "cstable mpphcg:"+this.id + ",uid"+this.handCards[i];
  1654. // logger.info(str3a);////cssj
  1655. // this.handCards[i].push(moCard.card2);
  1656. __isHu = true;
  1657. moPaiIsCanHu = true;/////TL++
  1658. this.huRes[i] = huRes2;
  1659. }
  1660. }
  1661. if (__isHu){
  1662. this.masks[i] |= 16;
  1663. }
  1664. let canSelectData = [];
  1665. //杠过的人不能吃碰补,可杠可胡
  1666. if(!this.everyIsGang[i][0]){
  1667. if (this.hasEat && i == (chairId + 1) % this.ccount) {//// 以前是否可吃为可选项 只能自摸情况下不能吃
  1668. let canChiList = [];
  1669. let ress = this.logic.chiAnalyze(this.handCards[i], moCard.card1);
  1670. let _isChi1 = (ress.length > 0);
  1671. if(_isChi1) canChiList[canChiList.length] = moCard.card1;
  1672. let ress2 = this.logic.chiAnalyze(this.handCards[i], moCard.card2);
  1673. let _isChi2 = (ress2.length > 0);
  1674. if(_isChi2) canChiList[canChiList.length] = moCard.card2;
  1675. if(_isChi1 || _isChi2){
  1676. this.masks[i] |= 2;
  1677. canSelectData.push({type:2,cards:canChiList})
  1678. }
  1679. }
  1680. let canPengList = [];
  1681. let isPeng1 = this.logic.isPeng(this.handCards[i], moCard.card1);
  1682. if(isPeng1) canPengList[canPengList.length] = moCard.card1;
  1683. let isPeng2 = this.logic.isPeng(this.handCards[i], moCard.card2);
  1684. if(isPeng2) canPengList[canPengList.length] = moCard.card2;
  1685. if(isPeng1 || isPeng2){
  1686. this.masks[i] |= 4;
  1687. canSelectData.push({type:4,cards:canPengList})
  1688. }
  1689. }
  1690. let canGangList = [];
  1691. let canBuList = [];
  1692. let isGang1 = false;
  1693. let isBu1 = false;
  1694. let res = this.logic.gangAnalyze(this.handCards[i], moCard.card1);
  1695. if(!!res){
  1696. if(!this.everyIsGang[i][0]){
  1697. isBu1 = true
  1698. canBuList[canBuList.length] = {pos:1,card:moCard.card1};
  1699. }
  1700. if(this.logic.isCanGang(this.handCards[i],this.huCards[i],1,moCard.card1)){
  1701. isGang1 = true;
  1702. canGangList[canGangList.length] = {pos:1,card:moCard.card1};
  1703. }
  1704. }
  1705. else{
  1706. if(i == chairId){
  1707. let handCards1 = this.logic.deepCloneTL(this.handCards[chairId]);
  1708. handCards1.push(moCard.card1);
  1709. let res1 = this.logic.zmGangAnalyze(handCards1, this.huCards[i],moCard.card1);
  1710. // console.warn(">>>>>>>杠后两张牌 res1 "+JSON.stringify(res1));
  1711. if((res1.length > 0)){
  1712. if(!this.everyIsGang[i][0]){
  1713. isBu1 = true
  1714. canBuList[canBuList.length] = {pos:3,card:moCard.card1};
  1715. }
  1716. if(this.logic.isCanGang(handCards1,this.huCards[i],3,moCard.card1)){
  1717. isGang1 = true;
  1718. canGangList[canGangList.length] = {pos:3,card:moCard.card1};
  1719. }
  1720. }
  1721. }
  1722. }
  1723. let isGang2 = false;
  1724. let isBu2 = false;
  1725. let res2 = this.logic.gangAnalyze(this.handCards[i], moCard.card2);
  1726. if(!!res2){
  1727. if(!this.everyIsGang[i][0]){
  1728. isBu2 = true
  1729. canBuList[canBuList.length] = {pos:1,card:moCard.card2};
  1730. }
  1731. if(this.logic.isCanGang(this.handCards[i],this.huCards[i],1,moCard.card2)){
  1732. isGang2 = true;
  1733. canGangList[canGangList.length] = {pos:1,card:moCard.card2};
  1734. }
  1735. }
  1736. else{
  1737. if(i == chairId){
  1738. let handCards1 = this.logic.deepCloneTL(this.handCards[chairId]);
  1739. handCards1.push(moCard.card2);
  1740. let res3 = this.logic.zmGangAnalyze(handCards1,this.huCards[i],moCard.card2);
  1741. // console.warn(">>>>>>>杠后两张牌 res3 "+JSON.stringify(res3));
  1742. if((res3.length > 0)){
  1743. if(!this.everyIsGang[i][0]){
  1744. isBu2 = true
  1745. canBuList[canBuList.length] = {pos:3,card:moCard.card2};
  1746. }
  1747. if(this.logic.isCanGang(handCards1,this.huCards[i],3,moCard.card2)){
  1748. isGang2 = true;
  1749. canGangList[canGangList.length] = {pos:3,card:moCard.card2};
  1750. }
  1751. }
  1752. }
  1753. }
  1754. // console.warn(">>>>>>>杠后两张牌 canGangList "+JSON.stringify(canGangList));
  1755. if(isGang1 || isGang2){
  1756. this.masks[i] |= 8;
  1757. canSelectData.push({type:8,cards:canGangList})
  1758. }
  1759. if(isBu1 || isBu2){
  1760. this.masks[i] |= this.maskValeList[0];
  1761. canSelectData.push({type:this.maskValeList[0],cards:canBuList})
  1762. }
  1763. let data = {
  1764. chairId: chairId,
  1765. keGangInfo: this.keGangInfo,
  1766. cards: moCard,
  1767. canSelectData: canSelectData,
  1768. isGangInfo: this.everyIsGang[chairId],/////每个人是否杠了,如果杠了就只能摸啥打啥了
  1769. mask: this.masks[i]
  1770. }
  1771. // console.warn("杠后两张牌=== ",i,this.masks[i],this.masks);
  1772. this.gangAfterData.canSelectData[i] = canSelectData;
  1773. yield this.pushMsgAsync(i, 'csjiang_event', { type: M.GANGAFTER, data: data });
  1774. }
  1775. this.gangAfterData.chairId = chairId;
  1776. this.gangAfterData.cards = moCard;
  1777. pjhfsplist = {
  1778. chairId: chairId,
  1779. cards: moCard,
  1780. canSelectData: [],
  1781. mask: this.masks
  1782. }
  1783. this.setPaijuHuiFangData(M.GANGAFTER,pjhfsplist);/////TL++ 牌局回放 push摸牌数据
  1784. let str3 = "cstable 杠牌之后 id:"+this.id + " ,uid "+chairId+" ,this.masks "+ this.masks +" card1 "+moCard.card1+" card2 "+moCard.card2;
  1785. logger.warn(str3);////cssj
  1786. // 围观通知
  1787. let wgdata = {
  1788. chairId: chairId,
  1789. cards: moCard,
  1790. canSelectData: [],
  1791. mask: 0
  1792. }
  1793. yield this.lookMsgAsync('csjiang_event', { type: M.GANGAFTER, data: wgdata });
  1794. let isqwqx = true;//是否全无吃碰胡权限
  1795. for (var i = 0; i < this.masks.length; i++) {
  1796. if(this.masks[i] > 0){
  1797. isqwqx = false;
  1798. break;
  1799. }
  1800. }
  1801. if(isqwqx){
  1802. // console.error("开始定时器=====000");
  1803. if(!this.updataGangTimer){
  1804. this.updataGangTimer = this.app.timer.setTimeout(() =>
  1805. {
  1806. // console.error("开始定时器=====111");
  1807. if(this.updataGangTimer)
  1808. {
  1809. clearTimeout(this.updataGangTimer);
  1810. this.updataGangTimer = null;
  1811. }
  1812. let nextId = (this.gangAfterData.chairId + 1) % this.ccount;
  1813. // console.error("开始定时器=====222 "+nextId);
  1814. //全无吃碰胡权限,给下家发牌
  1815. this.updateGangafterData(chairId,moCard);
  1816. this.touchCardAsync(nextId); ///////杠后两张牌无权限摸牌
  1817. }
  1818. , 2000);//延迟2秒开始游戏
  1819. }
  1820. }
  1821. return { code: C.OK };
  1822. });
  1823. //更新杠后两张牌状态信息 杠后两张牌没有人可以操作或者操作之后清空gangAfterData和每个人的出牌列表
  1824. proto.updateGangafterData = cor(function* (chairId,moCard) {
  1825. // console.error("更新杠后两张牌状态信息 重置了杠后数据 "+chairId);
  1826. this.gangAfterData = {//清空杠后2张牌信息
  1827. chairId: -1,
  1828. cards: {card1:0,card2:0},
  1829. canSelectData: [[],[],[],[]],
  1830. mask: 0
  1831. }
  1832. this.logic.isGGMG = [false,false,false,false];;//////TL++,是否刚刚直杠(明杠)用于判断是否是直杠杠开
  1833. this.logic.isGGAG = [false,false,false,false];//////TL++,是否刚暗杠用于判断是否暗杠杠开
  1834. this.logic.isGGFXG = [false,false,false,false];//////TL++,是否刚刚风险杠用于判断是否风险杠杠开
  1835. let lastCount22 = this.logic.leaveCount();/////TL++xg
  1836. let update = {
  1837. gangAfterData: this.gangAfterData,
  1838. lastCount: String(lastCount22),
  1839. addOutCards:{chairId: chairId,addOut: moCard}
  1840. }
  1841. let card1 = moCard.card1;
  1842. let card2 = moCard.card2;
  1843. if(card1 > 0)this.outCards[chairId].push(card1);
  1844. if(card2 > 0)this.outCards[chairId].push(card2);
  1845. let pjhfsplist = this.logic.deepCloneTL(update)
  1846. pjhfsplist.outCards = this.logic.deepCloneTL(this.outCards);
  1847. this.setPaijuHuiFangData(M.UPDATEGANGAFTER,pjhfsplist);/////TL++ 牌局回放 push摸牌数据
  1848. yield this.pushMsgAsync(-1, 'csjiang_event', { type: M.UPDATEGANGAFTER, data: update });
  1849. // yield this.lookMsgAsync('csjiang_event', { type: M.UPDATEGANGAFTER, data: update });
  1850. })
  1851. proto.autoOutCard = cor(function* (moCard) {
  1852. let isGangHou = this.everyIsGang[this.currentId][0] && this.everyIsGang[this.currentId][1] > 0 && this.everyIsGang[this.currentId][1] < 60
  1853. let str1 = "cstable自动出牌 id:"+this.id +" "+this.currentId+" "+this.everyIsAutoOut+" "+isGangHou+" "+this.masks + " "+moCard;
  1854. logger.warn(str1);////cssj
  1855. if(this.masks[this.currentId] == 0 && (isGangHou || this.everyIsAutoOut[this.currentId])) {
  1856. //杠后或者选择了自动出牌
  1857. if(!this.autoOutTimer){
  1858. this.autoOutTimer = this.app.timer.setTimeout(() =>
  1859. {
  1860. // console.error("开始定时器=====111 moCard "+moCard);
  1861. if(this.autoOutTimer)
  1862. {
  1863. let str2 = "cstable删除定时器 id:"+this.id +" moCard "+moCard;
  1864. logger.warn(str2);////cssj
  1865. clearTimeout(this.autoOutTimer);
  1866. this.autoOutTimer = null;
  1867. }
  1868. if(isGangHou){
  1869. let str3 = "cstable 自动出牌gh id:"+this.id + " ,uid "+this.currentId+" ,this.masks "+ this.masks +" isGangHou "+isGangHou+" card "+this.everyIsGang[this.currentId][1];
  1870. logger.warn(str3);////cssj
  1871. this.outCardAsync(this.currentId,this.everyIsGang[this.currentId][1]);
  1872. }
  1873. else{
  1874. let str3 = "cstable 自动出牌 id:"+this.id + " ,uid "+this.currentId+" ,this.masks "+ this.masks +" isGangHou "+isGangHou+" card "+moCard;
  1875. logger.warn(str3);////cssj
  1876. this.outCardAsync(this.currentId,moCard);
  1877. }
  1878. }
  1879. , 1100);//各玩家均没有操作的情况下延迟2秒更新杠后两张牌的状态
  1880. }
  1881. }
  1882. return;
  1883. })
  1884. ///////摸牌函数 参数ifGang是否因为杠而摸牌 TL++ ,为了判断是否花杠杠开 是否最后一张的海底捞月
  1885. proto.touchCardAsync = cor(function* (chairId,ifGang,ishdly) {
  1886. // if(this.buhuaTimeout) {
  1887. // clearTimeout(this.buhuaTimeout);
  1888. // this.buhuaTimeout = null;
  1889. // }
  1890. // 状态校验
  1891. if (this.state != STATE.PLAYING) return;
  1892. if (this.winner.chs.length > 0 || !this.users[chairId]) return;
  1893. if(this.logic.isGuoHuList[chairId][0]) this.logic.isGuoHuList[chairId] = [false,-1];/////TL++,设置过胡玩家的是否点击过胡为false; 摸牌
  1894. this.keGangInfo = {chairId: -1,data:[]};////可杠信息,因为摸牌之后手上虽然有多个杠,但是没有听牌的话是不能杠的
  1895. let isyrxzhdly =_.findIndex(this.everyHDLY, (m, i) => (m == 1)) != -1;//是否有人选择海底捞月
  1896. if(!isyrxzhdly && this.logic.leaveCount() == 1 ){
  1897. // console.warn("判断海底捞月 ");
  1898. let targetId = -1
  1899. let nextId = -1;
  1900. for (let i = 0; i < this.ccount; ++i) {
  1901. if(i == 0) nextId = chairId;
  1902. else nextId = (nextId + 1) % this.ccount;
  1903. if(this.everyHDLY[nextId] >= 0) continue;
  1904. // console.warn("开始检查听牌准备海底捞月");
  1905. if(this.logic.checkTing(this.handCards[nextId],this.huCards[nextId])){
  1906. // console.warn("判断海底捞月222 停牌了 nextId "+nextId);
  1907. targetId = nextId;
  1908. break;
  1909. }
  1910. }
  1911. // console.warn("判断海底捞月333 targetId "+targetId);
  1912. if(targetId >= 0){
  1913. let guohudataTL = {
  1914. chairId:targetId,
  1915. msg: "是否“海底捞月”?", /////海底捞月通知
  1916. }
  1917. this.logic.isZHYZ = true;/////是不是最后1张
  1918. yield this.pushMsgAsync(targetId, 'csjiang_event', { type: M.FHLASTCARDTIP, data: guohudataTL }); //////海底捞月通知 放弃操作中调用摸牌函数
  1919. let strx = "cstable 摸 询问海底 id:"+this.id + " ,uid "+targetId+" ,this.masks "+ this.masks;
  1920. logger.warn(strx);////cssj
  1921. // this.setPaijuHuiFangData(M.FHLASTCARDTIP,guohudataTL);/////TL++ 牌局回放 push海底捞月数据 放弃操作
  1922. return { code: C.OK };
  1923. }
  1924. else{
  1925. this.logic.lastMoPaiChairID = chairId;//最后都没有听牌,就流局,按照顺序摸海底的那位玩家当庄家
  1926. yield this.concludeGameAsync(MODE.NOCARD);
  1927. return { code: C.OK };
  1928. }
  1929. }
  1930. if(this.logic.leaveCount() > 1 ) this.logic.isZHYZ = false;
  1931. // 当前顺序
  1932. this.currentId = chairId;
  1933. // 摸牌
  1934. // var moCard = this.logic.moCard();TL++zsyl
  1935. ////TL++
  1936. var moCard = { card: 0 };
  1937. let isG = (ifGang && (ifGang == 1) || (ifGang == 2) || (ifGang == 3))
  1938. // console.warn("<<<<<<<<<",isG,ifGang)
  1939. moCard = this.logic.moCard();
  1940. this.logic.moPaiTL();
  1941. let moPaiIsCanHu = false;//////TL++,摸牌的人是否可以胡牌
  1942. let ischange = false;
  1943. if(this.gangAfterData.chairId != -1){
  1944. let csc = this.logic.deepCloneTL(this.gangAfterData.cards);
  1945. yield this.updateGangafterData(this.gangAfterData.chairId,csc);
  1946. }
  1947. this.logic.isGGMG = [false,false,false,false];//////TL++,是否刚刚直杠(明杠)用于判断是否是直杠杠开
  1948. this.logic.isGGAG = [false,false,false,false];//////TL++,是否刚暗杠用于判断是否暗杠杠开
  1949. this.logic.isGGFXG = [false,false,false,false];//////TL++,是否刚刚风险杠用于判断是否风险杠杠开
  1950. // 是否流局
  1951. if (moCard.card <= 0) {
  1952. // console.warn("提前结算888");
  1953. yield this.concludeGameAsync(MODE.NOCARD);
  1954. return { code: C.OK };
  1955. }
  1956. if(this.everyIsGang[chairId][0]) this.everyIsGang[chairId][1] = moCard.card;
  1957. let lastCount22 = this.logic.leaveCount();/////TL++xg
  1958. let pjhfsplist = {};
  1959. let __isHu2 = false;
  1960. for (let i = 0; i < this.ccount; ++i) {
  1961. let touchCard = { currentId: String(chairId), touch: '0',lastCount : '0' };
  1962. // console.warn("1111WWWWWWWTTTTTT",i,chairId,moCard.card);
  1963. touchCard.isGangInfo = [0,0];/////每个人是否杠了,如果杠了就只能摸啥打啥了 = [0,0];
  1964. if (i == chairId) {
  1965. touchCard.touch = String(moCard.card);
  1966. touchCard.isGangInfo = this.everyIsGang[chairId];/////每个人是否杠了,如果杠了就只能摸啥打啥了 = this.everyIsGang[chairId];
  1967. // this.handCards[i].push(moCard.card);/////TL++zsyl
  1968. this.handCards[i].push(moCard.card);/////TL++,因为在补花的时候已经将新发的牌放进手牌里了所以这里不用push
  1969. let __isHu = false;
  1970. // console.error("sscc111胡牌分析 摸牌 i",i);
  1971. this.logic.isLaGang = false;//////TL++,是否刚刚被拉杠用于判断是否被拉杠胡
  1972. // this.logic.chengBaoTL = [[],[],[],[]];////别人放弃拉杠之后还没想好要怎么清空,因为不清空也行
  1973. // console.warn("222摸牌的时候设置刚才是否有杠",i,ifGang,this.logic.isGGMG,this.logic.isGGAG,this.logic.isGGFXG);
  1974. let huRes = this.logic.huAnalyze(i,this.handCards[i], moCard.card, this.huCards[i], true);//摸牌函数判胡
  1975. // console.error("ssccBBB胡牌分析 huRes",huRes);
  1976. if (huRes) {
  1977. // let str3a = "cstable mpphcg:"+this.id + ",uid"+this.handCards[i];
  1978. // logger.info(str3a);////cssj
  1979. __isHu = true;
  1980. if(this.logic.isZHYZ) __isHu2 = true;
  1981. moPaiIsCanHu = true;/////TL++
  1982. this.huRes[i] = huRes;
  1983. }
  1984. if(!this.logic.isZHYZ){
  1985. let res1 = this.logic.anGangAnalyze(this.handCards[i]);
  1986. let isGang1 = (res1.length > 0);
  1987. let res2 = this.logic.zmGangAnalyze(this.handCards[i], this.huCards[i]);
  1988. let isGang2 = (res2.length > 0);
  1989. let res = [];
  1990. let isGang = isGang1 || isGang2;
  1991. if(isGang1) res = res.concat(res1);//暗杠
  1992. if(isGang2) res = res.concat(res2);//自摸杠
  1993. if(isGang){
  1994. for (let x = 0; x < res.length; ++x) {
  1995. if(this.logic.isCanGang(this.handCards[i],this.huCards[i],res[x].type,res[x].card)){
  1996. if(!this.everyIsGang[i][0]){
  1997. this.masks[i] |= this.maskValeList[0];//能杠肯定就能补
  1998. }
  1999. this.masks[i] |= 8;
  2000. this.keGangInfo.chairId = i;
  2001. this.keGangInfo.data.push({pos:res[x].type,card:res[x].card});////可杠信息,因为摸牌之后手上虽然有多个杠,但是没有听牌的话是不能杠的
  2002. }
  2003. else{
  2004. if(!this.everyIsGang[i][0]){
  2005. this.masks[i] |= this.maskValeList[0];
  2006. }
  2007. }
  2008. }
  2009. }
  2010. }
  2011. if (__isHu) this.masks[i] |= 16;
  2012. this.logic.qshuAnalyze(i,this.handCards[i]);
  2013. this.currQSHInfo[chairId] = []//当前各个玩家展示的起手胡信息
  2014. // console.warn("摸牌判断小胡 i "+i+" " +this.logic.everyQSHType[i]);
  2015. for (let x = 0; x < this.logic.everyQSHType[i].length; ++x) {
  2016. if(this.logic.everyQSHType[i][x] == 1){
  2017. this.masks[i] |= this.maskValeList[x+1];
  2018. }
  2019. }
  2020. ////摸排时候的摸排玩家的胡牌提示
  2021. let hutipdataTL = this.logic.hutip(i,this.handCards[i],this.huCards[i],this.huCards,this.outCards);////摸牌时调用胡牌提示
  2022. touchCard.hutipdata = hutipdataTL;
  2023. let isGuoHuList = [[false,-1],[false,-1],[false,-1],[false,-1]];
  2024. isGuoHuList[chairId] = this.logic.isGuoHuList[chairId];
  2025. touchCard.isGuoHuList = isGuoHuList;
  2026. touchCard.canSelects = this.logic.canSelects[i]
  2027. }
  2028. else {
  2029. this.masks[i] = 0;
  2030. touchCard.hutipdata = {
  2031. renyi:0,//////是否可胡任意牌,0表示不满足1表示满足
  2032. kehuData:[]/////对象数组,分别表示打哪张可胡哪几张数据
  2033. };
  2034. touchCard.isGuoHuList = [[false,-1],[false,-1],[false,-1],[false,-1]]
  2035. touchCard.canSelects = [];
  2036. }
  2037. touchCard.mask = String(this.masks[i]);
  2038. touchCard.lastCount = String(lastCount22);
  2039. if (i == chairId) touchCard.keGangInfo = this.keGangInfo;
  2040. else touchCard.keGangInfo = {chairId: -1,data:[]};
  2041. this.logic.lastMoPaiChairID = this.currentId;
  2042. // 摸牌通知
  2043. // console.warn("222WWWWWWWTTTTTT",i,chairId,moCard.card);
  2044. yield this.pushMsgAsync(i, 'csjiang_event', { type: M.TOUCH_CARD, data: touchCard});
  2045. if (i == chairId) {
  2046. pjhfsplist = {
  2047. shouPai:this.logic.deepCloneTL(this.handCards),
  2048. lastCount:String(this.logic.leaveCount()),
  2049. touchCard:this.logic.deepCloneTL(touchCard),
  2050. outCards:this.logic.deepCloneTL(this.outCards),
  2051. canSelects: this.logic.canSelects[i],
  2052. isGuoHuList:this.logic.deepCloneTL(this.logic.isGuoHuList)
  2053. }
  2054. }
  2055. if(i == (this.ccount - 1)){/////TL++if条件判断,10月28号,为了实现能看到每个玩家的操作
  2056. pjhfsplist.maskList = this.logic.deepCloneTL(this.masks);/////TL++,10月28号,为了实现能看到每个玩家的操作
  2057. this.setPaijuHuiFangData(M.TOUCH_CARD,pjhfsplist);/////TL++ 牌局回放 push摸牌数据
  2058. }
  2059. }
  2060. let str3 = "cstable 摸牌函数id:"+this.id + " ,uid "+chairId+" ,this.masks "+ this.masks +" card "+moCard.card;
  2061. logger.warn(str3);////cssj
  2062. // 围观通知
  2063. // return this.lookMsgAsync('csjiang_event', { type: M.TOUCH_CARD, data: { currentId: String(chairId),lastCount:String(lastCount22)} });
  2064. yield this.lookMsgAsync('csjiang_event', { type: M.TOUCH_CARD, data: { currentId: String(chairId),lastCount:String(lastCount22)} });
  2065. if(this.logic.isZHYZ){
  2066. //如果是海底捞月,能胡直接胡不能胡直接打出
  2067. if (__isHu2) return this.succCardAsync(chairId).then(() => ({ code: C.OK }));
  2068. else return this.outCardAsync(chairId,moCard.card).then(() => ({ code: C.OK }));
  2069. }
  2070. yield this.autoOutCard(moCard.card);
  2071. return { code: C.OK };
  2072. });
  2073. // 放弃操作
  2074. proto.giveUpAsync = cor(function* (chairId) {
  2075. let str3 = "cstable 放弃操作id: "+this.id + " ,uid "+chairId+", this.masks "+ this.masks;
  2076. logger.warn(str3);////cssj
  2077. // 权限掩码
  2078. var mask = this.masks[chairId];
  2079. if (mask <= 0) {
  2080. return { code: C.FAILD, msg: C.TABLE_MASK_ERROR };
  2081. }
  2082. if(chairId == this.currentId){
  2083. let isGangHou = this.everyIsGang[this.currentId][0] && this.everyIsGang[this.currentId][1] > 0 && this.everyIsGang[this.currentId][1] < 60
  2084. if((mask & 16) && isGangHou && this.everyIsGang[this.currentId][1] == 51) {
  2085. return { code: C.FAILD, msg: C.TABLE_NOTOUTHZGUOSB };
  2086. }
  2087. }
  2088. if(chairId == this.keGangInfo.chairId){
  2089. this.keGangInfo = {chairId: -1,data:[]};////可杠信息,因为摸牌之后手上虽然有多个杠,但是没有听牌的话是不能杠的
  2090. }
  2091. // console.warn("111放弃操作放弃操作放弃操作放弃操作放弃操作chairId,this.masks",chairId,this.masks,(mask & 16));
  2092. if (mask & 16) {////mask = 16~31时结果=16这个if能进去 0~15或者32~47之间结果=0这个if进不去
  2093. // console.warn("放弃操作里设置过胡为true",chairId, this.logic.isLaGang,this.logic.isGuoHuList,this.logic.everyAllTaiShu);
  2094. this.logic.isGuoHuList[chairId][0] = true;/////TL++,设置过胡玩家的是否点击过胡为true 点击过按钮
  2095. let pxgs = 0;
  2096. for (let x = 0; x < this.logic.everyDAHType[chairId].length; ++x) {
  2097. if(this.logic.everyDAHType[chairId][x] == 1) pxgs++;
  2098. }
  2099. this.logic.isGuoHuList[chairId][1] = pxgs;/////TL++,设置过胡玩家的是否点击过胡为true 出牌
  2100. let guohudataTL = {
  2101. chairId:chairId,
  2102. msg: "下次摸牌或满足更大牌型之前将不能胡牌", /////过胡通知
  2103. }
  2104. let isGuoHuList = [[false,-1],[false,-1],[false,-1],[false,-1]];
  2105. isGuoHuList[chairId] = this.logic.isGuoHuList[chairId];
  2106. guohudataTL.isGuoHuList = isGuoHuList;
  2107. //////过胡通知
  2108. yield this.pushMsgAsync(chairId, 'csjiang_event', { type: M.FHGUOHUTIP, data: guohudataTL });
  2109. if(this.logic.leaveCount() > 0){/////TL++
  2110. this.lgkhCount -= 1;/////TL++拉杠可胡玩家的数量
  2111. }
  2112. // console.warn("666拉杠胡%%%%%%%%%%%%%%%%%%%%%%",this.logic.isLaGang);
  2113. }
  2114. // 删除权限
  2115. this.masks[chairId] = 0;
  2116. // console.warn("放弃操作 "+this.currentId +" "+ chairId+" "+this.masks);
  2117. // 是否自摸
  2118. if (this.currentId == chairId) {
  2119. let isCanOut = this.logic.getIsCanOut(this.masks);
  2120. if(isCanOut){
  2121. //////麻将过牌通知,用于隐藏手牌遮罩
  2122. let fqdata = {
  2123. isGangInfo: this.everyIsGang[chairId],
  2124. isCanOut: isCanOut
  2125. }
  2126. yield this.pushMsgAsync(this.currentId, 'csjiang_event', { type: M.GIVE_UP, data:fqdata });
  2127. }
  2128. let qtrsfhycz = false;//其他人是否还有操作
  2129. for (let i = 0; i < this.masks.length; ++i) {
  2130. if(this.masks[i] > 0){
  2131. qtrsfhycz = true;
  2132. break;
  2133. }
  2134. }
  2135. if(!qtrsfhycz){
  2136. // console.warn("放弃操作 其他人都没有操作了 ");
  2137. if(this.gangAfterData.chairId != -1){
  2138. let nextId = (this.gangAfterData.chairId + 1) % this.ccount;
  2139. yield this.updateGangafterData(this.gangAfterData.chairId,this.gangAfterData.cards);
  2140. // console.warn("放弃操作 这里发排列 ");
  2141. yield this.touchCardAsync(nextId); ///////放弃操作杠后两张牌之后发牌
  2142. }
  2143. return { code: C.OK };
  2144. }
  2145. }
  2146. // 忽略牌
  2147. if (this.outCard) {
  2148. let except = this.excepts[chairId];
  2149. except[this.outCard] = this.outCard;
  2150. }
  2151. // console.warn("放弃操作里 mask "+mask + " "+(mask & 16)+" "+this.gangAfterData.chairId);
  2152. // 放弃胡牌
  2153. let isfqhp = false;//是否放弃胡牌
  2154. if (mask & 16) isfqhp = true;
  2155. if(!isfqhp){
  2156. for (var x = 1; x < this.maskValeList.length; x++) {
  2157. if(mask & this.maskValeList[x]){
  2158. isfqhp = true;
  2159. break;
  2160. }
  2161. }
  2162. }
  2163. if (isfqhp){//(mask & 16) {////mask = 16~31时结果=16这个if能进去 0~15或者32~47之间结果=0这个if进不去
  2164. let winner = this.winner;
  2165. do {
  2166. // 一炮多响
  2167. if (this.isMHu) {
  2168. let __cHu = _.findIndex(this.masks, (m) => (m & 16));//////
  2169. // console.warn("?????? "+this.gangAfterData.chairId);
  2170. // console.warn("允许一炮多想 放弃操作放弃操作放弃操作this.isMHu,__cHu",this.isGangHu,this.isMHu,__cHu);
  2171. if (__cHu != -1){
  2172. let __cHuDengDai = _.findIndex(this.masks, (m) => (m == 17));//////
  2173. if(__cHuDengDai == -1) {
  2174. break;
  2175. }
  2176. else {
  2177. // console.warn("放弃这里调用了胡牌",winner.chs.length,__cHuDengDai)
  2178. return this.succCardAsync(__cHuDengDai).then(() => ({ code: C.OK }));
  2179. }
  2180. }
  2181. // else{
  2182. // 有人胡牌
  2183. if (winner.chs.length > 0) {
  2184. // console.warn("允许一炮多想 操作放弃操作放弃操作winner.chs",winner.chs);
  2185. yield this.pushMsgAsync(-1, 'csjiang_event', { type: M.HU, data: { lead: String(this.logic.getLead(this.gangAfterData.chairId,winner.lead,winner.chs)), chairIds: winner.chs } });
  2186. // console.warn("提前结算1111");
  2187. yield this.concludeGameAsync(MODE.NORMAL).then(() => ({ code: C.OK }));/////结算游戏
  2188. return { code: C.OK };
  2189. }
  2190. // }
  2191. } else {///// 没炮多响
  2192. // console.warn("没炮多想 放弃操作放弃操作放弃操作winner.chs",this.isGangHu,winner.chs);
  2193. // 有人胡牌
  2194. if (winner.chs.length > 0) {
  2195. let dist = (winner.chs[0] - winner.lead + this.ccount) % this.ccount;
  2196. // let __cHu = _.findIndex(this.masks, (m, i) => (m & 16 && (i - winner.lead + this.ccount) % this.ccount < dist));////TL++,zsyl,
  2197. let __cHu = _.findIndex(this.masks, (m, i) => (m & 16));///TL++,以前是上面那句写法,有个问题:0打牌后1,2,3号玩家都能胡,1点胡2点过,3就没有机会选择是否胡牌
  2198. // console.warn("111没炮多想 放弃操作放弃操作放弃操作__cHu",__cHu);
  2199. if (__cHu != -1){
  2200. let __cHuDengDai = _.findIndex(this.masks, (m) => (m == 17));//////
  2201. if(__cHuDengDai == -1) break;
  2202. else return this.succCardAsync(__cHuDengDai).then(() => ({ code: C.OK }));
  2203. }
  2204. yield this.pushMsgAsync(-1, 'csjiang_event', { type: M.HU, data: { lead: String(this.logic.getLead(this.gangAfterData.chairId,winner.lead,winner.chs)), chairIds: winner.chs } });
  2205. // console.warn("提前结算2222");
  2206. yield this.concludeGameAsync(MODE.NORMAL).then(() => ({ code: C.OK }));/////结算游戏
  2207. return { code: C.OK };
  2208. } else {
  2209. let __cHu = _.findIndex(this.masks, (m) => (m & 16));
  2210. // console.warn("111没炮多想 放弃操作放弃操作放弃操作__cHu",__cHu);
  2211. if (__cHu != -1) {
  2212. let __cHuDengDai = _.findIndex(this.masks, (m) => (m == 17));//////
  2213. if(__cHuDengDai == -1) break;
  2214. else return this.succCardAsync(__cHuDengDai).then(() => ({ code: C.OK }));
  2215. }
  2216. }
  2217. }
  2218. // 查找等待
  2219. for (let i = 0; i < this.masks.length; ++i) {
  2220. let cqsh = -1;
  2221. // console.warn("处理等待的起手胡111 "+this.masks[i]);
  2222. // if (i == this.currentId || i == chairId) continue;///////TL++zsyl 这种写法会导致拉杠胡的玩家点击过胡之后被拉杠胡的玩家杠不出来的问题
  2223. if (i == chairId) continue;//////TL++,为了解决拉杠胡的玩家点击过胡之后被拉杠胡的玩家杠不出来的问题
  2224. if (this.masks[i] == 65 || this.masks[i] == 129 ||this.masks[i] == 257 ||this.masks[i] == 513 ||this.masks[i] == 1025 ||this.masks[i] == 2049) {
  2225. cqsh = i;
  2226. }
  2227. if (cqsh != -1 ) {
  2228. // console.warn("处理等待的起手胡222 ",cqsh, this.qshType[cqsh], this.qshCards[cqsh]);
  2229. this.masks[i]--;//mask=129传给前端是不显示按钮的,为了等待在原本的mask上+1了,现在可以操作了所以-1
  2230. yield this.qshCardAsync(cqsh, this.qshType[cqsh], this.qshCards[cqsh]).then(() => ({ code: C.OK }));
  2231. }
  2232. }
  2233. let cGang = -1;
  2234. let cbu = -1;
  2235. let cPeng = -1;
  2236. let _cChi = -1;
  2237. // console.warn("这里是啥情况啊",this.masks);
  2238. for (let i = 0; i < this.masks.length; ++i) {
  2239. // if (i == this.currentId || i == chairId) continue;///////TL++zsyl 这种写法会导致拉杠胡的玩家点击过胡之后被拉杠胡的玩家杠不出来的问题
  2240. if (i == chairId) continue;//////TL++,为了解决拉杠胡的玩家点击过胡之后被拉杠胡的玩家杠不出来的问题
  2241. // if (this.masks[i] == 65 || this.masks[i] & 129 ||this.masks[i] & 257 ||this.masks[i] & 513 ||this.masks[i] & 1025 ||this.masks[i] & 2049) {
  2242. // cqsh = i;
  2243. // continue;
  2244. // }
  2245. if (this.masks[i] == 9) {
  2246. cGang = i;
  2247. continue;
  2248. }
  2249. if (this.masks[i] == 33) {
  2250. cbu = i;
  2251. continue;
  2252. }
  2253. if (this.masks[i] == 5) {
  2254. cPeng = i;
  2255. continue;
  2256. }
  2257. if (this.masks[i] == 3) {
  2258. _cChi = i;
  2259. continue;
  2260. }
  2261. }
  2262. // 杠碰吃
  2263. if (cGang != -1 && this.gangType > 0 && this.gangCard > 0) {
  2264. // console.warn("这里是放弃操作再次调用 杠 次");
  2265. return this.gangCardAsync(cGang, this.gangCard, this.gangType).then(() => ({ code: C.OK }));
  2266. }
  2267. else if (cbu != -1 && this.buCard > 0) {
  2268. // console.warn("这里是放弃操作再次调用 杠 次");
  2269. return this.buCardAsync(cbu, this.buCard, this.buType).then(() => ({ code: C.OK }));
  2270. }
  2271. else if (cPeng != -1) {
  2272. let cc = this.outCard;
  2273. if(this.gangAfterData.chairId != -1){
  2274. cc = this.pengCard;
  2275. }
  2276. if(cc > 0){
  2277. return this.pengCardAsync(cPeng, cc).then(() => ({ code: C.OK }));
  2278. }
  2279. }
  2280. else if (_cChi != -1 && this._eatType > 0) {
  2281. let cc = this.outCard;
  2282. if(this.gangAfterData.chairId != -1){
  2283. cc = this._eatCard;
  2284. }
  2285. if(cc > 0){
  2286. return this.eatCardAsync(_cChi, cc, this._eatType).then(() => ({ code: C.OK }));
  2287. }
  2288. }
  2289. } while (0);
  2290. }
  2291. // 放弃杠补
  2292. if ((mask & 8) || (mask & 32)) {
  2293. // console.warn("下面是放弃杠补");
  2294. let __cHu = _.findIndex(this.masks, (m) => (m & 16));
  2295. if (__cHu == -1) {
  2296. // console.warn("放弃杠补 其他人没有胡 ");
  2297. let cGang = _.findIndex(this.masks, (m) => (m == 9));
  2298. if (cGang != -1 && this.gangType > 0 && this.gangCard > 0) {
  2299. // console.warn("这里是放弃操作再次调用 杠 次");
  2300. return this.gangCardAsync(cGang, this.gangCard, this.gangType).then(() => ({ code: C.OK }));
  2301. }
  2302. let cbu = _.findIndex(this.masks, (m) => (m == 33));
  2303. if (cbu != -1 && this.buCard > 0) {
  2304. // console.warn("这里是放弃操作再次调用 杠 次");
  2305. return this.buCardAsync(cbu, this.buCard, this.buType).then(() => ({ code: C.OK }));
  2306. }
  2307. let cPeng = _.findIndex(this.masks, (m) => (m == 5));
  2308. // console.warn("放弃杠补 其他人是否有碰 cPeng "+cPeng+" this.pengCard "+this.pengCard);
  2309. if (cPeng != -1) {
  2310. let cc = this.outCard;
  2311. if(this.gangAfterData.chairId != -1){
  2312. cc = this.pengCard;
  2313. }
  2314. // console.warn("放弃杠补NNNNNNNNN 333 "+cc);
  2315. if(cc > 0){
  2316. return this.pengCardAsync(cPeng, cc).then(() => ({ code: C.OK }));
  2317. }
  2318. }
  2319. let chi = _.findIndex(this.masks, (m) => (m == 3));
  2320. // console.warn("放弃杠补 其他人是否有吃 chi "+chi+" this._eatType "+this._eatType);
  2321. if (chi != -1) {
  2322. let cc = this.outCard;
  2323. if(this.gangAfterData.chairId != -1){
  2324. cc = this._eatCard;
  2325. }
  2326. if(cc > 0){
  2327. return this.eatCardAsync(chi, cc, this._eatType).then(() => ({ code: C.OK }));
  2328. }
  2329. }
  2330. }
  2331. }
  2332. // 放弃碰
  2333. if (mask & 4) {
  2334. let __cHu = _.findIndex(this.masks, (m) => (m == 16));
  2335. if (__cHu == -1) {
  2336. let cPeng = _.findIndex(this.masks, (m) => (m == 5));
  2337. // console.warn("放弃碰 其他人是否有碰 cPeng "+cPeng+" this.pengCard "+this.pengCard);
  2338. if (cPeng != -1) {
  2339. let cc = this.outCard;
  2340. if(this.gangAfterData.chairId != -1){
  2341. cc = this.pengCard;
  2342. }
  2343. // console.warn("放弃碰NNNNNNNNN 333 "+cc);
  2344. if(cc > 0){
  2345. return this.pengCardAsync(cPeng, cc).then(() => ({ code: C.OK }));
  2346. }
  2347. }
  2348. let _cChi = _.findIndex(this.masks, (m) => (m == 3));
  2349. let cc = this.outCard;
  2350. if(this.gangAfterData.chairId != -1){
  2351. cc = this._eatCard;
  2352. }
  2353. if (_cChi != -1 && this._eatType > 0 && cc > 0) {
  2354. return this.eatCardAsync(_cChi, cc, this._eatType).then(() => ({ code: C.OK }));
  2355. }
  2356. }
  2357. }
  2358. // 全无权限
  2359. if(!this.logic.getIsQS()){
  2360. for (let i = 0; i < this.ccount; ++i) {
  2361. if (this.masks[i] != 0) break;
  2362. // 切换用户
  2363. if (i == this.ccount - 1) {
  2364. // 下家摸牌
  2365. let nextId = (this.currentId + 1) % this.ccount;
  2366. if(this.gangAfterData.chairId != -1){
  2367. nextId = (this.gangAfterData.chairId + 1) % this.ccount;
  2368. yield this.updateGangafterData(this.gangAfterData.chairId,this.gangAfterData.cards);
  2369. }
  2370. ///////TL++,整个if,因为海底捞月需要玩家自己去判断要不要摸牌
  2371. // console.warn("222 声剩余声剩余声剩 nextId "+nextId+" outCards "+this.outCards[nextId]);
  2372. let lastCount = this.logic.leaveCount();/////TL++xg
  2373. return this.touchCardAsync(nextId).then(() => ({ code: C.OK }));//////放弃操作引起的摸牌
  2374. }
  2375. }
  2376. }
  2377. let isCanOut = this.logic.getIsCanOut(this.masks);
  2378. if(isCanOut){
  2379. //////麻将过牌通知,用于隐藏手牌遮罩
  2380. let fqdata = {
  2381. isGangInfo: this.everyIsGang[chairId],
  2382. keGangInfo: this.keGangInfo,
  2383. isCanOut: isCanOut
  2384. }
  2385. yield this.pushMsgAsync(this.currentId, 'csjiang_event', { type: M.GIVE_UP, data:fqdata });
  2386. }
  2387. return { code: C.OK};
  2388. });
  2389. // /////TL++,是否进行海底捞月的操作 处理前端海底捞月函数
  2390. proto.haiDiLaoYue = cor(function* (chairId,data) {
  2391. let str3 = "cstable 海底,id: "+this.id + " ,uid "+chairId+", this.masks "+ this.masks +" ,type "+data.type;
  2392. logger.warn(str3);////cssj
  2393. // console.warn("海底捞月海底捞月 chairId "+chairId+" type "+data.type+" isZHYZ "+this.logic.isZHYZ);
  2394. if(!this.logic.isZHYZ) return;
  2395. if(this.everyHDLY[chairId] != -1) return;
  2396. // // console.warn("海底捞月海底捞月",chairId,data.type);
  2397. if(data.type && data.type == 1){
  2398. this.everyHDLY[chairId] = 1;//每个玩家海底捞月选择情况,不选择海底不能胡海底
  2399. yield this.touchCardAsync(chairId).then(() => ({ code: C.OK }));//////海底捞月引起的摸牌
  2400. }
  2401. else if(data.type == 0){
  2402. this.everyHDLY[chairId] = 0;//每个玩家海底捞月选择情况,不选择海底不能胡海底
  2403. let targetId = -1
  2404. let nextId = chairId;
  2405. for (let i = 0; i < this.ccount; ++i) {
  2406. nextId = (nextId + 1) % this.ccount;
  2407. if(this.everyHDLY[nextId] >= 0) continue;
  2408. // console.warn("海底捞月玩家不要 开始检查下一个人听牌");
  2409. if(this.logic.checkTing(this.handCards[nextId],this.huCards[nextId])){
  2410. targetId = nextId;
  2411. break;
  2412. }
  2413. }
  2414. // console.warn("海底捞月海底捞月 拒绝 chairId "+chairId+" targetId "+targetId);
  2415. if(targetId >= 0){
  2416. let guohudataTL = {
  2417. chairId:targetId,
  2418. msg: "是否“海底捞月”?", /////海底捞月通知
  2419. }
  2420. this.logic.isZHYZ = true;/////是不是最后1张
  2421. yield this.pushMsgAsync(targetId, 'csjiang_event', { type: M.FHLASTCARDTIP, data: guohudataTL }); //////海底捞月通知 放弃操作中调用摸牌函数
  2422. let strx = "cstable 海 询问海底 id:"+this.id + " ,uid "+targetId+" ,this.masks "+ this.masks;
  2423. logger.warn(strx);////cssj
  2424. // this.setPaijuHuiFangData(M.FHLASTCARDTIP,guohudataTL);/////TL++ 牌局回放 push海底捞月数据 放弃操作
  2425. return { code: C.OK };
  2426. }
  2427. else{
  2428. yield this.concludeGameAsync(MODE.NOCARD);
  2429. return { code: C.OK };
  2430. }
  2431. }
  2432. // console.warn("海底捞月海底捞月");
  2433. return { code: C.OK };
  2434. });
  2435. // 杠牌,1-普通杠, 2-暗杠, 3-自摸明杠
  2436. proto.gangCardAsync = cor(function* (chairId, card, type) {
  2437. let str3 = "cstable 杠牌,id: "+this.id + " ,uid "+chairId+", this.masks "+ this.masks +" ,card "+card +" ,type "+type;
  2438. logger.warn(str3);////cssj
  2439. // 参数校验
  2440. if (!type && (type < 1 || type > 3)) {
  2441. return { code: C.FAILD, msg: C.GAME_PARAM_ERROR };
  2442. }
  2443. // console.warn("1-普通杠, 2-暗杠, 3-自摸明杠 "+type+" "+this.gangAfterData.chairId);
  2444. if(this.gangAfterData.chairId == -1){
  2445. if (type == 1 && card != this.outCard) {
  2446. return { code: C.FAILD, msg: C.GAME_PARAM_ERROR };
  2447. }
  2448. }
  2449. else{
  2450. if (card != this.gangAfterData.cards.card1 && card != this.gangAfterData.cards.card2){
  2451. return { code: C.FAILD, msg: C.GAME_PARAM_ERROR };
  2452. }
  2453. }
  2454. if(this.gangAfterData.chairId == -1){
  2455. if (type > 1 && this.currentId != chairId) {
  2456. return { code: C.FAILD, msg: C.GAME_PARAM_ERROR };
  2457. }
  2458. }
  2459. if (!(this.masks[chairId] & 8)) {
  2460. return { code: C.FAILD, msg: C.TABLE_MASK_ERROR };
  2461. }
  2462. // if(!this.logic.isCanCPB(this.handCards[chairId],Logic.STYLE.GANG,type)){
  2463. // return { code: C.FAILD, msg: C.TABLE_NOTONLYBD };
  2464. // }
  2465. // 他人可胡
  2466. // let __cHu = (type == 2) ? -1 : _.findIndex(this.masks, (m) => ((m & 16) && !(m & 8) && !(m & 32)));
  2467. let isHveeQSH = false;//是否有起手胡
  2468. let tagetChairId = -1;
  2469. let tagetOP = -1;
  2470. for (var i = 0; i < this.masks.length; i++) {
  2471. if(i != chairId){
  2472. if(this.masks[i] & 16){
  2473. isHveeQSH = true;
  2474. break;
  2475. }
  2476. for (var x = 1; x < this.maskValeList.length; x++) {
  2477. if(this.masks[i] & this.maskValeList[x]){
  2478. isHveeQSH = true;
  2479. break;
  2480. }
  2481. }
  2482. }
  2483. }
  2484. if(!isHveeQSH && this.gangAfterData.chairId != -1){
  2485. //只有杠后两张牌的时候杠才会两个人同时出现
  2486. //至此没有人可以胡
  2487. let otherKG = -1;//除点杠之外可杠或可补的玩家
  2488. for (var i = 0; i < this.masks.length; i++) {
  2489. if(i != chairId && (this.masks[i] & 8 || chairId && this.masks[i] & 32)){
  2490. otherKG = i;
  2491. break;
  2492. }
  2493. }
  2494. if(otherKG >= 0){
  2495. let zjjl = 0;
  2496. if((this.gangAfterData.chairId + 1) % this.ccount == chairId) zjjl = 1;
  2497. else if((this.gangAfterData.chairId + 2) % this.ccount == chairId) zjjl = 2;
  2498. else if((this.gangAfterData.chairId + 3) % this.ccount == chairId) zjjl = 3;
  2499. let qtjl = 0;
  2500. if((this.gangAfterData.chairId + 1) % this.ccount == otherKG) qtjl = 1;
  2501. else if((this.gangAfterData.chairId + 2) % this.ccount == otherKG) qtjl = 2;
  2502. else if((this.gangAfterData.chairId + 3) % this.ccount == otherKG) qtjl = 3;
  2503. if(zjjl > qtjl){
  2504. if(this.masks[otherKG] == 9 || this.masks[otherKG] == 33){
  2505. tagetChairId = otherKG;
  2506. if(this.masks[otherKG] == 33) tagetOP = 32;
  2507. }
  2508. else{
  2509. isHveeQSH = true;
  2510. }
  2511. }
  2512. }
  2513. }
  2514. // console.warn("111拉杠胡%%%%%%%%%%%%%%%%%%%%%%",isHveeQSH ,tagetChairId,tagetOP,this.masks);
  2515. if (!isHveeQSH){//(__cHu == -1) {
  2516. let newCh = chairId;
  2517. let newCa = card;
  2518. let newTy = type
  2519. if(tagetChairId > 0){
  2520. newCh = tagetChairId;//B玩家点杠或补之后需要等待C玩家点胡,如果C玩家点了杠就让B玩家杠或补
  2521. if(tagetOP == 32){
  2522. newCa = this.buCard;
  2523. newTy = this.buType;
  2524. }else{
  2525. newCa = this.gangCard;
  2526. newTy = this.gangType;
  2527. }
  2528. }
  2529. // console.warn("杠牌===111 chairId "+chairId+" tagetChairId "+tagetChairId+" tagetOP "+tagetOP)
  2530. // console.warn("杠牌===222 newTy "+newTy+" newCa "+newCa+" this.huCards[newCh] "+JSON.stringify(this.huCards[newCh])+" this.handCards[newCh] "+this.handCards[newCh])
  2531. let res = null;
  2532. if (newTy == 1 || newTy == 2) {
  2533. res = this.logic.gang(newCh,this.handCards[newCh], newCa, newTy);
  2534. } else if (newTy == 3) {
  2535. let handCards1 = this.handCards[newCh];
  2536. if(this.gangAfterData.chairId != -1){
  2537. handCards1 = this.logic.deepCloneTL(this.handCards[newCh]);
  2538. handCards1.push(newCa);
  2539. }
  2540. res = this.logic.zmGang(newCh,handCards1, this.huCards[newCh], newCa);
  2541. }
  2542. if (!res) {
  2543. return { code: C.FAILD, msg: C.TABLE_GANG_ERROR };
  2544. }
  2545. /////TL++7月17日,这整个if的内容 和else的判断
  2546. let winner = this.winner;
  2547. if (winner.chs.length > 0) {
  2548. yield this.pushMsgAsync(-1, 'csjiang_event', { type: M.HU, data: { lead: String(this.logic.getLead(this.gangAfterData.chairId,winner.lead,winner.chs)), chairIds: winner.chs } });
  2549. this.setPaijuHuiFangData(M.HU,{ lead: String(winner.lead), chairIds: winner.chs });/////TL++ 牌局回放 push吃胡牌数据
  2550. // console.warn("提前结算BBB");
  2551. yield this.concludeGameAsync(MODE.NORMAL);
  2552. }
  2553. else{
  2554. // 记录杠牌
  2555. if (newTy == 1) {
  2556. // 被杠玩家
  2557. if(this.gangAfterData.chairId == -1){
  2558. this.gangOuter = this.outerId;
  2559. res.origin = this.outerId;
  2560. this.outCards[this.outerId].pop();
  2561. }
  2562. else{
  2563. this.gangOuter = this.gangAfterData.chairId;
  2564. res.origin = this.gangAfterData.chairId;
  2565. }
  2566. this.huCards[newCh].push(res);
  2567. this.logic.remove(this.handCards[newCh], res.cards);
  2568. } else if (newTy == 2) {
  2569. // 被杠玩家
  2570. this.gangOuter = -1;
  2571. this.huCards[newCh].push(res);
  2572. this.logic.remove(this.handCards[newCh], [newCa, newCa, newCa, newCa]);
  2573. this.logic.adjust(this.handCards[newCh]);
  2574. } else if (newTy == 3) {
  2575. // console.warn("333拉杠胡%%%%%%%%%%%%%%%%%%%%%%",this.logic.isLaGang,this.isGangHu);
  2576. let huCard = _.find(this.huCards[newCh], (o) => {
  2577. return (o.style == Logic.STYLE.PENG && o.cards[0] == newCa);
  2578. });
  2579. if (!huCard) {
  2580. return { code: C.FAILD, msg: C.TABLE_GANG_ERROR };
  2581. }
  2582. // 被杠玩家
  2583. this.gangOuter = -1;
  2584. // console.warn("拉杠胡%%%%%%%%%%%%%%%%%%%%%%" ,this.isGangHu);
  2585. // 抢杠胡
  2586. if (!this.isGangHu) {
  2587. this.lgkhCount = 0;/////TL++拉杠可胡玩家的数量
  2588. let allowIds = [], otherIds = [];
  2589. for (let i = 0; i < this.ccount; ++i) {
  2590. // 排除自己
  2591. if (i != newCh) {
  2592. this.logic.isLaGang = true;//////TL++,是否刚刚被拉杠用于判断是否被拉杠胡
  2593. // console.error("sscc222胡牌分析 杠牌i",i,this.logic.isLaGang);
  2594. let huRes = this.logic.huAnalyze(i,this.handCards[i], newCa, this.huCards[i]);//抢杠胡
  2595. // console.error("ssccCCC胡牌分析 huRes",huRes);
  2596. // let lg2 = false;///TL++
  2597. if (huRes) {
  2598. // let str3a = "cstable lgphcg:"+this.id + ",uid"+this.handCards[i];
  2599. // logger.info(str3a);////cssj
  2600. if (!this.isGangHu) this.isGangHu = true;
  2601. //////////TL++,为了记录承包情况,第一个元素表示承包原因 1:海底捞月打出去被胡 2:被人拉杠胡 第二个元素承包的玩家座位号
  2602. // this.logic.chengBaoTL[chairId][this.logic.chengBaoTL[chairId].length] = [2,this.currentId];
  2603. // lg2 = true//////TL++
  2604. this.huRes[i] = huRes;
  2605. this.masks[i] |= 16;
  2606. this.lgkhCount += 1;/////TL++拉杠可胡玩家的数量
  2607. allowIds.push(this.users[i].id); continue;
  2608. }
  2609. }
  2610. // 其他玩家
  2611. otherIds.push(this.users[i].id);
  2612. }
  2613. // 有人可胡
  2614. if (allowIds.length > 0) {
  2615. // 置于等待
  2616. this.masks[chairId] = 9;
  2617. this.gangType = type;
  2618. this.gangCard = card;
  2619. // 抢杠通知
  2620. yield this.pushMsgAsync(otherIds, 'csjiang_event', { type: M.MASK_HU, data: { mask: '0', card: String(newCa) } });
  2621. yield this.pushMsgAsync(allowIds, 'csjiang_event', { type: M.MASK_HU, data: { mask: '16', card: String(newCa) } });
  2622. let pjhfsplist2 = {
  2623. shouPai:this.logic.deepCloneTL(this.handCards),
  2624. lastCount:this.logic.leaveCount(),
  2625. outCards:this.logic.deepCloneTL(this.outCards),
  2626. opData:{ mask: '16', card: String(newCa) }
  2627. }
  2628. this.setPaijuHuiFangData(M.MASK_HU,pjhfsplist2);/////TL++ 牌局回放 push杠操作数据
  2629. // console.warn("抢杠胡同盟会告知",allowIds);
  2630. return { code: C.OK };
  2631. }
  2632. }
  2633. huCard.style = Logic.STYLE.ZMGANG;
  2634. // console.warn("55拉杠胡%%%%%%%%%%%%%%%%%%%%%%",this.logic.isLaGang,this.gangType,this.gangCard = 0);
  2635. this.isGangHu = false;/////TL++,8月28日晚上,为了解决过胡拉杠之后就算自己已经摸牌也不能再次拉杠的问题
  2636. this.logic.remove(this.handCards[newCh], newCa);
  2637. this.logic.adjust(this.handCards[newCh]);
  2638. }
  2639. // if(this.chBanker == chairId) this.isZJYG = true;////本局庄家是否有杠
  2640. // 清空权限 杠牌里面
  2641. this._eatType = 0;
  2642. this._eatCard = 0
  2643. this.gangType = 0;
  2644. this.gangCard = 0;
  2645. this.pengCard = 0;
  2646. _.fill(this.masks, 0);
  2647. // 总杠次
  2648. // this.gonCount += 1;
  2649. // 发送通知
  2650. // console.warn("333 声剩余声剩余声剩");
  2651. let lastCount = this.logic.leaveCount();/////TL++xg
  2652. let pjhfsplist = {
  2653. shouPai:this.logic.deepCloneTL(this.handCards),
  2654. lastCount:lastCount,
  2655. outCards:this.logic.deepCloneTL(this.outCards),
  2656. opData:{ chairId: String(newCh), type: String(newTy), card: String(newCa), lastCount: String(lastCount) }
  2657. }
  2658. if(tagetOP == 32){
  2659. this.changeCurrQSHInfo(newCh,M.BU,newTy,newCa);
  2660. this.setPaijuHuiFangData(M.BU,pjhfsplist);/////TL++ 牌局回放 push杠操作数据
  2661. yield this.pushMsgAsync(-1, 'csjiang_event', { type: M.BU, data: { chairId: String(newCh), type: String(newTy), card: String(newCa), lastCount: String(lastCount) } });
  2662. }else{
  2663. this.changeCurrQSHInfo(newCh,M.GANG,newTy,newCa)
  2664. this.setPaijuHuiFangData(M.GANG,pjhfsplist);/////TL++ 牌局回放 push杠操作数据
  2665. yield this.pushMsgAsync(-1, 'csjiang_event', { type: M.GANG, data: { chairId: String(newCh), type: String(newTy), card: String(newCa), lastCount: String(lastCount) } });
  2666. }
  2667. if(this.gangAfterData.chairId != -1){
  2668. let gfcards = this.gangAfterData.cards;
  2669. let xdIndex = 0;
  2670. if(newCa == gfcards.card1) xdIndex = 1;
  2671. else if(newCa == gfcards.card2) xdIndex = 2;
  2672. if(xdIndex > 0){
  2673. let cmoCard = {};
  2674. if(xdIndex == 1) cmoCard = {card1:0,card2:gfcards.card2}
  2675. else if(xdIndex == 2) cmoCard = {card1:gfcards.card1,card2:0}
  2676. yield this.updateGangafterData(this.gangAfterData.chairId,cmoCard);
  2677. }
  2678. }
  2679. if(this.logic.leaveCount() >= 2){
  2680. // console.error("杠牌 杠牌摸2张牌",tagetOP);
  2681. if(tagetOP == 32){
  2682. yield this.touchCardAsync(newCh, newTy); ///////杠牌摸牌
  2683. }
  2684. else{
  2685. yield this.touchCardAfterGang(newCh, newTy); ///////杠牌摸2张牌
  2686. }
  2687. }
  2688. else{
  2689. //只剩最后一张牌时杠完之后进行海底捞月轮询
  2690. // console.error("杠牌 杠牌摸牌");
  2691. yield this.touchCardAsync(chairId, type); ///////杠牌摸牌
  2692. }
  2693. }
  2694. } else {
  2695. // console.warn("杠牌 置于等待 ???");
  2696. let ddcwj = _.findIndex(this.masks, (m, i) => (m == 9));//等待吃的玩家
  2697. let gxtype = this.logic.getDDGXType(2,chairId,ddcwj,this.gangAfterData.chairId,this.ccount,this.masks);
  2698. let old_gangType = this.gangType;
  2699. let old_gangCard = this.gangCard;
  2700. // 置于等待
  2701. this.masks[chairId] = 9;
  2702. this.gangType = type;
  2703. this.gangCard = card;
  2704. if(gxtype == 1){
  2705. this.masks[ddcwj] = 0;
  2706. }
  2707. else if(gxtype == 2){
  2708. this.masks[chairId] = 0;
  2709. this.gangType = old_gangType;
  2710. this.gangCard = old_gangCard;
  2711. }
  2712. let __cHuDengDai = _.findIndex(this.masks, (m) => (m == 17));//////
  2713. if(__cHuDengDai != -1) {
  2714. // console.warn("杠牌这里调用了胡牌",__cHuDengDai)
  2715. // 为了解决A玩家杠后2张牌发出来之后,B玩家可吃胡C,D玩家可碰杠补胡,然后几人的操作顺序如果最后一个操作为胡或过的时候正常,
  2716. // 但是如果最后一个操作为为吃碰杠补时会卡住的bug
  2717. this.masks[chairId] = 0;
  2718. return this.succCardAsync(__cHuDengDai).then(() => ({ code: C.OK }));
  2719. }
  2720. else{
  2721. // 查找起手胡等待
  2722. // 为了解决A玩家起手牌可以胡杠补,BC玩家有六六顺时,BC玩家先点六六顺之后A玩家点杠或补会卡住的bug,
  2723. // (正确应为:BC玩家先点六六顺之后A玩家点杠后应该六六顺和杠或补都生效,若玩家A点胡则胡生效六六顺不生效)
  2724. for (let i = 0; i < this.masks.length; ++i) {
  2725. let cqsh = -1;
  2726. // console.warn("杠牌里处理等待的起手胡111 "+this.masks[i]);
  2727. // if (i == this.currentId || i == chairId) continue;///////TL++zsyl 这种写法会导致拉杠胡的玩家点击过胡之后被拉杠胡的玩家杠不出来的问题
  2728. if (i == chairId) continue;//////TL++,为了解决拉杠胡的玩家点击过胡之后被拉杠胡的玩家杠不出来的问题
  2729. if (this.masks[i] == 65 || this.masks[i] == 129 ||this.masks[i] == 257 ||this.masks[i] == 513 ||this.masks[i] == 1025 ||this.masks[i] == 2049) {
  2730. cqsh = i;
  2731. }
  2732. if (cqsh != -1 ) {
  2733. // console.warn("处理等待的起手胡222 ",cqsh, this.qshType[cqsh], this.qshCards[cqsh]);
  2734. this.masks[i]--;//mask=129传给前端是不显示按钮的,为了等待在原本的mask上+1了,现在可以操作了所以-1
  2735. yield this.qshCardAsync(cqsh, this.qshType[cqsh], this.qshCards[cqsh]).then(() => ({ code: C.OK }));
  2736. }
  2737. }
  2738. }
  2739. }
  2740. // let str4 = "cstable222 杠牌,id:"+this.id + ",uid"+chairId+","+ this.state +",card "+card;
  2741. // logger.info(str4);////cssj
  2742. return { code: C.OK };
  2743. });
  2744. // 碰牌
  2745. proto.pengCardAsync = cor(function* (chairId, card) {
  2746. let str3 = "cstable 碰牌id:%s "+this.id + " ,uid "+chairId+" ,this.masks "+ this.masks +" ,card "+card;
  2747. logger.warn(str3);////cssj
  2748. // 参数校验
  2749. if(this.gangAfterData.chairId == -1){
  2750. if (card != this.outCard || this.currentId == chairId) {
  2751. return { code: C.FAILD, msg: C.GAME_PARAM_ERROR };
  2752. }
  2753. }
  2754. else{
  2755. if (card != this.gangAfterData.cards.card1 && card != this.gangAfterData.cards.card2){
  2756. return { code: C.FAILD, msg: C.GAME_PARAM_ERROR };
  2757. }
  2758. }
  2759. // 权限校验
  2760. if (!(this.masks[chairId] & 4)) {
  2761. return { code: C.FAILD, msg: C.TABLE_MASK_ERROR };
  2762. }
  2763. if(!this.logic.isCanCPB(this.handCards[chairId],Logic.STYLE.PENG,0)){
  2764. return { code: C.FAILD, msg: C.TABLE_NOTONLYBD };
  2765. }
  2766. // 他人可胡杠
  2767. // var cHuGang = _.findIndex(this.masks, (m) => (((m & 16) || (m & 8) || (m & 32)) && !(m & 4)));
  2768. let isHaveHuGang = false;
  2769. let tagetChairId = -1;
  2770. if(this.gangAfterData.chairId == -1){
  2771. //这是普通正常情况
  2772. let cHuGang = _.findIndex(this.masks, (m) => (((m & 16) || (m & 8) || (m & 32)) && !(m & 4)));
  2773. if (cHuGang != -1) isHaveHuGang = true;
  2774. }
  2775. else{
  2776. //这是有玩家杠牌之后发两张牌的情况
  2777. // console.warn("碰牌按钮被点击了 这是有玩家杠牌之后发两张牌的情况 ");
  2778. for (var i = 0; i < this.masks.length; i++) {
  2779. if(i != chairId && (this.masks[i] & 16 || this.masks[i] & 8 || this.masks[i] & 32)){
  2780. // console.warn("碰牌按钮被点击了 有人可以胡杠补 ");
  2781. isHaveHuGang = true;
  2782. break;
  2783. }
  2784. }
  2785. // console.warn("碰牌按钮被点击了 isHaveHuGang ",isHaveHuGang);
  2786. if(!isHaveHuGang){
  2787. //至此没有人可以胡杠补
  2788. let otherKP = -1;//除点碰之外可碰的玩家
  2789. for (var i = 0; i < this.masks.length; i++) {
  2790. if(i != chairId && this.masks[i] & 4){
  2791. otherKP = i;
  2792. }
  2793. }
  2794. if(otherKP >= 0){
  2795. let zjjl = 0;
  2796. if((this.gangAfterData.chairId + 1) % this.ccount == chairId) zjjl = 1;
  2797. else if((this.gangAfterData.chairId + 2) % this.ccount == chairId) zjjl = 2;
  2798. else if((this.gangAfterData.chairId + 3) % this.ccount == chairId) zjjl = 3;
  2799. let qtjl = 0;
  2800. if((this.gangAfterData.chairId + 1) % this.ccount == otherKP) qtjl = 1;
  2801. else if((this.gangAfterData.chairId + 2) % this.ccount == otherKP) qtjl = 2;
  2802. else if((this.gangAfterData.chairId + 3) % this.ccount == otherKP) qtjl = 3;
  2803. // console.warn("碰牌按钮被点击了 zjjl ",zjjl," qtjl ",qtjl);
  2804. // isHaveHuGang = zjjl > qtjl;
  2805. if(zjjl > qtjl){
  2806. if(this.masks[otherKP] == 5){
  2807. tagetChairId = otherKP;
  2808. }
  2809. else{
  2810. isHaveHuGang = true;
  2811. }
  2812. }
  2813. }
  2814. }
  2815. }
  2816. // console.warn("碰牌按钮被点击了 他人可胡杠",isHaveHuGang,this.masks);
  2817. if (!isHaveHuGang) {
  2818. let newCh = chairId;
  2819. let newCa = card;
  2820. if(tagetChairId > 0){
  2821. newCh = tagetChairId;//B玩家点碰之后需要等待C玩家点杠,如果C玩家点了碰就让B玩家碰
  2822. newCa = this.pengCard;
  2823. }
  2824. let res = this.logic.peng(newCh,this.handCards[newCh], newCa);
  2825. if (!res) {
  2826. return { code: C.FAILD, msg: C.TABLE_PENG_ERROR };
  2827. }
  2828. // console.warn("到这里了嘛??? newCh "+newCh+" newCa "+newCa);
  2829. /////TL++7月17日,这整个if的内容 和else的判断
  2830. let winner = this.winner;
  2831. if (winner.chs.length > 0) {
  2832. yield this.pushMsgAsync(-1, 'csjiang_event', { type: M.HU, data: { lead: String(this.logic.getLead(this.gangAfterData.chairId,winner.lead,winner.chs)), chairIds: winner.chs } });
  2833. this.setPaijuHuiFangData(M.HU,{ lead: String(winner.lead), chairIds: winner.chs });/////TL++ 牌局回放 push吃胡牌数据
  2834. // console.warn("提前结算AAA");
  2835. yield this.concludeGameAsync(MODE.NORMAL);
  2836. }
  2837. else{
  2838. // 记录碰牌
  2839. if(this.gangAfterData.chairId == -1){
  2840. res.origin = this.outerId;
  2841. this.outCards[this.outerId].pop();
  2842. }
  2843. else{
  2844. res.origin = this.gangAfterData.chairId;
  2845. }
  2846. this.huCards[newCh].push(res);
  2847. this.logic.remove(this.handCards[newCh], [newCa, newCa]);
  2848. // 清空权限 碰牌里面
  2849. this._eatType = 0;
  2850. this._eatCard = 0;
  2851. this.gangType = 0;
  2852. this.gangCard = 0;
  2853. this.pengCard = 0;
  2854. _.fill(this.masks, 0);
  2855. // 用户顺序
  2856. this.currentId = newCh;
  2857. //下面是碰后可以直接杠
  2858. this.keGangInfo = {chairId: -1,data:[]};
  2859. let resx1 = this.logic.anGangAnalyze(this.handCards[this.currentId]);
  2860. let isGang1 = (resx1.length > 0);
  2861. let resx2 = this.logic.zmGangAnalyze(this.handCards[this.currentId], this.huCards[this.currentId]);
  2862. let isGang2 = (resx2.length > 0);
  2863. let resx = [];
  2864. let isGang = isGang1 || isGang2;
  2865. if(isGang1) resx = resx.concat(resx1);//暗杠
  2866. if(isGang2) resx = resx.concat(resx2);//自摸杠
  2867. if(isGang){
  2868. for (let x = 0; x < resx.length; ++x) {
  2869. if(this.logic.isCanGang(this.handCards[this.currentId],this.huCards[this.currentId],resx[x].type,resx[x].card)){
  2870. if(!this.everyIsGang[this.currentId][0]){
  2871. this.masks[this.currentId] |= this.maskValeList[0];//能杠肯定就能补
  2872. }
  2873. this.masks[this.currentId] |= 8;
  2874. this.keGangInfo.chairId = this.currentId;
  2875. this.keGangInfo.data.push({pos:resx[x].type,card:resx[x].card});////可杠信息,因为碰牌之后手上虽然有多个杠,但是没有听牌的话是不能杠的
  2876. }
  2877. else{
  2878. if(!this.everyIsGang[this.currentId][0]){
  2879. this.masks[this.currentId] |= this.maskValeList[0];
  2880. }
  2881. }
  2882. }
  2883. }
  2884. for (let i = 0; i < this.ccount; ++i) {
  2885. let pengdata = {////这种一定要声明在for循环里面
  2886. chairId: String(newCh),
  2887. card: String(newCa)
  2888. }
  2889. if(i == newCh){
  2890. pengdata.mask = this.masks[i];
  2891. pengdata.keGangInfo = this.keGangInfo;
  2892. let hutipdataTL = this.logic.hutip(i,this.handCards[i],this.huCards[i],this.huCards,this.outCards);////碰牌调用胡牌提示
  2893. pengdata.hutipdata = hutipdataTL;
  2894. this.changeCurrQSHInfo(newCh,M.PENG,0,newCa);
  2895. }
  2896. else{
  2897. pengdata.mask = 0;
  2898. pengdata.keGangInfo = {chairId: -1,data:[]};
  2899. pengdata.hutipdata = {
  2900. renyi:0,//////是否可胡任意牌,0表示不满足1表示满足
  2901. kehuData:[]/////对象数组,分别表示打哪张可胡哪几张数据
  2902. };
  2903. }
  2904. yield this.pushMsgAsync(i, 'csjiang_event', { type: M.PENG, data: pengdata });
  2905. }
  2906. let pengdatapg = {////碰的旁观数据
  2907. chairId: String(newCh),
  2908. card: String(newCa)
  2909. }
  2910. pengdatapg.hutipdata = {
  2911. renyi:0,//////是否可胡任意牌,0表示不满足1表示满足
  2912. kehuData:[]/////对象数组,分别表示打哪张可胡哪几张数据
  2913. };
  2914. yield this.lookMsgAsync('csjiang_event', { type: M.PENG, data: pengdatapg });////TL++
  2915. ////20200831增加胡牌提示的时候把下面这句换成了上面那一段
  2916. // yield this.pushMsgAsync(-1, 'csjiang_event', { type: M.PENG, data: { chairId: String(chairId), card: String(card) } });
  2917. let pjhfsplist = {
  2918. shouPai:this.logic.deepCloneTL(this.handCards),
  2919. lastCount:String(this.logic.leaveCount()),
  2920. outCards:this.logic.deepCloneTL(this.outCards),
  2921. opData:{ chairId: String(newCh), card: String(newCa) }
  2922. }
  2923. this.setPaijuHuiFangData(M.PENG,pjhfsplist);/////TL++ 牌局回放 push碰操作数据
  2924. if(this.gangAfterData.chairId != -1){
  2925. let gfcards = this.gangAfterData.cards;
  2926. let xdIndex = 0;
  2927. if(newCa == gfcards.card1) xdIndex = 1;
  2928. else if(newCa == gfcards.card2) xdIndex = 2;
  2929. if(xdIndex > 0){
  2930. let cmoCard = {};
  2931. if(xdIndex == 1) cmoCard = {card1:0,card2:gfcards.card2}
  2932. else if(xdIndex == 2) cmoCard = {card1:gfcards.card1,card2:0}
  2933. yield this.updateGangafterData(this.gangAfterData.chairId,cmoCard);
  2934. }
  2935. }
  2936. }
  2937. } else {
  2938. let ddcwj = _.findIndex(this.masks, (m, i) => (m == 5));//等待吃的玩家
  2939. let gxtype = this.logic.getDDGXType(1,chairId,ddcwj,this.gangAfterData.chairId,this.ccount,this.masks);
  2940. let old_pengCard = this.pengCard;
  2941. // 置于等待
  2942. this.masks[chairId] = 5;
  2943. this.pengCard = card;
  2944. if(gxtype == 1){
  2945. this.masks[ddcwj] = 0;
  2946. }
  2947. else if(gxtype == 2){
  2948. this.masks[chairId] = 0;
  2949. this.pengCard = old_pengCard;
  2950. }
  2951. let __cHuDengDai = _.findIndex(this.masks, (m) => (m == 17));//////
  2952. if(__cHuDengDai != -1) {
  2953. // console.warn("碰牌这里调用了胡牌",__cHuDengDai)
  2954. // 为了解决A玩家杠后2张牌发出来之后,B玩家可吃胡C,D玩家可碰杠补胡,然后几人的操作顺序如果最后一个操作为胡或过的时候正常,
  2955. // 但是如果最后一个操作为为吃碰杠补时会卡住的bug
  2956. this.masks[chairId] = 0;
  2957. return this.succCardAsync(__cHuDengDai).then(() => ({ code: C.OK }));
  2958. }
  2959. // console.warn("碰牌 置于等待 this.pengCard "+this.pengCard);
  2960. // 查找等待 TL++下面这一段,为了解决A打出一张牌之后B可吃胡C可碰情况下 C先点碰B点吃会死掉的问题 这是原始代码的重大天然Bug
  2961. let cGang = -1;
  2962. let cBu = -1;
  2963. let cPeng = -1;
  2964. let _cChi = -1;
  2965. // console.warn("这里是啥情况啊",this.masks);
  2966. for (let i = 0; i < this.masks.length; ++i) {
  2967. // if (i == this.currentId || i == chairId) continue;///////TL++zsyl 这种写法会导致拉杠胡的玩家点击过胡之后被拉杠胡的玩家杠不出来的问题
  2968. if (i == chairId) continue;//////TL++,为了解决拉杠胡的玩家点击过胡之后被拉杠胡的玩家杠不出来的问题
  2969. if (this.masks[i] == 9) {
  2970. cGang = i;
  2971. continue;
  2972. }
  2973. if (this.masks[i] == 33) {
  2974. cBu = i;
  2975. continue;
  2976. }
  2977. if (this.masks[i] == 5) {
  2978. cPeng = i;
  2979. continue;
  2980. }
  2981. if (this.masks[i] == 3) {
  2982. _cChi = i;
  2983. continue;
  2984. }
  2985. }
  2986. // console.warn("ppppppppppp444 ",chairId,cGang,cPeng,_cChi);
  2987. // console.warn("2222情况啊",cGang, this.gangType,this.gangCard);
  2988. // 杠
  2989. if (cGang != -1 && this.gangType > 0 && this.gangCard > 0) {
  2990. return this.gangCardAsync(cGang, this.gangCard, this.gangType).then(() => ({ code: C.OK }));
  2991. }
  2992. else if (cBu != -1 && this.buType > 0 && this.buCard > 0) {
  2993. return this.buCardAsync(cBu, this.buCard, this.buType).then(() => ({ code: C.OK }));
  2994. }
  2995. }
  2996. // let str4 = "cstable 碰牌id:%s"+this.id + ",uid"+chairId+","+ this.state +" card "+card;
  2997. // logger.info(str4);////cssj
  2998. return { code: C.OK };
  2999. });
  3000. // 吃牌,1-@**左吃, 2-*@*中吃, 3-@**右吃 吃碰完可以直接杠
  3001. proto.eatCardAsync = cor(function* (chairId, card, type) {
  3002. let str3 = "cstable 吃牌id:%s "+this.id + " ,uid "+chairId+" ,this.masks "+ this.masks +",card "+card;
  3003. logger.warn(str3);////cssj
  3004. // 参数校验
  3005. if (!type && (type < 1 || type > 3)) {
  3006. return { code: C.FAILD, msg: C.GAME_PARAM_ERROR };
  3007. }
  3008. if(this.gangAfterData.chairId == -1){
  3009. if (card != this.outCard) {
  3010. return { code: C.FAILD, msg: C.GAME_PARAM_ERROR };
  3011. }
  3012. }
  3013. else{
  3014. if (card != this.gangAfterData.cards.card1 && card != this.gangAfterData.cards.card2){
  3015. return { code: C.FAILD, msg: C.GAME_PARAM_ERROR };
  3016. }
  3017. }
  3018. // 权限校验
  3019. if (!(this.masks[chairId] & 2)) {
  3020. return { code: C.FAILD, msg: C.TABLE_MASK_ERROR };
  3021. }
  3022. if(!this.logic.isCanCPB(this.handCards[chairId],Logic.STYLE.CHI,type)){
  3023. return { code: C.FAILD, msg: C.TABLE_NOTONLYBD };
  3024. }
  3025. // 他人可胡杠碰
  3026. var cHuGangPeng = _.findIndex(this.masks, (m) => (((m & 16) || (m & 8) || (m & 4) || (m & 32)) && !(m & 2)));
  3027. // console.warn("111他人可胡杠碰",cHuGangPeng);
  3028. if (cHuGangPeng == -1) {
  3029. let res = this.logic.chi(this.handCards[chairId], card, type);
  3030. if (!res) {
  3031. return { code: C.FAILD, msg: C.TABLE_PENG_ERROR };
  3032. }
  3033. /////TL++7月17日,这整个if的内容 和else的判断
  3034. let winner = this.winner;
  3035. // console.warn("222他人可胡杠碰",winner.chs.length);
  3036. if (winner.chs.length > 0) {
  3037. yield this.pushMsgAsync(-1, 'csjiang_event', { type: M.HU, data: { lead: String(this.logic.getLead(this.gangAfterData.chairId,winner.lead,winner.chs)), chairIds: winner.chs } });
  3038. this.setPaijuHuiFangData(M.HU,{ lead: String(winner.lead), chairIds: winner.chs });/////TL++ 牌局回放 push吃胡牌数据
  3039. // console.warn("提前结算aaa");
  3040. yield this.concludeGameAsync(MODE.NORMAL);
  3041. }
  3042. else{
  3043. // 记录吃牌
  3044. if(this.gangAfterData.chairId == -1){
  3045. res.origin = this.outerId;
  3046. this.outCards[this.outerId].pop();
  3047. }
  3048. else{
  3049. res.origin = this.gangAfterData.chairId;
  3050. }
  3051. this.huCards[chairId].push(res);
  3052. if (type == 1) {
  3053. this.logic.remove(this.handCards[chairId], [card + 1, card + 2]);
  3054. } else if (type == 2) {
  3055. this.logic.remove(this.handCards[chairId], [card - 1, card + 1]);
  3056. } else {
  3057. this.logic.remove(this.handCards[chairId], [card - 2, card - 1]);
  3058. }
  3059. // 清空权限 吃牌里面
  3060. this._eatType = 0;
  3061. this._eatCard = 0;
  3062. this.gangType = 0;
  3063. this.gangCard = 0;
  3064. this.pengCard = 0;
  3065. _.fill(this.masks, 0);
  3066. // 用户顺序
  3067. this.currentId = chairId;
  3068. //下面是吃后可以直接杠
  3069. this.keGangInfo = {chairId: -1,data:[]};
  3070. let resx1 = this.logic.anGangAnalyze(this.handCards[chairId]);
  3071. let isGang1 = (resx1.length > 0);
  3072. let resx2 = this.logic.zmGangAnalyze(this.handCards[chairId], this.huCards[chairId]);
  3073. let isGang2 = (resx2.length > 0);
  3074. let resx = [];
  3075. let isGang = isGang1 || isGang2;
  3076. if(isGang1) resx = resx.concat(resx1);//暗杠
  3077. if(isGang2) resx = resx.concat(resx2);//自摸杠
  3078. if(isGang){
  3079. for (let x = 0; x < resx.length; ++x) {
  3080. if(this.logic.isCanGang(this.handCards[chairId],this.huCards[chairId],resx[x].type,resx[x].card)){
  3081. if(!this.everyIsGang[chairId][0]){
  3082. this.masks[chairId] |= this.maskValeList[0];//能杠肯定就能补
  3083. }
  3084. this.masks[chairId] |= 8;
  3085. this.keGangInfo.chairId = chairId;
  3086. this.keGangInfo.data.push({pos:resx[x].type,card:resx[x].card});////可杠信息,因为吃牌之后手上虽然有多个杠,但是没有听牌的话是不能杠的
  3087. }
  3088. else{
  3089. if(!this.everyIsGang[chairId][0]){
  3090. this.masks[chairId] |= this.maskValeList[0];
  3091. }
  3092. }
  3093. }
  3094. }
  3095. // 发送通知
  3096. for (let i = 0; i < this.ccount; ++i) {
  3097. let chidata = {
  3098. chairId: String(chairId),
  3099. type: String(type),
  3100. card: String(card)
  3101. }
  3102. if(i == chairId){
  3103. chidata.mask = this.masks[i];
  3104. chidata.keGangInfo = this.keGangInfo;
  3105. let hutipdataTL = this.logic.hutip(i,this.handCards[i],this.huCards[i],this.huCards,this.outCards);////吃牌调用胡牌提示
  3106. chidata.hutipdata = hutipdataTL;
  3107. this.changeCurrQSHInfo(chairId,M.CHI,type,card);
  3108. }
  3109. else{
  3110. chidata.mask = 0;
  3111. chidata.keGangInfo = {chairId: -1,data:[]};
  3112. chidata.hutipdata = {
  3113. renyi:0,//////是否可胡任意牌,0表示不满足1表示满足
  3114. kehuData:[]/////对象数组,分别表示打哪张可胡哪几张数据
  3115. };
  3116. }
  3117. yield this.pushMsgAsync(i, 'csjiang_event', { type: M.CHI, data: chidata });
  3118. }
  3119. let chidatapg = { ////TL++吃牌旁观数据
  3120. chairId: String(chairId),
  3121. type: String(type),
  3122. card: String(card)
  3123. }
  3124. chidatapg.hutipdata = {
  3125. renyi:0,//////是否可胡任意牌,0表示不满足1表示满足
  3126. kehuData:[]/////对象数组,分别表示打哪张可胡哪几张数据
  3127. };
  3128. yield this.lookMsgAsync('csjiang_event', { type: M.CHI, data: chidatapg });////TL++吃牌旁观消息
  3129. ////20200901为了增加胡牌提示把下面这一段换成了上面那一段
  3130. // yield this.pushMsgAsync(-1, 'csjiang_event', { type: M.CHI, data: { chairId: String(chairId), type: String(type), card: String(card) } });
  3131. let pjhfsplist = {
  3132. shouPai:this.logic.deepCloneTL(this.handCards),
  3133. lastCount:String(this.logic.leaveCount()),
  3134. outCards:this.logic.deepCloneTL(this.outCards),
  3135. opData:{ chairId: String(chairId), type: String(type), card: String(card) }
  3136. }
  3137. this.setPaijuHuiFangData(M.CHI,pjhfsplist);/////TL++ 牌局回放 push吃操作数据
  3138. if(this.gangAfterData.chairId != -1){
  3139. let gfcards = this.gangAfterData.cards;
  3140. let xdIndex = 0;
  3141. let newCa = card;
  3142. if(newCa == gfcards.card1) xdIndex = 1;
  3143. else if(newCa == gfcards.card2) xdIndex = 2;
  3144. if(xdIndex > 0){
  3145. let cmoCard = {};
  3146. if(xdIndex == 1) cmoCard = {card1:0,card2:gfcards.card2}
  3147. else if(xdIndex == 2) cmoCard = {card1:gfcards.card1,card2:0}
  3148. yield this.updateGangafterData(this.gangAfterData.chairId,cmoCard);
  3149. }
  3150. }
  3151. }
  3152. } else {
  3153. // 置于等待
  3154. this.masks[chairId] = 3;
  3155. this._eatType = type;
  3156. this._eatCard = card;
  3157. let __cHuDengDai = _.findIndex(this.masks, (m) => (m == 17));//////
  3158. if(__cHuDengDai != -1) {
  3159. // console.warn("吃牌这里调用了胡牌",__cHuDengDai)
  3160. // 为了解决A玩家杠后2张牌发出来之后,B玩家可吃胡C,D玩家可碰杠补胡,然后几人的操作顺序如果最后一个操作为胡或过的时候正常,
  3161. // 但是如果最后一个操作为为吃碰杠补时会卡住的bug
  3162. this.masks[chairId] = 0;
  3163. return this.succCardAsync(__cHuDengDai).then(() => ({ code: C.OK }));
  3164. }
  3165. // 查找等待 TL++下面这一段,为了解决A打出一张牌之后B可吃胡C可碰情况下 C先点碰B点吃会死掉的问题 这是原始代码的重大天然Bug
  3166. let cGang = -1;
  3167. let cBu = -1;
  3168. let cPeng = -1;
  3169. let _cChi = -1;
  3170. // console.warn("这里是啥情况啊",this.masks);
  3171. for (let i = 0; i < this.masks.length; ++i) {
  3172. // if (i == this.currentId || i == chairId) continue;///////TL++zsyl 这种写法会导致拉杠胡的玩家点击过胡之后被拉杠胡的玩家杠不出来的问题
  3173. if (i == chairId) continue;//////TL++,为了解决拉杠胡的玩家点击过胡之后被拉杠胡的玩家杠不出来的问题
  3174. if (this.masks[i] == 9) {
  3175. cGang = i;
  3176. continue;
  3177. }
  3178. if (this.masks[i] == 33) {
  3179. cBu = i;
  3180. continue;
  3181. }
  3182. if (this.masks[i] == 5) {
  3183. cPeng = i;
  3184. continue;
  3185. }
  3186. if (this.masks[i] == 3) {
  3187. _cChi = i;
  3188. continue;
  3189. }
  3190. }
  3191. // console.warn("2222情况啊",cGang, this.gangType,this.gangCard);
  3192. // 杠碰吃
  3193. if (cGang != -1 && this.gangType > 0 && this.gangCard > 0) {
  3194. return this.gangCardAsync(cGang, this.gangCard, this.gangType).then(() => ({ code: C.OK }));
  3195. }
  3196. else if (cBu != -1) {
  3197. return this.buCardAsync(cBu, this.buCard, this.buType).then(() => ({ code: C.OK }));
  3198. }
  3199. else if (cPeng != -1) {
  3200. let cc = this.outCard;
  3201. if(this.gangAfterData.chairId != -1){
  3202. cc = this.pengCard;
  3203. }
  3204. if(cc > 0){
  3205. return this.pengCardAsync(cPeng, cc).then(() => ({ code: C.OK }));
  3206. }
  3207. }
  3208. else if (_cChi != -1 && this._eatType > 0) {
  3209. let cc = this.outCard;
  3210. if(this.gangAfterData.chairId != -1){
  3211. cc = this._eatCard;
  3212. }
  3213. if(cc > 0){
  3214. return this.eatCardAsync(_cChi, cc, this._eatType).then(() => ({ code: C.OK }));
  3215. }
  3216. }
  3217. }
  3218. // let str4 = "cstable 吃牌id:"+this.id + ",uid"+chairId+","+ this.state +",card "+card;
  3219. // logger.info(str4);////cssj
  3220. return { code: C.OK };
  3221. });
  3222. // 补牌,1-普通补, 2-暗补, 3-自摸补
  3223. proto.buCardAsync = cor(function* (chairId, card, type) {
  3224. let str3 = "cstable 补牌,id: "+this.id + " ,uid "+chairId+", this.masks "+ this.masks +" ,card "+card;
  3225. logger.warn(str3);////cssj
  3226. // 参数校验
  3227. if (!type && (type < 1 || type > 3)) {
  3228. return { code: C.FAILD, msg: C.GAME_PARAM_ERROR };
  3229. }
  3230. if(this.gangAfterData.chairId == -1){
  3231. if (type == 1 && card != this.outCard) {
  3232. return { code: C.FAILD, msg: C.GAME_PARAM_ERROR };
  3233. }
  3234. }
  3235. else{
  3236. if (card != this.gangAfterData.cards.card1 && card != this.gangAfterData.cards.card2){
  3237. return { code: C.FAILD, msg: C.GAME_PARAM_ERROR };
  3238. }
  3239. }
  3240. if(this.gangAfterData.chairId == -1){
  3241. if (type > 1 && this.currentId != chairId) {
  3242. return { code: C.FAILD, msg: C.GAME_PARAM_ERROR };
  3243. }
  3244. }
  3245. if (!(this.masks[chairId] & 32)) {
  3246. return { code: C.FAILD, msg: C.TABLE_MASK_ERROR };
  3247. }
  3248. if(!this.logic.isCanCPB(this.handCards[chairId],Logic.STYLE.BU,type)){
  3249. return { code: C.FAILD, msg: C.TABLE_NOTONLYBD };
  3250. }
  3251. // 他人可胡
  3252. // let __cHu = (type == 2) ? -1 : _.findIndex(this.masks, (m) => ((m & 16) && !(m & 8) && !(m & 32) ));
  3253. // console.warn("111拉杠胡%%%%%%%%%%%%%%%%%%%%%%",__cHu,type);
  3254. let isHveeQSH = false;//是否有起手胡
  3255. let tagetChairId = -1;
  3256. let tagetOP = -1;
  3257. for (var i = 0; i < this.masks.length; i++) {
  3258. if(i != chairId){
  3259. if(this.masks[i] & 16){
  3260. isHveeQSH = true;
  3261. break;
  3262. }
  3263. for (var x = 1; x < this.maskValeList.length; x++) {
  3264. if(this.masks[i] & this.maskValeList[x]){
  3265. isHveeQSH = true;
  3266. break;
  3267. }
  3268. }
  3269. }
  3270. }
  3271. if(!isHveeQSH && this.gangAfterData.chairId != -1){
  3272. //只有杠后两张牌的时候杠才会两个人同时出现
  3273. //至此没有人可以胡
  3274. let otherKG = -1;//除点补之外可杠或可补的玩家
  3275. for (var i = 0; i < this.masks.length; i++) {
  3276. if(i != chairId && (this.masks[i] & 8 || chairId && this.masks[i] & 32)){
  3277. otherKG = i;
  3278. break;
  3279. }
  3280. }
  3281. if(otherKG >= 0){
  3282. let zjjl = 0;
  3283. if((this.gangAfterData.chairId + 1) % this.ccount == chairId) zjjl = 1;
  3284. else if((this.gangAfterData.chairId + 2) % this.ccount == chairId) zjjl = 2;
  3285. else if((this.gangAfterData.chairId + 3) % this.ccount == chairId) zjjl = 3;
  3286. let qtjl = 0;
  3287. if((this.gangAfterData.chairId + 1) % this.ccount == otherKG) qtjl = 1;
  3288. else if((this.gangAfterData.chairId + 2) % this.ccount == otherKG) qtjl = 2;
  3289. else if((this.gangAfterData.chairId + 3) % this.ccount == otherKG) qtjl = 3;
  3290. if(zjjl > qtjl){
  3291. if(this.masks[otherKG] == 9 || this.masks[otherKG] == 33){
  3292. tagetChairId = otherKG;
  3293. if(this.masks[otherKG] == 9) tagetOP = 8;
  3294. }
  3295. else{
  3296. isHveeQSH = true;
  3297. }
  3298. }
  3299. }
  3300. }
  3301. if (!isHveeQSH) { //(__cHu == -1) {
  3302. let newCh = chairId;
  3303. let newCa = card;
  3304. let newTy = type
  3305. if(tagetChairId > 0){
  3306. newCh = tagetChairId;//B玩家点杠或补之后需要等待C玩家点胡,如果C玩家点了杠就让B玩家杠或补
  3307. if(tagetOP == 8){
  3308. newCa = this.gangCard;
  3309. newTy = this.gangType;
  3310. }else{
  3311. newCa = this.buCard;
  3312. newTy = this.buType;
  3313. }
  3314. }
  3315. let res = null;
  3316. if (newTy == 1 || newTy == 2) {
  3317. res = this.logic.bu(newCh,this.handCards[newCh], newCa, newTy);
  3318. } else if (newTy == 3) {
  3319. res = this.logic.zmBu(newCh,this.handCards[newCh], this.huCards[newCh], newCa);
  3320. }
  3321. if (!res) {
  3322. return { code: C.FAILD, msg: C.TABLE_GANG_ERROR };
  3323. }
  3324. /////TL++7月17日,这整个if的内容 和else的判断
  3325. let winner = this.winner;
  3326. if (winner.chs.length > 0) {
  3327. yield this.pushMsgAsync(-1, 'csjiang_event', { type: M.HU, data: { lead: String(this.logic.getLead(this.gangAfterData.chairId,winner.lead,winner.chs)), chairIds: winner.chs } });
  3328. this.setPaijuHuiFangData(M.HU,{ lead: String(winner.lead), chairIds: winner.chs });/////TL++ 牌局回放 push吃胡牌数据
  3329. // console.warn("提前结算BBB");
  3330. yield this.concludeGameAsync(MODE.NORMAL);
  3331. }
  3332. else{
  3333. // 记录补牌
  3334. if (newTy == 1) {
  3335. if(this.gangAfterData.chairId == -1){
  3336. res.origin = this.outerId;
  3337. this.outCards[this.outerId].pop();
  3338. }
  3339. else{
  3340. res.origin = this.gangAfterData.chairId;
  3341. }
  3342. this.huCards[newCh].push(res);
  3343. this.logic.remove(this.handCards[newCh], res.cards);
  3344. } else if (newTy == 2) {
  3345. this.huCards[newCh].push(res);
  3346. this.logic.remove(this.handCards[newCh], [newCa, newCa, newCa, newCa]);
  3347. this.logic.adjust(this.handCards[newCh]);
  3348. } else if (newTy == 3) {
  3349. // console.warn("333拉杠胡%%%%%%%%%%%%%%%%%%%%%%",this.logic.isLaGang,this.isGangHu);
  3350. let huCard = _.find(this.huCards[newCh], (o) => {
  3351. return (o.style == Logic.STYLE.PENG && o.cards[0] == newCa);
  3352. });
  3353. if (!huCard) {
  3354. return { code: C.FAILD, msg: C.TABLE_GANG_ERROR };
  3355. }
  3356. // console.warn("拉杠胡%%%%%%%%%%%%%%%%%%%%%%" ,this.isGangHu);
  3357. // 抢杠胡
  3358. if (!this.isBuHu) {
  3359. let allowIds = [], otherIds = [];
  3360. for (let i = 0; i < this.ccount; ++i) {
  3361. // 排除自己
  3362. if (i != newCh) {
  3363. let huRes = this.logic.huAnalyze(i,this.handCards[i], newCa, this.huCards[i]);
  3364. // console.error("ssccCCC胡牌分析 huRes",huRes);
  3365. // let lg2 = false;///TL++
  3366. if (huRes) {
  3367. if (!this.isBuHu) this.isGangHu = true;
  3368. this.huRes[i] = huRes;
  3369. this.masks[i] |= 16;
  3370. allowIds.push(this.users[i].id); continue;
  3371. }
  3372. }
  3373. // 其他玩家
  3374. otherIds.push(this.users[i].id);
  3375. }
  3376. // 有人可胡
  3377. if (allowIds.length > 0) {
  3378. // 置于等待
  3379. this.masks[chairId] = 33;
  3380. this.buType = type;
  3381. this.buCard = card;
  3382. // 抢补通知
  3383. yield this.pushMsgAsync(otherIds, 'csjiang_event', { type: M.MASK_HU, data: { mask: '0', card: String(newCa),isBu: '1' } });
  3384. yield this.pushMsgAsync(allowIds, 'csjiang_event', { type: M.MASK_HU, data: { mask: '16', card: String(newCa),isBu: '1' } });
  3385. let pjhfsplist2 = {
  3386. shouPai:this.logic.deepCloneTL(this.handCards),
  3387. lastCount:this.logic.leaveCount(),
  3388. outCards:this.logic.deepCloneTL(this.outCards),
  3389. opData:{ mask: '16', card: String(newCa),isBu: '1' }
  3390. }
  3391. this.setPaijuHuiFangData(M.MASK_HU,pjhfsplist2);/////TL++ 牌局回放 push杠操作数据
  3392. // console.warn("抢杠胡同盟会告知",allowIds);
  3393. return { code: C.OK };
  3394. }
  3395. }
  3396. huCard.style = Logic.STYLE.ZMBU;
  3397. this.isGangHu = false;/////TL++,修复20250309号bug
  3398. // console.warn("55拉补胡%%%%%%%%%%%%%%%%%%%%%%",this.logic.isLaGang,this.buType,this.buCard = 0);
  3399. this.isBuHu = false;/////TL++,8月28日晚上,为了解决过胡拉杠之后就算自己已经摸牌也不能再次拉杠的问题
  3400. this.logic.remove(this.handCards[newCh], newCa);
  3401. this.logic.adjust(this.handCards[newCh]);
  3402. }
  3403. // if(this.chBanker == chairId) this.isZJYG = true;////本局庄家是否有杠
  3404. // 清空权限 补牌里面
  3405. this._eatType = 0;
  3406. this._eatCard = 0;
  3407. this.gangType = 0;
  3408. this.gangCard = 0;
  3409. this.buType = 0;
  3410. this.buCard = 0;
  3411. this.pengCard = 0;
  3412. _.fill(this.masks, 0);
  3413. // 总杠次
  3414. // this.gonCount += 1;
  3415. // 发送通知
  3416. // console.warn("333 声剩余声剩余声剩");
  3417. let lastCount = this.logic.leaveCount();/////TL++xg
  3418. let pjhfsplist = {
  3419. shouPai:this.logic.deepCloneTL(this.handCards),
  3420. lastCount:lastCount,
  3421. outCards:this.logic.deepCloneTL(this.outCards),
  3422. opData:{ chairId: String(newCh), type: String(newTy), card: String(newCa), lastCount: String(lastCount) }
  3423. }
  3424. if(tagetOP == 8){
  3425. // console.warn("走到这里了=== newCh "+newCh);
  3426. this.changeCurrQSHInfo(newCh,M.GANG,newTy,newCa);
  3427. this.setPaijuHuiFangData(M.GANG,pjhfsplist);/////TL++ 牌局回放 push杠操作数据
  3428. yield this.pushMsgAsync(-1, 'csjiang_event', { type: M.GANG, data: { chairId: String(newCh), type: String(newTy), card: String(newCa), lastCount: String(lastCount) } });
  3429. }else {
  3430. this.changeCurrQSHInfo(newCh,M.BU,newTy,newCa);
  3431. this.setPaijuHuiFangData(M.BU,pjhfsplist);/////TL++ 牌局回放 push杠操作数据
  3432. yield this.pushMsgAsync(-1, 'csjiang_event', { type: M.BU, data: { chairId: String(newCh), type: String(newTy), card: String(newCa), lastCount: String(lastCount) } });
  3433. }
  3434. if(this.gangAfterData.chairId != -1){
  3435. let gfcards = this.gangAfterData.cards;
  3436. let xdIndex = 0;
  3437. if(newCa == gfcards.card1) xdIndex = 1;
  3438. else if(newCa == gfcards.card2) xdIndex = 2;
  3439. if(xdIndex > 0){
  3440. let cmoCard = {};
  3441. if(xdIndex == 1) cmoCard = {card1:0,card2:gfcards.card2}
  3442. else if(xdIndex == 2) cmoCard = {card1:gfcards.card1,card2:0}
  3443. yield this.updateGangafterData(this.gangAfterData.chairId,cmoCard);
  3444. }
  3445. }
  3446. yield this.touchCardAsync(newCh); ///////补牌摸牌
  3447. }
  3448. } else {
  3449. let ddcwj = _.findIndex(this.masks, (m, i) => (m == 33));//等待吃的玩家
  3450. let gxtype = this.logic.getDDGXType(3,chairId,ddcwj,this.gangAfterData.chairId,this.ccount,this.masks);
  3451. let old_buType = this.buType;
  3452. let old_buCard = this.buCard;
  3453. // 置于等待
  3454. this.masks[chairId] = 33;
  3455. this.buType = type;
  3456. this.buCard = card;
  3457. if(gxtype == 1){
  3458. this.masks[ddcwj] = 0;
  3459. }
  3460. else if(gxtype == 2){
  3461. this.masks[chairId] = 0;
  3462. this.buType = old_buType;
  3463. this.buCard = old_buCard;
  3464. }
  3465. let __cHuDengDai = _.findIndex(this.masks, (m) => (m == 17));//////
  3466. if(__cHuDengDai != -1) {
  3467. // console.warn("补牌这里调用了胡牌",__cHuDengDai)
  3468. // 为了解决A玩家杠后2张牌发出来之后,B玩家可吃胡C,D玩家可碰杠补胡,然后几人的操作顺序如果最后一个操作为胡或过的时候正常,
  3469. // 但是如果最后一个操作为为吃碰杠补时会卡住的bug
  3470. this.masks[chairId] = 0;
  3471. return this.succCardAsync(__cHuDengDai).then(() => ({ code: C.OK }));
  3472. }
  3473. else{
  3474. // 查找起手胡等待
  3475. // 为了解决A玩家起手牌可以胡杠补,BC玩家有六六顺时,BC玩家先点六六顺之后A玩家点杠或补会卡住的bug,
  3476. // (正确应为:BC玩家先点六六顺之后A玩家点杠后应该六六顺和杠或补都生效,若玩家A点胡则胡生效六六顺不生效)
  3477. for (let i = 0; i < this.masks.length; ++i) {
  3478. let cqsh = -1;
  3479. // console.warn("补牌里处理等待的起手胡111 "+this.masks[i]);
  3480. // if (i == this.currentId || i == chairId) continue;///////TL++zsyl 这种写法会导致拉杠胡的玩家点击过胡之后被拉杠胡的玩家杠不出来的问题
  3481. if (i == chairId) continue;//////TL++,为了解决拉杠胡的玩家点击过胡之后被拉杠胡的玩家杠不出来的问题
  3482. if (this.masks[i] == 65 || this.masks[i] == 129 ||this.masks[i] == 257 ||this.masks[i] == 513 ||this.masks[i] == 1025 ||this.masks[i] == 2049) {
  3483. cqsh = i;
  3484. }
  3485. if (cqsh != -1 ) {
  3486. // console.warn("处理等待的起手胡222 ",cqsh, this.qshType[cqsh], this.qshCards[cqsh]);
  3487. this.masks[i]--;//mask=129传给前端是不显示按钮的,为了等待在原本的mask上+1了,现在可以操作了所以-1
  3488. yield this.qshCardAsync(cqsh, this.qshType[cqsh], this.qshCards[cqsh]).then(() => ({ code: C.OK }));
  3489. }
  3490. }
  3491. }
  3492. }
  3493. // let str4 = "cstable222 杠牌,id:"+this.id + ",uid"+chairId+","+ this.state +",card "+card;
  3494. // logger.info(str4);////cssj
  3495. return { code: C.OK };
  3496. });
  3497. proto.changeCurrQSHInfo = function (chairId,operate,type,card){
  3498. // console.warn("吃碰杠之后修改起手胡需要展示的牌 ",chairId,operate,type,card,this.currQSHInfo[chairId].length);
  3499. if(this.currQSHInfo[chairId].length == 0) return;
  3500. let cards = [];
  3501. if(operate == M.OUT_CARD){
  3502. cards = [card];
  3503. }
  3504. else if(operate == M.CHI){
  3505. if(type == 1) cards = [card+1,card+2];
  3506. else if(type == 2) cards = [card-1,card+1];
  3507. else if(type == 3) cards = [card-1,card-2];
  3508. }
  3509. else if(operate == M.PENG){
  3510. cards = [card,card];
  3511. }
  3512. else if(operate == M.GANG){
  3513. if(type == 1) cards = [card,card,card];
  3514. else if(type == 2) cards = [card,card,card,card];
  3515. else if(type == 3) cards = [card];
  3516. }
  3517. else if(operate == M.BU){
  3518. if(type == 1) cards = [card,card,card];
  3519. else if(type == 2) cards = [card,card,card,card];
  3520. else if(type == 3) cards = [card];
  3521. }
  3522. let oldCards = this.logic.deepCloneTL(this.currQSHInfo[chairId][0].cards);
  3523. // console.warn("更新当前起手牌型数据111oldCards ",oldCards)
  3524. for (let j = 0; j < cards.length; j++) {
  3525. if(cards[j] == 0) continue;
  3526. let iscz = false;
  3527. for (let k = 0; k < oldCards.length; k++) {
  3528. if(cards[j] == oldCards[k]){
  3529. oldCards[k] = -1;
  3530. iscz = true;
  3531. break;
  3532. }
  3533. }
  3534. if(!iscz){
  3535. for (let k = 0; k < oldCards.length; k++) {
  3536. if(oldCards[k] == 0){
  3537. oldCards[k] = -1;
  3538. break;
  3539. }
  3540. }
  3541. }
  3542. }
  3543. // console.warn("更新当前起手牌型数据222oldCards ",oldCards)
  3544. let newCards = [];
  3545. for (let k = 0; k < oldCards.length; k++) {
  3546. if(oldCards[k] > -1){
  3547. newCards[newCards.length] = oldCards[k];
  3548. }
  3549. }
  3550. // console.warn("更新当前起手牌型数据333newCards ",newCards)
  3551. this.currQSHInfo[chairId][0].cards = newCards;
  3552. // console.warn("更新当前起手牌型数据444 .Cards ",this.currQSHInfo[chairId][0].cards)
  3553. };
  3554. // 起手胡 处理前端
  3555. proto.qshCardAsync = cor(function* (chairId,_type,_cards) {
  3556. let str4 = "cstable222 起手胡,id:"+this.id + ",uid"+chairId+" _type "+ _type +",_cards "+_cards;
  3557. logger.warn(str4);////cssj
  3558. let msk = this.masks[chairId];
  3559. // console.warn("起手胡 chairId " + chairId + " msk "+msk+" _cards "+_cards );
  3560. if (!(msk & 64 || msk & 128 || msk & 256 || msk & 512 || msk & 1024 || msk & 2048)) {
  3561. return { code: C.FAILD, msg: C.TABLE_MASK_ERROR };
  3562. }
  3563. let cards = _cards;//起手牌型需要展示给其他玩家的牌
  3564. let cards2 = this.logic.deepCloneTL(_cards);
  3565. let qshType = _type;//.indexOf(1);
  3566. if(this.logic.everyQSHType[chairId][qshType] == 0){
  3567. return { code: C.FAILD, msg: C.TABLE_MASK_ERROR };
  3568. }
  3569. else{
  3570. //起手的六六顺消耗过的牌起手四喜不能再次使用,起手四喜消耗过的牌起手六六顺不能再次使用,
  3571. // console.warn("起手胡22 qshType " + qshType + " everyXiaoHuList "+this.logic.everyXiaoHuList[chairId]);
  3572. if(qshType == 0){
  3573. if(this.logic.getISBH(this.handCards[chairId],cards) && !this.logic.getISBH(this.logic.everyQSHCZGList[chairId],cards)){
  3574. // console.warn("起手牌型参数合法");
  3575. if(qshType == 0){
  3576. if(this.logic.everyXiaoHuList[chairId].indexOf(1) != -1 || this.logic.everyXiaoHuList[chairId].indexOf(2) != -1){
  3577. //起手点了板板胡或者缺一色之后再点大四喜或者六六顺,需要展示全部的牌
  3578. cards = this.logic.deepCloneTL(this.handCards[chairId]);
  3579. }
  3580. }
  3581. }
  3582. else{
  3583. return { code: C.FAILD, msg: C.GAME_PARAM_ERROR };
  3584. }
  3585. }
  3586. else if(qshType == 1 ){
  3587. if(this.logic.everyXiaoHuList[chairId].indexOf(qshType) == -1){
  3588. // console.warn("起手牌型参数合法");
  3589. cards = this.logic.deepCloneTL(this.handCards[chairId]);
  3590. }
  3591. else{
  3592. return { code: C.FAILD, msg: C.GAME_PARAM_ERROR };
  3593. }
  3594. }
  3595. else if(qshType == 2){
  3596. if(this.logic.everyXiaoHuList[chairId].indexOf(qshType) == -1){
  3597. // console.warn("起手牌型参数合法");
  3598. cards = this.logic.deepCloneTL(this.handCards[chairId]);
  3599. }
  3600. else{
  3601. let isqs = this.logic.castCount == this.playerAllCount*this.mcount+1;//是否起手
  3602. let shoupai = this.logic.deepCloneTL(this.handCards[chairId]);
  3603. let ismz = this.logic.isQueYiSe(chairId,shoupai,isqs);
  3604. //清一色可胡两次缺一色
  3605. if(ismz) cards = this.logic.deepCloneTL(this.handCards[chairId]);
  3606. else return { code: C.FAILD, msg: C.GAME_PARAM_ERROR };
  3607. }
  3608. }
  3609. else if(qshType == 3 || qshType == 5){
  3610. if(this.logic.getISBH(this.handCards[chairId],cards) && !this.logic.getISBH(this.logic.everyQSHCZGList[chairId],cards)){
  3611. if(qshType == 3){
  3612. if(this.logic.everyXiaoHuList[chairId].indexOf(1) != -1 || this.logic.everyXiaoHuList[chairId].indexOf(2) != -1){
  3613. //起手点了板板胡或者缺一色之后再点大四喜或者六六顺,需要展示全部的牌
  3614. cards = this.logic.deepCloneTL(this.handCards[chairId]);
  3615. }
  3616. }
  3617. }
  3618. else{
  3619. return { code: C.FAILD, msg: C.GAME_PARAM_ERROR };
  3620. }
  3621. }
  3622. else if(qshType == 4){
  3623. //起手六六顺或者中途六六顺消耗过的牌中途四喜可以再次使用,
  3624. if(this.logic.getISBH(this.handCards[chairId],cards) && !this.logic.getISBH2(this.logic.everyQSHCZGList2[chairId],cards)){
  3625. if(qshType == 3){
  3626. if(this.logic.everyXiaoHuList[chairId].indexOf(1) != -1 || this.logic.everyXiaoHuList[chairId].indexOf(2) != -1){
  3627. //起手点了板板胡或者缺一色之后再点大四喜或者六六顺,需要展示全部的牌
  3628. cards = this.logic.deepCloneTL(this.handCards[chairId]);
  3629. }
  3630. }
  3631. }
  3632. else{
  3633. return { code: C.FAILD, msg: C.GAME_PARAM_ERROR };
  3634. }
  3635. }
  3636. }
  3637. let __cHu = -1;//_.findIndex(this.masks, (m) => ((m & 16) ));
  3638. for (let i = 0; i < this.masks.length; ++i) {
  3639. if(i != chairId && this.masks[i] & 16){
  3640. __cHu = i;
  3641. break;
  3642. }
  3643. }
  3644. this.qshType[chairId] = 0;
  3645. this.qshCards[chairId] = [];
  3646. if (__cHu == -1) {
  3647. //删除起手胡权限
  3648. // console.warn("删除起手胡权限之前");
  3649. this.masks[chairId] = this.logic.getNewMask(this.masks[chairId]);
  3650. if(qshType == 0 || qshType == 4 || qshType == 3 || qshType == 5){
  3651. this.logic.everyQSHCZGList[chairId] = this.logic.everyQSHCZGList[chairId].concat(cards2);
  3652. this.logic.everyQSHCZGList2[chairId].push(cards2);
  3653. // console.warn("...... everyQSHCZGList "+chairId+" "+JSON.stringify(this.logic.everyQSHCZGList2[chairId]));
  3654. }
  3655. this.logic.everyXiaoHuList[chairId].push(qshType);
  3656. // console.warn("删除起手胡权限 everyXiaoHuList "+this.logic.everyXiaoHuList[chairId]);
  3657. this.logic.qshuAnalyze(chairId,this.handCards[chairId]);
  3658. for (let x = 0; x < this.logic.everyQSHType[chairId].length; ++x) {
  3659. if(this.logic.everyQSHType[chairId][x] == 1){
  3660. this.masks[chairId] |= this.maskValeList[x+1];
  3661. }
  3662. }
  3663. for (let x = 0; x < this.handCards[chairId].length; ++x) {
  3664. if(x >= cards.length) cards[cards.length] = 0;
  3665. }
  3666. _.reverse(cards)
  3667. let isCanOut = this.logic.getIsCanOut(this.masks);
  3668. let diceNum1 = this.logic.dice();
  3669. let diceNum2 = this.logic.dice();
  3670. this.currQSHInfo[chairId][0] = {//当前各个玩家展示的起手胡信息
  3671. chairId: chairId,
  3672. type: qshType,
  3673. cards: cards,
  3674. diceNums: [diceNum1,diceNum2]
  3675. }
  3676. let qshdata = {
  3677. chairId: chairId,
  3678. type: qshType,
  3679. cards: cards,
  3680. isCanOut: isCanOut
  3681. }
  3682. qshdata.startNum1 = String(diceNum1);////骰子1的点数
  3683. qshdata.startNum2 = String(diceNum2);////骰子2的点数
  3684. let bcQSHSY = this.logic.getBCQSHSY(chairId,qshType,diceNum1,diceNum2);//本次起手胡各个玩家的输赢
  3685. let playNowScore = [];
  3686. for (let i = 0; i < this.ccount; ++i) {
  3687. let user = this.users[i];
  3688. if (user)
  3689. {
  3690. playNowScore[i] = this.score.getScore(user.id) + bcQSHSY[i];
  3691. // console.warn("得到分数 i "+i+" get "+this.score.getScore(user.id)+" bcsy "+bcQSHSY[i]+" now "+playNowScore[i]);
  3692. this.score.writeScore(user.id,bcQSHSY[i], 0);//设置分数
  3693. }
  3694. }
  3695. qshdata.playNowScore = playNowScore;
  3696. for (let i = 0; i < this.ccount; ++i) {
  3697. if(i == chairId){
  3698. // console.warn("this.masks[chairId] "+this.masks[chairId]);
  3699. qshdata.canSelects = this.logic.canSelects[chairId]
  3700. qshdata.mask = String(this.masks[chairId]);
  3701. //
  3702. }
  3703. else{
  3704. qshdata.mask = 0;
  3705. qshdata.canSelects = {type:-1,cards:[]}
  3706. }
  3707. yield this.pushMsgAsync(i, 'csjiang_event', { type: M.QSH, data: qshdata } );
  3708. }
  3709. qshdata.mask = 0;
  3710. qshdata.canSelects = {type:-1,cards:[]}
  3711. yield this.lookMsgAsync('csjiang_event', { type: M.QSH, data: qshdata });
  3712. qshdata.mask = String(this.masks[chairId]);
  3713. qshdata.canSelects = this.logic.canSelects[chairId];
  3714. this.setPaijuHuiFangData(M.QSH,qshdata);
  3715. // console.warn("起手胡操作之后的mask "+this.masks);
  3716. if(_.findIndex(this.masks, (m) => ((m >= 64))) == -1){
  3717. //没有玩家有起手胡的时候查找并处理杠补的等待
  3718. for (let i = 0; i < this.masks.length; ++i) {
  3719. let cGang = -1;
  3720. let cbu = -1;
  3721. if (this.masks[i] == 9) {
  3722. cGang = i;
  3723. }
  3724. if (this.masks[i] == 33) {
  3725. cbu = i;
  3726. }
  3727. if (cGang != -1 && this.gangType > 0 && this.gangCard > 0) {
  3728. yield this.gangCardAsync(cGang, this.gangCard, this.gangType).then(() => ({ code: C.OK }));
  3729. }
  3730. else if (cbu != -1 && this.buCard > 0) {
  3731. yield this.buCardAsync(cbu, this.buCard, this.buType).then(() => ({ code: C.OK }));
  3732. }
  3733. }
  3734. }
  3735. } else {
  3736. // 置于等待
  3737. let ddmskList = [65,129,257,513,1025,2049];
  3738. this.masks[chairId] = ddmskList[qshType];
  3739. this.qshType[chairId] = qshType;
  3740. this.qshCards[chairId] = _cards;
  3741. // console.warn("置于等待 "+this.masks[chairId]);
  3742. }
  3743. return { code: C.OK };
  3744. })
  3745. // 操作是否自动出牌
  3746. proto.autoOutCardAsync = cor(function* (chairId) {
  3747. // console.warn("操作是否自动出牌 "+chairId);
  3748. if(this.everyIsAutoOut[chairId]) this.everyIsAutoOut[chairId] = 0;
  3749. else this.everyIsAutoOut[chairId] = 1;
  3750. return { code: C.OK,isAutoOut:this.everyIsAutoOut[chairId]};
  3751. })
  3752. // 胡牌 处理前端
  3753. proto.succCardAsync = cor(function* (chairId) {
  3754. let str3 = "cstable 胡牌:%s "+this.id + " ,uid "+chairId+" ,this.masks "+ this.masks;
  3755. logger.warn(str3);////cssj
  3756. // 权限校验
  3757. if (!(this.masks[chairId] & 16)) {
  3758. return { code: C.FAILD, msg: C.TABLE_MASK_ERROR };
  3759. }
  3760. // 删除权限
  3761. let isCanSCQX = true;//是否可以删除权限
  3762. if(this.gangAfterData.chairId != -1){
  3763. if(chairId != this.gangAfterData.chairId && this.masks[this.gangAfterData.chairId] & 16) isCanSCQX = false;
  3764. //1022修复杠后两张牌一炮多响,一人点胡之后另外一个人点过之后卡住(没胡成功也没继续发牌)的bug添加下面这个if
  3765. if(chairId != this.gangAfterData.chairId && isCanSCQX){
  3766. let otherKH = _.findIndex(this.masks, (m, i) => ((m & 16 && m != 17 && i != chairId)))
  3767. if(otherKH != -1) isCanSCQX = false;
  3768. }
  3769. }
  3770. // console.warn("是否可以删除权限 "+isCanSCQX);
  3771. if(isCanSCQX){
  3772. // console.error("胡牌 处理前端 可以删除权限 ");
  3773. if(chairId == this.gangAfterData.chairId){
  3774. for (let i = 0; i < this.masks.length; ++i) {
  3775. this.masks[i] = 0;
  3776. }
  3777. }
  3778. else{
  3779. this.masks[chairId] = 0;
  3780. }
  3781. }
  3782. else{
  3783. this.masks[chairId] = 17;//置于等待
  3784. // console.warn("胡牌 处理前端 置于等待");
  3785. return { code: C.OK };
  3786. }
  3787. // 是否自摸
  3788. let winner = this.winner;
  3789. var isMoHu = (this.currentId == chairId);
  3790. // if(this.gangAfterData.chairId != -1 && this.gangAfterData.chairId == chairId) isMoHu = true;
  3791. //1022修复杠后两张牌一炮多响,两人都点胡只有一个能胡成功的bug把上面的if换成了下面这个if
  3792. if(this.gangAfterData.chairId != -1){
  3793. isMoHu = (this.gangAfterData.chairId == chairId)
  3794. }
  3795. // console.warn("胡牌 处理前端 ",this.currentId ,chairId,this.masks,this.gangAfterData.chairId);
  3796. if (isMoHu) {
  3797. // console.warn("胡牌 这里是自摸胡 ");
  3798. winner.chs[0] = chairId;
  3799. yield this.pushMsgAsync(-1, 'csjiang_event', { type: M.HU, data: { lead: String(this.logic.getLead(this.gangAfterData.chairId,winner.lead,winner.chs)), chairIds: winner.chs } });
  3800. this.setPaijuHuiFangData(M.HU,{ lead: String(winner.lead), chairIds: winner.chs });/////TL++ 牌局回放 push摸胡牌数据
  3801. // console.warn("提前结算444");
  3802. yield this.concludeGameAsync(MODE.NORMAL);
  3803. } else {
  3804. // console.warn("胡牌 这里补是自摸胡 isGangHu "+this.isGangHu+" isMHu "+this.isMHu);
  3805. // 抢杠胡
  3806. if (this.isGangHu) {
  3807. winner.lead = this.currentId;
  3808. // 抢杠牌
  3809. if (this.gangType > 0 && this.gangCard > 0) {
  3810. this.logic.remove(this.handCards[this.currentId], this.gangCard);
  3811. this.masks[this.currentId] = 0;
  3812. this.gangType = 0; this.gangCard = 0;
  3813. this.buType = 0; this.buCard = 0;
  3814. this.pengCard = 0;
  3815. }
  3816. } else {
  3817. // 点炮
  3818. winner.lead = this.outerId;
  3819. }
  3820. // 一炮多响
  3821. let __cHu = -1;
  3822. if (this.isMHu) {
  3823. // 胡牌者
  3824. winner.chs.push(chairId);
  3825. // 他人可胡
  3826. __cHu = _.findIndex(this.masks, (m) => ((m & 16)));
  3827. } else {
  3828. // 胡牌者
  3829. if (winner.chs.length <= 0) winner.chs[0] = chairId;
  3830. else {
  3831. let hutype = [];//this.logic.getReasultTypeTL(winner.chs[0],this.huCards[winner.chs[0]],false)
  3832. let hutypenew = []//this.logic.getReasultTypeTL(chairId,this.huCards[chairId],false)
  3833. winner.chs[0] = chairId;
  3834. }
  3835. // 他人可胡
  3836. __cHu = _.findIndex(this.masks, (m, i) => ((m & 16)))
  3837. }
  3838. // console.warn("有一炮多响 __cHu "+__cHu+" gangAfterData.chairId "+this.gangAfterData.chairId);
  3839. // console.warn("22局部变量改变全局变量??",winner ,this.winner);
  3840. // console.warn("点击胡按钮",__cHu,this.masks);
  3841. if (__cHu == -1) {
  3842. yield this.pushMsgAsync(-1, 'csjiang_event', { type: M.HU, data: { lead: String(this.logic.getLead(this.gangAfterData.chairId,winner.lead,winner.chs)), chairIds: winner.chs } });
  3843. this.setPaijuHuiFangData(M.HU,{ lead: String(winner.lead), chairIds: winner.chs });/////TL++ 牌局回放 push吃胡牌数据
  3844. // console.warn("提前结算555");
  3845. yield this.concludeGameAsync(MODE.NORMAL);
  3846. }
  3847. else{
  3848. let __cHuDEngDai = _.findIndex(this.masks, (m, i) => ((m == 17)))
  3849. // console.warn("这里调用的嘛?? __cHuDEngDai "+__cHuDEngDai);
  3850. if(__cHuDEngDai != -1){
  3851. return this.succCardAsync(__cHuDEngDai).then(() => ({ code: C.OK }));
  3852. }
  3853. }
  3854. }
  3855. return { code: C.OK };
  3856. });
  3857. // 结算游戏
  3858. proto.concludeGameAsync = cor(function* (mode) {
  3859. /////增加下面这几行是为了保证每一把只执行一次结算方法
  3860. if(this.isYJJSGL){
  3861. // let strk = "cstable 结算游戏 id:了保证每一把只执行一次结算方法 "+this.id +"结算模式"+mode
  3862. // logger.info(strk);////cssj
  3863. return;
  3864. }
  3865. this.isYJJSGL = true;
  3866. this.isYJKSGL = false;/////是否已经执行过开始函数了
  3867. this.everyIsAutoOut = _.fill(Array(this.ccount), 0);
  3868. // console.warn("结算函数",mode);
  3869. let str1 = "cstable 结算游戏 id: "+this.id +" 结算模式 "+mode
  3870. logger.warn(str1);////cssj
  3871. //ts--end
  3872. // 结算数据
  3873. var winner = this.winner;
  3874. var data = { mode: String(mode), lead: String(winner.lead) };
  3875. var wins = this.logic.fillDeep(Array(this.ccount), {
  3876. win: 0,//总输赢
  3877. lucky: 0,
  3878. trans: 0,//明杠个数
  3879. dark: 0,//暗杠个数
  3880. penggang: 0,//碰杠个数
  3881. isPoChan: 0,
  3882. shiJiKouFen: 0,
  3883. gangfen: 0,
  3884. cardfen: 0,
  3885. jiangma: 0,
  3886. });
  3887. // data.hutype = [];//this.logic.getReasultTypeTL(winner.chs[0],this.huCards[winner.chs[0]],true)///////TL++胡牌牌型 胡牌人的chairID
  3888. data.banker = this.chBanker;/////TL++
  3889. data.chengbao = [];
  3890. let jiangmaInfo = this.logic.getJiangmaInfo();
  3891. data.jiangmaList = jiangmaInfo.jiangmaList;
  3892. data.startNum1 = jiangmaInfo.startNum1;
  3893. data.startNum2 = jiangmaInfo.startNum2;
  3894. // let jiangmaFen = jiangmaInfo.mafen;
  3895. let everyIsHLZ = [false,false,false,false];
  3896. let everyDaHuType = [[[],[]],[[],[]],[[],[]],[[],[]]];
  3897. if(this.gangAfterData.chairId != -1){
  3898. // console.warn("如果杠后两张牌都能胡则2张牌都要计算 "+this.gangAfterData.cards.card1+" "+this.gangAfterData.cards.card2);
  3899. //如果杠后两张牌都能胡则2张牌都要计算
  3900. for (let i = 0; i < wins.length; ++i) {
  3901. if (winner.chs.indexOf(i) == -1) continue;
  3902. // console.warn("数据会不会变000 "+this.handCards[i]+" huCards "+JSON.stringify(this.huCards[i]));
  3903. let istouch = false;//this.gangAfterData.chairId == i;
  3904. let card1 = this.gangAfterData.cards.card1;
  3905. let huRes1 = this.logic.huAnalyze(i,this.handCards[i], card1, this.huCards[i], istouch);//杠后摸牌判断第1张
  3906. // console.warn("数据会不会变111 "+this.handCards[i]+" huCards "+JSON.stringify(this.huCards[i]));
  3907. if (huRes1) {
  3908. let dhType = this.logic.deepCloneTL(this.logic.everyDAHType[i]);
  3909. let card2 = this.gangAfterData.cards.card2;
  3910. let huRes2 = this.logic.huAnalyze(i,this.handCards[i], card2, this.huCards[i], istouch);//杠后摸牌判断第2张
  3911. // console.warn("数据会不会变222 "+this.handCards[i]+" huCards "+JSON.stringify(this.huCards[i]));
  3912. if (huRes2) {
  3913. everyIsHLZ[i] = true;
  3914. everyDaHuType[i][0] = dhType;
  3915. everyDaHuType[i][1] = this.logic.everyDAHType[i];
  3916. }
  3917. }
  3918. }
  3919. }
  3920. // console.warn("结算函数计算每个人是否胡两张 "+this.gangAfterData.chairId+" everyIsHLZ "+everyIsHLZ+" everyDaHuType "+JSON.stringify(everyDaHuType));
  3921. let yjgs = 0;//赢家个数
  3922. for (let i = 0; i < wins.length; ++i) {
  3923. if (winner.chs.indexOf(i) != -1) yjgs++;
  3924. }
  3925. // 自摸
  3926. let isMoHu = winner.lead == -1;
  3927. // console.warn("计算是否自摸111 this.gangAfterData.chairId "+this.gangAfterData.chairId+" yjgs "+yjgs+" lead "+winner.lead);
  3928. if(this.gangAfterData.chairId != -1){
  3929. if(yjgs > 1){
  3930. isMoHu = false;
  3931. winner.lead = this.gangAfterData.chairId;
  3932. }
  3933. else if(yjgs == 1){
  3934. if(winner.chs[0] == this.gangAfterData.chairId){
  3935. isMoHu = true;
  3936. winner.lead = -1;
  3937. }
  3938. else{
  3939. isMoHu = false;
  3940. winner.lead = this.gangAfterData.chairId;
  3941. }
  3942. }
  3943. else if(yjgs == 0){
  3944. isMoHu = false;
  3945. winner.lead = -1;
  3946. }
  3947. }
  3948. // console.warn("计算是否自摸222 this.gangAfterData.chairId "+this.gangAfterData.chairId+" yjgs "+yjgs+" lead "+winner.lead);
  3949. data.lead = String(winner.lead)
  3950. let znzId = -1;//抓鸟者id
  3951. if(yjgs == 1) znzId = winner.chs[0];
  3952. // else if(yjgs > 1) znzId = this.currentId;
  3953. //1022修复杠后两张牌一炮多响,2张鸟牌为5,9(开杠者中两鸟)情况下中鸟分计算错误的bug把上面那句else换成下面else
  3954. else if(yjgs > 1){
  3955. if(this.gangAfterData.chairId != -1){
  3956. znzId = this.gangAfterData.chairId;
  3957. }
  3958. else{
  3959. znzId = this.currentId;
  3960. }
  3961. }
  3962. let everyZNGS = this.logic.getBJGWJZBGS(znzId,data.jiangmaList,data.startNum1,data.startNum2,winner.lead,winner.chs);
  3963. let znfb = [0,1,2];//分别表示中0个1个2个鸟在中鸟相加方式时中鸟额外输赢的分数倍数
  3964. if(this.ZNJSType == 2) znfb = [0,1,3];//分别表示中0个1个2个鸟在中鸟相乘方式时中鸟额外输赢的分数倍数
  3965. // console.error("这局是否自摸??? "+isMoHu+" lead "+winner.lead);
  3966. // 计算牌型
  3967. for (let i = 0; i < wins.length; ++i) {
  3968. wins[i].huType = "";
  3969. if (winner.chs.indexOf(i) == -1) continue;
  3970. let typeList = [];
  3971. if(everyIsHLZ[i]){
  3972. for (let x = 0; x < everyDaHuType[i][0].length; ++x) {
  3973. typeList[x] = 0;
  3974. if(everyDaHuType[i][0][x] == 1) typeList[x] ++;
  3975. }
  3976. for (let x = 0; x < everyDaHuType[i][1].length; ++x) {
  3977. if(everyDaHuType[i][1][x] == 1) typeList[x] ++;
  3978. }
  3979. }
  3980. else{
  3981. // console.warn("计算牌型111 i "+i+" everyDAHType[i] "+this.logic.everyDAHType[i]);
  3982. for (let x = 0; x < this.logic.everyDAHType[i].length; ++x) {
  3983. typeList[x] = 0;
  3984. if(this.logic.everyDAHType[i][x] == 1) typeList[x] ++;
  3985. }
  3986. }
  3987. // console.warn("计算牌型222 i "+i+" typeList "+typeList);
  3988. for (let x = 0; x < typeList.length; ++x) {
  3989. let gs = typeList[x];
  3990. if(gs == 1){
  3991. if(x == 9){
  3992. //前端展示大胡牌型的时候用到了大胡牌型的名字,如果“杠开”改为“杠上开花”也要修改前端的大胡展示判断
  3993. if(isMoHu) wins[i].huType += "杠开" + ",";
  3994. else wins[i].huType += "杠炮" + ",";
  3995. }
  3996. else{
  3997. wins[i].huType += this.logic.dahuTypeTL[x][0] + ",";
  3998. }
  3999. }
  4000. else if(gs > 1){
  4001. if(x == 9){
  4002. if(isMoHu) wins[i].huType += ("杠开" + ",");
  4003. else wins[i].huType += ("杠炮" + ",");
  4004. }
  4005. else{
  4006. wins[i].huType += ("" + gs+this.logic.dahuTypeTL[x][0] + ",");
  4007. }
  4008. }
  4009. }
  4010. }
  4011. /////封顶类型1:不封顶;2:封顶56分;3:封顶112分;
  4012. let max = 1000000;
  4013. if(this.fengDingType == 1) max = 1000000;
  4014. else if(this.fengDingType == 2) max = 56;
  4015. else if(this.fengDingType == 3) max = 112;
  4016. // 计算输赢
  4017. for (let i = 0; i < wins.length; ++i) {
  4018. // 胡牌者
  4019. if (winner.chs.indexOf(i) != -1) {
  4020. // console.warn("结算承包数据",this.logic.chengBaoTL,isMoHu,cbqk);
  4021. if(this.logic.isLaGang){
  4022. //抢杠胡:只输自己一家
  4023. let lead = winner.lead;
  4024. let sy = this.logic.getDaHuFen(i) * this.cell;
  4025. wins.forEach((w, c) => {
  4026. if (c == lead) {
  4027. wins[lead].cardfen -= sy;
  4028. wins[i].cardfen += sy;
  4029. if(sy > max) sy = max;
  4030. wins[lead].win -= sy;
  4031. wins[i].win += sy;
  4032. }
  4033. });
  4034. ////下面这段是计算奖码的分数
  4035. wins.forEach((w, c) => {
  4036. if (c == lead) {
  4037. if(c == lead){//////点炮玩家
  4038. let jiangmaFen = sy*(znfb[everyZNGS[i]+everyZNGS[lead]]);
  4039. wins[lead].jiangma -= jiangmaFen;
  4040. wins[i].jiangma += jiangmaFen;
  4041. if(sy >= max) jiangmaFen = 0;
  4042. else if((jiangmaFen + sy) > max) jiangmaFen = max - sy
  4043. wins[lead].win -= jiangmaFen;
  4044. wins[i].win += jiangmaFen;
  4045. }
  4046. }
  4047. });
  4048. }
  4049. else{
  4050. //不是抢杠胡
  4051. let sy = 0;
  4052. if(everyIsHLZ[i]){
  4053. let sy1 = this.logic.getDaHuFen2(i,everyDaHuType[i][0]) * this.cell;
  4054. let sy2 = this.logic.getDaHuFen2(i,everyDaHuType[i][1]) * this.cell;
  4055. sy = sy1 + sy2
  4056. // console.warn("不是抢杠胡算分 可胡两张牌 i "+i+" sy1 "+sy1+" sy2 "+sy2);
  4057. }
  4058. else{
  4059. sy = this.logic.getDaHuFen(i) * this.cell;
  4060. // console.warn("不是抢杠胡算分 可胡1张牌 i "+i+" sy "+sy+" everyDAHType[i] "+this.logic.everyDAHType[i]);
  4061. }
  4062. // console.warn("不是抢杠胡算分 i "+i+" 是否胡两张 "+everyIsHLZ[i]+" sy "+sy+" 自摸 "+isMoHu);
  4063. if (isMoHu) {
  4064. //自摸每家输2分
  4065. wins.forEach((w, c) => {
  4066. if (c != i) {
  4067. w.cardfen -= sy;
  4068. wins[i].cardfen += sy;
  4069. if(sy > max) sy = max;
  4070. w.win -= sy;
  4071. wins[i].win += sy;
  4072. }
  4073. });
  4074. ////下面这段是计算抓鸟的分数
  4075. wins.forEach((w, c) => {
  4076. if (c != i) {
  4077. // console.warn("不是抢杠胡算分 i "+i+" c "+c + " ")
  4078. let jiangmaFen = sy*znfb[everyZNGS[i]+everyZNGS[c]];
  4079. w.jiangma -= jiangmaFen;
  4080. wins[i].jiangma += jiangmaFen;
  4081. if(sy >= max) jiangmaFen = 0;
  4082. else if((jiangmaFen + sy) > max) jiangmaFen = max - sy
  4083. w.win -= jiangmaFen;
  4084. wins[i].win += jiangmaFen;
  4085. }
  4086. });
  4087. }
  4088. else {
  4089. //点炮者:给赢家输2分,其他人不输分
  4090. let lead = winner.lead;
  4091. if(this.gangAfterData.chairId != -1) lead = this.gangAfterData.chairId;
  4092. // 点炮出钱
  4093. wins.forEach((w, c) => {
  4094. if (c != i) {
  4095. if(c == lead){//////点炮玩家
  4096. w.cardfen -= sy;
  4097. wins[i].cardfen += sy;
  4098. if(sy > max) sy = max;
  4099. w.win -= sy;
  4100. wins[i].win += sy;
  4101. }
  4102. }
  4103. });
  4104. ////下面这段是计算奖码的分数
  4105. wins.forEach((w, c) => {
  4106. if (c != i) {
  4107. if(c == lead){//////点炮玩家
  4108. let jiangmaFen = sy*(znfb[everyZNGS[i]+everyZNGS[lead]]);
  4109. wins[lead].jiangma -= jiangmaFen;
  4110. wins[i].jiangma += jiangmaFen;
  4111. if(sy >= max) jiangmaFen = 0;
  4112. else if((jiangmaFen + sy) > max) jiangmaFen = max - sy
  4113. wins[lead].win -= jiangmaFen;
  4114. wins[i].win += jiangmaFen;
  4115. }
  4116. }
  4117. });
  4118. }
  4119. }
  4120. wins[i].lucky = 1;
  4121. }
  4122. // let str2 = "cstable 222结算函数---id:"+this.id +"结算模式"+mode
  4123. // logger.info(str2);////cssj
  4124. // if(!(mode != MODE.NORMAL && this.isHZHG)) {
  4125. // // 杠牌 流局了而且勾选荒庄荒杠 的话则不计算杠分
  4126. // let gangMul = 0;
  4127. // for (let huCard of this.huCards[i]) {
  4128. // if (huCard.style == Logic.STYLE.ZMGANG) {
  4129. // gangMul += 1;
  4130. // wins[i].penggang += 1;
  4131. // } else if (huCard.style == Logic.STYLE.ANGANG) {
  4132. // gangMul += 2;
  4133. // wins[i].dark += 1;
  4134. // } else if (huCard.style == Logic.STYLE.GANG){
  4135. // //明杠谁点的杠谁付3分
  4136. // wins[i].trans += 1;
  4137. // wins[huCard.origin].win -= 3 * this.cell;
  4138. // wins[i].win += 3 * this.cell;
  4139. // wins[huCard.origin].gangfen -= 3 * this.cell;
  4140. // wins[i].gangfen += 3 * this.cell;
  4141. // }
  4142. // }
  4143. // if (gangMul > 0) {
  4144. // wins.forEach((w, c) => {
  4145. // if (c != i) {
  4146. // w.win -= gangMul * this.cell;
  4147. // wins[i].win += gangMul * this.cell;
  4148. // w.gangfen -= gangMul * this.cell;
  4149. // wins[i].gangfen += gangMul * this.cell;
  4150. // }
  4151. // });/////TL++杠牌有赢
  4152. // }
  4153. // }
  4154. wins.forEach((w, c) => {
  4155. // console.warn("?????/ "+JSON.stringify(w));
  4156. if (c != i) {
  4157. let qshFen = this.logic.getQSHFen(i)
  4158. // console.warn("?????----- "+qshFen);
  4159. // w.win -= qshFen * this.cell;
  4160. // wins[i].win += qshFen * this.cell;
  4161. w.gangfen -= qshFen * this.cell;
  4162. wins[i].gangfen += qshFen * this.cell;
  4163. }
  4164. });/////TL++杠牌有赢
  4165. // 手牌
  4166. let cards = { card: 0, groups: [], hands: [] };
  4167. if (wins[i].lucky) {
  4168. cards.card = this.huRes[i].card;
  4169. }
  4170. for (let huCard of this.huCards[i]) {
  4171. cards.groups.push({ style: huCard.style, card: huCard.cards[0] });
  4172. }
  4173. let handCard = this.handCards[i] || [];
  4174. let count = this.mcount - this.huCards[i].length * 3;
  4175. cards.hands = handCard.slice(0, count);
  4176. if(everyIsHLZ[i]){
  4177. cards.card = this.gangAfterData.cards.card1;
  4178. cards.card2 = this.gangAfterData.cards.card2;
  4179. }
  4180. wins[i].cards = cards;
  4181. }
  4182. // let str3 = "cstable 333结算函数---id:"+this.id +",结算模式"+mode
  4183. // logger.info(str3);////cssj
  4184. //////TL++
  4185. let shiJiKouFen = [];
  4186. if(this.playerAllCount == 2) shiJiKouFen = [wins[0].win,wins[1].win];
  4187. else if(this.playerAllCount == 3) shiJiKouFen = [wins[0].win,wins[1].win,wins[2].win];
  4188. else if(this.playerAllCount == 4) shiJiKouFen = [wins[0].win,wins[1].win,wins[2].win,wins[3].win];
  4189. if(this.gameKindTL == 2){
  4190. /////冲刺最多输50
  4191. for (let i = 0; i < this.ccount; ++i) {
  4192. if(i == winner.chs[0]) continue;
  4193. let user = this.users[i];
  4194. if (user){
  4195. let oldScore = this.score.getScore(user.id);
  4196. let newScore = oldScore + shiJiKouFen[i];
  4197. if(newScore <= 0) wins[i].isPoChan = 1;/////玩家破产了
  4198. if(newScore < 0){/////输家破产了
  4199. let ableShu = 0 - newScore;
  4200. shiJiKouFen[winner.chs[0]] += newScore;/////赢家没赢够
  4201. shiJiKouFen[i] = shiJiKouFen[i] - newScore;
  4202. }
  4203. }
  4204. }
  4205. }
  4206. // console.warn("实际扣分XXX "+JSON.stringify(shiJiKouFen));
  4207. for (let i = 0; i < this.ccount; ++i) {
  4208. wins[i].shiJiKouFen = shiJiKouFen[i];
  4209. }
  4210. //console.warn("实际扣分XXX",shiJiKouFen,wins[0].win,wins[1].win,wins[2].win,wins[3].win)
  4211. // 胜负情况
  4212. data.wins = wins;
  4213. let bjsy = [];//本局每个人的输赢
  4214. for (let i = 0; i < this.ccount; ++i) {
  4215. bjsy[i] = wins[i].win;
  4216. }
  4217. this.sszjDataList[this.sszjDataList.length] = bjsy;
  4218. this.over += 1;// 局数+1
  4219. //ts++
  4220. let sszjScore = [];//ts++实时本局成绩
  4221. let sszjAllScore = [];//ts++实时总成绩
  4222. // 记录分数
  4223. for (let i = 0; i < this.ccount; ++i) {
  4224. let user = this.users[i];
  4225. if (user)
  4226. {
  4227. sszjScore[i] = shiJiKouFen[i];
  4228. this.score.writeScore(user.id,shiJiKouFen[i], 1);//设置分数
  4229. sszjAllScore[i] = this.score.getScore(user.id);
  4230. if(this.gameKindTL == 2) sszjAllScore[i] -=50;
  4231. if(this.over == 1)
  4232. {
  4233. this.score.writeCost(user.id,this.cost, 0); //ts++设置消耗
  4234. }
  4235. }
  4236. }
  4237. let endmode=ENDMODE.PLAYING;
  4238. if(this.isGameOver())
  4239. {
  4240. this.isGameOk=true;
  4241. endmode=ENDMODE.NORMALEND;//局数完成--正常结束
  4242. }
  4243. data.isover = this.isGameOk;
  4244. data.nowTime = Date.now();
  4245. this.setPaijuHuiFangData(M.CONCLUDE,data);/////TL++ 牌局回放 push结算数据
  4246. /////TL++,用于记录玩家牌局回放的json文件名
  4247. this.pjhffileName[this.pjhffileName.length] = this.PJHF.getjsonFileName(this.over,this.recordid,this.ctime);
  4248. // let str4 = "cstable 444结算函数---id:%s"+this.id +"结算模式"+mode
  4249. // logger.info(str4);////cssj
  4250. //ts++胡的人
  4251. let hu=-1;
  4252. if (winner.chs.length >0 && winner.chs[0] >= 0 && winner.chs[0] <= 3)
  4253. {
  4254. hu=winner.chs[0];
  4255. }
  4256. //ts++实时战绩
  4257. //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});
  4258. this.sszjs.push({_id: String(this.over),sszjScore:sszjScore,sszjAllScore:sszjAllScore,banker:this.chBanker,hu:hu,pao:winner.lead});
  4259. /////固定庄家,不固定的话解除下面这一段的注释
  4260. // 切换庄家
  4261. if(yjgs == 0){
  4262. //没有赢家,流局了,最后一个摸牌的人坐庄
  4263. this.chBanker = this.logic.lastMoPaiChairID;
  4264. }
  4265. else if(yjgs == 1){
  4266. //只有一个人赢了,谁赢谁做庄
  4267. this.chBanker = winner.chs[0];
  4268. }
  4269. else if(yjgs > 1) {
  4270. //一炮多响,放炮的人坐庄
  4271. this.chBanker = winner.lead
  4272. }
  4273. /////TL++,10月9号,为了解决冲刺时前端的玩家分数偶尔会显示负数的bug
  4274. data.playNowScore = [];
  4275. for (let i = 0; i < this.ccount; ++i) {
  4276. let user = this.users[i];
  4277. if (user)
  4278. {
  4279. data.playNowScore[i] = this.score.getScore(user.id);
  4280. }
  4281. }
  4282. // 重置本局
  4283. this.resetRound();
  4284. // 结算通知
  4285. yield this.pushMsgAsync(-1, 'csjiang_event', { type: M.CONCLUDE, data: data });
  4286. this.PJHF.writePJHFJson({"pjhfDataList":this.PaijuHuiFang},this.over,this.id)
  4287. this.logic.isZHYZ = false; /////TL++,是否最后一张
  4288. // yield this.pushMsgAsync(-1, 'csjiang_event', { type: 100, data: {"pjhfDataList":this.PaijuHuiFang}});//////最终发送给前端的牌局回放
  4289. // let str6 = "cstable end 结算函数-id:"+this.id +"结算模式"+mode
  4290. // logger.info(str6);////cssj
  4291. yield this.endResultAsync(endmode);
  4292. });
  4293. // 发送聊天
  4294. proto.sendMsgAsync = cor(function* (chairId, msg) {
  4295. // console.error("sscc发送聊天+++++++++++++++++++++++++++++++++",chairId,msg)
  4296. yield this.pushMsgAsync(-1, 'csjiang_event', { type: M.CHAT, data: { chairId: String(chairId), msg: msg } });
  4297. return { code: C.OK };
  4298. });
  4299. // 收费聊天 礼物收费
  4300. proto.vsendMsgAsync = cor(function* (schairId, dchairId, msg) {
  4301. if (schairId == dchairId || !this.users[dchairId]) {
  4302. return { code: C.FAILD, msg: C.GAME_PARAM_ERROR };
  4303. }
  4304. let user = this.users[schairId];
  4305. if (!user) {
  4306. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  4307. }
  4308. let lwcost = this.LWKF[msg.type];//////TL++礼物扣费
  4309. if(lwcost > 0){
  4310. var player = yield this.app.models.Player.findByIdAsync(user.id, 'diamond');
  4311. if(player)
  4312. {
  4313. if (((player.diamond) || 0) < lwcost) {
  4314. return { code: C.FAILD, msg: C.GAME_DIAMOND_LOW };
  4315. }
  4316. let dSource=player.diamond;
  4317. let dNow=player.diamond-lwcost;
  4318. player.diamond -= lwcost;
  4319. yield player.saveAsync();
  4320. // 钻石记录
  4321. var diamondrecord = new this.app.models.DiamondRecord({
  4322. _id: uuid.v1(),
  4323. playerId: user.id,
  4324. dType: 5,//礼物
  4325. dSource: dSource,
  4326. dSwap: -lwcost,
  4327. dNow: dNow,
  4328. tableId: this.recordid
  4329. });
  4330. yield diamondrecord.saveAsync();
  4331. //ts++设置消耗 20230804取消了礼物扣钻的奖励
  4332. // this.score.writeCost(user.id,0, lwcost);
  4333. }
  4334. }
  4335. yield this.pushMsgAsync(-1, 'csjiang_event', { type: M.FEE_CHAT, data: { cost: String(lwcost),schairId: String(schairId), dchairId: String(dchairId), msg: msg } });
  4336. return { code: C.OK };
  4337. });
  4338. //ts++写分 endtype = { 正常: 0,局数完成: 1, 房主解散: 2, 申请解散: 3 ,超时解散: 4 };
  4339. proto.writeResultAsync = cor(function* (endmode) {
  4340. logger.warn("牌局写入-------------- " + this.id );
  4341. // console.warn("ts++---------牌局写入writeResultAsync",this.id);
  4342. let gameCost=0;//游戏消耗
  4343. let giftCost = 0;////道具消耗
  4344. this.etime = Date.now();
  4345. let users = [];
  4346. let localUsers = [];
  4347. var scorers = this.score.getUsers();
  4348. if (scorers.length > 0)
  4349. {
  4350. var scorersSort = _.sortBy(scorers, (i) => i.chairId);
  4351. for (let scorer of scorersSort) {
  4352. gameCost+=this.cost;
  4353. giftCost+=scorer.giftCost;
  4354. let userscore=scorer.score;
  4355. if(this.gameKindTL == 2) userscore -= 50;
  4356. 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});
  4357. //, gameCost: scorer.gameCost,giftCost: scorer.giftCost,diamond: scorer.diamond
  4358. localUsers.push({_id: scorer.playerId,userId: scorer.userId, name: scorer.name, gameCost: scorer.gameCost,giftCost: scorer.giftCost,});
  4359. }
  4360. }
  4361. // if(this.isGameOk)////以前是解散的不算返利
  4362. if(this.over > 0)////改成只要玩家扣钻了就有返利
  4363. {
  4364. // this.agentRebate=gameCost;//parseInt(gameCost*0.5);
  4365. this.agentRebate=gameCost+giftCost;////礼物也算消耗进行返利
  4366. // console.warn("代理返利+++++",this.agentRebate);
  4367. }
  4368. else
  4369. {
  4370. this.agentRebate=0;
  4371. }
  4372. //console.warn("实时战绩",this.sszjs);//ts++
  4373. this.PJHF.getTSjsonFileName(100,this.recordid,this.ctime);/////TL++,用于记录玩家牌局回放的json文件名
  4374. // console.error("000HHHHHHHHHHHHHHHHHHHHHH",this.pjhffileName.length,this.pjhffileName);
  4375. let datats = {
  4376. _id: this.recordid,//记录
  4377. gameId: this.gameId,
  4378. tableNo: this.id,
  4379. ownerId: this.ownerId,
  4380. agentId: this.agentId,
  4381. type: this.type,
  4382. kind: this.gameKindTL,//玩法 2冲刺
  4383. other: this.other,//////TL++2人3人的游戏规则
  4384. playerCount: this.playerAllCount,//游戏人数
  4385. round: this.round,//
  4386. over: this.over,//游戏局数
  4387. ctime: this.ctime,//创建时间
  4388. stime: this.stime,//开始时间
  4389. time: this.etime,//结束时间
  4390. endMode: endmode,//结束类型
  4391. gameCost: gameCost,//游戏消耗
  4392. giftCost: giftCost,//礼物消耗
  4393. agentRebate: parseInt(this.agentRebate),//代理返利
  4394. sszjFile: this.logic.deepCloneTL(this.pjhffileName),
  4395. sszj: this.logic.deepCloneTL(this.sszjs),
  4396. users: users
  4397. }
  4398. this.PJHF.writeTSJson(datats,100,this.id);////在开始第一局的时候将桌子信息写入本地的json文件
  4399. var fhmjtable = new this.app.models.FHMJTables({
  4400. _id: this.recordid,//记录
  4401. gameId: this.gameId,
  4402. tableNo: this.id,
  4403. ownerId: this.ownerId,
  4404. agentId: this.agentId,
  4405. type: this.type,
  4406. kind: this.gameKindTL,//玩法 2冲刺
  4407. other: this.other,//////TL++2人3人的游戏规则
  4408. playerCount: this.playerAllCount,//游戏人数
  4409. round: this.round,//
  4410. over: this.over,//游戏局数
  4411. ctime: this.ctime,//创建时间
  4412. stime: this.stime,//开始时间
  4413. time: this.etime,//结束时间
  4414. endMode: endmode,//结束类型
  4415. gameCost: gameCost,//游戏消耗
  4416. giftCost: giftCost,//礼物消耗
  4417. agentRebate: parseInt(this.agentRebate),//代理返利
  4418. sszjFile: this.pjhffileName,
  4419. sszj: this.sszjs,
  4420. users: users
  4421. });
  4422. // console.warn("fhmjtable new",fhmjtable);
  4423. yield fhmjtable.saveAsync();
  4424. //下面是记录返利相关的
  4425. if(this.agentId && this.agentRebate>0){
  4426. yield this.lsetReabte.writeReabteInfo(this.agentId,this.etime,this.agentRebate,gameCost,giftCost,this.recordid,localUsers,this.gameId);
  4427. // yield this.lsetReabte.writePlayerCountInfo(this.agentId,this.etime,users,this.cost,this.isGameOk,this.gameId);
  4428. }
  4429. //下面是记录邀请新人按比例送钻这个活动的数据
  4430. if(!this.lconfigCommon) {
  4431. // console.warn("邀请新人送钻石活动 this.lconfigCommon 不存在 "+this.etime);
  4432. this.lconfigCommon = new configCommon(this.app);
  4433. }
  4434. yield this.lconfigCommon.yxActivityAsync(scorers,this.etime);
  4435. // logger.info("战绩写入fhmjtable.saveAsync()--------------",this.id);
  4436. });
  4437. // 结束信息 var endtype = { 局数完成: 1, 主动解散: 2, 断线解散: 3 ,超时解散: 4 };
  4438. proto.endResultAsync = cor(function* (endmode) {
  4439. // console.warn("ts++---------记录信息",this.id);
  4440. let str6 = "cstable 结束信息--id: "+this.id +" ,结算模式 "+endmode;
  4441. logger.warn(str6);////cssj
  4442. if(endmode>ENDMODE.PLAYING)//ts++关闭
  4443. {
  4444. let nowTime = Date.now();
  4445. if(this.state<STATE.END)//ts++防止重复写入
  4446. {
  4447. this.state = STATE.END;
  4448. if (this.endTimer) {
  4449. clearTimeout(this.endTimer);
  4450. this.endTimer = null;
  4451. }
  4452. if (this.overTimer) {
  4453. clearTimeout(this.overTimer);
  4454. this.overTimer = null;
  4455. }
  4456. // console.warn("ts++---------局数完成",this.over);
  4457. if(this.over>0)
  4458. {
  4459. var scorers = this.score.getUsers();
  4460. if (scorers.length > 0) {
  4461. let data = {
  4462. _id: this.recordid,
  4463. gameId: this.gameId,
  4464. tableNo: this.id,
  4465. ownerId: this.ownerId,
  4466. type:String(this.type),
  4467. kind: String(this.gameKindTL),
  4468. over: String(this.over),
  4469. round: String(this.round),
  4470. time: String(nowTime),
  4471. ctime: String(this.ctime),
  4472. keep: String(nowTime - this.stime),
  4473. other: this.other,
  4474. playerCount:this.playerAllCount,
  4475. agentId: this.agentId
  4476. };
  4477. let collects = [];
  4478. for (let scorer of scorers) {
  4479. let userscore=scorer.score;
  4480. if(this.gameKindTL == 2) userscore -= 50;//TL++,因为总的结算界面的每个玩家的分数范围为-200 ~ 600
  4481. collects.push({ chairId:scorer.chairId,name: scorer.name, sex: scorer.sex, headurl: scorer.headurl, score: userscore });
  4482. }
  4483. data.users = _.sortBy(collects, (i) => -i.score);
  4484. //data.sszjFile=this.pjhffileName;
  4485. data.sszj=this.sszjs;
  4486. yield this.pushMsgAsync(-1, 'csjiang_event', { type: M.TOTAL_CONCLUDE, data: data });////汇总结算
  4487. }
  4488. //console.warn("ts++---------牌局写入");
  4489. yield this.writeResultAsync(endmode);
  4490. }
  4491. //console.warn("ts---------牌局结束");
  4492. for (let user of this.users) {
  4493. if (user) {
  4494. if (user.isOffline())
  4495. {
  4496. user.state = User.STATE.FREE;
  4497. user.state2 = User.STATE.FREE;
  4498. this.leaveUsers.push(user.id);
  4499. ///yield this.game.leaveTableAsync(user.id);
  4500. }
  4501. else
  4502. {
  4503. user.state = User.STATE.FREE;
  4504. user.state2 = User.STATE.FREE;
  4505. }
  4506. }
  4507. }
  4508. }
  4509. if(endmode==ENDMODE.SYSTEMEND)
  4510. {
  4511. yield this.pushMsgAsync(-1, 'csjiang_event', { type: M.TABLE_JIESAN });
  4512. }
  4513. if(this.leaveUsers.length>0)
  4514. {
  4515. this.app.timer.setTimeout(() => this.leaveUserTimeAsync(), 100);
  4516. }
  4517. // var gametable = yield this.app.models.GameTable.findByIdAsync(this.recordid, '_id tableNo agentId endMode');
  4518. // if(gametable){
  4519. // gametable.endMode = 1;
  4520. // yield gametable.saveAsync();
  4521. // }
  4522. this.game.deleteTable(this.id);//ts++删除房间
  4523. // let str5 = "cstable 结束信息22 关闭-id:"+this.id +"结算模式"+endmode;
  4524. // logger.info(str5);////cssj
  4525. }
  4526. else//普通结束
  4527. {
  4528. // let str5 = "cstable 结束信息 普通结束---id:"+this.id +"结算模式"+endmode
  4529. // logger.info(str5);////cssj
  4530. this.state = STATE.FREE2;
  4531. for (let user of this.users) {
  4532. if (user) user.state2 = User.STATE.FREE;
  4533. }
  4534. }
  4535. let str7 = "cstable end 结束信息---id:%s "+this.id +" 结算模式 "+endmode;
  4536. logger.warn(str7);////cssj
  4537. });
  4538. //ts++离开用户退出定时器
  4539. proto.leaveUserTimeAsync = cor(function* () {
  4540. // console.warn("离开用户退出定时器,离开用户数==%d",this.leaveUsers.length);////cssj
  4541. if(this.leaveUsers.length>0)
  4542. {
  4543. let userid = this.leaveUsers[0];
  4544. this.leaveUsers.splice(0, 1);
  4545. let str7 = "cstable end 离开用户退出定时器---id:%s "+this.id +" userid "+userid;
  4546. logger.warn(str7);////cssj
  4547. yield this.game.leaveTableAsync(userid);
  4548. }
  4549. if(this.leaveUsers.length>0)
  4550. {
  4551. this.app.timer.setTimeout(() => this.leaveUserTimeAsync(), 100);
  4552. }
  4553. });
  4554. // TL++,得到玩家位置
  4555. proto.sendLocationAsync = cor(function* (user,msg) {
  4556. /////设置玩家的经纬度
  4557. user.longitude = msg.longitude; // 经度,浮点数,范围为180 ~ -180。
  4558. user.latitude = msg.latitude; // 纬度,浮点数,范围为90 ~ -90
  4559. let tempData = {
  4560. userId: user.userId,
  4561. account: user.account,
  4562. longitude: msg.longitude,
  4563. latitude: msg.latitude
  4564. }
  4565. //////向其他玩家广播该玩家位置
  4566. yield this.pushMsgAsync(-1, 'csjiang_event', { type: M.COAST_PLAYERLOCATION, data: tempData });
  4567. return { code: C.OK, data: tempData };
  4568. });
  4569. // 玩家信息
  4570. proto.roleInfoAsync = cor(function* (chairId) {
  4571. // console.log("玩家信息玩家信息玩家信息");
  4572. var user = this.users[chairId];
  4573. if (!user) {
  4574. return { code: C.FAILD, msg: C.GAME_PARAM_ERROR };
  4575. }
  4576. var data = { userId: '0', ttCount: '0', winCount: '0', noCount: '0', runCount: '0' };
  4577. data.userId =user.userId;
  4578. return { code: C.OK, data: data };
  4579. });
  4580. //ts++请求结束定时器
  4581. proto.overTimeAsync = cor(function* (endmode) {
  4582. yield this.pushMsgAsync(-1, 'csjiang_event', { type: M.TABLE_JIESAN });
  4583. let str6 = "cstable 请求结束定时器---id: "+this.id +" ,endmode: "+endmode
  4584. logger.warn(str6);////cssj
  4585. yield this.endResultAsync(endmode);//ts++ 房主解散 写分
  4586. });
  4587. // 请求结束
  4588. proto.overTableAsync = cor(function* (user) {
  4589. // console.warn("ts+++++请求结束",user.chairId);
  4590. let str3 = "cstable 请求结束.......id: "+ this.id + " user.chairId: " + user.chairId + " user.name: " + user.name ;
  4591. logger.warn(str3);////cssj
  4592. if(this.state == STATE.END)
  4593. {
  4594. this.leaveAsync(user);
  4595. return { code: C.OK, data:{jieSanType: 2}};//离开房间
  4596. }
  4597. if(this.reqJieSan.indexOf(2) != -1) return;/////有发起人的时候
  4598. // console.warn("2222请求结束请求结束请求结束",this.reqJieSan);
  4599. //解散桌子数据,前面为chirid后面为情况-1:未操作 0:拒绝 1:同意 2为解散发起
  4600. //jieSanType =1:游戏开始前房主申请解散 =2:游戏开始前非房主玩家退出房间 =3:游戏过程中玩家申请解散 =4游戏过程中是房主但没参与游戏退出房间 =5其他
  4601. if(this.gameNeverStart) {//游戏是否从未开始过,用于解散房间判断
  4602. if(user.userId == this.ownerUid){
  4603. yield this.pushMsgAsync(-1, 'csjiang_event', { type: M.TABLE_JIESAN });
  4604. // let str5 = "cstable 房主解散-id:"+this.id+ ",uid"+user.userId;
  4605. // logger.info(str5);////cssj
  4606. yield this.endResultAsync(ENDMODE.OWNEREND);//ts++ 房主解散 写分
  4607. return { code: C.OK, data:{jieSanType: 1}};
  4608. }
  4609. else{
  4610. this.leaveAsync(user);
  4611. return { code: C.OK, data:{jieSanType: 2}};//离开房间
  4612. }
  4613. }
  4614. else
  4615. {
  4616. let chairId=user.chairId;
  4617. if(chairId >= 0 && chairId < 4 )
  4618. {
  4619. if(this.overFlag==0)//发起
  4620. {
  4621. this.overFlag = 1;
  4622. this.reqJieSan[0]=-1;
  4623. this.reqJieSan[1]=-1;
  4624. this.reqJieSan[2]=-1;
  4625. this.reqJieSan[3]=-1;
  4626. this.reqJieSan[chairId]=2;
  4627. let jsdata = [];//ts++实时本局成绩
  4628. jsdata[0] = this.reqJieSan[0];
  4629. jsdata[1] = this.reqJieSan[1];
  4630. jsdata[2] = this.reqJieSan[2];
  4631. jsdata[3] = this.reqJieSan[3];
  4632. this.JSFJTime = 60;//////解散倒计时60秒
  4633. this.SQJSTime = Date.now() + this.JSFJTime*1000;
  4634. if (!this.overTimer) this.overTimer = this.app.timer.setTimeout(() => this.overTimeAsync(ENDMODE.REGEND),this.JSFJTime*1000);//解散倒计时60秒
  4635. yield this.pushMsgAsync(-1, 'csjiang_event', { type: M.REQUEST_END, data: { chairId: String(chairId),time: this.JSFJTime,jsdata:jsdata}});
  4636. return { code: C.OK, data:{jieSanType: 3}};
  4637. }
  4638. else//同意
  4639. {
  4640. return this.agreeOverAsync(chairId);
  4641. }
  4642. }
  4643. else
  4644. {
  4645. return { code: C.FAILD, msg: C.TABLE_ALREADY_SQJS };
  4646. }
  4647. }
  4648. return { code: C.OK, data:{jieSanType: 5}};
  4649. });
  4650. // 拒绝结束
  4651. proto.refuseOverAsync = cor(function* (user) {
  4652. let str3 = "cstable 拒绝结束.......id: "+ this.id + " user.chairId: " + user.chairId + " user.name: " + user.name ;
  4653. logger.warn(str3);////cssj
  4654. if(this.state == STATE.END)
  4655. {
  4656. this.leaveAsync(user);
  4657. return { code: C.OK, data:{jieSanType: 2}};//离开房间
  4658. }
  4659. if(this.overFlag == 0) //ts++已经拒绝了
  4660. {
  4661. return { code: C.OK };
  4662. }
  4663. this.overFlag = 0;
  4664. let chairId=user.chairId;
  4665. // console.error("ts++----------拒绝结束",chairId);
  4666. this.reqJieSan[chairId]=0;//解散桌子数据,前面为chirid后面为情况-1:未操作 0:拒绝 1:同意 2为解散发起
  4667. let jsdata = [];//ts++实时本局成绩
  4668. jsdata[0] = this.reqJieSan[0];
  4669. jsdata[1] = this.reqJieSan[1];
  4670. jsdata[2] = this.reqJieSan[2];
  4671. jsdata[3] = this.reqJieSan[3];
  4672. if (this.overTimer) {
  4673. clearTimeout(this.overTimer);
  4674. this.overTimer = null;
  4675. }
  4676. yield this.pushMsgAsync(-1, 'csjiang_event', { type: M.REFUSE_END, data: { chairId: String(chairId),time: 0,jsdata:jsdata} });
  4677. //this.reqJieSan = [[-1,-1],[-1,-1],[-1,-1],[-1,-1]];/////解散桌子数据,前面为chirid后面为情况-1:未操作 0:拒绝 1:同意 2为解散发起
  4678. this.reqJieSan[0]=-1;
  4679. this.reqJieSan[1]=-1;
  4680. this.reqJieSan[2]=-1;
  4681. this.reqJieSan[3]=-1;
  4682. return { code: C.OK };
  4683. });
  4684. // 同意结束
  4685. proto.agreeOverAsync = cor(function* (user) {
  4686. let str3 = "cstable 同意结束.......id: "+ this.id + " user.chairId: " + user.chairId + " user.name: " + user.name ;
  4687. logger.warn(str3);////cssj
  4688. if(this.state == STATE.END)
  4689. {
  4690. this.leaveAsync(user);
  4691. return { code: C.OK, data:{jieSanType: 2}};//离开房间
  4692. }
  4693. if(this.overFlag == 0) //ts++已经拒绝了
  4694. {
  4695. return { code: C.OK };
  4696. }
  4697. let chairId=user.chairId;
  4698. // console.error("ts++----------同意结束",chairId);
  4699. this.reqJieSan[chairId] = 1;/////解散桌子数据,前面为chirid后面为情况-1:未操作 0:拒绝 1:同意 2为解散发起
  4700. let jsdata = [];//ts++实时本局成绩
  4701. jsdata[0] = this.reqJieSan[0];
  4702. jsdata[1] = this.reqJieSan[1];
  4703. jsdata[2] = this.reqJieSan[2];
  4704. jsdata[3] = this.reqJieSan[3];
  4705. this.JSFJTime = Math.floor((this.SQJSTime - Date.now())/1000);
  4706. if(this.JSFJTime >= 25)this.JSFJTime -= 20;//////解散房间倒计时60秒
  4707. else this.JSFJTime = 10;
  4708. this.SQJSTime = Date.now() + this.JSFJTime*1000;
  4709. yield this.pushMsgAsync(-1, 'csjiang_event', { type: M.AGREE_END, data: { chairId: String(chairId),time: this.JSFJTime,jsdata:jsdata} });
  4710. let jsFlag = 0;
  4711. for (let i = 0; i < 4; ++i)
  4712. {
  4713. if(this.reqJieSan[i] >=1 )
  4714. {
  4715. jsFlag+=1;
  4716. }
  4717. }
  4718. if(jsFlag>=this.ccount || this.JSFJTime<=0)
  4719. {
  4720. if(this.backStartTimer)
  4721. {
  4722. clearTimeout(this.backStartTimer);
  4723. this.backStartTimer = null;
  4724. }
  4725. yield this.pushMsgAsync(-1, 'csjiang_event', { type: M.TABLE_JIESAN });
  4726. // let str4 = "cstable 全部同意结束-id:%s"+this.id + ",uid"+user.userId+",state"+ this.state;
  4727. // logger.info(str4);////cssj
  4728. yield this.endResultAsync(ENDMODE.REGEND);//ts++ 结束
  4729. }
  4730. else
  4731. {
  4732. if (this.overTimer) {
  4733. clearTimeout(this.overTimer);
  4734. this.overTimer = null;
  4735. }
  4736. if (!this.overTimer) this.overTimer = this.app.timer.setTimeout(() => this.overTimeAsync(ENDMODE.REGEND),this.JSFJTime*1000);//解散倒计时60秒
  4737. }
  4738. // let str3 = "cstable end 同意结束-id:"+this.id + ",uid"+user.userId+",state"+ this.state;
  4739. // logger.info(str3);////cssj
  4740. return { code: C.OK, data: { chairId: String(chairId),time: this.JSFJTime, jieSanType: 1 }};
  4741. });
  4742. //////TL++,设置记录游戏过程中的记录数据
  4743. proto.setPaijuHuiFangData = function (_operateKind,_data){
  4744. let data = this.logic.deepCloneTL(_data);
  4745. data.operateKind = _operateKind;
  4746. this.PaijuHuiFang[this.PaijuHuiFang.length] = data;
  4747. };
  4748. // 得到玩家位置
  4749. proto.getLocationAsync = cor(function* () {
  4750. let location = [];
  4751. // 桌上玩家
  4752. for (let i = 0; i < this.users.length; ++i) {
  4753. let user = this.users[i];
  4754. if (user) {
  4755. location.push({
  4756. chairId: user.chairId,
  4757. longitude: user.longitude,
  4758. latitude: user.latitude,
  4759. headurl: user.headurl,
  4760. name: user.name
  4761. });
  4762. }
  4763. }
  4764. // console.warn("ts+++++玩家位置",location);
  4765. return { code: C.OK, data: location };
  4766. });