Default egg restocking to ten draws and add single-draw opt-in

This commit is contained in:
AttilaNet
2026-11-09 07:44:41 +08:00
parent d7ca68b5f9
commit df0259febf
7 changed files with 79 additions and 16 deletions
+1 -1
View File
@@ -24,7 +24,7 @@
| 培育室 | 显示已开启、未开启、VIP坑位及魔物阶段、剩余时间和成熟资质;孵化与成长到期自动同步。普通坑位可在确认费用后扩建。 |
| 分类背包 | 魔物蛋、可使用物品、消耗品、材料、其他、装备分别展示;支持搜索和排序。每种蛋可配置孵化开关、优先级、孵出后去向、补货下限/目标及市场;物品可配置赠礼开关和保留数量。 |
| 牧场与魔物管理 | 默认平铺全部魔物,可切换为按牧场折叠分组;显示容量、空位、等级与突破上限、资质、参考属性、好感上限及喜欢的物品。支持详情查看、多选锁定/解锁、派遣、指定喂养,以及确认费用后新建牧场。 |
| 自动孵蛋与补货 | 按手动规则完成金币市场买蛋/抽蛋、孵化、成长同步、成熟收取、派遣或喂养;支持优先十连、金币保留和每日购蛋额度。空坑按优先级独立随机1~2秒装填,不受整体刷新间隔影响。 |
| 自动孵蛋与补货 | 按手动规则完成金币市场买蛋/抽蛋、孵化、成长同步、成熟收取、派遣或喂养;默认只十连,可单独开启“允许单抽”,遵守金币保留和每日购蛋额度。空坑按优先级独立随机1~2秒装填,不受整体刷新间隔影响。 |
| 资质保留与经验喂养 | 支持星级、综合资质、四项全S(4S)保护,另可保留资质严格高于牧场同种培养代表的新魔物。经验喂养按目标优先级批量提交素材,遵守当前突破上限与停止等级,保护锁定、在队和委托所需魔物。 |
| 自动赠礼与好感培养 | 在背包选择物品、牧场选择目标后自动赠礼;跳过冷却目标,连续处理其他可送目标,在本地倒计时并到期核对状态。支持喜欢物品筛选、库存保留及当前好感上限。可在本地自动为每种魔物选择唯一培养代表,依次按等级、好感、成长资质比较,完全相同时随机选定并记住。 |
| 每日事务 | 查看并领取每日签到礼包、七日签到、累计奖励、已有VIP日奖和邮件附件;支持手动领取及按勾选项目自动领取。 |
+3 -3
View File
@@ -34,7 +34,7 @@
- 每个页面的表格和空白处可右键“刷新本页”;刷新会同步到期的成长状态,不执行派遣、喂养等消耗类策略。
- 多账号:同一程序内多个独立账号页签,登录后各自自动刷新状态,策略分别开启或关闭;切换页签不停止其他账号。
- 会话保存:成功读取角色后自动加密保存 Token、账号/区服/角色和请求编号,重启后可恢复。
- 自动孵蛋:按手动规则执行,使用顶部统一的“开启 / 停止”开关;支持十连优先、金币保留和每日购蛋额度。
- 自动孵蛋:按手动规则执行,使用顶部统一的“开启 / 停止”开关;默认关闭单抽,只十连,遵守金币保留和每日购蛋额度。
可选随机30秒、60秒、2分钟或5分钟,每轮刷新完成后从0到所选上限重新取间隔;喂养遵守当前突破上限,满级后转到下一喂养目标。
空坑装填单独计时:有可用蛋时随机等待1~2秒装填一个坑位,确认成功后继续下一坑,不受整体刷新间隔影响。
每次装填前重新读取坑位和库存;无可用蛋、坑位已满或关闭策略时暂停。此快速计时不会执行购蛋、派遣或其他操作。
@@ -148,8 +148,8 @@
莉莉托斯市场单次价格为100金币(本地客户端表),买到的蛋随机,不能指定全部为绿色史莱姆。
绿色史莱姆总培育时间10分钟,成熟派遣150金币;这不代表整个随机蛋池都固定净赚50金币。
购蛋默认关闭,需要勾选或应用预设。默认优先十连,保留1000金币、每日额度5000金币。
补货缺口和可用金币均达到10枚时发送 `num=10`;有库存时等待缺口,无蛋且不足十连时可按单抽上限补充。
购蛋默认关闭,需要勾选或应用预设。“允许单抽”默认关闭,旧配置未包含此开关时也默认关闭;保留1000金币、每日额度5000金币。
单抽关闭时,购买数量始终为10的倍数;补货缺口、可用金币或每日额度不足十连就等待,无蛋时也不单抽。请将魔物蛋规则的“补至”至少设为10。开启“允许单抽”后,可按“优先十连”和单抽每批上限配置补货。此开关修改后自动保存,支持策略导入/导出。
十连的赠蛋数量以服务端实际返回为准,“最近抽蛋”显示收到的蛋种类和数量。
只购买已解锁城市的金币市场蛋,不使用氪金、抽蛋券或酒馆抽蛋。
额度按北京时间自然日、账号区服角色分别累计,保存在角色目录的 `purchase_budget.json`;
+2 -2
View File
@@ -2,7 +2,7 @@
import re
def battle_message(message):
def battle_message(message, *, translate_unknown=True):
text = str(message or "")
objective = "Non-elimination win/loss objective is unsupported"
units = "Protected/destroy objective units are unsupported"
@@ -33,6 +33,6 @@ def battle_message(message):
(r"Invalid numeric field: [^;;\n]+", "战斗数据包含无效数值,暂时无法模拟"),
):
text = re.sub(pattern, target, text)
if re.search(r"[a-zA-Z]{2,}", text) and not re.search(r"[\u3400-\u9fff]", text):
if translate_unknown and re.search(r"[a-zA-Z]{2,}", text) and not re.search(r"[\u3400-\u9fff]", text):
return "战斗模拟暂时无法处理当前数据,详细原因已保留在调试记录中"
return text
+11 -4
View File
@@ -543,8 +543,12 @@ class Window(ProgressionPages, ActivityPages, W.QMainWindow):
form = W.QFormLayout()
form.addRow(self.ranch_enabled)
self.buy_eggs = W.QCheckBox("自动从金币市场购蛋 / 抽蛋")
self.buy_ten = W.QCheckBox("优先十连;库存缺口累计到10再补货,无蛋且金币不足时单抽")
self.buy_ten = W.QCheckBox("优先十连(允许单抽时生效)")
self.buy_ten.setChecked(True)
self.allow_single_draw = W.QCheckBox("允许单抽(关闭时只进行十连)")
self.allow_single_draw.setToolTip("默认关闭。关闭时,补货缺口、可用金币或每日额度不足十连就等待,无蛋时也不会自动单抽;请将蛋规则的补货目标至少设为10。")
self.buy_ten.setEnabled(False)
self.allow_single_draw.toggled.connect(self.buy_ten.setEnabled)
self.dispatch = W.QCheckBox("成熟后按策略自动派遣")
self.collect = W.QCheckBox("保留或待喂养的魔物自动收取到牧场")
self.feed = W.QCheckBox("按策略喂养选定目标(受当前突破上限限制)")
@@ -561,7 +565,7 @@ class Window(ProgressionPages, ActivityPages, W.QMainWindow):
self.egg_stock.setParent(self.session_fields)
self.hatch_max_star.setParent(self.session_fields)
for label, widget in (("买蛋", self.buy_eggs), ("新增规则默认市场", self.market),
("购买方式", self.buy_ten), ("单抽时每批上限", self.buy_batch),
("允许单抽", self.allow_single_draw), ("购买偏好", self.buy_ten), ("单抽时每批上限", self.buy_batch),
("至少保留金币", self.keep_money), ("每日购蛋金币额度(0=不购买)", self.daily_buy_money),
("孵蛋", self.fill), ("派遣", self.dispatch),
("收取", self.collect)):
@@ -671,6 +675,7 @@ class Window(ProgressionPages, ActivityPages, W.QMainWindow):
for widget in (self.buy_eggs, self.fill, self.dispatch, self.collect):
widget.setChecked(True)
self.buy_ten.setChecked(True)
self.allow_single_draw.setChecked(False)
self.feed.setChecked(False)
for widget, value in ((self.strategy, "gold"), (self.market, "sc_city1"), (self.egg_order, "shortest"), (self.protect_quality, 3), (self.hatch_max_star, 3)):
widget.setCurrentIndex(widget.findData(value))
@@ -892,7 +897,7 @@ class Window(ProgressionPages, ActivityPages, W.QMainWindow):
message = message.replace(secret, "<隐藏>")
if "策略暂不可用" in message or "页面数据暂不可用" in message:
self.trace.emit("error", "本地策略 / 页面处理", scope="local", message=message)
self.log.appendPlainText(time.strftime("%H:%M:%S ") + battle_message(message))
self.log.appendPlainText(time.strftime("%H:%M:%S ") + battle_message(message, translate_unknown=False))
def remember_log_sizes(self, *args):
if self.show_log.isChecked():
@@ -1492,6 +1497,7 @@ class Window(ProgressionPages, ActivityPages, W.QMainWindow):
collect=self.collect.isChecked(), dispatch=self.dispatch.isChecked(), feed=self.feed.isChecked(), hatch_max_star=self.hatch_max_star.currentData(),
buy=self.buy_eggs.isChecked(), market_id=self.market.currentData(), egg_stock=self.egg_stock.value(), buy_batch=self.buy_batch.value(),
buy_ten=self.buy_ten.isChecked(),
allow_single_draw=self.allow_single_draw.isChecked(),
manual_eggs=True, egg_rules=copy.deepcopy(self.egg_rules),
feed_targets=copy.deepcopy(self.feed_targets),
gift_enabled=self.gift_enabled.isChecked(), gift_targets=copy.deepcopy(self.gift_targets),
@@ -1971,7 +1977,7 @@ class Window(ProgressionPages, ActivityPages, W.QMainWindow):
self.auto_save_timer.timeout.connect(self.persist_settings)
names = ("ranch_enabled", "strategy", "protect_star", "protect_quality", "room",
"coin_exp", "reserved_types", "reserve_eggs", "fill", "egg_order", "min_gold", "min_exp", "buy_eggs",
"buy_ten", "dispatch", "collect", "feed", "market", "egg_stock", "buy_batch", "keep_money", "daily_buy_money",
"buy_ten", "allow_single_draw", "dispatch", "collect", "feed", "market", "egg_stock", "buy_batch", "keep_money", "daily_buy_money",
"hatch_max_star", "gift_enabled", "gift_liked_only", "quest_enabled", "quest_accept", "quest_city", "quest_items",
"quest_monsters", "quest_money", "quest_battles", "quest_reserves", "keep_better_quality", "gift_auto_representative")
for name in names:
@@ -2134,6 +2140,7 @@ class Window(ProgressionPages, ActivityPages, W.QMainWindow):
for widget, checked in ((self.buy_eggs, policy.buy), (self.collect, policy.collect), (self.dispatch, policy.dispatch), (self.feed, policy.feed)):
widget.setChecked(checked)
self.buy_ten.setChecked(policy.buy_ten)
self.allow_single_draw.setChecked(policy.allow_single_draw)
for widget, number in ((self.egg_stock, policy.egg_stock), (self.buy_batch, policy.buy_batch), (self.keep_money, policy.keep_money), (self.daily_buy_money, policy.daily_buy_money)):
widget.setValue(number)
for star, check in self.yield_stars.items():
+7 -4
View File
@@ -291,6 +291,7 @@ class Policy:
egg_stock: int = 12
buy_batch: int = 5
buy_ten: bool = True
allow_single_draw: bool = False
keep_money: int = 1000
daily_buy_money: int = 5000
manual_eggs: bool = False
@@ -472,11 +473,13 @@ class Planner:
money = int(snapshot.raw["master"].get("money", 0))
left = min(max(0, policy.daily_buy_money), daily_left) if daily_left is not None else max(0, policy.daily_buy_money)
affordable = min(int(market.get("max") or 1), max(0, money - policy.keep_money) // price, left // price)
if policy.buy_ten and policy.egg_stock >= 10 and missing >= 10 and affordable >= 10:
if not policy.allow_single_draw:
count = min(missing, max(10, policy.buy_batch), affordable) // 10 * 10
if count < 10:
self.notes.append(f"十连等待:单抽已关闭,补货缺口 {missing};十连需 {price * 10} 可用金币,保留 {policy.keep_money},额度剩余 {left};补货目标至少设为10")
return []
elif policy.buy_ten and missing >= 10 and affordable >= 10:
count = min(missing, max(10, policy.buy_batch), affordable) // 10 * 10
elif policy.buy_ten and policy.egg_stock >= 10 and stock > 0:
self.notes.append(f"十连等待:可孵蛋库存 {stock},补货缺口 {missing};十连需 {price * 10} 可用金币,保留 {policy.keep_money},额度剩余 {left}")
return []
else:
count = min(missing, max(0, policy.buy_batch), affordable)
if count <= 0:
+54 -1
View File
@@ -30,7 +30,7 @@ class AutomationTests(unittest.TestCase):
self.snapshot.raw["items"] = []
self.planner = Planner(self.catalog)
self.policy = Policy(strategy="gold", buy=True, protect_star=4, protect_quality=5,
hatch_max_star=3, egg_stock=3, buy_batch=2, keep_money=1000, daily_buy_money=1000)
hatch_max_star=3, egg_stock=3, buy_batch=2, keep_money=1000, daily_buy_money=1000, allow_single_draw=True)
def test_market_city_price_and_nonpremium_payload(self):
action = self.planner.plan(self.snapshot, self.policy)[0]
@@ -98,6 +98,7 @@ class AutomationTests(unittest.TestCase):
self.assertEqual(plans[0].payload["eggs"][0]["itemId"], 503)
def test_ten_draw_waits_for_stock_gap_and_honors_money_limits(self):
self.policy.allow_single_draw = False
self.policy.egg_stock, self.policy.buy_batch = 12, 5
self.policy.fill = False
self.assertEqual(self.planner.plan(self.snapshot, self.policy)[0].payload["num"], 10)
@@ -108,11 +109,33 @@ class AutomationTests(unittest.TestCase):
self.snapshot.raw["master"]["money"] = 1900
self.assertEqual(self.planner.plan(self.snapshot, self.policy), [])
self.snapshot.raw["items"] = []
self.assertEqual(self.planner.plan(self.snapshot, self.policy), [])
self.policy.allow_single_draw = True
self.assertLess(self.planner.plan(self.snapshot, self.policy)[0].payload["num"], 10)
self.snapshot.raw["master"]["money"] = 12345
self.policy.buy_ten = False
self.assertEqual(self.planner.plan(self.snapshot, self.policy)[0].payload["num"], 5)
def test_single_draw_is_disabled_by_default_even_with_no_eggs(self):
policy = Policy(buy=True, fill=False, egg_stock=12, keep_money=1000, daily_buy_money=5000)
self.assertFalse(policy.allow_single_draw)
self.snapshot.raw["master"]["money"] = 1900
self.assertEqual(self.planner.plan(self.snapshot, policy), [])
self.assertIn("单抽已关闭", ";".join(self.planner.notes))
self.snapshot.raw["master"]["money"] = 2000
self.assertEqual(self.planner.plan(self.snapshot, policy)[0].payload["num"], 10)
self.assertEqual(self.planner.plan(self.snapshot, policy, 999), [])
policy.buy_ten = False
self.assertEqual(self.planner.plan(self.snapshot, policy)[0].payload["num"], 10)
def test_manual_refill_keeps_single_draw_disabled(self):
policy = Policy(buy=True, fill=False, manual_eggs=True, keep_money=1000, daily_buy_money=5000,
egg_rules={"1001010": asdict(EggRule(enabled=True, refill_below=1, refill_target=10, market_id="sc_city1"))})
self.snapshot.raw["master"]["money"] = 1900
self.assertEqual(self.planner.plan(self.snapshot, policy), [])
policy.allow_single_draw = True
self.assertLess(self.planner.plan(self.snapshot, policy)[0].payload["num"], 10)
def test_independent_dispatch_collection_and_feeding_switches(self):
snapshot = demo_snapshot(self.catalog)
policy = Policy(strategy="gold", fill=False, dispatch=False, collect=False)
@@ -314,6 +337,36 @@ class AutomationGuiTests(unittest.TestCase):
return
self.fail("Qt task did not finish")
def test_single_draw_switch_defaults_off_and_autosaves_across_restart(self):
with workspace_temp() as folder:
window = gui.Window(folder)
window.timer.stop()
try:
self.wait(window)
self.assertFalse(window.allow_single_draw.isChecked())
self.assertFalse(window.buy_ten.isEnabled())
window.allow_single_draw.setChecked(True)
self.assertTrue(window.buy_ten.isEnabled())
QTest.qWait(400)
self.wait(window)
saved = json.loads((folder / "settings.json").read_text(encoding="utf-8"))
self.assertTrue(saved["policy"]["allow_single_draw"])
from ranch_assistant.policy_io import portable_config, import_config
exported = portable_config(saved, window.engine.snapshot)
self.assertTrue(import_config(exported, window.engine.snapshot)["policy"]["allow_single_draw"])
finally:
window.close()
restored = gui.Window(folder)
restored.timer.stop()
try:
self.wait(restored)
self.assertTrue(restored.allow_single_draw.isChecked())
restored.allow_single_draw.setChecked(False)
self.assertFalse(restored.read_policy().allow_single_draw)
self.assertFalse(restored.buy_ten.isEnabled())
finally:
restored.close()
def test_strategy_toggle_off_keeps_refreshing_and_settings_restore_with_strategy_off(self):
with workspace_temp() as folder:
window = gui.Window(folder)
@@ -58,7 +58,7 @@ class ManualRuleTests(unittest.TestCase):
self.snapshot.raw["stacks"] = []
self.snapshot.raw["monsters"] = []
self.snapshot.raw["items"] = [{"id": 502, "typeId": 1002010, "num": 100}]
policy = Policy(manual_eggs=True, buy=True, fill=False, buy_ten=False, buy_batch=2,
policy = Policy(manual_eggs=True, buy=True, fill=False, buy_ten=False, allow_single_draw=True, buy_batch=2,
egg_rules={"1001010": self.rule(refill_below=1, refill_target=5, market_id="sc_city1")})
self.assertEqual(self.planner.plan(self.snapshot, policy)[0].payload["num"], 2)
self.snapshot.raw["items"].append({"id": 501, "typeId": 1001010, "num": 2})