From 33d150dab5a18dee81b6c3b03a386935b6c86ad4 Mon Sep 17 00:00:00 2001 From: dyceron Date: Sat, 22 Jun 2024 20:36:28 -0400 Subject: [PATCH 1/3] Prevent inventory update if launcher < 0 --- src/open_samus_returns_rando/lua_editor.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/open_samus_returns_rando/lua_editor.py b/src/open_samus_returns_rando/lua_editor.py index cdabf09..c4c7603 100644 --- a/src/open_samus_returns_rando/lua_editor.py +++ b/src/open_samus_returns_rando/lua_editor.py @@ -215,13 +215,15 @@ def _create_custom_init(self, editor: PatcherEditor, configuration: dict) -> str max_life += etanks * energy_per_tank # use _MAX if main is unlocked to unlock the ammo too - # FIXME: These checks are kinda wrong if you use something like `"ITEM_WEAPON_MISSILE_LAUNCHER": 0` - if "ITEM_WEAPON_MISSILE_LAUNCHER" in inventory and "ITEM_MISSILE_TANKS" in inventory: - inventory["ITEM_WEAPON_MISSILE_MAX"] = inventory.pop("ITEM_MISSILE_TANKS") - if "ITEM_WEAPON_SUPER_MISSILE" in inventory and "ITEM_SUPER_MISSILE_TANKS" in inventory: - inventory["ITEM_WEAPON_SUPER_MISSILE_MAX"] = inventory.pop("ITEM_SUPER_MISSILE_TANKS") - if "ITEM_WEAPON_POWER_BOMB" in inventory and "ITEM_POWER_BOMB_TANKS" in inventory: - inventory["ITEM_WEAPON_POWER_BOMB_MAX"] = inventory.pop("ITEM_POWER_BOMB_TANKS") + LAUNCHER_TANK_MAPPING = [ + ("ITEM_WEAPON_MISSILE_LAUNCHER", "ITEM_MISSILE_TANKS"), + ("ITEM_WEAPON_SUPER_MISSILE", "ITEM_SUPER_MISSILE_TANKS"), + ("ITEM_WEAPON_POWER_BOMB", "ITEM_POWER_BOMB_TANKS"), + ] + for launcher, tanks in LAUNCHER_TANK_MAPPING: + ammo_max = "ITEM_WEAPON_" + tanks[5:].replace("TANKS", "MAX") + if max(1, inventory.get(launcher, 0)) and tanks in inventory: + inventory[ammo_max] = inventory.pop(tanks) # These fields are required to start the game final_inventory = { From f44bf47f09b11b4357fdf0a6c5ee6b083137c7a9 Mon Sep 17 00:00:00 2001 From: dyceron Date: Sat, 22 Jun 2024 22:34:06 -0400 Subject: [PATCH 2/3] Actually do the check --- src/open_samus_returns_rando/lua_editor.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/open_samus_returns_rando/lua_editor.py b/src/open_samus_returns_rando/lua_editor.py index c4c7603..01752f9 100644 --- a/src/open_samus_returns_rando/lua_editor.py +++ b/src/open_samus_returns_rando/lua_editor.py @@ -221,8 +221,8 @@ def _create_custom_init(self, editor: PatcherEditor, configuration: dict) -> str ("ITEM_WEAPON_POWER_BOMB", "ITEM_POWER_BOMB_TANKS"), ] for launcher, tanks in LAUNCHER_TANK_MAPPING: - ammo_max = "ITEM_WEAPON_" + tanks[5:].replace("TANKS", "MAX") - if max(1, inventory.get(launcher, 0)) and tanks in inventory: + if inventory.get(launcher) and tanks in inventory: + ammo_max = "ITEM_WEAPON_" + tanks[5:].replace("TANKS", "MAX") inventory[ammo_max] = inventory.pop(tanks) # These fields are required to start the game From 6489bbace807199def67ff1969c432ef3834afb7 Mon Sep 17 00:00:00 2001 From: dyceron Date: Sun, 23 Jun 2024 10:19:28 -0400 Subject: [PATCH 3/3] Only update inventory if lauchers > 0 --- src/open_samus_returns_rando/lua_editor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/open_samus_returns_rando/lua_editor.py b/src/open_samus_returns_rando/lua_editor.py index 01752f9..db4942d 100644 --- a/src/open_samus_returns_rando/lua_editor.py +++ b/src/open_samus_returns_rando/lua_editor.py @@ -221,7 +221,7 @@ def _create_custom_init(self, editor: PatcherEditor, configuration: dict) -> str ("ITEM_WEAPON_POWER_BOMB", "ITEM_POWER_BOMB_TANKS"), ] for launcher, tanks in LAUNCHER_TANK_MAPPING: - if inventory.get(launcher) and tanks in inventory: + if launcher in inventory and inventory[launcher] > 0 and tanks in inventory: ammo_max = "ITEM_WEAPON_" + tanks[5:].replace("TANKS", "MAX") inventory[ammo_max] = inventory.pop(tanks)