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
+30 -1
View File
@@ -1,5 +1,6 @@
"""The built-in three-difficulty-cleared sweep path from StageStartPanel."""
from dataclasses import dataclass, field
from types import SimpleNamespace
import json
from pathlib import Path
import sqlite3
@@ -7,6 +8,7 @@ import uuid
from .daily import day
from .maps import stages
from .resource_stages import resource_entry_reason
from .drop_statistics import SweepStatistics, event_reward, normalize_reward
from .team_availability import team_availability_reason
@@ -22,6 +24,14 @@ class SweepPolicy:
keep_stamina: int = 0
team: str = "teamA"
allow_challenge: bool = True
allow_special: bool = False
keep_tickets: int = 0
def __post_init__(self):
if type(self.allow_special) is not bool:
raise ValueError("资源关卡开关必须为布尔值")
if type(self.keep_tickets) is not int or self.keep_tickets < 0:
raise ValueError("保留工具数量必须为非负整数")
class SweepRunner:
@@ -51,10 +61,27 @@ class SweepRunner:
cost = (response.get("stageEvent") or {}).get("costTi") if kind == "event" else response.get("costTi")
self.statistics.record(snapshot.raw["master"]["id"], stage.stage_id, stage.level, kind, source,
snapshot.now, reward, cost)
except (OSError, sqlite3.Error, ValueError, TypeError) as error:
except (OSError, sqlite3.Error, ValueError, TypeError, KeyError) as error:
# A local statistics failure must never repeat an awarded request.
self.statistics_error = "奖励统计未写入:" + str(error)
def remember_map_reward(self, snapshot, record, response, *, event=False):
"""Attach an already journaled resource result to existing drop statistics."""
self.last_outcome = "resource_event" if event else "resource"
reward = record.get("reward")
if reward is None:
self.statistics_error = "资源关卡结算缺少奖励,未写入掉落统计"
return
self.statistics_error = ""
try:
self.last_reward = normalize_reward(self.catalog, reward)
source_response = record.get("response") or record.get("start_response") or response or {}
self.statistics.record(snapshot.raw["master"]["id"], record["stage_id"], str(record["difficulty"]), "event" if event else "sweep",
"battle:" + record["attempt_id"], snapshot.now, reward,
(source_response.get("stageEvent") or {}).get("costTi") if event else source_response.get("costTi"))
except (OSError, sqlite3.Error, ValueError, TypeError, KeyError) as error:
self.statistics_error = "奖励统计未写入:" + str(error)
def recover_reward_event(self, snapshot, trace_path):
"""Repair only old reward-event blocks with a role-matched log reply.
@@ -130,6 +157,8 @@ class SweepRunner:
return "扫荡 / 自动挑战已关闭,禁止新的入场"
if self.state.get("pending"):
return "有未完成的扫荡,请先在游戏内检查"
if stage.category in ("mine", "ticket"):
return resource_entry_reason(self.catalog, snapshot, stage, policy) or team_availability_reason(snapshot, policy.team)
if challenge:
config = self.catalog.data.get("stage_info", {}).get(stage.stage_id, {})
if not stage.unlocked or not stage.open: