diff --git a/src/open_samus_returns_rando/files/.gitignore b/src/open_samus_returns_rando/files/.gitignore new file mode 100644 index 00000000..8e5eb400 --- /dev/null +++ b/src/open_samus_returns_rando/files/.gitignore @@ -0,0 +1,3 @@ +levels/*.lc +custom/*.lc +pickups/*.lc \ No newline at end of file diff --git a/src/open_samus_returns_rando/files/templates/custom_init.lua b/src/open_samus_returns_rando/files/templates/custom_init.lua index c20831a6..0fe4e7df 100644 --- a/src/open_samus_returns_rando/files/templates/custom_init.lua +++ b/src/open_samus_returns_rando/files/templates/custom_init.lua @@ -12,11 +12,6 @@ Init.iNumRandoTextBoxes = TEMPLATE("textbox_count") Init.sThisRandoIdentifier = TEMPLATE("configuration_identifier") Init.tBoxesSeen = 0 -Game.LogWarn(0, "Inventory:") -for k, v in pairs(Init.tNewGameInventory) do - Game.LogWarn(0, tostring(k) .. " = " .. tostring(v)) -end - function Init.InitGameBlackboard() Blackboard.ResetWithExceptionList({ "GAME_PROGRESS" @@ -69,7 +64,6 @@ end function Init.InitNewGame(arg1, arg2, arg3, arg4, arg4) Init.tBoxesSeen = 0 - Game.LogWarn(0, string.format("Will start Game - %s / %s / %s / %s", tostring(arg1), tostring(arg2), tostring(arg3), tostring(arg4))) Game.LoadScenario("c10_samus", Init.sStartingScenario, Init.sStartingActor, "samus", 1) if Init.bRevealMap then Game.AddGUISF(0.0, Game.ScanVisitDiscoverEverything, "", "") @@ -78,8 +72,6 @@ function Init.InitNewGame(arg1, arg2, arg3, arg4, arg4) Game.SetForceSkipCutscenes(true) -Game.LogWarn(0, "Finished modded system/init.lc") - ALL_SCENARIOS = { "s000_surface", "s010_area1", diff --git a/src/open_samus_returns_rando/files/templates/metroid_template.lua b/src/open_samus_returns_rando/files/templates/metroid_template.lua index 4fb09342..84de2945 100644 --- a/src/open_samus_returns_rando/files/templates/metroid_template.lua +++ b/src/open_samus_returns_rando/files/templates/metroid_template.lua @@ -1,5 +1,4 @@ -Game.ImportLibrary("actors/items/randomizer_powerup/scripts/randomizer_powerup.lua", false) - +Game.ImportLibrary("actors/items/randomizerpowerup/scripts/randomizerpowerup.lua", false) Metroid = Metroid or {} function Metroid.Dummy() end @@ -66,6 +65,22 @@ function Metroid.RemoveMetroid(_ARG_0_) Metroid.Pickups[scenario][spawnGroupName].OnPickedUp ~= nil then Metroid.Pickups[scenario][spawnGroupName].OnPickedUp() end + + if scenario == nil then + GUI.LaunchMessage("Oops 1", "Metroid.Dummy", "") + end + if Metroid.Pickups == nil then + GUI.LaunchMessage("Oops 2", "Metroid.Dummy", "") + end + if Metroid.Pickups[scenario] == nil then + GUI.LaunchMessage("Oops 3", "Metroid.Dummy", "") + end + if Metroid.Pickups[scenario][spawnGroupName] == nil then + GUI.LaunchMessage("Oops 4", "Metroid.Dummy", "") + end + if Metroid.Pickups[scenario][spawnGroupName].OnPickedUp == nil then + GUI.LaunchMessage("Oops 5", "Metroid.Dummy", "") + end Game.SetInGameMusicState("RELAX") if not CurrentScenario.isMultiGamma then Game.SaveGame("checkpoint", "AfterNewAbilityAcquired", "", true) diff --git a/src/open_samus_returns_rando/files/templates/randomizer_item_template.lua b/src/open_samus_returns_rando/files/templates/randomizer_item_template.lua index a89cbd72..518e7a64 100644 --- a/src/open_samus_returns_rando/files/templates/randomizer_item_template.lua +++ b/src/open_samus_returns_rando/files/templates/randomizer_item_template.lua @@ -1,5 +1,4 @@ -T__name__T = {} -setmetatable(T__name__T, {__index = TEMPLATE("parent")}) +Game.ImportLibrary(TEMPLATE("parent_lua"), false) function T__name__T.main() end function T__name__T.OnPickedUp() diff --git a/src/open_samus_returns_rando/files/templates/randomizer_powerup.lua b/src/open_samus_returns_rando/files/templates/randomizer_powerup.lua deleted file mode 100644 index 10d3bf24..00000000 --- a/src/open_samus_returns_rando/files/templates/randomizer_powerup.lua +++ /dev/null @@ -1,350 +0,0 @@ -RandomizerPowerup = RandomizerPowerup or {} -function RandomizerPowerup.main() -end - -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 - if type(capacity) == "string" then - capacity = RandomizerPowerup.GetItemAmount(capacity) - end - target = math.min(target, capacity) - end - target = math.max(target, 0) - RandomizerPowerup.SetItemAmount(item_id, target) - - local itemAmount = Game.GetPlayer().INVENTORY - if item_id == "ITEM_CURRENT_SPECIAL_ENERGY" then - local specialEnergy = Game.GetPlayer().SPECIALENERGY - specialEnergy.fMaxEnergy = capacity - specialEnergy.fEnergy = capacity - elseif item_id == "ITEM_WEAPON_MISSILE_CURRENT" then - itemAmount:SetItemAmount(item_id, capacity) - elseif item_id == "ITEM_WEAPON_SUPER_MISSILE_CURRENT" then - itemAmount:SetItemAmount(item_id, capacity) - elseif item_id == "ITEM_WEAPON_POWER_BOMB_CURRENT" then - itemAmount:SetItemAmount(item_id, capacity) - end -end - -function RandomizerPowerup.OnPickedUp(resources) - local granted = RandomizerPowerup.HandlePickupResources(resources) - - for _, resource in ipairs(granted) do - RandomizerPowerup.IncreaseAmmo(resource) - end - - Scenario.UpdateProgressiveItemModels() - - return granted -end - -function RandomizerPowerup.DisableLiquids() - if Game.GetPlayer().MODELUPDATER.sModelAlias ~= "Gravity" then - if Scenario.CurrentScenarioID == "s010_area1" then - Game.GetEntity("Lava_Trigger_001").TRIGGER:DisableTrigger() - elseif Scenario.CurrentScenarioID == "s050_area5" then - Game.GetEntity("TG_Water_006").TRIGGER:DisableTrigger() - Game.GetEntity("TG_Water_009").TRIGGER:DisableTrigger() - elseif Scenario.CurrentScenarioID == "s067_area6c" then - Game.GetEntity("TG_SP_Water_002").TRIGGER:DisableTrigger() - end - end -end - -function RandomizerPowerup.EnableLiquids() - if Scenario.CurrentScenarioID == "s010_area1" then - Game.GetEntity("Lava_Trigger_001").TRIGGER:EnableTrigger() - elseif Scenario.CurrentScenarioID == "s050_area5" then - Game.GetEntity("TG_Water_006").TRIGGER:EnableTrigger() - Game.GetEntity("TG_Water_009").TRIGGER:EnableTrigger() - elseif Scenario.CurrentScenarioID == "s067_area6c" then - Game.GetEntity("TG_SP_Water_002").TRIGGER:EnableTrigger() - end -end - -function RandomizerPowerup.ObjectiveComplete() - if Game.GetItemAmount(Game.GetPlayerName(), "ITEM_ADN") == 39 then - local baby = Game.GetItemAmount(Game.GetPlayerName(), "ITEM_BABY_HATCHLING") - local dnaCounter = GUI.GetDisplayObject("IngameMenuRoot.IngameMenuComposition.LowerComposition.LowerInfoComposition.DNACounter") - GUI.SetProperties(dnaCounter, { - ColorR = "0.90908", - ColorG = "0.88627", - ColorB = "0.66274", - }) - if baby > 0 then - GUI.LaunchMessage("All Metroid DNA has been collected!\nThe path to Proteus Ridley has been opened in Surface - West!", - "RandomizerPowerup.Dummy", "") - elseif baby == 0 then - GUI.LaunchMessage("All Metroid DNA has been collected!\nContinue searching for the Baby Metroid!", - "RandomizerPowerup.Dummy", "") - end - end -end - -function RandomizerPowerup.HandlePickupResources(progression) - progression = progression or {} - - local alwaysGrant = false - - if #progression == 0 then - return {} - elseif #progression == 1 then - alwaysGrant = true - end - - for _, resource_list in ipairs(progression) do - local data = " - " - for _, resource in ipairs(resource_list) do - data = data .. resource.item_id .. " (" .. resource.quantity .. ") / " - end - end - - -- For each progression stage, if the player does not have the FIRST item in that stage, the whole stage is granted - for _, resource_list in ipairs(progression) do - -- Check if we need to grant anything from this progression stage - - if #resource_list > 0 then - local current = RandomizerPowerup.GetItemAmount(resource_list[1].item_id) - local shouldGrant = alwaysGrant or current < resource_list[1].quantity - - if shouldGrant then - for _, resource in ipairs(resource_list) do - RandomizerPowerup.DisableLiquids() - RandomizerPowerup.IncreaseItemAmount(resource.item_id, resource.quantity) - RandomizerPowerup.EnableLiquids() - if string.sub(resource.item_id, 0, 14) == "ITEM_RANDO_DNA" then - local scenario = Init.tScenarioMapping[Scenario.CurrentScenarioID] - local currentDNA = Blackboard.GetProp("GAME", scenario .."_acquired_dna") or 0 - Blackboard.SetProp("GAME", scenario .. "_acquired_dna", "i", currentDNA + 1) - Scenario.UpdateDNACounter() - RandomizerPowerup.IncreaseItemAmount("ITEM_ADN", resource.quantity) - Game.AddSF(0, "RandomizerPowerup.ObjectiveComplete", "") - end - end - - return resource_list - end - end - - -- Otherwise, loop to next progression stage (or fall out of loop) - end - - return {} -- nothing granted after final stage of progression is reached -end - - -function RandomizerPowerup.IncreaseAmmo(resource) - if not resource then return end - - local current_id = nil - - if resource.item_id == "ITEM_WEAPON_MISSILE_MAX" then - current_id = "ITEM_WEAPON_MISSILE_CURRENT" - elseif resource.item_id == "ITEM_WEAPON_SUPER_MISSILE_MAX" then - current_id = "ITEM_WEAPON_SUPER_MISSILE_CURRENT" - elseif resource.item_id == "ITEM_WEAPON_POWER_BOMB_MAX" then - current_id = "ITEM_WEAPON_POWER_BOMB_CURRENT" - elseif resource.item_id == "ITEM_MAX_SPECIAL_ENERGY" then - current_id = "ITEM_CURRENT_SPECIAL_ENERGY" - end - - if current_id == nil then return end - - RandomizerPowerup.IncreaseItemAmount(current_id, resource.quantity, resource.item_id) -end - -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 - -RandomizerPowerBomb = {} -setmetatable(RandomizerPowerBomb, {__index = RandomizerPowerup}) -function RandomizerPowerBomb.OnPickedUp(progression) - local locked_pbs = RandomizerPowerup.GetItemAmount("ITEM_POWER_BOMB_TANKS") - for _, outer in ipairs(progression) do - for _, inner in ipairs(outer) do - if inner.item_id == "ITEM_POWER_BOMB_TANKS" then - inner.item_id = "ITEM_WEAPON_POWER_BOMB_MAX" - inner.quantity = inner.quantity + locked_pbs - end - end - end - RandomizerPowerup.OnPickedUp(progression) - RandomizerPowerup.SetItemAmount("ITEM_POWER_BOMB_TANKS", 0) -end - - -RandomizerPowerBombTank = {} -setmetatable(RandomizerPowerBombTank, {__index = RandomizerPowerup}) -function RandomizerPowerBombTank.OnPickedUp(progression) - -- if we have main item use power bomb max else use locked power bombs - local new_item_id = "ITEM_POWER_BOMB_TANKS" - local is_main_unlocked = RandomizerPowerup.GetItemAmount("ITEM_WEAPON_POWER_BOMB") > 0 - if is_main_unlocked then - new_item_id = "ITEM_WEAPON_POWER_BOMB_MAX" - end - - -- grant locked pbs 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 - -RandomizerSuperMissile = {} -setmetatable(RandomizerSuperMissile, {__index = RandomizerPowerup}) -function RandomizerSuperMissile.OnPickedUp(progression) - local locked_supers = RandomizerPowerup.GetItemAmount("ITEM_SUPER_MISSILE_TANKS") - for _, outer in ipairs(progression) do - for _, inner in ipairs(outer) do - if inner.item_id == "ITEM_SUPER_MISSILE_TANKS" then - inner.item_id = "ITEM_WEAPON_SUPER_MISSILE_MAX" - inner.quantity = inner.quantity + locked_supers - end - end - end - RandomizerPowerup.OnPickedUp(progression) - RandomizerPowerup.SetItemAmount("ITEM_SUPER_MISSILE_TANKS", 0) -end - -RandomizerSuperMissileTank = {} -setmetatable(RandomizerSuperMissileTank, {__index = RandomizerPowerup}) -function RandomizerSuperMissileTank.OnPickedUp(progression) - -- if we have main item use super missile max else use locked supers - local new_item_id = "ITEM_SUPER_MISSILE_TANKS" - local is_main_unlocked = RandomizerPowerup.GetItemAmount("ITEM_WEAPON_SUPER_MISSILE") > 0 - if is_main_unlocked then - new_item_id = "ITEM_WEAPON_SUPER_MISSILE_MAX" - end - -- 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 - -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 - -RandomizerEnergyTank = {} -setmetatable(RandomizerEnergyTank, {__index = RandomizerPowerup}) -function RandomizerEnergyTank.OnPickedUp(progression) - RandomizerPowerup.OnPickedUp(progression) - RandomizerPowerup.IncreaseEnergy() -end - -RandomizerBabyHatchling = {} -setmetatable(RandomizerBabyHatchling, {__index = RandomizerPowerup}) -function RandomizerBabyHatchling.OnPickedUp(progression) - RandomizerPowerup.OnPickedUp(progression) - Game.GetDefaultPlayer("Samus").BABYHATCHLINGCREATION:SpawnBaby() - Game.GetEntity("Baby Hatchling").vPos = Game.GetDefaultPlayer("Samus").vPos -end - -RandomizerScanningPulse = {} -setmetatable(RandomizerScanningPulse, {__index = RandomizerPowerup}) -function RandomizerScanningPulse.OnPickedUp(progression) - RandomizerPowerup.OnPickedUp(progression) - Player.SetAbilityUnlocked("ScanningPulse", true) -end - -RandomizerEnergyShield = {} -setmetatable(RandomizerEnergyShield, {__index = RandomizerPowerup}) -function RandomizerEnergyShield.OnPickedUp(progression) - RandomizerPowerup.OnPickedUp(progression) - Player.SetAbilityUnlocked("EnergyShield", true) -end - -RandomizerEnergyWave = {} -setmetatable(RandomizerEnergyWave, {__index = RandomizerPowerup}) -function RandomizerEnergyWave.OnPickedUp(progression) - RandomizerPowerup.OnPickedUp(progression) - Player.SetAbilityUnlocked("EnergyWave", true) -end - -RandomizerPhaseDisplacement = {} -setmetatable(RandomizerPhaseDisplacement, {__index = RandomizerPowerup}) -function RandomizerPhaseDisplacement.OnPickedUp(progression) - RandomizerPowerup.OnPickedUp(progression) - Player.SetAbilityUnlocked("PhaseDisplacement", true) -end - -RandomizerReserveTankE = {} -setmetatable(RandomizerReserveTankE, {__index = RandomizerPowerup}) -function RandomizerReserveTankE.OnPickedUp(progression) - RandomizerPowerup.OnPickedUp(progression) - Blackboard.SetProp("GAME", "ITEM_RESERVE_TANK_LIFE_ACTIVE", "b", true) - Blackboard.SetProp("GAME", "ITEM_RESERVE_TANK_LIFE_FULL", "b", true) - Game.AddSF(0.0, "Game.HUDIdleScreenGo", "") - Game.AddSF(0.5, "Game.HUDIdleScreenLeave", "") -end - -RandomizerReserveTankM = {} -setmetatable(RandomizerReserveTankM, {__index = RandomizerPowerup}) -function RandomizerReserveTankM.OnPickedUp(progression) - RandomizerPowerup.OnPickedUp(progression) - Blackboard.SetProp("GAME", "ITEM_RESERVE_TANK_MISSILE_ACTIVE", "b", true) - Blackboard.SetProp("GAME", "ITEM_RESERVE_TANK_MISSILE_FULL", "b", true) - Game.AddSF(0.0, "Game.HUDIdleScreenGo", "") - Game.AddSF(0.5, "Game.HUDIdleScreenLeave", "") -end - -RandomizerReserveTankA = {} -setmetatable(RandomizerReserveTankA, {__index = RandomizerPowerup}) -function RandomizerReserveTankA.OnPickedUp(progression) - RandomizerPowerup.OnPickedUp(progression) - Blackboard.SetProp("GAME", "ITEM_RESERVE_TANK_SPECIAL_ENERGY_ACTIVE", "b", true) - Blackboard.SetProp("GAME", "ITEM_RESERVE_TANK_SPECIAL_ENERGY_FULL", "b", true) - Game.AddSF(0.0, "Game.HUDIdleScreenGo", "") - Game.AddSF(0.5, "Game.HUDIdleScreenLeave", "") -end - -TEMPLATE("custom_code") \ No newline at end of file diff --git a/src/open_samus_returns_rando/files/templates/randomizerpowerup.lua b/src/open_samus_returns_rando/files/templates/randomizerpowerup.lua new file mode 100644 index 00000000..60433581 --- /dev/null +++ b/src/open_samus_returns_rando/files/templates/randomizerpowerup.lua @@ -0,0 +1,150 @@ +RandomizerPowerup = RandomizerPowerup or {} +function RandomizerPowerup.main() +end + +RandomizerPowerup.tProgressiveModels = {} + +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 + if type(capacity) == "string" then + capacity = RandomizerPowerup.GetItemAmount(capacity) + end + target = math.min(target, capacity) + end + target = math.max(target, 0) + RandomizerPowerup.SetItemAmount(item_id, target) + + local itemAmount = Game.GetPlayer().INVENTORY + if item_id == "ITEM_CURRENT_SPECIAL_ENERGY" then + local specialEnergy = Game.GetPlayer().SPECIALENERGY + specialEnergy.fMaxEnergy = capacity + specialEnergy.fEnergy = capacity + elseif item_id == "ITEM_WEAPON_MISSILE_CURRENT" then + itemAmount:SetItemAmount(item_id, capacity) + elseif item_id == "ITEM_WEAPON_SUPER_MISSILE_CURRENT" then + itemAmount:SetItemAmount(item_id, capacity) + elseif item_id == "ITEM_WEAPON_POWER_BOMB_CURRENT" then + itemAmount:SetItemAmount(item_id, capacity) + end +end + +function RandomizerPowerup.OnPickedUp(resources) + local granted = RandomizerPowerup.HandlePickupResources(resources) + + for _, resource in ipairs(granted) do + RandomizerPowerup.IncreaseAmmo(resource) + end + + Scenario.UpdateProgressiveItemModels() + + return granted +end + +function RandomizerPowerup.ObjectiveComplete() + if Game.GetItemAmount(Game.GetPlayerName(), "ITEM_ADN") == 39 then + local baby = Game.GetItemAmount(Game.GetPlayerName(), "ITEM_BABY_HATCHLING") + local dnaCounter = GUI.GetDisplayObject("IngameMenuRoot.IngameMenuComposition.LowerComposition.LowerInfoComposition.DNACounter") + GUI.SetProperties(dnaCounter, { + ColorR = "0.90908", + ColorG = "0.88627", + ColorB = "0.66274", + }) + if baby > 0 then + GUI.LaunchMessage("All Metroid DNA has been collected!\nThe path to Proteus Ridley has been opened in Surface - West!", + "RandomizerPowerup.Dummy", "") + elseif baby == 0 then + GUI.LaunchMessage("All Metroid DNA has been collected!\nContinue searching for the Baby Metroid!", + "RandomizerPowerup.Dummy", "") + end + end +end + +function RandomizerPowerup.HandlePickupResources(progression) + progression = progression or {} + + local alwaysGrant = false + + if #progression == 0 then + return {} + elseif #progression == 1 then + alwaysGrant = true + end + + for _, resource_list in ipairs(progression) do + local data = " - " + for _, resource in ipairs(resource_list) do + data = data .. resource.item_id .. " (" .. resource.quantity .. ") / " + end + end + + -- For each progression stage, if the player does not have the FIRST item in that stage, the whole stage is granted + for _, resource_list in ipairs(progression) do + -- Check if we need to grant anything from this progression stage + + if #resource_list > 0 then + local current = RandomizerPowerup.GetItemAmount(resource_list[1].item_id) + local shouldGrant = alwaysGrant or current < resource_list[1].quantity + + if shouldGrant then + for _, resource in ipairs(resource_list) do + RandomizerPowerup.IncreaseItemAmount(resource.item_id, resource.quantity) + if string.sub(resource.item_id, 0, 14) == "ITEM_RANDO_DNA" then + local scenario = Init.tScenarioMapping[Scenario.CurrentScenarioID] + local currentDNA = Blackboard.GetProp("GAME", scenario .."_acquired_dna") or 0 + Blackboard.SetProp("GAME", scenario .. "_acquired_dna", "i", currentDNA + 1) + Scenario.UpdateDNACounter() + RandomizerPowerup.IncreaseItemAmount("ITEM_ADN", resource.quantity) + Game.AddSF(0, "RandomizerPowerup.ObjectiveComplete", "") + end + end + + return resource_list + end + end + + -- Otherwise, loop to next progression stage (or fall out of loop) + end + + return {} -- nothing granted after final stage of progression is reached +end + + +function RandomizerPowerup.IncreaseAmmo(resource) + if not resource then return end + + local current_id = nil + + if resource.item_id == "ITEM_WEAPON_MISSILE_MAX" then + current_id = "ITEM_WEAPON_MISSILE_CURRENT" + elseif resource.item_id == "ITEM_WEAPON_SUPER_MISSILE_MAX" then + current_id = "ITEM_WEAPON_SUPER_MISSILE_CURRENT" + elseif resource.item_id == "ITEM_WEAPON_POWER_BOMB_MAX" then + current_id = "ITEM_WEAPON_POWER_BOMB_CURRENT" + elseif resource.item_id == "ITEM_MAX_SPECIAL_ENERGY" then + current_id = "ITEM_CURRENT_SPECIAL_ENERGY" + end + + if current_id == nil then return end + + RandomizerPowerup.IncreaseItemAmount(current_id, resource.quantity, resource.item_id) +end diff --git a/src/open_samus_returns_rando/files/templates/template_powerup_bmsad.json b/src/open_samus_returns_rando/files/templates/template_powerup_bmsad.json index 1daee830..a1ea2632 100644 --- a/src/open_samus_returns_rando/files/templates/template_powerup_bmsad.json +++ b/src/open_samus_returns_rando/files/templates/template_powerup_bmsad.json @@ -1,7 +1,7 @@ { "magic": "MSAD", "version": 2883585, - "name": "randomizer_powerup", + "name": "randomizerpowerup", "header": { "model_name": "actors/items/itemsphere/models/itemsphere.bcmdl", "unk_1": 0, @@ -108,7 +108,7 @@ "params": { "Param1": { "type": "s", - "value": "actors/items/randomizer_powerup/scripts/randomizer_powerup.lua" + "value": "actors/items/randomizerpowerup/scripts/randomizerpowerup.lua" }, "Param2": { "type": "s", diff --git a/src/open_samus_returns_rando/lua/custom/guilib.lua b/src/open_samus_returns_rando/lua/custom/guilib.lua index 6e681773..58a80e98 100644 --- a/src/open_samus_returns_rando/lua/custom/guilib.lua +++ b/src/open_samus_returns_rando/lua/custom/guilib.lua @@ -75,15 +75,15 @@ function GUILib.UpdateDNACounter(currentDNA, maxDNA) GUI.SetTextText(dna, tostring(currentDNA) .. " / " .. tostring(maxDNA)) dna:ForceRedraw() end +end - function GUILib.UpdateTotalDNAColor() - if Game.GetItemAmount(Game.GetPlayerName(), "ITEM_ADN") < 39 then - local dnaCounter = GUI.GetDisplayObject("IngameMenuRoot.IngameMenuComposition.LowerComposition.LowerInfoComposition.DNACounter") - GUI.SetProperties(dnaCounter, { - ColorR = "0.68000", - ColorG = "0.83000", - ColorB = "0.93000", - }) - end +function GUILib.UpdateTotalDNAColor() + if Game.GetItemAmount(Game.GetPlayerName(), "ITEM_ADN") < 39 then + local dnaCounter = GUI.GetDisplayObject("IngameMenuRoot.IngameMenuComposition.LowerComposition.LowerInfoComposition.DNACounter") + GUI.SetProperties(dnaCounter, { + ColorR = "0.68000", + ColorG = "0.83000", + ColorB = "0.93000", + }) end end \ No newline at end of file diff --git a/src/open_samus_returns_rando/lua/custom/scenario.lua b/src/open_samus_returns_rando/lua/custom/scenario.lua index 16f596bc..94d7a222 100644 --- a/src/open_samus_returns_rando/lua/custom/scenario.lua +++ b/src/open_samus_returns_rando/lua/custom/scenario.lua @@ -12,23 +12,23 @@ function Scenario.EnableHazarous(_ARG_0_, _ARG_1_) original_enable(_ARG_0_, _ARG_1_) end -function Scenario._UpdateProgressiveItemModels() - for name, actordef in pairs(Game.GetEntities()) do - local progressive_models = RandomizerPowerup.tProgressiveModels[actordef] - if progressive_models ~= nil then - for index, model in ipairs(progressive_models) do - if not RandomizerPowerup.HasItem(model.item) or #progressive_models == index then - local pickup = Game.GetEntity(name) - pickup.MODELUPDATER.sModelAlias = model.alias - break - end - end - end - end -end +-- function Scenario._UpdateProgressiveItemModels() +-- for name, actordef in pairs(Game.GetEntities()) do +-- local progressive_models = RandomizerPowerup.tProgressiveModels[actordef] +-- if progressive_models ~= nil then +-- for index, model in ipairs(progressive_models) do +-- if not RandomizerPowerup.HasItem(model.item) or #progressive_models == index then +-- local pickup = Game.GetEntity(name) +-- pickup.MODELUPDATER.sModelAlias = model.alias +-- break +-- end +-- end +-- end +-- end +-- end function Scenario.UpdateProgressiveItemModels() - Game.AddSF(0.2, "Scenario._UpdateProgressiveItemModels", "") + -- Game.AddSF(0.2, "Scenario._UpdateProgressiveItemModels", "") end function Scenario.OnSubAreaChange(old_subarea, old_actorgroup, new_subarea, new_actorgroup, disable_fade) @@ -75,6 +75,14 @@ function Scenario.InitScenario(_ARG_0_, _ARG_1_, _ARG_2_, _ARG_3_) Game.HUDIdleScreenLeave() Scenario.ShowText() end + -- if Scenario.CurrentScenarioID == "s000_surface" then + -- local next_number = (NextScenario % 17) + 1 + -- NextScenario = next_number + -- local next_scenario = ALL_SCENARIOS[next_number] + -- Game.AddSF(0.5, "Game.LoadScenario", "ssssi", "c10_samus", next_scenario, Init.sStartingActor, "samus", 1) + -- else + -- Game.AddSF(1.0, "Game.KillPlayer", "") + -- end end end diff --git a/src/open_samus_returns_rando/lua/pickups/randomizerbabyhatchling.lua b/src/open_samus_returns_rando/lua/pickups/randomizerbabyhatchling.lua new file mode 100644 index 00000000..e585156e --- /dev/null +++ b/src/open_samus_returns_rando/lua/pickups/randomizerbabyhatchling.lua @@ -0,0 +1,10 @@ +Game.ImportLibrary("actors/items/randomizerpowerup/scripts/randomizerpowerup.lc", false) +RandomizerBabyHatchling = RandomizerBabyHatchling or {} +function RandomizerBabyHatchling.main() +end + +function RandomizerBabyHatchling.OnPickedUp(progression) + RandomizerPowerup.OnPickedUp(progression) + Game.GetDefaultPlayer("Samus").BABYHATCHLINGCREATION:SpawnBaby() + Game.GetEntity("Baby Hatchling").vPos = Game.GetDefaultPlayer("Samus").vPos +end \ No newline at end of file diff --git a/src/open_samus_returns_rando/lua/pickups/randomizerenergyshield.lua b/src/open_samus_returns_rando/lua/pickups/randomizerenergyshield.lua new file mode 100644 index 00000000..27d88142 --- /dev/null +++ b/src/open_samus_returns_rando/lua/pickups/randomizerenergyshield.lua @@ -0,0 +1,8 @@ +RandomizerEnergyShield = RandomizerEnergyShield or {} +function RandomizerEnergyShield.main() +end + +function RandomizerEnergyShield.OnPickedUp(progression) + RandomizerPowerup.OnPickedUp(progression) + Player.SetAbilityUnlocked("EnergyShield", true) +end \ No newline at end of file diff --git a/src/open_samus_returns_rando/lua/pickups/randomizerenergytank.lua b/src/open_samus_returns_rando/lua/pickups/randomizerenergytank.lua new file mode 100644 index 00000000..461806c7 --- /dev/null +++ b/src/open_samus_returns_rando/lua/pickups/randomizerenergytank.lua @@ -0,0 +1,9 @@ +Game.ImportLibrary("actors/items/randomizerpowerup/scripts/randomizerpowerup.lc", false) +RandomizerEnergyTank = RandomizerEnergyTank or {} +function RandomizerEnergyTank.main() +end + +function RandomizerEnergyTank.OnPickedUp(progression) + RandomizerPowerup.OnPickedUp(progression) + RandomizerPowerup.IncreaseEnergy() +end diff --git a/src/open_samus_returns_rando/lua/pickups/randomizerenergywave.lua b/src/open_samus_returns_rando/lua/pickups/randomizerenergywave.lua new file mode 100644 index 00000000..797bf4b3 --- /dev/null +++ b/src/open_samus_returns_rando/lua/pickups/randomizerenergywave.lua @@ -0,0 +1,8 @@ +Game.ImportLibrary("actors/items/randomizerpowerup/scripts/randomizerpowerup.lc", false) +RandomizerEnergyWave = RandomizerEnergyWave or {} +function RandomizerEnergyWave.main() +end +function RandomizerEnergyWave.OnPickedUp(progression) + RandomizerPowerup.OnPickedUp(progression) + Player.SetAbilityUnlocked("EnergyWave", true) +end \ No newline at end of file diff --git a/src/open_samus_returns_rando/lua/pickups/randomizerphasedisplacement.lua b/src/open_samus_returns_rando/lua/pickups/randomizerphasedisplacement.lua new file mode 100644 index 00000000..59a4cb3a --- /dev/null +++ b/src/open_samus_returns_rando/lua/pickups/randomizerphasedisplacement.lua @@ -0,0 +1,9 @@ +Game.ImportLibrary("actors/items/randomizerpowerup/scripts/randomizerpowerup.lc", false) +RandomizerPhaseDisplacement = RandomizerPhaseDisplacement or {} +function RandomizerPhaseDisplacement.main() +end + +function RandomizerPhaseDisplacement.OnPickedUp(progression) + RandomizerPowerup.OnPickedUp(progression) + Player.SetAbilityUnlocked("PhaseDisplacement", true) +end diff --git a/src/open_samus_returns_rando/lua/pickups/randomizerpowerbomb.lua b/src/open_samus_returns_rando/lua/pickups/randomizerpowerbomb.lua new file mode 100644 index 00000000..ffbeeb67 --- /dev/null +++ b/src/open_samus_returns_rando/lua/pickups/randomizerpowerbomb.lua @@ -0,0 +1,18 @@ +Game.ImportLibrary("actors/items/randomizerpowerup/scripts/randomizerpowerup.lc", false) +RandomizerPowerBomb = RandomizerPowerBomb or {} +function RandomizerPowerBomb.main() +end + +function RandomizerPowerBomb.OnPickedUp(progression) + local locked_pbs = RandomizerPowerup.GetItemAmount("ITEM_POWER_BOMB_TANKS") + for _, outer in ipairs(progression) do + for _, inner in ipairs(outer) do + if inner.item_id == "ITEM_POWER_BOMB_TANKS" then + inner.item_id = "ITEM_WEAPON_POWER_BOMB_MAX" + inner.quantity = inner.quantity + locked_pbs + end + end + end + RandomizerPowerup.OnPickedUp(progression) + RandomizerPowerup.SetItemAmount("ITEM_POWER_BOMB_TANKS", 0) +end \ No newline at end of file diff --git a/src/open_samus_returns_rando/lua/pickups/randomizerpowerbombtank.lua b/src/open_samus_returns_rando/lua/pickups/randomizerpowerbombtank.lua new file mode 100644 index 00000000..26df3015 --- /dev/null +++ b/src/open_samus_returns_rando/lua/pickups/randomizerpowerbombtank.lua @@ -0,0 +1,21 @@ +Game.ImportLibrary("actors/items/randomizerpowerup/scripts/randomizerpowerup.lc", false) +RandomizerPowerBombTank = RandomizerPowerBombTank or {} +function RandomizerPowerBombTank.main() +end + +function RandomizerPowerBombTank.OnPickedUp(progression) + -- if we have main item use power bomb max else use locked power bombs + local new_item_id = "ITEM_POWER_BOMB_TANKS" + local is_main_unlocked = RandomizerPowerup.GetItemAmount("ITEM_WEAPON_POWER_BOMB") > 0 + if is_main_unlocked then + new_item_id = "ITEM_WEAPON_POWER_BOMB_MAX" + end + + -- grant locked pbs 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 diff --git a/src/open_samus_returns_rando/lua/pickups/randomizerreservetanka.lua b/src/open_samus_returns_rando/lua/pickups/randomizerreservetanka.lua new file mode 100644 index 00000000..6b341f31 --- /dev/null +++ b/src/open_samus_returns_rando/lua/pickups/randomizerreservetanka.lua @@ -0,0 +1,12 @@ +Game.ImportLibrary("actors/items/randomizerpowerup/scripts/randomizerpowerup.lc", false) +RandomizerReserveTankA = RandomizerReserveTankA or {} +function RandomizerReserveTankA.main() +end + +function RandomizerReserveTankA.OnPickedUp(progression) + RandomizerPowerup.OnPickedUp(progression) + Blackboard.SetProp("GAME", "ITEM_RESERVE_TANK_SPECIAL_ENERGY_ACTIVE", "b", true) + Blackboard.SetProp("GAME", "ITEM_RESERVE_TANK_SPECIAL_ENERGY_FULL", "b", true) + Game.AddSF(0.0, "Game.HUDIdleScreenGo", "") + Game.AddSF(0.5, "Game.HUDIdleScreenLeave", "") +end \ No newline at end of file diff --git a/src/open_samus_returns_rando/lua/pickups/randomizerreservetanke.lua b/src/open_samus_returns_rando/lua/pickups/randomizerreservetanke.lua new file mode 100644 index 00000000..799422d4 --- /dev/null +++ b/src/open_samus_returns_rando/lua/pickups/randomizerreservetanke.lua @@ -0,0 +1,12 @@ +Game.ImportLibrary("actors/items/randomizerpowerup/scripts/randomizerpowerup.lc", false) +RandomizerReserveTankE = RandomizerReserveTankE or {} +function RandomizerReserveTankE.main() +end + +function RandomizerReserveTankE.OnPickedUp(progression) + RandomizerPowerup.OnPickedUp(progression) + Blackboard.SetProp("GAME", "ITEM_RESERVE_TANK_LIFE_ACTIVE", "b", true) + Blackboard.SetProp("GAME", "ITEM_RESERVE_TANK_LIFE_FULL", "b", true) + Game.AddSF(0.0, "Game.HUDIdleScreenGo", "") + Game.AddSF(0.5, "Game.HUDIdleScreenLeave", "") +end diff --git a/src/open_samus_returns_rando/lua/pickups/randomizerreservetankm.lua b/src/open_samus_returns_rando/lua/pickups/randomizerreservetankm.lua new file mode 100644 index 00000000..f050647c --- /dev/null +++ b/src/open_samus_returns_rando/lua/pickups/randomizerreservetankm.lua @@ -0,0 +1,12 @@ +Game.ImportLibrary("actors/items/randomizerpowerup/scripts/randomizerpowerup.lc", false) +RandomizerReserveTankM = RandomizerReserveTankM or {} +function RandomizerReserveTankM.main() +end + +function RandomizerReserveTankM.OnPickedUp(progression) + RandomizerPowerup.OnPickedUp(progression) + Blackboard.SetProp("GAME", "ITEM_RESERVE_TANK_MISSILE_ACTIVE", "b", true) + Blackboard.SetProp("GAME", "ITEM_RESERVE_TANK_MISSILE_FULL", "b", true) + Game.AddSF(0.0, "Game.HUDIdleScreenGo", "") + Game.AddSF(0.5, "Game.HUDIdleScreenLeave", "") +end \ No newline at end of file diff --git a/src/open_samus_returns_rando/lua/pickups/randomizerscanningpulse.lua b/src/open_samus_returns_rando/lua/pickups/randomizerscanningpulse.lua new file mode 100644 index 00000000..f281e2b5 --- /dev/null +++ b/src/open_samus_returns_rando/lua/pickups/randomizerscanningpulse.lua @@ -0,0 +1,10 @@ +Game.ImportLibrary("actors/items/randomizerpowerup/scripts/randomizerpowerup.lc", false) +RandomizerScanningPulse = RandomizerScanningPulse or {} +function RandomizerScanningPulse.main() +end + +function RandomizerScanningPulse.OnPickedUp(progression) + RandomizerPowerup.OnPickedUp(progression) + Player.SetAbilityUnlocked("ScanningPulse", true) +end + diff --git a/src/open_samus_returns_rando/lua/pickups/randomizersuit.lua b/src/open_samus_returns_rando/lua/pickups/randomizersuit.lua new file mode 100644 index 00000000..04b99d20 --- /dev/null +++ b/src/open_samus_returns_rando/lua/pickups/randomizersuit.lua @@ -0,0 +1,40 @@ +Game.ImportLibrary("actors/items/randomizerpowerup/scripts/randomizerpowerup.lc", false) +RandomizerSuit = RandomizerSuit or {} +function RandomizerSuit.main() +end + +function RandomizerSuit.DisableLiquids() + if Game.GetPlayer().MODELUPDATER.sModelAlias ~= "Gravity" then + if Scenario.CurrentScenarioID == "s010_area1" then + Game.GetEntity("Lava_Trigger_001").TRIGGER:DisableTrigger() + elseif Scenario.CurrentScenarioID == "s050_area5" then + Game.GetEntity("TG_Water_006").TRIGGER:DisableTrigger() + Game.GetEntity("TG_Water_009").TRIGGER:DisableTrigger() + elseif Scenario.CurrentScenarioID == "s067_area6c" then + Game.GetEntity("TG_SP_Water_002").TRIGGER:DisableTrigger() + end + end +end + +function RandomizerSuit.EnableLiquids() + if Scenario.CurrentScenarioID == "s010_area1" then + Game.GetEntity("Lava_Trigger_001").TRIGGER:EnableTrigger() + elseif Scenario.CurrentScenarioID == "s050_area5" then + Game.GetEntity("TG_Water_006").TRIGGER:EnableTrigger() + Game.GetEntity("TG_Water_009").TRIGGER:EnableTrigger() + elseif Scenario.CurrentScenarioID == "s067_area6c" then + Game.GetEntity("TG_SP_Water_002").TRIGGER:EnableTrigger() + end +end + +function RandomizerSuit.OnPickedUp(progression) + RandomizerSuit.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) + RandomizerSuit.EnableLiquids() +end \ No newline at end of file diff --git a/src/open_samus_returns_rando/lua/pickups/randomizersupermissile.lua b/src/open_samus_returns_rando/lua/pickups/randomizersupermissile.lua new file mode 100644 index 00000000..562b1d4d --- /dev/null +++ b/src/open_samus_returns_rando/lua/pickups/randomizersupermissile.lua @@ -0,0 +1,18 @@ +Game.ImportLibrary("actors/items/randomizerpowerup/scripts/randomizerpowerup.lc", false) +RandomizerSuperMissile = RandomizerSuperMissile or {} +function RandomizerSuperMissile.main() +end + +function RandomizerSuperMissile.OnPickedUp(progression) + local locked_supers = RandomizerPowerup.GetItemAmount("ITEM_SUPER_MISSILE_TANKS") + for _, outer in ipairs(progression) do + for _, inner in ipairs(outer) do + if inner.item_id == "ITEM_SUPER_MISSILE_TANKS" then + inner.item_id = "ITEM_WEAPON_SUPER_MISSILE_MAX" + inner.quantity = inner.quantity + locked_supers + end + end + end + RandomizerPowerup.OnPickedUp(progression) + RandomizerPowerup.SetItemAmount("ITEM_SUPER_MISSILE_TANKS", 0) +end \ No newline at end of file diff --git a/src/open_samus_returns_rando/lua/pickups/randomizersupermissiletank.lua b/src/open_samus_returns_rando/lua/pickups/randomizersupermissiletank.lua new file mode 100644 index 00000000..ad79d550 --- /dev/null +++ b/src/open_samus_returns_rando/lua/pickups/randomizersupermissiletank.lua @@ -0,0 +1,20 @@ +Game.ImportLibrary("actors/items/randomizerpowerup/scripts/randomizerpowerup.lc", false) +RandomizerSuperMissileTank = RandomizerSuperMissileTank or {} +function RandomizerSuperMissileTank.main() +end + +function RandomizerSuperMissileTank.OnPickedUp(progression) + -- if we have main item use super missile max else use locked supers + local new_item_id = "ITEM_SUPER_MISSILE_TANKS" + local is_main_unlocked = RandomizerPowerup.GetItemAmount("ITEM_WEAPON_SUPER_MISSILE") > 0 + if is_main_unlocked then + new_item_id = "ITEM_WEAPON_SUPER_MISSILE_MAX" + end + -- 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 diff --git a/src/open_samus_returns_rando/lua_editor.py b/src/open_samus_returns_rando/lua_editor.py index 1ee4a4ea..b54936b5 100644 --- a/src/open_samus_returns_rando/lua_editor.py +++ b/src/open_samus_returns_rando/lua_editor.py @@ -1,16 +1,12 @@ import itertools from open_samus_returns_rando.constants import ALL_SCENARIOS -from open_samus_returns_rando.files import files_path, templates_path +from open_samus_returns_rando.files import files_path from open_samus_returns_rando.misc_patches import lua_util from open_samus_returns_rando.misc_patches.text_patches import patch_text from open_samus_returns_rando.patcher_editor import PatcherEditor, path_for_level -def _read_powerup_lua() -> bytes: - return templates_path().joinpath("randomizer_powerup.lua").read_bytes() - - def _read_level_lua(level_id: str) -> bytes: return files_path().joinpath("levels", f"{level_id}.lc").read_bytes() @@ -64,6 +60,48 @@ def _read_level_lua(level_id: str) -> bytes: "s110_surfaceb": "s00", } +class ScriptClass: + def __init__( + self, + class_name: str, + actor_def_id: str, + lua_content: str, + lua_parent: str, + ): + self.class_name = class_name + self.actor_def_name = actor_def_id + self.lua_content = lua_content + self.lua_parent = lua_parent + + def get_lua_file_name(self) -> str: + actor_def_lower = self.actor_def_name.lower() + return f"actors/items/{actor_def_lower}/scripts/{actor_def_lower}.lc" + + def get_lua_parent_file_name(self) -> str: + parent_lower = self.lua_parent.lower() + return f"actors/items/{parent_lower}/scripts/{parent_lower}.lc" + + def get_bmsad_path(self) -> str: + return f"actors/items/{self.actor_def_name}/charclasses/{self.actor_def_name}.bmsad" + + def ensure_files(self, editor: PatcherEditor, pkgs_for_level: set[str]) -> None: + # ensure file itself + lua_file_name = self.get_lua_file_name() + if editor.does_asset_exists(lua_file_name): + for pkg in pkgs_for_level: + editor.ensure_present(pkg, lua_file_name) + else: + editor.add_new_asset(lua_file_name, self.lua_content.encode("utf-8"), pkgs_for_level) + + # ensure parent file + parent_file_name = self.get_lua_parent_file_name() + if editor.does_asset_exists(parent_file_name): + for pkg in pkgs_for_level: + editor.ensure_present(pkg, parent_file_name) + else: + parent_content = files_path().joinpath("pickups", f"{self.lua_parent.lower()}.lc").read_bytes() + editor.add_new_asset(parent_file_name, parent_content, pkgs_for_level) + class LuaEditor: def __init__(self): @@ -71,8 +109,8 @@ def __init__(self): self._metroid_dict = {} self._dna_count_dict = {} self._hint_dict = {} - self._powerup_script = _read_powerup_lua() self._custom_level_scripts: dict[str, dict] = self._read_levels() + self._metroid_imports = [] def _read_levels(self) -> dict[str, dict]: return { @@ -83,13 +121,14 @@ 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, actordef_name: str = "") -> str: + def create_script_class(self, pickup: dict, actordef_id: str = "") -> ScriptClass: pickup_resources = pickup["resources"] first_item_id = pickup_resources[0][0]["item_id"] parent = self.get_parent_for(first_item_id) + model_array = pickup.get("model", None) - if actordef_name and len(pickup["model"]) > 1: - self.add_progressive_models(pickup, actordef_name) + if actordef_id and model_array and len(model_array) > 1: + self.add_progressive_models(pickup, actordef_id) hashable_progression = "_".join([ f'{pickup["item_id"]}_{pickup["quantity"]}' @@ -116,22 +155,22 @@ def get_script_class(self, pickup: dict, actordef_name: str = "") -> str: sound = "streams/music/k_matad_jinchozo.wav" else: sound = SPECIFIC_SOUNDS.get(first_item_id, "streams/music/sphere_jingle_placeholder.wav") + + parent_file_name = f"actors/items/{parent.lower()}/scripts/{parent.lower()}.lc" replacement = { "name": class_name, "resources": resources, "parent": parent, + "parent_lua": lua_util.wrap_string(parent_file_name), "caption": lua_util.wrap_string(pickup["caption"].replace("\n", "\\n")), "sound": lua_util.wrap_string(sound), } - self.add_item_class(replacement) - self._item_classes[hashable_progression] = class_name + lua_content = lua_util.replace_lua_template("randomizer_item_template.lua", replacement) + new_script_class = ScriptClass(class_name, actordef_id, lua_content, parent) + self._item_classes[hashable_progression] = new_script_class - return class_name - - def add_item_class(self, replacement): - new_class = lua_util.replace_lua_template("randomizer_item_template.lua", replacement) # noqa: F841 - # self._powerup_script += new_class.encode("utf-8") + return new_script_class def add_progressive_models(self, pickup: dict, actordef_name: str): progressive_models = [ @@ -149,6 +188,7 @@ def add_progressive_models(self, pickup: dict, actordef_name: str): "progressive_models": progressive_models, } + # TODO: Fix progressives models = lua_util.replace_lua_template("progressive_model_template.lua", replacement) # noqa: F841 # self._powerup_script += models.encode("utf-8") @@ -238,9 +278,10 @@ def save_modifications(self, editor: PatcherEditor, configuration: dict): ) # replace ensured scripts with the final code - editor.replace_asset("actors/items/randomizer_powerup/scripts/randomizer_powerup.lc", self._powerup_script) - + # TODO: Doesn't work :/ final_metroid_script = lua_util.replace_lua_template("metroid_template.lua", {"mapping": self._metroid_dict}) + imports_in_metroid = [f'Game.ImportLibrary("{a_import}", false)' for a_import in self._metroid_imports] + final_metroid_script = "\n".join(imports_in_metroid) + "\n" + final_metroid_script editor.replace_asset("actors/scripts/metroid.lc", final_metroid_script.encode("utf-8")) final_chozo_seal_script = lua_util.replace_lua_template("chozoseal_template.lua", {"mapping": self._hint_dict}) @@ -250,13 +291,14 @@ def save_modifications(self, editor: PatcherEditor, configuration: dict): for scenario, script in self._custom_level_scripts.items(): editor.replace_asset(path_for_level(scenario) + ".lc", script["script"]) - def add_metroid_pickup(self, metroid_callback: dict, lua_class: str) -> None: + def add_metroid_pickup(self, metroid_callback: dict, script_class: ScriptClass) -> None: scenario = metroid_callback["scenario"] spawngroup = metroid_callback["spawngroup"] if scenario not in self._metroid_dict: self._metroid_dict[scenario] = {} scenario_list = self._metroid_dict[scenario] - scenario_list[spawngroup] = lua_class + scenario_list[spawngroup] = script_class.class_name + self._metroid_imports.append(script_class.get_lua_file_name()) def add_hint(self, hint: dict) -> None: actor_ref = hint["accesspoint_actor"] diff --git a/src/open_samus_returns_rando/pickups/pickup.py b/src/open_samus_returns_rando/pickups/pickup.py index 1344e768..5f45ccae 100644 --- a/src/open_samus_returns_rando/pickups/pickup.py +++ b/src/open_samus_returns_rando/pickups/pickup.py @@ -8,7 +8,7 @@ from open_samus_returns_rando.constants import get_package_name from open_samus_returns_rando.files import templates_path from open_samus_returns_rando.logger import LOG -from open_samus_returns_rando.lua_editor import LuaEditor +from open_samus_returns_rando.lua_editor import LuaEditor, ScriptClass from open_samus_returns_rando.patcher_editor import PatcherEditor, path_for_level from open_samus_returns_rando.pickups.model_data import get_data @@ -92,9 +92,9 @@ def get_scenario(self): raise NotImplementedError class ActorPickup(BasePickup): - _bmsad_dict = {} + _bmsad_dict: dict[str, tuple[str, ScriptClass]] = {} - def patch_item_pickup(self, bmsad: dict) -> dict: + def patch_item_pickup(self, bmsad: dict) -> tuple[dict, ScriptClass]: pickable: dict = bmsad["components"]["PICKABLE"] script: dict = bmsad["components"]["SCRIPT"] @@ -102,14 +102,15 @@ def patch_item_pickup(self, bmsad: dict) -> dict: 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_class = self.lua_editor.create_script_class( + self.pickup, actordef_id=bmsad["name"] ) - return bmsad - def add_new_bmsad(self, editor: PatcherEditor, actordef_id: str, pkgs_for_level: set[str]): + script["functions"][0]["params"]["Param1"]["value"] = script_class.get_lua_file_name() + script["functions"][0]["params"]["Param2"]["value"] = script_class.class_name + return bmsad, script_class + + def add_new_bmsad(self, editor: PatcherEditor, actordef_id: str, pkgs_for_level: set[str]) -> ScriptClass: template_bmsad = _read_template_powerup() new_template = copy.deepcopy(template_bmsad) new_template["name"] = actordef_id @@ -124,10 +125,11 @@ def add_new_bmsad(self, editor: PatcherEditor, actordef_id: str, pkgs_for_level: pickable["functions"][0]["params"]["Param7"]["value"] = self.pickup["caption"] # Update given item - new_template = self.patch_item_pickup(new_template) + new_template, script_class = self.patch_item_pickup(new_template) - new_path = f"actors/items/{actordef_id}/charclasses/{actordef_id}.bmsad" + new_path = script_class.get_bmsad_path() editor.add_new_asset(new_path, Bmsad(new_template, editor.target_game), in_pkgs=pkgs_for_level) + return script_class def patch_model(self, model_names: list[str], bmsad: dict) -> None: @@ -135,7 +137,7 @@ def patch_model(self, model_names: list[str], bmsad: dict) -> None: item_id: str = self.pickup["resources"][0][0]["item_id"] model_name = model_names[0] y_offset = MODEL_TO_OFFSET.get(model_name, 20) - if len(model_names) == 1: + if True or len(model_names) == 1: model_data = get_data(model_name) action_sets: dict = bmsad["action_sets"][0]["animations"][0] bmsad["header"]["model_name"] = model_data.bcmdl_path @@ -218,27 +220,27 @@ def patch_model(self, model_names: list[str], bmsad: dict) -> None: else: bmsad["components"].pop("FX") bmsad["sound_fx"] = ListContainer([]) - else: - bmsad["components"].pop("FX") - MODELUPDATER["type"] = "CMultiModelUpdaterComponent" - # no idea what this is - MODELUPDATER["unk_1"] = 2500 - MODELUPDATER["unk_2"] = 0.0 - - for idx, model_name in enumerate(model_names): - model_data = get_data(model_name) - if idx != 0: - MODELUPDATER["functions"].append(copy.deepcopy(MODELUPDATER["functions"][0])) - MODELUPDATER["functions"][idx]["name"] = "AddModel" - MODELUPDATER["functions"][idx]["unk1"] = True - MODELUPDATER["functions"][idx]["unk2"] = False - # this is just the alias which needs to be used in the update functions of lua - # we are simply using the model name as alias - MODELUPDATER["functions"][idx]["params"]["Param1"]["value"] = model_name - MODELUPDATER["functions"][idx]["params"]["Param2"] = copy.deepcopy( - MODELUPDATER["functions"][idx]["params"]["Param1"] - ) - MODELUPDATER["functions"][idx]["params"]["Param2"]["value"] = model_data.bcmdl_path + # else: + # bmsad["components"].pop("FX") + # MODELUPDATER["type"] = "CMultiModelUpdaterComponent" + # # no idea what this is + # MODELUPDATER["unk_1"] = 2500 + # MODELUPDATER["unk_2"] = 0.0 + + # for idx, model_name in enumerate(model_names): + # model_data = get_data(model_name) + # if idx != 0: + # MODELUPDATER["functions"].append(copy.deepcopy(MODELUPDATER["functions"][0])) + # MODELUPDATER["functions"][idx]["name"] = "AddModel" + # MODELUPDATER["functions"][idx]["unk1"] = True + # MODELUPDATER["functions"][idx]["unk2"] = False + # # this is just the alias which needs to be used in the update functions of lua + # # we are simply using the model name as alias + # MODELUPDATER["functions"][idx]["params"]["Param1"]["value"] = model_name + # MODELUPDATER["functions"][idx]["params"]["Param2"] = copy.deepcopy( + # MODELUPDATER["functions"][idx]["params"]["Param1"] + # ) + # MODELUPDATER["functions"][idx]["params"]["Param2"]["value"] = model_data.bcmdl_path # offset for single and multimodels if model_name not in TANK_MODELS: @@ -261,13 +263,15 @@ def patch(self, editor: PatcherEditor): item_id = self.pickup["resources"][0][0]["item_id"] cached_bmsad = self._bmsad_dict.get(item_id, None) if cached_bmsad is None: - actordef_id = f"randomizer_powerup_{self.pickup_id}" - self._bmsad_dict[item_id] = actordef_id - self.add_new_bmsad(editor, actordef_id, pkgs_for_level) + actordef_id = f"randomizerpowerup{self.pickup_id}" + script_class = self.add_new_bmsad(editor, actordef_id, pkgs_for_level) + script_class.ensure_files(editor, pkgs_for_level) + self._bmsad_dict[item_id] = (actordef_id, script_class) else: - actordef_id = cached_bmsad - path = f"actors/items/{actordef_id}/charclasses/{actordef_id}.bmsad" - editor.ensure_present_in_scenario(scenario_name, path) + actordef_id = cached_bmsad[0] + script_class = cached_bmsad[1] + bmsad_path = script_class.get_bmsad_path() + editor.ensure_present_in_scenario(scenario_name, bmsad_path) actor.type = actordef_id @@ -281,11 +285,11 @@ def patch(self, editor: PatcherEditor): mirrored_actor = next((layer[actor_name] for layer in surface_b.raw.actors if actor_name in layer), None) assert mirrored_actor is not None mirrored_actor.type = actordef_id - # TODO: Code clean up - path = f"actors/items/{actordef_id}/charclasses/{actordef_id}.bmsad" + path = script_class.get_bmsad_path() editor.ensure_present_in_scenario(surfaceb_name, path) pkgs_for_level.update(set(editor.find_pkgs(path_for_level(surfaceb_name) + ".bmsld"))) + script_class.ensure_files(editor, pkgs_for_level) # Dependencies for level_pkg in pkgs_for_level: @@ -300,8 +304,11 @@ def get_scenario(self): class MetroidPickup(BasePickup): def patch(self, editor: PatcherEditor): - lua_class = self.lua_editor.get_script_class(self.pickup) - self.lua_editor.add_metroid_pickup(self.pickup["metroid_callback"], lua_class) + # TODO: This does not work and needs to be revisited + script_class = self.lua_editor.create_script_class(self.pickup, f"metroid_{self.pickup_id}") + pkg = editor.get_level_pkgs(self.get_scenario()) + script_class.ensure_files(editor, pkg) + self.lua_editor.add_metroid_pickup(self.pickup["metroid_callback"], script_class) def get_scenario(self): return self.pickup["metroid_callback"]["scenario"] @@ -333,7 +340,11 @@ def count_dna(lua_scripts: LuaEditor, pickup_object: BasePickup): def patch_pickups(editor: PatcherEditor, lua_scripts: LuaEditor, pickups_config: list[dict], configuration: dict): ActorPickup._bmsad_dict = {} - editor.add_new_asset("actors/items/randomizer_powerup/scripts/randomizer_powerup.lc", b'', []) + editor.add_new_asset( + "actors/items/randomizerpowerup/scripts/randomizerpowerup.lc", + templates_path().joinpath("randomizerpowerup.lua").read_bytes(), + editor.get_all_level_pkgs() + ) editor.add_new_asset("actors/scripts/metroid.lc", b'', []) ensure_base_models(editor)