def is_finished(status: Status): global Prequeue if not bool(Prequeue) or status.ball != BallManager.WhiteBall: start = time.perf_counter() ans = try_solve(status, 5) if ans: Prequeue = ans[1] Logger("new plan in {:.2f}s:{}({})".format( time.perf_counter() - start, Prequeue, ans[0].currentQuality), tag="stage_3") return not bool(Prequeue)
def try_solve(status: Status, timeLimit=None): best = None queue = [[status, []]] Logger.hideTag("Math") record = set() start = time.perf_counter() while queue: if timeLimit is not None and time.perf_counter() - start > timeLimit: Logger.showTag("Math") return best tempData = queue.pop(0) allow = allowSkills(tempData[0]) for skills in allow: tempStats = tempData[0] for i, skill in enumerate(skills): tempStats = tempStats.use_skill(SkillManager[skill]) if tempStats.ball != BallManager.WhiteBall: tempStats.ball = BallManager.WhiteBall if tempStats.get_status_string() not in record: record.add(tempStats.get_status_string()) newData = [tempStats, tempData[1] + skills] if tempStats.currentDurability > durReq and ( best is None or tempStats.currentQuality > best[0].currentQuality): for s in newData[1]: if s not in AllowBuffs: best = newData break queue.append(newData) Logger.showTag("Math") return best
def solver(msg): global status, data_queue, start, start_time_stamp, terminate Logger(msg, tag="Solver") data = msg.split(" ", 1) if data[0] == "start": if memFix: fix_crafter(player) status = Status(player, target, BallManager.defaultBall) format_status(status) data_queue = [[None, type(BallManager.defaultBall).__name__]] start = time.perf_counter() start_time_stamp = int(time.time()) return deal_status(status) elif data[0] == "use": if len(data) == 2 and status is not None: data = data[1].rsplit(" ", 1) skill = data[0] if len( data) == 1 or data[1] == "成功" else data[0] + ":fail" if skill in SkillManager: print("use:", skill) data_queue[-1][0] = skill status = status.use_skill(SkillManager[skill]) if not status.is_finish(): sleep(0.5) status.ball = get_ball() if memFix: fix_status(status) data_queue.append([None, type(status.ball).__name__]) format_status(status) return deal_status(status) else: raise Exception("unknown skill %s" % skill) elif data[0] == "end": if data_queue and status is not None: with open(os.path.join(config.BasePath, log_name), "a+") as f: f.write(str(start_time_stamp) + "|") f.write("|".join("{};{}".format(i[0], i[1]) for i in data_queue)) f.write("|{}|{}|{}\n".format(status.currentProgress, status.currentQuality, time.perf_counter() - start)) print("#" * 10 + "end" + "#" * 10) TTS("finsih") status = None terminate = False return ("end") else: print("unknown") return ""
def total_efficiency(skill, buffSum=0): Logger("skill:{}\tbuffSum:{}".format(skill, buffSum), tag=tag) return math.floor(skill * (1 + buffSum)) / 100
def total_push(efficiency, base, ball=1): Logger("efficiency:{}\tbase:{}\tball:{}".format(efficiency, base, ball), tag=tag) temp = math.floor(efficiency * base * ball) Logger("total push:{}".format(temp), tag=tag) return temp
int(config['player']['cp']), ) target = Target(int(config['target']['rlv']), int(config['target']['Durability']), int(config['target']['Progress']), int(config['target']['Quality'])) ''' Status: object store the craft state Status([Crafter], [Target], [the ball state]) ''' status = None memFix = config['MemoryFixStatus']['open'] == 'True' terminator = config['AutoTerminator']['open'] == 'True' log_name = "log.txt" Logger.hideTag("Math") CraftSolver.init(player, target) Logger.showTag("Math") data_queue = [] if memFix: from core.Utils.FFxivCraftMem import fix_status, fix_crafter if terminator: from solver.stages.Terminator import Terminator terminate = False def format_status(status): print("#" * 10 + "r %s" % status.rounds + "#" * 10) print("ball:\t{}".format(status.ball.name)) print("durability:\t{}/{}".format(status.currentDurability, status.target.maxDurability)) print("progress:\t{}/{}".format(status.currentProgress, status.target.maxProgress))
def Terminator(status: Status): Logger("terminate!!!", tag="terminator") if status.currentCp >= SkillManager.getCp('坯料加工', status) * status.ball.cp: return '坯料加工' return '仓促'