头部新增的方法.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. function printStack(){
  2. const stack = new Error().stack;
  3. console.log("调用堆栈:",stack);
  4. }
  5. const originalConsoleLog = console.log;
  6. function isHighSurrogate(codeUnit) {
  7. return codeUnit >= 0xD800 && codeUnit <= 0xDBFF;
  8. }
  9. function isLowSurrogate(codeUnit) {
  10. return codeUnit >= 0xDC00 && codeUnit <= 0xDFFF;
  11. }
  12. function splitAndPrintString(str, maxSize) {
  13. // if(str.indexOf(`{"optionInfo":[{"amount`)!=-1){
  14. // printStack();
  15. // }
  16. let strLength = str.length;
  17. for (let i = 0; i < strLength; i += maxSize) {
  18. let end = i + maxSize;
  19. // 确保不要在代理对中间拆分
  20. if (end < str.length && isHighSurrogate(str.charCodeAt(end - 1)) && isLowSurrogate(str.charCodeAt(end))) {
  21. end++;
  22. }
  23. if (strLength > maxSize) {//超过1页
  24. if (i === 0) { // 第一段
  25. originalConsoleLog(str.slice(i, end), "__>>__");
  26. } else if (end >= strLength) { // 最后一段
  27. originalConsoleLog("__<<__", str.slice(i, end));
  28. } else { // 中间的段
  29. originalConsoleLog("__<<__", str.slice(i, end), "__>>__");
  30. }
  31. } else {
  32. originalConsoleLog(str.slice(i, end));
  33. }
  34. }
  35. }
  36. //重新定义console.log方法
  37. console.log = function (...args) {
  38. const maxChunkSize = 800; // 设定最大字符数,可根据需要调整
  39. // 将所有参数转换为字符串并拼接
  40. const combinedString = args.map(arg => {
  41. if (typeof arg === 'object') {
  42. try {
  43. return JSON.stringify(arg);
  44. } catch (e) {
  45. return "啊啊啊啊啊,解析失败了" + e.message;
  46. }
  47. } else {
  48. return String(arg);
  49. }
  50. }).join(' ');
  51. // 分段打印处理过的字符串
  52. splitAndPrintString(combinedString, maxChunkSize);
  53. };
  54. //下注对象
  55. var OptionInfo = { option: 0, odds: 1, totalBet: 0 }
  56. var betInfoMap = new Map();
  57. var totalProfit = 0;
  58. function dealMsg(msgType,data) {
  59. switch(msgType){
  60. case "GameDataSynNotify"://进房间后同步已下注信息
  61. betInfoMap.clear();
  62. // console.log("====>>>>啦啦啦啦",data.optionInfo);
  63. data.optionInfo.forEach((info) => {
  64. if (betInfoMap.has(info.option)) {
  65. // console.log("====>>>>有这个option",info.option);
  66. // 如果 option 已存在,累加 totalBet
  67. let existingInfo = betInfoMap.get(info.option);
  68. existingInfo.totalBet += info.totalBet;
  69. existingInfo.option = info.option;
  70. existingInfo.odds = info.odds;
  71. betInfoMap.set(info.option, existingInfo);
  72. } else {
  73. // console.log("====>>>>没有这个option",info.option);
  74. // 如果 option 不存在,直接添加
  75. betInfoMap.set(info.option, {
  76. odds: info.odds,
  77. totalBet: info.totalBet,
  78. option: info.option
  79. });
  80. }
  81. });
  82. console.log("====>>>>同步后自己的数据",[...betInfoMap]);
  83. break;
  84. case "BetNotify"://局中下注信息
  85. var detail = data.detail;
  86. var option = detail.option;
  87. var betAmount = detail.betAmount;
  88. if (betInfoMap.has(option)) {
  89. // 如果 option 已存在,累加 betAmount 到 totalBet
  90. let existingInfo = betInfoMap.get(option);
  91. existingInfo.totalBet += betAmount; // 累加投注金额
  92. existingInfo.option = info.option;
  93. existingInfo.odds = info.odds;
  94. betInfoMap.set(option, existingInfo);
  95. } else {
  96. // 如果 option 不存在,创建新记录
  97. betInfoMap.set(option, {
  98. odds: detail.odds, // 初始赔率
  99. totalBet: betAmount, // 初始投注金额
  100. limitRed: 0 // 示例中未提及,这里假设为 0
  101. });
  102. };
  103. // console.log("====>>>>同步 下注后的数据",[...betInfoMap]);
  104. break;
  105. case "StopBetNotify"://开牌信息,后面打印用
  106. break;
  107. case "StartSettlementNotify"://估计只是执行开奖动画?
  108. break;
  109. case "GameRoundEndNotify"://本轮游戏结束,结算玩家和盈利信息
  110. // 初始化总赢取金额为 0
  111. let totalPayAmount = 0;
  112. // 遍历每个玩家的结算信息
  113. data.playerSettle.forEach(player => {
  114. // 遍历每个玩家的 settle 数组
  115. player.settle.forEach(settleItem => {
  116. // 累加 winAmount 到总赢取金额
  117. totalPayAmount += settleItem.winAmount;
  118. });
  119. });
  120. // 遍历 otherPlayers 中的 settle 数组(如果存在)
  121. if (data.otherPlayers && data.otherPlayers.settle) {
  122. data.otherPlayers.settle.forEach(settleItem => {
  123. // 累加 winAmount 到总赢取金额
  124. totalPayAmount += settleItem.winAmount;
  125. });
  126. }
  127. // 初始化一个变量来存储 totalBet 的累计值
  128. let totalBetSum = 0;
  129. // 使用 forEach 遍历 map 中的每一个元素
  130. betInfoMap.forEach((value, key) => {
  131. // 累加每一个 totalBet 值
  132. totalBetSum += value.totalBet;
  133. });
  134. var curentRoundProfit = totalBetSum-totalPayAmount;
  135. totalProfit += curentRoundProfit;
  136. // 打印总赢取金额
  137. console.log(`====>>>>同步后:总盈亏:${totalProfit/100}¥,\t本局总收入是:${totalBetSum/100}¥,\t庄家总付出金额: ${totalPayAmount/100}¥,\t本局利润是:${(curentRoundProfit)/100}¥`);
  138. betInfoMap.clear();
  139. break;
  140. case "ReadyGameNotify"://新一轮开始,时间还有剩余秒速 {"nextRoundEndStamp":1711691423,"leftSeconds":3}
  141. break;
  142. case "DealNotify"://更新座位上的玩家信息、前几轮大师和鲨鱼的胜负结果、鲨鱼和大师的手牌信息
  143. break;
  144. case "ShowOddsNotify"://更新本轮赔率、几秒后开始
  145. break;
  146. case "StartBetNotify"://可以开始下注通知、可下注时长 JS: {"nextRoundEndStamp":1711691443,"leftSeconds":15}
  147. break;
  148. case "MergeAutoBetNotify"://同步自动下注的玩家信息?还是后台电脑人?
  149. break;
  150. default:
  151. //
  152. }
  153. }