app_dongri.py 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640
  1. # -*- coding: utf-8 -*-
  2. from flask import Flask, render_template,jsonify
  3. from flask_socketio import SocketIO, emit
  4. from scriptBase.comon import *
  5. import pyautogui
  6. import base64
  7. import threading
  8. from dongri_task import *
  9. from collections import deque
  10. import json
  11. from concurrent.futures import ThreadPoolExecutor
  12. from flask_caching import Cache
  13. # 全局线程池,限制最大线程数为1
  14. executor = ThreadPoolExecutor(max_workers=1)
  15. cache = Cache(config={'CACHE_TYPE': 'null'}) # 使用 null 缓存类型
  16. app = Flask(__name__)
  17. cache.init_app(app)
  18. app.config['TEMPLATES_AUTO_RELOAD'] = True
  19. socketio = SocketIO(app, cors_allowed_origins="*", max_http_buffer_size=1e8)
  20. class GlobalState:
  21. event = threading.Event()
  22. g_status_list = []
  23. last_time = 0.0
  24. task_queue = deque()
  25. last_process = ''
  26. isGameBegin = True
  27. isReset = False
  28. g_times = 0
  29. g_cureNum = 500
  30. g_switch = False
  31. g_isRestart = True
  32. last_change_time = time.time()
  33. @app.after_request
  34. def add_no_cache_header(response):
  35. # 添加禁用缓存的响应头
  36. response.headers["Cache-Control"] = "no-cache, no-store, must-revalidate"
  37. response.headers["Pragma"] = "no-cache"
  38. response.headers["Expires"] = "0"
  39. return response
  40. def thread_runTask():
  41. while True:
  42. if GlobalState.event.is_set():
  43. GlobalState.task_queue.clear()
  44. if len(GlobalState.task_queue) != 0:
  45. # 初始时间
  46. current_time = time.time()
  47. task = GlobalState.task_queue[-1]
  48. GlobalState.task_queue.pop()
  49. print(f"{task.name} 开始执行")
  50. GlobalState.last_process = task.name
  51. try:
  52. task.run()
  53. except Exception as e:
  54. print(f"{task.name} 执行失败,错误原因:{e}")
  55. cost_time = int(time.time() - current_time)
  56. send_status(f"{task.name} 执行完成,耗时{cost_time}秒")
  57. print(f"{task.name} 执行完成,耗时{cost_time}秒")
  58. myTimeSleep_small()
  59. else:
  60. myTimeSleep_big()
  61. if GlobalState.isReset:
  62. GlobalState.isReset = False
  63. cfg = read_cfg()
  64. if cfg['switch']:
  65. type = update_rungame_type()
  66. print(f'启动游戏{type}')
  67. restart_game(type)
  68. else:
  69. restart_game(0)
  70. @app.route('/')
  71. def index():
  72. return render_template('index_dongri.html')
  73. @socketio.on('connect')
  74. def handle_connect():
  75. print('Client connected')
  76. @socketio.on('disconnect')
  77. def handle_disconnect():
  78. print('Client disconnected')
  79. def send_hint(msg):#数组信息
  80. emit('processing_hint', msg)
  81. def send_todo():
  82. emit('processing_todo', get_todo_msgList())
  83. def send_status(msg):#软件执行状态
  84. try:
  85. if not msg == "":
  86. # 添加新的状态消息和时间到列表
  87. timestamp = datetime.now().strftime('%H:%M:%S') # 获取当前时间
  88. status_entry = {'msg': msg, 'time': timestamp} # 存储消息和时间
  89. GlobalState.g_status_list.append(status_entry)
  90. # 如果列表超过 5 条,移除最早的一条
  91. if len(GlobalState.g_status_list) > 5:
  92. GlobalState.g_status_list.pop(0)
  93. else:
  94. sendStr = ''
  95. for item in GlobalState.g_status_list:
  96. sendStr = f"{GlobalState.g_times}次-{item['time']}-{item['msg']}<br>" + sendStr
  97. emit('processing_status', sendStr)
  98. # 如果消息是 "结束",发送所有状态并清空列表
  99. if msg == "结束":
  100. GlobalState.g_status_list = [] # 清空列表
  101. GlobalState.event.clear()
  102. except Exception as e:
  103. print(f"Error in send_status: {e}")
  104. return
  105. @socketio.on('monitor_begin')
  106. def monitor_begin():
  107. current_time = time.time()
  108. elapsed_time = current_time - GlobalState.last_time
  109. if elapsed_time < 0.5:
  110. return
  111. GlobalState.last_time = current_time
  112. regionRet, regionPos = game_region()
  113. screenshot = pyautogui.screenshot(region=regionPos)
  114. #binary_img = binarize_image(screenshot)
  115. compressed_data = compress_image(screenshot)
  116. image_data_base64 = base64.b64encode(compressed_data).decode('utf-8')
  117. socketio.emit('image_data', image_data_base64)
  118. task_arr = []
  119. if not GlobalState.event.is_set():
  120. task_arr.append(GlobalState.last_process)
  121. for item in reversed(GlobalState.task_queue):
  122. task_arr.append(item.name)
  123. latest_tasks = task_arr[:5] # only show the last 5 tasks
  124. send_hint(json.dumps(latest_tasks, ensure_ascii=False))
  125. send_todo()
  126. send_status('')
  127. #print("send img")
  128. @socketio.on('end_script')
  129. def handle_end_script():
  130. GlobalState.event.set()
  131. @socketio.on('end_game')
  132. def handle_end_game():
  133. GlobalState.event.set()
  134. task_close_game()
  135. send_status("结束2")
  136. GlobalState.event.clear()
  137. @socketio.on('get_title')
  138. def handle_get_title():
  139. str = task_getComputerName()
  140. dst = str + ' machine'
  141. emit('processing_title', dst)
  142. @socketio.on('reset_script')
  143. def handle_reset_script():
  144. python = sys.executable
  145. while '--reset' in sys.argv:
  146. # 从 sys.argv 列表中删除 --reset 参数
  147. sys.argv.remove('--reset')
  148. os.execl(python, python, *sys.argv)
  149. @socketio.on('restart_game')
  150. def handle_restart_game():
  151. python = sys.executable
  152. script = os.path.abspath(sys.argv[0]) # 获取当前脚本的绝对路径
  153. # 构建新的参数列表,移除旧的 --reset 并添加新的
  154. new_args = [arg for arg in sys.argv[1:] if arg != '--reset'] # 排除脚本名和旧的 --reset
  155. print(f"当前 Python 解释器: {python}")
  156. print(f"当前脚本路径: {script}")
  157. print(f"重启参数: {[python, script, *new_args, '--reset']}")
  158. try:
  159. # 使用 os.execv 是一种更“彻底”的重启方式,它会替换当前进程
  160. # 但 subprocess.Popen 也可以,前提是旧进程退出
  161. # subprocess.Popen([python, script, *new_args, '--reset'])
  162. os.execv(python, [python, script, *new_args, '--reset'])
  163. except Exception as e:
  164. print(f"重启失败: {e}")
  165. # 如果 os.execv 失败,可以尝试 subprocess.Popen 作为备用
  166. subprocess.Popen([python, script, *new_args, '--reset'])
  167. sys.exit(0) # 终止当前进程
  168. @app.route('/restart_game', methods=['POST'])
  169. def http_restart_game():
  170. print("HTTP 触发 restart_game")
  171. socketio.start_background_task(handle_restart_game)
  172. return jsonify({"status": "success", "message": "已重启"})
  173. @socketio.on('close_game')
  174. def handle_close_game():
  175. task_close_game()
  176. send_status("结束2")
  177. GlobalState.event.clear()
  178. @app.route('/close_game', methods=['POST'])
  179. def http_close_game():
  180. print("HTTP 触发 close_game")
  181. handle_close_game()
  182. socketio.start_background_task(handle_reset_script)
  183. return jsonify({"status": "success", "message": "已关闭"})
  184. @socketio.on('read_cfg')
  185. def handle_read_cfg():
  186. cfg = read_cfg()
  187. emit('processing_cfg', cfg)
  188. def restart_game(type=0):
  189. GlobalState.isGameBegin = False
  190. while True:
  191. task_close_game()
  192. if True == task_start_game(type):
  193. break
  194. else:
  195. send_status("启动失败")
  196. GlobalState.isGameBegin = True
  197. send_status("结束")
  198. config = read_cfg()
  199. print("config", config)
  200. auto_task(config)
  201. def auto_participate():
  202. GlobalState.task_queue.appendleft(task_returnAllLine())
  203. timeout = 40 * 60
  204. start_time = time.time() # 记录开始时间
  205. while not GlobalState.event.is_set():
  206. if len(GlobalState.task_queue) < 4:
  207. GlobalState.task_queue.appendleft(task_useAnnimalSkill(True))
  208. GlobalState.task_queue.appendleft(task_paticipateInTeam(False))
  209. GlobalState.task_queue.appendleft(task_paticipateInTeam())
  210. GlobalState.task_queue.appendleft(task_paticipateInTeam(False))
  211. GlobalState.task_queue.appendleft(task_paticipateInTeam())
  212. myTimeSleep_big()
  213. # 每次循环检查已用时间
  214. current_time = time.time()
  215. elapsed_time = current_time - start_time
  216. if elapsed_time >= timeout:
  217. handle_restart_game()
  218. break
  219. def auto_palace():
  220. timeout = 180 * 60
  221. start_time = time.time() # 记录开始时间
  222. read_cfg()
  223. while not GlobalState.event.is_set():
  224. GlobalState.g_times += 1
  225. if len(GlobalState.task_queue) < 4:
  226. GlobalState.task_queue.appendleft(task_cure(True, GlobalState.g_cureNum * 5))
  227. GlobalState.task_queue.appendleft(task_cure(True, GlobalState.g_cureNum * 3))
  228. GlobalState.task_queue.appendleft(task_fight_enemy())
  229. myTimeSleep_big()
  230. current_time = time.time()
  231. elapsed_time = current_time - start_time
  232. if elapsed_time >= timeout:
  233. handle_restart_game()
  234. def add_auto_task(isMaxCollect, isJina, isSimple = False, isAddStrengh = False, activity = 'None', isAutoParticipate = True, isDailyConfig = False, train_type = 'None', always = False):
  235. collectArr = [int(x) for x in isMaxCollect.split(",")]
  236. print("collectArr", collectArr)
  237. if len(collectArr) == 1:
  238. collectArr = collectArr[0]
  239. while not GlobalState.event.is_set():
  240. if isSimple == False and is_within_n_minutes(get_todo_time("巨熊行动"), 30, 35):
  241. print("in fight bear")
  242. if len(GlobalState.task_queue) < 5:
  243. start_recording()
  244. GlobalState.task_queue.appendleft(task_returnAllLine())
  245. GlobalState.task_queue.appendleft(task_useAnnimalSkill(True))
  246. GlobalState.task_queue.appendleft(task_paticipateInTeam2(not GlobalState.g_switch))
  247. GlobalState.task_queue.appendleft(task_paticipateInTeam2(not GlobalState.g_switch))
  248. GlobalState.task_queue.appendleft(task_paticipateInTeam(not GlobalState.g_switch))
  249. GlobalState.task_queue.appendleft(task_paticipateInTeam(not GlobalState.g_switch))
  250. GlobalState.task_queue.appendleft(task_paticipateInTeam2(not GlobalState.g_switch))
  251. GlobalState.task_queue.appendleft(task_paticipateInTeam2(not GlobalState.g_switch))
  252. GlobalState.task_queue.appendleft(task_paticipateInTeam(not GlobalState.g_switch))
  253. GlobalState.task_queue.appendleft(task_paticipateInTeam(not GlobalState.g_switch))
  254. GlobalState.task_queue.appendleft(task_paticipateInTeam(False))
  255. myTimeSleep_big()
  256. send_status(f'巨熊行动中')
  257. continue
  258. elif isSimple == False and is_within_n_minutes(get_todo_time("巨熊行动"), 60, 0):
  259. # 设置无尽运行和启动的游戏为0
  260. always = True
  261. if GlobalState.g_switch:
  262. update_rungame_type(0)
  263. send_status(f'巨熊行动:在60min内,切换到无尽模式')
  264. stop_recording()
  265. print("add special activity")
  266. # special activity
  267. if activity == 'lianmeng':
  268. GlobalState.task_queue.appendleft(task_activity_lianmeng())
  269. elif activity == 'cure':
  270. GlobalState.task_queue.appendleft(task_cure(True, GlobalState.g_cureNum))
  271. elif activity == 'only_cure':
  272. GlobalState.task_queue.appendleft(task_cure(True, GlobalState.g_cureNum))
  273. GlobalState.task_queue.appendleft(task_cure(True, GlobalState.g_cureNum))
  274. GlobalState.task_queue.appendleft(task_cure(True, GlobalState.g_cureNum))
  275. return
  276. print("add normal activity")
  277. GlobalState.task_queue.appendleft(task_checkActivities())
  278. if GlobalState.g_switch == True:
  279. GlobalState.task_queue.appendleft(task_checkBenifitStatus())
  280. if isSimple == False:
  281. GlobalState.task_queue.appendleft(task_information())
  282. GlobalState.task_queue.appendleft(task_check_Research())
  283. GlobalState.task_queue.appendleft(task_checkStoreRoom())
  284. if not isSimple:
  285. if isJina == 'jina':
  286. GlobalState.task_queue.appendleft(task_fight_jina(isAddStrengh))
  287. elif isJina == 'yongbing':
  288. GlobalState.task_queue.appendleft(task_fight_yongbing(isAddStrengh))
  289. elif isJina == 'monster':
  290. GlobalState.task_queue.appendleft(task_fightMonster(isAddStrengh, False, isSimple))
  291. elif isJina == 'big_monster' or isJina == 'bigMonster_max':
  292. GlobalState.task_queue.appendleft(task_fightMonster(isAddStrengh, True, isSimple))
  293. elif isJina == 'jina_call':
  294. ### 全部聊天记录都是新吉娜
  295. GlobalState.task_queue.appendleft(task_call_jina())
  296. GlobalState.task_queue.appendleft(task_call_jina())
  297. GlobalState.task_queue.appendleft(task_call_jina())
  298. GlobalState.task_queue.appendleft(task_call_jina())
  299. elif isJina == 'jina_onlyFight':
  300. GlobalState.task_queue.appendleft(task_fight_jina_only())
  301. GlobalState.task_queue.appendleft(task_collect(collectArr, isSimple, isAddStrengh))
  302. GlobalState.task_queue.appendleft(task_train(train_type))
  303. if isSimple == False:
  304. if not isAddStrengh: # 如果不是添加体力,则添加一次采集
  305. GlobalState.task_queue.appendleft(task_collect(collectArr, isSimple, isAddStrengh))
  306. if isJina == 'monster' and isAddStrengh:
  307. GlobalState.task_queue.appendleft(task_fightMonster(isAddStrengh, False, isSimple))
  308. else:
  309. GlobalState.task_queue.appendleft(task_collect(collectArr, isSimple, isAddStrengh))
  310. else:
  311. GlobalState.task_queue.appendleft(task_collect(collectArr, isSimple, isAddStrengh))
  312. print("add rare activity")
  313. if GlobalState.g_times % 5 == 1:
  314. if get_rungame_type() == 0:
  315. GlobalState.task_queue.appendleft(check_buildOrResearch())
  316. GlobalState.task_queue.appendleft(task_cure(True, GlobalState.g_cureNum))
  317. GlobalState.task_queue.appendleft(task_information())
  318. GlobalState.task_queue.appendleft(task_checkDonata())
  319. GlobalState.task_queue.appendleft(task_checkMaster())
  320. GlobalState.task_queue.appendleft(task_checkAdventure())
  321. GlobalState.task_queue.appendleft(task_train(train_type))
  322. GlobalState.task_queue.appendleft(task_useAnnimalSkill())
  323. GlobalState.task_queue.appendleft(task_read_mails())
  324. GlobalState.task_queue.appendleft(task_getStrength())
  325. if auto_participate:
  326. GlobalState.task_queue.appendleft(task_checkConfilits())
  327. GlobalState.task_queue.appendleft(task_checkDiamond())
  328. GlobalState.task_queue.appendleft(task_fight_campion())
  329. GlobalState.task_queue.appendleft(task_get_fire_crystal())
  330. GlobalState.task_queue.appendleft(task_checkUnionTreasure())
  331. #GlobalState.task_queue.appendleft(task_checkBenifitStatus())
  332. GlobalState.task_queue.appendleft(task_gotoTree())
  333. GlobalState.task_queue.appendleft(task_checkHelp())
  334. if activity == 'redPackage':
  335. GlobalState.task_queue.appendleft(task_get_redPackage())
  336. if isJina == 'bigMonster_max':
  337. GlobalState.task_queue.appendleft(task_fightMonster(isAddStrengh, True, isSimple))
  338. print("check restart")
  339. GlobalState.g_times += 1
  340. restart_times = 7
  341. if GlobalState.g_switch:
  342. restart_times = 4
  343. if GlobalState.g_times % restart_times == 0 and GlobalState.g_times != 0:
  344. if GlobalState.g_isRestart:
  345. handle_end_game()
  346. if GlobalState.g_switch == False:
  347. if always:
  348. nextTaskTime = random.randint(400, 450)
  349. set_nextTaskTime(nextTaskTime)
  350. myTimeSleep(nextTaskTime, send_status)
  351. else:
  352. nextTaskTime = random.randint(1000, 2000)
  353. set_nextTaskTime(nextTaskTime)
  354. myTimeSleep(nextTaskTime, send_status)
  355. else:
  356. nextTaskTime = random.randint(20, 50)
  357. set_nextTaskTime(nextTaskTime)
  358. myTimeSleep(nextTaskTime, send_status)
  359. if GlobalState.g_isRestart:
  360. handle_restart_game()
  361. else:
  362. nextTaskTime = random.randint(400, 450)
  363. set_nextTaskTime(nextTaskTime)
  364. myTimeSleep(nextTaskTime, send_status)
  365. GlobalState.task_queue.clear()
  366. send_status(f'自动模式结束')
  367. GlobalState.event.clear()
  368. daily_config = {
  369. "login_task": False,
  370. "fight_bigMonster_times": 0
  371. }
  372. def check_daily_config(config):
  373. today = datetime.now().strftime('%Y-%m-%d') # 获取当前日期
  374. print(f"Today: {today}") # 打印当前日期
  375. print(f"Config: {config}") # 打印传入的配置
  376. if "daily" not in config:
  377. print("Daily key not found, creating it.") # 调试信息
  378. config["daily"] = {}
  379. return False
  380. if today not in config["daily"]:
  381. print(f"Today's config not found: {today}") # 调试信息
  382. return False
  383. else:
  384. print(f"Today's config found: {today}") # 调试信息
  385. return True
  386. def update_rungame_type(dstType=None):
  387. config = read_Dailycfg()
  388. runTypeStr = 'runType'
  389. if runTypeStr not in config:
  390. if dstType is not None:
  391. config[runTypeStr] = dstType
  392. else:
  393. config[runTypeStr] = 1
  394. write_Dailycfg(config)
  395. print(f"更新下次启动{config[runTypeStr]}")
  396. return 0
  397. else:
  398. value = config[runTypeStr]
  399. if dstType is not None:
  400. config[runTypeStr] = dstType
  401. else:
  402. config[runTypeStr] = (value + 1) % 2
  403. write_Dailycfg(config)
  404. print(f"更新下次启动{config[runTypeStr]}")
  405. return value
  406. def get_rungame_type():
  407. config = read_Dailycfg()
  408. runTypeStr = 'runType'
  409. if runTypeStr not in config:
  410. return 0
  411. else:
  412. if config[runTypeStr] == 0:
  413. return 1
  414. else:
  415. return 0
  416. # 修改或添加 "login_task" 的值
  417. def set_login_task(config, value):
  418. today = datetime.now().strftime('%Y-%m-%d') # 获取当前日期
  419. if today not in config["daily"]: # 如果当天的配置不存在
  420. config["daily"][today] = {} # 创建当天的配置
  421. config["daily"][today]["login_task"] = value # 设置或更新 "login_task"
  422. return config
  423. # 修改或添加 "fight_bigMonster_times" 的值
  424. def set_fight_big_monster_times(config, value):
  425. today = datetime.now().strftime('%Y-%m-%d') # 获取当前日期
  426. if today not in config["daily"]: # 如果当天的配置不存在
  427. config["daily"][today] = {} # 创建当天的配置
  428. config["daily"][today]["fight_bigMonster_times"] = value # 设置或更新 "fight_bigMonster_times"
  429. return config
  430. def add_today_daily_config(config, daily_config, overwrite=False):
  431. today = datetime.now().strftime('%Y-%m-%d') # 获取当前日期
  432. if today not in config["daily"] or overwrite: # 如果不存在或允许覆盖
  433. config["daily"][today] = daily_config # 添加或更新
  434. return config
  435. # 清理非当天的每日配置
  436. def clean_old_daily_configs(config):
  437. today = datetime.now().strftime('%Y-%m-%d') # 获取当前日期
  438. keys_to_remove = [key for key in config["daily"] if key != today] # 找到非当天的每日配置
  439. for key in keys_to_remove:
  440. del config["daily"][key] # 删除非当天的每日配置
  441. return config
  442. def write_cfg(config):
  443. with open('config.json', 'w') as config_file:
  444. json.dump(config, config_file, indent=4)
  445. def read_cfg():
  446. try:
  447. with open('config.json', 'r') as config_file:
  448. config = json.load(config_file)
  449. GlobalState.g_cureNum = int(config['cureNumber'])
  450. return config
  451. except FileNotFoundError:
  452. print("配置文件不存在,请检查文件路径。")
  453. return None
  454. except PermissionError:
  455. print("没有权限读取配置文件。")
  456. return None
  457. except json.JSONDecodeError:
  458. print("配置文件格式错误,请检查文件内容是否为有效的 JSON。")
  459. return None
  460. def write_Dailycfg(config):
  461. with open('daily.json', 'w') as config_file:
  462. json.dump(config, config_file, indent=4)
  463. def read_Dailycfg():
  464. try:
  465. with open('daily.json', 'r') as config_file:
  466. config = json.load(config_file)
  467. return config
  468. except FileNotFoundError:
  469. print("配置文件不存在,请检查文件路径。")
  470. return None
  471. except PermissionError:
  472. print("没有权限读取配置文件。")
  473. return None
  474. except json.JSONDecodeError:
  475. print("配置文件格式错误,请检查文件内容是否为有效的 JSON。")
  476. return None
  477. @socketio.on('begin_auto')
  478. def handle_auto(data):
  479. write_cfg(data)
  480. config = read_cfg()
  481. print("config", config)
  482. auto_task(config)
  483. def auto_task(data):
  484. if data == None:
  485. isMaxCollect = '4,3,2,1'
  486. isSimple = False
  487. isJina = 'jina'
  488. isAddStrengh = False
  489. activity = 'none'
  490. participateJijie = False
  491. auto_daily = False
  492. train_type = 'none'
  493. always = False
  494. cureNumber = 500
  495. lineCheck = False
  496. switch = False
  497. GlobalState.g_isRestart = True
  498. else:
  499. isMaxCollect = data['maxCollect']
  500. isSimple = data['simple']
  501. isJina = data['jina']
  502. isAddStrengh = data['add_strength']
  503. activity = data['activity']
  504. participateJijie = data['participate_jijie']
  505. auto_daily = False
  506. train_type = data['train']
  507. always = data['always']
  508. cureNumber = int(data['cureNumber'])
  509. lineCheck = data['lineCheck']
  510. switch = data['switch']
  511. GlobalState.g_isRestart = data['is_restart']
  512. GlobalState.g_cureNum = cureNumber
  513. GlobalState.g_switch = switch
  514. set_lineCheck(lineCheck)
  515. send_status(f'开始自动模式')
  516. executor.submit(add_auto_task, isMaxCollect, isJina, isSimple, isAddStrengh, activity, participateJijie, auto_daily, train_type, always)
  517. @socketio.on('begin_auto_participate')
  518. def handle_auto_participate():
  519. send_status(f'开始自动集结模式')
  520. executor.submit(auto_participate)
  521. @socketio.on('begin_testNewFun')
  522. def handle_auto_testNewFun():
  523. send_status(f'开始自动测试新功能')
  524. task_testFun().run()
  525. @socketio.on('auto_palace')
  526. def handle_auto_palace():
  527. send_status(f'开始自动王城')
  528. executor.submit(auto_palace)
  529. def monitor_game_runtime():
  530. last_value = GlobalState.g_times
  531. while True:
  532. current_value = GlobalState.g_times
  533. if current_value != last_value:
  534. last_value = current_value
  535. GlobalState.last_change_time = time.time()
  536. print(f"g_times changed to {current_value}")
  537. # 检查是否超过60分钟没有变化
  538. if time.time() - GlobalState.last_change_time > 3600: # 3600秒=60分钟
  539. print("g_times hasn't changed for 60 minutes!")
  540. handle_restart_game()
  541. time.sleep(10)
  542. if __name__ == '__main__':
  543. init()
  544. if '--reset' in sys.argv:
  545. time.sleep(2)
  546. GlobalState.isReset = True
  547. print("需要重启游戏")
  548. runTask = threading.Thread(target=thread_runTask)#启动线程往里面添加任务
  549. runTask.daemon = True
  550. runTask.start()
  551. monitor_thread = threading.Thread(target=monitor_game_runtime, daemon=True)
  552. monitor_thread.start()
  553. socketio.run(app, host= '0.0.0.0', debug=True, use_reloader=False)#关闭自动重载