table.js 137 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193
  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').sxjiang || {};
  18. var M = require('../../share/message');
  19. var C = require('../../share/constant');
  20. var paiJuHuiFang = require('../../share/paiJuHuiFang');//////TL++ 牌局回放
  21. var logger = quick.logger.getLogger('fhmj', __filename);
  22. // 桌子状态
  23. var STATE = { FREE: 1, PLAYING: 2, FREE2: 3 , END: 4};//ts++REFREE 二次空闲 END结束
  24. // 结算模式
  25. var MODE = { NORMAL: 1, NOCARD: 2, OFFLINE: 3 };
  26. //ts++结束模式 空闲0,游戏中1, 正常结束3,房主解散3,断线解散4,断线解散5,系统解散6
  27. var ENDMODE = { FREE: 0,PLAYING: 1, OWNEREND: 2,NORMALEND: 3,REGEND: 4, OFFLINEEND: 5, SYSTEMEND: 6 };
  28. // 金币消耗
  29. const COSTS = conf.sit_costs || {};
  30. /////TL++,下面这几行为了记录用户行为
  31. // var log4js2 = require("log4js");////cssj
  32. // var log4js_config2 = require("./logConf.json");
  33. // log4js2.configure(log4js_config2);
  34. // var LogFile2 = log4js2.getLogger('log_file');////cssj
  35. // 构造方法
  36. var Table = function (cPlayerId,cUserId,cName,cHead,game, id, cell, round, type,gameKindTL,playerAllCount,upId,other,agentId) {
  37. let str3 = "table构造方法.......id: "+id + " type " + type;
  38. logger.warn(str3);////cssj
  39. this.app = game.app;
  40. this.game = game;
  41. this.id = id;
  42. this.recordid = uuid.v1()+'_'+id;//ts++唯一记录
  43. this.upId = upId;//ts++上局的ID
  44. this.type = type;
  45. this.agentId=agentId;
  46. var num_cost = 50;
  47. // if(gameKindTL == 2){
  48. // //num_cost = 50;//////冲刺扣50
  49. // num_cost =parseInt(COSTS[1]);
  50. // }
  51. // else
  52. // {
  53. num_cost =parseInt(COSTS[round]);
  54. // }
  55. this.other = other;//////TL++2人3人的游戏规则
  56. console.warn("222创建房间的other",other,this.other," gameKindTL ",gameKindTL," type " ,type);
  57. this.jiangmaType = -1;////奖码类型:-1:不奖码,1:159奖码,2:摸几奖几,3:一码全中
  58. this.jiangmaCount = -1;////奖码张数
  59. if(this.other & 1){
  60. this.jiangmaType = 1;
  61. if(this.other & 8) this.jiangmaCount = 2;
  62. else if(this.other & 16) this.jiangmaCount = 4;
  63. else if(this.other & 32) this.jiangmaCount = 6;
  64. }
  65. else if(this.other & 2){
  66. this.jiangmaType = 2;
  67. this.jiangmaCount = 0;
  68. }
  69. else if(this.other & 4){
  70. this.jiangmaType = 3;
  71. this.jiangmaCount = 1;
  72. }
  73. this.hzCount = 0;/////红中个数
  74. if(this.other & 64) this.hzCount = 4;
  75. else if(this.other & 1024) this.hzCount = 6;
  76. else if(this.other & 2048) this.hzCount = 8;
  77. this.isQGHJM = false;/////是否抢杠胡奖码
  78. if(this.other & 128) this.isQGHJM = true;
  79. this.isHZHG = false;/////是否荒庄荒杠
  80. if(this.other & 256) this.isHZHG = true;
  81. this.isWGHZJYM = false;/////无红中胡加一码
  82. if(this.other & 512) this.isWGHZJYM = true;
  83. this.isZNZM = this.type == 2;/////是否只能自摸,拉杠情况可以胡
  84. // console.warn("奖码类型:-1:不奖码,1:159奖码,2:摸几奖几,3:一码全中 "+this.jiangmaType)
  85. // console.warn("奖码张数 "+this.jiangmaCount)
  86. // console.warn("红中个数 "+this.hzCount)
  87. // console.warn("是否抢杠胡奖码 "+this.isQGHJM)
  88. // console.warn("是否荒庄荒杠 "+this.isHZHG)
  89. // console.warn("无红中胡加一码 "+this.isWGHZJYM)
  90. // console.warn("是否只能自摸 "+this.isZNZM)
  91. this.cost = num_cost;
  92. this.over = 0;
  93. this.round = round;
  94. this.stime = 0;
  95. this.ctime = Date.now();
  96. // 人数
  97. this.ccount = playerAllCount;//Logic.CHAIR_COUNT;
  98. this.mcount = Logic.CARDS_COUNT;
  99. // 房主
  100. this.ownerChairId = -1;//房主的chairid
  101. this.ownerId = cPlayerId;//房主Id
  102. this.ownerUid = cUserId;//房主的userID
  103. this.ownerName = cName;
  104. this.ownerHeadUrl = cHead;
  105. // 数据
  106. var logic = new Logic(type,gameKindTL,playerAllCount,other);
  107. this.logic = logic;
  108. this.score = new Score(this);
  109. this.handCards = Array(this.ccount);
  110. this.huCards = logic.fillDeep(Array(this.ccount), []);
  111. this.users = Array(this.ccount);
  112. this.chBanker = 0;
  113. this.quFeng = 0;
  114. this.bankFlag = 0;
  115. this.outCards = logic.fillDeep(Array(this.ccount), []);
  116. // 标记
  117. this.isDihus = _.fill(Array(this.ccount), true);
  118. this.isTianhu = true;
  119. this.outCard = 0;
  120. this.outerId = -1;
  121. this.disCards = [];
  122. this.currentId = -1;
  123. // 包含字,总杠次,保留量
  124. // this.hasWords = !(type & 2);/////TL++zs
  125. // this.hasWords = true;/////是否含有字牌/////TL++
  126. this.gonCount = 0;
  127. // this.disCounts = [26, 14, 16, 26];/////TL++zs
  128. // this.disCounts = [1,1,1,1,];
  129. // 允许吃牌
  130. this.hasEat = false;//!!(type & 4);////是否可吃牌
  131. // 允许点炮
  132. this.hasEHu = true;///!!(type & 8);
  133. // 一炮多响
  134. this.isMHu = true;//!!(type & 16);
  135. // 允许杠胡
  136. this.hasGHu = true;///!!(type & 32);
  137. // 点炮出钱
  138. this.isWOne = true;//!!(type & 64);
  139. // 权限:16-胡,8-杠,4-碰,2-吃,1-等待,0-无
  140. this.masks = _.fill(Array(this.ccount), 0);
  141. this.excepts = logic.fillDeep(Array(this.ccount), {});
  142. // 等待杠类型,1-普通杠, 2-暗杠, 3-自摸明杠
  143. this.gangType = 0;
  144. this.gangCard = 0;
  145. // 抢杠胡、被杠玩家
  146. this.isGangHu = false;
  147. this.gangOuter = -1;
  148. // 等待吃类型,1-@**左吃, 2-*@*中吃, 3-@**右吃
  149. this._eatType = 0;
  150. // 胡牌者
  151. this.anams = Array(this.ccount);
  152. this.huRes = Array(this.ccount);
  153. this.winner = { lead: -1, chs: [] };
  154. // 底分
  155. this.cell = cell;
  156. // 围观者
  157. this.lookers = [];
  158. //结束时的继线用户
  159. this.leaveUsers = [];
  160. // 状态
  161. this.state = STATE.FREE;
  162. // 申请结束标记
  163. this.overFlag = 0;
  164. this.overTimer = null;
  165. this.endTableTime = 60;//////TL++,申请解散房间之后60秒之后不操作则认为同意解散
  166. this.reqJieSan = [-1,-1,-1,-1];/////解散桌子数据,前面为chirid后面为情况-1:未操作 0:拒绝 1:同意 2为解散发起
  167. //断线 结束定时器
  168. this.endTimer = null;
  169. //////以下全为TL++
  170. /////TL++,补花定时器,防止连续补花太快
  171. this.PJHF = new paiJuHuiFang();
  172. // this.buhuaTimeout = null;
  173. this.backStartTimer = null;//////重入之后系统会自动准备为了解决可能没牌的问题2秒之后才开始游戏
  174. this.PaijuHuiFang = [];////TL++,牌局回放
  175. // this.zhyzfgs = [-2,null,null];/////TL++,由于最后一张牌的摸牌被打断所以 用来记录最后一张牌的发牌函数的参数
  176. // this.isLianGang = [-1,false,-1];/////TL++,连杠的玩家座位号,是否连杠 杠的牌
  177. this.isYJJSGL = false;/////是否已经执行过结算函数了
  178. this.isYJKSGL = false;/////是否已经执行过开始函数了
  179. this.JSFJTimeout = null;//解散房间倒计时
  180. this.JSFJTime = 60;//解散房间倒计时60秒
  181. this.gameNeverStart = true;//游戏是否从未开始过,用于解散房间判断
  182. this.pjhffileName = [];//用于记录玩家牌局回放的json文件名
  183. this.playerPosList = [[],[],[],[]];//记录玩家的位置信息数组
  184. this.gameKindTL = gameKindTL || 1;//平搓还是冲刺 = 1代表平搓 = 2代表冲刺
  185. this.playerAllCount = playerAllCount || 4;//游戏人数 = 2表示2人局 = 3表示3人局 = 4表示4人局
  186. this.isNeverStart = true;//游戏是否从未开始
  187. this.sszjDataList = [];//设置实时战绩的数据
  188. this.isEveryZZ = false;//是否每一个人都做过庄
  189. // this.isZJYG = false;////本局庄家是否有杠
  190. this.chairArry = [0,1,2,3];//
  191. // this.isNeverTounchHU = false;/////是否从未点击过胡按钮
  192. this.sszjs = [];//ts++实时战绩
  193. this.LWKF = [0,0,10,0,10];//////TL++礼物扣费
  194. this.isGameOk=false;//ts++牌局正常结束
  195. this.agentRebate=0;//ts++本局的返利
  196. //代理返利比例
  197. this.rEBATERATE=1;//业绩模式必须为100% 0.5;
  198. };
  199. // 导出状态
  200. Table.STATE = STATE;
  201. //ts++ 结束模式
  202. Table.ENDMODE = ENDMODE;
  203. // 导出类
  204. module.exports = Table;
  205. // 原型对象
  206. var proto = Table.prototype;
  207. // 是否站满
  208. proto.isFull = function () {
  209. return (this.lookers.length >= 5);
  210. };
  211. // 是否准备
  212. proto.isReady = function () {
  213. for (let user of this.users) {
  214. if (!user || !user.isReady()) return false;
  215. }
  216. return true;
  217. };
  218. // ts++是否二次准备
  219. proto.isReady2 = function () {
  220. for (let user of this.users) {
  221. if (!user || !user.isReady2()) return false;
  222. }
  223. return true;
  224. };
  225. // 是否游戏中
  226. proto.isPlaying = function () {
  227. return this.state > STATE.FREE;
  228. };
  229. // 是否全在线
  230. proto.isOnline = function () {
  231. for (let user of this.users) {
  232. if (user && user.isOffline()) return false;
  233. }
  234. return true;
  235. };
  236. // 是否全断线
  237. proto.isOffline = function () {
  238. for (let user of this.users) {
  239. if (!user || !user.isOffline()) return false;
  240. }
  241. return true;
  242. };
  243. // 是否空桌
  244. proto.isEmpty = function () {
  245. if (this.lookers.length > 0) return false;
  246. for (let i = 0; i < this.users.length; ++i) {
  247. if (this.users[i]) return false;
  248. }
  249. return true;
  250. };
  251. // 局数完成
  252. proto.isGameOver = function () {
  253. let str3 = "table 局数完成 .......id: "+ this.id + " this.over " + this.over;
  254. logger.warn(str3);////cssj
  255. return (this.over >= this.round);
  256. };
  257. // 重置本局
  258. proto.resetRound = function () {
  259. _.fill(this.handCards, null);
  260. _.fill(this.isDihus, true);
  261. this.isTianhu = true;
  262. _.fill(this.masks, 0);
  263. this.logic.fillDeep(this.excepts, {});
  264. _.fill(this.huRes, null);
  265. this.gonCount = 0;
  266. this.winner.chs = [];
  267. this.winner.lead = -1;
  268. this.logic.fillDeep(this.huCards, []);
  269. this.logic.fillDeep(this.outCards, []);
  270. this.outCard = 0;
  271. this.outerId = -1;
  272. this.currentId = -1;
  273. this._eatType = 0;
  274. this.gangType = 0;
  275. this.gangCard = 0;
  276. this.isGangHu = false;
  277. this.gangOuter = -1;
  278. };
  279. // 发送消息
  280. proto.pushMsgAsync = cor(function* (cidOrIds, route, msg) {
  281. // console.warn("444WWWWWWWTTTTTT",cidOrIds, route, msg);
  282. var playerIds = [];
  283. if (Array.isArray(cidOrIds)) playerIds = cidOrIds;
  284. else {
  285. if (cidOrIds < 0 || cidOrIds >= this.users.length) {
  286. for (let user of this.users) {
  287. if (user) playerIds.push(user.id);
  288. }
  289. for (let lker of this.lookers) {
  290. playerIds.push(lker.id);
  291. }
  292. } else {
  293. let user = this.users[cidOrIds];
  294. if (user) playerIds.push(user.id);
  295. // console.warn("555WWWWWWWTTTTTT",cidOrIds, route, user.name);
  296. }
  297. }
  298. if (playerIds.length > 0) {
  299. let channelId = 'xct:' + this.id;
  300. // console.warn("666WWWWWWWTTTTTT",cidOrIds, route, playerIds,msg);
  301. return this.app.controllers.push._pushAsync(channelId, playerIds, route, msg);
  302. }
  303. });
  304. // 围观消息
  305. proto.lookMsgAsync = cor(function* (route, msg) {
  306. var playerIds = [];
  307. for (let lker of this.lookers) {
  308. playerIds.push(lker.id);
  309. }
  310. if (playerIds.length > 0) {
  311. let channelId = 'xct:' + this.id;
  312. return this.app.controllers.push._pushAsync(channelId, playerIds, route, msg);
  313. }
  314. });
  315. // 获得桌子信息
  316. proto.getTableInfo = function () {
  317. // 桌子信息
  318. var tableInfo = {
  319. id: this.id,
  320. type: this.type,
  321. cost: this.cost,
  322. over: this.over,
  323. round: this.round,
  324. users: [],
  325. lookers: [],
  326. ownerId: -1,//this.ownerChairid
  327. ownerUserId: this.ownerUid,////TL++,房主的userID
  328. ownerName: this.ownerName,//////TL++,房主的昵称
  329. ownerHeadUrl: this.ownerHeadUrl,//////TL++,房主的头像地址
  330. gameKindTL: this.gameKindTL,////平搓还是冲刺 = 1代表平搓 = 2代表冲刺
  331. playerAllCount: this.playerAllCount,////游戏人数 = 2表示2人局 = 3表示3人局 = 4表示4人局
  332. other: this.other,
  333. creatTime : this.ctime,
  334. state: this.state,
  335. sszjDataList: this.sszjDataList,////TL++,设置实时战绩的数据
  336. isZHYZ: this.logic.isZHYZ, /////TL++,是否最后一张
  337. playerPosList: this.playerPosList,/////TL++玩家位置数据
  338. chairArry: this.chairArry,/////TL++
  339. isNeverStart: this.isNeverStart,/////TL++,游戏是否从未开始
  340. overFlag:this.overFlag,//ts++房间解散标识
  341. endTableTime:this.endTableTime,
  342. recordid:this.recordid,
  343. reqJieSan:this.reqJieSan
  344. };
  345. // 正在游戏
  346. var isPlaying = this.isPlaying();
  347. if (isPlaying) {
  348. tableInfo.qFeng = this.quFeng;
  349. tableInfo.banker = this.chBanker;
  350. tableInfo.stime = Date.now() - this.stime;
  351. tableInfo.currentId = this.currentId;
  352. tableInfo.disCards = this.disCards;
  353. tableInfo.lastCount = this.logic.leaveCount();
  354. tableInfo.isGangHu = this.isGangHu;
  355. tableInfo.gangCard = this.gangCard;
  356. //////TL++,游戏过程中重入
  357. tableInfo.baiDaCard = String(this.logic.baiDaCard);//////TL++,本局百搭牌
  358. tableInfo.everyFllowerCardList = [[],[],[],[]]; /////每个人手上的花牌
  359. //////TL++ end,游戏过程中重入
  360. }
  361. // 桌上玩家
  362. for (let i = 0; i < this.users.length; ++i) {
  363. let user = this.users[i];
  364. if (user) {
  365. let score = this.score.getScore(user.id);
  366. let uinfo = {
  367. account: user.account, name: user.name, sex: user.sex, headurl: user.headurl,
  368. state: user.state2, score: score, chairId: user.chairId
  369. };
  370. if (isPlaying) {
  371. let huCards = [];
  372. for (let huCard of this.huCards[i]) {
  373. huCards.push({ style: huCard.style, type: huCard.type, card: huCard.cards[0], origin: huCard.origin });
  374. }
  375. uinfo.huCards = huCards;
  376. uinfo.outCards = this.outCards[i];
  377. let handCard = this.handCards[i] || [];
  378. uinfo.handCount = handCard.length;
  379. }
  380. tableInfo.users.push(uinfo);
  381. }
  382. }
  383. // 围观玩家
  384. for (let i = 0; i < this.lookers.length; ++i) {
  385. let user = this.lookers[i];
  386. if (user) {
  387. tableInfo.lookers.push({ account: user.account, name: user.name, sex: user.sex, headurl: user.headurl });
  388. }
  389. }
  390. return tableInfo;
  391. };
  392. // 回到桌子
  393. proto.backAsync = cor(function* (user) {
  394. let str3 = "table回到桌子.......id: "+ this.id + " user.chairId: " + user.chairId + " user.name: " + user.name ;
  395. logger.warn(str3);////cssj
  396. user.offlinetime=0;//ts++
  397. var data = { chairId: String(user.chairId) };
  398. var chairId = user.chairId;
  399. let isGuoHuList = [[false,0],[false,0],[false,0],[false,0],];
  400. if (chairId != -1) {
  401. // 加入频道
  402. var connectorId = user.connectorId || '';
  403. if (connectorId) {
  404. let channelId = 'xct:' + this.id;
  405. yield this.app.controllers.push._joinAsync(channelId, user.id, connectorId);
  406. }
  407. // 恢复状态
  408. if (this.state == STATE.FREE) {
  409. yield this.readyGameAsync(user);
  410. } else if (this.state == STATE.PLAYING) {
  411. //user.state = User.STATE.PLAYING;//ts--
  412. user.state2 = User.STATE.PLAYING;//ts++
  413. data.mask = String(this.masks[chairId]);
  414. data.handCards = this.handCards[chairId];
  415. // 状态通知
  416. yield this.pushMsgAsync(-1, 'sxjiang_event', { type: M.STATE_CHANGE, data: { chairId: String(user.chairId), state: String(user.state2), state2: String(user.state2) } });
  417. }else if (this.state == STATE.FREE2) {//ts++二次准备
  418. //user.state = User.STATE.PLAYING;//ts--
  419. user.state2 = User.STATE.READY;
  420. yield this.pushMsgAsync(-1, 'sxjiang_event', { type: M.STATE_CHANGE, data: { chairId: String(user.chairId), state: String(user.state2), state2: String(user.state2) } });
  421. if (this.isReady2() && !this.isGameOk)
  422. {
  423. if(!this.backStartTimer){
  424. this.backStartTimer = this.app.timer.setTimeout(() => this.backStartTimeAsync(), 2 * 1000);//延迟2秒开始游戏
  425. }
  426. }
  427. }
  428. // 取消计时
  429. if (this.isOnline() && this.endTimer) {
  430. clearTimeout(this.endTimer);
  431. this.endTimer = null;
  432. }
  433. isGuoHuList[chairId] = this.logic.isGuoHuList[chairId];
  434. }
  435. // 数据处理
  436. data.fee = this.score.isFeed(user.id) ? '0' : '1';
  437. data.table = this.getTableInfo();
  438. let hutipdata = {
  439. renyi:0,//////是否可胡任意牌,0表示不满足1表示满足
  440. kehuData:[]/////对象数组,分别表示打哪张可胡哪几张数据
  441. };
  442. if(chairId == this.currentId){
  443. let tipres = this.logic.hutip(this.currentId,this.handCards[this.currentId],this.huCards[this.currentId],this.huCards,this.outCards);////重入时调用胡牌提示
  444. data.table.hutipdata = tipres;
  445. }
  446. else{
  447. data.table.hutipdata = hutipdata;
  448. }
  449. data.table.isGuoHuList = isGuoHuList;
  450. return { code: C.OK, data: data };
  451. });
  452. //ts++重入后自动开始
  453. proto.backStartTimeAsync = cor(function* () {
  454. yield this.startGameAsync();
  455. });
  456. // 加入桌子
  457. proto.joinAsync = cor(function* (user) {
  458. // 撤出删除队列
  459. //this.game.cancelDelete(this.id);
  460. // 加入桌子之前
  461. yield this.beforeJoinAsync(user);
  462. // 加入围观者
  463. this.lookers.push(user);
  464. // 加入桌子之后
  465. yield this.afterJoinAsync(user);
  466. // 数据返回处理
  467. var data = { chairId: String(user.chairId) };
  468. data.fee = this.score.isFeed(user.id) ? '0' : '1';
  469. data.table = this.getTableInfo();
  470. return { code: C.OK, data: data };
  471. });
  472. // 加入桌子之前
  473. proto.beforeJoinAsync = cor(function* (user) {
  474. var connectorId = user.connectorId || '';
  475. if (connectorId) {
  476. let channelId = 'xct:' + this.id;
  477. return this.app.controllers.push._joinAsync(channelId, user.id, connectorId);
  478. }
  479. });
  480. // 加入桌子之后
  481. proto.afterJoinAsync = cor(function* (user) {
  482. // 加入通知
  483. return this.pushMsgAsync(-1, 'sxjiang_event', {
  484. type: M.JOIN, data: { account: user.account, userId: user.userId, name: user.name, sex: user.sex, headurl: user.headurl,playerPosList: this.playerPosList }
  485. });
  486. });
  487. // 坐下桌子
  488. proto.seatAsync = cor(function* (user, chairId) {
  489. // let chairId = this.chairArry[_chairId];
  490. // console.warn("坐下桌子不不vvvvvv",chairId,_chairId,this.chairArry,this.users.length);
  491. // 参数校验
  492. if (chairId < 0 || chairId >= this.ccount) {
  493. return { code: C.FAILD, msg: C.CHAIR_NOT_FOUND };
  494. }
  495. if (this.users[chairId]) {
  496. // console.warn("坐下桌子死了vv000",this.users[chairId]);
  497. // console.warn("坐下桌子死了vvvvvv",this.users.length,this.users);
  498. return { code: C.FAILD, msg: C.CHAIR_HAS_SOMEONE };
  499. }
  500. // 查找玩家
  501. var player = yield this.app.models.Player.findByIdAsync(user.id, 'diamond cost');
  502. if (!player) {
  503. return { code: C.FAILD, msg: C.PLAYER_NOT_FOUND };
  504. }
  505. if (this.users[chairId]) {
  506. return { code: C.FAILD, msg: C.CHAIR_HAS_SOMEONE };
  507. }
  508. // 调换座位
  509. if (user.chairId != -1) {
  510. return this.changeChairAsync(user, chairId);
  511. }
  512. // 围观玩家
  513. var pos = _.findIndex(this.lookers, (u) => (u.id == user.id));
  514. if (pos == -1) {
  515. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  516. }
  517. //ts++
  518. let dSource=player.diamond;
  519. let dNow=player.diamond;
  520. //坐下花费
  521. var costdata = null;
  522. if (!this.score.isFeed(user.id)) {
  523. if (player.diamond < this.cost) {
  524. return { code: C.FAILD, msg: C.GAME_DIAMOND_LOW };
  525. }//////TL++zsyl 1000局测完之后要放出来的
  526. player.diamond -= this.cost;
  527. player.cost = (player.cost || 0) + this.cost;
  528. dNow-=this.cost;
  529. this.score.addUser(user.id,chairId,user.userId, user.name, user.sex, user.headurl,user.diamond,this.gameKindTL);
  530. costdata = { cost: String(this.cost) };
  531. }
  532. // 坐下处理
  533. this.lookers.splice(pos, 1);
  534. this.users[chairId] = user;
  535. user.chairId = chairId;
  536. user.state = User.STATE.READY;
  537. yield this.afterSeatAsync(user);
  538. if (player.isModified())
  539. {
  540. yield player.saveAsync();/////只有第一次坐下的时候才会执行
  541. // 钻石记录
  542. var diamondrecord = new this.app.models.DiamondRecord({
  543. _id: uuid.v1(),
  544. playerId: user.id,
  545. dType: 3,//坐下
  546. dSource: dSource,
  547. dSwap: -1*this.cost,
  548. dNow: dNow,
  549. tableId: this.recordid
  550. });
  551. yield diamondrecord.saveAsync();
  552. // console.warn("ts++坐下-------------------钻石记录");
  553. if (costdata) yield this.pushMsgAsync(chairId, 'sxjiang_event', { type: M.COST_FEE, data: costdata });
  554. }
  555. // if (this.isReady()) yield this.pushMsgAsync(this.ownerChairid, 'sxjiang_event', { type: M.START_BUTTON });//////TL++zsyl所有人准备之后通知房主点击开始游戏
  556. if (this.state == STATE.FREE && this.isReady() && !this.isGameOk) {
  557. yield this.randomChangeChairTL();
  558. }
  559. return { code: C.OK, chairId: String(chairId) };
  560. });
  561. // 调换座位 自己坐下之后点击另外一个位子的时候调用这个方法 这个参数user输出之后相当的长
  562. proto.changeChairAsync = cor(function* (user, chairId) {
  563. if (this.state != STATE.FREE) {
  564. return { code: C.FAILD, msg: C.TABLE_NOT_FREE };
  565. }
  566. if (this.users[chairId]) {
  567. return { code: C.FAILD, msg: C.CHAIR_HAS_SOMEONE };
  568. }
  569. // var _chairId = user.chairId;
  570. // delete this.users[_chairId];
  571. // this.users[chairId] = user;
  572. // user.chairId = chairId;
  573. // user.state = User.STATE.READY;
  574. // yield this.pushMsgAsync(-1, 'sxjiang_event', { type: M.CHAIR_CHANGE, data: { oldId: String(_chairId), newId: String(chairId), state: String(user.state), state2: String(user.state2) } });
  575. // // if (this.ownerChairid == _chairId) {
  576. // // this.ownerChairid = chairId;
  577. // // // 换房主通知
  578. // // yield this.pushMsgAsync(-1, 'sxjiang_event', { type: M.OWNER_CHANGE, data: { ownerChairid: String(this.ownerChairid) } });
  579. // // }
  580. return { code: C.OK, chairId: String(chairId) };
  581. });
  582. // 坐下桌子之后
  583. proto.afterSeatAsync = cor(function* (user) {
  584. let posListTL = {
  585. chairId: user.chairId,
  586. headurl: user.headurl,
  587. longitude: user.longitude, // 经度,浮点数,范围为180 ~ -180。
  588. latitude: user.latitude, // 纬度,浮点数,范围为90 ~ -90
  589. }
  590. this.playerPosList[user.chairId] = posListTL/////TL++记录玩家的位置信息数组
  591. // 坐下通知
  592. let score = this.score.getScore(user.id);
  593. yield this.pushMsgAsync(-1, 'sxjiang_event', {///////发送坐下
  594. type: M.SEAT, data: {
  595. account: user.account,
  596. name: user.name,
  597. sex: user.sex,
  598. headurl: user.headurl,
  599. state: String(user.state),
  600. score: String(score),
  601. chairId: String(user.chairId),
  602. userId: String(user.userId),
  603. playerPosList: this.playerPosList, /////TL++记录玩家的位置信息数组
  604. }
  605. });
  606. });
  607. //////TL++,在首次游戏开始的时候随机打乱用户的座位
  608. proto.randomChangeChairTL = cor(function* () {
  609. // console.warn("111在首次游戏开始的时候随机打乱用户的座位",this.users[0].name,this.users[1].name,this.users[2].name,this.users[3].name);
  610. // console.warn("1在首次游戏开始的时候随机打乱用户的座位",this.users[0].chairId,this.users[1].chairId,this.users[2].chairId,this.users[3].chairId);
  611. if(this.playerAllCount > 2){
  612. let changeResult = [];
  613. if (this.over <= 0) {///////本房间开始的第一局游戏
  614. // for (let i = 0; i < this.ccount; i++) {/////这种随机4次可能会导致4次随机之后和打乱之前的顺序一样所以弃用
  615. for (let i = 0; i < 1; i++) {
  616. let oldchaieID = i;
  617. let olduser = this.users[i];
  618. let newchaieID = Math.floor(Math.random()*this.playerAllCount);////// 区间[0,3]取整数
  619. while (newchaieID == oldchaieID) {
  620. newchaieID = Math.floor(Math.random()*this.playerAllCount);////// 区间[0,3]取整数
  621. }
  622. let newuser = this.users[newchaieID];
  623. // console.warn("222在首次游戏开始的时候随机打乱用户的座位",oldchaieID,newchaieID);
  624. // console.warn("xxxxxxxxx删除有没有用啊",this.users.length);
  625. delete this.users[newchaieID];
  626. delete this.users[oldchaieID];
  627. // console.warn("xxxxxxxxx22删除有没有用啊",this.users.length);
  628. this.users[newchaieID] = olduser;
  629. this.users[newchaieID].chairId = newchaieID;
  630. // this.users[newchaieID].id = newuser.id;
  631. this.users[oldchaieID] = newuser;
  632. this.users[oldchaieID].chairId = oldchaieID;
  633. // this.users[oldchaieID].id = olduser.id;
  634. changeResult.push([oldchaieID,newchaieID])
  635. }
  636. // console.warn("333在首次游戏开始的时候随机打乱用户的座位",this.users[0].name,this.users[1].name,this.users[2].name,this.users[3].name);
  637. // console.warn("3在首次游戏开始的时候随机打乱用户的座位",this.users[0].chairId,this.users[1].chairId,this.users[2].chairId,this.users[3].chairId);
  638. // console.warn("3在首次游戏开始的时候随机打乱用户的座位",this.users[0].id,this.users[1].id,this.users[2].id,this.users[3].id);
  639. // console.warn("3在首次游戏开始的",this.users[0]);
  640. ////// this.users 发送给前端会代码报错
  641. // yield this.pushMsgAsync(-1, 'sxjiang_event', { type: M.CHAIR_DALUAN, data: { changeResult:changeResult } });
  642. /////TL++
  643. for (let i = 0; i < this.users.length; ++i) {
  644. this.score.setUserChair(this.users[i].id,this.users[i].chairId)
  645. }
  646. let daluanData = [];
  647. var isPlaying = this.isPlaying();
  648. for (let i = 0; i < this.users.length; ++i) {
  649. let user = this.users[i];
  650. if (user) {
  651. let score = this.score.getScore(user.id);
  652. let uinfo = {
  653. account: user.account, name: user.name, sex: user.sex, headurl: user.headurl,
  654. state: user.state, score: score, chairId: user.chairId
  655. };
  656. if (isPlaying) {
  657. let huCards = [];
  658. for (let huCard of this.huCards[i]) {
  659. huCards.push({ style: huCard.style, type: huCard.type, card: huCard.cards[0], origin: huCard.origin });
  660. }
  661. uinfo.huCards = huCards;
  662. uinfo.outCards = this.outCards[i];
  663. let handCard = this.handCards[i] || [];
  664. uinfo.handCount = handCard.length;
  665. }
  666. daluanData.push(uinfo);
  667. }
  668. }
  669. // this.score.delUser(user.id);
  670. yield this.pushMsgAsync(-1, 'sxjiang_event', { type: M.CHAIR_DALUAN, data: { daluanData:daluanData } });
  671. }
  672. }
  673. // console.warn("444在首次游戏开始的时候随机打乱用户的座位",changeResult);
  674. // this.starTimer = this.app.timer.setTimeout(() => this.startGameAsync(), 500);
  675. yield this.startGameAsync()/////TL++,在首次游戏的时候随机打乱用户的座位
  676. });
  677. // 站起桌子
  678. proto.standAsync = cor(function* (user) {
  679. let str3 = "table 站起桌子.......id: "+ this.id + " user.chairId: " + user.chairId + " user.name: " + user.name ;
  680. logger.warn(str3);////cssj
  681. var chairId = user.chairId;
  682. if (chairId != -1) {
  683. user.state = User.STATE.FREE;
  684. delete this.users[chairId];
  685. delete this.handCards[chairId];
  686. user.chairId = -1;
  687. this.lookers.push(user);
  688. yield this.afterStandAsync(user, chairId);
  689. }
  690. return { code: C.OK };
  691. });
  692. // 站起桌子之后
  693. proto.afterStandAsync = cor(function* (user, chairId) {
  694. // 站起通知
  695. yield this.pushMsgAsync(-1, 'sxjiang_event', { type: M.STAND, data: { chairId: String(chairId) } });
  696. //if (this.ownerChairid == -1) this.ownerChairid = -1;//////TL++,房主坐下之后重置房主chairid
  697. /////TL++,作坐下的玩家离开桌子之后将他的位置信息从位置列表里面删除
  698. if(chairId != -1) this.playerPosList[chairId] = [];
  699. // 桌主离开
  700. //////TL++zsyl,原先的这个逻辑是房主站起之后会切换房主
  701. // if (chairId == this.ownerChairid) {
  702. // let newCid = _.findIndex(this.users, (user) => user);
  703. // this.ownerChairid = newCid;
  704. // if (newCid != -1) this.ownerUid = this.users[newCid].id;
  705. // // 换房主通知
  706. // yield this.pushMsgAsync(-1, 'sxjiang_event', { type: M.OWNER_CHANGE, data: { ownerChairid: String(this.ownerChairid) } });
  707. // }
  708. //是否退费
  709. // console.warn("ts++++++++站起桌子之后");
  710. var scorer = this.score.getUser(user.id);
  711. if (scorer && scorer.over <= 0) {
  712. // console.warn("ts++没有开始游戏退分",user.id);
  713. this.score.delUser(user.id);
  714. let player = yield this.app.models.Player.findByIdAsync(user.id, 'diamond cost');
  715. if (player) {
  716. // console.warn("ts++没有开始游戏退分",player.diamond);
  717. let dSource=player.diamond;
  718. let dNow=player.diamond+this.cost;
  719. player.diamond += this.cost;
  720. player.cost -= this.cost;
  721. yield player.saveAsync();
  722. //return this.app.controllers.player.pushAsync(user.id, 'sxjiang_event', { type: M.BACK_FEE, data: { back: String(this.cost) } });
  723. // 退费 钻石记录
  724. var diamondrecord = new this.app.models.DiamondRecord({
  725. _id: uuid.v1(),
  726. playerId: user.id,
  727. dType: 4,//退费
  728. dSource: dSource,
  729. dSwap: this.cost,
  730. dNow: dNow,
  731. tableId: this.recordid
  732. });
  733. yield diamondrecord.saveAsync();
  734. // console.warn("ts++退分-------------------钻石记录");
  735. //var costdata = { cost: String(-1*this.cost) };
  736. //if (costdata) yield this.pushMsgAsync(chairId, 'sxjiang_event', { type: M.COST_FEE, data: costdata });
  737. }
  738. }
  739. else
  740. {
  741. if(user.cost==0 && user.spreadId)//ts++推荐人奖励
  742. {
  743. // let spreader = yield this.app.models.Player.findByIdAsync(user.spreadId, 'spreadCount spreadRebate');
  744. // if (spreader) {
  745. // spreader.spreadCount += 1;
  746. // spreader.spreadRebate += 100;
  747. // yield spreader.saveAsync();
  748. // }
  749. ////20200928因为现在的spreadId存的是userId,所以上面那段用不了了
  750. let xzdsjc = Date.now();
  751. if(xzdsjc > 1602172800000 || xzdsjc < 1601481600000){////国庆期间不发放
  752. var cpopts = {};
  753. cpopts['userId'] = parseInt(user.spreadId);
  754. let spreadList = yield this.app.models.Player.findMongoAsync(cpopts, 'spreadCount spreadRebate', { sort: { stime: 1 } });//
  755. if(spreadList.length == 1){
  756. spreadList[0].spreadCount += 1;
  757. spreadList[0].spreadRebate += 100;
  758. yield spreadList[0].saveAsync();
  759. }
  760. }
  761. }
  762. if(this.agentId) //正常结束的才能算
  763. {
  764. if(this.agentRebate>0)
  765. {
  766. //console.warn("代理返利写分+++++");
  767. let gameCost2=this.agentRebate;//游戏消耗
  768. let agentRebate2=parseInt(this.agentRebate*this.rEBATERATE);
  769. this.agentRebate=0;
  770. var today = new Date();
  771. today.setHours(0);
  772. today.setMinutes(0);
  773. today.setSeconds(0);
  774. today.setMilliseconds(0);
  775. let nowverifyDate=today.getTime();
  776. var agenter = yield this.app.models.Agenter.findByIdAsync(this.agentId,'rebateOther rebateCount rebateAll rebateNow rebateOut verifyDate verifyRebate dateGameTimes02 dateGameTimes03 dateGameTimes0 dateGameTimes42 dateGameTimes43 dateGameTimes4 dateGameTimes82 dateGameTimes83 dateGameTimes8 dateGameTimes162 dateGameTimes163 dateGameTimes16 dateGameCost0 dateGameCost4 dateGameCost8 dateGameCost16 agentRate');
  777. if (agenter)
  778. {
  779. //日结算
  780. let verifyBool=false;
  781. let verifyDate=0;
  782. let verifyRebate=0;
  783. //日奖励
  784. let dateAgentRate=0;
  785. let dateRebate=0;
  786. let dateGameTimes02=0;
  787. let dateGameTimes42=0;
  788. let dateGameTimes82=0;
  789. let dateGameTimes162=0;
  790. let dateGameTimes03=0;
  791. let dateGameTimes43=0;
  792. let dateGameTimes83=0;
  793. let dateGameTimes163=0;
  794. let dateGameTimes0=0;
  795. let dateGameTimes4=0;
  796. let dateGameTimes8=0;
  797. let dateGameTimes16=0;
  798. let dateGameCost0=0;
  799. let dateGameCost4=0;
  800. let dateGameCost8=0;
  801. let dateGameCost16=0;
  802. if(agenter.verifyRebate>0 && agenter.verifyDate!=nowverifyDate)
  803. {
  804. verifyBool=true;
  805. verifyDate=agenter.verifyDate;
  806. verifyRebate=agenter.verifyRebate;
  807. dateAgentRate=agenter.agentRate;
  808. dateGameTimes0=agenter.dateGameTimes0;
  809. dateGameTimes4=agenter.dateGameTimes4;
  810. dateGameTimes8=agenter.dateGameTimes8;
  811. dateGameTimes16=agenter.dateGameTimes16;
  812. dateGameTimes02=agenter.dateGameTimes02;
  813. dateGameTimes42=agenter.dateGameTimes42;
  814. dateGameTimes82=agenter.dateGameTimes82;
  815. dateGameTimes162=agenter.dateGameTimes162;
  816. dateGameTimes03=agenter.dateGameTimes03;
  817. dateGameTimes43=agenter.dateGameTimes43;
  818. dateGameTimes83=agenter.dateGameTimes83;
  819. dateGameTimes163=agenter.dateGameTimes163;
  820. dateGameCost0=agenter.dateGameCost0;
  821. dateGameCost4=agenter.dateGameCost4;
  822. dateGameCost8=agenter.dateGameCost8;
  823. dateGameCost16=agenter.dateGameCost16;
  824. ////20200801去掉额外返利
  825. // if(dateAgentRate==10 || dateAgentRate==20 || dateAgentRate==30 || dateAgentRate==40 || dateAgentRate==50)
  826. // {
  827. // if(dateGameCost0>0)
  828. // {
  829. // dateRebate+=parseInt(dateGameCost0*dateAgentRate/100);
  830. // }
  831. // if(dateGameCost4>0)
  832. // {
  833. // dateRebate+=parseInt(dateGameCost4*dateAgentRate/100);
  834. // }
  835. // if(dateGameCost8>0)
  836. // {
  837. // dateRebate+=parseInt(dateGameCost8*dateAgentRate/100);
  838. // }
  839. // if(dateGameCost16>0)
  840. // {
  841. // dateRebate+=parseInt(dateGameCost16*dateAgentRate/100);
  842. // }
  843. // }
  844. agenter.dateGameTimes0=0;
  845. agenter.dateGameTimes4=0;
  846. agenter.dateGameTimes8=0;
  847. agenter.dateGameTimes16=0;
  848. agenter.dateGameTimes02=0;
  849. agenter.dateGameTimes42=0;
  850. agenter.dateGameTimes82=0;
  851. agenter.dateGameTimes162=0;
  852. agenter.dateGameTimes03=0;
  853. agenter.dateGameTimes43=0;
  854. agenter.dateGameTimes83=0;
  855. agenter.dateGameTimes163=0;
  856. agenter.dateGameCost0=0;
  857. agenter.dateGameCost4=0;
  858. agenter.dateGameCost8=0;
  859. agenter.dateGameCost16=0;
  860. agenter.rebateNow += verifyRebate;
  861. agenter.rebateNow += dateRebate;
  862. agenter.rebateOther += dateRebate;
  863. agenter.rebateCount += dateRebate;
  864. agenter.verifyRebate=0;
  865. }
  866. //修改代理数据
  867. agenter.rebateCount += agentRebate2;
  868. agenter.rebateAll += agentRebate2;
  869. agenter.verifyDate=nowverifyDate;
  870. agenter.verifyRebate+= agentRebate2;
  871. if(this.gameKindTL == 2){
  872. if(this.ccount==2)
  873. {
  874. agenter.dateGameTimes02+=1;
  875. }
  876. else if(this.ccount==3)
  877. {
  878. agenter.dateGameTimes03+=1;
  879. }
  880. else if(this.ccount==4)
  881. {
  882. agenter.dateGameTimes0+=1;
  883. }
  884. agenter.dateGameCost0+=gameCost2;
  885. }
  886. else
  887. {
  888. if(this.round == 4){
  889. if(this.ccount==2)
  890. {
  891. agenter.dateGameTimes42+=1;
  892. }
  893. else if(this.ccount==3)
  894. {
  895. agenter.dateGameTimes43+=1;
  896. }
  897. else if(this.ccount==4)
  898. {
  899. agenter.dateGameTimes4+=1;
  900. }
  901. agenter.dateGameCost4+=gameCost2;
  902. }
  903. else if(this.round == 8){
  904. if(this.ccount==2)
  905. {
  906. agenter.dateGameTimes82+=1;
  907. }
  908. else if(this.ccount==3)
  909. {
  910. agenter.dateGameTimes83+=1;
  911. }
  912. else if(this.ccount==4)
  913. {
  914. agenter.dateGameTimes8+=1;
  915. }
  916. agenter.dateGameCost8+=gameCost2;
  917. }
  918. else if(this.round == 16){
  919. if(this.ccount==2)
  920. {
  921. agenter.dateGameTimes162+=1;
  922. }
  923. else if(this.ccount==3)
  924. {
  925. agenter.dateGameTimes163+=1;
  926. }
  927. else if(this.ccount==4)
  928. {
  929. agenter.dateGameTimes16+=1;
  930. }
  931. agenter.dateGameCost16+=gameCost2;
  932. }
  933. }
  934. let rCount=agenter.rebateCount;
  935. let rOther=agenter.rebateOther;
  936. let rAll=agenter.rebateAll;
  937. let rNow=agenter.rebateNow;
  938. let rOut=agenter.rebateOut;
  939. let rVerifyDate=agenter.verifyDate;
  940. let rVerifyRebate=agenter.verifyRebate;
  941. yield agenter.saveAsync();
  942. // console.warn("代理返利写分+++++agenter.saveAsync()");
  943. // 锁定返利记录
  944. if(verifyBool && verifyRebate>0)
  945. {
  946. var verifyrebateRecord = new this.app.models.RebateRecord({
  947. _id: uuid.v1(),
  948. agentId:this.agentId,
  949. tableId: '',
  950. rType: 3,
  951. rCount: rCount- agentRebate2,
  952. rOther: rOther,
  953. rAll: rAll- agentRebate2,
  954. rNow: rNow,
  955. rOut: rOut,
  956. rSwap: verifyRebate,
  957. rDateSwap: dateRebate,
  958. rVerifyDate: verifyDate,
  959. rVerifyRebate: 0
  960. });
  961. yield verifyrebateRecord.saveAsync();
  962. var daterebateRecord = new this.app.models.DateRebateRecord({
  963. _id: uuid.v1(),
  964. agentId:this.agentId,
  965. verifyDate: verifyDate,
  966. verifyRebate: verifyRebate,
  967. dateAgentRate: dateAgentRate,
  968. dateRebate: dateRebate,
  969. dateGameTimes0: dateGameTimes0,
  970. dateGameTimes4: dateGameTimes4,
  971. dateGameTimes8: dateGameTimes8,
  972. dateGameTimes16: dateGameTimes16,
  973. dateGameTimes02: dateGameTimes02,
  974. dateGameTimes42: dateGameTimes42,
  975. dateGameTimes82: dateGameTimes82,
  976. dateGameTimes162: dateGameTimes162,
  977. dateGameTimes03: dateGameTimes03,
  978. dateGameTimes43: dateGameTimes43,
  979. dateGameTimes83: dateGameTimes83,
  980. dateGameTimes163: dateGameTimes163,
  981. dateGameCost0: dateGameCost0,
  982. dateGameCost4: dateGameCost4,
  983. dateGameCost8: dateGameCost8,
  984. dateGameCost16: dateGameCost16
  985. });
  986. yield daterebateRecord.saveAsync();
  987. }
  988. // 返利记录
  989. var rebateRecord = new this.app.models.RebateRecord({
  990. _id: uuid.v1(),
  991. agentId:this.agentId,
  992. tableId: this.recordid,
  993. rType: 1,
  994. rCount: rCount,
  995. rOther: rOther,
  996. rAll: rAll,
  997. rNow: rNow,
  998. rOut: rOut,
  999. rSwap: agentRebate2,
  1000. rDateSwap: 0,
  1001. rVerifyDate: rVerifyDate,
  1002. rVerifyRebate: rVerifyRebate
  1003. });
  1004. yield rebateRecord.saveAsync();
  1005. // console.warn("返利记录+++++rebateRecord.saveAsync()");
  1006. }
  1007. }
  1008. let gameRebate=0;
  1009. if(this.isGameOk)
  1010. {
  1011. gameRebate=parseInt(this.cost*this.rEBATERATE);
  1012. }
  1013. var today = new Date();
  1014. today.setHours(0);
  1015. today.setMinutes(0);
  1016. today.setSeconds(0);
  1017. today.setMilliseconds(0);
  1018. let date=today.getTime();
  1019. let countid=this.agentId+'-'+user.userId+'-'+date;
  1020. var playercount = yield this.app.models.PlayerCount.findByIdAsync(countid,'gameCount gameCost agentRebate time');
  1021. if (playercount)
  1022. {
  1023. playercount.gameCount+=1;
  1024. playercount.gameCost+=this.cost;
  1025. playercount.agentRebate+=gameRebate;
  1026. playercount.time=Date.now();
  1027. }
  1028. else
  1029. {
  1030. playercount = new this.app.models.PlayerCount({
  1031. _id: countid,
  1032. agentId:this.agentId,
  1033. playerId: user.id,
  1034. userId: user.userId,
  1035. name: user.name,
  1036. date: date,
  1037. gameCount: 1,
  1038. gameCost: this.cost,
  1039. agentRebate: gameRebate,
  1040. time:Date.now()
  1041. });
  1042. }
  1043. yield playercount.saveAsync();
  1044. }
  1045. // console.warn("活动奖励 下面开始进行判断 ",user.spreadId,user.registerTime,user.lastLoginTime);
  1046. // let str11 = "hdjl xmksjxpd "+ this.id + " isGameOk: " + this.isGameOk + " userId: " + user.userId + " spreadId: " + user.spreadId + " registerTime: " + user.registerTime + " lastLoginTime: " + user.lastLoginTime ;
  1047. // logger.warn(str11);////cssj
  1048. // if(this.isGameOk && this.ccount == 4 && user.spreadId)//活动奖励
  1049. // {
  1050. // // console.warn("活动奖励 至此是游戏正常结束而且玩家有推荐id",user.spreadId,user.registerTime,user.lastLoginTime);
  1051. // ////正常结束而且该玩家有推荐人id
  1052. // let acSTime = 1601481600000;////20201001零点的时间戳,活动开始时间
  1053. // let acETime = acSTime + 86400000*8;////20201008这天截止的时间戳 活动结束时间
  1054. // let xzsjc = Date.now();
  1055. // let str12 = "hdjl zcyxszcjseqwjytjr "+this.id + " userId: " + user.userId +" xzsjc: "+xzsjc;
  1056. // logger.warn(str12);////cssj
  1057. // if(xzsjc >= acSTime && xzsjc < acETime){
  1058. // if((user.registerTime >= acSTime && user.registerTime < acETime) || user.lastLoginTime < 1598889600000){
  1059. // // console.warn("活动奖励 至此该玩家是新用户",user.spreadId,user.registerTime,user.lastLoginTime);
  1060. // let str13 = "hdjl zcgwjsxyh "+this.id + " userId: " + user.userId;
  1061. // logger.warn(str13);////cssj
  1062. // ////活动期间注册或者9月1号10月1日之间未登陆过的玩家
  1063. // var todayTL = new Date();
  1064. // todayTL.setHours(0);
  1065. // todayTL.setMinutes(0);
  1066. // todayTL.setSeconds(0);
  1067. // todayTL.setMilliseconds(0);
  1068. // let jrldsjc=todayTL.getTime();////今日零点时间戳
  1069. // let jrjssjc=jrldsjc + 86400000;////今日结束时间戳
  1070. // var opts = { stime: { $gte: jrldsjc, $lt: jrjssjc },type: { $gte: 1, $lt: 2 }};
  1071. // opts['sid'] = user.id;
  1072. // let acrlist = yield this.app.models.ActiveRewardRecord.findMongoAsync(opts, '_id rewardtype totalfee type sid rid gameCount stime succtime succState', { sort: { stime: 1 } });//
  1073. // if(acrlist.length == 0){
  1074. // // console.warn("活动奖励 活动期间今日该玩家产生新的记录",user.spreadId,user.registerTime,user.lastLoginTime);
  1075. // let str14 = "hdjl hdqjjrgwjcsxdjl "+this.id + " userId: " + user.userId;
  1076. // logger.warn(str14);////cssj
  1077. // ////活动期间今日该玩家产生新的记录
  1078. // var activerewardrec = new this.app.models.ActiveRewardRecord({
  1079. // _id: uuid.v1(), // UUID
  1080. // rewardtype: 0, // 奖励类型,0红包
  1081. // totalfee: 0, // 产生金额,红包为分
  1082. // type:1, //活动类型:1国庆签到2国庆邀请
  1083. // sid: user.id, // 产生奖励的玩家id
  1084. // sname:user.name, // 产生奖励的玩家name
  1085. // suid:user.userId, // 产生奖励的玩家userId
  1086. // rid: user.id, // 此条奖励的受益玩家
  1087. // gameCount: 1, // 游戏局数
  1088. // stime: xzsjc, // 记录产生时间
  1089. // succtime: 0, // 任务完成时间,任务未完成的时候这里是0
  1090. // succState: 0 // 任务是否完成的状态,0:未完成1:已达成
  1091. // });
  1092. // yield activerewardrec.saveAsync();
  1093. // }
  1094. // else{
  1095. // let str15 = "hdjl hdqjjrgwjyjcsgjl "+this.id + " userId: " + user.userId;
  1096. // logger.warn(str15);////cssj
  1097. // ////活动期间更新今日该玩家已经产生的记录
  1098. // let newre = acrlist[0];
  1099. // newre.gameCount++;
  1100. // if(newre.gameCount >= 2){
  1101. // // console.warn("活动奖励 活动期间更新今日该玩家已经产生的记录",user.spreadId,user.registerTime,user.lastLoginTime);
  1102. // let str16 = "hdjl hdqjgxjrgwjyjcsdjl "+this.id + " userId: " + user.userId + " gameCount: " + newre.gameCount;
  1103. // logger.warn(str16);////cssj
  1104. // ////完成为解散2局,该玩家完成了签到的任务了
  1105. // if(newre.gameCount == 2){
  1106. // newre.totalfee = 500;
  1107. // newre.succtime = xzsjc;
  1108. // newre.succState = 1;
  1109. // }
  1110. // yield newre.saveAsync();
  1111. // }
  1112. // if(newre.gameCount == 2){
  1113. // var opts2 = { stime: { $gte: acSTime, $lt: acETime },type: { $gte: 2, $lt: 3 }};
  1114. // opts2['sid'] = user.id;
  1115. // let acrlist2 = yield this.app.models.ActiveRewardRecord.findMongoAsync(opts2, 'rid', { sort: { stime: 1 } });//
  1116. // let isneedcj = false;////是否需要创建邀请奖励产生记录
  1117. // if(acrlist2.length == 0){
  1118. // isneedcj = true;
  1119. // // if(parseInt(acrlist2[0].rid) && parseInt(acrlist2[0].rid) == user.spreadId) isneedcj = true;
  1120. // }
  1121. // // console.warn("活动奖励 完成未解散2局,该玩家的推荐人完成了邀请的任务了",user.spreadId,user.registerTime,user.lastLoginTime);
  1122. // let str17 = "hdjl csgwjdyqjl "+this.id + " userId: " + user.userId + " isneedcj: " + isneedcj;
  1123. // logger.warn(str17);////cssj
  1124. // if(isneedcj){
  1125. // ////完成为解散2局,该玩家的推荐人完成了邀请的任务了
  1126. // var activerewardrec = new this.app.models.ActiveRewardRecord({
  1127. // _id: uuid.v1(), // UUID
  1128. // rewardtype: 0, // 奖励类型,0红包
  1129. // totalfee: 500, // 产生金额,红包为分
  1130. // type:2, //活动类型:1国庆签到2国庆邀请
  1131. // sid: user.id, // 产生奖励的玩家id
  1132. // suid:user.userId, // 产生奖励的玩家userId
  1133. // sname:user.name, // 产生奖励的玩家name
  1134. // rid: user.spreadId,// 此条奖励的受益玩家
  1135. // gameCount: newre.gameCount, // 游戏局数
  1136. // stime: xzsjc, // 记录产生时间
  1137. // succtime: xzsjc, // 任务完成时间,任务未完成的时候这里是0
  1138. // succState: 1 // 任务是否完成的状态,0:未完成1:已达成
  1139. // });
  1140. // yield activerewardrec.saveAsync();
  1141. // }
  1142. // }
  1143. // }
  1144. // }
  1145. // }
  1146. // }
  1147. // let str4 = "table 222 站起桌子之后---id:%s"+this.id + " uid"+user.userId+" "+ this.state;
  1148. // logger.info(str4);////cssj
  1149. }
  1150. });
  1151. // 玩家断线
  1152. proto.offlineAsync = cor(function* (user) {
  1153. let str3 = "table 玩家断线.......id: "+ this.id + " user.chairId: " + user.chairId + " user.name: " + user.name ;
  1154. logger.warn(str3);////cssj
  1155. if (user.chairId != -1) {
  1156. //user.state = User.STATE.OFFLINE;//ts--
  1157. user.state2 = User.STATE.OFFLINE;//ts++
  1158. user.offlinetime = Date.now();//ts++断线
  1159. var channelId = 'xct:' + this.id;
  1160. yield this.app.controllers.push._quitAsync(channelId, user.id);
  1161. yield this.pushMsgAsync(-1, 'sxjiang_event', { type: M.STATE_CHANGE, data: { chairId: String(user.chairId), state: String(user.state2), state2: String(user.state2) } });
  1162. // 无人在线
  1163. // console.warn("提前结算666");
  1164. //if (this.isOffline()) return this.overTimeAsync(MODE.OFFLINE);
  1165. // console.warn("玩家断线-------定时器启动");
  1166. // 计时结算
  1167. if (!this.endTimer) this.endTimer = this.app.timer.setTimeout(() => this.overTimeAsync(ENDMODE.OFFLINEEND),1200000);/////断线3分钟自动结算
  1168. // let str4 = "table 玩家断线---id:"+this.id + ",uid"+user.userId+" "+ this.state;
  1169. // logger.info(str4);////cssj
  1170. }
  1171. });
  1172. // 离开桌子
  1173. proto.leaveAsync = cor(function* (user) {
  1174. let str3 = "table 离开桌子.......id: "+ this.id + " user.chairId: " + user.chairId + " user.name: " + user.name ;
  1175. logger.warn(str3);////cssj
  1176. // this.leavePlayerID = user.id;//////TL++,旁观为房主的话离开之后由于从观战者列表里面删除了,导致发消息的时候他收不到离开桌子的消息
  1177. // console.warn("离开桌子、、、、、、、");
  1178. yield this.beforeLeaveAsync(user);
  1179. var chairId = user.chairId;
  1180. // yield this.pushMsgAsync(-1, 'sxjiang_event', { type: M.LEAVE, data: { account: user.account } });/////TL++zs,原来在下面
  1181. if (chairId != -1) {
  1182. delete this.users[chairId];
  1183. delete this.handCards[chairId];
  1184. yield this.afterStandAsync(user, chairId);
  1185. } else {
  1186. let pos = _.findIndex(this.lookers, (u) => (u.id == user.id));
  1187. if (pos != -1) this.lookers.splice(pos, 1);
  1188. }
  1189. return this.afterLeaveAsync(user);
  1190. });
  1191. // 离开桌子之前
  1192. proto.beforeLeaveAsync = cor(function* (user) {
  1193. var channelId = 'xct:' + this.id;
  1194. return this.app.controllers.push._quitAsync(channelId, user.id);
  1195. });
  1196. // 离开桌子之后
  1197. proto.afterLeaveAsync = cor(function* (user) {
  1198. // 离开通知
  1199. /////TL++zsyl 在此之前离开玩家已经从玩家列表或者旁观者列表中删除了所以把下面这句提到前面去了
  1200. return this.pushMsgAsync(-1, 'sxjiang_event', { type: M.LEAVE, data: { account: user.account } });
  1201. });
  1202. // 玩家准备
  1203. proto.readyGameAsync = cor(function* (user) {
  1204. let str3 = "table 玩家准备.......id: "+ this.id + " user.chairId: " + user.chairId + " this.over: " + this.over + " user.name: " + user.name ;
  1205. logger.warn(str3);////cssj
  1206. // let str3 = "table 玩家准备---id:"+this.id + ",uid"+user.userId+","+ this.state;
  1207. // logger.info(str3);////cssj
  1208. if(this.state==STATE.FREE2)//ts++二次空闲
  1209. {
  1210. user.state2 = User.STATE.READY;
  1211. yield this.pushMsgAsync(-1, 'sxjiang_event', { type: M.STATE_CHANGE, data: { chairId: String(user.chairId), state: String(user.state2), state2: String(user.state2) } });
  1212. if (this.isReady2() && !this.isGameOk) yield this.startGameAsync();
  1213. }
  1214. else
  1215. {
  1216. user.state = User.STATE.READY;
  1217. user.state2 = User.STATE.READY;
  1218. yield this.pushMsgAsync(-1, 'sxjiang_event', { type: M.STATE_CHANGE, data: { chairId: String(user.chairId), state: String(user.state2), state2: String(user.state2) } });
  1219. // console.warn("玩家准备玩家准备玩家准备 ",this.isReady() ,this.isGameOver());
  1220. if (this.isReady() && !this.isGameOk) yield this.startGameAsync();
  1221. }
  1222. // let str4 = "table 222玩家准备---id:"+this.id + ",uid"+user.userId+","+ this.state;
  1223. // logger.info(str4);////cssj
  1224. return { code: C.OK };
  1225. });
  1226. // 开始游戏
  1227. proto.startGameAsync = cor(function* () {
  1228. //this.backStartTimer = null;//////重入之后系统会自动准备为了解决可能没牌的问题2秒之后才开始游戏
  1229. let str4 = "table 开始游戏---id:"+this.id +" ,state "+ this.state +" 当前局 "+ (this.over+1);
  1230. logger.warn(str4);////cssj
  1231. if(this.isYJKSGL){
  1232. return;
  1233. }
  1234. this.isYJKSGL = true;/////是否已经执行过开始函数了
  1235. this.isYJJSGL = false;/////是否已经执行过结算函数了
  1236. if(this.backStartTimer)
  1237. {
  1238. clearTimeout(this.backStartTimer);
  1239. this.backStartTimer = null;
  1240. }
  1241. // 状态设置
  1242. this.state = STATE.PLAYING;
  1243. //this.setUserState(-1, User.STATE.PLAYING);//ts--
  1244. //ts++设置为游戏状态
  1245. for (let user of this.users)
  1246. {
  1247. if (user) {
  1248. if(user.state == User.STATE.PLAYING)//ts++已经开始
  1249. {
  1250. if(user.state2 == User.STATE.READY)
  1251. {
  1252. user.state2 = User.STATE.PLAYING
  1253. user.offlinetime = 0;
  1254. }
  1255. }
  1256. else//ts++第一次开始
  1257. {
  1258. user.state = User.STATE.PLAYING
  1259. user.state2 = User.STATE.PLAYING
  1260. user.offlinetime = 0;
  1261. }
  1262. }
  1263. }
  1264. //ts++end
  1265. let whdata = yield this.app.models.WHstate.findByIdReadOnlyAsync('wh', 'rebaterate');
  1266. // console.warn("22检查是否维护状态",whdata);
  1267. if (whdata) {
  1268. if(whdata.rebaterate || whdata.rebaterate == 0){///
  1269. /////维护状态中
  1270. this.rEBATERATE= 1;//业绩模式必须为100%//whdata.rebaterate / 100;
  1271. }
  1272. else{
  1273. let whdata2 = yield this.app.models.WHstate.findByIdAsync('wh', 'rebaterate');
  1274. if (whdata2) {
  1275. whdata2.rebaterate = 100;
  1276. yield whdata2.saveAsync();
  1277. this.rEBATERATE= 1;//业绩模式必须为100%
  1278. }
  1279. }
  1280. }
  1281. this.PaijuHuiFang = [];////TL++,牌局回放 重置数据
  1282. this.lgkhCount = 0;/////TL++拉杠可胡玩家的数量
  1283. this.logic.isZHYZ = false;/////是不是最后1张
  1284. // this.logic.isNeedBuHua = false/////TL++在游戏开始的时候初始化是否需要补花
  1285. // this.isLianGang = [-1,false,-1];/////TL++,连杠的玩家座位号,是否连杠 在游戏开始的时候清空
  1286. // 初始信息
  1287. if (this.over <= 0) {///////本房间开始的第一局游戏
  1288. this.stime = Date.now();
  1289. // this.chBanker = this.ownerChairid;///////TL++zsyl
  1290. this.chBanker = 0;
  1291. //this.game.cancelDelete(this.id);//////TL++游戏第一次开始时候关闭房间20分钟未开始删除桌子
  1292. this.pjhffileName[this.pjhffileName.length] = this.PJHF.getjsonFileName(0,this.recordid,this.ctime);/////TL++,用于记录玩家牌局回放的json文件名
  1293. // console.error("000HHHHHHHHHHHHHHHHHHHHHH",this.pjhffileName.length,this.pjhffileName);
  1294. this.PJHF.writePJHFJson(this.getTableInfo(),0,this.id);////在开始第一局的时候将桌子信息写入本地的json文件
  1295. this.isNeverStart = false;/////TL++,游戏是否从未开始
  1296. // yield this.randomChangeChairTL()/////TL++,在首次游戏的时候随机打乱用户的座位
  1297. }
  1298. this.gameNeverStart = false;/////TL++,游戏是否从未开始过,用于解散房间判断
  1299. this.currentId = this.chBanker;
  1300. this.isDihus[this.chBanker] = false;
  1301. // 发手牌 把这句提前是为了洗牌之后能拿到百搭牌在游戏开始的时候给客户端发过去
  1302. let dice1 = this.logic.dice();/////骰子1的点数
  1303. let dice2 = this.logic.dice();/////骰子2的点数
  1304. var handCards = this.logic.handCards(this.chBanker,this.PJHF,this.over,this.recordid,this.ctime);
  1305. if(this.playerAllCount == 4){
  1306. if(this.chBanker == 0) this.logic.isMZWF = [0,1,2,3];/////是不是满足位风
  1307. else if(this.chBanker == 1) this.logic.isMZWF = [3,0,1,2];/////是不是满足位风
  1308. else if(this.chBanker == 2) this.logic.isMZWF = [2,3,0,1];/////是不是满足位风
  1309. else if(this.chBanker == 3) this.logic.isMZWF = [1,2,3,0];/////是不是满足位风
  1310. }
  1311. // }
  1312. else if(this.playerAllCount == 3){
  1313. if(this.chBanker == 0) this.logic.isMZWF = [0,1,2,8];/////是不是满足位风
  1314. else if(this.chBanker == 1) this.logic.isMZWF = [3,0,1,8];/////是不是满足位风
  1315. else if(this.chBanker == 2) this.logic.isMZWF = [2,3,0,8];/////是不是满足位风
  1316. }
  1317. else if(this.playerAllCount == 2){
  1318. if(this.chBanker == 0) this.logic.isMZWF = [0,2,8,8];/////是不是满足位风
  1319. else if(this.chBanker == 1) this.logic.isMZWF = [2,0,8,8];/////是不是满足位风
  1320. }
  1321. //console.warn("ccccccccccccccccccccc当局的圈风",this.logic.fengQuan,this.chBanker);
  1322. let scoreListTL = []
  1323. for (let i = 0; i < this.users.length; ++i) {
  1324. let user = this.users[i];
  1325. if (user) {
  1326. let score = this.score.getScore(user.id);
  1327. scoreListTL[i] = score
  1328. }
  1329. }
  1330. // 掷骰子
  1331. var sttGame = {
  1332. banker: String(this.chBanker),
  1333. qFeng: String(this.quFeng),
  1334. stime: String(Date.now() - this.stime),
  1335. baiDaCard: String(this.logic.baiDaCard),//////TL++,本局百搭牌
  1336. startNum1: String(dice1),////骰子点数
  1337. startNum2: String(dice2),////骰子点数
  1338. setCardFileName: String(this.logic.setCardFileName),////TL++设置手牌的文件名
  1339. scoreListTL:scoreListTL,/////TL++,每个玩家当前的分数列表
  1340. };
  1341. // console.warn("游侠开始*******************this.chBanker",this.chBanker);
  1342. this.setPaijuHuiFangData(M.START_GAME,sttGame);/////TL++ 牌局回放 push游戏开始
  1343. // 开始通知
  1344. yield this.pushMsgAsync(-1, 'sxjiang_event', { type: M.START_GAME, data: sttGame });
  1345. ////// 发手牌原来在这里
  1346. var lastCount = this.logic.leaveCount();/////TL++
  1347. for (let i = 0; i < handCards.length; ++i) {
  1348. this.handCards[i] = handCards[i].cards;/////TL++zsyl
  1349. if (i == this.chBanker) {
  1350. let __isHu = false;
  1351. let length = this.handCards[i].length;
  1352. this.logic.isLaGang = false;//////TL++,是否刚刚被拉杠用于判断是否被拉杠胡
  1353. // this.logic.chengBaoTL = [[],[],[],[]];
  1354. // console.error("sscc3333胡牌分析 游戏开始i",i);
  1355. let huRes = this.logic.huAnalyze(i,this.handCards[i], this.handCards[i][length - 1], this.huCards[i], true);
  1356. // console.error("ssccDDD胡牌分析 huRes",huRes);
  1357. if (huRes) {
  1358. // let str3a = "table fpphcg:"+this.id + ",uid"+this.handCards[i];
  1359. // logger.info(str3a);////cssj
  1360. __isHu = true;
  1361. this.huRes[i] = huRes;
  1362. }
  1363. let res = this.logic.anGangAnalyze(this.handCards[i]);
  1364. let isGang = (res.length > 0);
  1365. if (isGang) this.masks[i] |= 8;
  1366. if (__isHu) this.masks[i] |= 16;
  1367. }
  1368. let scards = {
  1369. mask: String(this.masks[i]),
  1370. cards: handCards[i].cards,
  1371. lastCount: String(lastCount)
  1372. };
  1373. ////发牌的胡牌提示
  1374. if (i == this.chBanker) {
  1375. ////游戏开始时候的庄家的胡牌提示
  1376. scards.hutipdata = this.logic.hutip(this.chBanker,handCards[i].cards,this.huCards[i],this.huCards,this.outCards);////起手发牌调用胡牌提示
  1377. }
  1378. else{
  1379. ////游戏开始时候的闲家的胡牌提示
  1380. scards.hutipdata = {
  1381. renyi:0,//////是否可胡任意牌,0表示不满足1表示满足
  1382. kehuData:[]/////对象数组,分别表示打哪张可胡哪几张数据
  1383. };
  1384. }
  1385. // 发牌通知
  1386. // console.error("sscc发牌通知 4条应该=================",i,handCards.lengt);
  1387. yield this.pushMsgAsync(i, 'sxjiang_event', { type: M.SEND_CARD, data: scards });
  1388. }
  1389. let pjhfsplist = {
  1390. shouPai:this.logic.deepCloneTL(this.handCards),
  1391. maskList:this.logic.deepCloneTL(this.masks),/////TL++,10月28号,为了实现能看到每个玩家的操作
  1392. lastCount:String(this.logic.leaveCount())
  1393. }
  1394. this.setPaijuHuiFangData(M.SEND_CARD,pjhfsplist);/////TL++ 牌局回放 push发牌数据
  1395. // 围观通知
  1396. var cardCounts = _.fill(Array(this.ccount), 0);
  1397. for (let i = 0; i < cardCounts.length; ++i) {
  1398. cardCounts[i] = this.handCards[i].length;
  1399. }
  1400. yield this.lookMsgAsync('sxjiang_event', { type: M.SEND_CARD, data: { cardCounts: cardCounts, lastCount: String(lastCount) } });
  1401. let str3 = "table 222开始游戏---id:"+this.id +","+ this.state;
  1402. logger.warn(str3);////cssj
  1403. return { code: C.OK };
  1404. });
  1405. // 出牌
  1406. proto.outCardAsync = cor(function* (chairId, card) {
  1407. let str3 = "table 出牌---id:"+this.id + " ,uid "+chairId+" this.masks "+ this.masks +" card "+card;
  1408. logger.warn(str3);////cssj
  1409. // console.warn("出牌出剖出牌",chairId,this.buhuaTimeout);///// 您正在补花,请稍后出牌。/////TL++,正在补花的时候不允许玩家出牌
  1410. // if(this.buhuaTimeout) return { code: C.FAILD, msg: C.GAME_BUHUA_ING };
  1411. // 校验顺序
  1412. if (this.currentId != chairId) {
  1413. return { code: C.FAILD, msg: C.TABLE_TURN_ERROR };
  1414. }
  1415. this.logic.chuPaiTL()////TL++,统计出牌个数,为了判断天胡和地胡
  1416. // 吃椪杠胡
  1417. var pos = _.findIndex(this.masks, (m, i) => (i != chairId && m > 0));
  1418. if (pos != -1) {
  1419. return { code: C.FAILD, msg: C.TABLE_TURN_ERROR };
  1420. }
  1421. // 删除手牌
  1422. if (!this.logic.remove(this.handCards[chairId], card)) {
  1423. return { code: C.FAILD, msg: C.TABLE_CARD_ERROR };
  1424. }
  1425. if (this.masks[chairId] & 16){
  1426. this.logic.isGuoHuList[chairId][0] = true;/////TL++,设置过胡玩家的是否点击过胡为true 出牌
  1427. let guohudataTL = {
  1428. chairId:chairId,
  1429. msg: "下次摸牌之前将不能胡牌", /////过胡通知
  1430. }
  1431. let isGuoHuList = [[false,0],[false,0],[false,0],[false,0],];
  1432. isGuoHuList[chairId] = this.logic.isGuoHuList[chairId];
  1433. guohudataTL.isGuoHuList = isGuoHuList;
  1434. ////过胡通知
  1435. yield this.pushMsgAsync(chairId, 'sxjiang_event', { type: M.FHGUOHUTIP, data: guohudataTL });
  1436. this.logic.isLaGang = false;//////TL++,是否刚刚被拉杠用于判断是否被拉杠胡
  1437. }
  1438. // 置空权限
  1439. if (this.masks[chairId] > 0) this.masks[chairId] = 0;
  1440. // 置灰的牌
  1441. this.disCards = [];
  1442. // 调整手牌
  1443. this.logic.adjust(this.handCards[chairId]);
  1444. this.outCard = card;
  1445. this.outerId = chairId;
  1446. this.outCards[chairId].push(card);
  1447. // 天胡地胡
  1448. if (this.isTianhu) this.isTianhu = false;
  1449. if (this.isDihus[chairId]) this.isDihus[chairId] = false;
  1450. // 忽略牌
  1451. this.excepts[chairId] = {};
  1452. let sfyrkh = false;//////TL++,是否有人可胡,没有的话海底捞月之后直接结算
  1453. let pjhfsplist = {};
  1454. // 吃碰杠胡
  1455. for (let i = 0; i < this.ccount; ++i) {
  1456. let ocard = { chairId: String(chairId), card: String(card) };
  1457. // 排除自己
  1458. if (i != chairId) {
  1459. ocard.isGuoHuList = [[false,0],[false,0],[false,0],[false,0],]
  1460. let _isChi = false;
  1461. let isPeng = false;
  1462. let isGang = false;
  1463. let __isHu = false;
  1464. do {
  1465. // 检测吃牌
  1466. if (this.hasEat && i == (chairId + 1) % this.ccount && (!this.isZNZM)) {//// 以前是否可吃为可选项 只能自摸情况下不能吃
  1467. let ress = this.logic.chiAnalyze(this.handCards[i], card);
  1468. _isChi = (ress.length > 0);
  1469. }
  1470. // 忽略牌
  1471. if (this.excepts[i][card]) break;/////TL++zsyl.同一圈过碰之后不能再次碰的
  1472. // 检测碰牌
  1473. isPeng = this.logic.isPeng(this.handCards[i], card);
  1474. // 忽略牌
  1475. // if (this.excepts[i][card]) break;/////TL++.为了解决同一圈过碰之后不能再次碰的问题
  1476. let res = this.logic.gangAnalyze(this.handCards[i], card);
  1477. isGang = !!res;
  1478. this.logic.isLaGang = false;//////TL++,是否刚刚被拉杠用于判断是否被拉杠胡
  1479. let huRes = (!this.isZNZM) ? this.logic.huAnalyze(i,this.handCards[i], card, this.huCards[i]) : undefined;
  1480. // console.error("ssccAAA胡牌分析 huRes",huRes);
  1481. if (huRes) {
  1482. // let str3a = "table cpphcg:"+this.id + ",uid"+this.handCards[i];
  1483. // logger.info(str3a);////cssj
  1484. __isHu = true;
  1485. this.huRes[i] = huRes;
  1486. }
  1487. } while (0);
  1488. /////TL++,整个if
  1489. if(this.logic.leaveCount() == 0 && this.logic.isZHYZ){
  1490. if (_isChi) _isChi = false;
  1491. if (isPeng) isPeng = false;
  1492. if (isGang) isGang = false;
  1493. if(__isHu) sfyrkh = true
  1494. }
  1495. // 权限掩码
  1496. if (_isChi) this.masks[i] |= 2;
  1497. if (isPeng) this.masks[i] |= 4;
  1498. if (isGang) this.masks[i] |= 8;
  1499. if (__isHu) this.masks[i] |= 16;
  1500. }
  1501. else{
  1502. let isGuoHuList = [[false,0],[false,0],[false,0],[false,0],];
  1503. isGuoHuList[chairId] = this.logic.isGuoHuList[chairId];
  1504. ocard.isGuoHuList = isGuoHuList;
  1505. }
  1506. ocard.mask = String(this.masks[i]);
  1507. // 出牌通知
  1508. yield this.pushMsgAsync(i, 'sxjiang_event', { type: M.OUT_CARD, data: ocard });
  1509. if (i == chairId) {
  1510. // let pjhfcp = ocard
  1511. // pjhfcp.allMask = this.masks;
  1512. pjhfsplist = {
  1513. shouPai:this.logic.deepCloneTL(this.handCards),
  1514. lastCount:String(this.logic.leaveCount()),
  1515. ocard:this.logic.deepCloneTL(ocard),
  1516. outCards:this.logic.deepCloneTL(this.outCards),
  1517. isGuoHuList:this.logic.deepCloneTL(this.logic.isGuoHuList)
  1518. }
  1519. }
  1520. if(i == (this.ccount - 1)){/////TL++if条件判断,10月28号,为了实现能看到每个玩家的操作
  1521. pjhfsplist.maskList = this.logic.deepCloneTL(this.masks);/////TL++,10月28号,为了实现能看到每个玩家的操作
  1522. this.setPaijuHuiFangData(M.OUT_CARD,pjhfsplist);/////TL++ 牌局回放 push出牌数据
  1523. }
  1524. }
  1525. // 被杠玩家
  1526. this.gangOuter = -1;
  1527. // 围观通知
  1528. yield this.lookMsgAsync('sxjiang_event', { type: M.OUT_CARD, data: { chairId: String(chairId), card: String(card) } });
  1529. // 全无权限
  1530. for (let i = 0; i < this.ccount; ++i) {
  1531. if (this.masks[i] != 0) break;
  1532. // 切换用户
  1533. if (i == this.ccount - 1) {
  1534. // 下家摸牌
  1535. let nextId = (chairId + 1) % this.ccount;
  1536. ///////TL++,整个if,因为海底捞月需要玩家自己去判断要不要摸牌
  1537. // console.warn("000 声剩余声剩余声剩");
  1538. let lastCount = this.logic.leaveCount();/////TL++xg
  1539. this.touchCardAsync(nextId); ///////出牌摸牌
  1540. }
  1541. }
  1542. let str4 = "table end出牌---id:"+this.id + " ,uid "+chairId+" this.masks "+ this.masks +" card "+card;
  1543. logger.warn(str4);////cssj
  1544. return { code: C.OK };
  1545. });
  1546. ///////摸牌函数 参数ifGang是否因为杠而摸牌 TL++ 参数isBHMP 是否补花摸牌,为了判断是否花杠杠开 是否最后一张的海底捞月
  1547. proto.touchCardAsync = cor(function* (chairId,ifGang,isBHMP,ishdly) {
  1548. // console.warn("这不会死循环吧",chairId,isBHMP,this.buhuaTimeout);
  1549. // if(this.buhuaTimeout) {
  1550. // clearTimeout(this.buhuaTimeout);
  1551. // this.buhuaTimeout = null;
  1552. // }
  1553. // 状态校验
  1554. if (this.state != STATE.PLAYING) return;
  1555. if (this.winner.chs.length > 0 || !this.users[chairId]) return;
  1556. if(this.logic.isGuoHuList[chairId][0]) this.logic.isGuoHuList[chairId][0] = false;/////TL++,设置过胡玩家的是否点击过胡为false; 摸牌
  1557. // 当前顺序
  1558. this.currentId = chairId;
  1559. // 摸牌
  1560. // var moCard = this.logic.moCard();TL++zsyl
  1561. ////TL++
  1562. var moCard = { card: 0 };
  1563. // if(isBHMP) moCard.card = this.logic.buHuaMoDePai;//////TL++,补花摸上的牌
  1564. // else {
  1565. let isG = (ifGang && (ifGang == 1) || (ifGang == 2) || (ifGang == 3))
  1566. // console.warn("<<<<<<<<<",isG,ifGang)
  1567. moCard = this.logic.moCard(isG);
  1568. this.logic.moPaiTL();
  1569. // }
  1570. let moPaiIsCanHu = false;//////TL++,摸牌的人是否可以胡牌
  1571. // 是否流局
  1572. if (moCard.card <= 0) {
  1573. // console.warn("提前结算888");
  1574. yield this.concludeGameAsync(MODE.NOCARD);
  1575. return { code: C.OK };
  1576. }
  1577. let lastCount22 = this.logic.leaveCount();/////TL++xg
  1578. let pjhfsplist = {};
  1579. for (let i = 0; i < this.ccount; ++i) {
  1580. let touchCard = { currentId: String(chairId), touch: '0',lastCount : '0' };
  1581. // console.warn("1111WWWWWWWTTTTTT",i,chairId,moCard.card);
  1582. if (i == chairId) {
  1583. touchCard.touch = String(moCard.card);
  1584. // this.handCards[i].push(moCard.card);/////TL++zsyl
  1585. if(!isBHMP) this.handCards[i].push(moCard.card);/////TL++,因为在补花的时候已经将新发的牌放进手牌里了所以这里不用push
  1586. let __isHu = false;
  1587. // console.error("sscc111胡牌分析 摸牌 i",i);
  1588. this.logic.isLaGang = false;//////TL++,是否刚刚被拉杠用于判断是否被拉杠胡
  1589. // this.logic.chengBaoTL = [[],[],[],[]];////别人放弃拉杠之后还没想好要怎么清空,因为不清空也行
  1590. // console.warn("222摸牌的时候设置刚才是否有杠",i,ifGang,this.logic.isGGMG,this.logic.isGGAG,this.logic.isGGFXG);
  1591. let huRes = this.logic.huAnalyze(i,this.handCards[i], moCard.card, this.huCards[i], true);
  1592. // console.error("ssccBBB胡牌分析 huRes",huRes);
  1593. if (huRes) {
  1594. // let str3a = "table mpphcg:"+this.id + ",uid"+this.handCards[i];
  1595. // logger.info(str3a);////cssj
  1596. __isHu = true;
  1597. moPaiIsCanHu = true;/////TL++
  1598. this.huRes[i] = huRes;
  1599. }
  1600. let res = this.logic.anGangAnalyze(this.handCards[i]);
  1601. let isGang = (res.length > 0);
  1602. if (!isGang) {
  1603. res = this.logic.zmGangAnalyze(this.handCards[i], this.huCards[i]);
  1604. isGang = (res.length > 0);
  1605. }
  1606. if (isGang) this.masks[i] |= 8;
  1607. if (__isHu) this.masks[i] |= 16;
  1608. ////摸排时候的摸排玩家的胡牌提示
  1609. let hutipdataTL = this.logic.hutip(i,this.handCards[i],this.huCards[i],this.huCards,this.outCards);////摸牌时调用胡牌提示
  1610. touchCard.hutipdata = hutipdataTL;
  1611. let isGuoHuList = [[false,0],[false,0],[false,0],[false,0],];
  1612. isGuoHuList[chairId] = this.logic.isGuoHuList[chairId];
  1613. touchCard.isGuoHuList = isGuoHuList;
  1614. }
  1615. else {
  1616. this.masks[i] = 0;
  1617. touchCard.hutipdata = {
  1618. renyi:0,//////是否可胡任意牌,0表示不满足1表示满足
  1619. kehuData:[]/////对象数组,分别表示打哪张可胡哪几张数据
  1620. };
  1621. touchCard.isGuoHuList = [[false,0],[false,0],[false,0],[false,0],]
  1622. }
  1623. touchCard.mask = String(this.masks[i]);
  1624. touchCard.lastCount = String(lastCount22);
  1625. this.logic.lastMoPaiChairID = this.currentId;
  1626. // 摸牌通知
  1627. // console.warn("222WWWWWWWTTTTTT",i,chairId,moCard.card);
  1628. yield this.pushMsgAsync(i, 'sxjiang_event', { type: M.TOUCH_CARD, data: touchCard});
  1629. if (i == chairId) {
  1630. pjhfsplist = {
  1631. shouPai:this.logic.deepCloneTL(this.handCards),
  1632. lastCount:String(this.logic.leaveCount()),
  1633. touchCard:this.logic.deepCloneTL(touchCard),
  1634. outCards:this.logic.deepCloneTL(this.outCards),
  1635. isGuoHuList:this.logic.deepCloneTL(this.logic.isGuoHuList)
  1636. }
  1637. }
  1638. if(i == (this.ccount - 1)){/////TL++if条件判断,10月28号,为了实现能看到每个玩家的操作
  1639. pjhfsplist.maskList = this.logic.deepCloneTL(this.masks);/////TL++,10月28号,为了实现能看到每个玩家的操作
  1640. this.setPaijuHuiFangData(M.TOUCH_CARD,pjhfsplist);/////TL++ 牌局回放 push摸牌数据
  1641. }
  1642. }
  1643. let str3 = "table 摸牌函数id:"+this.id + " ,uid "+chairId+" ,this.masks "+ this.masks +" card "+moCard.card;
  1644. logger.warn(str3);////cssj
  1645. // 围观通知
  1646. return this.lookMsgAsync('sxjiang_event', { type: M.TOUCH_CARD, data: { currentId: String(chairId),lastCount:String(lastCount22)} });
  1647. });
  1648. // 放弃操作
  1649. proto.giveUpAsync = cor(function* (chairId) {
  1650. let str3 = "table 放弃操作id: "+this.id + " ,uid "+chairId+", this.masks "+ this.masks;
  1651. logger.warn(str3);////cssj
  1652. // 权限掩码
  1653. var mask = this.masks[chairId];
  1654. if (mask <= 0) {
  1655. return { code: C.FAILD, msg: C.TABLE_MASK_ERROR };
  1656. }
  1657. // console.warn("111放弃操作放弃操作放弃操作放弃操作放弃操作chairId,this.masks",chairId,this.masks,(mask & 16));
  1658. if (mask & 16) {////mask = 16~31时结果=16这个if能进去 0~15或者32~47之间结果=0这个if进不去
  1659. // console.warn("放弃操作里设置过胡为true",chairId, this.logic.isLaGang,this.logic.isGuoHuList,this.logic.everyAllTaiShu);
  1660. this.logic.isGuoHuList[chairId][0] = true;/////TL++,设置过胡玩家的是否点击过胡为true 点击过按钮
  1661. let guohudataTL = {
  1662. chairId:chairId,
  1663. msg: "下次摸牌之前将不能胡牌", /////过胡通知
  1664. }
  1665. let isGuoHuList = [[false,0],[false,0],[false,0],[false,0],];
  1666. isGuoHuList[chairId] = this.logic.isGuoHuList[chairId];
  1667. guohudataTL.isGuoHuList = isGuoHuList;
  1668. //////过胡通知
  1669. yield this.pushMsgAsync(chairId, 'sxjiang_event', { type: M.FHGUOHUTIP, data: guohudataTL });
  1670. if(this.logic.leaveCount() > 0){/////TL++
  1671. this.lgkhCount -= 1;/////TL++拉杠可胡玩家的数量
  1672. }
  1673. // console.warn("666拉杠胡%%%%%%%%%%%%%%%%%%%%%%",this.logic.isLaGang);
  1674. }
  1675. // 删除权限
  1676. this.masks[chairId] = 0;
  1677. // 是否自摸
  1678. if (this.currentId == chairId) {
  1679. return { code: C.OK };
  1680. }
  1681. // 忽略牌
  1682. if (this.outCard) {
  1683. let except = this.excepts[chairId];
  1684. except[this.outCard] = this.outCard;
  1685. }
  1686. // 放弃胡牌
  1687. if (mask & 16) {////mask = 16~31时结果=16这个if能进去 0~15或者32~47之间结果=0这个if进不去
  1688. this.logic.isGuoHuList[chairId][0] = true;/////TL++,设置过胡玩家的是否点击过胡为true 点击过按钮(这句没啥用,在这个函数开始的时候设置过了)
  1689. // console.warn("放弃操作里设置过胡为true",chairId, this.isGangHu,this.logic.isGuoHuList);
  1690. let winner = this.winner;
  1691. do {
  1692. // 一炮多响
  1693. if (this.isMHu) {
  1694. let __cHu = _.findIndex(this.masks, (m) => (m & 16));//////
  1695. // console.warn("允许一炮多想 放弃操作放弃操作放弃操作this.isMHu,__cHu",this.isGangHu,this.isMHu,__cHu);
  1696. if (__cHu != -1) break;
  1697. // 有人胡牌
  1698. if (winner.chs.length > 0) {
  1699. // console.warn("允许一炮多想 操作放弃操作放弃操作winner.chs",winner.chs);
  1700. yield this.pushMsgAsync(-1, 'sxjiang_event', { type: M.HU, data: { lead: String(winner.lead), chairIds: winner.chs } });
  1701. // console.warn("提前结算1111");
  1702. yield this.concludeGameAsync(MODE.NORMAL).then(() => ({ code: C.OK }));/////结算游戏
  1703. return { code: C.OK };
  1704. }
  1705. } else {///// 没炮多响
  1706. // console.warn("没炮多想 放弃操作放弃操作放弃操作winner.chs",this.isGangHu,winner.chs);
  1707. // 有人胡牌
  1708. if (winner.chs.length > 0) {
  1709. let dist = (winner.chs[0] - winner.lead + this.ccount) % this.ccount;
  1710. // let __cHu = _.findIndex(this.masks, (m, i) => (m & 16 && (i - winner.lead + this.ccount) % this.ccount < dist));////TL++,zsyl,
  1711. let __cHu = _.findIndex(this.masks, (m, i) => (m & 16));///TL++,以前是上面那句写法,有个问题:0打牌后1,2,3号玩家都能胡,1点胡2点过,3就没有机会选择是否胡牌
  1712. // console.warn("111没炮多想 放弃操作放弃操作放弃操作__cHu",__cHu);
  1713. if (__cHu != -1) break;
  1714. yield this.pushMsgAsync(-1, 'sxjiang_event', { type: M.HU, data: { lead: String(winner.lead), chairIds: winner.chs } });
  1715. // console.warn("提前结算2222");
  1716. yield this.concludeGameAsync(MODE.NORMAL).then(() => ({ code: C.OK }));/////结算游戏
  1717. return { code: C.OK };
  1718. } else {
  1719. let __cHu = _.findIndex(this.masks, (m) => (m & 16));
  1720. // console.warn("111没炮多想 放弃操作放弃操作放弃操作__cHu",__cHu);
  1721. if (__cHu != -1) break;
  1722. }
  1723. }
  1724. // 查找等待
  1725. let cGang = -1
  1726. let cPeng = -1;
  1727. let _cChi = -1;
  1728. // console.warn("这里是啥情况啊",this.masks);
  1729. for (let i = 0; i < this.masks.length; ++i) {
  1730. // if (i == this.currentId || i == chairId) continue;///////TL++zsyl 这种写法会导致拉杠胡的玩家点击过胡之后被拉杠胡的玩家杠不出来的问题
  1731. if (i == chairId) continue;//////TL++,为了解决拉杠胡的玩家点击过胡之后被拉杠胡的玩家杠不出来的问题
  1732. if (this.masks[i] == 9) {
  1733. cGang = i;
  1734. continue;
  1735. }
  1736. if (this.masks[i] == 5) {
  1737. cPeng = i;
  1738. continue;
  1739. }
  1740. if (this.masks[i] == 3) {
  1741. _cChi = i;
  1742. continue;
  1743. }
  1744. }
  1745. // console.warn("2222情况啊",cGang, this.gangType,this.gangCard);
  1746. // 杠碰吃
  1747. if (cGang != -1 && this.gangType > 0 && this.gangCard > 0) {
  1748. // console.warn("这里是放弃操作再次调用 杠 次");
  1749. return this.gangCardAsync(cGang, this.gangCard, this.gangType).then(() => ({ code: C.OK }));
  1750. } else if (cPeng != -1) {
  1751. return this.pengCardAsync(cPeng, this.outCard).then(() => ({ code: C.OK }));
  1752. } else if (_cChi != -1 && this._eatType > 0) {
  1753. return this.eatCardAsync(_cChi, this.outCard, this._eatType).then(() => ({ code: C.OK }));
  1754. }
  1755. } while (0);
  1756. }
  1757. // 放弃杠碰
  1758. if ((mask & 8) || (mask & 4)) {
  1759. let __cHu = _.findIndex(this.masks, (m) => (m & 16));
  1760. if (__cHu == -1) {
  1761. let _cChi = _.findIndex(this.masks, (m) => (m & 3));
  1762. if (_cChi != -1 && this._eatType > 0) {
  1763. return this.eatCardAsync(_cChi, this.outCard, this._eatType).then(() => ({ code: C.OK }));
  1764. }
  1765. }
  1766. }
  1767. // 全无权限
  1768. for (let i = 0; i < this.ccount; ++i) {
  1769. if (this.masks[i] != 0) break;
  1770. // 切换用户
  1771. if (i == this.ccount - 1) {
  1772. // 下家摸牌
  1773. let nextId = (this.currentId + 1) % this.ccount;
  1774. // return this.touchCardAsync(nextId).then(() => ({ code: C.OK }));//////放弃操作引起的摸牌 /////TL++zs
  1775. ///////TL++,整个if,因为海底捞月需要玩家自己去判断要不要摸牌
  1776. // console.warn("222 声剩余声剩余声剩");
  1777. let lastCount = this.logic.leaveCount();/////TL++xg
  1778. return this.touchCardAsync(nextId).then(() => ({ code: C.OK }));//////放弃操作引起的摸牌
  1779. }
  1780. }
  1781. return { code: C.OK };
  1782. });
  1783. // /////TL++,是否进行海底捞月的操作 处理前端海底捞月函数
  1784. proto.haiDiLaoYue = cor(function* (chairId,data) {
  1785. // console.warn("海底捞月海底捞月");
  1786. return { code: C.OK };
  1787. });
  1788. // 杠牌,1-普通杠, 2-暗杠, 3-自摸明杠
  1789. proto.gangCardAsync = cor(function* (chairId, card, type) {
  1790. let str3 = "table 杠牌,id: "+this.id + " ,uid "+chairId+", this.masks "+ this.masks +" ,card "+card;
  1791. logger.warn(str3);////cssj
  1792. // 参数校验
  1793. if (!type && (type < 1 || type > 3)) {
  1794. return { code: C.FAILD, msg: C.GAME_PARAM_ERROR };
  1795. }
  1796. if (type == 1 && card != this.outCard) {
  1797. return { code: C.FAILD, msg: C.GAME_PARAM_ERROR };
  1798. }
  1799. if (type > 1 && this.currentId != chairId) {
  1800. return { code: C.FAILD, msg: C.GAME_PARAM_ERROR };
  1801. }
  1802. if (!(this.masks[chairId] & 8)) {
  1803. return { code: C.FAILD, msg: C.TABLE_MASK_ERROR };
  1804. }
  1805. // 他人可胡
  1806. let __cHu = (type == 2) ? -1 : _.findIndex(this.masks, (m) => ((m & 16) && !(m & 8)));
  1807. // console.warn("111拉杠胡%%%%%%%%%%%%%%%%%%%%%%",__cHu,type);
  1808. if (__cHu == -1) {
  1809. let res = null;
  1810. if (type == 1 || type == 2) {
  1811. res = this.logic.gang(chairId,this.handCards[chairId], card, type);
  1812. } else if (type == 3) {
  1813. res = this.logic.zmGang(chairId,this.handCards[chairId], this.huCards[chairId], card);
  1814. }
  1815. if (!res) {
  1816. return { code: C.FAILD, msg: C.TABLE_GANG_ERROR };
  1817. }
  1818. /////TL++7月17日,这整个if的内容 和else的判断
  1819. let winner = this.winner;
  1820. if (winner.chs.length > 0) {
  1821. yield this.pushMsgAsync(-1, 'sxjiang_event', { type: M.HU, data: { lead: String(winner.lead), chairIds: winner.chs } });
  1822. this.setPaijuHuiFangData(M.HU,{ lead: String(winner.lead), chairIds: winner.chs });/////TL++ 牌局回放 push吃胡牌数据
  1823. // console.warn("提前结算BBB");
  1824. yield this.concludeGameAsync(MODE.NORMAL);
  1825. }
  1826. else{
  1827. // 记录杠牌
  1828. if (type == 1) {
  1829. // 被杠玩家
  1830. this.gangOuter = this.outerId;
  1831. res.origin = this.outerId;
  1832. this.outCards[this.outerId].pop();
  1833. this.huCards[chairId].push(res);
  1834. this.logic.remove(this.handCards[chairId], res.cards);
  1835. } else if (type == 2) {
  1836. // 被杠玩家
  1837. this.gangOuter = -1;
  1838. this.huCards[chairId].push(res);
  1839. this.logic.remove(this.handCards[chairId], [card, card, card, card]);
  1840. this.logic.adjust(this.handCards[chairId]);
  1841. } else if (type == 3) {
  1842. // console.warn("333拉杠胡%%%%%%%%%%%%%%%%%%%%%%",this.logic.isLaGang,this.isGangHu);
  1843. let huCard = _.find(this.huCards[chairId], (o) => {
  1844. return (o.style == Logic.STYLE.PENG && o.cards[0] == card);
  1845. });
  1846. if (!huCard) {
  1847. return { code: C.FAILD, msg: C.TABLE_GANG_ERROR };
  1848. }
  1849. // 被杠玩家
  1850. this.gangOuter = -1;
  1851. // console.warn("拉杠胡%%%%%%%%%%%%%%%%%%%%%%" ,this.isGangHu);
  1852. // 抢杠胡
  1853. if (!this.isGangHu) {
  1854. this.lgkhCount = 0;/////TL++拉杠可胡玩家的数量
  1855. let allowIds = [], otherIds = [];
  1856. for (let i = 0; i < this.ccount; ++i) {
  1857. // 排除自己
  1858. if (i != chairId) {
  1859. this.logic.isLaGang = true;//////TL++,是否刚刚被拉杠用于判断是否被拉杠胡
  1860. // console.error("sscc222胡牌分析 杠牌i",i,this.logic.isLaGang);
  1861. let huRes = this.logic.huAnalyze(i,this.handCards[i], card, this.huCards[i]);
  1862. // console.error("ssccCCC胡牌分析 huRes",huRes);
  1863. // let lg2 = false;///TL++
  1864. if (huRes) {
  1865. // let str3a = "table lgphcg:"+this.id + ",uid"+this.handCards[i];
  1866. // logger.info(str3a);////cssj
  1867. if (!this.isGangHu) this.isGangHu = true;
  1868. //////////TL++,为了记录承包情况,第一个元素表示承包原因 1:海底捞月打出去被胡 2:被人拉杠胡 第二个元素承包的玩家座位号
  1869. // this.logic.chengBaoTL[chairId][this.logic.chengBaoTL[chairId].length] = [2,this.currentId];
  1870. // lg2 = true//////TL++
  1871. this.huRes[i] = huRes;
  1872. this.masks[i] |= 16;
  1873. this.lgkhCount += 1;/////TL++拉杠可胡玩家的数量
  1874. allowIds.push(this.users[i].id); continue;
  1875. }
  1876. }
  1877. // 其他玩家
  1878. otherIds.push(this.users[i].id);
  1879. }
  1880. // 有人可胡
  1881. if (allowIds.length > 0) {
  1882. // 置于等待
  1883. this.masks[chairId] = 9;
  1884. this.gangType = type;
  1885. this.gangCard = card;
  1886. // 抢杠通知
  1887. yield this.pushMsgAsync(otherIds, 'sxjiang_event', { type: M.MASK_HU, data: { mask: '0', card: String(card) } });
  1888. yield this.pushMsgAsync(allowIds, 'sxjiang_event', { type: M.MASK_HU, data: { mask: '16', card: String(card) } });
  1889. // console.warn("抢杠胡同盟会告知",allowIds);
  1890. return { code: C.OK };
  1891. }
  1892. }
  1893. huCard.style = Logic.STYLE.ZMGANG;
  1894. // console.warn("55拉杠胡%%%%%%%%%%%%%%%%%%%%%%",this.logic.isLaGang,this.gangType,this.gangCard = 0);
  1895. this.isGangHu = false;/////TL++,8月28日晚上,为了解决过胡拉杠之后就算自己已经摸牌也不能再次拉杠的问题
  1896. this.logic.remove(this.handCards[chairId], card);
  1897. this.logic.adjust(this.handCards[chairId]);
  1898. }
  1899. // if(this.chBanker == chairId) this.isZJYG = true;////本局庄家是否有杠
  1900. // 清空权限
  1901. this._eatType = 0;
  1902. this.gangType = 0;
  1903. this.gangCard = 0;
  1904. _.fill(this.masks, 0);
  1905. // 总杠次
  1906. this.gonCount += 1;
  1907. // 发送通知
  1908. // console.warn("333 声剩余声剩余声剩");
  1909. let lastCount = this.logic.leaveCount();/////TL++xg
  1910. let pjhfsplist = {
  1911. shouPai:this.logic.deepCloneTL(this.handCards),
  1912. lastCount:lastCount,
  1913. outCards:this.logic.deepCloneTL(this.outCards),
  1914. opData:{ chairId: String(chairId), type: String(type), card: String(card), lastCount: String(lastCount) }
  1915. }
  1916. this.setPaijuHuiFangData(M.GANG,pjhfsplist);/////TL++ 牌局回放 push杠操作数据
  1917. yield this.pushMsgAsync(-1, 'sxjiang_event', { type: M.GANG, data: { chairId: String(chairId), type: String(type), card: String(card), lastCount: String(lastCount) } });
  1918. this.touchCardAsync(chairId, type); ///////杠牌摸牌
  1919. }
  1920. } else {
  1921. // 置于等待
  1922. this.masks[chairId] = 9;
  1923. this.gangType = type;
  1924. this.gangCard = card;
  1925. }
  1926. // let str4 = "table222 杠牌,id:"+this.id + ",uid"+chairId+","+ this.state +",card "+card;
  1927. // logger.info(str4);////cssj
  1928. return { code: C.OK };
  1929. });
  1930. // 碰牌
  1931. proto.pengCardAsync = cor(function* (chairId, card) {
  1932. let str3 = "table 碰牌id:%s "+this.id + " ,uid "+chairId+" ,this.masks "+ this.masks +" ,card "+card;
  1933. logger.warn(str3);////cssj
  1934. // 参数校验
  1935. if (card != this.outCard || this.currentId == chairId) {
  1936. return { code: C.FAILD, msg: C.GAME_PARAM_ERROR };
  1937. }
  1938. // 权限校验
  1939. if (!(this.masks[chairId] & 4)) {
  1940. return { code: C.FAILD, msg: C.TABLE_MASK_ERROR };
  1941. }
  1942. // 他人可胡杠
  1943. var cHuGang = _.findIndex(this.masks, (m) => (((m & 16) || (m & 8)) && !(m & 4)));
  1944. // console.warn("碰牌按钮被点击了 他人可胡杠",cHuGang,this.masks);
  1945. if (cHuGang == -1) {
  1946. let res = this.logic.peng(chairId,this.handCards[chairId], card);
  1947. if (!res) {
  1948. return { code: C.FAILD, msg: C.TABLE_PENG_ERROR };
  1949. }
  1950. /////TL++7月17日,这整个if的内容 和else的判断
  1951. let winner = this.winner;
  1952. if (winner.chs.length > 0) {
  1953. yield this.pushMsgAsync(-1, 'sxjiang_event', { type: M.HU, data: { lead: String(winner.lead), chairIds: winner.chs } });
  1954. this.setPaijuHuiFangData(M.HU,{ lead: String(winner.lead), chairIds: winner.chs });/////TL++ 牌局回放 push吃胡牌数据
  1955. // console.warn("提前结算AAA");
  1956. yield this.concludeGameAsync(MODE.NORMAL);
  1957. }
  1958. else{
  1959. // 记录碰牌
  1960. res.origin = this.outerId;
  1961. this.outCards[this.outerId].pop();
  1962. this.huCards[chairId].push(res);
  1963. this.logic.remove(this.handCards[chairId], [card, card]);
  1964. // 清空权限
  1965. this._eatType = 0;
  1966. this.gangType = 0;
  1967. this.gangCard = 0;
  1968. _.fill(this.masks, 0);
  1969. // 用户顺序
  1970. this.currentId = chairId;
  1971. for (let i = 0; i < this.ccount; ++i) {
  1972. let pengdata = {////这种一定要声明在for循环里面
  1973. chairId: String(chairId),
  1974. card: String(card)
  1975. }
  1976. if(i == chairId){
  1977. let hutipdataTL = this.logic.hutip(i,this.handCards[i],this.huCards[i],this.huCards,this.outCards);////碰牌调用胡牌提示
  1978. pengdata.hutipdata = hutipdataTL;
  1979. }
  1980. else{
  1981. pengdata.hutipdata = {
  1982. renyi:0,//////是否可胡任意牌,0表示不满足1表示满足
  1983. kehuData:[]/////对象数组,分别表示打哪张可胡哪几张数据
  1984. };
  1985. }
  1986. yield this.pushMsgAsync(i, 'sxjiang_event', { type: M.PENG, data: pengdata });
  1987. }
  1988. let pengdatapg = {////碰的旁观数据
  1989. chairId: String(chairId),
  1990. card: String(card)
  1991. }
  1992. pengdatapg.hutipdata = {
  1993. renyi:0,//////是否可胡任意牌,0表示不满足1表示满足
  1994. kehuData:[]/////对象数组,分别表示打哪张可胡哪几张数据
  1995. };
  1996. yield this.lookMsgAsync('sxjiang_event', { type: M.PENG, data: pengdatapg });////TL++
  1997. ////20200831增加胡牌提示的时候把下面这句换成了上面那一段
  1998. // yield this.pushMsgAsync(-1, 'sxjiang_event', { type: M.PENG, data: { chairId: String(chairId), card: String(card) } });
  1999. let pjhfsplist = {
  2000. shouPai:this.logic.deepCloneTL(this.handCards),
  2001. lastCount:String(this.logic.leaveCount()),
  2002. outCards:this.logic.deepCloneTL(this.outCards),
  2003. opData:{ chairId: String(chairId), card: String(card) }
  2004. }
  2005. this.setPaijuHuiFangData(M.PENG,pjhfsplist);/////TL++ 牌局回放 push碰操作数据
  2006. }
  2007. } else {
  2008. // 置于等待
  2009. this.masks[chairId] = 5;
  2010. // 查找等待 TL++下面这一段,为了解决A打出一张牌之后B可吃胡C可碰情况下 C先点碰B点吃会死掉的问题 这是原始代码的重大天然Bug
  2011. let cGang = -1
  2012. let cPeng = -1;
  2013. let _cChi = -1;
  2014. // console.warn("这里是啥情况啊",this.masks);
  2015. for (let i = 0; i < this.masks.length; ++i) {
  2016. // if (i == this.currentId || i == chairId) continue;///////TL++zsyl 这种写法会导致拉杠胡的玩家点击过胡之后被拉杠胡的玩家杠不出来的问题
  2017. if (i == chairId) continue;//////TL++,为了解决拉杠胡的玩家点击过胡之后被拉杠胡的玩家杠不出来的问题
  2018. if (this.masks[i] == 9) {
  2019. cGang = i;
  2020. continue;
  2021. }
  2022. if (this.masks[i] == 5) {
  2023. cPeng = i;
  2024. continue;
  2025. }
  2026. if (this.masks[i] == 3) {
  2027. _cChi = i;
  2028. continue;
  2029. }
  2030. }
  2031. // console.warn("ppppppppppp444 ",chairId,cGang,cPeng,_cChi);
  2032. // console.warn("2222情况啊",cGang, this.gangType,this.gangCard);
  2033. // 杠
  2034. if (cGang != -1 && this.gangType > 0 && this.gangCard > 0) {
  2035. return this.gangCardAsync(cGang, this.gangCard, this.gangType).then(() => ({ code: C.OK }));
  2036. }
  2037. }
  2038. // let str4 = "table 碰牌id:%s"+this.id + ",uid"+chairId+","+ this.state +" card "+card;
  2039. // logger.info(str4);////cssj
  2040. return { code: C.OK };
  2041. });
  2042. // 吃牌,1-@**左吃, 2-*@*中吃, 3-@**右吃
  2043. proto.eatCardAsync = cor(function* (chairId, card, type) {
  2044. let str3 = "table 吃牌id:%s "+this.id + " ,uid "+chairId+" ,this.masks "+ this.masks +",card "+card;
  2045. logger.warn(str3);////cssj
  2046. // 参数校验
  2047. if (!type && (type < 1 || type > 3)) {
  2048. return { code: C.FAILD, msg: C.GAME_PARAM_ERROR };
  2049. }
  2050. if (card != this.outCard) {
  2051. return { code: C.FAILD, msg: C.GAME_PARAM_ERROR };
  2052. }
  2053. // 权限校验
  2054. if (!(this.masks[chairId] & 2)) {
  2055. return { code: C.FAILD, msg: C.TABLE_MASK_ERROR };
  2056. }
  2057. // if(this.logic.isGuoHuList[chairId][0]) this.logic.isGuoHuList[chairId][0] = false;/////TL++,吃牌设置过胡玩家的是否点击过胡为false;
  2058. // 他人可胡杠碰
  2059. var cHuGangPeng = _.findIndex(this.masks, (m) => (((m & 16) || (m & 8) || (m & 4)) && !(m & 2)));
  2060. // console.warn("111他人可胡杠碰",cHuGangPeng);
  2061. if (cHuGangPeng == -1) {
  2062. let res = this.logic.chi(this.handCards[chairId], card, type);
  2063. if (!res) {
  2064. return { code: C.FAILD, msg: C.TABLE_PENG_ERROR };
  2065. }
  2066. /////TL++7月17日,这整个if的内容 和else的判断
  2067. let winner = this.winner;
  2068. // console.warn("222他人可胡杠碰",winner.chs.length);
  2069. if (winner.chs.length > 0) {
  2070. yield this.pushMsgAsync(-1, 'sxjiang_event', { type: M.HU, data: { lead: String(winner.lead), chairIds: winner.chs } });
  2071. this.setPaijuHuiFangData(M.HU,{ lead: String(winner.lead), chairIds: winner.chs });/////TL++ 牌局回放 push吃胡牌数据
  2072. // console.warn("提前结算aaa");
  2073. yield this.concludeGameAsync(MODE.NORMAL);
  2074. }
  2075. else{
  2076. // 记录吃牌
  2077. res.origin = this.outerId;
  2078. this.outCards[this.outerId].pop();
  2079. this.huCards[chairId].push(res);
  2080. if (type == 1) {
  2081. this.logic.remove(this.handCards[chairId], [card + 1, card + 2]);
  2082. } else if (type == 2) {
  2083. this.logic.remove(this.handCards[chairId], [card - 1, card + 1]);
  2084. } else {
  2085. this.logic.remove(this.handCards[chairId], [card - 2, card - 1]);
  2086. }
  2087. // 清空权限
  2088. this._eatType = 0;
  2089. this.gangType = 0;
  2090. this.gangCard = 0;
  2091. _.fill(this.masks, 0);
  2092. // 用户顺序
  2093. this.currentId = chairId;
  2094. // 发送通知
  2095. for (let i = 0; i < this.ccount; ++i) {
  2096. let chidata = {
  2097. chairId: String(chairId),
  2098. type: String(type),
  2099. card: String(card)
  2100. }
  2101. if(i == chairId){
  2102. let hutipdataTL = this.logic.hutip(i,this.handCards[i],this.huCards[i],this.huCards,this.outCards);////吃牌调用胡牌提示
  2103. chidata.hutipdata = hutipdataTL;
  2104. }
  2105. else{
  2106. chidata.hutipdata = {
  2107. renyi:0,//////是否可胡任意牌,0表示不满足1表示满足
  2108. kehuData:[]/////对象数组,分别表示打哪张可胡哪几张数据
  2109. };
  2110. }
  2111. yield this.pushMsgAsync(i, 'sxjiang_event', { type: M.CHI, data: chidata });
  2112. }
  2113. let chidatapg = { ////TL++吃牌旁观数据
  2114. chairId: String(chairId),
  2115. type: String(type),
  2116. card: String(card)
  2117. }
  2118. chidatapg.hutipdata = {
  2119. renyi:0,//////是否可胡任意牌,0表示不满足1表示满足
  2120. kehuData:[]/////对象数组,分别表示打哪张可胡哪几张数据
  2121. };
  2122. yield this.lookMsgAsync('sxjiang_event', { type: M.CHI, data: chidatapg });////TL++吃牌旁观消息
  2123. ////20200901为了增加胡牌提示把下面这一段换成了上面那一段
  2124. // yield this.pushMsgAsync(-1, 'sxjiang_event', { type: M.CHI, data: { chairId: String(chairId), type: String(type), card: String(card) } });
  2125. let pjhfsplist = {
  2126. shouPai:this.logic.deepCloneTL(this.handCards),
  2127. lastCount:String(this.logic.leaveCount()),
  2128. outCards:this.logic.deepCloneTL(this.outCards),
  2129. opData:{ chairId: String(chairId), type: String(type), card: String(card) }
  2130. }
  2131. this.setPaijuHuiFangData(M.CHI,pjhfsplist);/////TL++ 牌局回放 push吃操作数据
  2132. }
  2133. } else {
  2134. // 置于等待
  2135. this.masks[chairId] = 3;
  2136. this._eatType = type;
  2137. // 查找等待 TL++下面这一段,为了解决A打出一张牌之后B可吃胡C可碰情况下 C先点碰B点吃会死掉的问题 这是原始代码的重大天然Bug
  2138. let cGang = -1
  2139. let cPeng = -1;
  2140. let _cChi = -1;
  2141. // console.warn("这里是啥情况啊",this.masks);
  2142. for (let i = 0; i < this.masks.length; ++i) {
  2143. // if (i == this.currentId || i == chairId) continue;///////TL++zsyl 这种写法会导致拉杠胡的玩家点击过胡之后被拉杠胡的玩家杠不出来的问题
  2144. if (i == chairId) continue;//////TL++,为了解决拉杠胡的玩家点击过胡之后被拉杠胡的玩家杠不出来的问题
  2145. if (this.masks[i] == 9) {
  2146. cGang = i;
  2147. continue;
  2148. }
  2149. if (this.masks[i] == 5) {
  2150. cPeng = i;
  2151. continue;
  2152. }
  2153. if (this.masks[i] == 3) {
  2154. _cChi = i;
  2155. continue;
  2156. }
  2157. }
  2158. // console.warn("2222情况啊",cGang, this.gangType,this.gangCard);
  2159. // 杠碰吃
  2160. if (cGang != -1 && this.gangType > 0 && this.gangCard > 0) {
  2161. return this.gangCardAsync(cGang, this.gangCard, this.gangType).then(() => ({ code: C.OK }));
  2162. } else if (cPeng != -1) {
  2163. return this.pengCardAsync(cPeng, this.outCard).then(() => ({ code: C.OK }));
  2164. } else if (_cChi != -1 && this._eatType > 0) {
  2165. return this.eatCardAsync(_cChi, this.outCard, this._eatType).then(() => ({ code: C.OK }));
  2166. }
  2167. }
  2168. // let str4 = "table 吃牌id:"+this.id + ",uid"+chairId+","+ this.state +",card "+card;
  2169. // logger.info(str4);////cssj
  2170. return { code: C.OK };
  2171. });
  2172. // 胡牌 处理前端
  2173. proto.succCardAsync = cor(function* (chairId) {
  2174. let str3 = "table 胡牌:%s "+this.id + " ,uid "+chairId+" ,this.masks "+ this.masks;
  2175. logger.warn(str3);////cssj
  2176. // 权限校验
  2177. if (!(this.masks[chairId] & 16)) {
  2178. return { code: C.FAILD, msg: C.TABLE_MASK_ERROR };
  2179. }
  2180. // 删除权限
  2181. this.masks[chairId] = 0;
  2182. // 是否自摸
  2183. let winner = this.winner;
  2184. var isMoHu = (this.currentId == chairId);
  2185. if (isMoHu) {
  2186. winner.chs[0] = chairId;
  2187. yield this.pushMsgAsync(-1, 'sxjiang_event', { type: M.HU, data: { lead: String(winner.lead), chairIds: winner.chs } });
  2188. this.setPaijuHuiFangData(M.HU,{ lead: String(winner.lead), chairIds: winner.chs });/////TL++ 牌局回放 push摸胡牌数据
  2189. // console.warn("提前结算444");
  2190. yield this.concludeGameAsync(MODE.NORMAL);
  2191. } else {
  2192. // 抢杠胡
  2193. if (this.isGangHu) {
  2194. winner.lead = this.currentId;
  2195. // 抢杠牌
  2196. if (this.gangType > 0 && this.gangCard > 0) {
  2197. this.logic.remove(this.handCards[this.currentId], this.gangCard);
  2198. this.masks[this.currentId] = 0;
  2199. this.gangType = 0; this.gangCard = 0;
  2200. }
  2201. } else {
  2202. // 点炮
  2203. winner.lead = this.outerId;
  2204. }
  2205. // 一炮多响
  2206. let __cHu = -1;
  2207. if (this.isMHu) {
  2208. // 胡牌者
  2209. winner.chs.push(chairId);
  2210. // 他人可胡
  2211. __cHu = _.findIndex(this.masks, (m) => ((m & 16)));
  2212. } else {
  2213. // 胡牌者
  2214. if (winner.chs.length <= 0) winner.chs[0] = chairId;
  2215. else {
  2216. let hutype = [];//this.logic.getReasultTypeTL(winner.chs[0],this.huCards[winner.chs[0]],false)
  2217. let hutypenew = []//this.logic.getReasultTypeTL(chairId,this.huCards[chairId],false)
  2218. winner.chs[0] = chairId;
  2219. }
  2220. // 他人可胡
  2221. __cHu = _.findIndex(this.masks, (m, i) => ((m & 16)))
  2222. }
  2223. // console.warn("22局部变量改变全局变量??",winner ,this.winner);
  2224. // console.warn("点击胡按钮",__cHu,this.masks);
  2225. if (__cHu == -1) {
  2226. yield this.pushMsgAsync(-1, 'sxjiang_event', { type: M.HU, data: { lead: String(winner.lead), chairIds: winner.chs } });
  2227. this.setPaijuHuiFangData(M.HU,{ lead: String(winner.lead), chairIds: winner.chs });/////TL++ 牌局回放 push吃胡牌数据
  2228. // console.warn("提前结算555");
  2229. yield this.concludeGameAsync(MODE.NORMAL);
  2230. }
  2231. }
  2232. return { code: C.OK };
  2233. });
  2234. // 结算游戏
  2235. proto.concludeGameAsync = cor(function* (mode) {
  2236. /////增加下面这几行是为了保证每一把只执行一次结算方法
  2237. if(this.isYJJSGL){
  2238. // let strk = "table 结算游戏 id:了保证每一把只执行一次结算方法 "+this.id +"结算模式"+mode
  2239. // logger.info(strk);////cssj
  2240. return;
  2241. }
  2242. this.isYJJSGL = true;
  2243. this.isYJKSGL = false;/////是否已经执行过开始函数了
  2244. // console.warn("结算函数",mode);
  2245. let str1 = "table 结算游戏 id: "+this.id +" 结算模式 "+mode
  2246. logger.warn(str1);////cssj
  2247. //ts--end
  2248. // 结算数据
  2249. var winner = this.winner;
  2250. var data = { mode: String(mode), lead: String(winner.lead) };
  2251. var wins = this.logic.fillDeep(Array(this.ccount), {
  2252. win: 0,//总输赢
  2253. lucky: 0,
  2254. trans: 0,//明杠个数
  2255. dark: 0,//暗杠个数
  2256. penggang: 0,//碰杠个数
  2257. isPoChan: 0,
  2258. shiJiKouFen: 0,
  2259. gangfen: 0,
  2260. cardfen: 0,
  2261. jiangma: 0,
  2262. });
  2263. data.hutype = [];//this.logic.getReasultTypeTL(winner.chs[0],this.huCards[winner.chs[0]],true)///////TL++胡牌牌型 胡牌人的chairID
  2264. data.banker = this.chBanker;/////TL++
  2265. data.chengbao = [];
  2266. let isMZJYM = false;//是否满足无红中加一码
  2267. if(winner.chs.length == 1 && this.jiangmaType == 1 && this.hzCount > 0 && this.isWGHZJYM){
  2268. //无红中加1码,规则只能在红中个数大于0而且是159奖码情况下才能勾选
  2269. if(this.handCards[winner.chs[0]].indexOf(51) == -1){
  2270. //有多个赢家的时候无红中加一码不生效
  2271. isMZJYM = true;
  2272. }
  2273. }
  2274. let jiangmaInfo = this.logic.getJiangmaInfo(isMZJYM);
  2275. data.jiangmaList = jiangmaInfo.jiangmaList;
  2276. let jiangmaFen = jiangmaInfo.mafen;
  2277. let yjgs = 0;//赢家个数
  2278. // 计算输赢
  2279. for (let i = 0; i < wins.length; ++i) {
  2280. // 自摸
  2281. let isMoHu = winner.lead == -1;
  2282. // 胡牌者
  2283. if (winner.chs.indexOf(i) != -1) {
  2284. yjgs++;
  2285. // console.warn("结算承包数据",this.logic.chengBaoTL,isMoHu,cbqk);
  2286. if(this.logic.isLaGang){
  2287. //抢杠胡:被抢者替每家输2分
  2288. let lead = winner.lead;
  2289. let sy = 2 * this.cell
  2290. wins.forEach((w, c) => {
  2291. if (c != i) {
  2292. wins[lead].win -= sy;
  2293. wins[i].win += sy;
  2294. wins[lead].cardfen -= sy;
  2295. wins[i].cardfen += sy;
  2296. }
  2297. });
  2298. ////下面这段是计算奖码的分数
  2299. wins.forEach((w, c) => {
  2300. if (c != i) {
  2301. if(c == lead){//////点炮玩家
  2302. wins[lead].win -= jiangmaFen;
  2303. wins[i].win += jiangmaFen;
  2304. wins[lead].jiangma -= jiangmaFen;
  2305. wins[i].jiangma += jiangmaFen;
  2306. }
  2307. }
  2308. });
  2309. }
  2310. else{
  2311. //不是抢杠胡
  2312. if (isMoHu) {
  2313. //自摸每家输2分
  2314. let sy = 2 * this.cell
  2315. wins.forEach((w, c) => {
  2316. if (c != i) {
  2317. w.win -= sy;
  2318. wins[i].win += sy;
  2319. w.cardfen -= sy;
  2320. wins[i].cardfen += sy;
  2321. }
  2322. });
  2323. ////下面这段是计算奖码的分数
  2324. wins.forEach((w, c) => {
  2325. if (c != i) {
  2326. w.win -= jiangmaFen;
  2327. wins[i].win += jiangmaFen;
  2328. w.jiangma -= jiangmaFen;
  2329. wins[i].jiangma += jiangmaFen;
  2330. }
  2331. });
  2332. }
  2333. else {
  2334. //点炮者:给赢家输1分,其他人不输分
  2335. let lead = winner.lead;
  2336. // 点炮出钱
  2337. // if (this.isWOne) {/////TL++zsyl,次判断方式适用于点炮出钱
  2338. let hutype = [];
  2339. let sy = this.cell
  2340. wins.forEach((w, c) => {
  2341. if (c != i) {
  2342. if(c == lead){//////点炮玩家
  2343. w.win -= sy;
  2344. wins[i].win += sy;
  2345. w.cardfen -= sy;
  2346. wins[i].cardfen += sy;
  2347. }
  2348. }
  2349. });
  2350. ////下面这段是计算奖码的分数
  2351. wins.forEach((w, c) => {
  2352. if (c != i) {
  2353. if(c == lead){//////点炮玩家
  2354. wins[lead].win -= jiangmaFen;
  2355. wins[i].win += jiangmaFen;
  2356. wins[lead].jiangma -= jiangmaFen;
  2357. wins[i].jiangma += jiangmaFen;
  2358. }
  2359. }
  2360. });
  2361. }
  2362. }
  2363. wins[i].lucky = 1;
  2364. }
  2365. // let str2 = "table 222结算函数---id:"+this.id +"结算模式"+mode
  2366. // logger.info(str2);////cssj
  2367. if(!(mode != MODE.NORMAL && this.isHZHG)) {
  2368. // 杠牌 流局了而且勾选荒庄荒杠 的话则不计算杠分
  2369. let gangMul = 0;
  2370. for (let huCard of this.huCards[i]) {
  2371. if (huCard.style == Logic.STYLE.ZMGANG) {
  2372. gangMul += 1;
  2373. wins[i].penggang += 1;
  2374. } else if (huCard.style == Logic.STYLE.ANGANG) {
  2375. gangMul += 2;
  2376. wins[i].dark += 1;
  2377. } else if (huCard.style == Logic.STYLE.GANG){
  2378. //明杠谁点的杠谁付3分
  2379. wins[i].trans += 1;
  2380. wins[huCard.origin].win -= 3 * this.cell;
  2381. wins[i].win += 3 * this.cell;
  2382. wins[huCard.origin].gangfen -= 3 * this.cell;
  2383. wins[i].gangfen += 3 * this.cell;
  2384. }
  2385. }
  2386. if (gangMul > 0) {
  2387. wins.forEach((w, c) => {
  2388. if (c != i) {
  2389. w.win -= gangMul * this.cell;
  2390. wins[i].win += gangMul * this.cell;
  2391. w.gangfen -= gangMul * this.cell;
  2392. wins[i].gangfen += gangMul * this.cell;
  2393. }
  2394. });/////TL++杠牌有赢
  2395. }
  2396. }
  2397. // 手牌
  2398. let cards = { card: 0, groups: [], hands: [] };
  2399. if (wins[i].lucky) {
  2400. cards.card = this.huRes[i].card;
  2401. }
  2402. for (let huCard of this.huCards[i]) {
  2403. cards.groups.push({ style: huCard.style, card: huCard.cards[0] });
  2404. }
  2405. let handCard = this.handCards[i] || [];
  2406. let count = this.mcount - this.huCards[i].length * 3;
  2407. cards.hands = handCard.slice(0, count);
  2408. wins[i].cards = cards;
  2409. }
  2410. // let str3 = "table 333结算函数---id:"+this.id +",结算模式"+mode
  2411. // logger.info(str3);////cssj
  2412. //////TL++
  2413. let shiJiKouFen = [];
  2414. if(this.playerAllCount == 2) shiJiKouFen = [wins[0].win,wins[1].win];
  2415. else if(this.playerAllCount == 3) shiJiKouFen = [wins[0].win,wins[1].win,wins[2].win];
  2416. else if(this.playerAllCount == 4) shiJiKouFen = [wins[0].win,wins[1].win,wins[2].win,wins[3].win];
  2417. for (let i = 0; i < this.ccount; ++i) {
  2418. wins[i].shiJiKouFen = shiJiKouFen[i];
  2419. }
  2420. //console.warn("实际扣分XXX",shiJiKouFen,wins[0].win,wins[1].win,wins[2].win,wins[3].win)
  2421. // 胜负情况
  2422. data.wins = wins;
  2423. let bjsy = [];//本局每个人的输赢
  2424. for (let i = 0; i < this.ccount; ++i) {
  2425. bjsy[i] = wins[i].win;
  2426. }
  2427. this.sszjDataList[this.sszjDataList.length] = bjsy;
  2428. this.over += 1;// 局数+1
  2429. //ts++
  2430. let sszjScore = [];//ts++实时本局成绩
  2431. let sszjAllScore = [];//ts++实时总成绩
  2432. // 记录分数
  2433. for (let i = 0; i < this.ccount; ++i) {
  2434. let user = this.users[i];
  2435. if (user)
  2436. {
  2437. sszjScore[i] = shiJiKouFen[i];
  2438. this.score.writeScore(user.id,shiJiKouFen[i], 1);//设置分数
  2439. sszjAllScore[i] = this.score.getScore(user.id);
  2440. // if(this.gameKindTL == 2) sszjAllScore[i] -=200;
  2441. if(this.over == 1)
  2442. {
  2443. this.score.writeCost(user.id,this.cost, 0); //ts++设置消耗
  2444. }
  2445. }
  2446. }
  2447. let endmode=ENDMODE.PLAYING;
  2448. if(this.isGameOver())
  2449. {
  2450. this.isGameOk=true;
  2451. endmode=ENDMODE.NORMALEND;//局数完成--正常结束
  2452. }
  2453. data.isover = this.isGameOk;
  2454. data.nowTime = Date.now();
  2455. this.setPaijuHuiFangData(M.CONCLUDE,data);/////TL++ 牌局回放 push结算数据
  2456. /////TL++,用于记录玩家牌局回放的json文件名
  2457. this.pjhffileName[this.pjhffileName.length] = this.PJHF.getjsonFileName(this.over,this.recordid,this.ctime);
  2458. // let str4 = "table 444结算函数---id:%s"+this.id +"结算模式"+mode
  2459. // logger.info(str4);////cssj
  2460. //ts++胡的人
  2461. let hu=-1;
  2462. if (winner.chs.length >0 && winner.chs[0] >= 0 && winner.chs[0] <= 3)
  2463. {
  2464. hu=winner.chs[0];
  2465. }
  2466. //ts++实时战绩
  2467. //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});
  2468. this.sszjs.push({_id: String(this.over),sszjScore:sszjScore,sszjAllScore:sszjAllScore,banker:this.chBanker,hu:hu,pao:winner.lead});
  2469. /////固定庄家,不固定的话解除下面这一段的注释
  2470. // 切换庄家
  2471. if(yjgs == 0){
  2472. //没有赢家,流局了,最后一个摸牌的人坐庄
  2473. this.chBanker = this.logic.lastMoPaiChairID;
  2474. }
  2475. else if(yjgs == 1){
  2476. //只有一个人赢了,谁赢谁做庄
  2477. this.chBanker = winner.chs[0];
  2478. }
  2479. else if(yjgs > 1) {
  2480. //一炮多响,放炮的人坐庄
  2481. this.chBanker = winner.lead
  2482. }
  2483. /////TL++,10月9号,为了解决冲刺时前端的玩家分数偶尔会显示负数的bug
  2484. data.playNowScore = [];
  2485. for (let i = 0; i < this.ccount; ++i) {
  2486. let user = this.users[i];
  2487. if (user)
  2488. {
  2489. data.playNowScore[i] = this.score.getScore(user.id);
  2490. }
  2491. }
  2492. // 重置本局
  2493. this.resetRound();
  2494. // 结算通知
  2495. yield this.pushMsgAsync(-1, 'sxjiang_event', { type: M.CONCLUDE, data: data });
  2496. this.PJHF.writePJHFJson({"pjhfDataList":this.PaijuHuiFang},this.over,this.id)
  2497. this.logic.isZHYZ = false; /////TL++,是否最后一张
  2498. // yield this.pushMsgAsync(-1, 'sxjiang_event', { type: 100, data: {"pjhfDataList":this.PaijuHuiFang}});//////最终发送给前端的牌局回放
  2499. // let str6 = "table end 结算函数-id:"+this.id +"结算模式"+mode
  2500. // logger.info(str6);////cssj
  2501. yield this.endResultAsync(endmode);
  2502. });
  2503. // 发送聊天
  2504. proto.sendMsgAsync = cor(function* (chairId, msg) {
  2505. // console.error("sscc发送聊天+++++++++++++++++++++++++++++++++",chairId,msg)
  2506. yield this.pushMsgAsync(-1, 'sxjiang_event', { type: M.CHAT, data: { chairId: String(chairId), msg: msg } });
  2507. return { code: C.OK };
  2508. });
  2509. // 收费聊天 礼物收费
  2510. proto.vsendMsgAsync = cor(function* (schairId, dchairId, msg) {
  2511. if (schairId == dchairId || !this.users[dchairId]) {
  2512. return { code: C.FAILD, msg: C.GAME_PARAM_ERROR };
  2513. }
  2514. let user = this.users[schairId];
  2515. if (!user) {
  2516. return { code: C.FAILD, msg: C.TABLE_NOT_USER };
  2517. }
  2518. var player = yield this.app.models.Player.findByIdAsync(user.id, 'diamond');
  2519. let lwcost = this.LWKF[msg.type];//////TL++礼物扣费
  2520. if(player)
  2521. {
  2522. if (((player.diamond) || 0) < lwcost) {
  2523. return { code: C.FAILD, msg: C.GAME_DIAMOND_LOW };
  2524. }
  2525. let dSource=player.diamond;
  2526. let dNow=player.diamond-lwcost;
  2527. player.diamond -= lwcost;
  2528. yield player.saveAsync();
  2529. // 钻石记录
  2530. var diamondrecord = new this.app.models.DiamondRecord({
  2531. _id: uuid.v1(),
  2532. playerId: user.id,
  2533. dType: 5,//礼物
  2534. dSource: dSource,
  2535. dSwap: -lwcost,
  2536. dNow: dNow,
  2537. tableId: this.recordid
  2538. });
  2539. yield diamondrecord.saveAsync();
  2540. //ts++设置消耗
  2541. this.score.writeCost(user.id,0, lwcost);
  2542. }
  2543. yield this.pushMsgAsync(-1, 'sxjiang_event', { type: M.FEE_CHAT, data: { cost: String(lwcost),schairId: String(schairId), dchairId: String(dchairId), msg: msg } });
  2544. return { code: C.OK };
  2545. });
  2546. //ts++写分 endtype = { 正常: 0,局数完成: 1, 房主解散: 2, 申请解散: 3 ,超时解散: 4 };
  2547. proto.writeResultAsync = cor(function* (endmode) {
  2548. logger.warn("牌局写入-------------- " + this.id );
  2549. // console.warn("ts++---------牌局写入writeResultAsync",this.id);
  2550. let gameCost=0;//游戏消耗
  2551. let giftCost = 0;////道具消耗
  2552. let nowTime = Date.now();
  2553. let users = [];
  2554. var scorers = this.score.getUsers();
  2555. if (scorers.length > 0)
  2556. {
  2557. var scorersSort = _.sortBy(scorers, (i) => i.chairId);
  2558. for (let scorer of scorersSort) {
  2559. gameCost+=this.cost;
  2560. giftCost+=scorer.giftCost;
  2561. let userscore=scorer.score;
  2562. // if(this.gameKindTL == 2) userscore -= 200;
  2563. 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});
  2564. //, gameCost: scorer.gameCost,giftCost: scorer.giftCost,diamond: scorer.diamond
  2565. }
  2566. }
  2567. // if(this.isGameOk)////以前是解散的不算返利
  2568. if(this.over > 0)////改成只要玩家扣钻了就有返利
  2569. {
  2570. // this.agentRebate=gameCost;//parseInt(gameCost*0.5);
  2571. this.agentRebate=gameCost+giftCost;////礼物也算消耗进行返利
  2572. console.warn("代理返利+++++",this.agentRebate);
  2573. }
  2574. else
  2575. {
  2576. this.agentRebate=0;
  2577. }
  2578. //console.warn("实时战绩",this.sszjs);//ts++
  2579. this.PJHF.getTSjsonFileName(100,this.recordid,this.ctime);/////TL++,用于记录玩家牌局回放的json文件名
  2580. // console.error("000HHHHHHHHHHHHHHHHHHHHHH",this.pjhffileName.length,this.pjhffileName);
  2581. let datats = {
  2582. _id: this.recordid,//记录
  2583. tableNo: this.id,
  2584. ownerId: this.ownerId,
  2585. agentId: this.agentId,
  2586. type: this.type,
  2587. kind: this.gameKindTL,//玩法 2冲刺
  2588. other: this.other,//////TL++2人3人的游戏规则
  2589. playerCount: this.playerAllCount,//游戏人数
  2590. round: this.round,//
  2591. over: this.over,//游戏局数
  2592. ctime: this.ctime,//创建时间
  2593. stime: this.stime,//开始时间
  2594. time: nowTime,//结束时间
  2595. endMode: endmode,//结束类型
  2596. gameCost: gameCost,//游戏消耗
  2597. giftCost: giftCost,//礼物消耗
  2598. agentRebate: parseInt(this.agentRebate*this.rEBATERATE),//代理返利
  2599. sszjFile: this.logic.deepCloneTL(this.pjhffileName),
  2600. sszj: this.logic.deepCloneTL(this.sszjs),
  2601. users: users
  2602. }
  2603. this.PJHF.writeTSJson(datats,100,this.id);////在开始第一局的时候将桌子信息写入本地的json文件
  2604. var fhmjtable = new this.app.models.FHMJTables({
  2605. _id: this.recordid,//记录
  2606. tableNo: this.id,
  2607. ownerId: this.ownerId,
  2608. agentId: this.agentId,
  2609. type: this.type,
  2610. kind: this.gameKindTL,//玩法 2冲刺
  2611. other: this.other,//////TL++2人3人的游戏规则
  2612. playerCount: this.playerAllCount,//游戏人数
  2613. round: this.round,//
  2614. over: this.over,//游戏局数
  2615. ctime: this.ctime,//创建时间
  2616. stime: this.stime,//开始时间
  2617. time: nowTime,//结束时间
  2618. endMode: endmode,//结束类型
  2619. gameCost: gameCost,//游戏消耗
  2620. giftCost: giftCost,//礼物消耗
  2621. agentRebate: parseInt(this.agentRebate*this.rEBATERATE),//代理返利
  2622. sszjFile: this.pjhffileName,
  2623. sszj: this.sszjs,
  2624. users: users
  2625. });
  2626. // console.warn("fhmjtable new",fhmjtable);
  2627. yield fhmjtable.saveAsync();
  2628. // logger.info("战绩写入fhmjtable.saveAsync()--------------",this.id);
  2629. });
  2630. // 结束信息 var endtype = { 局数完成: 1, 主动解散: 2, 断线解散: 3 ,超时解散: 4 };
  2631. proto.endResultAsync = cor(function* (endmode) {
  2632. // console.warn("ts++---------记录信息",this.id);
  2633. let str6 = "table 结束信息--id: "+this.id +" ,结算模式 "+endmode;
  2634. logger.warn(str6);////cssj
  2635. if(endmode>ENDMODE.PLAYING)//ts++关闭
  2636. {
  2637. let nowTime = Date.now();
  2638. if(this.state<STATE.END)//ts++防止重复写入
  2639. {
  2640. this.state = STATE.END;
  2641. if (this.endTimer) {
  2642. clearTimeout(this.endTimer);
  2643. this.endTimer = null;
  2644. }
  2645. if (this.overTimer) {
  2646. clearTimeout(this.overTimer);
  2647. this.overTimer = null;
  2648. }
  2649. // console.warn("ts++---------局数完成",this.over);
  2650. if(this.over>0)
  2651. {
  2652. var scorers = this.score.getUsers();
  2653. if (scorers.length > 0) {
  2654. let data = {
  2655. _id: this.recordid,
  2656. tableNo: this.id,
  2657. ownerId: this.ownerId,
  2658. type:String(this.type),
  2659. kind: String(this.gameKindTL),
  2660. over: String(this.over),
  2661. round: String(this.round),
  2662. time: String(nowTime),
  2663. ctime: String(this.ctime),
  2664. keep: String(nowTime - this.stime),
  2665. other: this.other,
  2666. playerCount:this.playerAllCount,
  2667. agentId: this.agentId
  2668. };
  2669. let collects = [];
  2670. for (let scorer of scorers) {
  2671. let userscore=scorer.score;
  2672. // if(this.gameKindTL == 2) userscore -= 200;//TL++,因为总的结算界面的每个玩家的分数范围为-200 ~ 600
  2673. collects.push({ chairId:scorer.chairId,name: scorer.name, sex: scorer.sex, headurl: scorer.headurl, score: userscore });
  2674. }
  2675. data.users = _.sortBy(collects, (i) => -i.score);
  2676. //data.sszjFile=this.pjhffileName;
  2677. data.sszj=this.sszjs;
  2678. yield this.pushMsgAsync(-1, 'sxjiang_event', { type: M.TOTAL_CONCLUDE, data: data });////汇总结算
  2679. }
  2680. //console.warn("ts++---------牌局写入");
  2681. yield this.writeResultAsync(endmode);
  2682. }
  2683. //console.warn("ts---------牌局结束");
  2684. for (let user of this.users) {
  2685. if (user) {
  2686. if (user.isOffline())
  2687. {
  2688. user.state = User.STATE.FREE;
  2689. user.state2 = User.STATE.FREE;
  2690. this.leaveUsers.push(user.id);
  2691. ///yield this.game.leaveTableAsync(user.id);
  2692. }
  2693. else
  2694. {
  2695. user.state = User.STATE.FREE;
  2696. user.state2 = User.STATE.FREE;
  2697. }
  2698. }
  2699. }
  2700. }
  2701. if(endmode==ENDMODE.SYSTEMEND)
  2702. {
  2703. yield this.pushMsgAsync(-1, 'sxjiang_event', { type: M.TABLE_JIESAN });
  2704. }
  2705. if(this.leaveUsers.length>0)
  2706. {
  2707. this.app.timer.setTimeout(() => this.leaveUserTimeAsync(), 100);
  2708. }
  2709. this.game.deleteTable(this.id);//ts++删除房间
  2710. // let str5 = "table 结束信息22 关闭-id:"+this.id +"结算模式"+endmode;
  2711. // logger.info(str5);////cssj
  2712. }
  2713. else//普通结束
  2714. {
  2715. // let str5 = "table 结束信息 普通结束---id:"+this.id +"结算模式"+endmode
  2716. // logger.info(str5);////cssj
  2717. this.state = STATE.FREE2;
  2718. for (let user of this.users) {
  2719. if (user) user.state2 = User.STATE.FREE;
  2720. }
  2721. }
  2722. let str7 = "table end 结束信息---id:%s "+this.id +" 结算模式 "+endmode;
  2723. logger.warn(str7);////cssj
  2724. });
  2725. //ts++离开用户退出定时器
  2726. proto.leaveUserTimeAsync = cor(function* () {
  2727. // console.warn("离开用户退出定时器,离开用户数==%d",this.leaveUsers.length);////cssj
  2728. if(this.leaveUsers.length>0)
  2729. {
  2730. let userid = this.leaveUsers[0];
  2731. this.leaveUsers.splice(0, 1);
  2732. let str7 = "table end 离开用户退出定时器---id:%s "+this.id +" userid "+userid;
  2733. logger.warn(str7);////cssj
  2734. yield this.game.leaveTableAsync(userid);
  2735. }
  2736. if(this.leaveUsers.length>0)
  2737. {
  2738. this.app.timer.setTimeout(() => this.leaveUserTimeAsync(), 100);
  2739. }
  2740. });
  2741. // TL++,得到玩家位置
  2742. proto.sendLocationAsync = cor(function* (user,msg) {
  2743. /////设置玩家的经纬度
  2744. user.longitude = msg.longitude; // 经度,浮点数,范围为180 ~ -180。
  2745. user.latitude = msg.latitude; // 纬度,浮点数,范围为90 ~ -90
  2746. let tempData = {
  2747. userId: user.userId,
  2748. account: user.account,
  2749. longitude: msg.longitude,
  2750. latitude: msg.latitude
  2751. }
  2752. //////向其他玩家广播该玩家位置
  2753. yield this.pushMsgAsync(-1, 'sxjiang_event', { type: M.COAST_PLAYERLOCATION, data: tempData });
  2754. return { code: C.OK, data: tempData };
  2755. });
  2756. // 玩家信息
  2757. proto.roleInfoAsync = cor(function* (chairId) {
  2758. // console.log("玩家信息玩家信息玩家信息");
  2759. var user = this.users[chairId];
  2760. if (!user) {
  2761. return { code: C.FAILD, msg: C.GAME_PARAM_ERROR };
  2762. }
  2763. var data = { userId: '0', ttCount: '0', winCount: '0', noCount: '0', runCount: '0' };
  2764. data.userId =user.userId;
  2765. return { code: C.OK, data: data };
  2766. });
  2767. //ts++请求结束定时器
  2768. proto.overTimeAsync = cor(function* (endmode) {
  2769. yield this.pushMsgAsync(-1, 'sxjiang_event', { type: M.TABLE_JIESAN });
  2770. let str6 = "table 请求结束定时器---id: "+this.id +" ,endmode: "+endmode
  2771. logger.warn(str6);////cssj
  2772. yield this.endResultAsync(endmode);//ts++ 房主解散 写分
  2773. });
  2774. // 请求结束
  2775. proto.overTableAsync = cor(function* (user) {
  2776. // console.warn("ts+++++请求结束",user.chairId);
  2777. let str3 = "table 请求结束.......id: "+ this.id + " user.chairId: " + user.chairId + " user.name: " + user.name ;
  2778. logger.warn(str3);////cssj
  2779. if(this.state == STATE.END)
  2780. {
  2781. this.leaveAsync(user);
  2782. return { code: C.OK, data:{jieSanType: 2}};//离开房间
  2783. }
  2784. if(this.reqJieSan.indexOf(2) != -1) return;/////有发起人的时候
  2785. // console.warn("2222请求结束请求结束请求结束",this.reqJieSan);
  2786. //解散桌子数据,前面为chirid后面为情况-1:未操作 0:拒绝 1:同意 2为解散发起
  2787. //jieSanType =1:游戏开始前房主申请解散 =2:游戏开始前非房主玩家退出房间 =3:游戏过程中玩家申请解散 =4游戏过程中是房主但没参与游戏退出房间 =5其他
  2788. if(this.gameNeverStart) {//游戏是否从未开始过,用于解散房间判断
  2789. if(user.userId == this.ownerUid){
  2790. yield this.pushMsgAsync(-1, 'sxjiang_event', { type: M.TABLE_JIESAN });
  2791. // let str5 = "table 房主解散-id:"+this.id+ ",uid"+user.userId;
  2792. // logger.info(str5);////cssj
  2793. yield this.endResultAsync(ENDMODE.OWNEREND);//ts++ 房主解散 写分
  2794. return { code: C.OK, data:{jieSanType: 1}};
  2795. }
  2796. else{
  2797. this.leaveAsync(user);
  2798. return { code: C.OK, data:{jieSanType: 2}};//离开房间
  2799. }
  2800. }
  2801. else
  2802. {
  2803. let chairId=user.chairId;
  2804. if(chairId >= 0 && chairId < 4 )
  2805. {
  2806. if(this.overFlag==0)//发起
  2807. {
  2808. this.overFlag = 1;
  2809. this.reqJieSan[0]=-1;
  2810. this.reqJieSan[1]=-1;
  2811. this.reqJieSan[2]=-1;
  2812. this.reqJieSan[3]=-1;
  2813. this.reqJieSan[chairId]=2;
  2814. let jsdata = [];//ts++实时本局成绩
  2815. jsdata[0] = this.reqJieSan[0];
  2816. jsdata[1] = this.reqJieSan[1];
  2817. jsdata[2] = this.reqJieSan[2];
  2818. jsdata[3] = this.reqJieSan[3];
  2819. this.JSFJTime = 60;//////解散倒计时60秒
  2820. if (!this.overTimer) this.overTimer = this.app.timer.setTimeout(() => this.overTimeAsync(ENDMODE.REGEND),this.JSFJTime*1000);//解散倒计时60秒
  2821. yield this.pushMsgAsync(-1, 'sxjiang_event', { type: M.REQUEST_END, data: { chairId: String(chairId),time: this.JSFJTime,jsdata:jsdata}});
  2822. return { code: C.OK, data:{jieSanType: 3}};
  2823. }
  2824. else//同意
  2825. {
  2826. return this.agreeOverAsync(chairId);
  2827. }
  2828. }
  2829. else
  2830. {
  2831. return { code: C.FAILD, msg: C.TABLE_ALREADY_SQJS };
  2832. }
  2833. }
  2834. return { code: C.OK, data:{jieSanType: 5}};
  2835. });
  2836. // 拒绝结束
  2837. proto.refuseOverAsync = cor(function* (user) {
  2838. let str3 = "table 拒绝结束.......id: "+ this.id + " user.chairId: " + user.chairId + " user.name: " + user.name ;
  2839. logger.warn(str3);////cssj
  2840. if(this.state == STATE.END)
  2841. {
  2842. this.leaveAsync(user);
  2843. return { code: C.OK, data:{jieSanType: 2}};//离开房间
  2844. }
  2845. if(this.overFlag == 0) //ts++已经拒绝了
  2846. {
  2847. return { code: C.OK };
  2848. }
  2849. this.overFlag = 0;
  2850. let chairId=user.chairId;
  2851. // console.error("ts++----------拒绝结束",chairId);
  2852. this.reqJieSan[chairId]=0;//解散桌子数据,前面为chirid后面为情况-1:未操作 0:拒绝 1:同意 2为解散发起
  2853. let jsdata = [];//ts++实时本局成绩
  2854. jsdata[0] = this.reqJieSan[0];
  2855. jsdata[1] = this.reqJieSan[1];
  2856. jsdata[2] = this.reqJieSan[2];
  2857. jsdata[3] = this.reqJieSan[3];
  2858. if (this.overTimer) {
  2859. clearTimeout(this.overTimer);
  2860. this.overTimer = null;
  2861. }
  2862. yield this.pushMsgAsync(-1, 'sxjiang_event', { type: M.REFUSE_END, data: { chairId: String(chairId),time: 0,jsdata:jsdata} });
  2863. //this.reqJieSan = [[-1,-1],[-1,-1],[-1,-1],[-1,-1]];/////解散桌子数据,前面为chirid后面为情况-1:未操作 0:拒绝 1:同意 2为解散发起
  2864. this.reqJieSan[0]=-1;
  2865. this.reqJieSan[1]=-1;
  2866. this.reqJieSan[2]=-1;
  2867. this.reqJieSan[3]=-1;
  2868. return { code: C.OK };
  2869. });
  2870. // 同意结束
  2871. proto.agreeOverAsync = cor(function* (user) {
  2872. let str3 = "table 同意结束.......id: "+ this.id + " user.chairId: " + user.chairId + " user.name: " + user.name ;
  2873. logger.warn(str3);////cssj
  2874. if(this.state == STATE.END)
  2875. {
  2876. this.leaveAsync(user);
  2877. return { code: C.OK, data:{jieSanType: 2}};//离开房间
  2878. }
  2879. if(this.overFlag == 0) //ts++已经拒绝了
  2880. {
  2881. return { code: C.OK };
  2882. }
  2883. let chairId=user.chairId;
  2884. // console.error("ts++----------同意结束",chairId);
  2885. this.reqJieSan[chairId] = 1;/////解散桌子数据,前面为chirid后面为情况-1:未操作 0:拒绝 1:同意 2为解散发起
  2886. let jsdata = [];//ts++实时本局成绩
  2887. jsdata[0] = this.reqJieSan[0];
  2888. jsdata[1] = this.reqJieSan[1];
  2889. jsdata[2] = this.reqJieSan[2];
  2890. jsdata[3] = this.reqJieSan[3];
  2891. this.JSFJTime -= 20;//////解散房间倒计时60秒
  2892. yield this.pushMsgAsync(-1, 'sxjiang_event', { type: M.AGREE_END, data: { chairId: String(chairId),time: this.JSFJTime,jsdata:jsdata} });
  2893. let jsFlag = 0;
  2894. for (let i = 0; i < 4; ++i)
  2895. {
  2896. if(this.reqJieSan[i] >=1 )
  2897. {
  2898. jsFlag+=1;
  2899. }
  2900. }
  2901. if(jsFlag>=this.ccount || this.JSFJTime<=0)
  2902. {
  2903. if(this.backStartTimer)
  2904. {
  2905. clearTimeout(this.backStartTimer);
  2906. this.backStartTimer = null;
  2907. }
  2908. yield this.pushMsgAsync(-1, 'sxjiang_event', { type: M.TABLE_JIESAN });
  2909. // let str4 = "table 全部同意结束-id:%s"+this.id + ",uid"+user.userId+",state"+ this.state;
  2910. // logger.info(str4);////cssj
  2911. yield this.endResultAsync(ENDMODE.REGEND);//ts++ 结束
  2912. }
  2913. else
  2914. {
  2915. if (this.overTimer) {
  2916. clearTimeout(this.overTimer);
  2917. this.overTimer = null;
  2918. }
  2919. if (!this.overTimer) this.overTimer = this.app.timer.setTimeout(() => this.overTimeAsync(ENDMODE.REGEND),this.JSFJTime*1000);//解散倒计时60秒
  2920. }
  2921. // let str3 = "table end 同意结束-id:"+this.id + ",uid"+user.userId+",state"+ this.state;
  2922. // logger.info(str3);////cssj
  2923. return { code: C.OK, data: { chairId: String(chairId),time: this.JSFJTime, jieSanType: 1 }};
  2924. });
  2925. //////TL++,设置记录游戏过程中的记录数据
  2926. proto.setPaijuHuiFangData = function (_operateKind,_data){
  2927. let data = this.logic.deepCloneTL(_data);
  2928. data.operateKind = _operateKind;
  2929. this.PaijuHuiFang[this.PaijuHuiFang.length] = data;
  2930. };
  2931. // 得到玩家位置
  2932. proto.getLocationAsync = cor(function* () {
  2933. let location = [];
  2934. // 桌上玩家
  2935. for (let i = 0; i < this.users.length; ++i) {
  2936. let user = this.users[i];
  2937. if (user) {
  2938. location.push({
  2939. chairId: user.chairId,
  2940. longitude: user.longitude,
  2941. latitude: user.latitude,
  2942. headurl: user.headurl,
  2943. name: user.name
  2944. });
  2945. }
  2946. }
  2947. // console.warn("ts+++++玩家位置",location);
  2948. return { code: C.OK, data: location };
  2949. });