Add automatic mining and ticket resource stages

This commit is contained in:
AttilaNet
2026-11-10 12:54:48 +08:00
parent 0109cc0d1c
commit 5082c2df5c
20 changed files with 1615 additions and 67 deletions
+28 -7
View File
@@ -15,7 +15,7 @@ No estimation module is imported here. SweepRunner is the sole sweep executor.
from __future__ import annotations
from copy import deepcopy
from dataclasses import asdict, is_dataclass
from dataclasses import asdict, is_dataclass, replace
import hashlib
import json
import math
@@ -24,9 +24,11 @@ from pathlib import Path
import threading
import time
import uuid
from types import SimpleNamespace
from .drop_statistics import event_reward
from .maps import stages
from .resource_stages import resource_entry_reason, item_requirements, available_item_count
from .quests import indexed, stage_has_level
from .sweeping import SweepPolicy
from .team_availability import team_availability_reason
@@ -158,7 +160,7 @@ class BattleJournal:
raise ValueError("有待核对的任务 / 战斗,禁止重复开始")
record = {name: public_data(value(intent, name)) for name in (
"kind", "description", "path", "payload", "task_id", "task_type_id", "step_number",
"position", "stage_id", "difficulty", "battle_kind", "source_task_id", "source_task_type_id", "source_step_number", "farming_target")}
"position", "stage_id", "difficulty", "battle_kind", "stage_category", "source_task_id", "source_task_type_id", "source_step_number", "farming_target")}
record.update(attempt_id=uuid.uuid4().hex, role_id=role_id(snapshot),
phase="prepared", outcome="", timestamp=time.time(), started_at=time.time(), team=value(intent, "team", ""),
message="", kind=kind or record["kind"], battle_mode=value(intent, "battle_mode", "original"),
@@ -313,7 +315,7 @@ class BattleOrchestrator:
"taskStep": max(0, int(value(intent, "step_number", 1) or 1) - 1) if task else 0}
request = {"snapshot": snapshot.raw if self.request_builder else deepcopy(snapshot.raw), "team": policy.team, "battle_position": position,
"battle_mode": value(policy, "battle_mode", "original"),
**{name: value(intent, name) for name in ("stage_id", "difficulty", "task_type_id", "step_number", "battle_kind")}}
**{name: value(intent, name) for name in ("stage_id", "difficulty", "task_type_id", "step_number", "battle_kind", "stage_category")}}
return self.request_builder(snapshot, intent, policy, request) if self.request_builder else request
def resource_reason(self, snapshot, intent, policy, ranch=None):
@@ -350,6 +352,27 @@ class BattleOrchestrator:
if not stage or difficulty not in stage.get("level", {}):
return "关卡配置缺失"
if not value(intent, "task_id"):
if value(intent, "kind") == "map_battle" and value(intent, "stage_category") in ("mine", "ticket"):
if value(intent, "battle_kind") != "resource_stage":
return "资源关卡战斗类型不匹配,禁止入场"
if self.sweeper:
rule = value(policy, "rules", {}).get(stage_id, {})
key = self.sweeper.key(snapshot, SimpleNamespace(stage_id=stage_id, level=difficulty))
if (not rule.get("enabled") or str(rule.get("level")) != difficulty
or int(self.sweeper.state.get("counts", {}).get(key, 0)) >= max(0, int(rule.get("limit") or 0))):
return "资源关卡未显式勾选或已达本日次数上限"
match = next((row for row in stages(self.catalog, snapshot)
if row.stage_id == stage_id and row.level == difficulty), None)
if match is None:
return "资源关卡配置缺失"
reason = resource_entry_reason(self.catalog, snapshot, match, policy)
if reason:
return reason
policy = replace(policy, item_reserves={key: max(int(value(policy, "item_reserves", {}).get(key, 0)),
int(value(policy, "keep_tickets", 0))) for key in item_requirements((stage.get("cost") or {}).get("items", []))}) \
if is_dataclass(policy) else SimpleNamespace(**(vars(policy) | {"item_reserves": {key: max(
int(value(policy, "item_reserves", {}).get(key, 0)), int(value(policy, "keep_tickets", 0)))
for key in item_requirements((stage.get("cost") or {}).get("items", []))}}))
position = value(intent, "position") or f"city{stage.get('city')}_wild_stage{stage_id}_level{difficulty}"
if self.task_at_position(snapshot, position):
return "该位置由当前任务优先处理,不能执行普通挑战或扫荡"
@@ -366,13 +389,11 @@ class BattleOrchestrator:
money = float(base.get("money") or 0)
if money and (money > policy.max_money or float(master.get("money") or 0) - money < max(0, value(ranch, "keep_money", 0))):
return "入场金币超过上限或保留金币不足"
for item in base.get("items") or []:
key, count = str(item["typeId"]), int(item["num"])
for key, count in item_requirements(base.get("items") or []).items():
if count and not policy.allow_items:
return "入场需要消耗道具,未启用"
reserve = max(int(policy.item_reserves.get(key, 0)), int(value(ranch, "reserved_eggs", {}).get(key, 0)))
owned = sum(int(i.get("num") or 0) for i in snapshot.raw.get("items", [])
if str(i.get("typeId")) == key and not i.get("lock") and not i.get("sysLock") and not i.get("feedLock"))
owned = available_item_count(snapshot, key)
reserve = max(reserve, int(value(ranch, "gift_items", {}).get(key, {}).get("reserve", 0)))
if owned - count < reserve:
return "入场道具不足或已达保留数量"