diff --git a/src/open_samus_returns_rando/files/guilib.lua b/src/open_samus_returns_rando/files/guilib.lua index babedd6..598b0ac 100644 --- a/src/open_samus_returns_rando/files/guilib.lua +++ b/src/open_samus_returns_rando/files/guilib.lua @@ -1,78 +1,81 @@ -GUILib = GUILib or {} +if GUILib == nil then -function GUILib.AddDNACounter() - local randoUI = GUI.GetDisplayObject("IngameMenuRoot.IngameMenuComposition.LowerComposition.LowerInfoComposition.DNAMechIconRando") - if randoUI ~= nil then - return + GUILib = GUILib or {} + + function GUILib.AddDNACounter() + local randoUI = GUI.GetDisplayObject("IngameMenuRoot.IngameMenuComposition.LowerComposition.LowerInfoComposition.DNAMechIconRando") + if randoUI ~= nil then + return + end + + local lowerInfo = GUI.GetDisplayObject("IngameMenuRoot.IngameMenuComposition.LowerComposition.LowerInfoComposition") + lowerInfo:AddChild((GUI.CreateDisplayObjectEx("DNAMechIconRando", "CSprite", { + X = "0.17188", + Y = "0.02500", + SizeX = "0.06562", + SizeY = "0.09166", + ScaleX = "1.00000", + ScaleY = "1.00000", + Angle = "0.00000", + FlipX = false, + FlipY = false, + Enabled = true, + Visible = true, + SkinItemType = "", + Autosize = false, + SpriteSheetItem = "IconL_MetroidDNAData", + BlendMode = "AlphaBlend", + USelMode = "Scale", + VSelMode = "Scale" + }))) + lowerInfo:AddChild((GUI.CreateDisplayObjectEx("DNAMechCounterRando", "CText", { + X = "0.24688", + Y = "0.02500", + SizeX = "0.12499", + SizeY = "0.05833", + ScaleX = "1.00000", + ScaleY = "1.00000", + Angle = "0.00000", + FlipX = false, + FlipY = false, + ColorR = "0.68000", + ColorG = "0.83000", + ColorB = "0.93000", + ColorA = "1.00000", + Enabled = true, + Visible = true, + SkinItemType = "", + Text = "10 / 10", + Font = "digital_hefty", + TextAlignment = "Left", + Autosize = true, + Outline = true, + EmbeddedSpritesSuffix = "", + BlinkColorR = "1.00000", + BlinkColorG = "1.00000", + BlinkColorB = "1.00000", + BlinkAlpha = "1.00000", + Blink = "-1.00000" + }))) + local dnaCounterVanilla = GUI.GetDisplayObject("IngameMenuRoot.IngameMenuComposition.LowerComposition.LowerInfoComposition.DNAMechCounter") + local dnaIconVanilla = GUI.GetDisplayObject("IngameMenuRoot.IngameMenuComposition.LowerComposition.LowerInfoComposition.DNAMechIcon") + GUI.SetProperties(dnaCounterVanilla, { + Enabled = false, + Visible = false + }) + GUI.SetProperties(dnaIconVanilla, { + Enabled = false, + Visible = false + }) end - - local lowerInfo = GUI.GetDisplayObject("IngameMenuRoot.IngameMenuComposition.LowerComposition.LowerInfoComposition") - lowerInfo:AddChild((GUI.CreateDisplayObjectEx("DNAMechIconRando", "CSprite", { - X = "0.17188", - Y = "0.02500", - SizeX = "0.06562", - SizeY = "0.09166", - ScaleX = "1.00000", - ScaleY = "1.00000", - Angle = "0.00000", - FlipX = false, - FlipY = false, - Enabled = true, - Visible = true, - SkinItemType = "", - Autosize = false, - SpriteSheetItem = "IconL_MetroidDNAData", - BlendMode = "AlphaBlend", - USelMode = "Scale", - VSelMode = "Scale" - }))) - lowerInfo:AddChild((GUI.CreateDisplayObjectEx("DNAMechCounterRando", "CText", { - X = "0.24688", - Y = "0.02500", - SizeX = "0.12499", - SizeY = "0.05833", - ScaleX = "1.00000", - ScaleY = "1.00000", - Angle = "0.00000", - FlipX = false, - FlipY = false, - ColorR = "0.68000", - ColorG = "0.83000", - ColorB = "0.93000", - ColorA = "1.00000", - Enabled = true, - Visible = true, - SkinItemType = "", - Text = "10 / 10", - Font = "digital_hefty", - TextAlignment = "Left", - Autosize = true, - Outline = true, - EmbeddedSpritesSuffix = "", - BlinkColorR = "1.00000", - BlinkColorG = "1.00000", - BlinkColorB = "1.00000", - BlinkAlpha = "1.00000", - Blink = "-1.00000" - }))) - local dnaCounterVanilla = GUI.GetDisplayObject("IngameMenuRoot.IngameMenuComposition.LowerComposition.LowerInfoComposition.DNAMechCounter") - local dnaIconVanilla = GUI.GetDisplayObject("IngameMenuRoot.IngameMenuComposition.LowerComposition.LowerInfoComposition.DNAMechIcon") - GUI.SetProperties(dnaCounterVanilla, { - Enabled = false, - Visible = false - }) - GUI.SetProperties(dnaIconVanilla, { - Enabled = false, - Visible = false - }) -end -function GUILib.UpdateDNACounter(currentDNA, maxDNA) - local dna = GUI.GetDisplayObject("IngameMenuRoot.IngameMenuComposition.LowerComposition.LowerInfoComposition.DNAMechCounterRando") - if dna ~= nil then - GUI.SetTextText(dna, tostring(currentDNA) .. " / " .. tostring(maxDNA)) - dna:ForceRedraw() + function GUILib.UpdateDNACounter(currentDNA, maxDNA) + local dna = GUI.GetDisplayObject("IngameMenuRoot.IngameMenuComposition.LowerComposition.LowerInfoComposition.DNAMechCounterRando") + if dna ~= nil then + GUI.SetTextText(dna, tostring(currentDNA) .. " / " .. tostring(maxDNA)) + dna:ForceRedraw() + end end end \ No newline at end of file diff --git a/src/open_samus_returns_rando/files/randomizer_powerup.lua b/src/open_samus_returns_rando/files/randomizer_powerup.lua deleted file mode 100644 index 471eb5b..0000000 --- a/src/open_samus_returns_rando/files/randomizer_powerup.lua +++ /dev/null @@ -1,328 +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.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) - 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 diff --git a/src/open_samus_returns_rando/files/templates/randomizer_powerup.lua b/src/open_samus_returns_rando/files/templates/randomizer_powerup.lua new file mode 100644 index 0000000..2a93343 --- /dev/null +++ b/src/open_samus_returns_rando/files/templates/randomizer_powerup.lua @@ -0,0 +1,333 @@ +if RandomizerPowerup == nil then + + 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.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) + 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") +end \ No newline at end of file diff --git a/src/open_samus_returns_rando/lua_editor.py b/src/open_samus_returns_rando/lua_editor.py index 4b0de49..17c90b4 100644 --- a/src/open_samus_returns_rando/lua_editor.py +++ b/src/open_samus_returns_rando/lua_editor.py @@ -7,10 +7,6 @@ from open_samus_returns_rando.patcher_editor import PatcherEditor, path_for_level -def _read_powerup_lua() -> bytes: - return files_path().joinpath("randomizer_powerup.lua").read_bytes() - - def _read_level_lua(level_id: str) -> str: return files_path().joinpath("levels", f"{level_id}.lua").read_text() @@ -72,7 +68,7 @@ def __init__(self): self._metroid_dict = {} self._dna_count_dict = {} self._hint_dict = {} - self._powerup_script = _read_powerup_lua() + self._powerup_script_custom = "" self._custom_level_scripts: dict[str, dict] = self._read_levels() def _read_levels(self) -> dict[str, dict]: @@ -132,7 +128,7 @@ def get_script_class(self, pickup: dict, actordef_name: str = "") -> str: 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") + self._powerup_script_custom += new_class def add_progressive_models(self, pickup: dict, actordef_name: str): progressive_models = [ @@ -151,7 +147,7 @@ def add_progressive_models(self, pickup: dict, actordef_name: str): } models = lua_util.replace_lua_template("progressive_model_template.lua", replacement) - self._powerup_script += models.encode("utf-8") + self._powerup_script_custom += models def _create_custom_init(self, editor: PatcherEditor, configuration: dict) -> str: inventory: dict[str, int] = configuration["starting_items"] @@ -239,7 +235,16 @@ 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) + replacement = { + "custom_code": self._powerup_script_custom, + } + powerup_script = lua_util.replace_lua_template("randomizer_powerup.lua", replacement) + + + editor.replace_asset( + "actors/items/randomizer_powerup/scripts/randomizer_powerup.lc", + powerup_script.encode("utf-8") + ) final_metroid_script = lua_util.replace_lua_template("metroid_template.lua", {"mapping": self._metroid_dict}) editor.replace_asset("actors/scripts/metroid.lc", final_metroid_script.encode("utf-8"))