|
@@ -24,14 +24,13 @@ class BetOption:
|
|
|
# 用户信息
|
|
|
class User:
|
|
|
# 对应option的下注金额
|
|
|
- betOptionAmounts = {option: 0 for option in OPTIONS}
|
|
|
-
|
|
|
- finance = 0
|
|
|
|
|
|
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):
|
|
@@ -90,9 +89,12 @@ async def gameRoundEndNotify(data):
|
|
|
# 开始结算
|
|
|
# 总收入
|
|
|
current_round_income = 0
|
|
|
+ all_bet_amount = 0
|
|
|
|
|
|
for option in round_option_info.values():
|
|
|
- current_round_income += option.total_bet
|
|
|
+ all_bet_amount += option.total_bet
|
|
|
+ current_round_income = all_bet_amount
|
|
|
+
|
|
|
# 开奖结果
|
|
|
option_results = data["optionResult"]
|
|
|
for open_result in option_results:
|
|
@@ -102,30 +104,33 @@ async def gameRoundEndNotify(data):
|
|
|
# 这个是下注的选项信息
|
|
|
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}¥")
|
|
|
- current_round_income -= final_out
|
|
|
- # 玩家结算
|
|
|
- for user in round_user_betinfo.values():
|
|
|
- if result == 1:
|
|
|
+
|
|
|
+ # 玩家结算
|
|
|
+ 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("庄家盈亏记录.log", "a") as f:
|
|
|
- finalxx = f"庄家金币: {banker_finance / 100}¥ 本轮总收入: {current_round_income / 100}¥"
|
|
|
+ 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("bet_finance.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()
|
|
@@ -177,13 +182,14 @@ def ShowOddsNotify(data):
|
|
|
|
|
|
async def gameDataSynNotify(data):
|
|
|
# print(f"同步游戏数据: {data}")
|
|
|
- sync_user = User(0, DATA_SYN_NOTIFY_UID, 0)
|
|
|
+ sync_user = User(1, DATA_SYN_NOTIFY_UID, 0)
|
|
|
for optionInfo in data["optionInfo"]:
|
|
|
option_ = optionInfo["option"]
|
|
|
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_)
|
|
@@ -191,7 +197,9 @@ async def gameDataSynNotify(data):
|
|
|
sync_user.betOptionAmounts[option_] = total_bet_
|
|
|
round_user_betinfo[DATA_SYN_NOTIFY_UID] = sync_user
|
|
|
|
|
|
- print(f"同步后下注信息:", round_option_info)
|
|
|
+ # 同步的数据应该包含了所有的下注选项,所以这里直接清空,但是这样统计个人数据的时候,就会有点出入
|
|
|
+ round_user_betinfo.clear()
|
|
|
+ print(f"同步后下注信息:", list(map(lambda x: str(x), round_option_info.values())))
|
|
|
|
|
|
|
|
|
async def MergeAutoBetNotify(data):
|