Skip to content

Commit

Permalink
Merge pull request #248 from randovania/feature/split-weapons
Browse files Browse the repository at this point in the history
split weapons
  • Loading branch information
duncathan authored Aug 11, 2023
2 parents 8897fc3 + e351809 commit 2fa4b9c
Show file tree
Hide file tree
Showing 6 changed files with 726 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/open_dread_rando/dread_patcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from open_dread_rando.patcher_editor import PatcherEditor
from open_dread_rando.pickups.lua_editor import LuaEditor
from open_dread_rando.pickups.pickup import pickup_object_for
from open_dread_rando.pickups.split_pickups import patch_split_pickups, update_starting_inventory_split_pickups
from open_dread_rando.specific_patches import game_patches
from open_dread_rando.specific_patches.environmental_damage import apply_constant_damage
from open_dread_rando.specific_patches.objective import apply_objective_patches
Expand Down Expand Up @@ -56,6 +57,13 @@ def create_custom_init(editor: PatcherEditor, configuration: dict) -> str:
shards = inventory.pop("ITEM_LIFE_SHARDS")
max_life += shards * energy_per_part

inventory.update({
# TODO: expose shuffling these
"ITEM_WEAPON_POWER_BEAM": 1,
"ITEM_WEAPON_MISSILE_LAUNCHER": 1,
})
inventory = update_starting_inventory_split_pickups(inventory)

# Game doesn't like to start if some fields are missing, like ITEM_WEAPON_POWER_BOMB_MAX
final_inventory = {
"ITEM_MAX_LIFE": max_life,
Expand Down Expand Up @@ -117,6 +125,8 @@ def create_collision_camera_table(editor: PatcherEditor, configuration: dict):
editor.add_new_asset("system/scripts/cc_to_room_name.lc", file, ["packs/system/system.pkg"])

def patch_pickups(editor: PatcherEditor, lua_scripts: LuaEditor, pickups_config: list[dict], configuration: dict):
patch_split_pickups(editor)

# add to the TOC
editor.add_new_asset("actors/items/randomizer_powerup/scripts/randomizer_powerup.lc", b'', [])

Expand Down
29 changes: 29 additions & 0 deletions src/open_dread_rando/files/custom_scenario.lua
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,32 @@ function Scenario.UpdateProgressiveItemModels()
Game.AddSF(0.1, "Scenario._UpdateProgressiveItemModels", "")
end

Scenario._BlastShieldTypes = {
doorshieldsupermissile = {
item = "ITEM_WEAPON_SUPER_MISSILE",
damage = {"SUPER_MISSILE", "ICE_MISSILE"},
},
door_shield_plasma = {
item = "ITEM_WEAPON_PLASMA_BEAM",
damage = {"PLASMA_BEAM"}
}
}
function Scenario._UpdateBlastShields()
for name, actordef in pairs(Game.GetEntities()) do
shield_type = Scenario._BlastShieldTypes[actordef]
if shield_type ~= nil and RandomizerPowerup.HasItem(shield_type.item) then
local shield = Game.GetActor(name)
for _, damage in ipairs(shield_type.damage) do
shield.LIFE:AddDamageSource(damage)
end
end
end
end

function Scenario.UpdateBlastShields()
Game.AddSF(0.1, "Scenario._UpdateBlastShields", "")
end

local original_onload = Scenario.OnLoadScenarioFinished
function Scenario.OnLoadScenarioFinished()
original_onload()
Expand Down Expand Up @@ -257,6 +283,7 @@ function Scenario.OnLoadScenarioFinished()
if Scenario.VisitAllTeleportScenarios() then return end

Scenario.UpdateProgressiveItemModels()
Scenario.UpdateBlastShields()

Blackboard.SetProp("GAME_PROGRESS", "RandoMapSeen" .. CurrentScenarioID, "b", true)

Expand Down Expand Up @@ -339,10 +366,12 @@ end

function Scenario.InitFromBlackboard()
RandomizerPowerup.ApplyTunableChanges()
RandomizerPowerup.UpdateWeapons()
end

function Scenario.OnSubAreaChange(old_subarea, old_actorgroup, new_subarea, new_actorgroup, disable_fade)
Scenario.UpdateProgressiveItemModels()
Scenario.UpdateBlastShields()
Scenario.UpdateRoomName(new_subarea)
end

Expand Down
201 changes: 201 additions & 0 deletions src/open_dread_rando/files/randomizer_powerup.lua
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ function RandomizerPowerup.OnPickedUp(actor, resources)
end

RandomizerPowerup.ApplyTunableChanges()
RandomizerPowerup.UpdateWeapons()
Scenario.UpdateProgressiveItemModels()
Scenario.UpdateBlastShields()
RandomizerPowerup.IncrementInventoryIndex()
RL.UpdateRDVClient(false)
return granted
Expand Down Expand Up @@ -279,6 +281,101 @@ function RandomizerPowerup._ApplyTunableChanges()
end
end

function RandomizerPowerup.UpdateWeapons()
RandomizerPowerup.UpdateBeams()
RandomizerPowerup.UpdateMissiles()
end

function RandomizerPowerup.BeamsState()
return {
power = RandomizerPowerup.HasItem("ITEM_WEAPON_POWER_BEAM"),
wide = RandomizerPowerup.HasItem("ITEM_WEAPON_WIDE_BEAM"),
plasma = RandomizerPowerup.HasItem("ITEM_WEAPON_PLASMA_BEAM"),
wave = RandomizerPowerup.HasItem("ITEM_WEAPON_WAVE_BEAM"),
}
end

function RandomizerPowerup.MissileState()
return {
missile = RandomizerPowerup.HasItem("ITEM_WEAPON_MISSILE_LAUNCHER"),
super = RandomizerPowerup.HasItem("ITEM_WEAPON_SUPER_MISSILE"),
ice = RandomizerPowerup.HasItem("ITEM_WEAPON_ICE_MISSILE"),
}
end

function RandomizerPowerup.UpdateBeams()
RandomizerPowerup._UpdateBeams(RandomizerPowerup.BeamsState())
end

function RandomizerPowerup.UpdateMissiles()
RandomizerPowerup._UpdateMissiles(RandomizerPowerup.MissileState())
end

function RandomizerPowerup._UpdateBeams(beams)
if not beams.power then return nil end

local offset = 60
local plasma_damage = 50
local wave_damage = 80
if not beams.wide then
offset = 0
plasma_damage = plasma_damage / 3
wave_damage = wave_damage / 3
end
if not beams.plasma then
wave_damage = wave_damage / 2
end
Scenario.SetTunableValue("CTunableWideBeam", "fPerpendicularOffsetSize", offset)
Scenario.SetTunableValue("CTunablePlasmaBeam", "fDamageAmount", plasma_damage)
Scenario.SetTunableValue("CTunableWaveBeam", "fDamageAmount", wave_damage)

if beams.wide and beams.plasma and beams.wave then
return "ITEM_WEAPON_WIDE_PLASMA_WAVE_BEAM"
end
if beams.plasma and beams.wave then
return "ITEM_WEAPON_PLASMA_WAVE_BEAM"
end
if beams.wide and beams.wave then
return "ITEM_WEAPON_WIDE_WAVE_BEAM"
end
if beams.wide and beams.plasma then
return "ITEM_WEAPON_WIDE_PLASMA_BEAM"
end
if beams.wave then
return "ITEM_WEAPON_SOLO_WAVE_BEAM"
end
if beams.plasma then
return "ITEM_WEAPON_SOLO_PLASMA_BEAM"
end
if beams.wide then
return "ITEM_WEAPON_SOLO_WIDE_BEAM"
end
return "ITEM_WEAPON_POWER_BEAM"
end

function RandomizerPowerup._UpdateMissiles(missiles)
-- don't give any missiles without launcher
if not missiles.missile then return nil end

local ice_damage = 400
if not missiles.super then
ice_damage = ice_damage / 3
end
Scenario.SetTunableValue("CTunableIceMissile", "fDamageAmount", ice_damage)

if missiles.super and missiles.ice then
return "ITEM_WEAPON_SUPER_ICE_MISSILE"
end
if missiles.ice then
return "ITEM_WEAPON_SOLO_ICE_MISSILE"
end
if missiles.super then
return "ITEM_WEAPON_SOLO_SUPER_MISSILE"
end

return "ITEM_WEAPON_MISSILE_LAUNCHER"
end

-- Main PBs
RandomizerPowerBomb = {}
setmetatable(RandomizerPowerBomb, {__index = RandomizerPowerup})
Expand Down Expand Up @@ -345,6 +442,11 @@ end
RandomizerStormMissile = {}
setmetatable(RandomizerStormMissile, {__index = RandomizerPowerup})
function RandomizerStormMissile.OnPickedUp(actor, progression)
progression = progression or {{{item_id = "ITEM_MULTILOCKON", quantity = 1}}}
if RandomizerPowerup.HasItem("ITEM_WEAPON_MISSILE_LAUNCHER") then
table.insert(progression[1], 1, {item_id = "ITEM_WEAPON_STORM_MISSILE", quantity = 1})
end

RandomizerPowerup.ToggleInputsOnPickedUp(
actor, progression, "ITEM_MULTILOCKON"
)
Expand All @@ -363,3 +465,102 @@ function RandomizerEnergyPart.OnPickedUp(actor, progression)
end
end

local function pick_up_beam(beam, actor, progression)
progression = progression or {{{item_id = "ITEM_WEAPON_" .. beam:upper() .. "_BEAM", quantity = 1}}}
local beams = RandomizerPowerup.BeamsState()
if #progression == 1 then
beams[beam] = true
local to_grant = RandomizerPowerup._UpdateBeams(beams)
if to_grant ~= nil then
table.insert(progression[1], 1, {item_id = to_grant, quantity = 1})
end
else
-- progressive beams
progression = {
{
{item_id = "ITEM_WEAPON_SOLO_WIDE_BEAM", quantity = 1},
{item_id = "ITEM_WEAPON_WIDE_BEAM", quantity = 1,}
},
{
{item_id = "ITEM_WEAPON_WIDE_PLASMA_BEAM", quantity = 1},
{item_id = "ITEM_WEAPON_PLASMA_BEAM", quantity = 1},
},
{
{item_id = "ITEM_WEAPON_WIDE_PLASMA_WAVE_BEAM", quantity = 1},
{item_id = "ITEM_WEAPON_WAVE_BEAM", quantity = 1},
}
}
Game.AddSF(0.1, "RandomizerPowerup.UpdateBeams", "")
end

return RandomizerPowerup.OnPickedUp(actor, progression)
end

RandomizerPowerBeam = {}
setmetatable(RandomizerPowerBeam, {__index = RandomizerPowerup})
function RandomizerPowerBeam.OnPickedUp(actor, progression)
return pick_up_beam("power", actor, progression)
end

RandomizerWideBeam = {}
setmetatable(RandomizerWideBeam, {__index = RandomizerPowerup})
function RandomizerWideBeam.OnPickedUp(actor, progression)
return pick_up_beam("wide", actor, progression)
end

RandomizerPlasmaBeam = {}
setmetatable(RandomizerPlasmaBeam, {__index = RandomizerPowerup})
function RandomizerPlasmaBeam.OnPickedUp(actor, progression)
return pick_up_beam("plasma", actor, progression)
end

RandomizerWaveBeam = {}
setmetatable(RandomizerWaveBeam, {__index = RandomizerPowerup})
function RandomizerWaveBeam.OnPickedUp(actor, progression)
return pick_up_beam("wave", actor, progression)
end

local function pick_up_missile(id, item, actor, progression)
progression = progression or {{{item_id = item, quantity = 1}}}
local missiles = RandomizerPowerup.MissileState()
if #progression == 1 then
missiles[id] = true
local to_grant = RandomizerPowerup._UpdateMissiles(missiles)
if to_grant ~= nil then
table.insert(progression[1], 1, {item_id = to_grant, quantity = 1})
end
else
-- progressive missiles
progression = {
{
{item_id = "ITEM_WEAPON_SOLO_SUPER_MISSILE", quantity = 1},
{item_id = "ITEM_WEAPON_SUPER_MISSILE", quantity = 1,}
},
{
{item_id = "ITEM_WEAPON_SUPER_ICE_MISSILE", quantity = 1},
{item_id = "ITEM_WEAPON_ICE_MISSILE", quantity = 1},
},
}
Game.AddSF(0.1, "RandomizerPowerup.UpdateMissiles", "")
end

return RandomizerPowerup.OnPickedUp(actor, progression)
end

RandomizerMissileLauncher = {}
setmetatable(RandomizerMissileLauncher, {__index = RandomizerPowerup})
function RandomizerMissileLauncher.OnPickedUp(actor, progression)
return pick_up_missile("missile", "ITEM_WEAPON_MISSILE_LAUNCHER", actor, progression)
end

RandomizerSuperMissile = {}
setmetatable(RandomizerSuperMissile, {__index = RandomizerPowerup})
function RandomizerSuperMissile.OnPickedUp(actor, progression)
return pick_up_missile("super", "ITEM_WEAPON_SUPER_MISSILE", actor, progression)
end

RandomizerIceMissile = {}
setmetatable(RandomizerIceMissile, {__index = RandomizerPowerup})
function RandomizerIceMissile.OnPickedUp(actor, progression)
return pick_up_missile("ice", "ITEM_WEAPON_ICE_MISSILE", actor, progression)
end
7 changes: 7 additions & 0 deletions src/open_dread_rando/pickups/lua_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ def _read_level_lua(level_id: str) -> str:
"ITEM_MULTILOCKON": "RandomizerStormMissile",
"ITEM_LIFE_SHARDS": "RandomizerEnergyPart",
"ITEM_GHOST_AURA": "RandomizerFlashShift",
"ITEM_WEAPON_POWER_BEAM": "RandomizerPowerBeam",
"ITEM_WEAPON_WIDE_BEAM": "RandomizerWideBeam",
"ITEM_WEAPON_PLASMA_BEAM": "RandomizerPlasmaBeam",
"ITEM_WEAPON_WAVE_BEAM": "RandomizerWaveBeam",
"ITEM_WEAPON_MISSILE_LAUNCHER": "RandomizerMissileLauncher",
"ITEM_WEAPON_SUPER_MISSILE": "RandomizerSuperMissile",
"ITEM_WEAPON_ICE_MISSILE": "RandomizerIceMissile",
}


Expand Down
8 changes: 7 additions & 1 deletion src/open_dread_rando/pickups/pickup.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,14 @@ def patch_multi_item_pickup(self, bmsad: dict) -> dict:
pickable: dict = bmsad["property"]["components"]["PICKABLE"]
script: dict = bmsad["property"]["components"]["SCRIPT"]

item_id = "ITEM_NONE"
first_progression = self.pickup["resources"][0][0]["item_id"]
if first_progression in {"ITEM_WEAPON_WIDE_BEAM", "ITEM_WEAPON_SUPER_MISSILE"}:
# the gun doesn't appear to be selected properly on pickup unless we do this
item_id = first_progression

set_custom_params: dict = pickable["functions"][0]["params"]
set_custom_params["Param1"]["value"] = "ITEM_NONE"
set_custom_params["Param1"]["value"] = item_id

script["functions"][0]["params"]["Param2"]["value"] = self.lua_editor.get_script_class(self.pickup,
actordef_name=bmsad[
Expand Down
Loading

0 comments on commit 2fa4b9c

Please sign in to comment.