| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193 |
- 'use strict';
- var util = require('util');
- var quick = require('quick-pomelo');
- var P = quick.Promise;
- var cor = P.coroutine;
- var _ = require('lodash');/////是一个一致性、模块化、高性能的 JavaScript 实用工具库。
- //// 为什么选择 Lodash ?
- //// Lodash 通过降低 array、number、objects、string 等等的使用难度从而让 JavaScript 变得更简单。
- //// Lodash 的模块化方法 非常适用于:
- //// 遍历 array、object 和 string
- //// 对值进行操作和检测
- //// 创建符合功能的函数
- var uuid = require('node-uuid');
- var Logic = require('./logic');
- var User = require('./user');
- var Score = require('./score');
- var conf = require('../config/games').sxjiang || {};
- var M = require('../../share/message');
- var C = require('../../share/constant');
- var paiJuHuiFang = require('../../share/paiJuHuiFang');//////TL++ 牌局回放
- var logger = quick.logger.getLogger('fhmj', __filename);
- // 桌子状态
- var STATE = { FREE: 1, PLAYING: 2, FREE2: 3 , END: 4};//ts++REFREE 二次空闲 END结束
- // 结算模式
- var MODE = { NORMAL: 1, NOCARD: 2, OFFLINE: 3 };
- //ts++结束模式 空闲0,游戏中1, 正常结束3,房主解散3,断线解散4,断线解散5,系统解散6
- var ENDMODE = { FREE: 0,PLAYING: 1, OWNEREND: 2,NORMALEND: 3,REGEND: 4, OFFLINEEND: 5, SYSTEMEND: 6 };
- // 金币消耗
- const COSTS = conf.sit_costs || {};
- /////TL++,下面这几行为了记录用户行为
- // var log4js2 = require("log4js");////cssj
- // var log4js_config2 = require("./logConf.json");
- // log4js2.configure(log4js_config2);
- // var LogFile2 = log4js2.getLogger('log_file');////cssj
- // 构造方法
- var Table = function (cPlayerId,cUserId,cName,cHead,game, id, cell, round, type,gameKindTL,playerAllCount,upId,other,agentId) {
- let str3 = "table构造方法.......id: "+id + " type " + type;
- logger.warn(str3);////cssj
- this.app = game.app;
- this.game = game;
- this.id = id;
- this.recordid = uuid.v1()+'_'+id;//ts++唯一记录
- this.upId = upId;//ts++上局的ID
- this.type = type;
- this.agentId=agentId;
- var num_cost = 50;
- // if(gameKindTL == 2){
- // //num_cost = 50;//////冲刺扣50
- // num_cost =parseInt(COSTS[1]);
- // }
- // else
- // {
- num_cost =parseInt(COSTS[round]);
- // }
- this.other = other;//////TL++2人3人的游戏规则
- console.warn("222创建房间的other",other,this.other," gameKindTL ",gameKindTL," type " ,type);
- this.jiangmaType = -1;////奖码类型:-1:不奖码,1:159奖码,2:摸几奖几,3:一码全中
- this.jiangmaCount = -1;////奖码张数
- if(this.other & 1){
- this.jiangmaType = 1;
- if(this.other & 8) this.jiangmaCount = 2;
- else if(this.other & 16) this.jiangmaCount = 4;
- else if(this.other & 32) this.jiangmaCount = 6;
- }
- else if(this.other & 2){
- this.jiangmaType = 2;
- this.jiangmaCount = 0;
- }
- else if(this.other & 4){
- this.jiangmaType = 3;
- this.jiangmaCount = 1;
- }
- this.hzCount = 0;/////红中个数
- if(this.other & 64) this.hzCount = 4;
- else if(this.other & 1024) this.hzCount = 6;
- else if(this.other & 2048) this.hzCount = 8;
- this.isQGHJM = false;/////是否抢杠胡奖码
- if(this.other & 128) this.isQGHJM = true;
- this.isHZHG = false;/////是否荒庄荒杠
- if(this.other & 256) this.isHZHG = true;
- this.isWGHZJYM = false;/////无红中胡加一码
- if(this.other & 512) this.isWGHZJYM = true;
- this.isZNZM = this.type == 2;/////是否只能自摸,拉杠情况可以胡
- // console.warn("奖码类型:-1:不奖码,1:159奖码,2:摸几奖几,3:一码全中 "+this.jiangmaType)
- // console.warn("奖码张数 "+this.jiangmaCount)
- // console.warn("红中个数 "+this.hzCount)
- // console.warn("是否抢杠胡奖码 "+this.isQGHJM)
- // console.warn("是否荒庄荒杠 "+this.isHZHG)
- // console.warn("无红中胡加一码 "+this.isWGHZJYM)
- // console.warn("是否只能自摸 "+this.isZNZM)
- this.cost = num_cost;
- this.over = 0;
- this.round = round;
- this.stime = 0;
- this.ctime = Date.now();
- // 人数
- this.ccount = playerAllCount;//Logic.CHAIR_COUNT;
- this.mcount = Logic.CARDS_COUNT;
- // 房主
- this.ownerChairId = -1;//房主的chairid
- this.ownerId = cPlayerId;//房主Id
- this.ownerUid = cUserId;//房主的userID
- this.ownerName = cName;
- this.ownerHeadUrl = cHead;
- // 数据
- var logic = new Logic(type,gameKindTL,playerAllCount,other);
- this.logic = logic;
- this.score = new Score(this);
- this.handCards = Array(this.ccount);
- this.huCards = logic.fillDeep(Array(this.ccount), []);
- this.users = Array(this.ccount);
- this.chBanker = 0;
- this.quFeng = 0;
- this.bankFlag = 0;
- this.outCards = logic.fillDeep(Array(this.ccount), []);
- // 标记
- this.isDihus = _.fill(Array(this.ccount), true);
- this.isTianhu = true;
- this.outCard = 0;
- this.outerId = -1;
- this.disCards = [];
- this.currentId = -1;
- // 包含字,总杠次,保留量
- // this.hasWords = !(type & 2);/////TL++zs
- // this.hasWords = true;/////是否含有字牌/////TL++
- this.gonCount = 0;
- // this.disCounts = [26, 14, 16, 26];/////TL++zs
- // this.disCounts = [1,1,1,1,];
- // 允许吃牌
- this.hasEat = false;//!!(type & 4);////是否可吃牌
- // 允许点炮
- this.hasEHu = true;///!!(type & 8);
- // 一炮多响
- this.isMHu = true;//!!(type & 16);
- // 允许杠胡
- this.hasGHu = true;///!!(type & 32);
- // 点炮出钱
- this.isWOne = true;//!!(type & 64);
- // 权限:16-胡,8-杠,4-碰,2-吃,1-等待,0-无
- this.masks = _.fill(Array(this.ccount), 0);
- this.excepts = logic.fillDeep(Array(this.ccount), {});
- // 等待杠类型,1-普通杠, 2-暗杠, 3-自摸明杠
- this.gangType = 0;
- this.gangCard = 0;
- // 抢杠胡、被杠玩家
- this.isGangHu = false;
- this.gangOuter = -1;
- // 等待吃类型,1-@**左吃, 2-*@*中吃, 3-@**右吃
- this._eatType = 0;
- // 胡牌者
- this.anams = Array(this.ccount);
- this.huRes = Array(this.ccount);
- this.winner = { lead: -1, chs: [] };
- // 底分
- this.cell = cell;
- // 围观者
- this.lookers = [];
- //结束时的继线用户
- this.leaveUsers = [];
- // 状态
- this.state = STATE.FREE;
- // 申请结束标记
- this.overFlag = 0;
- this.overTimer = null;
- this.endTableTime = 60;//////TL++,申请解散房间之后60秒之后不操作则认为同意解散
- this.reqJieSan = [-1,-1,-1,-1];/////解散桌子数据,前面为chirid后面为情况-1:未操作 0:拒绝 1:同意 2为解散发起
- //断线 结束定时器
- this.endTimer = null;
- //////以下全为TL++
- /////TL++,补花定时器,防止连续补花太快
- this.PJHF = new paiJuHuiFang();
- // this.buhuaTimeout = null;
- this.backStartTimer = null;//////重入之后系统会自动准备为了解决可能没牌的问题2秒之后才开始游戏
- this.PaijuHuiFang = [];////TL++,牌局回放
- // this.zhyzfgs = [-2,null,null];/////TL++,由于最后一张牌的摸牌被打断所以 用来记录最后一张牌的发牌函数的参数
- // this.isLianGang = [-1,false,-1];/////TL++,连杠的玩家座位号,是否连杠 杠的牌
-
- this.isYJJSGL = false;/////是否已经执行过结算函数了
- this.isYJKSGL = false;/////是否已经执行过开始函数了
- this.JSFJTimeout = null;//解散房间倒计时
- this.JSFJTime = 60;//解散房间倒计时60秒
- this.gameNeverStart = true;//游戏是否从未开始过,用于解散房间判断
- this.pjhffileName = [];//用于记录玩家牌局回放的json文件名
- this.playerPosList = [[],[],[],[]];//记录玩家的位置信息数组
- this.gameKindTL = gameKindTL || 1;//平搓还是冲刺 = 1代表平搓 = 2代表冲刺
- this.playerAllCount = playerAllCount || 4;//游戏人数 = 2表示2人局 = 3表示3人局 = 4表示4人局
- this.isNeverStart = true;//游戏是否从未开始
- this.sszjDataList = [];//设置实时战绩的数据
- this.isEveryZZ = false;//是否每一个人都做过庄
- // this.isZJYG = false;////本局庄家是否有杠
- this.chairArry = [0,1,2,3];//
- // this.isNeverTounchHU = false;/////是否从未点击过胡按钮
- this.sszjs = [];//ts++实时战绩
- this.LWKF = [0,0,10,0,10];//////TL++礼物扣费
- this.isGameOk=false;//ts++牌局正常结束
- this.agentRebate=0;//ts++本局的返利
- //代理返利比例
- this.rEBATERATE=1;//业绩模式必须为100% 0.5;
- };
- // 导出状态
- Table.STATE = STATE;
- //ts++ 结束模式
- Table.ENDMODE = ENDMODE;
- // 导出类
- module.exports = Table;
- // 原型对象
- var proto = Table.prototype;
- // 是否站满
- proto.isFull = function () {
- return (this.lookers.length >= 5);
- };
- // 是否准备
- proto.isReady = function () {
- for (let user of this.users) {
- if (!user || !user.isReady()) return false;
- }
- return true;
- };
- // ts++是否二次准备
- proto.isReady2 = function () {
- for (let user of this.users) {
- if (!user || !user.isReady2()) return false;
- }
- return true;
- };
- // 是否游戏中
- proto.isPlaying = function () {
- return this.state > STATE.FREE;
- };
- // 是否全在线
- proto.isOnline = function () {
- for (let user of this.users) {
- if (user && user.isOffline()) return false;
- }
- return true;
- };
- // 是否全断线
- proto.isOffline = function () {
- for (let user of this.users) {
- if (!user || !user.isOffline()) return false;
- }
- return true;
- };
- // 是否空桌
- proto.isEmpty = function () {
- if (this.lookers.length > 0) return false;
- for (let i = 0; i < this.users.length; ++i) {
- if (this.users[i]) return false;
- }
- return true;
- };
- // 局数完成
- proto.isGameOver = function () {
- let str3 = "table 局数完成 .......id: "+ this.id + " this.over " + this.over;
- logger.warn(str3);////cssj
- return (this.over >= this.round);
- };
- // 重置本局
- proto.resetRound = function () {
- _.fill(this.handCards, null);
- _.fill(this.isDihus, true);
- this.isTianhu = true;
- _.fill(this.masks, 0);
- this.logic.fillDeep(this.excepts, {});
- _.fill(this.huRes, null);
- this.gonCount = 0;
- this.winner.chs = [];
- this.winner.lead = -1;
- this.logic.fillDeep(this.huCards, []);
- this.logic.fillDeep(this.outCards, []);
- this.outCard = 0;
- this.outerId = -1;
- this.currentId = -1;
- this._eatType = 0;
- this.gangType = 0;
- this.gangCard = 0;
- this.isGangHu = false;
- this.gangOuter = -1;
-
- };
- // 发送消息
- proto.pushMsgAsync = cor(function* (cidOrIds, route, msg) {
- // console.warn("444WWWWWWWTTTTTT",cidOrIds, route, msg);
- var playerIds = [];
- if (Array.isArray(cidOrIds)) playerIds = cidOrIds;
- else {
- if (cidOrIds < 0 || cidOrIds >= this.users.length) {
- for (let user of this.users) {
- if (user) playerIds.push(user.id);
- }
- for (let lker of this.lookers) {
- playerIds.push(lker.id);
- }
- } else {
- let user = this.users[cidOrIds];
- if (user) playerIds.push(user.id);
- // console.warn("555WWWWWWWTTTTTT",cidOrIds, route, user.name);
- }
- }
- if (playerIds.length > 0) {
- let channelId = 'xct:' + this.id;
- // console.warn("666WWWWWWWTTTTTT",cidOrIds, route, playerIds,msg);
- return this.app.controllers.push._pushAsync(channelId, playerIds, route, msg);
- }
- });
- // 围观消息
- proto.lookMsgAsync = cor(function* (route, msg) {
- var playerIds = [];
- for (let lker of this.lookers) {
- playerIds.push(lker.id);
- }
- if (playerIds.length > 0) {
- let channelId = 'xct:' + this.id;
- return this.app.controllers.push._pushAsync(channelId, playerIds, route, msg);
- }
- });
- // 获得桌子信息
- proto.getTableInfo = function () {
- // 桌子信息
- var tableInfo = {
- id: this.id,
- type: this.type,
- cost: this.cost,
- over: this.over,
- round: this.round,
- users: [],
- lookers: [],
- ownerId: -1,//this.ownerChairid
- ownerUserId: this.ownerUid,////TL++,房主的userID
- ownerName: this.ownerName,//////TL++,房主的昵称
- ownerHeadUrl: this.ownerHeadUrl,//////TL++,房主的头像地址
- gameKindTL: this.gameKindTL,////平搓还是冲刺 = 1代表平搓 = 2代表冲刺
- playerAllCount: this.playerAllCount,////游戏人数 = 2表示2人局 = 3表示3人局 = 4表示4人局
- other: this.other,
- creatTime : this.ctime,
- state: this.state,
- sszjDataList: this.sszjDataList,////TL++,设置实时战绩的数据
- isZHYZ: this.logic.isZHYZ, /////TL++,是否最后一张
- playerPosList: this.playerPosList,/////TL++玩家位置数据
- chairArry: this.chairArry,/////TL++
- isNeverStart: this.isNeverStart,/////TL++,游戏是否从未开始
- overFlag:this.overFlag,//ts++房间解散标识
- endTableTime:this.endTableTime,
- recordid:this.recordid,
- reqJieSan:this.reqJieSan
- };
- // 正在游戏
- var isPlaying = this.isPlaying();
- if (isPlaying) {
- tableInfo.qFeng = this.quFeng;
- tableInfo.banker = this.chBanker;
- tableInfo.stime = Date.now() - this.stime;
- tableInfo.currentId = this.currentId;
- tableInfo.disCards = this.disCards;
- tableInfo.lastCount = this.logic.leaveCount();
- tableInfo.isGangHu = this.isGangHu;
- tableInfo.gangCard = this.gangCard;
- //////TL++,游戏过程中重入
- tableInfo.baiDaCard = String(this.logic.baiDaCard);//////TL++,本局百搭牌
- tableInfo.everyFllowerCardList = [[],[],[],[]]; /////每个人手上的花牌
- //////TL++ end,游戏过程中重入
- }
- // 桌上玩家
- for (let i = 0; i < this.users.length; ++i) {
- let user = this.users[i];
- if (user) {
- let score = this.score.getScore(user.id);
- let uinfo = {
- account: user.account, name: user.name, sex: user.sex, headurl: user.headurl,
- state: user.state2, score: score, chairId: user.chairId
- };
- if (isPlaying) {
- let huCards = [];
- for (let huCard of this.huCards[i]) {
- huCards.push({ style: huCard.style, type: huCard.type, card: huCard.cards[0], origin: huCard.origin });
- }
- uinfo.huCards = huCards;
- uinfo.outCards = this.outCards[i];
- let handCard = this.handCards[i] || [];
- uinfo.handCount = handCard.length;
- }
- tableInfo.users.push(uinfo);
- }
- }
- // 围观玩家
- for (let i = 0; i < this.lookers.length; ++i) {
- let user = this.lookers[i];
- if (user) {
- tableInfo.lookers.push({ account: user.account, name: user.name, sex: user.sex, headurl: user.headurl });
- }
- }
- return tableInfo;
- };
- // 回到桌子
- proto.backAsync = cor(function* (user) {
- let str3 = "table回到桌子.......id: "+ this.id + " user.chairId: " + user.chairId + " user.name: " + user.name ;
- logger.warn(str3);////cssj
- user.offlinetime=0;//ts++
- var data = { chairId: String(user.chairId) };
- var chairId = user.chairId;
- let isGuoHuList = [[false,0],[false,0],[false,0],[false,0],];
- if (chairId != -1) {
- // 加入频道
- var connectorId = user.connectorId || '';
- if (connectorId) {
- let channelId = 'xct:' + this.id;
- yield this.app.controllers.push._joinAsync(channelId, user.id, connectorId);
- }
- // 恢复状态
-
- if (this.state == STATE.FREE) {
- yield this.readyGameAsync(user);
- } else if (this.state == STATE.PLAYING) {
- //user.state = User.STATE.PLAYING;//ts--
- user.state2 = User.STATE.PLAYING;//ts++
- data.mask = String(this.masks[chairId]);
- data.handCards = this.handCards[chairId];
- // 状态通知
- yield this.pushMsgAsync(-1, 'sxjiang_event', { type: M.STATE_CHANGE, data: { chairId: String(user.chairId), state: String(user.state2), state2: String(user.state2) } });
- }else if (this.state == STATE.FREE2) {//ts++二次准备
- //user.state = User.STATE.PLAYING;//ts--
- user.state2 = User.STATE.READY;
- yield this.pushMsgAsync(-1, 'sxjiang_event', { type: M.STATE_CHANGE, data: { chairId: String(user.chairId), state: String(user.state2), state2: String(user.state2) } });
-
- if (this.isReady2() && !this.isGameOk)
- {
- if(!this.backStartTimer){
- this.backStartTimer = this.app.timer.setTimeout(() => this.backStartTimeAsync(), 2 * 1000);//延迟2秒开始游戏
- }
- }
- }
- // 取消计时
- if (this.isOnline() && this.endTimer) {
- clearTimeout(this.endTimer);
- this.endTimer = null;
- }
- isGuoHuList[chairId] = this.logic.isGuoHuList[chairId];
- }
- // 数据处理
- data.fee = this.score.isFeed(user.id) ? '0' : '1';
- data.table = this.getTableInfo();
- let hutipdata = {
- renyi:0,//////是否可胡任意牌,0表示不满足1表示满足
- kehuData:[]/////对象数组,分别表示打哪张可胡哪几张数据
- };
- if(chairId == this.currentId){
- let tipres = this.logic.hutip(this.currentId,this.handCards[this.currentId],this.huCards[this.currentId],this.huCards,this.outCards);////重入时调用胡牌提示
- data.table.hutipdata = tipres;
- }
- else{
- data.table.hutipdata = hutipdata;
- }
- data.table.isGuoHuList = isGuoHuList;
- return { code: C.OK, data: data };
- });
- //ts++重入后自动开始
- proto.backStartTimeAsync = cor(function* () {
- yield this.startGameAsync();
- });
- // 加入桌子
- proto.joinAsync = cor(function* (user) {
- // 撤出删除队列
- //this.game.cancelDelete(this.id);
- // 加入桌子之前
- yield this.beforeJoinAsync(user);
- // 加入围观者
- this.lookers.push(user);
- // 加入桌子之后
- yield this.afterJoinAsync(user);
- // 数据返回处理
- var data = { chairId: String(user.chairId) };
- data.fee = this.score.isFeed(user.id) ? '0' : '1';
- data.table = this.getTableInfo();
- return { code: C.OK, data: data };
- });
- // 加入桌子之前
- proto.beforeJoinAsync = cor(function* (user) {
- var connectorId = user.connectorId || '';
- if (connectorId) {
- let channelId = 'xct:' + this.id;
- return this.app.controllers.push._joinAsync(channelId, user.id, connectorId);
- }
- });
- // 加入桌子之后
- proto.afterJoinAsync = cor(function* (user) {
- // 加入通知
- return this.pushMsgAsync(-1, 'sxjiang_event', {
- type: M.JOIN, data: { account: user.account, userId: user.userId, name: user.name, sex: user.sex, headurl: user.headurl,playerPosList: this.playerPosList }
- });
- });
- // 坐下桌子
- proto.seatAsync = cor(function* (user, chairId) {
- // let chairId = this.chairArry[_chairId];
- // console.warn("坐下桌子不不vvvvvv",chairId,_chairId,this.chairArry,this.users.length);
- // 参数校验
- if (chairId < 0 || chairId >= this.ccount) {
- return { code: C.FAILD, msg: C.CHAIR_NOT_FOUND };
- }
- if (this.users[chairId]) {
- // console.warn("坐下桌子死了vv000",this.users[chairId]);
- // console.warn("坐下桌子死了vvvvvv",this.users.length,this.users);
- return { code: C.FAILD, msg: C.CHAIR_HAS_SOMEONE };
- }
-
- // 查找玩家
- var player = yield this.app.models.Player.findByIdAsync(user.id, 'diamond cost');
- if (!player) {
- return { code: C.FAILD, msg: C.PLAYER_NOT_FOUND };
- }
- if (this.users[chairId]) {
- return { code: C.FAILD, msg: C.CHAIR_HAS_SOMEONE };
- }
- // 调换座位
- if (user.chairId != -1) {
- return this.changeChairAsync(user, chairId);
- }
- // 围观玩家
- var pos = _.findIndex(this.lookers, (u) => (u.id == user.id));
- if (pos == -1) {
- return { code: C.FAILD, msg: C.TABLE_NOT_USER };
- }
- //ts++
- let dSource=player.diamond;
- let dNow=player.diamond;
- //坐下花费
- var costdata = null;
- if (!this.score.isFeed(user.id)) {
- if (player.diamond < this.cost) {
- return { code: C.FAILD, msg: C.GAME_DIAMOND_LOW };
- }//////TL++zsyl 1000局测完之后要放出来的
- player.diamond -= this.cost;
- player.cost = (player.cost || 0) + this.cost;
- dNow-=this.cost;
- this.score.addUser(user.id,chairId,user.userId, user.name, user.sex, user.headurl,user.diamond,this.gameKindTL);
- costdata = { cost: String(this.cost) };
- }
- // 坐下处理
- this.lookers.splice(pos, 1);
- this.users[chairId] = user;
- user.chairId = chairId;
- user.state = User.STATE.READY;
- yield this.afterSeatAsync(user);
- if (player.isModified())
- {
- yield player.saveAsync();/////只有第一次坐下的时候才会执行
- // 钻石记录
- var diamondrecord = new this.app.models.DiamondRecord({
- _id: uuid.v1(),
- playerId: user.id,
- dType: 3,//坐下
- dSource: dSource,
- dSwap: -1*this.cost,
- dNow: dNow,
- tableId: this.recordid
- });
- yield diamondrecord.saveAsync();
- // console.warn("ts++坐下-------------------钻石记录");
- if (costdata) yield this.pushMsgAsync(chairId, 'sxjiang_event', { type: M.COST_FEE, data: costdata });
- }
-
- // if (this.isReady()) yield this.pushMsgAsync(this.ownerChairid, 'sxjiang_event', { type: M.START_BUTTON });//////TL++zsyl所有人准备之后通知房主点击开始游戏
- if (this.state == STATE.FREE && this.isReady() && !this.isGameOk) {
- yield this.randomChangeChairTL();
- }
- return { code: C.OK, chairId: String(chairId) };
- });
- // 调换座位 自己坐下之后点击另外一个位子的时候调用这个方法 这个参数user输出之后相当的长
- proto.changeChairAsync = cor(function* (user, chairId) {
- if (this.state != STATE.FREE) {
- return { code: C.FAILD, msg: C.TABLE_NOT_FREE };
- }
- if (this.users[chairId]) {
- return { code: C.FAILD, msg: C.CHAIR_HAS_SOMEONE };
- }
- // var _chairId = user.chairId;
- // delete this.users[_chairId];
- // this.users[chairId] = user;
- // user.chairId = chairId;
- // user.state = User.STATE.READY;
- // yield this.pushMsgAsync(-1, 'sxjiang_event', { type: M.CHAIR_CHANGE, data: { oldId: String(_chairId), newId: String(chairId), state: String(user.state), state2: String(user.state2) } });
- // // if (this.ownerChairid == _chairId) {
- // // this.ownerChairid = chairId;
- // // // 换房主通知
- // // yield this.pushMsgAsync(-1, 'sxjiang_event', { type: M.OWNER_CHANGE, data: { ownerChairid: String(this.ownerChairid) } });
- // // }
- return { code: C.OK, chairId: String(chairId) };
- });
- // 坐下桌子之后
- proto.afterSeatAsync = cor(function* (user) {
- let posListTL = {
- chairId: user.chairId,
- headurl: user.headurl,
- longitude: user.longitude, // 经度,浮点数,范围为180 ~ -180。
- latitude: user.latitude, // 纬度,浮点数,范围为90 ~ -90
- }
- this.playerPosList[user.chairId] = posListTL/////TL++记录玩家的位置信息数组
- // 坐下通知
- let score = this.score.getScore(user.id);
- yield this.pushMsgAsync(-1, 'sxjiang_event', {///////发送坐下
- type: M.SEAT, data: {
- account: user.account,
- name: user.name,
- sex: user.sex,
- headurl: user.headurl,
- state: String(user.state),
- score: String(score),
- chairId: String(user.chairId),
- userId: String(user.userId),
- playerPosList: this.playerPosList, /////TL++记录玩家的位置信息数组
- }
- });
-
- });
- //////TL++,在首次游戏开始的时候随机打乱用户的座位
- proto.randomChangeChairTL = cor(function* () {
- // console.warn("111在首次游戏开始的时候随机打乱用户的座位",this.users[0].name,this.users[1].name,this.users[2].name,this.users[3].name);
- // console.warn("1在首次游戏开始的时候随机打乱用户的座位",this.users[0].chairId,this.users[1].chairId,this.users[2].chairId,this.users[3].chairId);
- if(this.playerAllCount > 2){
- let changeResult = [];
- if (this.over <= 0) {///////本房间开始的第一局游戏
- // for (let i = 0; i < this.ccount; i++) {/////这种随机4次可能会导致4次随机之后和打乱之前的顺序一样所以弃用
- for (let i = 0; i < 1; i++) {
- let oldchaieID = i;
- let olduser = this.users[i];
- let newchaieID = Math.floor(Math.random()*this.playerAllCount);////// 区间[0,3]取整数
- while (newchaieID == oldchaieID) {
- newchaieID = Math.floor(Math.random()*this.playerAllCount);////// 区间[0,3]取整数
- }
- let newuser = this.users[newchaieID];
- // console.warn("222在首次游戏开始的时候随机打乱用户的座位",oldchaieID,newchaieID);
- // console.warn("xxxxxxxxx删除有没有用啊",this.users.length);
- delete this.users[newchaieID];
- delete this.users[oldchaieID];
- // console.warn("xxxxxxxxx22删除有没有用啊",this.users.length);
- this.users[newchaieID] = olduser;
- this.users[newchaieID].chairId = newchaieID;
- // this.users[newchaieID].id = newuser.id;
- this.users[oldchaieID] = newuser;
- this.users[oldchaieID].chairId = oldchaieID;
- // this.users[oldchaieID].id = olduser.id;
- changeResult.push([oldchaieID,newchaieID])
- }
-
- // console.warn("333在首次游戏开始的时候随机打乱用户的座位",this.users[0].name,this.users[1].name,this.users[2].name,this.users[3].name);
- // console.warn("3在首次游戏开始的时候随机打乱用户的座位",this.users[0].chairId,this.users[1].chairId,this.users[2].chairId,this.users[3].chairId);
- // console.warn("3在首次游戏开始的时候随机打乱用户的座位",this.users[0].id,this.users[1].id,this.users[2].id,this.users[3].id);
- // console.warn("3在首次游戏开始的",this.users[0]);
- ////// this.users 发送给前端会代码报错
- // yield this.pushMsgAsync(-1, 'sxjiang_event', { type: M.CHAIR_DALUAN, data: { changeResult:changeResult } });
- /////TL++
- for (let i = 0; i < this.users.length; ++i) {
- this.score.setUserChair(this.users[i].id,this.users[i].chairId)
- }
- let daluanData = [];
- var isPlaying = this.isPlaying();
- for (let i = 0; i < this.users.length; ++i) {
- let user = this.users[i];
- if (user) {
- let score = this.score.getScore(user.id);
- let uinfo = {
- account: user.account, name: user.name, sex: user.sex, headurl: user.headurl,
- state: user.state, score: score, chairId: user.chairId
- };
- if (isPlaying) {
- let huCards = [];
- for (let huCard of this.huCards[i]) {
- huCards.push({ style: huCard.style, type: huCard.type, card: huCard.cards[0], origin: huCard.origin });
- }
- uinfo.huCards = huCards;
- uinfo.outCards = this.outCards[i];
- let handCard = this.handCards[i] || [];
- uinfo.handCount = handCard.length;
- }
- daluanData.push(uinfo);
- }
- }
- // this.score.delUser(user.id);
- yield this.pushMsgAsync(-1, 'sxjiang_event', { type: M.CHAIR_DALUAN, data: { daluanData:daluanData } });
- }
- }
- // console.warn("444在首次游戏开始的时候随机打乱用户的座位",changeResult);
- // this.starTimer = this.app.timer.setTimeout(() => this.startGameAsync(), 500);
- yield this.startGameAsync()/////TL++,在首次游戏的时候随机打乱用户的座位
- });
- // 站起桌子
- proto.standAsync = cor(function* (user) {
- let str3 = "table 站起桌子.......id: "+ this.id + " user.chairId: " + user.chairId + " user.name: " + user.name ;
- logger.warn(str3);////cssj
- var chairId = user.chairId;
- if (chairId != -1) {
- user.state = User.STATE.FREE;
- delete this.users[chairId];
- delete this.handCards[chairId];
- user.chairId = -1;
- this.lookers.push(user);
- yield this.afterStandAsync(user, chairId);
- }
- return { code: C.OK };
- });
- // 站起桌子之后
- proto.afterStandAsync = cor(function* (user, chairId) {
- // 站起通知
- yield this.pushMsgAsync(-1, 'sxjiang_event', { type: M.STAND, data: { chairId: String(chairId) } });
- //if (this.ownerChairid == -1) this.ownerChairid = -1;//////TL++,房主坐下之后重置房主chairid
- /////TL++,作坐下的玩家离开桌子之后将他的位置信息从位置列表里面删除
- if(chairId != -1) this.playerPosList[chairId] = [];
-
- // 桌主离开
- //////TL++zsyl,原先的这个逻辑是房主站起之后会切换房主
- // if (chairId == this.ownerChairid) {
- // let newCid = _.findIndex(this.users, (user) => user);
- // this.ownerChairid = newCid;
- // if (newCid != -1) this.ownerUid = this.users[newCid].id;
- // // 换房主通知
- // yield this.pushMsgAsync(-1, 'sxjiang_event', { type: M.OWNER_CHANGE, data: { ownerChairid: String(this.ownerChairid) } });
- // }
- //是否退费
- // console.warn("ts++++++++站起桌子之后");
- var scorer = this.score.getUser(user.id);
- if (scorer && scorer.over <= 0) {
- // console.warn("ts++没有开始游戏退分",user.id);
- this.score.delUser(user.id);
- let player = yield this.app.models.Player.findByIdAsync(user.id, 'diamond cost');
- if (player) {
- // console.warn("ts++没有开始游戏退分",player.diamond);
- let dSource=player.diamond;
- let dNow=player.diamond+this.cost;
- player.diamond += this.cost;
- player.cost -= this.cost;
- yield player.saveAsync();
- //return this.app.controllers.player.pushAsync(user.id, 'sxjiang_event', { type: M.BACK_FEE, data: { back: String(this.cost) } });
-
- // 退费 钻石记录
- var diamondrecord = new this.app.models.DiamondRecord({
- _id: uuid.v1(),
- playerId: user.id,
- dType: 4,//退费
- dSource: dSource,
- dSwap: this.cost,
- dNow: dNow,
- tableId: this.recordid
- });
- yield diamondrecord.saveAsync();
- // console.warn("ts++退分-------------------钻石记录");
- //var costdata = { cost: String(-1*this.cost) };
- //if (costdata) yield this.pushMsgAsync(chairId, 'sxjiang_event', { type: M.COST_FEE, data: costdata });
- }
- }
- else
- {
- if(user.cost==0 && user.spreadId)//ts++推荐人奖励
- {
- // let spreader = yield this.app.models.Player.findByIdAsync(user.spreadId, 'spreadCount spreadRebate');
- // if (spreader) {
- // spreader.spreadCount += 1;
- // spreader.spreadRebate += 100;
- // yield spreader.saveAsync();
- // }
- ////20200928因为现在的spreadId存的是userId,所以上面那段用不了了
- let xzdsjc = Date.now();
- if(xzdsjc > 1602172800000 || xzdsjc < 1601481600000){////国庆期间不发放
- var cpopts = {};
- cpopts['userId'] = parseInt(user.spreadId);
- let spreadList = yield this.app.models.Player.findMongoAsync(cpopts, 'spreadCount spreadRebate', { sort: { stime: 1 } });//
- if(spreadList.length == 1){
- spreadList[0].spreadCount += 1;
- spreadList[0].spreadRebate += 100;
- yield spreadList[0].saveAsync();
- }
- }
- }
- if(this.agentId) //正常结束的才能算
- {
- if(this.agentRebate>0)
- {
- //console.warn("代理返利写分+++++");
- let gameCost2=this.agentRebate;//游戏消耗
- let agentRebate2=parseInt(this.agentRebate*this.rEBATERATE);
- this.agentRebate=0;
-
- var today = new Date();
- today.setHours(0);
- today.setMinutes(0);
- today.setSeconds(0);
- today.setMilliseconds(0);
- let nowverifyDate=today.getTime();
-
- var agenter = yield this.app.models.Agenter.findByIdAsync(this.agentId,'rebateOther rebateCount rebateAll rebateNow rebateOut verifyDate verifyRebate dateGameTimes02 dateGameTimes03 dateGameTimes0 dateGameTimes42 dateGameTimes43 dateGameTimes4 dateGameTimes82 dateGameTimes83 dateGameTimes8 dateGameTimes162 dateGameTimes163 dateGameTimes16 dateGameCost0 dateGameCost4 dateGameCost8 dateGameCost16 agentRate');
- if (agenter)
- {
- //日结算
- let verifyBool=false;
- let verifyDate=0;
- let verifyRebate=0;
-
- //日奖励
- let dateAgentRate=0;
- let dateRebate=0;
- let dateGameTimes02=0;
- let dateGameTimes42=0;
- let dateGameTimes82=0;
- let dateGameTimes162=0;
- let dateGameTimes03=0;
- let dateGameTimes43=0;
- let dateGameTimes83=0;
- let dateGameTimes163=0;
- let dateGameTimes0=0;
- let dateGameTimes4=0;
- let dateGameTimes8=0;
- let dateGameTimes16=0;
- let dateGameCost0=0;
- let dateGameCost4=0;
- let dateGameCost8=0;
- let dateGameCost16=0;
- if(agenter.verifyRebate>0 && agenter.verifyDate!=nowverifyDate)
- {
- verifyBool=true;
- verifyDate=agenter.verifyDate;
- verifyRebate=agenter.verifyRebate;
-
- dateAgentRate=agenter.agentRate;
-
- dateGameTimes0=agenter.dateGameTimes0;
- dateGameTimes4=agenter.dateGameTimes4;
- dateGameTimes8=agenter.dateGameTimes8;
- dateGameTimes16=agenter.dateGameTimes16;
- dateGameTimes02=agenter.dateGameTimes02;
- dateGameTimes42=agenter.dateGameTimes42;
- dateGameTimes82=agenter.dateGameTimes82;
- dateGameTimes162=agenter.dateGameTimes162;
- dateGameTimes03=agenter.dateGameTimes03;
- dateGameTimes43=agenter.dateGameTimes43;
- dateGameTimes83=agenter.dateGameTimes83;
- dateGameTimes163=agenter.dateGameTimes163;
- dateGameCost0=agenter.dateGameCost0;
- dateGameCost4=agenter.dateGameCost4;
- dateGameCost8=agenter.dateGameCost8;
- dateGameCost16=agenter.dateGameCost16;
- ////20200801去掉额外返利
- // if(dateAgentRate==10 || dateAgentRate==20 || dateAgentRate==30 || dateAgentRate==40 || dateAgentRate==50)
- // {
- // if(dateGameCost0>0)
- // {
- // dateRebate+=parseInt(dateGameCost0*dateAgentRate/100);
- // }
- // if(dateGameCost4>0)
- // {
- // dateRebate+=parseInt(dateGameCost4*dateAgentRate/100);
- // }
- // if(dateGameCost8>0)
- // {
- // dateRebate+=parseInt(dateGameCost8*dateAgentRate/100);
- // }
- // if(dateGameCost16>0)
- // {
- // dateRebate+=parseInt(dateGameCost16*dateAgentRate/100);
- // }
- // }
- agenter.dateGameTimes0=0;
- agenter.dateGameTimes4=0;
- agenter.dateGameTimes8=0;
- agenter.dateGameTimes16=0;
- agenter.dateGameTimes02=0;
- agenter.dateGameTimes42=0;
- agenter.dateGameTimes82=0;
- agenter.dateGameTimes162=0;
- agenter.dateGameTimes03=0;
- agenter.dateGameTimes43=0;
- agenter.dateGameTimes83=0;
- agenter.dateGameTimes163=0;
- agenter.dateGameCost0=0;
- agenter.dateGameCost4=0;
- agenter.dateGameCost8=0;
- agenter.dateGameCost16=0;
- agenter.rebateNow += verifyRebate;
- agenter.rebateNow += dateRebate;
- agenter.rebateOther += dateRebate;
- agenter.rebateCount += dateRebate;
- agenter.verifyRebate=0;
- }
- //修改代理数据
- agenter.rebateCount += agentRebate2;
- agenter.rebateAll += agentRebate2;
- agenter.verifyDate=nowverifyDate;
- agenter.verifyRebate+= agentRebate2;
- if(this.gameKindTL == 2){
- if(this.ccount==2)
- {
- agenter.dateGameTimes02+=1;
- }
- else if(this.ccount==3)
- {
- agenter.dateGameTimes03+=1;
- }
- else if(this.ccount==4)
- {
- agenter.dateGameTimes0+=1;
- }
- agenter.dateGameCost0+=gameCost2;
- }
- else
- {
- if(this.round == 4){
- if(this.ccount==2)
- {
- agenter.dateGameTimes42+=1;
- }
- else if(this.ccount==3)
- {
- agenter.dateGameTimes43+=1;
- }
- else if(this.ccount==4)
- {
- agenter.dateGameTimes4+=1;
- }
- agenter.dateGameCost4+=gameCost2;
- }
- else if(this.round == 8){
- if(this.ccount==2)
- {
- agenter.dateGameTimes82+=1;
- }
- else if(this.ccount==3)
- {
- agenter.dateGameTimes83+=1;
- }
- else if(this.ccount==4)
- {
- agenter.dateGameTimes8+=1;
- }
- agenter.dateGameCost8+=gameCost2;
- }
- else if(this.round == 16){
- if(this.ccount==2)
- {
- agenter.dateGameTimes162+=1;
- }
- else if(this.ccount==3)
- {
- agenter.dateGameTimes163+=1;
- }
- else if(this.ccount==4)
- {
- agenter.dateGameTimes16+=1;
- }
- agenter.dateGameCost16+=gameCost2;
- }
-
- }
- let rCount=agenter.rebateCount;
- let rOther=agenter.rebateOther;
- let rAll=agenter.rebateAll;
- let rNow=agenter.rebateNow;
- let rOut=agenter.rebateOut;
- let rVerifyDate=agenter.verifyDate;
- let rVerifyRebate=agenter.verifyRebate;
- yield agenter.saveAsync();
- // console.warn("代理返利写分+++++agenter.saveAsync()");
-
- // 锁定返利记录
- if(verifyBool && verifyRebate>0)
- {
- var verifyrebateRecord = new this.app.models.RebateRecord({
- _id: uuid.v1(),
- agentId:this.agentId,
- tableId: '',
- rType: 3,
- rCount: rCount- agentRebate2,
- rOther: rOther,
- rAll: rAll- agentRebate2,
- rNow: rNow,
- rOut: rOut,
- rSwap: verifyRebate,
- rDateSwap: dateRebate,
- rVerifyDate: verifyDate,
- rVerifyRebate: 0
- });
- yield verifyrebateRecord.saveAsync();
- var daterebateRecord = new this.app.models.DateRebateRecord({
- _id: uuid.v1(),
- agentId:this.agentId,
- verifyDate: verifyDate,
- verifyRebate: verifyRebate,
- dateAgentRate: dateAgentRate,
- dateRebate: dateRebate,
- dateGameTimes0: dateGameTimes0,
- dateGameTimes4: dateGameTimes4,
- dateGameTimes8: dateGameTimes8,
- dateGameTimes16: dateGameTimes16,
- dateGameTimes02: dateGameTimes02,
- dateGameTimes42: dateGameTimes42,
- dateGameTimes82: dateGameTimes82,
- dateGameTimes162: dateGameTimes162,
- dateGameTimes03: dateGameTimes03,
- dateGameTimes43: dateGameTimes43,
- dateGameTimes83: dateGameTimes83,
- dateGameTimes163: dateGameTimes163,
- dateGameCost0: dateGameCost0,
- dateGameCost4: dateGameCost4,
- dateGameCost8: dateGameCost8,
- dateGameCost16: dateGameCost16
- });
- yield daterebateRecord.saveAsync();
- }
- // 返利记录
- var rebateRecord = new this.app.models.RebateRecord({
- _id: uuid.v1(),
- agentId:this.agentId,
- tableId: this.recordid,
- rType: 1,
- rCount: rCount,
- rOther: rOther,
- rAll: rAll,
- rNow: rNow,
- rOut: rOut,
- rSwap: agentRebate2,
- rDateSwap: 0,
- rVerifyDate: rVerifyDate,
- rVerifyRebate: rVerifyRebate
- });
- yield rebateRecord.saveAsync();
- // console.warn("返利记录+++++rebateRecord.saveAsync()");
- }
- }
- let gameRebate=0;
- if(this.isGameOk)
- {
- gameRebate=parseInt(this.cost*this.rEBATERATE);
- }
- var today = new Date();
- today.setHours(0);
- today.setMinutes(0);
- today.setSeconds(0);
- today.setMilliseconds(0);
- let date=today.getTime();
- let countid=this.agentId+'-'+user.userId+'-'+date;
- var playercount = yield this.app.models.PlayerCount.findByIdAsync(countid,'gameCount gameCost agentRebate time');
- if (playercount)
- {
- playercount.gameCount+=1;
- playercount.gameCost+=this.cost;
- playercount.agentRebate+=gameRebate;
- playercount.time=Date.now();
- }
- else
- {
- playercount = new this.app.models.PlayerCount({
- _id: countid,
- agentId:this.agentId,
- playerId: user.id,
- userId: user.userId,
- name: user.name,
- date: date,
- gameCount: 1,
- gameCost: this.cost,
- agentRebate: gameRebate,
- time:Date.now()
- });
- }
- yield playercount.saveAsync();
-
- }
- // console.warn("活动奖励 下面开始进行判断 ",user.spreadId,user.registerTime,user.lastLoginTime);
- // let str11 = "hdjl xmksjxpd "+ this.id + " isGameOk: " + this.isGameOk + " userId: " + user.userId + " spreadId: " + user.spreadId + " registerTime: " + user.registerTime + " lastLoginTime: " + user.lastLoginTime ;
- // logger.warn(str11);////cssj
- // if(this.isGameOk && this.ccount == 4 && user.spreadId)//活动奖励
- // {
- // // console.warn("活动奖励 至此是游戏正常结束而且玩家有推荐id",user.spreadId,user.registerTime,user.lastLoginTime);
- // ////正常结束而且该玩家有推荐人id
- // let acSTime = 1601481600000;////20201001零点的时间戳,活动开始时间
- // let acETime = acSTime + 86400000*8;////20201008这天截止的时间戳 活动结束时间
- // let xzsjc = Date.now();
- // let str12 = "hdjl zcyxszcjseqwjytjr "+this.id + " userId: " + user.userId +" xzsjc: "+xzsjc;
- // logger.warn(str12);////cssj
- // if(xzsjc >= acSTime && xzsjc < acETime){
- // if((user.registerTime >= acSTime && user.registerTime < acETime) || user.lastLoginTime < 1598889600000){
- // // console.warn("活动奖励 至此该玩家是新用户",user.spreadId,user.registerTime,user.lastLoginTime);
- // let str13 = "hdjl zcgwjsxyh "+this.id + " userId: " + user.userId;
- // logger.warn(str13);////cssj
- // ////活动期间注册或者9月1号10月1日之间未登陆过的玩家
- // var todayTL = new Date();
- // todayTL.setHours(0);
- // todayTL.setMinutes(0);
- // todayTL.setSeconds(0);
- // todayTL.setMilliseconds(0);
- // let jrldsjc=todayTL.getTime();////今日零点时间戳
- // let jrjssjc=jrldsjc + 86400000;////今日结束时间戳
- // var opts = { stime: { $gte: jrldsjc, $lt: jrjssjc },type: { $gte: 1, $lt: 2 }};
- // opts['sid'] = user.id;
- // let acrlist = yield this.app.models.ActiveRewardRecord.findMongoAsync(opts, '_id rewardtype totalfee type sid rid gameCount stime succtime succState', { sort: { stime: 1 } });//
- // if(acrlist.length == 0){
- // // console.warn("活动奖励 活动期间今日该玩家产生新的记录",user.spreadId,user.registerTime,user.lastLoginTime);
- // let str14 = "hdjl hdqjjrgwjcsxdjl "+this.id + " userId: " + user.userId;
- // logger.warn(str14);////cssj
- // ////活动期间今日该玩家产生新的记录
- // var activerewardrec = new this.app.models.ActiveRewardRecord({
- // _id: uuid.v1(), // UUID
- // rewardtype: 0, // 奖励类型,0红包
- // totalfee: 0, // 产生金额,红包为分
- // type:1, //活动类型:1国庆签到2国庆邀请
- // sid: user.id, // 产生奖励的玩家id
- // sname:user.name, // 产生奖励的玩家name
- // suid:user.userId, // 产生奖励的玩家userId
- // rid: user.id, // 此条奖励的受益玩家
- // gameCount: 1, // 游戏局数
- // stime: xzsjc, // 记录产生时间
- // succtime: 0, // 任务完成时间,任务未完成的时候这里是0
- // succState: 0 // 任务是否完成的状态,0:未完成1:已达成
- // });
- // yield activerewardrec.saveAsync();
- // }
- // else{
- // let str15 = "hdjl hdqjjrgwjyjcsgjl "+this.id + " userId: " + user.userId;
- // logger.warn(str15);////cssj
- // ////活动期间更新今日该玩家已经产生的记录
- // let newre = acrlist[0];
- // newre.gameCount++;
- // if(newre.gameCount >= 2){
- // // console.warn("活动奖励 活动期间更新今日该玩家已经产生的记录",user.spreadId,user.registerTime,user.lastLoginTime);
- // let str16 = "hdjl hdqjgxjrgwjyjcsdjl "+this.id + " userId: " + user.userId + " gameCount: " + newre.gameCount;
- // logger.warn(str16);////cssj
- // ////完成为解散2局,该玩家完成了签到的任务了
- // if(newre.gameCount == 2){
- // newre.totalfee = 500;
- // newre.succtime = xzsjc;
- // newre.succState = 1;
- // }
- // yield newre.saveAsync();
- // }
- // if(newre.gameCount == 2){
- // var opts2 = { stime: { $gte: acSTime, $lt: acETime },type: { $gte: 2, $lt: 3 }};
- // opts2['sid'] = user.id;
- // let acrlist2 = yield this.app.models.ActiveRewardRecord.findMongoAsync(opts2, 'rid', { sort: { stime: 1 } });//
- // let isneedcj = false;////是否需要创建邀请奖励产生记录
- // if(acrlist2.length == 0){
- // isneedcj = true;
- // // if(parseInt(acrlist2[0].rid) && parseInt(acrlist2[0].rid) == user.spreadId) isneedcj = true;
- // }
- // // console.warn("活动奖励 完成未解散2局,该玩家的推荐人完成了邀请的任务了",user.spreadId,user.registerTime,user.lastLoginTime);
- // let str17 = "hdjl csgwjdyqjl "+this.id + " userId: " + user.userId + " isneedcj: " + isneedcj;
- // logger.warn(str17);////cssj
- // if(isneedcj){
- // ////完成为解散2局,该玩家的推荐人完成了邀请的任务了
- // var activerewardrec = new this.app.models.ActiveRewardRecord({
- // _id: uuid.v1(), // UUID
- // rewardtype: 0, // 奖励类型,0红包
- // totalfee: 500, // 产生金额,红包为分
- // type:2, //活动类型:1国庆签到2国庆邀请
- // sid: user.id, // 产生奖励的玩家id
- // suid:user.userId, // 产生奖励的玩家userId
- // sname:user.name, // 产生奖励的玩家name
- // rid: user.spreadId,// 此条奖励的受益玩家
- // gameCount: newre.gameCount, // 游戏局数
- // stime: xzsjc, // 记录产生时间
- // succtime: xzsjc, // 任务完成时间,任务未完成的时候这里是0
- // succState: 1 // 任务是否完成的状态,0:未完成1:已达成
- // });
- // yield activerewardrec.saveAsync();
- // }
- // }
- // }
- // }
- // }
- // }
- // let str4 = "table 222 站起桌子之后---id:%s"+this.id + " uid"+user.userId+" "+ this.state;
- // logger.info(str4);////cssj
- }
- });
- // 玩家断线
- proto.offlineAsync = cor(function* (user) {
- let str3 = "table 玩家断线.......id: "+ this.id + " user.chairId: " + user.chairId + " user.name: " + user.name ;
- logger.warn(str3);////cssj
- if (user.chairId != -1) {
- //user.state = User.STATE.OFFLINE;//ts--
- user.state2 = User.STATE.OFFLINE;//ts++
- user.offlinetime = Date.now();//ts++断线
- var channelId = 'xct:' + this.id;
- yield this.app.controllers.push._quitAsync(channelId, user.id);
- yield this.pushMsgAsync(-1, 'sxjiang_event', { type: M.STATE_CHANGE, data: { chairId: String(user.chairId), state: String(user.state2), state2: String(user.state2) } });
- // 无人在线
- // console.warn("提前结算666");
- //if (this.isOffline()) return this.overTimeAsync(MODE.OFFLINE);
- // console.warn("玩家断线-------定时器启动");
- // 计时结算
- if (!this.endTimer) this.endTimer = this.app.timer.setTimeout(() => this.overTimeAsync(ENDMODE.OFFLINEEND),1200000);/////断线3分钟自动结算
- // let str4 = "table 玩家断线---id:"+this.id + ",uid"+user.userId+" "+ this.state;
- // logger.info(str4);////cssj
- }
- });
- // 离开桌子
- proto.leaveAsync = cor(function* (user) {
- let str3 = "table 离开桌子.......id: "+ this.id + " user.chairId: " + user.chairId + " user.name: " + user.name ;
- logger.warn(str3);////cssj
- // this.leavePlayerID = user.id;//////TL++,旁观为房主的话离开之后由于从观战者列表里面删除了,导致发消息的时候他收不到离开桌子的消息
- // console.warn("离开桌子、、、、、、、");
- yield this.beforeLeaveAsync(user);
- var chairId = user.chairId;
- // yield this.pushMsgAsync(-1, 'sxjiang_event', { type: M.LEAVE, data: { account: user.account } });/////TL++zs,原来在下面
- if (chairId != -1) {
- delete this.users[chairId];
- delete this.handCards[chairId];
- yield this.afterStandAsync(user, chairId);
- } else {
- let pos = _.findIndex(this.lookers, (u) => (u.id == user.id));
- if (pos != -1) this.lookers.splice(pos, 1);
- }
- return this.afterLeaveAsync(user);
- });
- // 离开桌子之前
- proto.beforeLeaveAsync = cor(function* (user) {
- var channelId = 'xct:' + this.id;
- return this.app.controllers.push._quitAsync(channelId, user.id);
- });
- // 离开桌子之后
- proto.afterLeaveAsync = cor(function* (user) {
-
- // 离开通知
- /////TL++zsyl 在此之前离开玩家已经从玩家列表或者旁观者列表中删除了所以把下面这句提到前面去了
- return this.pushMsgAsync(-1, 'sxjiang_event', { type: M.LEAVE, data: { account: user.account } });
- });
- // 玩家准备
- proto.readyGameAsync = cor(function* (user) {
- let str3 = "table 玩家准备.......id: "+ this.id + " user.chairId: " + user.chairId + " this.over: " + this.over + " user.name: " + user.name ;
- logger.warn(str3);////cssj
- // let str3 = "table 玩家准备---id:"+this.id + ",uid"+user.userId+","+ this.state;
- // logger.info(str3);////cssj
- if(this.state==STATE.FREE2)//ts++二次空闲
- {
- user.state2 = User.STATE.READY;
- yield this.pushMsgAsync(-1, 'sxjiang_event', { type: M.STATE_CHANGE, data: { chairId: String(user.chairId), state: String(user.state2), state2: String(user.state2) } });
- if (this.isReady2() && !this.isGameOk) yield this.startGameAsync();
- }
- else
- {
- user.state = User.STATE.READY;
- user.state2 = User.STATE.READY;
- yield this.pushMsgAsync(-1, 'sxjiang_event', { type: M.STATE_CHANGE, data: { chairId: String(user.chairId), state: String(user.state2), state2: String(user.state2) } });
- // console.warn("玩家准备玩家准备玩家准备 ",this.isReady() ,this.isGameOver());
- if (this.isReady() && !this.isGameOk) yield this.startGameAsync();
- }
- // let str4 = "table 222玩家准备---id:"+this.id + ",uid"+user.userId+","+ this.state;
- // logger.info(str4);////cssj
- return { code: C.OK };
- });
- // 开始游戏
- proto.startGameAsync = cor(function* () {
- //this.backStartTimer = null;//////重入之后系统会自动准备为了解决可能没牌的问题2秒之后才开始游戏
- let str4 = "table 开始游戏---id:"+this.id +" ,state "+ this.state +" 当前局 "+ (this.over+1);
- logger.warn(str4);////cssj
- if(this.isYJKSGL){
- return;
- }
- this.isYJKSGL = true;/////是否已经执行过开始函数了
- this.isYJJSGL = false;/////是否已经执行过结算函数了
- if(this.backStartTimer)
- {
- clearTimeout(this.backStartTimer);
- this.backStartTimer = null;
- }
- // 状态设置
- this.state = STATE.PLAYING;
- //this.setUserState(-1, User.STATE.PLAYING);//ts--
- //ts++设置为游戏状态
- for (let user of this.users)
- {
- if (user) {
- if(user.state == User.STATE.PLAYING)//ts++已经开始
- {
- if(user.state2 == User.STATE.READY)
- {
- user.state2 = User.STATE.PLAYING
- user.offlinetime = 0;
- }
- }
- else//ts++第一次开始
- {
- user.state = User.STATE.PLAYING
- user.state2 = User.STATE.PLAYING
- user.offlinetime = 0;
- }
- }
- }
- //ts++end
- let whdata = yield this.app.models.WHstate.findByIdReadOnlyAsync('wh', 'rebaterate');
- // console.warn("22检查是否维护状态",whdata);
- if (whdata) {
- if(whdata.rebaterate || whdata.rebaterate == 0){///
- /////维护状态中
- this.rEBATERATE= 1;//业绩模式必须为100%//whdata.rebaterate / 100;
- }
- else{
- let whdata2 = yield this.app.models.WHstate.findByIdAsync('wh', 'rebaterate');
- if (whdata2) {
- whdata2.rebaterate = 100;
- yield whdata2.saveAsync();
- this.rEBATERATE= 1;//业绩模式必须为100%
- }
- }
- }
- this.PaijuHuiFang = [];////TL++,牌局回放 重置数据
- this.lgkhCount = 0;/////TL++拉杠可胡玩家的数量
- this.logic.isZHYZ = false;/////是不是最后1张
- // this.logic.isNeedBuHua = false/////TL++在游戏开始的时候初始化是否需要补花
- // this.isLianGang = [-1,false,-1];/////TL++,连杠的玩家座位号,是否连杠 在游戏开始的时候清空
- // 初始信息
- if (this.over <= 0) {///////本房间开始的第一局游戏
- this.stime = Date.now();
- // this.chBanker = this.ownerChairid;///////TL++zsyl
- this.chBanker = 0;
- //this.game.cancelDelete(this.id);//////TL++游戏第一次开始时候关闭房间20分钟未开始删除桌子
- this.pjhffileName[this.pjhffileName.length] = this.PJHF.getjsonFileName(0,this.recordid,this.ctime);/////TL++,用于记录玩家牌局回放的json文件名
- // console.error("000HHHHHHHHHHHHHHHHHHHHHH",this.pjhffileName.length,this.pjhffileName);
- this.PJHF.writePJHFJson(this.getTableInfo(),0,this.id);////在开始第一局的时候将桌子信息写入本地的json文件
- this.isNeverStart = false;/////TL++,游戏是否从未开始
- // yield this.randomChangeChairTL()/////TL++,在首次游戏的时候随机打乱用户的座位
- }
- this.gameNeverStart = false;/////TL++,游戏是否从未开始过,用于解散房间判断
- this.currentId = this.chBanker;
- this.isDihus[this.chBanker] = false;
- // 发手牌 把这句提前是为了洗牌之后能拿到百搭牌在游戏开始的时候给客户端发过去
- let dice1 = this.logic.dice();/////骰子1的点数
- let dice2 = this.logic.dice();/////骰子2的点数
- var handCards = this.logic.handCards(this.chBanker,this.PJHF,this.over,this.recordid,this.ctime);
- if(this.playerAllCount == 4){
- if(this.chBanker == 0) this.logic.isMZWF = [0,1,2,3];/////是不是满足位风
- else if(this.chBanker == 1) this.logic.isMZWF = [3,0,1,2];/////是不是满足位风
- else if(this.chBanker == 2) this.logic.isMZWF = [2,3,0,1];/////是不是满足位风
- else if(this.chBanker == 3) this.logic.isMZWF = [1,2,3,0];/////是不是满足位风
- }
- // }
- else if(this.playerAllCount == 3){
- if(this.chBanker == 0) this.logic.isMZWF = [0,1,2,8];/////是不是满足位风
- else if(this.chBanker == 1) this.logic.isMZWF = [3,0,1,8];/////是不是满足位风
- else if(this.chBanker == 2) this.logic.isMZWF = [2,3,0,8];/////是不是满足位风
- }
- else if(this.playerAllCount == 2){
- if(this.chBanker == 0) this.logic.isMZWF = [0,2,8,8];/////是不是满足位风
- else if(this.chBanker == 1) this.logic.isMZWF = [2,0,8,8];/////是不是满足位风
- }
-
- //console.warn("ccccccccccccccccccccc当局的圈风",this.logic.fengQuan,this.chBanker);
- let scoreListTL = []
- for (let i = 0; i < this.users.length; ++i) {
- let user = this.users[i];
- if (user) {
- let score = this.score.getScore(user.id);
- scoreListTL[i] = score
- }
- }
- // 掷骰子
- var sttGame = {
- banker: String(this.chBanker),
- qFeng: String(this.quFeng),
- stime: String(Date.now() - this.stime),
- baiDaCard: String(this.logic.baiDaCard),//////TL++,本局百搭牌
- startNum1: String(dice1),////骰子点数
- startNum2: String(dice2),////骰子点数
- setCardFileName: String(this.logic.setCardFileName),////TL++设置手牌的文件名
- scoreListTL:scoreListTL,/////TL++,每个玩家当前的分数列表
- };
- // console.warn("游侠开始*******************this.chBanker",this.chBanker);
- this.setPaijuHuiFangData(M.START_GAME,sttGame);/////TL++ 牌局回放 push游戏开始
- // 开始通知
- yield this.pushMsgAsync(-1, 'sxjiang_event', { type: M.START_GAME, data: sttGame });
-
- ////// 发手牌原来在这里
- var lastCount = this.logic.leaveCount();/////TL++
- for (let i = 0; i < handCards.length; ++i) {
- this.handCards[i] = handCards[i].cards;/////TL++zsyl
- if (i == this.chBanker) {
- let __isHu = false;
- let length = this.handCards[i].length;
- this.logic.isLaGang = false;//////TL++,是否刚刚被拉杠用于判断是否被拉杠胡
- // this.logic.chengBaoTL = [[],[],[],[]];
- // console.error("sscc3333胡牌分析 游戏开始i",i);
- let huRes = this.logic.huAnalyze(i,this.handCards[i], this.handCards[i][length - 1], this.huCards[i], true);
- // console.error("ssccDDD胡牌分析 huRes",huRes);
- if (huRes) {
- // let str3a = "table fpphcg:"+this.id + ",uid"+this.handCards[i];
- // logger.info(str3a);////cssj
- __isHu = true;
- this.huRes[i] = huRes;
- }
- let res = this.logic.anGangAnalyze(this.handCards[i]);
- let isGang = (res.length > 0);
- if (isGang) this.masks[i] |= 8;
- if (__isHu) this.masks[i] |= 16;
- }
- let scards = {
- mask: String(this.masks[i]),
- cards: handCards[i].cards,
- lastCount: String(lastCount)
- };
- ////发牌的胡牌提示
- if (i == this.chBanker) {
- ////游戏开始时候的庄家的胡牌提示
- scards.hutipdata = this.logic.hutip(this.chBanker,handCards[i].cards,this.huCards[i],this.huCards,this.outCards);////起手发牌调用胡牌提示
- }
- else{
- ////游戏开始时候的闲家的胡牌提示
- scards.hutipdata = {
- renyi:0,//////是否可胡任意牌,0表示不满足1表示满足
- kehuData:[]/////对象数组,分别表示打哪张可胡哪几张数据
- };
- }
- // 发牌通知
- // console.error("sscc发牌通知 4条应该=================",i,handCards.lengt);
- yield this.pushMsgAsync(i, 'sxjiang_event', { type: M.SEND_CARD, data: scards });
- }
-
- let pjhfsplist = {
- shouPai:this.logic.deepCloneTL(this.handCards),
- maskList:this.logic.deepCloneTL(this.masks),/////TL++,10月28号,为了实现能看到每个玩家的操作
- lastCount:String(this.logic.leaveCount())
- }
- this.setPaijuHuiFangData(M.SEND_CARD,pjhfsplist);/////TL++ 牌局回放 push发牌数据
- // 围观通知
- var cardCounts = _.fill(Array(this.ccount), 0);
- for (let i = 0; i < cardCounts.length; ++i) {
- cardCounts[i] = this.handCards[i].length;
- }
- yield this.lookMsgAsync('sxjiang_event', { type: M.SEND_CARD, data: { cardCounts: cardCounts, lastCount: String(lastCount) } });
- let str3 = "table 222开始游戏---id:"+this.id +","+ this.state;
- logger.warn(str3);////cssj
- return { code: C.OK };
- });
- // 出牌
- proto.outCardAsync = cor(function* (chairId, card) {
- let str3 = "table 出牌---id:"+this.id + " ,uid "+chairId+" this.masks "+ this.masks +" card "+card;
- logger.warn(str3);////cssj
- // console.warn("出牌出剖出牌",chairId,this.buhuaTimeout);///// 您正在补花,请稍后出牌。/////TL++,正在补花的时候不允许玩家出牌
- // if(this.buhuaTimeout) return { code: C.FAILD, msg: C.GAME_BUHUA_ING };
- // 校验顺序
- if (this.currentId != chairId) {
- return { code: C.FAILD, msg: C.TABLE_TURN_ERROR };
- }
- this.logic.chuPaiTL()////TL++,统计出牌个数,为了判断天胡和地胡
- // 吃椪杠胡
- var pos = _.findIndex(this.masks, (m, i) => (i != chairId && m > 0));
- if (pos != -1) {
- return { code: C.FAILD, msg: C.TABLE_TURN_ERROR };
- }
- // 删除手牌
- if (!this.logic.remove(this.handCards[chairId], card)) {
- return { code: C.FAILD, msg: C.TABLE_CARD_ERROR };
- }
- if (this.masks[chairId] & 16){
- this.logic.isGuoHuList[chairId][0] = true;/////TL++,设置过胡玩家的是否点击过胡为true 出牌
- let guohudataTL = {
- chairId:chairId,
- msg: "下次摸牌之前将不能胡牌", /////过胡通知
- }
- let isGuoHuList = [[false,0],[false,0],[false,0],[false,0],];
- isGuoHuList[chairId] = this.logic.isGuoHuList[chairId];
- guohudataTL.isGuoHuList = isGuoHuList;
- ////过胡通知
- yield this.pushMsgAsync(chairId, 'sxjiang_event', { type: M.FHGUOHUTIP, data: guohudataTL });
- this.logic.isLaGang = false;//////TL++,是否刚刚被拉杠用于判断是否被拉杠胡
- }
- // 置空权限
- if (this.masks[chairId] > 0) this.masks[chairId] = 0;
- // 置灰的牌
- this.disCards = [];
- // 调整手牌
- this.logic.adjust(this.handCards[chairId]);
- this.outCard = card;
- this.outerId = chairId;
- this.outCards[chairId].push(card);
- // 天胡地胡
- if (this.isTianhu) this.isTianhu = false;
- if (this.isDihus[chairId]) this.isDihus[chairId] = false;
- // 忽略牌
- this.excepts[chairId] = {};
- let sfyrkh = false;//////TL++,是否有人可胡,没有的话海底捞月之后直接结算
- let pjhfsplist = {};
- // 吃碰杠胡
- for (let i = 0; i < this.ccount; ++i) {
- let ocard = { chairId: String(chairId), card: String(card) };
- // 排除自己
- if (i != chairId) {
- ocard.isGuoHuList = [[false,0],[false,0],[false,0],[false,0],]
- let _isChi = false;
- let isPeng = false;
- let isGang = false;
- let __isHu = false;
- do {
- // 检测吃牌
- if (this.hasEat && i == (chairId + 1) % this.ccount && (!this.isZNZM)) {//// 以前是否可吃为可选项 只能自摸情况下不能吃
- let ress = this.logic.chiAnalyze(this.handCards[i], card);
- _isChi = (ress.length > 0);
- }
- // 忽略牌
- if (this.excepts[i][card]) break;/////TL++zsyl.同一圈过碰之后不能再次碰的
- // 检测碰牌
- isPeng = this.logic.isPeng(this.handCards[i], card);
- // 忽略牌
- // if (this.excepts[i][card]) break;/////TL++.为了解决同一圈过碰之后不能再次碰的问题
- let res = this.logic.gangAnalyze(this.handCards[i], card);
- isGang = !!res;
- this.logic.isLaGang = false;//////TL++,是否刚刚被拉杠用于判断是否被拉杠胡
- let huRes = (!this.isZNZM) ? this.logic.huAnalyze(i,this.handCards[i], card, this.huCards[i]) : undefined;
- // console.error("ssccAAA胡牌分析 huRes",huRes);
- if (huRes) {
- // let str3a = "table cpphcg:"+this.id + ",uid"+this.handCards[i];
- // logger.info(str3a);////cssj
- __isHu = true;
- this.huRes[i] = huRes;
- }
- } while (0);
- /////TL++,整个if
- if(this.logic.leaveCount() == 0 && this.logic.isZHYZ){
- if (_isChi) _isChi = false;
- if (isPeng) isPeng = false;
- if (isGang) isGang = false;
- if(__isHu) sfyrkh = true
- }
- // 权限掩码
- if (_isChi) this.masks[i] |= 2;
- if (isPeng) this.masks[i] |= 4;
- if (isGang) this.masks[i] |= 8;
- if (__isHu) this.masks[i] |= 16;
- }
- else{
- let isGuoHuList = [[false,0],[false,0],[false,0],[false,0],];
- isGuoHuList[chairId] = this.logic.isGuoHuList[chairId];
- ocard.isGuoHuList = isGuoHuList;
- }
- ocard.mask = String(this.masks[i]);
- // 出牌通知
- yield this.pushMsgAsync(i, 'sxjiang_event', { type: M.OUT_CARD, data: ocard });
- if (i == chairId) {
- // let pjhfcp = ocard
- // pjhfcp.allMask = this.masks;
- pjhfsplist = {
- shouPai:this.logic.deepCloneTL(this.handCards),
- lastCount:String(this.logic.leaveCount()),
- ocard:this.logic.deepCloneTL(ocard),
- outCards:this.logic.deepCloneTL(this.outCards),
- isGuoHuList:this.logic.deepCloneTL(this.logic.isGuoHuList)
- }
- }
- if(i == (this.ccount - 1)){/////TL++if条件判断,10月28号,为了实现能看到每个玩家的操作
- pjhfsplist.maskList = this.logic.deepCloneTL(this.masks);/////TL++,10月28号,为了实现能看到每个玩家的操作
- this.setPaijuHuiFangData(M.OUT_CARD,pjhfsplist);/////TL++ 牌局回放 push出牌数据
- }
- }
- // 被杠玩家
- this.gangOuter = -1;
- // 围观通知
- yield this.lookMsgAsync('sxjiang_event', { type: M.OUT_CARD, data: { chairId: String(chairId), card: String(card) } });
- // 全无权限
- for (let i = 0; i < this.ccount; ++i) {
- if (this.masks[i] != 0) break;
- // 切换用户
- if (i == this.ccount - 1) {
- // 下家摸牌
- let nextId = (chairId + 1) % this.ccount;
- ///////TL++,整个if,因为海底捞月需要玩家自己去判断要不要摸牌
- // console.warn("000 声剩余声剩余声剩");
- let lastCount = this.logic.leaveCount();/////TL++xg
- this.touchCardAsync(nextId); ///////出牌摸牌
- }
- }
- let str4 = "table end出牌---id:"+this.id + " ,uid "+chairId+" this.masks "+ this.masks +" card "+card;
- logger.warn(str4);////cssj
- return { code: C.OK };
- });
- ///////摸牌函数 参数ifGang是否因为杠而摸牌 TL++ 参数isBHMP 是否补花摸牌,为了判断是否花杠杠开 是否最后一张的海底捞月
- proto.touchCardAsync = cor(function* (chairId,ifGang,isBHMP,ishdly) {
- // console.warn("这不会死循环吧",chairId,isBHMP,this.buhuaTimeout);
- // if(this.buhuaTimeout) {
- // clearTimeout(this.buhuaTimeout);
- // this.buhuaTimeout = null;
- // }
-
- // 状态校验
- if (this.state != STATE.PLAYING) return;
- if (this.winner.chs.length > 0 || !this.users[chairId]) return;
- if(this.logic.isGuoHuList[chairId][0]) this.logic.isGuoHuList[chairId][0] = false;/////TL++,设置过胡玩家的是否点击过胡为false; 摸牌
- // 当前顺序
- this.currentId = chairId;
- // 摸牌
- // var moCard = this.logic.moCard();TL++zsyl
- ////TL++
- var moCard = { card: 0 };
- // if(isBHMP) moCard.card = this.logic.buHuaMoDePai;//////TL++,补花摸上的牌
- // else {
- let isG = (ifGang && (ifGang == 1) || (ifGang == 2) || (ifGang == 3))
- // console.warn("<<<<<<<<<",isG,ifGang)
- moCard = this.logic.moCard(isG);
- this.logic.moPaiTL();
- // }
- let moPaiIsCanHu = false;//////TL++,摸牌的人是否可以胡牌
- // 是否流局
- if (moCard.card <= 0) {
- // console.warn("提前结算888");
- yield this.concludeGameAsync(MODE.NOCARD);
- return { code: C.OK };
- }
- let lastCount22 = this.logic.leaveCount();/////TL++xg
- let pjhfsplist = {};
- for (let i = 0; i < this.ccount; ++i) {
- let touchCard = { currentId: String(chairId), touch: '0',lastCount : '0' };
- // console.warn("1111WWWWWWWTTTTTT",i,chairId,moCard.card);
- if (i == chairId) {
- touchCard.touch = String(moCard.card);
- // this.handCards[i].push(moCard.card);/////TL++zsyl
- if(!isBHMP) this.handCards[i].push(moCard.card);/////TL++,因为在补花的时候已经将新发的牌放进手牌里了所以这里不用push
- let __isHu = false;
-
- // console.error("sscc111胡牌分析 摸牌 i",i);
- this.logic.isLaGang = false;//////TL++,是否刚刚被拉杠用于判断是否被拉杠胡
- // this.logic.chengBaoTL = [[],[],[],[]];////别人放弃拉杠之后还没想好要怎么清空,因为不清空也行
- // console.warn("222摸牌的时候设置刚才是否有杠",i,ifGang,this.logic.isGGMG,this.logic.isGGAG,this.logic.isGGFXG);
- let huRes = this.logic.huAnalyze(i,this.handCards[i], moCard.card, this.huCards[i], true);
- // console.error("ssccBBB胡牌分析 huRes",huRes);
- if (huRes) {
- // let str3a = "table mpphcg:"+this.id + ",uid"+this.handCards[i];
- // logger.info(str3a);////cssj
- __isHu = true;
- moPaiIsCanHu = true;/////TL++
- this.huRes[i] = huRes;
- }
- let res = this.logic.anGangAnalyze(this.handCards[i]);
- let isGang = (res.length > 0);
- if (!isGang) {
- res = this.logic.zmGangAnalyze(this.handCards[i], this.huCards[i]);
- isGang = (res.length > 0);
- }
- if (isGang) this.masks[i] |= 8;
- if (__isHu) this.masks[i] |= 16;
- ////摸排时候的摸排玩家的胡牌提示
- let hutipdataTL = this.logic.hutip(i,this.handCards[i],this.huCards[i],this.huCards,this.outCards);////摸牌时调用胡牌提示
- touchCard.hutipdata = hutipdataTL;
- let isGuoHuList = [[false,0],[false,0],[false,0],[false,0],];
- isGuoHuList[chairId] = this.logic.isGuoHuList[chairId];
- touchCard.isGuoHuList = isGuoHuList;
- }
- else {
- this.masks[i] = 0;
- touchCard.hutipdata = {
- renyi:0,//////是否可胡任意牌,0表示不满足1表示满足
- kehuData:[]/////对象数组,分别表示打哪张可胡哪几张数据
- };
- touchCard.isGuoHuList = [[false,0],[false,0],[false,0],[false,0],]
- }
- touchCard.mask = String(this.masks[i]);
- touchCard.lastCount = String(lastCount22);
- this.logic.lastMoPaiChairID = this.currentId;
- // 摸牌通知
- // console.warn("222WWWWWWWTTTTTT",i,chairId,moCard.card);
- yield this.pushMsgAsync(i, 'sxjiang_event', { type: M.TOUCH_CARD, data: touchCard});
-
- if (i == chairId) {
- pjhfsplist = {
- shouPai:this.logic.deepCloneTL(this.handCards),
- lastCount:String(this.logic.leaveCount()),
- touchCard:this.logic.deepCloneTL(touchCard),
- outCards:this.logic.deepCloneTL(this.outCards),
- isGuoHuList:this.logic.deepCloneTL(this.logic.isGuoHuList)
- }
- }
- if(i == (this.ccount - 1)){/////TL++if条件判断,10月28号,为了实现能看到每个玩家的操作
- pjhfsplist.maskList = this.logic.deepCloneTL(this.masks);/////TL++,10月28号,为了实现能看到每个玩家的操作
- this.setPaijuHuiFangData(M.TOUCH_CARD,pjhfsplist);/////TL++ 牌局回放 push摸牌数据
- }
- }
-
- let str3 = "table 摸牌函数id:"+this.id + " ,uid "+chairId+" ,this.masks "+ this.masks +" card "+moCard.card;
- logger.warn(str3);////cssj
- // 围观通知
- return this.lookMsgAsync('sxjiang_event', { type: M.TOUCH_CARD, data: { currentId: String(chairId),lastCount:String(lastCount22)} });
- });
- // 放弃操作
- proto.giveUpAsync = cor(function* (chairId) {
- let str3 = "table 放弃操作id: "+this.id + " ,uid "+chairId+", this.masks "+ this.masks;
- logger.warn(str3);////cssj
- // 权限掩码
- var mask = this.masks[chairId];
- if (mask <= 0) {
- return { code: C.FAILD, msg: C.TABLE_MASK_ERROR };
- }
- // console.warn("111放弃操作放弃操作放弃操作放弃操作放弃操作chairId,this.masks",chairId,this.masks,(mask & 16));
- if (mask & 16) {////mask = 16~31时结果=16这个if能进去 0~15或者32~47之间结果=0这个if进不去
- // console.warn("放弃操作里设置过胡为true",chairId, this.logic.isLaGang,this.logic.isGuoHuList,this.logic.everyAllTaiShu);
- this.logic.isGuoHuList[chairId][0] = true;/////TL++,设置过胡玩家的是否点击过胡为true 点击过按钮
- let guohudataTL = {
- chairId:chairId,
- msg: "下次摸牌之前将不能胡牌", /////过胡通知
- }
- let isGuoHuList = [[false,0],[false,0],[false,0],[false,0],];
- isGuoHuList[chairId] = this.logic.isGuoHuList[chairId];
- guohudataTL.isGuoHuList = isGuoHuList;
- //////过胡通知
- yield this.pushMsgAsync(chairId, 'sxjiang_event', { type: M.FHGUOHUTIP, data: guohudataTL });
- if(this.logic.leaveCount() > 0){/////TL++
- this.lgkhCount -= 1;/////TL++拉杠可胡玩家的数量
- }
- // console.warn("666拉杠胡%%%%%%%%%%%%%%%%%%%%%%",this.logic.isLaGang);
- }
- // 删除权限
- this.masks[chairId] = 0;
- // 是否自摸
- if (this.currentId == chairId) {
- return { code: C.OK };
- }
- // 忽略牌
- if (this.outCard) {
- let except = this.excepts[chairId];
- except[this.outCard] = this.outCard;
- }
- // 放弃胡牌
- if (mask & 16) {////mask = 16~31时结果=16这个if能进去 0~15或者32~47之间结果=0这个if进不去
- this.logic.isGuoHuList[chairId][0] = true;/////TL++,设置过胡玩家的是否点击过胡为true 点击过按钮(这句没啥用,在这个函数开始的时候设置过了)
- // console.warn("放弃操作里设置过胡为true",chairId, this.isGangHu,this.logic.isGuoHuList);
- let winner = this.winner;
- do {
- // 一炮多响
- if (this.isMHu) {
- let __cHu = _.findIndex(this.masks, (m) => (m & 16));//////
- // console.warn("允许一炮多想 放弃操作放弃操作放弃操作this.isMHu,__cHu",this.isGangHu,this.isMHu,__cHu);
- if (__cHu != -1) break;
- // 有人胡牌
- if (winner.chs.length > 0) {
- // console.warn("允许一炮多想 操作放弃操作放弃操作winner.chs",winner.chs);
- yield this.pushMsgAsync(-1, 'sxjiang_event', { type: M.HU, data: { lead: String(winner.lead), chairIds: winner.chs } });
- // console.warn("提前结算1111");
- yield this.concludeGameAsync(MODE.NORMAL).then(() => ({ code: C.OK }));/////结算游戏
- return { code: C.OK };
- }
- } else {///// 没炮多响
- // console.warn("没炮多想 放弃操作放弃操作放弃操作winner.chs",this.isGangHu,winner.chs);
- // 有人胡牌
- if (winner.chs.length > 0) {
- let dist = (winner.chs[0] - winner.lead + this.ccount) % this.ccount;
- // let __cHu = _.findIndex(this.masks, (m, i) => (m & 16 && (i - winner.lead + this.ccount) % this.ccount < dist));////TL++,zsyl,
- let __cHu = _.findIndex(this.masks, (m, i) => (m & 16));///TL++,以前是上面那句写法,有个问题:0打牌后1,2,3号玩家都能胡,1点胡2点过,3就没有机会选择是否胡牌
- // console.warn("111没炮多想 放弃操作放弃操作放弃操作__cHu",__cHu);
- if (__cHu != -1) break;
- yield this.pushMsgAsync(-1, 'sxjiang_event', { type: M.HU, data: { lead: String(winner.lead), chairIds: winner.chs } });
- // console.warn("提前结算2222");
- yield this.concludeGameAsync(MODE.NORMAL).then(() => ({ code: C.OK }));/////结算游戏
- return { code: C.OK };
- } else {
- let __cHu = _.findIndex(this.masks, (m) => (m & 16));
- // console.warn("111没炮多想 放弃操作放弃操作放弃操作__cHu",__cHu);
- if (__cHu != -1) break;
- }
- }
- // 查找等待
- let cGang = -1
- let cPeng = -1;
- let _cChi = -1;
- // console.warn("这里是啥情况啊",this.masks);
- for (let i = 0; i < this.masks.length; ++i) {
- // if (i == this.currentId || i == chairId) continue;///////TL++zsyl 这种写法会导致拉杠胡的玩家点击过胡之后被拉杠胡的玩家杠不出来的问题
- if (i == chairId) continue;//////TL++,为了解决拉杠胡的玩家点击过胡之后被拉杠胡的玩家杠不出来的问题
- if (this.masks[i] == 9) {
- cGang = i;
- continue;
- }
- if (this.masks[i] == 5) {
- cPeng = i;
- continue;
- }
- if (this.masks[i] == 3) {
- _cChi = i;
- continue;
- }
- }
- // console.warn("2222情况啊",cGang, this.gangType,this.gangCard);
- // 杠碰吃
- if (cGang != -1 && this.gangType > 0 && this.gangCard > 0) {
- // console.warn("这里是放弃操作再次调用 杠 次");
- return this.gangCardAsync(cGang, this.gangCard, this.gangType).then(() => ({ code: C.OK }));
- } else if (cPeng != -1) {
- return this.pengCardAsync(cPeng, this.outCard).then(() => ({ code: C.OK }));
- } else if (_cChi != -1 && this._eatType > 0) {
- return this.eatCardAsync(_cChi, this.outCard, this._eatType).then(() => ({ code: C.OK }));
- }
- } while (0);
- }
- // 放弃杠碰
- if ((mask & 8) || (mask & 4)) {
- let __cHu = _.findIndex(this.masks, (m) => (m & 16));
- if (__cHu == -1) {
- let _cChi = _.findIndex(this.masks, (m) => (m & 3));
- if (_cChi != -1 && this._eatType > 0) {
- return this.eatCardAsync(_cChi, this.outCard, this._eatType).then(() => ({ code: C.OK }));
- }
- }
- }
- // 全无权限
- for (let i = 0; i < this.ccount; ++i) {
- if (this.masks[i] != 0) break;
- // 切换用户
- if (i == this.ccount - 1) {
- // 下家摸牌
- let nextId = (this.currentId + 1) % this.ccount;
- // return this.touchCardAsync(nextId).then(() => ({ code: C.OK }));//////放弃操作引起的摸牌 /////TL++zs
- ///////TL++,整个if,因为海底捞月需要玩家自己去判断要不要摸牌
- // console.warn("222 声剩余声剩余声剩");
- let lastCount = this.logic.leaveCount();/////TL++xg
- return this.touchCardAsync(nextId).then(() => ({ code: C.OK }));//////放弃操作引起的摸牌
- }
- }
- return { code: C.OK };
- });
- // /////TL++,是否进行海底捞月的操作 处理前端海底捞月函数
- proto.haiDiLaoYue = cor(function* (chairId,data) {
- // console.warn("海底捞月海底捞月");
- return { code: C.OK };
- });
- // 杠牌,1-普通杠, 2-暗杠, 3-自摸明杠
- proto.gangCardAsync = cor(function* (chairId, card, type) {
- let str3 = "table 杠牌,id: "+this.id + " ,uid "+chairId+", this.masks "+ this.masks +" ,card "+card;
- logger.warn(str3);////cssj
- // 参数校验
- if (!type && (type < 1 || type > 3)) {
- return { code: C.FAILD, msg: C.GAME_PARAM_ERROR };
- }
- if (type == 1 && card != this.outCard) {
- return { code: C.FAILD, msg: C.GAME_PARAM_ERROR };
- }
- if (type > 1 && this.currentId != chairId) {
- return { code: C.FAILD, msg: C.GAME_PARAM_ERROR };
- }
- if (!(this.masks[chairId] & 8)) {
- return { code: C.FAILD, msg: C.TABLE_MASK_ERROR };
- }
- // 他人可胡
- let __cHu = (type == 2) ? -1 : _.findIndex(this.masks, (m) => ((m & 16) && !(m & 8)));
- // console.warn("111拉杠胡%%%%%%%%%%%%%%%%%%%%%%",__cHu,type);
- if (__cHu == -1) {
- let res = null;
- if (type == 1 || type == 2) {
- res = this.logic.gang(chairId,this.handCards[chairId], card, type);
- } else if (type == 3) {
- res = this.logic.zmGang(chairId,this.handCards[chairId], this.huCards[chairId], card);
- }
- if (!res) {
- return { code: C.FAILD, msg: C.TABLE_GANG_ERROR };
- }
- /////TL++7月17日,这整个if的内容 和else的判断
- let winner = this.winner;
- if (winner.chs.length > 0) {
- yield this.pushMsgAsync(-1, 'sxjiang_event', { type: M.HU, data: { lead: String(winner.lead), chairIds: winner.chs } });
- this.setPaijuHuiFangData(M.HU,{ lead: String(winner.lead), chairIds: winner.chs });/////TL++ 牌局回放 push吃胡牌数据
- // console.warn("提前结算BBB");
- yield this.concludeGameAsync(MODE.NORMAL);
- }
- else{
- // 记录杠牌
- if (type == 1) {
- // 被杠玩家
- this.gangOuter = this.outerId;
- res.origin = this.outerId;
- this.outCards[this.outerId].pop();
- this.huCards[chairId].push(res);
- this.logic.remove(this.handCards[chairId], res.cards);
- } else if (type == 2) {
- // 被杠玩家
- this.gangOuter = -1;
- this.huCards[chairId].push(res);
- this.logic.remove(this.handCards[chairId], [card, card, card, card]);
- this.logic.adjust(this.handCards[chairId]);
- } else if (type == 3) {
- // console.warn("333拉杠胡%%%%%%%%%%%%%%%%%%%%%%",this.logic.isLaGang,this.isGangHu);
- let huCard = _.find(this.huCards[chairId], (o) => {
- return (o.style == Logic.STYLE.PENG && o.cards[0] == card);
- });
- if (!huCard) {
- return { code: C.FAILD, msg: C.TABLE_GANG_ERROR };
- }
- // 被杠玩家
- this.gangOuter = -1;
- // console.warn("拉杠胡%%%%%%%%%%%%%%%%%%%%%%" ,this.isGangHu);
- // 抢杠胡
- if (!this.isGangHu) {
- this.lgkhCount = 0;/////TL++拉杠可胡玩家的数量
- let allowIds = [], otherIds = [];
- for (let i = 0; i < this.ccount; ++i) {
- // 排除自己
- if (i != chairId) {
- this.logic.isLaGang = true;//////TL++,是否刚刚被拉杠用于判断是否被拉杠胡
- // console.error("sscc222胡牌分析 杠牌i",i,this.logic.isLaGang);
- let huRes = this.logic.huAnalyze(i,this.handCards[i], card, this.huCards[i]);
- // console.error("ssccCCC胡牌分析 huRes",huRes);
- // let lg2 = false;///TL++
- if (huRes) {
- // let str3a = "table lgphcg:"+this.id + ",uid"+this.handCards[i];
- // logger.info(str3a);////cssj
- if (!this.isGangHu) this.isGangHu = true;
- //////////TL++,为了记录承包情况,第一个元素表示承包原因 1:海底捞月打出去被胡 2:被人拉杠胡 第二个元素承包的玩家座位号
- // this.logic.chengBaoTL[chairId][this.logic.chengBaoTL[chairId].length] = [2,this.currentId];
- // lg2 = true//////TL++
- this.huRes[i] = huRes;
- this.masks[i] |= 16;
- this.lgkhCount += 1;/////TL++拉杠可胡玩家的数量
- allowIds.push(this.users[i].id); continue;
- }
- }
- // 其他玩家
- otherIds.push(this.users[i].id);
- }
- // 有人可胡
- if (allowIds.length > 0) {
- // 置于等待
- this.masks[chairId] = 9;
- this.gangType = type;
- this.gangCard = card;
- // 抢杠通知
- yield this.pushMsgAsync(otherIds, 'sxjiang_event', { type: M.MASK_HU, data: { mask: '0', card: String(card) } });
- yield this.pushMsgAsync(allowIds, 'sxjiang_event', { type: M.MASK_HU, data: { mask: '16', card: String(card) } });
- // console.warn("抢杠胡同盟会告知",allowIds);
- return { code: C.OK };
- }
- }
- huCard.style = Logic.STYLE.ZMGANG;
- // console.warn("55拉杠胡%%%%%%%%%%%%%%%%%%%%%%",this.logic.isLaGang,this.gangType,this.gangCard = 0);
- this.isGangHu = false;/////TL++,8月28日晚上,为了解决过胡拉杠之后就算自己已经摸牌也不能再次拉杠的问题
- this.logic.remove(this.handCards[chairId], card);
- this.logic.adjust(this.handCards[chairId]);
- }
- // if(this.chBanker == chairId) this.isZJYG = true;////本局庄家是否有杠
- // 清空权限
- this._eatType = 0;
- this.gangType = 0;
- this.gangCard = 0;
- _.fill(this.masks, 0);
- // 总杠次
- this.gonCount += 1;
- // 发送通知
- // console.warn("333 声剩余声剩余声剩");
- let lastCount = this.logic.leaveCount();/////TL++xg
- let pjhfsplist = {
- shouPai:this.logic.deepCloneTL(this.handCards),
- lastCount:lastCount,
- outCards:this.logic.deepCloneTL(this.outCards),
- opData:{ chairId: String(chairId), type: String(type), card: String(card), lastCount: String(lastCount) }
- }
- this.setPaijuHuiFangData(M.GANG,pjhfsplist);/////TL++ 牌局回放 push杠操作数据
- yield this.pushMsgAsync(-1, 'sxjiang_event', { type: M.GANG, data: { chairId: String(chairId), type: String(type), card: String(card), lastCount: String(lastCount) } });
- this.touchCardAsync(chairId, type); ///////杠牌摸牌
- }
- } else {
- // 置于等待
- this.masks[chairId] = 9;
- this.gangType = type;
- this.gangCard = card;
- }
- // let str4 = "table222 杠牌,id:"+this.id + ",uid"+chairId+","+ this.state +",card "+card;
- // logger.info(str4);////cssj
- return { code: C.OK };
- });
- // 碰牌
- proto.pengCardAsync = cor(function* (chairId, card) {
- let str3 = "table 碰牌id:%s "+this.id + " ,uid "+chairId+" ,this.masks "+ this.masks +" ,card "+card;
- logger.warn(str3);////cssj
- // 参数校验
- if (card != this.outCard || this.currentId == chairId) {
- return { code: C.FAILD, msg: C.GAME_PARAM_ERROR };
- }
- // 权限校验
- if (!(this.masks[chairId] & 4)) {
- return { code: C.FAILD, msg: C.TABLE_MASK_ERROR };
- }
- // 他人可胡杠
- var cHuGang = _.findIndex(this.masks, (m) => (((m & 16) || (m & 8)) && !(m & 4)));
- // console.warn("碰牌按钮被点击了 他人可胡杠",cHuGang,this.masks);
- if (cHuGang == -1) {
- let res = this.logic.peng(chairId,this.handCards[chairId], card);
- if (!res) {
- return { code: C.FAILD, msg: C.TABLE_PENG_ERROR };
- }
- /////TL++7月17日,这整个if的内容 和else的判断
- let winner = this.winner;
- if (winner.chs.length > 0) {
- yield this.pushMsgAsync(-1, 'sxjiang_event', { type: M.HU, data: { lead: String(winner.lead), chairIds: winner.chs } });
- this.setPaijuHuiFangData(M.HU,{ lead: String(winner.lead), chairIds: winner.chs });/////TL++ 牌局回放 push吃胡牌数据
- // console.warn("提前结算AAA");
- yield this.concludeGameAsync(MODE.NORMAL);
- }
- else{
-
- // 记录碰牌
- res.origin = this.outerId;
- this.outCards[this.outerId].pop();
- this.huCards[chairId].push(res);
- this.logic.remove(this.handCards[chairId], [card, card]);
- // 清空权限
- this._eatType = 0;
- this.gangType = 0;
- this.gangCard = 0;
- _.fill(this.masks, 0);
- // 用户顺序
- this.currentId = chairId;
- for (let i = 0; i < this.ccount; ++i) {
- let pengdata = {////这种一定要声明在for循环里面
- chairId: String(chairId),
- card: String(card)
- }
- if(i == chairId){
- let hutipdataTL = this.logic.hutip(i,this.handCards[i],this.huCards[i],this.huCards,this.outCards);////碰牌调用胡牌提示
- pengdata.hutipdata = hutipdataTL;
- }
- else{
- pengdata.hutipdata = {
- renyi:0,//////是否可胡任意牌,0表示不满足1表示满足
- kehuData:[]/////对象数组,分别表示打哪张可胡哪几张数据
- };
- }
- yield this.pushMsgAsync(i, 'sxjiang_event', { type: M.PENG, data: pengdata });
- }
- let pengdatapg = {////碰的旁观数据
- chairId: String(chairId),
- card: String(card)
- }
- pengdatapg.hutipdata = {
- renyi:0,//////是否可胡任意牌,0表示不满足1表示满足
- kehuData:[]/////对象数组,分别表示打哪张可胡哪几张数据
- };
- yield this.lookMsgAsync('sxjiang_event', { type: M.PENG, data: pengdatapg });////TL++
- ////20200831增加胡牌提示的时候把下面这句换成了上面那一段
- // yield this.pushMsgAsync(-1, 'sxjiang_event', { type: M.PENG, data: { chairId: String(chairId), card: String(card) } });
- let pjhfsplist = {
- shouPai:this.logic.deepCloneTL(this.handCards),
- lastCount:String(this.logic.leaveCount()),
- outCards:this.logic.deepCloneTL(this.outCards),
- opData:{ chairId: String(chairId), card: String(card) }
- }
- this.setPaijuHuiFangData(M.PENG,pjhfsplist);/////TL++ 牌局回放 push碰操作数据
-
- }
- } else {
- // 置于等待
- this.masks[chairId] = 5;
- // 查找等待 TL++下面这一段,为了解决A打出一张牌之后B可吃胡C可碰情况下 C先点碰B点吃会死掉的问题 这是原始代码的重大天然Bug
- let cGang = -1
- let cPeng = -1;
- let _cChi = -1;
- // console.warn("这里是啥情况啊",this.masks);
- for (let i = 0; i < this.masks.length; ++i) {
- // if (i == this.currentId || i == chairId) continue;///////TL++zsyl 这种写法会导致拉杠胡的玩家点击过胡之后被拉杠胡的玩家杠不出来的问题
- if (i == chairId) continue;//////TL++,为了解决拉杠胡的玩家点击过胡之后被拉杠胡的玩家杠不出来的问题
- if (this.masks[i] == 9) {
- cGang = i;
- continue;
- }
- if (this.masks[i] == 5) {
- cPeng = i;
- continue;
- }
- if (this.masks[i] == 3) {
- _cChi = i;
- continue;
- }
- }
- // console.warn("ppppppppppp444 ",chairId,cGang,cPeng,_cChi);
- // console.warn("2222情况啊",cGang, this.gangType,this.gangCard);
- // 杠
- if (cGang != -1 && this.gangType > 0 && this.gangCard > 0) {
- return this.gangCardAsync(cGang, this.gangCard, this.gangType).then(() => ({ code: C.OK }));
- }
- }
- // let str4 = "table 碰牌id:%s"+this.id + ",uid"+chairId+","+ this.state +" card "+card;
- // logger.info(str4);////cssj
- return { code: C.OK };
- });
- // 吃牌,1-@**左吃, 2-*@*中吃, 3-@**右吃
- proto.eatCardAsync = cor(function* (chairId, card, type) {
- let str3 = "table 吃牌id:%s "+this.id + " ,uid "+chairId+" ,this.masks "+ this.masks +",card "+card;
- logger.warn(str3);////cssj
- // 参数校验
- if (!type && (type < 1 || type > 3)) {
- return { code: C.FAILD, msg: C.GAME_PARAM_ERROR };
- }
- if (card != this.outCard) {
- return { code: C.FAILD, msg: C.GAME_PARAM_ERROR };
- }
- // 权限校验
- if (!(this.masks[chairId] & 2)) {
- return { code: C.FAILD, msg: C.TABLE_MASK_ERROR };
- }
- // if(this.logic.isGuoHuList[chairId][0]) this.logic.isGuoHuList[chairId][0] = false;/////TL++,吃牌设置过胡玩家的是否点击过胡为false;
- // 他人可胡杠碰
- var cHuGangPeng = _.findIndex(this.masks, (m) => (((m & 16) || (m & 8) || (m & 4)) && !(m & 2)));
- // console.warn("111他人可胡杠碰",cHuGangPeng);
- if (cHuGangPeng == -1) {
- let res = this.logic.chi(this.handCards[chairId], card, type);
- if (!res) {
- return { code: C.FAILD, msg: C.TABLE_PENG_ERROR };
- }
- /////TL++7月17日,这整个if的内容 和else的判断
- let winner = this.winner;
- // console.warn("222他人可胡杠碰",winner.chs.length);
- if (winner.chs.length > 0) {
- yield this.pushMsgAsync(-1, 'sxjiang_event', { type: M.HU, data: { lead: String(winner.lead), chairIds: winner.chs } });
- this.setPaijuHuiFangData(M.HU,{ lead: String(winner.lead), chairIds: winner.chs });/////TL++ 牌局回放 push吃胡牌数据
- // console.warn("提前结算aaa");
- yield this.concludeGameAsync(MODE.NORMAL);
- }
- else{
- // 记录吃牌
- res.origin = this.outerId;
- this.outCards[this.outerId].pop();
- this.huCards[chairId].push(res);
- if (type == 1) {
- this.logic.remove(this.handCards[chairId], [card + 1, card + 2]);
- } else if (type == 2) {
- this.logic.remove(this.handCards[chairId], [card - 1, card + 1]);
- } else {
- this.logic.remove(this.handCards[chairId], [card - 2, card - 1]);
- }
- // 清空权限
- this._eatType = 0;
- this.gangType = 0;
- this.gangCard = 0;
- _.fill(this.masks, 0);
- // 用户顺序
- this.currentId = chairId;
- // 发送通知
- for (let i = 0; i < this.ccount; ++i) {
- let chidata = {
- chairId: String(chairId),
- type: String(type),
- card: String(card)
- }
- if(i == chairId){
- let hutipdataTL = this.logic.hutip(i,this.handCards[i],this.huCards[i],this.huCards,this.outCards);////吃牌调用胡牌提示
- chidata.hutipdata = hutipdataTL;
- }
- else{
- chidata.hutipdata = {
- renyi:0,//////是否可胡任意牌,0表示不满足1表示满足
- kehuData:[]/////对象数组,分别表示打哪张可胡哪几张数据
- };
- }
- yield this.pushMsgAsync(i, 'sxjiang_event', { type: M.CHI, data: chidata });
- }
- let chidatapg = { ////TL++吃牌旁观数据
- chairId: String(chairId),
- type: String(type),
- card: String(card)
- }
- chidatapg.hutipdata = {
- renyi:0,//////是否可胡任意牌,0表示不满足1表示满足
- kehuData:[]/////对象数组,分别表示打哪张可胡哪几张数据
- };
- yield this.lookMsgAsync('sxjiang_event', { type: M.CHI, data: chidatapg });////TL++吃牌旁观消息
- ////20200901为了增加胡牌提示把下面这一段换成了上面那一段
- // yield this.pushMsgAsync(-1, 'sxjiang_event', { type: M.CHI, data: { chairId: String(chairId), type: String(type), card: String(card) } });
- let pjhfsplist = {
- shouPai:this.logic.deepCloneTL(this.handCards),
- lastCount:String(this.logic.leaveCount()),
- outCards:this.logic.deepCloneTL(this.outCards),
- opData:{ chairId: String(chairId), type: String(type), card: String(card) }
- }
- this.setPaijuHuiFangData(M.CHI,pjhfsplist);/////TL++ 牌局回放 push吃操作数据
-
- }
- } else {
- // 置于等待
- this.masks[chairId] = 3;
- this._eatType = type;
- // 查找等待 TL++下面这一段,为了解决A打出一张牌之后B可吃胡C可碰情况下 C先点碰B点吃会死掉的问题 这是原始代码的重大天然Bug
- let cGang = -1
- let cPeng = -1;
- let _cChi = -1;
- // console.warn("这里是啥情况啊",this.masks);
- for (let i = 0; i < this.masks.length; ++i) {
- // if (i == this.currentId || i == chairId) continue;///////TL++zsyl 这种写法会导致拉杠胡的玩家点击过胡之后被拉杠胡的玩家杠不出来的问题
- if (i == chairId) continue;//////TL++,为了解决拉杠胡的玩家点击过胡之后被拉杠胡的玩家杠不出来的问题
- if (this.masks[i] == 9) {
- cGang = i;
- continue;
- }
- if (this.masks[i] == 5) {
- cPeng = i;
- continue;
- }
- if (this.masks[i] == 3) {
- _cChi = i;
- continue;
- }
- }
- // console.warn("2222情况啊",cGang, this.gangType,this.gangCard);
- // 杠碰吃
- if (cGang != -1 && this.gangType > 0 && this.gangCard > 0) {
- return this.gangCardAsync(cGang, this.gangCard, this.gangType).then(() => ({ code: C.OK }));
- } else if (cPeng != -1) {
- return this.pengCardAsync(cPeng, this.outCard).then(() => ({ code: C.OK }));
- } else if (_cChi != -1 && this._eatType > 0) {
- return this.eatCardAsync(_cChi, this.outCard, this._eatType).then(() => ({ code: C.OK }));
- }
- }
- // let str4 = "table 吃牌id:"+this.id + ",uid"+chairId+","+ this.state +",card "+card;
- // logger.info(str4);////cssj
- return { code: C.OK };
- });
- // 胡牌 处理前端
- proto.succCardAsync = cor(function* (chairId) {
- let str3 = "table 胡牌:%s "+this.id + " ,uid "+chairId+" ,this.masks "+ this.masks;
- logger.warn(str3);////cssj
- // 权限校验
- if (!(this.masks[chairId] & 16)) {
- return { code: C.FAILD, msg: C.TABLE_MASK_ERROR };
- }
- // 删除权限
- this.masks[chairId] = 0;
- // 是否自摸
- let winner = this.winner;
- var isMoHu = (this.currentId == chairId);
- if (isMoHu) {
- winner.chs[0] = chairId;
- yield this.pushMsgAsync(-1, 'sxjiang_event', { type: M.HU, data: { lead: String(winner.lead), chairIds: winner.chs } });
- this.setPaijuHuiFangData(M.HU,{ lead: String(winner.lead), chairIds: winner.chs });/////TL++ 牌局回放 push摸胡牌数据
- // console.warn("提前结算444");
- yield this.concludeGameAsync(MODE.NORMAL);
- } else {
- // 抢杠胡
- if (this.isGangHu) {
- winner.lead = this.currentId;
- // 抢杠牌
- if (this.gangType > 0 && this.gangCard > 0) {
- this.logic.remove(this.handCards[this.currentId], this.gangCard);
- this.masks[this.currentId] = 0;
- this.gangType = 0; this.gangCard = 0;
- }
- } else {
- // 点炮
- winner.lead = this.outerId;
- }
- // 一炮多响
- let __cHu = -1;
- if (this.isMHu) {
- // 胡牌者
- winner.chs.push(chairId);
- // 他人可胡
- __cHu = _.findIndex(this.masks, (m) => ((m & 16)));
- } else {
- // 胡牌者
- if (winner.chs.length <= 0) winner.chs[0] = chairId;
- else {
- let hutype = [];//this.logic.getReasultTypeTL(winner.chs[0],this.huCards[winner.chs[0]],false)
- let hutypenew = []//this.logic.getReasultTypeTL(chairId,this.huCards[chairId],false)
- winner.chs[0] = chairId;
- }
- // 他人可胡
- __cHu = _.findIndex(this.masks, (m, i) => ((m & 16)))
- }
- // console.warn("22局部变量改变全局变量??",winner ,this.winner);
- // console.warn("点击胡按钮",__cHu,this.masks);
- if (__cHu == -1) {
- yield this.pushMsgAsync(-1, 'sxjiang_event', { type: M.HU, data: { lead: String(winner.lead), chairIds: winner.chs } });
- this.setPaijuHuiFangData(M.HU,{ lead: String(winner.lead), chairIds: winner.chs });/////TL++ 牌局回放 push吃胡牌数据
- // console.warn("提前结算555");
- yield this.concludeGameAsync(MODE.NORMAL);
- }
- }
- return { code: C.OK };
- });
- // 结算游戏
- proto.concludeGameAsync = cor(function* (mode) {
- /////增加下面这几行是为了保证每一把只执行一次结算方法
- if(this.isYJJSGL){
- // let strk = "table 结算游戏 id:了保证每一把只执行一次结算方法 "+this.id +"结算模式"+mode
- // logger.info(strk);////cssj
- return;
- }
- this.isYJJSGL = true;
- this.isYJKSGL = false;/////是否已经执行过开始函数了
- // console.warn("结算函数",mode);
- let str1 = "table 结算游戏 id: "+this.id +" 结算模式 "+mode
- logger.warn(str1);////cssj
- //ts--end
- // 结算数据
- var winner = this.winner;
- var data = { mode: String(mode), lead: String(winner.lead) };
- var wins = this.logic.fillDeep(Array(this.ccount), {
- win: 0,//总输赢
- lucky: 0,
- trans: 0,//明杠个数
- dark: 0,//暗杠个数
- penggang: 0,//碰杠个数
- isPoChan: 0,
- shiJiKouFen: 0,
- gangfen: 0,
- cardfen: 0,
- jiangma: 0,
- });
- data.hutype = [];//this.logic.getReasultTypeTL(winner.chs[0],this.huCards[winner.chs[0]],true)///////TL++胡牌牌型 胡牌人的chairID
- data.banker = this.chBanker;/////TL++
- data.chengbao = [];
- let isMZJYM = false;//是否满足无红中加一码
- if(winner.chs.length == 1 && this.jiangmaType == 1 && this.hzCount > 0 && this.isWGHZJYM){
- //无红中加1码,规则只能在红中个数大于0而且是159奖码情况下才能勾选
- if(this.handCards[winner.chs[0]].indexOf(51) == -1){
- //有多个赢家的时候无红中加一码不生效
- isMZJYM = true;
- }
- }
- let jiangmaInfo = this.logic.getJiangmaInfo(isMZJYM);
- data.jiangmaList = jiangmaInfo.jiangmaList;
- let jiangmaFen = jiangmaInfo.mafen;
- let yjgs = 0;//赢家个数
- // 计算输赢
- for (let i = 0; i < wins.length; ++i) {
- // 自摸
- let isMoHu = winner.lead == -1;
- // 胡牌者
- if (winner.chs.indexOf(i) != -1) {
- yjgs++;
- // console.warn("结算承包数据",this.logic.chengBaoTL,isMoHu,cbqk);
- if(this.logic.isLaGang){
- //抢杠胡:被抢者替每家输2分
- let lead = winner.lead;
- let sy = 2 * this.cell
- wins.forEach((w, c) => {
- if (c != i) {
- wins[lead].win -= sy;
- wins[i].win += sy;
- wins[lead].cardfen -= sy;
- wins[i].cardfen += sy;
- }
- });
- ////下面这段是计算奖码的分数
- wins.forEach((w, c) => {
- if (c != i) {
- if(c == lead){//////点炮玩家
- wins[lead].win -= jiangmaFen;
- wins[i].win += jiangmaFen;
- wins[lead].jiangma -= jiangmaFen;
- wins[i].jiangma += jiangmaFen;
- }
- }
- });
- }
- else{
- //不是抢杠胡
- if (isMoHu) {
- //自摸每家输2分
- let sy = 2 * this.cell
- wins.forEach((w, c) => {
- if (c != i) {
- w.win -= sy;
- wins[i].win += sy;
- w.cardfen -= sy;
- wins[i].cardfen += sy;
- }
- });
- ////下面这段是计算奖码的分数
- wins.forEach((w, c) => {
- if (c != i) {
- w.win -= jiangmaFen;
- wins[i].win += jiangmaFen;
- w.jiangma -= jiangmaFen;
- wins[i].jiangma += jiangmaFen;
- }
- });
- }
- else {
- //点炮者:给赢家输1分,其他人不输分
- let lead = winner.lead;
- // 点炮出钱
- // if (this.isWOne) {/////TL++zsyl,次判断方式适用于点炮出钱
- let hutype = [];
- let sy = this.cell
- wins.forEach((w, c) => {
- if (c != i) {
- if(c == lead){//////点炮玩家
- w.win -= sy;
- wins[i].win += sy;
- w.cardfen -= sy;
- wins[i].cardfen += sy;
- }
- }
- });
- ////下面这段是计算奖码的分数
- wins.forEach((w, c) => {
- if (c != i) {
- if(c == lead){//////点炮玩家
- wins[lead].win -= jiangmaFen;
- wins[i].win += jiangmaFen;
- wins[lead].jiangma -= jiangmaFen;
- wins[i].jiangma += jiangmaFen;
- }
- }
- });
- }
- }
-
- wins[i].lucky = 1;
- }
- // let str2 = "table 222结算函数---id:"+this.id +"结算模式"+mode
- // logger.info(str2);////cssj
-
- if(!(mode != MODE.NORMAL && this.isHZHG)) {
- // 杠牌 流局了而且勾选荒庄荒杠 的话则不计算杠分
- let gangMul = 0;
- for (let huCard of this.huCards[i]) {
- if (huCard.style == Logic.STYLE.ZMGANG) {
- gangMul += 1;
- wins[i].penggang += 1;
- } else if (huCard.style == Logic.STYLE.ANGANG) {
- gangMul += 2;
- wins[i].dark += 1;
- } else if (huCard.style == Logic.STYLE.GANG){
- //明杠谁点的杠谁付3分
- wins[i].trans += 1;
- wins[huCard.origin].win -= 3 * this.cell;
- wins[i].win += 3 * this.cell;
- wins[huCard.origin].gangfen -= 3 * this.cell;
- wins[i].gangfen += 3 * this.cell;
- }
- }
- if (gangMul > 0) {
- wins.forEach((w, c) => {
- if (c != i) {
- w.win -= gangMul * this.cell;
- wins[i].win += gangMul * this.cell;
- w.gangfen -= gangMul * this.cell;
- wins[i].gangfen += gangMul * this.cell;
- }
- });/////TL++杠牌有赢
- }
- }
- // 手牌
- let cards = { card: 0, groups: [], hands: [] };
- if (wins[i].lucky) {
- cards.card = this.huRes[i].card;
- }
- for (let huCard of this.huCards[i]) {
- cards.groups.push({ style: huCard.style, card: huCard.cards[0] });
- }
- let handCard = this.handCards[i] || [];
- let count = this.mcount - this.huCards[i].length * 3;
- cards.hands = handCard.slice(0, count);
- wins[i].cards = cards;
- }
- // let str3 = "table 333结算函数---id:"+this.id +",结算模式"+mode
- // logger.info(str3);////cssj
- //////TL++
- let shiJiKouFen = [];
- if(this.playerAllCount == 2) shiJiKouFen = [wins[0].win,wins[1].win];
- else if(this.playerAllCount == 3) shiJiKouFen = [wins[0].win,wins[1].win,wins[2].win];
- else if(this.playerAllCount == 4) shiJiKouFen = [wins[0].win,wins[1].win,wins[2].win,wins[3].win];
-
- for (let i = 0; i < this.ccount; ++i) {
- wins[i].shiJiKouFen = shiJiKouFen[i];
- }
- //console.warn("实际扣分XXX",shiJiKouFen,wins[0].win,wins[1].win,wins[2].win,wins[3].win)
- // 胜负情况
- data.wins = wins;
-
- let bjsy = [];//本局每个人的输赢
- for (let i = 0; i < this.ccount; ++i) {
- bjsy[i] = wins[i].win;
- }
- this.sszjDataList[this.sszjDataList.length] = bjsy;
- this.over += 1;// 局数+1
- //ts++
-
- let sszjScore = [];//ts++实时本局成绩
- let sszjAllScore = [];//ts++实时总成绩
- // 记录分数
- for (let i = 0; i < this.ccount; ++i) {
- let user = this.users[i];
- if (user)
- {
- sszjScore[i] = shiJiKouFen[i];
- this.score.writeScore(user.id,shiJiKouFen[i], 1);//设置分数
- sszjAllScore[i] = this.score.getScore(user.id);
- // if(this.gameKindTL == 2) sszjAllScore[i] -=200;
- if(this.over == 1)
- {
- this.score.writeCost(user.id,this.cost, 0); //ts++设置消耗
- }
- }
- }
- let endmode=ENDMODE.PLAYING;
- if(this.isGameOver())
- {
- this.isGameOk=true;
- endmode=ENDMODE.NORMALEND;//局数完成--正常结束
- }
- data.isover = this.isGameOk;
- data.nowTime = Date.now();
-
- this.setPaijuHuiFangData(M.CONCLUDE,data);/////TL++ 牌局回放 push结算数据
- /////TL++,用于记录玩家牌局回放的json文件名
- this.pjhffileName[this.pjhffileName.length] = this.PJHF.getjsonFileName(this.over,this.recordid,this.ctime);
- // let str4 = "table 444结算函数---id:%s"+this.id +"结算模式"+mode
- // logger.info(str4);////cssj
- //ts++胡的人
- let hu=-1;
- if (winner.chs.length >0 && winner.chs[0] >= 0 && winner.chs[0] <= 3)
- {
- hu=winner.chs[0];
- }
- //ts++实时战绩
- //this.sszjs.push({_id: String(this.over),c0Score:bjsy[0],c1Score:bjsy[1], c2Score:bjsy[2], c3Score:bjsy[3],banker:this.chBanker,hu:hu,pao:winner.lead, fName:jsonFileName});
- this.sszjs.push({_id: String(this.over),sszjScore:sszjScore,sszjAllScore:sszjAllScore,banker:this.chBanker,hu:hu,pao:winner.lead});
- /////固定庄家,不固定的话解除下面这一段的注释
- // 切换庄家
- if(yjgs == 0){
- //没有赢家,流局了,最后一个摸牌的人坐庄
- this.chBanker = this.logic.lastMoPaiChairID;
- }
- else if(yjgs == 1){
- //只有一个人赢了,谁赢谁做庄
- this.chBanker = winner.chs[0];
-
- }
- else if(yjgs > 1) {
- //一炮多响,放炮的人坐庄
- this.chBanker = winner.lead
- }
- /////TL++,10月9号,为了解决冲刺时前端的玩家分数偶尔会显示负数的bug
- data.playNowScore = [];
- for (let i = 0; i < this.ccount; ++i) {
- let user = this.users[i];
- if (user)
- {
- data.playNowScore[i] = this.score.getScore(user.id);
- }
- }
- // 重置本局
- this.resetRound();
- // 结算通知
- yield this.pushMsgAsync(-1, 'sxjiang_event', { type: M.CONCLUDE, data: data });
- this.PJHF.writePJHFJson({"pjhfDataList":this.PaijuHuiFang},this.over,this.id)
- this.logic.isZHYZ = false; /////TL++,是否最后一张
- // yield this.pushMsgAsync(-1, 'sxjiang_event', { type: 100, data: {"pjhfDataList":this.PaijuHuiFang}});//////最终发送给前端的牌局回放
- // let str6 = "table end 结算函数-id:"+this.id +"结算模式"+mode
- // logger.info(str6);////cssj
-
- yield this.endResultAsync(endmode);
- });
- // 发送聊天
- proto.sendMsgAsync = cor(function* (chairId, msg) {
- // console.error("sscc发送聊天+++++++++++++++++++++++++++++++++",chairId,msg)
- yield this.pushMsgAsync(-1, 'sxjiang_event', { type: M.CHAT, data: { chairId: String(chairId), msg: msg } });
- return { code: C.OK };
- });
- // 收费聊天 礼物收费
- proto.vsendMsgAsync = cor(function* (schairId, dchairId, msg) {
- if (schairId == dchairId || !this.users[dchairId]) {
- return { code: C.FAILD, msg: C.GAME_PARAM_ERROR };
- }
- let user = this.users[schairId];
- if (!user) {
- return { code: C.FAILD, msg: C.TABLE_NOT_USER };
- }
- var player = yield this.app.models.Player.findByIdAsync(user.id, 'diamond');
- let lwcost = this.LWKF[msg.type];//////TL++礼物扣费
- if(player)
- {
- if (((player.diamond) || 0) < lwcost) {
- return { code: C.FAILD, msg: C.GAME_DIAMOND_LOW };
- }
- let dSource=player.diamond;
- let dNow=player.diamond-lwcost;
- player.diamond -= lwcost;
- yield player.saveAsync();
- // 钻石记录
- var diamondrecord = new this.app.models.DiamondRecord({
- _id: uuid.v1(),
- playerId: user.id,
- dType: 5,//礼物
- dSource: dSource,
- dSwap: -lwcost,
- dNow: dNow,
- tableId: this.recordid
- });
- yield diamondrecord.saveAsync();
-
- //ts++设置消耗
- this.score.writeCost(user.id,0, lwcost);
- }
- yield this.pushMsgAsync(-1, 'sxjiang_event', { type: M.FEE_CHAT, data: { cost: String(lwcost),schairId: String(schairId), dchairId: String(dchairId), msg: msg } });
- return { code: C.OK };
- });
- //ts++写分 endtype = { 正常: 0,局数完成: 1, 房主解散: 2, 申请解散: 3 ,超时解散: 4 };
- proto.writeResultAsync = cor(function* (endmode) {
- logger.warn("牌局写入-------------- " + this.id );
- // console.warn("ts++---------牌局写入writeResultAsync",this.id);
- let gameCost=0;//游戏消耗
- let giftCost = 0;////道具消耗
- let nowTime = Date.now();
- let users = [];
- var scorers = this.score.getUsers();
- if (scorers.length > 0)
- {
- var scorersSort = _.sortBy(scorers, (i) => i.chairId);
- for (let scorer of scorersSort) {
- gameCost+=this.cost;
- giftCost+=scorer.giftCost;
- let userscore=scorer.score;
- // if(this.gameKindTL == 2) userscore -= 200;
- users.push({_id: scorer.playerId,chairId:scorer.chairId,userId: scorer.userId, name: scorer.name, sex: scorer.sex, headurl: scorer.headurl,over: scorer.over, score: userscore});
- //, gameCost: scorer.gameCost,giftCost: scorer.giftCost,diamond: scorer.diamond
- }
- }
- // if(this.isGameOk)////以前是解散的不算返利
- if(this.over > 0)////改成只要玩家扣钻了就有返利
- {
- // this.agentRebate=gameCost;//parseInt(gameCost*0.5);
- this.agentRebate=gameCost+giftCost;////礼物也算消耗进行返利
- console.warn("代理返利+++++",this.agentRebate);
- }
- else
- {
- this.agentRebate=0;
- }
- //console.warn("实时战绩",this.sszjs);//ts++
-
- this.PJHF.getTSjsonFileName(100,this.recordid,this.ctime);/////TL++,用于记录玩家牌局回放的json文件名
- // console.error("000HHHHHHHHHHHHHHHHHHHHHH",this.pjhffileName.length,this.pjhffileName);
- let datats = {
- _id: this.recordid,//记录
- tableNo: this.id,
- ownerId: this.ownerId,
- agentId: this.agentId,
- type: this.type,
- kind: this.gameKindTL,//玩法 2冲刺
- other: this.other,//////TL++2人3人的游戏规则
- playerCount: this.playerAllCount,//游戏人数
- round: this.round,//
- over: this.over,//游戏局数
- ctime: this.ctime,//创建时间
- stime: this.stime,//开始时间
- time: nowTime,//结束时间
- endMode: endmode,//结束类型
- gameCost: gameCost,//游戏消耗
- giftCost: giftCost,//礼物消耗
- agentRebate: parseInt(this.agentRebate*this.rEBATERATE),//代理返利
- sszjFile: this.logic.deepCloneTL(this.pjhffileName),
- sszj: this.logic.deepCloneTL(this.sszjs),
- users: users
- }
- this.PJHF.writeTSJson(datats,100,this.id);////在开始第一局的时候将桌子信息写入本地的json文件
- var fhmjtable = new this.app.models.FHMJTables({
- _id: this.recordid,//记录
- tableNo: this.id,
- ownerId: this.ownerId,
- agentId: this.agentId,
- type: this.type,
- kind: this.gameKindTL,//玩法 2冲刺
- other: this.other,//////TL++2人3人的游戏规则
- playerCount: this.playerAllCount,//游戏人数
- round: this.round,//
- over: this.over,//游戏局数
- ctime: this.ctime,//创建时间
- stime: this.stime,//开始时间
- time: nowTime,//结束时间
- endMode: endmode,//结束类型
- gameCost: gameCost,//游戏消耗
- giftCost: giftCost,//礼物消耗
- agentRebate: parseInt(this.agentRebate*this.rEBATERATE),//代理返利
- sszjFile: this.pjhffileName,
- sszj: this.sszjs,
- users: users
- });
- // console.warn("fhmjtable new",fhmjtable);
- yield fhmjtable.saveAsync();
- // logger.info("战绩写入fhmjtable.saveAsync()--------------",this.id);
- });
- // 结束信息 var endtype = { 局数完成: 1, 主动解散: 2, 断线解散: 3 ,超时解散: 4 };
- proto.endResultAsync = cor(function* (endmode) {
- // console.warn("ts++---------记录信息",this.id);
- let str6 = "table 结束信息--id: "+this.id +" ,结算模式 "+endmode;
- logger.warn(str6);////cssj
- if(endmode>ENDMODE.PLAYING)//ts++关闭
- {
- let nowTime = Date.now();
- if(this.state<STATE.END)//ts++防止重复写入
- {
- this.state = STATE.END;
- if (this.endTimer) {
- clearTimeout(this.endTimer);
- this.endTimer = null;
- }
- if (this.overTimer) {
- clearTimeout(this.overTimer);
- this.overTimer = null;
- }
-
-
- // console.warn("ts++---------局数完成",this.over);
- if(this.over>0)
- {
- var scorers = this.score.getUsers();
- if (scorers.length > 0) {
- let data = {
- _id: this.recordid,
- tableNo: this.id,
- ownerId: this.ownerId,
- type:String(this.type),
- kind: String(this.gameKindTL),
- over: String(this.over),
- round: String(this.round),
- time: String(nowTime),
- ctime: String(this.ctime),
- keep: String(nowTime - this.stime),
- other: this.other,
- playerCount:this.playerAllCount,
- agentId: this.agentId
- };
- let collects = [];
-
- for (let scorer of scorers) {
- let userscore=scorer.score;
- // if(this.gameKindTL == 2) userscore -= 200;//TL++,因为总的结算界面的每个玩家的分数范围为-200 ~ 600
- collects.push({ chairId:scorer.chairId,name: scorer.name, sex: scorer.sex, headurl: scorer.headurl, score: userscore });
- }
-
- data.users = _.sortBy(collects, (i) => -i.score);
- //data.sszjFile=this.pjhffileName;
- data.sszj=this.sszjs;
- yield this.pushMsgAsync(-1, 'sxjiang_event', { type: M.TOTAL_CONCLUDE, data: data });////汇总结算
- }
- //console.warn("ts++---------牌局写入");
- yield this.writeResultAsync(endmode);
- }
- //console.warn("ts---------牌局结束");
- for (let user of this.users) {
- if (user) {
- if (user.isOffline())
- {
- user.state = User.STATE.FREE;
- user.state2 = User.STATE.FREE;
- this.leaveUsers.push(user.id);
- ///yield this.game.leaveTableAsync(user.id);
- }
- else
- {
- user.state = User.STATE.FREE;
- user.state2 = User.STATE.FREE;
- }
- }
- }
- }
- if(endmode==ENDMODE.SYSTEMEND)
- {
- yield this.pushMsgAsync(-1, 'sxjiang_event', { type: M.TABLE_JIESAN });
- }
-
- if(this.leaveUsers.length>0)
- {
- this.app.timer.setTimeout(() => this.leaveUserTimeAsync(), 100);
- }
- this.game.deleteTable(this.id);//ts++删除房间
- // let str5 = "table 结束信息22 关闭-id:"+this.id +"结算模式"+endmode;
- // logger.info(str5);////cssj
- }
- else//普通结束
- {
- // let str5 = "table 结束信息 普通结束---id:"+this.id +"结算模式"+endmode
- // logger.info(str5);////cssj
- this.state = STATE.FREE2;
- for (let user of this.users) {
- if (user) user.state2 = User.STATE.FREE;
- }
- }
-
- let str7 = "table end 结束信息---id:%s "+this.id +" 结算模式 "+endmode;
- logger.warn(str7);////cssj
-
- });
- //ts++离开用户退出定时器
- proto.leaveUserTimeAsync = cor(function* () {
- // console.warn("离开用户退出定时器,离开用户数==%d",this.leaveUsers.length);////cssj
- if(this.leaveUsers.length>0)
- {
- let userid = this.leaveUsers[0];
- this.leaveUsers.splice(0, 1);
- let str7 = "table end 离开用户退出定时器---id:%s "+this.id +" userid "+userid;
- logger.warn(str7);////cssj
- yield this.game.leaveTableAsync(userid);
- }
- if(this.leaveUsers.length>0)
- {
- this.app.timer.setTimeout(() => this.leaveUserTimeAsync(), 100);
- }
- });
- // TL++,得到玩家位置
- proto.sendLocationAsync = cor(function* (user,msg) {
- /////设置玩家的经纬度
- user.longitude = msg.longitude; // 经度,浮点数,范围为180 ~ -180。
- user.latitude = msg.latitude; // 纬度,浮点数,范围为90 ~ -90
- let tempData = {
- userId: user.userId,
- account: user.account,
- longitude: msg.longitude,
- latitude: msg.latitude
- }
- //////向其他玩家广播该玩家位置
- yield this.pushMsgAsync(-1, 'sxjiang_event', { type: M.COAST_PLAYERLOCATION, data: tempData });
- return { code: C.OK, data: tempData };
- });
- // 玩家信息
- proto.roleInfoAsync = cor(function* (chairId) {
- // console.log("玩家信息玩家信息玩家信息");
- var user = this.users[chairId];
- if (!user) {
- return { code: C.FAILD, msg: C.GAME_PARAM_ERROR };
- }
- var data = { userId: '0', ttCount: '0', winCount: '0', noCount: '0', runCount: '0' };
- data.userId =user.userId;
- return { code: C.OK, data: data };
- });
- //ts++请求结束定时器
- proto.overTimeAsync = cor(function* (endmode) {
- yield this.pushMsgAsync(-1, 'sxjiang_event', { type: M.TABLE_JIESAN });
- let str6 = "table 请求结束定时器---id: "+this.id +" ,endmode: "+endmode
- logger.warn(str6);////cssj
- yield this.endResultAsync(endmode);//ts++ 房主解散 写分
- });
- // 请求结束
- proto.overTableAsync = cor(function* (user) {
- // console.warn("ts+++++请求结束",user.chairId);
- let str3 = "table 请求结束.......id: "+ this.id + " user.chairId: " + user.chairId + " user.name: " + user.name ;
- logger.warn(str3);////cssj
- if(this.state == STATE.END)
- {
- this.leaveAsync(user);
- return { code: C.OK, data:{jieSanType: 2}};//离开房间
- }
- if(this.reqJieSan.indexOf(2) != -1) return;/////有发起人的时候
- // console.warn("2222请求结束请求结束请求结束",this.reqJieSan);
- //解散桌子数据,前面为chirid后面为情况-1:未操作 0:拒绝 1:同意 2为解散发起
- //jieSanType =1:游戏开始前房主申请解散 =2:游戏开始前非房主玩家退出房间 =3:游戏过程中玩家申请解散 =4游戏过程中是房主但没参与游戏退出房间 =5其他
-
- if(this.gameNeverStart) {//游戏是否从未开始过,用于解散房间判断
- if(user.userId == this.ownerUid){
- yield this.pushMsgAsync(-1, 'sxjiang_event', { type: M.TABLE_JIESAN });
- // let str5 = "table 房主解散-id:"+this.id+ ",uid"+user.userId;
- // logger.info(str5);////cssj
- yield this.endResultAsync(ENDMODE.OWNEREND);//ts++ 房主解散 写分
- return { code: C.OK, data:{jieSanType: 1}};
- }
- else{
- this.leaveAsync(user);
- return { code: C.OK, data:{jieSanType: 2}};//离开房间
- }
- }
- else
- {
- let chairId=user.chairId;
- if(chairId >= 0 && chairId < 4 )
- {
- if(this.overFlag==0)//发起
- {
- this.overFlag = 1;
- this.reqJieSan[0]=-1;
- this.reqJieSan[1]=-1;
- this.reqJieSan[2]=-1;
- this.reqJieSan[3]=-1;
- this.reqJieSan[chairId]=2;
- let jsdata = [];//ts++实时本局成绩
- jsdata[0] = this.reqJieSan[0];
- jsdata[1] = this.reqJieSan[1];
- jsdata[2] = this.reqJieSan[2];
- jsdata[3] = this.reqJieSan[3];
- this.JSFJTime = 60;//////解散倒计时60秒
-
- if (!this.overTimer) this.overTimer = this.app.timer.setTimeout(() => this.overTimeAsync(ENDMODE.REGEND),this.JSFJTime*1000);//解散倒计时60秒
- yield this.pushMsgAsync(-1, 'sxjiang_event', { type: M.REQUEST_END, data: { chairId: String(chairId),time: this.JSFJTime,jsdata:jsdata}});
- return { code: C.OK, data:{jieSanType: 3}};
- }
- else//同意
- {
- return this.agreeOverAsync(chairId);
- }
- }
- else
- {
- return { code: C.FAILD, msg: C.TABLE_ALREADY_SQJS };
- }
- }
-
- return { code: C.OK, data:{jieSanType: 5}};
- });
- // 拒绝结束
- proto.refuseOverAsync = cor(function* (user) {
-
- let str3 = "table 拒绝结束.......id: "+ this.id + " user.chairId: " + user.chairId + " user.name: " + user.name ;
- logger.warn(str3);////cssj
- if(this.state == STATE.END)
- {
- this.leaveAsync(user);
- return { code: C.OK, data:{jieSanType: 2}};//离开房间
- }
- if(this.overFlag == 0) //ts++已经拒绝了
- {
- return { code: C.OK };
- }
- this.overFlag = 0;
- let chairId=user.chairId;
- // console.error("ts++----------拒绝结束",chairId);
- this.reqJieSan[chairId]=0;//解散桌子数据,前面为chirid后面为情况-1:未操作 0:拒绝 1:同意 2为解散发起
- let jsdata = [];//ts++实时本局成绩
- jsdata[0] = this.reqJieSan[0];
- jsdata[1] = this.reqJieSan[1];
- jsdata[2] = this.reqJieSan[2];
- jsdata[3] = this.reqJieSan[3];
- if (this.overTimer) {
- clearTimeout(this.overTimer);
- this.overTimer = null;
- }
-
- yield this.pushMsgAsync(-1, 'sxjiang_event', { type: M.REFUSE_END, data: { chairId: String(chairId),time: 0,jsdata:jsdata} });
- //this.reqJieSan = [[-1,-1],[-1,-1],[-1,-1],[-1,-1]];/////解散桌子数据,前面为chirid后面为情况-1:未操作 0:拒绝 1:同意 2为解散发起
- this.reqJieSan[0]=-1;
- this.reqJieSan[1]=-1;
- this.reqJieSan[2]=-1;
- this.reqJieSan[3]=-1;
- return { code: C.OK };
- });
- // 同意结束
- proto.agreeOverAsync = cor(function* (user) {
- let str3 = "table 同意结束.......id: "+ this.id + " user.chairId: " + user.chairId + " user.name: " + user.name ;
- logger.warn(str3);////cssj
- if(this.state == STATE.END)
- {
- this.leaveAsync(user);
- return { code: C.OK, data:{jieSanType: 2}};//离开房间
- }
- if(this.overFlag == 0) //ts++已经拒绝了
- {
- return { code: C.OK };
- }
- let chairId=user.chairId;
- // console.error("ts++----------同意结束",chairId);
- this.reqJieSan[chairId] = 1;/////解散桌子数据,前面为chirid后面为情况-1:未操作 0:拒绝 1:同意 2为解散发起
- let jsdata = [];//ts++实时本局成绩
- jsdata[0] = this.reqJieSan[0];
- jsdata[1] = this.reqJieSan[1];
- jsdata[2] = this.reqJieSan[2];
- jsdata[3] = this.reqJieSan[3];
- this.JSFJTime -= 20;//////解散房间倒计时60秒
- yield this.pushMsgAsync(-1, 'sxjiang_event', { type: M.AGREE_END, data: { chairId: String(chairId),time: this.JSFJTime,jsdata:jsdata} });
- let jsFlag = 0;
- for (let i = 0; i < 4; ++i)
- {
- if(this.reqJieSan[i] >=1 )
- {
- jsFlag+=1;
- }
- }
-
- if(jsFlag>=this.ccount || this.JSFJTime<=0)
- {
- if(this.backStartTimer)
- {
- clearTimeout(this.backStartTimer);
- this.backStartTimer = null;
- }
- yield this.pushMsgAsync(-1, 'sxjiang_event', { type: M.TABLE_JIESAN });
- // let str4 = "table 全部同意结束-id:%s"+this.id + ",uid"+user.userId+",state"+ this.state;
- // logger.info(str4);////cssj
- yield this.endResultAsync(ENDMODE.REGEND);//ts++ 结束
- }
- else
- {
- if (this.overTimer) {
- clearTimeout(this.overTimer);
- this.overTimer = null;
- }
- if (!this.overTimer) this.overTimer = this.app.timer.setTimeout(() => this.overTimeAsync(ENDMODE.REGEND),this.JSFJTime*1000);//解散倒计时60秒
- }
-
- // let str3 = "table end 同意结束-id:"+this.id + ",uid"+user.userId+",state"+ this.state;
- // logger.info(str3);////cssj
- return { code: C.OK, data: { chairId: String(chairId),time: this.JSFJTime, jieSanType: 1 }};
- });
- //////TL++,设置记录游戏过程中的记录数据
- proto.setPaijuHuiFangData = function (_operateKind,_data){
- let data = this.logic.deepCloneTL(_data);
- data.operateKind = _operateKind;
- this.PaijuHuiFang[this.PaijuHuiFang.length] = data;
- };
- // 得到玩家位置
- proto.getLocationAsync = cor(function* () {
- let location = [];
- // 桌上玩家
- for (let i = 0; i < this.users.length; ++i) {
- let user = this.users[i];
- if (user) {
- location.push({
- chairId: user.chairId,
- longitude: user.longitude,
- latitude: user.latitude,
- headurl: user.headurl,
- name: user.name
- });
- }
- }
- // console.warn("ts+++++玩家位置",location);
- return { code: C.OK, data: location };
- });
|