app_dongri.py 24 KB

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