From f6ea1422ab06e6c845edb3ffd5908506155d42f8 Mon Sep 17 00:00:00 2001 From: Thanatos Date: Thu, 21 Sep 2023 19:17:20 +0200 Subject: [PATCH 1/5] Give all Items from via Lua --- .../files/randomizer_powerup.lua | 228 +++++++----------- .../files/templates/custom_init.lua | 5 +- .../templates/randomizer_item_template.lua | 11 + .../randomizer_progressive_template.lua | 11 - .../templates/template_powerup_bmsad.json | 10 +- open_samus_returns_rando/lua_editor.py | 47 ++-- open_samus_returns_rando/pickup.py | 55 ++--- 7 files changed, 155 insertions(+), 212 deletions(-) create mode 100644 open_samus_returns_rando/files/templates/randomizer_item_template.lua delete mode 100644 open_samus_returns_rando/files/templates/randomizer_progressive_template.lua diff --git a/open_samus_returns_rando/files/randomizer_powerup.lua b/open_samus_returns_rando/files/randomizer_powerup.lua index 2a8e490..b9562fb 100644 --- a/open_samus_returns_rando/files/randomizer_powerup.lua +++ b/open_samus_returns_rando/files/randomizer_powerup.lua @@ -6,18 +6,24 @@ RandomizerPowerup.tProgressiveModels = {} RandomizerPowerup.Self = nil +function RandomizerPowerup.Dummy() +end + function RandomizerPowerup.SetItemAmount(item_id, quantity) if type(quantity) == "string" then quantity = RandomizerPowerup.GetItemAmount(quantity) end Game.SetItemAmount(Game.GetPlayerName(), item_id, quantity) end + function RandomizerPowerup.GetItemAmount(item_id) return Game.GetItemAmount(Game.GetPlayerName(), item_id) end + function RandomizerPowerup.HasItem(item_id) return RandomizerPowerup.GetItemAmount(item_id) > 0 end + function RandomizerPowerup.IncreaseItemAmount(item_id, quantity, capacity) local target = RandomizerPowerup.GetItemAmount(item_id) + quantity if capacity ~= nil then @@ -30,12 +36,9 @@ function RandomizerPowerup.IncreaseItemAmount(item_id, quantity, capacity) RandomizerPowerup.SetItemAmount(item_id, target) end -function RandomizerPowerup.OnPickedUp(actor, resources) - RandomizerPowerup.Self = actor +function RandomizerPowerup.OnPickedUp(resources) local granted = RandomizerPowerup.HandlePickupResources(resources) - RandomizerPowerup.ChangeSuit() - for _, resource in ipairs(granted) do RandomizerPowerup.IncreaseAmmo(resource) end @@ -106,22 +109,6 @@ function RandomizerPowerup.HandlePickupResources(progression) return {} -- nothing granted after final stage of progression is reached end -function RandomizerPowerup.ChangeSuit() - -- ordered by priority - local suits = { - {item = "ITEM_GRAVITY_SUIT", model = "Gravity"}, - {item = "ITEM_VARIA_SUIT", model = "Varia"}, - } - local model_updater = Game.GetEntity("Samus").MODELUPDATER - for _, suit in ipairs(suits) do - if suit.model == model_updater.sModelAlias then break end - if Game.GetItemAmount(Game.GetPlayerName(), suit.item) > 0 then - Game.GetPlayer():StopEntityLoopWithFade("actors/samus/damage_alarm.wav", 0.6) - model_updater.sModelAlias = suit.model - break - end - end -end function RandomizerPowerup.IncreaseAmmo(resource) if not resource then return end @@ -139,50 +126,53 @@ function RandomizerPowerup.IncreaseAmmo(resource) RandomizerPowerup.IncreaseItemAmount(current_id, resource.quantity, resource.item_id) end --- Main PBs (always) + PB expansions (if required mains are disabled) -function RandomizerPowerup._AddLockedPBS(main_item) - local locked_pbs = RandomizerPowerup.GetItemAmount("ITEM_RANDO_LOCKED_PBS") - local current_max = RandomizerPowerup.GetItemAmount("ITEM_WEAPON_POWER_BOMB_MAX") - local current_current = RandomizerPowerup.GetItemAmount("ITEM_WEAPON_POWER_BOMB_CURRENT") - local new_current = 0 - if main_item then - new_current = current_max + locked_pbs - else - new_current = current_current + locked_pbs - end - RandomizerPowerup.SetItemAmount("ITEM_WEAPON_POWER_BOMB_MAX", current_max + locked_pbs) - RandomizerPowerup.SetItemAmount("ITEM_WEAPON_POWER_BOMB_CURRENT", new_current) - RandomizerPowerup.SetItemAmount("ITEM_RANDO_LOCKED_PBS", 0) - hud.UpdatePlayerInfo(true) +-- TODO: What's the max energy? +MAX_ENERGY= 1099 +function RandomizerPowerup.IncreaseEnergy() + local energy = Init.fEnergyPerTank + local new_max = RandomizerPowerup.GetItemAmount("ITEM_MAX_LIFE") + energy + new_max = math.min(new_max, MAX_ENERGY) + RandomizerPowerup.SetItemAmount("ITEM_MAX_LIFE", new_max) + RandomizerPowerup.SetItemAmount("ITEM_CURRENT_LIFE", new_max) + + local life = Game.GetPlayer().LIFE + life.fMaxLife = new_max + life.fCurrentLife = new_max +end + +-- TODO: What's the max aeion? +MAX_AEION= 2200 +function RandomizerPowerup.IncreaseAeion() + local aeion = Init.fAeionPerTank + local new_max = RandomizerPowerup.GetItemAmount("ITEM_MAX_SPECIAL_ENERGY") + aeion + new_max = math.min(new_max, MAX_AEION) + RandomizerPowerup.SetItemAmount("ITEM_MAX_SPECIAL_ENERGY", new_max) + RandomizerPowerup.SetItemAmount("ITEM_CURREITEM_CURRENT_SPECIAL_ENERGYNT_LIFE", new_max) + + local specialEnergy = Game.GetPlayer().SPECIALENERGY + specialEnergy.fMaxEnergy = new_max + specialEnergy.fEnergy = new_max end RandomizerPowerBomb = {} setmetatable(RandomizerPowerBomb, {__index = RandomizerPowerup}) -function RandomizerPowerBomb.OnPickedUp(actor, progression) - -- non actor case: grant locked pbs - if progression ~= nil then - local locked_pbs = RandomizerPowerup.GetItemAmount("ITEM_RANDO_LOCKED_PBS") - for _, outer in ipairs(progression) do - for _, inner in ipairs(outer) do - if inner.item_id == "ITEM_WEAPON_POWER_BOMB_MAX" then - inner.quantity = inner.quantity + locked_pbs - end +function RandomizerPowerBomb.OnPickedUp(progression) + local locked_pbs = RandomizerPowerup.GetItemAmount("ITEM_RANDO_LOCKED_PBS") + for _, outer in ipairs(progression) do + for _, inner in ipairs(outer) do + if inner.item_id == "ITEM_WEAPON_POWER_BOMB_MAX" then + inner.quantity = inner.quantity + locked_pbs end end - RandomizerPowerup.OnPickedUp(actor, progression) - RandomizerPowerup.SetItemAmount("ITEM_RANDO_LOCKED_PBS", 0) - -- actor case: increase ammo by locked pbs after game handled the pickup - else - RandomizerPowerup.OnPickedUp(actor, progression) - Game.AddSF(0.0, "RandomizerPowerup._AddLockedPBS", "b", true) end - + RandomizerPowerup.OnPickedUp(progression) + RandomizerPowerup.SetItemAmount("ITEM_RANDO_LOCKED_PBS", 0) end RandomizerPowerBombTank = {} setmetatable(RandomizerPowerBombTank, {__index = RandomizerPowerup}) -function RandomizerPowerBombTank.OnPickedUp(actor, progression) +function RandomizerPowerBombTank.OnPickedUp(progression) -- use locked supers or super missile max if > 0, which means we have main item local new_item_id = "ITEM_RANDO_LOCKED_PBS" local is_main_unlocked = RandomizerPowerup.GetItemAmount("ITEM_WEAPON_POWER_BOMB_MAX") > 0 @@ -190,141 +180,107 @@ function RandomizerPowerBombTank.OnPickedUp(actor, progression) new_item_id = "ITEM_WEAPON_POWER_BOMB_MAX" end - -- non actor case => change to correct item - if progression ~= nil then - -- grant locked supers or new tank - for _, outer in ipairs(progression) do - for _, inner in ipairs(outer) do - inner.item_id = new_item_id - end - end - RandomizerPowerup.OnPickedUp(actor, progression) - else - if is_main_unlocked then - RandomizerPowerup.OnPickedUp(actor, progression) - Game.AddSF(0.0, "RandomizerPowerup._AddLockedPBS", "") + -- grant locked supers or new tank + for _, outer in ipairs(progression) do + for _, inner in ipairs(outer) do + inner.item_id = new_item_id end end -end - --- Supers Main + Tanks -function RandomizerPowerup._AddLockedSupers(main_item) - local locked_supers = RandomizerPowerup.GetItemAmount("ITEM_RANDO_LOCKED_SUPERS") - local current_max = RandomizerPowerup.GetItemAmount("ITEM_WEAPON_SUPER_MISSILE_MAX") - local current_current = RandomizerPowerup.GetItemAmount("ITEM_WEAPON_SUPER_MISSILE_CURRENT") - local new_current = 0 - if main_item then - new_current = current_max + locked_supers - else - new_current = current_current + locked_supers - end - RandomizerPowerup.SetItemAmount("ITEM_WEAPON_SUPER_MISSILE_MAX", current_max + locked_supers) - RandomizerPowerup.SetItemAmount("ITEM_WEAPON_SUPER_MISSILE_CURRENT", new_current) - RandomizerPowerup.SetItemAmount("ITEM_RANDO_LOCKED_SUPERS", 0) - hud.UpdatePlayerInfo(true) + RandomizerPowerup.OnPickedUp(progression) end RandomizerSuperMissile = {} setmetatable(RandomizerSuperMissile, {__index = RandomizerPowerup}) -function RandomizerSuperMissile.OnPickedUp(actor, progression) - -- non actor case: grant locked supers - if progression ~= nil then - local locked_supers = RandomizerPowerup.GetItemAmount("ITEM_RANDO_LOCKED_SUPERS") - for _, outer in ipairs(progression) do - for _, inner in ipairs(outer) do - if inner.item_id == "ITEM_WEAPON_SUPER_MISSILE_MAX" then - inner.quantity = inner.quantity + locked_supers - end +function RandomizerSuperMissile.OnPickedUp(progression) + local locked_supers = RandomizerPowerup.GetItemAmount("ITEM_RANDO_LOCKED_SUPERS") + for _, outer in ipairs(progression) do + for _, inner in ipairs(outer) do + if inner.item_id == "ITEM_WEAPON_SUPER_MISSILE_MAX" then + inner.quantity = inner.quantity + locked_supers end end - RandomizerPowerup.OnPickedUp(actor, progression) - RandomizerPowerup.SetItemAmount("ITEM_RANDO_LOCKED_SUPERS", 0) - -- actor case: increase ammo by locked supers after game handled the pickup - else - RandomizerPowerup.OnPickedUp(actor, progression) - Game.AddSF(0.0, "RandomizerPowerup._AddLockedSupers", "b", true) end - + RandomizerPowerup.OnPickedUp(progression) + RandomizerPowerup.SetItemAmount("ITEM_RANDO_LOCKED_SUPERS", 0) end RandomizerSuperMissileTank = {} setmetatable(RandomizerSuperMissileTank, {__index = RandomizerPowerup}) -function RandomizerSuperMissileTank.OnPickedUp(actor, progression) +function RandomizerSuperMissileTank.OnPickedUp(progression) -- use locked supers or super missile max if > 0, which means we have main item local new_item_id = "ITEM_RANDO_LOCKED_SUPERS" local is_main_unlocked = RandomizerPowerup.GetItemAmount("ITEM_WEAPON_SUPER_MISSILE_MAX") > 0 if is_main_unlocked then new_item_id = "ITEM_WEAPON_SUPER_MISSILE_MAX" end - - -- non actor case => change to correct item - if progression ~= nil then - -- grant locked supers or new tank - for _, outer in ipairs(progression) do - for _, inner in ipairs(outer) do - inner.item_id = new_item_id - end - end - RandomizerPowerup.OnPickedUp(actor, progression) - else - if is_main_unlocked then - RandomizerPowerup.OnPickedUp(actor, progression) - Game.AddSF(0.0, "RandomizerPowerup._AddLockedSupers", "") + -- grant locked supers or new tank + for _, outer in ipairs(progression) do + for _, inner in ipairs(outer) do + inner.item_id = new_item_id end end + RandomizerPowerup.OnPickedUp(progression) end -RandomizerVariaSuit = {} -setmetatable(RandomizerVariaSuit, {__index = RandomizerPowerup}) -function RandomizerVariaSuit.OnPickedUp(actor, progression) - RandomizerPowerup.OnPickedUp(actor, progression) - -- Prevents changing the suit to varia if gravity - if Game.GetPlayer().MODELUPDATER.sModelAlias == "Default" then +RandomizerSuit = {} +setmetatable(RandomizerSuit, {__index = RandomizerPowerup}) +function RandomizerSuit.OnPickedUp(progression) + RandomizerPowerup.DisableLiquids() + RandomizerPowerup.OnPickedUp(progression) + if Game.GetEntity("Samus").MODELUPDATER.sModelAlias == "Default" then Game.GetEntity("Samus").MODELUPDATER.sModelAlias = "Varia" + else + Game.GetEntity("Samus").MODELUPDATER.sModelAlias = "Gravity" end Game.GetPlayer():StopEntityLoopWithFade("actors/samus/damage_alarm.wav", 0.6) + RandomizerPowerup.EnableLiquids() end -RandomizerGravitySuit = {} -setmetatable(RandomizerGravitySuit, {__index = RandomizerPowerup}) -function RandomizerGravitySuit.OnPickedUp(actor, progression) - RandomizerPowerup.DisableLiquids() - RandomizerPowerup.OnPickedUp(actor, progression) - Game.GetEntity("Samus").MODELUPDATER.sModelAlias = "Gravity" - RandomizerPowerup.EnableLiquids() +RandomizerEnergyTank = {} +setmetatable(RandomizerEnergyTank, {__index = RandomizerPowerup}) +function RandomizerEnergyTank.OnPickedUp(progression) + RandomizerPowerup.OnPickedUp(progression) + RandomizerPowerup.IncreaseEnergy() +end + +RandomizerAeionTank = {} +setmetatable(RandomizerAeionTank, {__index = RandomizerPowerup}) +function RandomizerAeionTank.OnPickedUp(progression) + RandomizerPowerup.OnPickedUp(progression) + RandomizerPowerup.IncreaseAeion() end RandomizerBabyHatchling = {} setmetatable(RandomizerBabyHatchling, {__index = RandomizerPowerup}) -function RandomizerBabyHatchling.OnPickedUp(actor, progression) - RandomizerPowerup.OnPickedUp(actor, progression) +function RandomizerBabyHatchling.OnPickedUp(progression) + RandomizerPowerup.OnPickedUp(progression) Game.GetDefaultPlayer("Samus").BABYHATCHLINGCREATION:SpawnBaby() end RandomizerScanningPulse = {} setmetatable(RandomizerScanningPulse, {__index = RandomizerPowerup}) -function RandomizerScanningPulse.OnPickedUp(actor, progression) - RandomizerPowerup.OnPickedUp(actor, progression) +function RandomizerScanningPulse.OnPickedUp(progression) + RandomizerPowerup.OnPickedUp(progression) Player.SetAbilityUnlocked("ScanningPulse", true) end RandomizerEnergyShield = {} setmetatable(RandomizerEnergyShield, {__index = RandomizerPowerup}) -function RandomizerEnergyShield.OnPickedUp(actor, progression) - RandomizerPowerup.OnPickedUp(actor, progression) +function RandomizerEnergyShield.OnPickedUp(progression) + RandomizerPowerup.OnPickedUp(progression) Player.SetAbilityUnlocked("EnergyShield", true) end RandomizerEnergyWave = {} setmetatable(RandomizerEnergyWave, {__index = RandomizerPowerup}) -function RandomizerEnergyWave.OnPickedUp(actor, progression) - RandomizerPowerup.OnPickedUp(actor, progression) +function RandomizerEnergyWave.OnPickedUp(progression) + RandomizerPowerup.OnPickedUp(progression) Player.SetAbilityUnlocked("EnergyWave", true) end RandomizerPhaseDisplacement = {} setmetatable(RandomizerPhaseDisplacement, {__index = RandomizerPowerup}) -function RandomizerPhaseDisplacement.OnPickedUp(actor, progression) - RandomizerPowerup.OnPickedUp(actor, progression) +function RandomizerPhaseDisplacement.OnPickedUp(progression) + RandomizerPowerup.OnPickedUp(progression) Player.SetAbilityUnlocked("PhaseDisplacement", true) end diff --git a/open_samus_returns_rando/files/templates/custom_init.lua b/open_samus_returns_rando/files/templates/custom_init.lua index 74bd589..0cc36ca 100644 --- a/open_samus_returns_rando/files/templates/custom_init.lua +++ b/open_samus_returns_rando/files/templates/custom_init.lua @@ -1,16 +1,15 @@ Game.ImportLibrary("system/scripts/init_original.lua") Init.tNewGameInventory = TEMPLATE("new_game_inventory") - Init.bRevealMap = TEMPLATE("reveal_map_on_start") +Init.fEnergyPerTank = TEMPLATE("energy_per_tank") +Init.fAeionPerTank = TEMPLATE("aeion_per_tank") Game.LogWarn(0, "Inventory:") for k, v in pairs(Init.tNewGameInventory) do Game.LogWarn(0, tostring(k) .. " = " .. tostring(v)) end -local buff = {} - function Init.InitGameBlackboard() Blackboard.ResetWithExceptionList({ "GAME_PROGRESS" diff --git a/open_samus_returns_rando/files/templates/randomizer_item_template.lua b/open_samus_returns_rando/files/templates/randomizer_item_template.lua new file mode 100644 index 0000000..eb800f5 --- /dev/null +++ b/open_samus_returns_rando/files/templates/randomizer_item_template.lua @@ -0,0 +1,11 @@ +T__name__T = {} +setmetatable(T__name__T, {__index = TEMPLATE("parent")}) +function T__name__T.main() +end +function T__name__T.OnPickedUp() + local resources = TEMPLATE("resources") + Game.PlayMusicStream(0, TEMPLATE("sound"), -1, -1, 0, 0, 0, 0) + GUI.LaunchMessage(TEMPLATE("caption"), "RandomizerPowerup.Dummy", "") + TEMPLATE("parent").OnPickedUp(resources) + hud.UpdatePlayerInfo(true) +end diff --git a/open_samus_returns_rando/files/templates/randomizer_progressive_template.lua b/open_samus_returns_rando/files/templates/randomizer_progressive_template.lua deleted file mode 100644 index 9404cea..0000000 --- a/open_samus_returns_rando/files/templates/randomizer_progressive_template.lua +++ /dev/null @@ -1,11 +0,0 @@ -Game.LogWarn(0, 'loading TEMPLATE("name")') - -T__name__T = {} -setmetatable(T__name__T, {__index = TEMPLATE("parent")}) -function T__name__T.main() -end -function T__name__T.OnPickedUp(actor) - Game.LogWarn(0, 'picked up TEMPLATE("name")') - local resources = TEMPLATE("resources") - TEMPLATE("parent").OnPickedUp(actor, resources) -end diff --git a/open_samus_returns_rando/files/templates/template_powerup_bmsad.json b/open_samus_returns_rando/files/templates/template_powerup_bmsad.json index b78e04e..7528cb9 100644 --- a/open_samus_returns_rando/files/templates/template_powerup_bmsad.json +++ b/open_samus_returns_rando/files/templates/template_powerup_bmsad.json @@ -72,19 +72,11 @@ }, "Param9": { "type": "b", - "value": true + "value": false }, "Param10": { - "type": "b", - "value": true - }, - "Param11": { "type": "b", "value": false - }, - "Param12": { - "type": "s", - "value": "NumMissileTanksPickedUp" } } } diff --git a/open_samus_returns_rando/lua_editor.py b/open_samus_returns_rando/lua_editor.py index 3edb24a..8c73cc6 100644 --- a/open_samus_returns_rando/lua_editor.py +++ b/open_samus_returns_rando/lua_editor.py @@ -15,8 +15,8 @@ def _read_level_lua(level_id: str) -> str: SPECIFIC_CLASSES = { - "ITEM_VARIA_SUIT": "RandomizerVariaSuit", - "ITEM_GRAVITY_SUIT": "RandomizerGravitySuit", + "ITEM_VARIA_SUIT": "RandomizerSuit", + "ITEM_GRAVITY_SUIT": "RandomizerSuit", "ITEM_BABY_HATCHLING": "RandomizerBabyHatchling", "ITEM_WEAPON_SUPER_MISSILE_MAX": "RandomizerSuperMissile", "ITEM_RANDO_LOCKED_SUPERS": "RandomizerSuperMissileTank", @@ -26,12 +26,26 @@ def _read_level_lua(level_id: str) -> str: "ITEM_SPECIAL_ENERGY_ENERGY_SHIELD": "RandomizerEnergyShield", "ITEM_SPECIAL_ENERGY_ENERGY_WAVE": "RandomizerEnergyWave", "ITEM_SPECIAL_ENERGY_PHASE_DISPLACEMENT": "RandomizerPhaseDisplacement", + "ITEM_ENERGY_TANKS": "RandomizerEnergyTank", + "ITEM_AEION_TANKS": "RandomizerAeionTank", +} + +SPECIFIC_SOUNDS = { + "ITEM_SPECIAL_ENERGY_SCANNING_PULSE": "streams/music/special_ability2_32.wav", + "ITEM_SPECIAL_ENERGY_ENERGY_SHIELD": "streams/music/special_ability2_32.wav", + "ITEM_SPECIAL_ENERGY_ENERGY_WAVE": "streams/music/special_ability2_32.wav", + "ITEM_SPECIAL_ENERGY_PHASE_DISPLACEMENT": "streams/music/special_ability2_32.wav", + "ITEM_ENERGY_TANKS": "streams/music/tank_jingle.wav", + "ITEM_AEION_TANKS": "streams/music/tank_jingle.wav", + "ITEM_RANDO_LOCKED_SUPERS": "streams/music/tank_jingle.wav", + "ITEM_RANDO_LOCKED_PBS": "streams/music/tank_jingle.wav", + "ITEM_WEAPON_MISSILE_MAX": "streams/music/tank_jingle.wav", } class LuaEditor: def __init__(self): - self._progressive_classes = {} + self._item_classes = {} self._powerup_script = _read_powerup_lua() self._custom_level_scripts: dict[str, dict] = self._read_levels() @@ -44,13 +58,10 @@ def _read_levels(self) -> dict[str, dict]: def get_parent_for(self, item_id) -> str: return SPECIFIC_CLASSES.get(item_id, "RandomizerPowerup") - def get_script_class(self, pickup: dict, boss: bool = False, actordef_name: str = "") -> str: + def get_script_class(self, pickup: dict, actordef_name: str = "") -> str: pickup_resources = pickup["resources"] - parent = self.get_parent_for(pickup_resources[0][0]["item_id"]) - - if not boss and len(pickup_resources) == 1 and len(pickup_resources[0]) == 1: - # Single-item pickup; don't include progressive template - return parent + first_item_id = pickup_resources[0][0]["item_id"] + parent = self.get_parent_for(first_item_id) if actordef_name and len(pickup["model"]) > 1: self.add_progressive_models(pickup, actordef_name) @@ -60,10 +71,10 @@ def get_script_class(self, pickup: dict, boss: bool = False, actordef_name: str for res in pickup_resources ]).replace("-", "MINUS") - if hashable_progression in self._progressive_classes.keys(): - return self._progressive_classes[hashable_progression] + if hashable_progression in self._item_classes.keys(): + return self._item_classes[hashable_progression] - class_name = f"RandomizerProgressive{hashable_progression}" + class_name = f"RandomizerItem{hashable_progression}" resources = [ [ @@ -75,18 +86,22 @@ def get_script_class(self, pickup: dict, boss: bool = False, actordef_name: str ] for resource_list in pickup_resources ] + sound = SPECIFIC_SOUNDS.get(first_item_id, "streams/music/sphere_jingle_placeholder.wav") replacement = { "name": class_name, "resources": resources, "parent": parent, + "caption": lua_util.wrap_string(pickup["caption"]), + "sound": lua_util.wrap_string(sound), } - self.add_progressive_class(replacement) - self._progressive_classes[hashable_progression] = class_name + self.add_item_class(replacement) + self._item_classes[hashable_progression] = class_name + return class_name - def add_progressive_class(self, replacement): - new_class = lua_util.replace_lua_template("randomizer_progressive_template.lua", replacement) + def add_item_class(self, replacement): + new_class = lua_util.replace_lua_template("randomizer_item_template.lua", replacement) self._powerup_script += new_class.encode("utf-8") def add_progressive_models(self, pickup: dict, actordef_name: str): diff --git a/open_samus_returns_rando/pickup.py b/open_samus_returns_rando/pickup.py index a6b991b..8108d09 100644 --- a/open_samus_returns_rando/pickup.py +++ b/open_samus_returns_rando/pickup.py @@ -13,6 +13,14 @@ LOG = logging.getLogger("pickup") +TANK_ITEMS = { + "ITEM_ENERGY_TANKS", + "ITEM_AEION_TANKS", + "ITEM_WEAPON_MISSILE_MAX", + "ITEM_RANDO_LOCKED_SUPERS", + "ITEM_RANDO_LOCKED_PBS", +} + @functools.cache def _read_template_powerup(): @@ -33,42 +41,21 @@ def __init__(self, lua_editor: LuaEditor, pickup: dict, pickup_id: int, configur def patch(self, editor: PatcherEditor): raise NotImplementedError -# Note: MSR has a lot of customised Lua for Pickups. We maybe need to add them / take the logic into account? class ActorPickup(BasePickup): def patch_single_item_pickup(self, bmsad: dict) -> dict: pickable = bmsad["components"]["PICKABLE"] script: dict = bmsad["components"]["SCRIPT"] item_id: str = self.pickup["resources"][0][0]["item_id"] - quantity: float = self.pickup["resources"][0][0]["quantity"] set_custom_params: dict = pickable["functions"][0]["params"] action_sets: dict = bmsad["action_sets"][0]["animations"][0] fx_create_and_link: dict = bmsad["components"]["FX"]["functions"][0]["params"] - if item_id == "ITEM_ENERGY_TANKS": - item_id = "fMaxLife" - quantity *= self.configuration["energy_per_tank"] - set_custom_params["Param4"]["value"] = "Full" - set_custom_params["Param5"]["value"] = "fCurrentLife" - set_custom_params["Param6"]["value"] = "LIFE" + if item_id in TANK_ITEMS: action_sets["animation_id"] = 150 action_sets["action"]["bcskla"] = "actors/items/itemtank/animations/relax.bcskla" - - elif item_id == "ITEM_AEION_TANKS": - item_id = "fMaxEnergy" - quantity *= self.configuration["aeion_per_tank"] - set_custom_params["Param4"]["value"] = "Full" - set_custom_params["Param5"]["value"] = "fEnergy" - set_custom_params["Param6"]["value"] = "SPECIALENERGY" - action_sets["animation_id"] = 150 - action_sets["action"]["bcskla"] = "actors/items/itemtank/animations/relax.bcskla" - - elif item_id in {"ITEM_WEAPON_MISSILE_MAX", "ITEM_RANDO_LOCKED_SUPERS", "ITEM_RANDO_LOCKED_PBS"}: - action_sets["animation_id"] = 150 - action_sets["action"]["bcskla"] = "actors/items/itemtank/animations/relax.bcskla" - elif item_id.startswith("ITEM_SPECIAL_ENERGY"): fx_create_and_link["Param13"]["value"] = True if item_id == "ITEM_SPECIAL_ENERGY_SCANNING_PULSE": @@ -83,20 +70,19 @@ def patch_single_item_pickup(self, bmsad: dict) -> dict: elif item_id == "ITEM_SPECIAL_ENERGY_PHASE_DISPLACEMENT": fx_create_and_link["Param1"]["value"] = "purpleorb" fx_create_and_link["Param2"]["value"] = "actors/items/powerup_phasedisplacement/fx/purpleorb.bcptl" - elif item_id == "ITEM_ADN": fx_create_and_link["Param1"]["value"] = "leak" fx_create_and_link["Param2"]["value"] = "actors/items/adn/fx/adnleak.bcptl" fx_create_and_link["Param13"]["value"] = True - set_custom_params["Param1"]["value"] = item_id - set_custom_params["Param2"]["value"] = quantity + set_custom_params["Param1"]["value"] = "ITEM_NONE" + set_custom_params["Param2"]["value"] = 0 script["functions"][0]["params"]["Param1"]["value"] = \ 'actors/items/randomizer_powerup/scripts/randomizer_powerup.lc' - script["functions"][0]["params"]["Param2"]["value"] = self.lua_editor.get_script_class(self.pickup, - actordef_name=bmsad[ - "name"]) + script["functions"][0]["params"]["Param2"]["value"] = self.lua_editor.get_script_class( + self.pickup, actordef_name=bmsad["name"] + ) return bmsad @@ -105,17 +91,14 @@ def patch_multi_item_pickup(self, bmsad: dict) -> dict: script: dict = bmsad["components"]["SCRIPT"] set_custom_params: dict = pickable["functions"][0]["params"] - # FIXME: Better would be a nothing item but the game is crashing if you pick up a second progressive when - # it tries to show the item on the inventory screen. Now it always shows the first progressive. - set_custom_params["Param1"]["value"] = self.pickup["resources"][0][0]["item_id"] + set_custom_params["Param1"]["value"] = "ITEM_NONE" set_custom_params["Param2"]["value"] = 0 script["functions"][0]["params"]["Param1"]["value"] = \ 'actors/items/randomizer_powerup/scripts/randomizer_powerup.lc' - script["functions"][0]["params"]["Param2"]["value"] = self.lua_editor.get_script_class(self.pickup, - actordef_name=bmsad[ - "name"]) - + script["functions"][0]["params"]["Param2"]["value"] = self.lua_editor.get_script_class( + self.pickup, actordef_name=bmsad["name"] + ) return bmsad def patch_model(self, model_names: list[str], new_template: dict) -> None: @@ -199,8 +182,6 @@ def patch(self, editor: PatcherEditor): for dep in model_data.dependencies: editor.ensure_present(level_pkg, dep) - # TODO: Add BMSAS :( ? - # For debugging, write the bmsad we just created # Path("custom_bmsad", f"randomizer_powerup_{i}.bmsad.json").write_text( # json.dumps(new_template, indent=4) From c212ab51818061b71e36508e4d3b08444c4f1f3c Mon Sep 17 00:00:00 2001 From: dyceron <38679103+dyceron@users.noreply.github.com> Date: Fri, 22 Sep 2023 18:24:30 -0400 Subject: [PATCH 2/5] Fix typo for Aeion in lua and change lines to say pbs --- open_samus_returns_rando/files/randomizer_powerup.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/open_samus_returns_rando/files/randomizer_powerup.lua b/open_samus_returns_rando/files/randomizer_powerup.lua index b9562fb..380a291 100644 --- a/open_samus_returns_rando/files/randomizer_powerup.lua +++ b/open_samus_returns_rando/files/randomizer_powerup.lua @@ -147,7 +147,7 @@ function RandomizerPowerup.IncreaseAeion() local new_max = RandomizerPowerup.GetItemAmount("ITEM_MAX_SPECIAL_ENERGY") + aeion new_max = math.min(new_max, MAX_AEION) RandomizerPowerup.SetItemAmount("ITEM_MAX_SPECIAL_ENERGY", new_max) - RandomizerPowerup.SetItemAmount("ITEM_CURREITEM_CURRENT_SPECIAL_ENERGYNT_LIFE", new_max) + RandomizerPowerup.SetItemAmount("ITEM_CURRENT_SPECIAL_ENERGY", new_max) local specialEnergy = Game.GetPlayer().SPECIALENERGY specialEnergy.fMaxEnergy = new_max @@ -173,14 +173,14 @@ end RandomizerPowerBombTank = {} setmetatable(RandomizerPowerBombTank, {__index = RandomizerPowerup}) function RandomizerPowerBombTank.OnPickedUp(progression) - -- use locked supers or super missile max if > 0, which means we have main item + -- use locked pbs or power bomb max if > 0, which means we have main item local new_item_id = "ITEM_RANDO_LOCKED_PBS" local is_main_unlocked = RandomizerPowerup.GetItemAmount("ITEM_WEAPON_POWER_BOMB_MAX") > 0 if is_main_unlocked then new_item_id = "ITEM_WEAPON_POWER_BOMB_MAX" end - -- grant locked supers or new tank + -- grant locked pbs or new tank for _, outer in ipairs(progression) do for _, inner in ipairs(outer) do inner.item_id = new_item_id From 235bbf90f1968ad64b732d4b8ad2b8a36ecb8ace Mon Sep 17 00:00:00 2001 From: dyceron <38679103+dyceron@users.noreply.github.com> Date: Fri, 22 Sep 2023 18:32:26 -0400 Subject: [PATCH 3/5] Remove `custom_player.lua` since its not called anymore --- open_samus_returns_rando/files/custom_player.lua | 5 ----- open_samus_returns_rando/samus_returns_patcher.py | 1 - 2 files changed, 6 deletions(-) delete mode 100644 open_samus_returns_rando/files/custom_player.lua diff --git a/open_samus_returns_rando/files/custom_player.lua b/open_samus_returns_rando/files/custom_player.lua deleted file mode 100644 index cdca18b..0000000 --- a/open_samus_returns_rando/files/custom_player.lua +++ /dev/null @@ -1,5 +0,0 @@ -Game.ImportLibrary("actors/characters/player/scripts/player_original.lua") - -function Player.UnlockScanningPulse() - Player.SetAbilityUnlocked("ScanningPulse", true) -end diff --git a/open_samus_returns_rando/samus_returns_patcher.py b/open_samus_returns_rando/samus_returns_patcher.py index e36932c..1da713c 100644 --- a/open_samus_returns_rando/samus_returns_patcher.py +++ b/open_samus_returns_rando/samus_returns_patcher.py @@ -119,7 +119,6 @@ def patch_extracted(input_path: Path, output_path: Path, configuration: dict): # Add custom lua files lua_util.replace_script(editor, "system/scripts/scenario", "custom_scenario.lua") - lua_util.replace_script(editor, "actors/characters/player/scripts/player", "custom_player.lua") lua_util.replace_script(editor, "actors/props/samusship/scripts/samusship", "custom_ship.lua") lua_util.replace_script(editor, "actors/props/savestation/scripts/savestation", "custom_savestation.lua") From a797ad1ff21a9ad5d9e8349b0d208d6848341ab9 Mon Sep 17 00:00:00 2001 From: dyceron <38679103+dyceron@users.noreply.github.com> Date: Fri, 22 Sep 2023 19:26:09 -0400 Subject: [PATCH 4/5] Fix starting Aeion --- open_samus_returns_rando/samus_returns_patcher.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/open_samus_returns_rando/samus_returns_patcher.py b/open_samus_returns_rando/samus_returns_patcher.py index 1da713c..ec2aa4f 100644 --- a/open_samus_returns_rando/samus_returns_patcher.py +++ b/open_samus_returns_rando/samus_returns_patcher.py @@ -32,11 +32,9 @@ def create_custom_init(configuration: dict) -> str: energy_per_tank = configuration["energy_per_tank"] max_life = inventory.pop("ITEM_MAX_LIFE") - - # max_aeion has to be setup like this, - # otherwise the starting aeion amount will be 1000 (hardcoded) plus the aeion tank amount + aeion_per_tank = configuration["aeion_per_tank"] - max_aeion = 1000 - aeion_per_tank + max_aeion = inventory.pop("ITEM_MAX_SPECIAL_ENERGY") # increase starting HP if starting with etanks if "ITEM_ENERGY_TANKS" in inventory: From a14cd7109a3177907ad15ee5077bdba2633c078d Mon Sep 17 00:00:00 2001 From: dyceron <38679103+dyceron@users.noreply.github.com> Date: Sat, 23 Sep 2023 00:43:25 -0400 Subject: [PATCH 5/5] Update randomizer_powerup.lua --- open_samus_returns_rando/files/randomizer_powerup.lua | 2 -- 1 file changed, 2 deletions(-) diff --git a/open_samus_returns_rando/files/randomizer_powerup.lua b/open_samus_returns_rando/files/randomizer_powerup.lua index 380a291..50df311 100644 --- a/open_samus_returns_rando/files/randomizer_powerup.lua +++ b/open_samus_returns_rando/files/randomizer_powerup.lua @@ -126,7 +126,6 @@ function RandomizerPowerup.IncreaseAmmo(resource) RandomizerPowerup.IncreaseItemAmount(current_id, resource.quantity, resource.item_id) end --- TODO: What's the max energy? MAX_ENERGY= 1099 function RandomizerPowerup.IncreaseEnergy() local energy = Init.fEnergyPerTank @@ -140,7 +139,6 @@ function RandomizerPowerup.IncreaseEnergy() life.fCurrentLife = new_max end --- TODO: What's the max aeion? MAX_AEION= 2200 function RandomizerPowerup.IncreaseAeion() local aeion = Init.fAeionPerTank