|
@@ -0,0 +1,171 @@
|
|
|
+function printStack(){
|
|
|
+ const stack = new Error().stack;
|
|
|
+ console.log("调用堆栈:",stack);
|
|
|
+}
|
|
|
+
|
|
|
+const originalConsoleLog = console.log;
|
|
|
+
|
|
|
+function isHighSurrogate(codeUnit) {
|
|
|
+ return codeUnit >= 0xD800 && codeUnit <= 0xDBFF;
|
|
|
+}
|
|
|
+
|
|
|
+function isLowSurrogate(codeUnit) {
|
|
|
+ return codeUnit >= 0xDC00 && codeUnit <= 0xDFFF;
|
|
|
+}
|
|
|
+
|
|
|
+function splitAndPrintString(str, maxSize) {
|
|
|
+ // if(str.indexOf(`{"optionInfo":[{"amount`)!=-1){
|
|
|
+ // printStack();
|
|
|
+ // }
|
|
|
+ let strLength = str.length;
|
|
|
+ for (let i = 0; i < strLength; i += maxSize) {
|
|
|
+ let end = i + maxSize;
|
|
|
+
|
|
|
+ // 确保不要在代理对中间拆分
|
|
|
+ if (end < str.length && isHighSurrogate(str.charCodeAt(end - 1)) && isLowSurrogate(str.charCodeAt(end))) {
|
|
|
+ end++;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (strLength > maxSize) {//超过1页
|
|
|
+ if (i === 0) { // 第一段
|
|
|
+ originalConsoleLog(str.slice(i, end), "__>>__");
|
|
|
+ } else if (end >= strLength) { // 最后一段
|
|
|
+ originalConsoleLog("__<<__", str.slice(i, end));
|
|
|
+ } else { // 中间的段
|
|
|
+ originalConsoleLog("__<<__", str.slice(i, end), "__>>__");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ originalConsoleLog(str.slice(i, end));
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+//重新定义console.log方法
|
|
|
+console.log = function (...args) {
|
|
|
+ const maxChunkSize = 800; // 设定最大字符数,可根据需要调整
|
|
|
+
|
|
|
+ // 将所有参数转换为字符串并拼接
|
|
|
+ const combinedString = args.map(arg => {
|
|
|
+ if (typeof arg === 'object') {
|
|
|
+ try {
|
|
|
+ return JSON.stringify(arg);
|
|
|
+ } catch (e) {
|
|
|
+ return "啊啊啊啊啊,解析失败了" + e.message;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ return String(arg);
|
|
|
+ }
|
|
|
+ }).join(' ');
|
|
|
+
|
|
|
+ // 分段打印处理过的字符串
|
|
|
+ splitAndPrintString(combinedString, maxChunkSize);
|
|
|
+};
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+//下注对象
|
|
|
+var OptionInfo = { option: 0, odds: 1, totalBet: 0 }
|
|
|
+
|
|
|
+var betInfoMap = new Map();
|
|
|
+
|
|
|
+function dealMsg(msgType,data) {
|
|
|
+ switch(msgType){
|
|
|
+ case "GameDataSynNotify"://进房间后同步已下注信息
|
|
|
+ betInfoMap.clear();
|
|
|
+ console.log("====>>>>啦啦啦啦",data.optionInfo);
|
|
|
+ data.optionInfo.forEach((info) => {
|
|
|
+ if (betInfoMap.has(info.option)) {
|
|
|
+ console.log("====>>>>有这个option",info.option);
|
|
|
+ // 如果 option 已存在,累加 totalBet
|
|
|
+ let existingInfo = betInfoMap.get(info.option);
|
|
|
+ existingInfo.totalBet += info.totalBet;
|
|
|
+ existingInfo.option = info.option;
|
|
|
+ existingInfo.odds = info.odds;
|
|
|
+
|
|
|
+ betInfoMap.set(info.option, existingInfo);
|
|
|
+ } else {
|
|
|
+ console.log("====>>>>没有这个option",info.option);
|
|
|
+ // 如果 option 不存在,直接添加
|
|
|
+ betInfoMap.set(info.option, {
|
|
|
+ odds: info.odds,
|
|
|
+ totalBet: info.totalBet,
|
|
|
+ option: info.option
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ console.log("====>>>>同步后自己的数据",[...betInfoMap]);
|
|
|
+ break;
|
|
|
+
|
|
|
+ case "BetNotify"://局中下注信息
|
|
|
+ var detail = data.detail;
|
|
|
+ var option = detail.option;
|
|
|
+ var betAmount = detail.betAmount;
|
|
|
+ if (betInfoMap.has(option)) {
|
|
|
+ // 如果 option 已存在,累加 betAmount 到 totalBet
|
|
|
+ let existingInfo = betInfoMap.get(option);
|
|
|
+ existingInfo.totalBet += betAmount; // 累加投注金额
|
|
|
+ existingInfo.option = info.option;
|
|
|
+ existingInfo.odds = info.odds;
|
|
|
+ betInfoMap.set(option, existingInfo);
|
|
|
+ } else {
|
|
|
+ // 如果 option 不存在,创建新记录
|
|
|
+ betInfoMap.set(option, {
|
|
|
+ odds: detail.odds, // 初始赔率
|
|
|
+ totalBet: betAmount, // 初始投注金额
|
|
|
+ limitRed: 0 // 示例中未提及,这里假设为 0
|
|
|
+ });
|
|
|
+ };
|
|
|
+ // console.log("====>>>>同步 下注后的数据",[...betInfoMap]);
|
|
|
+
|
|
|
+ break;
|
|
|
+ case "StopBetNotify"://开牌信息,后面打印用
|
|
|
+ break;
|
|
|
+ case "StartSettlementNotify"://估计只是执行开奖动画?
|
|
|
+ break;
|
|
|
+ case "GameRoundEndNotify"://本轮游戏结束,结算玩家和盈利信息
|
|
|
+ // 初始化总赢取金额为 0
|
|
|
+ let totalPayAmount = 0;
|
|
|
+
|
|
|
+ // 遍历每个玩家的结算信息
|
|
|
+ data.playerSettle.forEach(player => {
|
|
|
+ // 遍历每个玩家的 settle 数组
|
|
|
+ player.settle.forEach(settleItem => {
|
|
|
+ // 累加 winAmount 到总赢取金额
|
|
|
+ totalPayAmount += settleItem.winAmount;
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ // 遍历 otherPlayers 中的 settle 数组(如果存在)
|
|
|
+ if (data.otherPlayers && data.otherPlayers.settle) {
|
|
|
+ data.otherPlayers.settle.forEach(settleItem => {
|
|
|
+ // 累加 winAmount 到总赢取金额
|
|
|
+ totalPayAmount += settleItem.winAmount;
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ // 初始化一个变量来存储 totalBet 的累计值
|
|
|
+ let totalBetSum = 0;
|
|
|
+
|
|
|
+ // 使用 forEach 遍历 map 中的每一个元素
|
|
|
+ betInfoMap.forEach((value, key) => {
|
|
|
+ // 累加每一个 totalBet 值
|
|
|
+ totalBetSum += value.totalBet;
|
|
|
+ });
|
|
|
+ // 打印总赢取金额
|
|
|
+ console.log(`====>>>>同步后:本局总收入是:${totalBetSum/100}¥ ,庄家总付出金额: ${totalPayAmount/100}¥,利润是:${(totalBetSum-totalPayAmount)/100}¥`);
|
|
|
+ betInfoMap.clear();
|
|
|
+ break;
|
|
|
+ case "ReadyGameNotify"://新一轮开始,时间还有剩余秒速 {"nextRoundEndStamp":1711691423,"leftSeconds":3}
|
|
|
+ break;
|
|
|
+ case "DealNotify"://更新座位上的玩家信息、前几轮大师和鲨鱼的胜负结果、鲨鱼和大师的手牌信息
|
|
|
+ break;
|
|
|
+ case "ShowOddsNotify"://更新本轮赔率、几秒后开始
|
|
|
+ break;
|
|
|
+ case "StartBetNotify"://可以开始下注通知、可下注时长 JS: {"nextRoundEndStamp":1711691443,"leftSeconds":15}
|
|
|
+ break;
|
|
|
+ case "MergeAutoBetNotify"://同步自动下注的玩家信息?还是后台电脑人?
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ //
|
|
|
+ }
|
|
|
+}
|