diff --git a/arknights_mower/solvers/base_schedule.py b/arknights_mower/solvers/base_schedule.py index fa4be4ea..b55af36f 100644 --- a/arknights_mower/solvers/base_schedule.py +++ b/arknights_mower/solvers/base_schedule.py @@ -485,6 +485,7 @@ def plan_metadata(self): if _idx is not None: __type.append("dorm" + str(_idx)) planned_index.append(_idx) + logger.debug(f"计划干员为{x}") __room = self.op_data.operators[x].room if __room not in __plan.keys(): __plan[__room] = ["Current"] * len(self.op_data.plan[__room]) @@ -851,7 +852,6 @@ def agent_get_mood(self, skip_dorm=False, force=False): for item in _mood_data ] logger.info(f"房间 {self.translate_room(room)} {mood_info}") - # logger.info(f'房间 {room} 心情为:{_mood_data}') break except MowerExit: raise @@ -1466,6 +1466,8 @@ def plan_solver(self): return if self.agent_get_mood() is None: self.backup_plan_solver() + if not self.find_next_task(datetime.now() + timedelta(minutes=5)): + try_add_release_dorm({}, None, self.op_data, self.tasks) def backup_plan_solver(self, timing=None): if timing is None: diff --git a/arknights_mower/utils/operators.py b/arknights_mower/utils/operators.py index 697093f1..3f586ae7 100644 --- a/arknights_mower/utils/operators.py +++ b/arknights_mower/utils/operators.py @@ -366,7 +366,9 @@ def init_mood_limit(self): def evaluate_expression(self, expression): try: - result = Expr(expression, self.eval_model).eval({"op_data": self}) + model = {e: e for e in base_room_list} + model["op_data"] = self + result = Expr(expression, self.eval_model).eval(model) return result except Exception as e: logger.exception(f"Error evaluating expression: {e}") @@ -513,6 +515,7 @@ def correct_dorm(self): ): op.mood = op.upper_limit op.time_stamp = self.dorm[idx].time + op.depletion_rate = 0 logger.debug( f"检测到{op.name}心情恢复满,设置心情至{op.upper_limit}" ) diff --git a/arknights_mower/utils/scheduler_task.py b/arknights_mower/utils/scheduler_task.py index a3b18c07..fd4715a8 100644 --- a/arknights_mower/utils/scheduler_task.py +++ b/arknights_mower/utils/scheduler_task.py @@ -1,4 +1,5 @@ import copy +import heapq from datetime import datetime, timedelta from enum import Enum from typing import Literal @@ -171,12 +172,61 @@ def scheduling(tasks, run_order_delay=5, execution_time=0.75, time_now=None): def try_add_release_dorm(plan, time, op_data, tasks): if not op_data.config.free_room: return + # 有plan 的情况 for k, v in plan.items(): for name in v: if name != "Current": _idx, __dorm = op_data.get_dorm_by_name(name) if __dorm and __dorm.time < time: add_release_dorm(tasks, op_data, name) + # 普通情况 + if not plan: + try: + # 查看是否有未满心情的人 + logger.info("启动不养闲人安排空余宿舍位") + waiting_list = [] + for k, v in op_data.operators.items(): + if ( + not v.is_high() + and v.current_mood() < v.upper_limit + and v.current_room == "" + and v.name not in op_data.free_blacklist + ): + heapq.heappush( + waiting_list, + ( + 1 if k in ["九色鹿", "年"] else 0, + (v.current_mood() - v.lower_limit) + / (v.upper_limit - v.lower_limit), + k, + ), + ) + logger.debug(f"{k}:心情:{v.current_mood()}") + if not waiting_list: + return + logger.debug(f"有{len(waiting_list)}个干员心情未满") + plan = {} + for idx, value in enumerate(op_data.dorm): + if value.name in op_data.operators: + if not waiting_list: + break + agent = op_data.operators[value.name] + logger.info(str(value)) + if not v.is_high() and ( + agent.current_mood() >= agent.upper_limit + or (value.time is not None and value.time < datetime.now()) + ): + rest = heapq.heappop(waiting_list) + if value.position[0] not in plan: + plan[value.position[0]] = ["Current"] * 5 + plan[value.position[0]][value.position[1]] = rest[2] + if plan: + logger.debug(f"不养闲人任务:{plan}") + logger.info("添加不养闲人任务完成") + task = SchedulerTask(task_plan=plan) + tasks.append(task) + except Exception as ex: + logger.exception(ex) def add_release_dorm(tasks, op_data, name):