4 Коміти e28ab3a647 ... da9788229d

Автор SHA1 Опис Дата
  Alex da9788229d 优化数据统计 1 рік тому
  Alex ab9d825f0c 远端服务端统计代码优化 1 рік тому
  Alex 68526c563d 脚本更新 1 рік тому
  Alex 4bc554bfee 自动点击扑克大师线路1 1 рік тому

+ 116 - 17
yyyy_js/python-server/pokermaster/PokerMasterDataProccesser.py

@@ -10,6 +10,8 @@ OPTIONS = [101, 102, 103, 301, 302, 303, 304, 305]
 class BetOption:
     def __init__(self, option, odds, limit, total_bet=0):
         self.option = option
+        if odds == 0:
+            self.odds = 1
         self.odds = odds
         self.limitRed = limit
         self.total_bet = total_bet
@@ -22,26 +24,42 @@ class BetOption:
 # 用户信息
 class User:
     # 对应option的下注金额
-    betOptionAmounts = {option: 0 for option in OPTIONS}
 
     def __init__(self, bet_count, uid, amount):
         self.bet_count = bet_count
         self.uid = uid
         self.betAmount = amount
+        self.finance = 0
+        self.betOptionAmounts = {option: 0 for option in OPTIONS}
 
 
 class UserEncoder(json.JSONEncoder):
     def default(self, obj):
         if isinstance(obj, User):
-            return {"uid": obj.uid, "bet_count": obj.bet_count, "betAmount": obj.betAmount}
+            return {"uid": obj.uid, "bet_count": obj.bet_count, "betAmount": obj.betAmount, "finance": obj.finance}
         # 让基类的 default 方法抛出 TypeError
         return json.JSONEncoder.default(self, obj)
 
 
+def init_round_option_info():
+    global round_option_info
+    round_option_info = {option: BetOption(option, 0, 0) for option in OPTIONS}
+
+
 # 用于存储User对象的用户信息和次数,key为用户ID,value为User对象
 round_user_betinfo = {}
+
+round_option_info = {}
+
 # 本轮选项赔率和下注金额
-round_option_info = {option: BetOption(option, 0, 0) for option in OPTIONS}
+init_round_option_info()
+
+# 庄家的钱
+banker_finance = 0
+
+# 虚拟一个用户,用来记录同步下来的下注数据,不然结算会异常,但是这样统计个人数据的时候,就会有点出入,
+# 没办法,因为会被定时踢出
+DATA_SYN_NOTIFY_UID = -9999
 
 
 async def deal_message(message, broadcast_func):
@@ -51,25 +69,72 @@ async def deal_message(message, broadcast_func):
             await betNotify(data)
         elif msg_type == "GameDataSynNotify":
             await gameDataSynNotify(data)
+        elif msg_type == "ShowOddsNotify":
+            await ShowOddsNotify(data)
         elif msg_type == "KickNotify":
             await kickNotify(data, broadcast_func)
         elif msg_type == "GameRoundEndNotify":
-            await gameRoundEndNotify()
+            await gameRoundEndNotify(data)
+        elif msg_type == "MergeAutoBetNotify":
+            await MergeAutoBetNotify(data)
         else:
             logging.info(f"Received message: {message}")
     except Exception as e:
         logging.info(f"Received message: {message}")
 
 
-async def gameRoundEndNotify():
+async def gameRoundEndNotify(data):
+    global banker_finance
     print(f"收到结束下注GameRoundEndNotify")
+    # 开始结算
+    # 总收入
+    current_round_income = 0
+    all_bet_amount = 0
+
+    for option in round_option_info.values():
+        all_bet_amount += option.total_bet
+        current_round_income = all_bet_amount
+
+    # 开奖结果
+    option_results = data["optionResult"]
+    for open_result in option_results:
+        # 开奖结果
+        option = open_result["option"]
+        result = open_result["result"]
+        # 这个是下注的选项信息
+        option_info_option_ = round_option_info[option]
+        odds_rate = option_info_option_.odds
+        if result == 1:  # 证明这个选项中奖了
+            # 庄家结算
+            final_out = option_info_option_.total_bet * odds_rate
+            current_round_income -= final_out
+            print(
+                f"选项{option}中奖了, 赔率{odds_rate}, 该选项总下注{option_info_option_.total_bet / 100}¥, 赔付了{final_out / 100}¥")
+
+    # 玩家结算
+    for user in round_user_betinfo.values():
+        for option in user.betOptionAmounts:
+            open_result = next(filter(lambda opt: opt["option"] == option, option_results))
+            odds_rate = round_option_info[option].odds
+            if open_result is not None and open_result["result"] == 1:
+                user.finance += user.betOptionAmounts[option] * odds_rate
+            else:
+                user.finance -= user.betOptionAmounts[option]
+    banker_finance += current_round_income
+    print(f"庄家金币: {banker_finance / 100}¥    本轮总下注{all_bet_amount / 100}¥ 收入: {current_round_income / 100}¥")
+
+    time = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
+    # 格式化一下,避免数字位数导致各种缩进
+    with open("庄家盈亏记录.txt", "a", encoding="utf-8") as f:
+        finalxx = f"{time}:庄家金币: {banker_finance / 100}¥    本轮总收入: {current_round_income / 100}¥"
+        print(finalxx)
+        f.write(finalxx + "\n")
     # 每把结束存储数据,然后清空数据
-    with open("../user_bet.log", "a") as f:
-        time = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
+    with open("用户记录.txt", "a", encoding="utf-8") as f:
         # 将user_dict 转成json字符串
-
         f.write(f"{time}:{json.dumps(round_user_betinfo, cls=UserEncoder)}\n")
-        round_user_betinfo.clear()
+    round_user_betinfo.clear()
+    init_round_option_info()
 
 
 async def kickNotify(data, broadcast_func):
@@ -83,31 +148,65 @@ async def kickNotify(data, broadcast_func):
                         console.error("节点未找到或节点上没有cc.Button组件");
                     }
                 },3000);
+                
                 setTimeout(function(){
+                
                    let btnDownNode = cc.find("Canvas/container/content/smallGame/createScrollView/view/cotent/row1/pokerNode/porkermaster/allHand");
                     if (btnDownNode && btnDownNode.getComponent(cc.Button)) {
                         btnDownNode.getComponent(cc.Button).clickEvents[0].emit([btnDownNode]);
                     } else {
-                        console.error("节点未找到或节点上没有cc.Button组件");
+                        console.error("没有找到扑克大师游戏节点");
+                    }
+                    
+                    // 点击扑克大师游戏线路1
+                    let pokerMasterGameLine1 = cc.find("Canvas/container/content/smallGame/New Node/listPokerMasterContent/main/view/content/item/main");
+                    if (pokerMasterGameLine1 && pokerMasterGameLine1.getComponent(cc.Button)) {
+                        pokerMasterGameLine1.getComponent(cc.Button).clickEvents[0].emit([pokerMasterGameLine1]);
+                    } else {
+                        console.error("未找到扑克大师游戏游戏节点1");
                     }
-                },6000);
+                },5000);
             ''')
 
 
+def ShowOddsNotify(data):
+    option_odds = data["option_odds"]
+    for optionInfo in option_odds:
+        option_ = optionInfo["option"]
+        odds_ = optionInfo["odds"] / 100
+        limit_red_ = optionInfo["limitRed"]
+        # 打印信息
+        print(f"选项: {option_}, 赔率: {odds_}, 限红: {limit_red_}, 总下注: {0}")
+        round_option_info[option_] = BetOption(option_, odds_, limit_red_, 0)
+
+
 async def gameDataSynNotify(data):
     # print(f"同步游戏数据: {data}")
+    sync_user = User(1, DATA_SYN_NOTIFY_UID, 0)
     for optionInfo in data["optionInfo"]:
         option_ = optionInfo["option"]
-
-        if option_ == 103:
-            odds_ = 1
-        else:
-            odds_ = optionInfo["odds"]
+        odds_ = optionInfo["odds"] / 100
 
         limit_red_ = optionInfo["limitRed"]
         total_bet_ = optionInfo["totalBet"]
+        sync_user.betAmount += total_bet_
+        # 打印信息
+        print(f"同步下注选项: {option_}, 赔率: {odds_}, 限红: {limit_red_}, 总下注: {total_bet_}")
         round_option_info[option_] = BetOption(option_, odds_, limit_red_, total_bet_)
-    print(f"同步后下注信息:", round_option_info)
+        # 虚拟用户,用来记录同步下来的下注数据,后续用于赔付
+        sync_user.betOptionAmounts[option_] = total_bet_
+        round_user_betinfo[DATA_SYN_NOTIFY_UID] = sync_user
+
+    # 同步的数据应该包含了所有的下注选项,所以这里直接清空,但是这样统计个人数据的时候,就会有点出入
+    round_user_betinfo.clear()
+    print(f"同步后下注信息:", list(map(lambda x: str(x), round_option_info.values())))
+
+
+async def MergeAutoBetNotify(data):
+    print("收到合并通知")
+    bet_notifys = data["notify"]
+    for bet_notify in bet_notifys:
+        await betNotify(bet_notify)
 
 
 async def betNotify(data):

+ 1 - 0
yyyy_js/python-server/pokermaster/WebServer.py

@@ -24,6 +24,7 @@ async def echo(websocket, path):
             #     time = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
             #     f.write(f"{time}:{message}\n")
             await deal_message(message, broadcast)
+            # print(f"Received message: {message}")
         await websocket.send("Server says: 你好,服务端收到,连接建立成功")
     except websockets.ConnectionClosed as e:
         logging.warning(f"Connection closed: {e.reason}")

+ 122 - 81
yyyy_js/python-server/script.js

@@ -1,91 +1,132 @@
 CMD:
 console.log("====>>>>远程脚本加载成功");
-//var cScene = cc.director.getScene();
-//let scene = cc.director.getScene();
-//let layersCount = scene.childrenCount;
-//console.log("图层数量:", layersCount);
-//
-//function getTotalComponentsCount(node) {
-//    let count = node.getComponents(cc.Component).length;
-//    node.children.forEach(childNode => {
-//        count += getTotalComponentsCount(childNode);
-//    });
-//    return count;
-//}
-//
-//// 使用当前场景的根节点作为起点
-//let totalComponents = getTotalComponentsCount(scene);
-//console.log("场景中的组件总数量:", totalComponents);
-
-//function printNodePath(node, path = '') {
-//    // 构建当前节点的路径
-//    let currentPath = path ? `${path}/${node.name}` : node.name;
-//    console.log(currentPath); // 打印当前节点的路径
-//    lws.send(currentPath);
-//    // 遍历子节点
-//    node.children.forEach((child) => {
-//        printNodePath(child, currentPath);
-//    });
-//}
-//
-// 获取当前场景的根节点并开始遍历
-//let scene = cc.director.getScene();
-//scene.children.forEach((child) => {
-//    // 假设每个直接子节点都是一个“图层”
-//    printNodePath(child);
-//});
-//
-//function printNodePath(node, path = '') {
-//    // 构建当前节点的路径
-//    let currentPath = path ? `${path}/${node.name}` : node.name;
-//
-//    // 检查节点是否有 cc.Button 组件,这意味着它监听了点击事件
-//    let buttonComponent = node.getComponent(cc.Button);
-//
-//    // 可以根据需要,检查其他组件,如 cc.ScrollView 等
-//
-//    if (buttonComponent) {
-//        console.log(currentPath); // 打印当前节点的路径
-//        lws.send(currentPath);
-//    }
-//
-//    // 遍历子节点
-//    node.children.forEach((child) => {
-//        printNodePath(child, currentPath);
-//    });
-//}
-
-
-//// 获取当前场景的根节点并开始遍历
-//let scene = cc.director.getScene();
-//scene.children.forEach((child) => {
-//    printNodePath(child);
-//});
-
-// 点击扑克大师游戏
-let pokerMasterGame = cc.find("Canvas/container/content/smallGame/createScrollView/view/cotent/row1/pokerNode/porkermaster/allHand");//进入大师线路列表
-//let pokerMasterGame = cc.find("Canvas/container/content/smallGame/New Node/listPokerMasterContent/btn_down");//大师线路列表按钮下降
-
-// 检查节点是否找到以及是否有cc.Button组件
-if (pokerMasterGame && pokerMasterGame.getComponent(cc.Button)) {
-    // 模拟点击事件
-    pokerMasterGame.getComponent(cc.Button).clickEvents[0].emit([pokerMasterGame]);
-} else {
-//    console.error("节点未找到或节点上没有cc.Button组件");
-    console.error("未找到扑克大师游戏");
+
+function printNodesCount() {
+    var cScene = cc.director.getScene();
+    let scene = cc.director.getScene();
+    let layersCount = scene.childrenCount;
+    console.log("图层数量:", layersCount);
+
+    function getTotalComponentsCount(node) {
+        let count = node.getComponents(cc.Component).length;
+        node.children.forEach(childNode => {
+            count += getTotalComponentsCount(childNode);
+        });
+        return count;
+    }
+
+    // 使用当前场景的根节点作为起点
+    let totalComponents = getTotalComponentsCount(scene);
+    console.log("场景中的组件总数量:", totalComponents);
 }
 
-// 点击扑克大师游戏线路1
-let pokerMasterGameLine1 = cc.find("Canvas/container/content/smallGame/New Node/listPokerMasterContent/main/view/content/item/main");//线路1
-if (pokerMasterGameLine1 && pokerMasterGameLine1.getComponent(cc.Button)) {
-    // 模拟点击事件
-    pokerMasterGameLine1.getComponent(cc.Button).clickEvents[0].emit([pokerMasterGameLine1]);
-} else {
-//    console.error("节点未找到或节点上没有cc.Button组件");
-    console.error("未找到扑克大师游戏游戏节点1");
+function printAllNodes() {
+    function printNodePath(node, path = '') {
+        // 构建当前节点的路径
+        let currentPath = path ? `${path}/${node.name}` : node.name;
+        console.log(currentPath); // 打印当前节点的路径
+        lws.send(currentPath);
+        // 遍历子节点
+        node.children.forEach((child) => {
+            printNodePath(child, currentPath);
+        });
+    }
+
+    // 获取当前场景的根节点并开始遍历
+    let scene = cc.director.getScene();
+    scene.children.forEach((child) => {
+        // 假设每个直接子节点都是一个“图层”
+        printNodePath(child);
+    });
 }
 
+function printClickAbleNodes() {
+
+    function printNodePath(node, path = '') {
+        // 构建当前节点的路径
+        let currentPath = path ? `${path}/${node.name}` : node.name;
+
+        // 检查节点是否有 cc.Button 组件,这意味着它监听了点击事件
+        let buttonComponent = node.getComponent(cc.Button);
+
+        // 可以根据需要,检查其他组件,如 cc.ScrollView 等
+
+        if (buttonComponent) {
+            console.log(currentPath); // 打印当前节点的路径
+            lws.send(currentPath);
+        }
+
+        // 遍历子节点
+        node.children.forEach((child) => {
+            printNodePath(child, currentPath);
+        });
+    }
+
+
+    // 获取当前场景的根节点并开始遍历
+    let scene = cc.director.getScene();
+    scene.children.forEach((child) => {
+        printNodePath(child);
+    });
+}
+
+function enterGame() {
+    // 点击扑克大师游戏
+    let pokerMasterGame = cc.find("Canvas/container/content/smallGame/createScrollView/view/cotent/row1/pokerNode/porkermaster/allHand");//进入大师线路列表
+    //let pokerMasterGame = cc.find("Canvas/container/content/smallGame/New Node/listPokerMasterContent/btn_down");//大师线路列表按钮下降
+
+    // 检查节点是否找到以及是否有cc.Button组件
+    if (pokerMasterGame && pokerMasterGame.getComponent(cc.Button)) {
+        // 模拟点击事件
+        pokerMasterGame.getComponent(cc.Button).clickEvents[0].emit([pokerMasterGame]);
+    } else {
+    //    console.error("节点未找到或节点上没有cc.Button组件");
+        console.error("未找到扑克大师游戏");
+    }
+
+    // 点击扑克大师游戏线路1
+    let pokerMasterGameLine1 = cc.find("Canvas/container/content/smallGame/New Node/listPokerMasterContent/main/view/content/item/main");//线路1
+    if (pokerMasterGameLine1 && pokerMasterGameLine1.getComponent(cc.Button)) {
+        // 模拟点击事件
+        pokerMasterGameLine1.getComponent(cc.Button).clickEvents[0].emit([pokerMasterGameLine1]);
+    } else {
+    //    console.error("节点未找到或节点上没有cc.Button组件");
+        console.error("未找到扑克大师游戏游戏节点1");
+    }
+
+}
+
+function showDialogAndClose() {
+
+    // 点击显示退出弹窗
+    let btn_menu = cc.find("PokerMasterScene/btn_menu");//进入大师线路列表
+    //let btn_menu = cc.find("Canvas/container/content/smallGame/New Node/listPokerMasterContent/btn_down");//大师线路列表按钮下降
+
+    // 检查节点是否找到以及是否有cc.Button组件
+    if (btn_menu && btn_menu.getComponent(cc.Button)) {
+        // 模拟点击事件
+        btn_menu.getComponent(cc.Button).clickEvents[0].emit([]);
+    } else {
+    //    console.error("节点未找到或节点上没有cc.Button组件");
+        console.error("未找到显示弹出");
+    }
+
+    // 点击扑克大师游戏线路1
+//    let pokerMasterGameLine1 = cc.find("Canvas/container/content/smallGame/New Node/listPokerMasterContent/main/view/content/item/main");//线路1
+//    if (pokerMasterGameLine1 && pokerMasterGameLine1.getComponent(cc.Button)) {
+//        // 模拟点击事件
+//        pokerMasterGameLine1.getComponent(cc.Button).clickEvents[0].emit([pokerMasterGameLine1]);
+//    } else {
+//    //    console.error("节点未找到或节点上没有cc.Button组件");
+//        console.error("未找到扑克大师游戏游戏节点1");
+//    }
+
+}
 
+//printClickAbleNodes();
+//enterGame();
+//printAllNodes();
+//printNodesCount();
 
 //lws.send("存到本地");