From 880bb2a911b8e874512e538bfab42a643b65201b Mon Sep 17 00:00:00 2001 From: Schwarze-Katze <68176965+Schwarze-Katze@users.noreply.github.com> Date: Thu, 9 May 2024 15:36:52 +0800 Subject: [PATCH] Apply StoredCounter for counting farm times (#419) * Apply StoredCounter in counting farm times * i18n for SimulatedUniverseElite counter (probably used for display in future) * change display style to "counter" style * Configure ConfigUpdater.redirect and rename `SimulatedUniverseElite` config item to `SimulatedUniverseFarm` * show `Rogue.RogueWorld.SimulatedUniverseFarm` in disabled mode only when `Rogue.RogueWorld.WeeklyFarming` is checked * treat Rogue_RogueWorld_SimulatedUniverseFarm specially to display value only; i18n for SimulatedUniverseFarm item; bugfix on counter convert * Set display style of stored counter * update counter despite whether farming is enabled --- assets/gui/css/dark-alas.css | 5 +++ assets/gui/css/light-alas.css | 5 +++ config/template.json | 4 +- module/config/argument/args.json | 12 +++--- module/config/argument/argument.yaml | 5 ++- module/config/argument/stored.json | 12 +++--- module/config/config_generated.py | 2 +- module/config/config_updater.py | 3 ++ module/config/convert.py | 7 ++++ module/config/i18n/en-US.json | 8 ++-- module/config/i18n/es-ES.json | 8 ++-- module/config/i18n/ja-JP.json | 8 ++-- module/config/i18n/zh-CN.json | 8 ++-- module/config/i18n/zh-TW.json | 8 ++-- module/config/stored/classes.py | 21 ++-------- module/config/stored/stored_generated.py | 2 +- module/webui/widgets.py | 53 +++++++++++++++++------- tasks/rogue/entry/entry.py | 8 ++-- tasks/rogue/route/base.py | 8 ++-- 19 files changed, 107 insertions(+), 80 deletions(-) diff --git a/assets/gui/css/dark-alas.css b/assets/gui/css/dark-alas.css index 7cdc1e819..fc6962752 100644 --- a/assets/gui/css/dark-alas.css +++ b/assets/gui/css/dark-alas.css @@ -83,6 +83,11 @@ select.state-light { background-color: transparent !important; } +[id^="pywebio-scope-arg_stored-stored-value-"] { + border-bottom: .125rem solid #7a77bb; + background-color: #343a40; +} + textarea { border: 1px solid #21262d; } diff --git a/assets/gui/css/light-alas.css b/assets/gui/css/light-alas.css index ed295b88b..d9de9a2bd 100644 --- a/assets/gui/css/light-alas.css +++ b/assets/gui/css/light-alas.css @@ -84,6 +84,11 @@ select.state-light { background-color: transparent !important; } +[id^="pywebio-scope-arg_stored-stored-value-"] { + border-bottom: .125rem solid #4e4c97; + background-color: #e9ecef; +} + textarea { border: 1px solid lightgrey; } diff --git a/config/template.json b/config/template.json index a177646a8..5c4e3cc7c 100644 --- a/config/template.json +++ b/config/template.json @@ -200,8 +200,8 @@ "UseImmersifier": true, "DoubleEvent": true, "WeeklyFarming": false, - "UseStamina": false, - "SimulatedUniverseElite": {} + "SimulatedUniverseFarm": {}, + "UseStamina": false }, "RogueBlessing": { "PresetBlessingFilter": "preset", diff --git a/module/config/argument/args.json b/module/config/argument/args.json index fdf6bbc68..f72d0ed47 100644 --- a/module/config/argument/args.json +++ b/module/config/argument/args.json @@ -1475,15 +1475,15 @@ "type": "checkbox", "value": false }, + "SimulatedUniverseFarm": { + "type": "stored", + "value": {}, + "display": "disabled", + "stored": "StoredSimulatedUniverseElite" + }, "UseStamina": { "type": "checkbox", "value": false - }, - "SimulatedUniverseElite": { - "type": "stored", - "value": {}, - "display": "hide", - "stored": "StoredSimulatedUniverseElite" } }, "RogueBlessing": { diff --git a/module/config/argument/argument.yaml b/module/config/argument/argument.yaml index 206d023c0..9c9efd878 100644 --- a/module/config/argument/argument.yaml +++ b/module/config/argument/argument.yaml @@ -258,9 +258,10 @@ RogueWorld: UseImmersifier: true DoubleEvent: true WeeklyFarming: false - UseStamina: false - SimulatedUniverseElite: + SimulatedUniverseFarm: stored: StoredSimulatedUniverseElite + display: disabled + UseStamina: false RogueBlessing: PresetBlessingFilter: diff --git a/module/config/argument/stored.json b/module/config/argument/stored.json index 37764ba0c..b9c86336a 100644 --- a/module/config/argument/stored.json +++ b/module/config/argument/stored.json @@ -294,15 +294,15 @@ "order": 0, "color": "#777777" }, - "SimulatedUniverseElite": { - "name": "SimulatedUniverseElite", - "path": "Rogue.RogueWorld.SimulatedUniverseElite", - "i18n": "RogueWorld.SimulatedUniverseElite.name", + "SimulatedUniverseFarm": { + "name": "SimulatedUniverseFarm", + "path": "Rogue.RogueWorld.SimulatedUniverseFarm", + "i18n": "RogueWorld.SimulatedUniverseFarm.name", "stored": "StoredSimulatedUniverseElite", "attrs": { "time": "2020-01-01 00:00:00", - "total": 0, - "value": 100 + "total": 100, + "value": 0 }, "order": 0, "color": "#777777" diff --git a/module/config/config_generated.py b/module/config/config_generated.py index bd2a1f641..49c89f6e8 100644 --- a/module/config/config_generated.py +++ b/module/config/config_generated.py @@ -139,8 +139,8 @@ class GeneratedConfig: RogueWorld_UseImmersifier = True RogueWorld_DoubleEvent = True RogueWorld_WeeklyFarming = False + RogueWorld_SimulatedUniverseFarm = {} RogueWorld_UseStamina = False - RogueWorld_SimulatedUniverseElite = {} # Group `RogueBlessing` RogueBlessing_PresetBlessingFilter = 'preset' # preset, custom diff --git a/module/config/config_updater.py b/module/config/config_updater.py index b0c85c473..38111c606 100644 --- a/module/config/config_updater.py +++ b/module/config/config_updater.py @@ -653,6 +653,7 @@ class ConfigUpdater: ('Dungeon.Dungeon.NameAtDoubleCalyx', 'Dungeon.Dungeon.NameAtDoubleCalyx', convert_20_dungeon), ('Dungeon.DungeonDaily.CalyxGolden', 'Dungeon.DungeonDaily.CalyxGolden', convert_20_dungeon), ('Dungeon.DungeonDaily.CalyxCrimson', 'Dungeon.DungeonDaily.CalyxCrimson', convert_20_dungeon), + ('Rogue.RogueWorld.SimulatedUniverseElite', 'Rogue.RogueWorld.SimulatedUniverseFarm', convert_rogue_farm), ] @cached_property @@ -863,6 +864,8 @@ class ConfigUpdater: yield 'Rogue.RogueBlessing.CustomResonanceFilter' if deep_get(data, 'Rogue.RogueBlessing.PresetCurioFilter') != 'custom': yield 'Rogue.RogueBlessing.CustomCurioFilter' + if deep_get(data, 'Rogue.RogueWorld.WeeklyFarming') != True: + yield 'Rogue.RogueWorld.SimulatedUniverseFarm' def get_hidden_args(self, data) -> t.Set[str]: """ diff --git a/module/config/convert.py b/module/config/convert.py index aadc72df4..799a5ac03 100644 --- a/module/config/convert.py +++ b/module/config/convert.py @@ -30,3 +30,10 @@ def convert_20_dungeon(value): return 'Calyx_Crimson_Abundance_Jarilo_BackwaterPass' return value + + +def convert_rogue_farm(value): + if isinstance(value, dict) and 'value' in value.keys(): + value['value'] = 100 - value['value'] + value['total'] = 100 + return value diff --git a/module/config/i18n/en-US.json b/module/config/i18n/en-US.json index 8097ae3d7..8000fe0d1 100644 --- a/module/config/i18n/en-US.json +++ b/module/config/i18n/en-US.json @@ -976,13 +976,13 @@ "name": "Farm 100 Elites Weekly", "help": "" }, + "SimulatedUniverseFarm": { + "name": "Progress of elite boss farmed", + "help": "" + }, "UseStamina": { "name": "Farm Planers Using Trailblase Power", "help": "Task \"Dungeon\" will no longer run, and all trailblaze power will be used first to claim immersion rewards, except for double events." - }, - "SimulatedUniverseElite": { - "name": "RogueWorld.SimulatedUniverseElite.name", - "help": "RogueWorld.SimulatedUniverseElite.help" } }, "RogueBlessing": { diff --git a/module/config/i18n/es-ES.json b/module/config/i18n/es-ES.json index 4be840c8a..f02621f79 100644 --- a/module/config/i18n/es-ES.json +++ b/module/config/i18n/es-ES.json @@ -976,13 +976,13 @@ "name": "Granja 100 élites semanalmente", "help": "" }, + "SimulatedUniverseFarm": { + "name": "Progreso de élites derrotadas", + "help": "" + }, "UseStamina": { "name": "Reclamar de planers mediante poder trazacaminos", "help": "La tarea de mazmorra ya no se ejecutará y todo el poder trazacaminos se usará primero para reclamar recompensas de inmersión, excepto para eventos dobles" - }, - "SimulatedUniverseElite": { - "name": "RogueWorld.SimulatedUniverseElite.name", - "help": "RogueWorld.SimulatedUniverseElite.help" } }, "RogueBlessing": { diff --git a/module/config/i18n/ja-JP.json b/module/config/i18n/ja-JP.json index 68d47cc78..ae9002956 100644 --- a/module/config/i18n/ja-JP.json +++ b/module/config/i18n/ja-JP.json @@ -976,13 +976,13 @@ "name": "RogueWorld.WeeklyFarming.name", "help": "RogueWorld.WeeklyFarming.help" }, + "SimulatedUniverseFarm": { + "name": "RogueWorld.SimulatedUniverseFarm.name", + "help": "RogueWorld.SimulatedUniverseFarm.help" + }, "UseStamina": { "name": "RogueWorld.UseStamina.name", "help": "RogueWorld.UseStamina.help" - }, - "SimulatedUniverseElite": { - "name": "RogueWorld.SimulatedUniverseElite.name", - "help": "RogueWorld.SimulatedUniverseElite.help" } }, "RogueBlessing": { diff --git a/module/config/i18n/zh-CN.json b/module/config/i18n/zh-CN.json index 46ec76f7a..63eaccea1 100644 --- a/module/config/i18n/zh-CN.json +++ b/module/config/i18n/zh-CN.json @@ -976,13 +976,13 @@ "name": "每周刷100精英怪", "help": "" }, + "SimulatedUniverseFarm": { + "name": "刷精英怪进度", + "help": "" + }, "UseStamina": { "name": "使用开拓力刷内圈遗器", "help": "每日副本任务将不再打本,所有开拓力将优先被用于领取浸器奖励,双倍活动时除外" - }, - "SimulatedUniverseElite": { - "name": "剩余Boss材料掉落次数", - "help": "RogueWorld.SimulatedUniverseElite.help" } }, "RogueBlessing": { diff --git a/module/config/i18n/zh-TW.json b/module/config/i18n/zh-TW.json index c8522459b..5b781c922 100644 --- a/module/config/i18n/zh-TW.json +++ b/module/config/i18n/zh-TW.json @@ -976,13 +976,13 @@ "name": "每週農100精英怪", "help": "" }, + "SimulatedUniverseFarm": { + "name": "農精英怪進度", + "help": "" + }, "UseStamina": { "name": "用開拓力農遺器", "help": "每日副本任務將不再打本,所有開拓力將優先被用於領取浸器獎勵,雙倍活動時除外" - }, - "SimulatedUniverseElite": { - "name": "RogueWorld.SimulatedUniverseElite.name", - "help": "RogueWorld.SimulatedUniverseElite.help" } }, "RogueBlessing": { diff --git a/module/config/stored/classes.py b/module/config/stored/classes.py index 83c6ca9ef..e66cb299a 100644 --- a/module/config/stored/classes.py +++ b/module/config/stored/classes.py @@ -211,25 +211,10 @@ class StoredSimulatedUniverse(StoredCounter, StoredExpiredAtMonday0400): class StoredSimulatedUniverseElite(StoredCounter, StoredExpiredAtMonday0400): # These variables are used in Rogue Farming feature. - # Times of boss drop chance per week. In current version of StarRail, this value is 100. - FIXED_DEFAULT = 100 + # FIXED_TOTAL --- Times of boss drop chance per week. In current version of StarRail, this value is 100. + FIXED_TOTAL = 100 - # Times left to farm. Resets to 100 every Monday 04:00, and decreases each time the elite boss is cleared. - value = FIXED_DEFAULT - - def farm_dec(self, delta=1): - self.value -= delta - if self.value < 0: - self.value = 0 - - def farm_reset(self): - self.value = self.FIXED_DEFAULT - - def farm_not_complete(self) -> bool: - return self.value > 0 - - def farm_get_remain(self) -> int: - return self.value + # value --- Times left to farm. Resets to 100 every Monday 04:00, and decreases each time the elite boss is cleared. class StoredAssignment(StoredCounter): diff --git a/module/config/stored/stored_generated.py b/module/config/stored/stored_generated.py index 5a8708305..bcb853b5c 100644 --- a/module/config/stored/stored_generated.py +++ b/module/config/stored/stored_generated.py @@ -51,4 +51,4 @@ class StoredGenerated: Assignment = StoredAssignment("Assignment.Assignment.Assignment") Credit = StoredInt("DataUpdate.ItemStorage.Credit") StallerJade = StoredInt("DataUpdate.ItemStorage.StallerJade") - SimulatedUniverseElite = StoredSimulatedUniverseElite("Rogue.RogueWorld.SimulatedUniverseElite") + SimulatedUniverseFarm = StoredSimulatedUniverseElite("Rogue.RogueWorld.SimulatedUniverseFarm") diff --git a/module/webui/widgets.py b/module/webui/widgets.py index ef729a882..37fbdec9a 100644 --- a/module/webui/widgets.py +++ b/module/webui/widgets.py @@ -325,11 +325,11 @@ def put_arg_input(kwargs: T_Output_Kwargs) -> Output: ) -def product_stored_row(kwargs: T_Output_Kwargs, key, value): +def product_stored_row(kwargs: T_Output_Kwargs, key, value, style = "--input--"): kwargs = copy.copy(kwargs) kwargs["name"] += f'_{key}' kwargs["value"] = value - return put_input(**kwargs).style("--input--") + return put_input(**kwargs).style(style) def put_arg_stored(kwargs: T_Output_Kwargs) -> Output: @@ -338,20 +338,41 @@ def put_arg_stored(kwargs: T_Output_Kwargs) -> Output: values = kwargs.pop("value", {}) time_ = values.pop("time", "") - - rows = [product_stored_row(kwargs, key, value) for key, value in values.items() if value] - if time_: - rows += [product_stored_row(kwargs, "time", time_)] - return put_scope( - f"arg_container-stored-{name}", - [ - get_title_help(kwargs), - put_scope( - f"arg_stored-stored-value-{name}", - rows, - ) - ] - ) + + if "value" in values and "total" in values: + # display as counter style + counter = f'{values["value"]} / {values["total"]}' + rows = [product_stored_row( + kwargs, "counter", counter)] + if time_: + rows += [product_stored_row(kwargs, "time", time_)] + return put_scope( + f"arg_container-stored-{name}", + [ + get_title_help(kwargs), + put_scope( + f"arg_stored-stored-value-{name}", + rows, + ) + ] + ) + else: + # display per key + rows = [product_stored_row(kwargs, key, value) + for key, value in values.items() if value] + if time_: + rows += [product_stored_row(kwargs, "time", time_)] + + return put_scope( + f"arg_container-stored-{name}", + [ + get_title_help(kwargs), + put_scope( + f"arg_stored-stored-value-{name}", + rows, + ) + ] + ) def put_arg_select(kwargs: T_Output_Kwargs) -> Output: diff --git a/tasks/rogue/entry/entry.py b/tasks/rogue/entry/entry.py index 3b4b2a72a..35b647919 100644 --- a/tasks/rogue/entry/entry.py +++ b/tasks/rogue/entry/entry.py @@ -350,9 +350,9 @@ class RogueEntry(RouteBase, RogueRewardHandler, RoguePathHandler, DungeonUI): # Always run return - if self.config.stored.SimulatedUniverseElite.is_expired(): + if self.config.stored.SimulatedUniverseFarm.is_expired(): # Expired, reset farming counter - self.config.stored.SimulatedUniverseElite.farm_reset() + self.config.stored.SimulatedUniverseFarm.set(0) if self.config.stored.SimulatedUniverse.is_expired(): # Expired, do rogue @@ -361,11 +361,11 @@ class RogueEntry(RouteBase, RogueRewardHandler, RoguePathHandler, DungeonUI): if self.config.RogueWorld_UseImmersifier and self.config.stored.Immersifier.value > 0: logger.info( 'Reached weekly point limit but still have immersifiers left, continue to use them') - elif self.config.RogueWorld_WeeklyFarming and self.config.stored.SimulatedUniverseElite.farm_not_complete(): + elif self.config.RogueWorld_WeeklyFarming and not self.config.stored.SimulatedUniverseFarm.is_full(): logger.info( 'Reached weekly point limit but still continue to farm materials') logger.attr( - "Farming Counter", self.config.stored.SimulatedUniverseElite.farm_get_remain()) + "Farming Counter", self.config.stored.SimulatedUniverseFarm.to_counter()) else: raise RogueReachedWeeklyPointLimit else: diff --git a/tasks/rogue/route/base.py b/tasks/rogue/route/base.py index 6137166b3..859c6e7d8 100644 --- a/tasks/rogue/route/base.py +++ b/tasks/rogue/route/base.py @@ -168,11 +168,11 @@ class RouteBase(RouteBase_, RogueExit, RogueEvent, RogueReward): # logger.attr("result",result) if 'enemy' in result: - # runs when one elite battle finishes, and decreases rogue farming count by 1 - if self.config.RogueWorld_WeeklyFarming and self.config.stored.SimulatedUniverseElite.farm_not_complete(): - self.config.stored.SimulatedUniverseElite.farm_dec() + # runs when one elite battle finishes, and increases rogue farming count by 1 + if not self.config.stored.SimulatedUniverseFarm.is_full(): + self.config.stored.SimulatedUniverseFarm.add() logger.info( - f"Cleared elite boss, decreasing farming count by 1, now {self.config.stored.SimulatedUniverseElite.farm_get_remain()}") + f"Cleared elite boss, increasing farming count by 1, now " + self.config.stored.SimulatedUniverseFarm.to_counter()) return result def _domain_event_expected_end(self):