launcher.py 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655
  1. import random
  2. import json
  3. import os
  4. import win32gui
  5. import sys
  6. import logging
  7. import rougetask
  8. import rougesetting
  9. import pygame
  10. import requests
  11. import threading
  12. import concurrent.futures
  13. import tkinter as tk
  14. from datetime import datetime, timedelta
  15. from game import rogue_control
  16. from game.rogue_control import Control
  17. from game.algo import rougeGen
  18. from game.file_loader.fileLoader import load_json, load_png, save_encrypt_single_rouge_file, load_rouge_data
  19. from game.algo import utils as util
  20. from game.algo import rougeGen as RG
  21. from game.const import window as W, color as C, game as G
  22. from game.const import rouge as R
  23. from game.music import music_loader
  24. from game.sound import sound_player
  25. from game.ui.menu.component import PygameButton, PygameButtonBackIMG, Particle
  26. current_folder_path = os.getcwd()
  27. def current_lv(lv):
  28. lv_list = R.lv_list
  29. if lv >= sum(lv_list):
  30. return "--"
  31. for k in range(0, 14):
  32. if sum(lv_list[:k]) <= lv < sum(lv_list[:k + 1]):
  33. return str(sum(lv_list[:k + 1]) - lv)
  34. def check_rouge_ob_data(data):
  35. hero_data_dic = {
  36. "Fox": {"exp": 0, "lv": 1}, "Boboli": {"exp": 0, "lv": 1}, "Naruto_old": {"exp": 0, "lv": 1},
  37. "Asha": {"exp": 0, "lv": 1}, "Maria": {"exp": 0, "lv": 1}, "Surprise": {"exp": 0, "lv": 1}
  38. }
  39. err_cnt = 0
  40. for k, v in hero_data_dic.items():
  41. if k not in data.keys():
  42. data[k] = v
  43. err_cnt += 1
  44. print(f"缺失{k}数据, 正在补充...")
  45. if err_cnt > 0:
  46. save_encrypt_single_rouge_file(data, "rougeOB")
  47. class Menu:
  48. def __init__(self, screen, bg_image_path=None):
  49. self.screen = screen
  50. self.buttons = []
  51. self.particles = [] # 粒子列表
  52. self.current_hero = "Fox"
  53. self.current_difficulty = "Easy"
  54. self.is_random = False # 随机选择角色
  55. if bg_image_path:
  56. img = pygame.image.load(bg_image_path).convert()
  57. self.bg_image = pygame.transform.scale(img, screen.get_size())
  58. else:
  59. self.bg_image = None
  60. self._init_data()
  61. self._create_buttons()
  62. def _init_data(self):
  63. rougeOB_data = {}
  64. rougeOB_achivements = []
  65. with open("config.json", "r", encoding="utf-8") as json_file:
  66. mapsetdata = json.load(json_file)
  67. R.rouge_hero = mapsetdata["your_hero"]
  68. self.current_hero = mapsetdata["your_hero"]
  69. R.difficulty = mapsetdata["rogue_difficulty"]
  70. self.current_difficulty = mapsetdata["rogue_difficulty"]
  71. print(mapsetdata["rogue_difficulty"])
  72. user_documents_folder = os.path.expanduser("~\\Documents") # 获取用户的"文档"文件夹路径
  73. qqtpve_folder = os.path.join(user_documents_folder, "QQTPVE") # 构建QQTPVE文件夹路径
  74. os.makedirs(qqtpve_folder, exist_ok=True) # 确保QQTPVE文件夹存在,如果不存在则创建
  75. rouge_file_path = os.path.join(qqtpve_folder, "rougeOB.rougedata") # 构建文件路径
  76. rouge_achivements_file_path = os.path.join(qqtpve_folder, "rougeOB_achievement.rougedata") # 构建成就文件路径
  77. old_file_path = os.path.join(qqtpve_folder, "rouge.json") # 构建文件路径
  78. old_achivements_file_path = os.path.join(qqtpve_folder, "rouge_achievement.json") # 构建成就文件路径
  79. rouge_task_file_path = os.path.join(qqtpve_folder, "rougeOB_task.rougedata") # 构建任务文件路径
  80. last_game_file_path = os.path.join(qqtpve_folder, "rougeOBLastGame.rougedata") # 构建存档文件路径
  81. other_file_path = os.path.join(qqtpve_folder, "rougeOBOther.rougedata") # 构建其他文件路径
  82. # 杂项第一次打开
  83. if not os.path.exists(other_file_path):
  84. rougeOB_other_data = {"Bomb": [],
  85. "Pet": [],
  86. "Hat": [],
  87. "LastRandom": 0,
  88. "Other": []}
  89. save_encrypt_single_rouge_file(rougeOB_other_data, "rougeOBOther")
  90. # 正常打开
  91. else:
  92. rougeOB_other_data = load_rouge_data(other_file_path)
  93. if 'Cursor_Skin' not in rougeOB_other_data.keys():
  94. rougeOB_other_data['Cursor_Skin'] = "fire_cursor"
  95. R.cursor_skin = "fire_cursor"
  96. save_encrypt_single_rouge_file(rougeOB_other_data, "rougeOBOther")
  97. else:
  98. R.cursor_skin = rougeOB_other_data['Cursor_Skin']
  99. if 'Bomb_Skin' not in rougeOB_other_data.keys():
  100. rougeOB_other_data['Bomb_Skin'] = "bomb1"
  101. R.bomb_skin = "bomb1"
  102. save_encrypt_single_rouge_file(rougeOB_other_data, "rougeOBOther")
  103. else:
  104. R.bomb_skin = rougeOB_other_data['Bomb_Skin']
  105. # 第一次打开
  106. if not os.path.exists(rouge_task_file_path):
  107. rougeOB_task_data = {
  108. "1": {"task": "击杀5只命运维系者", "reward": "800经验", "process": 0, "finish": 5, "last_finish": 1970,
  109. "reward_exp": 800, "hero": "Fox", "rewarded": True},
  110. "2": {"task": "击杀3只渊烬龙王", "reward": "800经验", "process": 0, "finish": 3, "last_finish": 1970,
  111. "reward_exp": 800, "hero": "Fox", "rewarded": True},
  112. "3": {"task": "到达3-1十次", "reward": "800经验", "process": 0, "finish": 10, "last_finish": 1970,
  113. "reward_exp": 800, "hero": "Fox", "rewarded": True},
  114. "4": {"task": "击杀5只因果阅律者", "reward": "800经验", "process": 0, "finish": 5, "last_finish": 1970,
  115. "reward_exp": 800, "hero": "Fox", "rewarded": True},
  116. "5": {"task": "完成20次挑衅敌人", "reward": "800经验", "process": 0, "finish": 20, "last_finish": 1970,
  117. "reward_exp": 800, "hero": "Fox", "rewarded": True},
  118. "6": {"task": "使用小倩到达3-5三次", "reward": "800经验", "process": 0, "finish": 3, "last_finish": 1970,
  119. "reward_exp": 800, "hero": "Fox", "rewarded": True},
  120. "7": {"task": "使用波波丽到达3-5三次", "reward": "800经验", "process": 0, "finish": 3, "last_finish": 1970,
  121. "reward_exp": 800, "hero": "Fox", "rewarded": True},
  122. "8": {"task": "使用火影到达3-5三次", "reward": "800经验", "process": 0, "finish": 3, "last_finish": 1970,
  123. "reward_exp": 800, "hero": "Fox", "rewarded": True},
  124. "9": {"task": "使用阿莎到达3-5三次", "reward": "800经验", "process": 0, "finish": 3, "last_finish": 1970,
  125. "reward_exp": 800, "hero": "Fox", "rewarded": True},
  126. "10": {"task": "使用玛莉亚到达3-5三次", "reward": "800经验", "process": 0, "finish": 3, "last_finish": 1970,
  127. "reward_exp": 800, "hero": "Fox", "rewarded": True},
  128. "11": {"task": "到达4-1一次", "reward": "800经验", "process": 0, "finish": 1, "last_finish": 1970,
  129. "reward_exp": 800, "hero": "Fox", "rewarded": True},
  130. "12": {"task": "累积使用20次复活卡", "reward": "800经验", "process": 0, "finish": 20, "last_finish": 1970,
  131. "reward_exp": 800, "hero": "Fox", "rewarded": True},
  132. "today": {"task": "进行一盘游戏并到达2-1", "reward": "50经验", "process": 0, "finish": 1,
  133. "last_finish": "1970-1-1", "reward_exp": 50, "hero": "Fox", "rewarded": True}}
  134. save_encrypt_single_rouge_file(rougeOB_task_data, "rougeOB_task")
  135. # 正常打开
  136. else:
  137. rougeOB_task_data = load_rouge_data(rouge_task_file_path)
  138. now = datetime.now()
  139. # 格式化年月日
  140. year = now.strftime("%Y")
  141. month = now.strftime("%m")
  142. day = now.strftime("%d")
  143. # 移除月份和日期的前导零(如果有)
  144. month = month.lstrip("0")
  145. day = day.lstrip("0")
  146. R.today_datetime["year"] = int(year)
  147. R.today_datetime["month"] = int(month)
  148. R.today_datetime["day"] = int(day)
  149. try:
  150. if len(rougeOB_task_data[str(month)]["last_finish"]) > 4: # 防一手格式错误
  151. rougeOB_task_data[str(month)]["last_finish"] = rougeOB_task_data[str(month)]["last_finish"][0:4]
  152. except:
  153. pass
  154. if int(rougeOB_task_data[str(month)]["last_finish"]) < int(year):
  155. rougeOB_task_data[str(month)]["process"] = 0
  156. rougeOB_task_data[str(month)]["last_finish"] = year
  157. rougeOB_task_data[str(month)]["rewarded"] = False
  158. if rougeOB_task_data["today"]["last_finish"] != year + "-" + month + "-" + day:
  159. rougeOB_task_data["today"]["process"] = 0
  160. rougeOB_task_data["today"]["last_finish"] = year + "-" + month + "-" + day
  161. rougeOB_task_data["today"]["rewarded"] = False
  162. save_encrypt_single_rouge_file(rougeOB_task_data, "rougeOB_task")
  163. # 第一次打开
  164. if not os.path.exists(rouge_file_path):
  165. # 若参与过第一轮beta测试
  166. if os.path.exists(old_file_path):
  167. # 备份旧文件
  168. old_json = load_json(old_file_path)
  169. rougeOB_data = {"Fox": {"exp": old_json["Fox"]["exp"], "lv": old_json["Fox"]["lv"]},
  170. "Boboli": {"exp": old_json["Boboli"]["exp"], "lv": old_json["Boboli"]["exp"]},
  171. "Naruto_old": {"exp": 0, "lv": 1},
  172. "Asha": {"exp": old_json["Naruto_old"]["exp"], "lv": old_json["Naruto_old"]["exp"]},
  173. "Maria": {"exp": 0, "lv": 1},
  174. "Surprise": {"exp": 0, "lv": 1}}
  175. print("等级数据继承成功")
  176. else:
  177. rougeOB_data = {
  178. "Fox": {"exp": 0, "lv": 1},
  179. "Boboli": {"exp": 0, "lv": 1},
  180. "Naruto_old": {"exp": 0, "lv": 1},
  181. "Asha": {"exp": 0, "lv": 1},
  182. "Maria": {"exp": 0, "lv": 1},
  183. "Surprise": {"exp": 0, "lv": 1}
  184. }
  185. save_encrypt_single_rouge_file(rougeOB_data, "rougeOB")
  186. # 正常打开
  187. else:
  188. rougeOB_data = load_rouge_data(rouge_file_path)
  189. # =========================================================================================
  190. util.load_online_config()
  191. if G.UID == "" and G.USERNAME == "":
  192. # username = input("请输入昵称: ").strip()
  193. # password = input("请输入密码: ").strip()
  194. util.register()
  195. new_info = rougeOB_data
  196. new_info["record"] = "null"
  197. result = util.update_profile(G.UID, new_info, G.PASSWORD)
  198. print(result.get('message', '未知错误'))
  199. is_online = util.try_login()
  200. if is_online:
  201. rougeOB_data = util.get_online_data()
  202. # =========================================================================================
  203. check_rouge_ob_data(rougeOB_data)
  204. print(rougeOB_data)
  205. for hero in ["Fox", "Boboli", "Naruto_old", "Asha", "Maria"]:
  206. rougeOB_data[hero]["lv"] = R.current_lv(rougeOB_data[hero]["exp"])
  207. self.Fox_info = "小倩: 等级" + str(rougeOB_data["Fox"]["lv"]) + ", 升级还需经验:" + current_lv(
  208. rougeOB_data["Fox"]["exp"]) + "\n技能: 自身血量减少1则糖泡伤害增加" + str(R.FoxSkill(rougeOB_data["Fox"]["lv"]))
  209. self.Boboli_info = "波波丽: 等级" + str(rougeOB_data["Boboli"]["lv"]) + ", 升级还需经验:" + current_lv(
  210. rougeOB_data["Boboli"]["exp"]) + "\n技能: 每次攻击额外造成" + str(
  211. int(R.BoboliSkill(rougeOB_data["Boboli"]["lv"]) * 100)) + "%真实伤害"
  212. self.Naruto_old_info = "火影: 等级" + str(rougeOB_data["Naruto_old"]["lv"]) + ", 升级还需经验:" + current_lv(
  213. rougeOB_data["Naruto_old"]["exp"]) + "\n技能: 首次攻击每只怪物时攻击力变为" + str(
  214. int(R.Naruto_oldSkill(rougeOB_data["Naruto_old"]["lv"]) * 100)) + "%"
  215. self.Asha_info = "阿莎: 等级" + str(rougeOB_data["Asha"]["lv"]) + ", 升级还需经验:" + current_lv(
  216. rougeOB_data["Asha"]["exp"]) + "\n技能: 每次糖泡造成伤害恢复血量" + str(
  217. R.AshaSkill(rougeOB_data["Asha"]["lv"]) * 100) + "%"
  218. self.Maria_info = "玛莉亚: 等级" + str(rougeOB_data["Maria"]["lv"]) + ", 升级还需经验:" + current_lv(
  219. rougeOB_data["Maria"]["exp"]) + "\n技能: 每次造成伤害降低怪物近身" + str(
  220. R.MariaSkill(rougeOB_data["Maria"]["lv"]) * 100) + "%(最高50%)与" + str(
  221. R.MariaSkill2(rougeOB_data["Maria"]["lv"])) + "防御"
  222. # 第一次打开
  223. if not os.path.exists(rouge_achivements_file_path):
  224. # 若参与过第一轮beta测试
  225. '''
  226. if os.path.exists(old_achivements_file_path):
  227. # 备份旧文件
  228. old_achivements_json = load_json(old_achivements_file_path)
  229. rougeOB_achivements = old_achivements_json
  230. print("成就数据继承成功")
  231. else:
  232. rougeOB_achivements = []
  233. '''
  234. rougeOB_achivements = []
  235. save_encrypt_single_rouge_file(rougeOB_achivements, "rougeOB_achievement")
  236. # 正常打开
  237. else:
  238. rougeOB_achivements = load_rouge_data(rouge_achivements_file_path)
  239. # for ch in rougeOB_achivements:
  240. # print(ch)
  241. max_level = 0
  242. max_level_hero = "Fox"
  243. max_diff = "Easy"
  244. max_diff_num = 1
  245. self.hero_dic = {"Fox": "小倩", "Boboli": "波波丽", "Naruto_old": "火影", "Asha": "阿莎", "Maria": "玛莉亚",
  246. "Surprise": "???"}
  247. self.diff_dic = {"Easy": "简单", "Normal": "困难", "Hell": "炼狱", "Hell+": "炼狱+"}
  248. diff_num = {"Easy": 1, "Normal": 2, "Hell": 3, "Hell+": 4}
  249. diff_status = {"Easy": 0, "Normal": 0, "Hell": 0, "Hell+": 0}
  250. for data in rougeOB_achivements:
  251. if diff_num[data["DIFF"]] > max_diff_num:
  252. max_level = data["CL"]
  253. max_level_hero = data["HERO"]
  254. max_diff = data["DIFF"]
  255. max_diff_num = diff_num[data["DIFF"]]
  256. if diff_num[data["DIFF"]] == max_diff_num:
  257. if data["CL"] > max_level:
  258. max_level = data["CL"]
  259. max_level_hero = data["HERO"]
  260. if data["CL"] == 20:
  261. diff_status[data["DIFF"]] = 2
  262. if max_level > 0:
  263. self.record_text = f"最高挑战纪录: 通关<{self.diff_dic[max_diff]}{(max_level - 1) // 5 + 1}-{(max_level - 1) % 5 + 1}>; 使用英雄: {self.hero_dic[max_level_hero]}"
  264. else:
  265. self.record_text = "暂无挑战记录"
  266. if max_diff == "Hell+":
  267. R.pass_status["Easy"] = 1
  268. R.pass_status["Normal"] = 1
  269. R.pass_status["Hell"] = 1
  270. if max_level >= 15:
  271. R.pass_status["Hell+"] = 1
  272. elif max_diff == "Hell":
  273. R.pass_status["Easy"] = 1
  274. R.pass_status["Normal"] = 1
  275. # R.cursor_skin = "fire_cursor_kubi"
  276. if max_level >= 15:
  277. R.pass_status["Hell"] = 1
  278. # R.cursor_skin = "fire_cursor_gold_kubi"
  279. elif max_diff == "Normal":
  280. R.pass_status["Easy"] = 1
  281. # R.cursor_skin = "fire_cursor2"
  282. if max_level >= 15:
  283. R.pass_status["Normal"] = 1
  284. # R.cursor_skin = "fire_cursor_kubi"
  285. else:
  286. if max_level >= 15:
  287. R.pass_status["Easy"] = 1
  288. # R.cursor_skin = "fire_cursor2"
  289. for dif in ["Easy", "Normal", "Hell", "Hell+"]:
  290. if diff_status[dif] == 2:
  291. R.pass_status[dif] = 2
  292. def _create_buttons(self):
  293. # 主界面按钮
  294. self.buttons.clear()
  295. # "进入游戏"
  296. # self.buttons.append(PygameButton(self.screen, "进入游戏", 0.5, 0.29, 32, "#e1bd48", action=self._start_game, is_bold=True))
  297. self.buttons.append(PygameButtonBackIMG(self.screen, 0.5, 0.3, "res/ui/game/start_button_0.png", "res/ui/game/start_button_1.png", action=self._start_game, anchor='center'))
  298. # "继续游戏"
  299. if os.path.exists(os.path.join(os.path.expanduser("~\\Documents"), "QQTPVE", "rougeOBLastGame.rougedata")):
  300. last = load_rouge_data(os.path.join(os.path.expanduser("~\\Documents"), "QQTPVE", "rougeOBLastGame.rougedata"))
  301. lvl = ((last["current_level"] + 2) // 2 - 1) // 5 + 1
  302. stage = ((last["current_level"] + 2) // 2 - 1) % 5 + 1
  303. text_c = f"继续游戏 (关卡: {lvl}-{stage}) \n (难度: {self.diff_dic[last['difficulty']]}; 英雄: {self.hero_dic[last['rouge_hero']]})"
  304. self.buttons.append(PygameButton(self.screen, text_c, 0.5, 0.44, 18, "#e1bd48", action=lambda: self._continue_game(last), is_bold=True, bg_alpha=191))
  305. # 任务系统
  306. self.buttons.append(PygameButton(self.screen, "任务系统", 0.16, 0.16, 24, "#e1bd48", action=self._open_task, is_bold=True, fix_shape=(120,30), bg_alpha=127))
  307. # 陈列馆
  308. self.buttons.append(PygameButton(self.screen, "陈列馆", 0.16, 0.28, 24, "#e1bd48", action=self._open_setting, is_bold=True, fix_shape=(120,30), bg_alpha=127))
  309. # 难度选择
  310. last_diff = {"Easy": "Easy", "Normal": "Easy", "Hell": "Normal", "Hell+": "Hell"}
  311. for diff, rel in [("Easy", 0.1), ("Normal", 0.18), ("Hell", 0.26), ("Hell+", 0.34)]:
  312. if diff == R.difficulty:
  313. text = f"★ 当前难度: {self.diff_dic[diff]}"
  314. color = "#c7a44f"
  315. self.buttons.append(PygameButton(self.screen, text, 0.75, rel, 13, color, anchor="topleft", is_bold=True, fix_shape=(120,15), bg_alpha=191))
  316. else:
  317. enabled = R.pass_status.get(last_diff[diff], 0) > 0
  318. if diff == "Easy":
  319. text = f"● 选择{self.diff_dic[diff]}难度"
  320. color = "#99be7f"
  321. action = lambda d=diff: self._choose_diff(d)
  322. self.buttons.append(
  323. PygameButton(self.screen, text, 0.75, rel, 13, color, action=action, anchor="topleft", is_bold=True, fix_shape=(120,15), bg_alpha=191))
  324. else:
  325. text = f"● 选择{self.diff_dic[diff]}难度" if enabled else f"○ {self.diff_dic[diff]}难度(未解锁)"
  326. color = "#99be7f" if enabled else "#55516d"
  327. if enabled:
  328. action = lambda d=diff: self._choose_diff(d)
  329. self.buttons.append(PygameButton(self.screen, text, 0.75, rel, 13, color, action=action, anchor="topleft", is_bold=True, fix_shape=(120,15), bg_alpha=191))
  330. else:
  331. self.buttons.append(PygameButton(self.screen, text, 0.75, rel, 13, color, fg_color=(255, 255, 255), anchor="topleft", is_bold=False, fix_shape=(120,15), bg_alpha=63))
  332. # ================================= 英雄选择 =================================
  333. heroes = ["Fox", "Boboli", "Naruto_old", "Asha", "Maria", "Surprise"]
  334. x_position = 0.1
  335. y_positions = [0.64, 0.70, 0.76, 0.82, 0.88, 0.49]
  336. for hero, y in zip(heroes, y_positions):
  337. if not self.is_random and hero == R.rouge_hero:
  338. text = f"★ 使用{self.hero_dic[hero]}"
  339. self.buttons.append(PygameButton(self.screen, text, x_position, y, 12, "#c7a44f", action=lambda h=hero: self._choose_hero(h), anchor="topleft", is_bold=True, fix_shape=(80,15), bg_alpha=191))
  340. else:
  341. text = f"● 选择{self.hero_dic[hero]}"
  342. self.buttons.append(PygameButton(self.screen, text, x_position, y, 12, "#99be7f", action=lambda h=hero: self._choose_hero(h), anchor="topleft", is_bold=True, fix_shape=(80,15), bg_alpha=127))
  343. # 随机开局
  344. if self.is_random:
  345. self.buttons.append(PygameButton(self.screen, "★ 使用随机", x_position, 0.94, 12, "#c7a44f", action=lambda: self._choose_hero("Random"), anchor="topleft", is_bold=True, fix_shape=(80,15), bg_alpha=127))
  346. else:
  347. self.buttons.append(PygameButton(self.screen, "● 随机开局", x_position, 0.94, 12, "#99be7f", action=lambda: self._choose_hero("Random"), anchor="topleft", is_bold=True, fix_shape=(80,15), bg_alpha=127))
  348. # 英雄信息提示
  349. infos = [getattr(self, attr) for attr in ['Fox_info', 'Boboli_info', 'Naruto_old_info', 'Asha_info', 'Maria_info']]
  350. base_heroes = ["Fox", "Boboli", "Naruto_old", "Asha", "Maria"]
  351. if not self.is_random:
  352. for hero, info, y in zip(base_heroes, infos, y_positions):
  353. if hero == R.rouge_hero:
  354. self.buttons.append(PygameButton(self.screen, info, 0.32, y-0.03, 14, "#d7b8da", fg_color=(0, 0, 0), anchor="topleft", bg_alpha=127))
  355. # ==========================================================================
  356. # 最高记录
  357. record = getattr(self, 'record_text', "暂无挑战记录")
  358. self.buttons.append(PygameButton(self.screen, record, 0.5, 0.56, 14, "#7E354D", fg_color=(255, 255, 255), bg_alpha=191))
  359. # 各个按钮动作方法
  360. def _start_game(self):
  361. rougeGen.main_func()
  362. game = Control(
  363. screen=self.screen,
  364. is_continue=False
  365. )
  366. game.update()
  367. def _continue_game(self, last):
  368. self.read_continue_data(last)
  369. game = rogue_control.Control(
  370. screen=self.screen,
  371. is_continue=True
  372. )
  373. game.update()
  374. def _open_task(self):
  375. try:
  376. from rougetask import task
  377. print("启动 Task...")
  378. t = threading.Thread(target=task, daemon=True)
  379. t.start()
  380. except Exception as e:
  381. print("启动 Task 时出错:", e)
  382. # Task(pygame.display.set_mode((800, 600)))
  383. def _open_setting(self):
  384. try:
  385. print("启动 Setting...")
  386. from rougesetting import setting
  387. t = threading.Thread(target=setting, daemon=True)
  388. t.start()
  389. except Exception as e:
  390. print("启动 Setting 时出错:", e)
  391. # Setting(pygame.display.set_mode((800, 600)))
  392. def _choose_diff(self, diff):
  393. R.difficulty = diff
  394. with open("config.json", "r", encoding="utf-8") as json_file:
  395. mapsetdata = json.load(json_file)
  396. mapsetdata["map_set"] = "rogueMapSet"
  397. mapsetdata["rogue_difficulty"] = diff
  398. with open("config.json", "w", encoding="utf-8") as json_file:
  399. json.dump(mapsetdata, json_file, indent=4, ensure_ascii=False)
  400. self._create_buttons()
  401. def _choose_hero(self, hero):
  402. if hero == "Random":
  403. hero = random.choice(["Fox", "Boboli", "Naruto_old", "Asha", "Maria", "Surprise"])
  404. self.is_random = True
  405. else:
  406. self.is_random = False
  407. R.rouge_hero = hero
  408. self.current_hero = hero
  409. with open("config.json", "r", encoding="utf-8") as json_file:
  410. mapsetdata = json.load(json_file)
  411. mapsetdata["map_set"] = "rogueMapSet"
  412. mapsetdata["your_hero"] = hero
  413. with open("config.json", "w", encoding="utf-8") as json_file:
  414. json.dump(mapsetdata, json_file, indent=4, ensure_ascii=False)
  415. self._create_buttons()
  416. def run(self):
  417. clock = pygame.time.Clock()
  418. spawn_timer = 0
  419. while True:
  420. dt = clock.tick(60)
  421. spawn_timer += dt
  422. for event in pygame.event.get():
  423. if event.type == pygame.QUIT:
  424. pygame.quit()
  425. sys.exit()
  426. for btn in self.buttons:
  427. btn.handle_event(event)
  428. if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:
  429. # 看看有没有按钮自己处理了这次点击
  430. if not any(btn.bg_rect.collidepoint(event.pos) for btn in self.buttons):
  431. sound_player.play("uiFail")
  432. # 随机生成新粒子: 每200ms生成一个
  433. if spawn_timer > 200:
  434. spawn_timer = 0
  435. x = random.randint(0, self.screen.get_width())
  436. y = self.screen.get_height() + 10
  437. self.particles.append(Particle(x, y))
  438. # 更新和过滤粒子
  439. new_particles = []
  440. for p in self.particles:
  441. p.update()
  442. if p.is_alive():
  443. new_particles.append(p)
  444. self.particles = new_particles
  445. # 绘制背景
  446. if self.bg_image:
  447. self.screen.blit(self.bg_image, (0, 0))
  448. else:
  449. self.screen.fill((60, 90, 60))
  450. # 绘制粒子
  451. for p in self.particles:
  452. p.draw(self.screen)
  453. # 绘制按钮
  454. for btn in self.buttons:
  455. btn.draw()
  456. pygame.display.flip()
  457. # 读取上次存档
  458. def read_continue_data(self, last_data):
  459. R.continuing_game = True
  460. self.current_hero = last_data["rouge_hero"]
  461. with open("config.json", "r", encoding="utf-8") as json_file:
  462. mapsetdata = json.load(json_file)
  463. mapsetdata["map_set"] = "rogueMapSet"
  464. mapsetdata["your_hero"] = last_data["rouge_hero"]
  465. with open("config.json", "w", encoding="utf-8") as json_file:
  466. json.dump(mapsetdata, json_file, indent=4, ensure_ascii=False)
  467. # ===============================================================================
  468. G.CURRENT_LEVEL = last_data["current_level"]
  469. R.map_json_dic = last_data["map_json_dic"]
  470. R.central_mapset = last_data["central_mapset"]
  471. R.difficulty = last_data["difficulty"]
  472. R.today_datetime = last_data["today_datetime"]
  473. R.task_RougeTreasureDestinyElite = last_data["task_RougeTreasureDestinyElite"]
  474. R.task_MineCFireDragonBoss = last_data["task_MineCFireDragonBoss"]
  475. R.task_RougeTreasureDestinyWizard = last_data["task_RougeTreasureDestinyWizard"]
  476. R.task_combat = last_data["task_combat"]
  477. R.task_revival = last_data["task_revival"]
  478. R.rouge_data = last_data["rouge_data"]
  479. R.rouge_hero = last_data["rouge_hero"]
  480. R.rouge_lv = last_data["rouge_lv"]
  481. R.rouge_exp = last_data["rouge_exp"]
  482. R.game_exp = last_data["game_exp"]
  483. R.rouge_story = last_data["rouge_story"]
  484. R.rouge_theme_1 = last_data["rouge_theme_1"]
  485. R.rouge_theme_2 = last_data["rouge_theme_2"]
  486. R.rouge_theme_3 = last_data["rouge_theme_3"]
  487. R.rouge_theme_4 = last_data["rouge_theme_4"]
  488. R.rouge_destiny = last_data["rouge_destiny"]
  489. R.coin = last_data["coin"]
  490. R.general_mon_dic = last_data["general_mon_dic"]
  491. R.story_eden = last_data["story_eden"]
  492. R.story_destiny = last_data["story_destiny"]
  493. R.current_standard_HP = last_data["current_standard_HP"]
  494. R.current_standard_damage = last_data["current_standard_damage"]
  495. R.current_standard_speed = last_data["current_standard_speed"]
  496. R.current_standard_defense = last_data["current_standard_defense"]
  497. R.current_standard_bomb = last_data["current_standard_bomb"]
  498. R.se_district = last_data["se_district"]
  499. R.battle_district = last_data["battle_district"]
  500. R.monster_defense_delta = last_data["monster_defense_delta"]
  501. R.monster_HP_rate = last_data["monster_HP_rate"]
  502. R.player_bomb_self_damage_reduce_rate = last_data["player_bomb_self_damage_reduce_rate"]
  503. R.slow_immune = last_data["slow_immune"]
  504. R.reverse_immune = last_data["reverse_immune"]
  505. R.root_immune = last_data["root_immune"]
  506. R.stun_immune = last_data["stun_immune"]
  507. R.random_dmg = last_data["random_dmg"]
  508. R.show_cursor = last_data["show_cursor"]
  509. R.last_item = last_data["items"]
  510. if os.path.exists(os.path.join(os.path.expanduser("~\\Documents"), "QQTPVE", "rougeOBLastGame.rougedata")):
  511. os.remove(os.path.join(os.path.expanduser("~\\Documents"), "QQTPVE", "rougeOBLastGame.rougedata"))
  512. print("已读取,清除数据!!!!!!!!!!!!!")
  513. else:
  514. print("???")
  515. def show_prompt():
  516. """显示提示框,询问用户如何操作"""
  517. import tkinter as tk
  518. from tkinter import messagebox
  519. def close_existing():
  520. root.destroy()
  521. sys.exit()
  522. root = tk.Tk()
  523. root.withdraw() # 隐藏主窗口
  524. if messagebox.askyesno("进程已打开", "已有一个游戏进程正在运行。请关闭后再运行!"):
  525. close_existing()
  526. # 获取所有窗口句柄
  527. def get_all_windows():
  528. windows = []
  529. def enum_windows_proc(hwnd, _):
  530. if win32gui.IsWindowVisible(hwnd):
  531. window_text = win32gui.GetWindowText(hwnd)
  532. if window_text:
  533. windows.append(window_text)
  534. return True
  535. win32gui.EnumWindows(enum_windows_proc, None)
  536. return windows
  537. # 检测窗口是否存在
  538. def check_window_exists():
  539. windows = get_all_windows()
  540. # print(windows)
  541. for window in windows:
  542. if "QQTRogue" in window and "永恒" in window and "100の雨女" in window and "756422783" in window and "擅自售卖皆属剽窃" in window:
  543. return True
  544. return False
  545. class Launcher:
  546. def __init__(self):
  547. pygame.init()
  548. self.screen = pygame.display.set_mode(W.WINDOW_SIZE)
  549. pygame.display.set_caption(W.WINDOW_CAPTION)
  550. self.cfg_json = {}
  551. self.music_volume = 0.7
  552. self.display_flags = 0
  553. self.init_config()
  554. self.init_window()
  555. # 预加载资源
  556. # self.preload_resources()
  557. # 启动菜单
  558. music_loader.play("rogue_menu.mp3", self.music_volume)
  559. self.menu = Menu(self.screen, bg_image_path="res/ui/game/rogue_menu.png")
  560. self.menu.run()
  561. def init_config(self):
  562. try:
  563. with open("config.json", encoding="utf-8") as f:
  564. self.cfg_json = json.load(f)
  565. except json.JSONDecodeError:
  566. with open("config.json", encoding="utf-8_sig") as f:
  567. self.cfg_json = json.load(f)
  568. self.music_volume = self.cfg_json["music_volume"]
  569. if not self.cfg_json["frame_screen"]:
  570. self.display_flags = pygame.NOFRAME
  571. if self.cfg_json["full_screen"]:
  572. self.display_flags = pygame.FULLSCREEN | pygame.HWSURFACE | pygame.DOUBLEBUF
  573. try:
  574. if self.cfg_json["v_sync"] and self.cfg_json["frame_screen"] and not self.cfg_json["full_screen"]:
  575. self.display_flags = pygame.HWSURFACE | pygame.DOUBLEBUF
  576. # self.display_flags = pygame.HWSURFACE | pygame.DOUBLEBUF | pygame.OPENGL
  577. elif self.cfg_json["v_sync"] and not self.cfg_json["frame_screen"]:
  578. self.display_flags |= pygame.HWSURFACE | pygame.DOUBLEBUF
  579. elif self.cfg_json["v_sync"] and self.cfg_json["full_screen"]:
  580. self.display_flags = pygame.FULLSCREEN | pygame.HWSURFACE | pygame.DOUBLEBUF
  581. except Exception as e:
  582. print(e)
  583. def init_window(self):
  584. self.screen = pygame.display.set_mode(W.WINDOW_SIZE, flags=self.display_flags)
  585. pygame.display.set_icon(pygame.image.load("res/img/ui/icon.png").convert_alpha())
  586. for i in range(10):
  587. file_name = "itemNum_0_" + str(i) + ".png"
  588. img = pygame.image.load("res/img/ui/number/" + file_name).convert_alpha()
  589. G.NUMBER_IMG.append(img)
  590. def preload_resources(self):
  591. with concurrent.futures.ThreadPoolExecutor() as executor:
  592. executor.submit(Control.preload)
  593. if __name__ == "__main__":
  594. # # 定义日志文件路径
  595. # # log_file_path = os.path.join(os.path.dirname(os.path.abspath(sys.argv[0])), "program.log")
  596. # log_file_path = os.path.join(os.getcwd(), "program.log")
  597. # # 打开日志文件并重定向 stdout
  598. # log_file = open(log_file_path, 'a', encoding='utf-8') # 'a' 是追加模式
  599. # # 重定向 sys.stdout(print 函数输出)
  600. # sys.stdout = log_file
  601. # # 重定向 sys.stderr(报错信息)
  602. # sys.stderr = log_file
  603. print("=========== start ==============")
  604. if check_window_exists():
  605. show_prompt()
  606. Launcher()