Skip to content

Commit

Permalink
Merge pull request #335 from randovania/custom-doors
Browse files Browse the repository at this point in the history
Add support for custom door locks
  • Loading branch information
ThanatosGit authored May 9, 2024
2 parents 9b62024 + cb14cb9 commit 00d7f3e
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 9 deletions.
29 changes: 29 additions & 0 deletions src/open_samus_returns_rando/files/custom/sprites_texturehud.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
Game.ImportLibrary("gui/scripts/sprites_texturehud_original.lua")

GUI.AddSpriteSheetItem("dooriceleft", "gui/textures/texturehud.bctex", {
TextureWidth = "512",
TextureHeight = "256",
UPixelOffset = "120",
VPixelOffset = "40",
UPixelScale = "4",
VPixelScale = "8",
AngleOffset = "0"
})
GUI.AddSpriteSheetItem("dooriceright", "gui/textures/texturehud.bctex", {
TextureWidth = "512",
TextureHeight = "256",
UPixelOffset = "124",
VPixelOffset = "40",
UPixelScale = "4",
VPixelScale = "8",
AngleOffset = "0"
})
GUI.AddSpriteSheetItem("dooricecenter", "gui/textures/texturehud.bctex", {
TextureWidth = "512",
TextureHeight = "256",
UPixelOffset = "120",
VPixelOffset = "40",
UPixelScale = "8",
VPixelScale = "8",
AngleOffset = "0"
})
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
3 changes: 2 additions & 1 deletion src/open_samus_returns_rando/files/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,8 @@
"wave_beam",
"missile",
"super_missile",
"power_bomb"
"power_bomb",
"ice_beam"
]
}
},
Expand Down
1 change: 1 addition & 0 deletions src/open_samus_returns_rando/lua_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ def _add_replacement_files(self, editor: PatcherEditor, configuration: dict) ->
lua_util.replace_script(editor, "actors/props/savestation/scripts/savestation", "custom/savestation.lua")
lua_util.replace_script(editor, "actors/props/heatzone/scripts/heatzone", "custom/heatzone.lua")
lua_util.replace_script(editor, "gui/scripts/sprites_splashes", "custom/sprites_splashes.lua")
lua_util.replace_script(editor, "gui/scripts/sprites_texturehud", "custom/sprites_texturehud.lua")

def save_modifications(self, editor: PatcherEditor, configuration: dict) -> None:
self._add_replacement_files(editor, configuration)
Expand Down
70 changes: 62 additions & 8 deletions src/open_samus_returns_rando/specific_patches/door_patches.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import copy
import re
import typing
Expand Down Expand Up @@ -191,6 +190,14 @@ def _patch_one_way_doors(editor: PatcherEditor) -> None:
properties.components[0]["arguments"][2]["value"] = False


def _static_door_patches(editor: PatcherEditor) -> None:
_patch_one_way_doors(editor)
_patch_missile_covers(editor)
_patch_beam_bmsads(editor)
_patch_beam_covers(editor)
_patch_charge_doors(editor)


class ActorData(Enum):
"""
Enum containing data on actors
Expand All @@ -205,6 +212,7 @@ class ActorData(Enum):
SHIELD_MISSILE = (["doorshieldmissile"])
SHIELD_SUPER_MISSILE = (["doorshieldsupermissile"])
SHIELD_POWER_BOMB = (["doorshieldpowerbomb"])
SHIELD_ICE_BEAM = (["doorshieldicebeam"])

class DoorType(Enum):
"""
Expand Down Expand Up @@ -240,6 +248,9 @@ class DoorType(Enum):
"actors/props/doorshield", "actors/props/doorshieldpowerbomb",
"sounds/props/doorchargecharge/powerbombdoor_hum.bcwav"
])
ICE_BEAM = ("ice_beam", ActorData.DOOR_POWER, "doorice", True, ActorData.SHIELD_ICE_BEAM, [
"actors/props/doorshield", "actors/props/doorshieldicebeam"
])

def __init__(self, rdv_door_type: str, door_data: ActorData, minimap_name: str,
need_shield: bool = False, shield_data: ActorData | None = None,
Expand Down Expand Up @@ -426,20 +437,63 @@ def patch_actor(
self.editor.ensure_present_in_scenario(scenario_name, asset)


def _static_door_patches(editor: PatcherEditor) -> None:
_patch_one_way_doors(editor)
_patch_missile_covers(editor)
_patch_beam_bmsads(editor)
_patch_beam_covers(editor)
_patch_charge_doors(editor)
class NewShield(typing.NamedTuple):
shield_name: str
weakness: str


new_shields = [
NewShield("icebeam", "ICE_BEAM"),
]


def add_custom_shields(editor: PatcherEditor, new_shield: NewShield) -> None:
plasma_bmsad = "actors/props/doorcreature/charclasses/doorcreature.bmsad"
missile_bmsad = "actors/props/doorshieldmissile/charclasses/doorshieldmissile.bmsad"
new_bmsad = f"actors/props/doorshield{new_shield.shield_name}/charclasses/doorshield{new_shield.shield_name}.bmsad"
new_model = f"actors/props/doorshield{new_shield.shield_name}/models/doorshield{new_shield.shield_name}.bcmdl"

# Create a copy of the bmsad
template_shield = editor.get_raw_asset(plasma_bmsad)
editor.add_new_asset(new_bmsad, template_shield, [])

# Modify the new bmsad
custom_shield = editor.get_file(new_bmsad, Bmsad)
custom_shield.name = f"doorshield{new_shield.shield_name}"
custom_shield.raw["header"]["model_name"] = new_model

# Update the collision to be able to open both sides
missile_shield = editor.get_file(missile_bmsad, Bmsad)
custom_shield.raw["components"]["COLLISION"] = missile_shield.raw["components"]["COLLISION"]
custom_shield.components["MODELUPDATER"].functions[0].params["Param1"]["value"] = new_model

# Update the life component
life_component = custom_shield.raw["components"]["LIFE"]["functions"]
life_component[0]["params"]["Param1"]["value"] = new_shield.weakness

# Remove the second weakness container
life_component.pop(1)

# Set shield health to 1
life_component[2]["params"]["Param2"]["value"] = 1.0
life_component[3]["params"]["Param2"]["value"] = 1.0

# Remove the drops from breaking the shield
custom_shield.raw["components"].pop("DROP")

# Remove the particle animation that occurs after the shield breaks (color mismatch)
custom_shield.raw["action_sets"][0]["animations"][0]["events0"][1]["args"][729149823]["value"] = 0


def patch_doors(editor: PatcherEditor, door_patches: list[dict]) -> None:
_static_door_patches(editor)

for new_shield in new_shields:
add_custom_shields(editor, new_shield)
door_patcher = DoorPatcher(editor)

# small hack to eliminate duplicates (randovania exports everything duplicated)
import json

set_of_jsons = {json.dumps(d, sort_keys=True) for d in door_patches}
door_patches_set = [json.loads(t) for t in set_of_jsons]

Expand Down

0 comments on commit 00d7f3e

Please sign in to comment.