From 0f76d35a8c57b2114538a43698e9331cd32a81b2 Mon Sep 17 00:00:00 2001 From: Alchav <59858495+Alchav@users.noreply.github.com> Date: Thu, 6 Aug 2026 01:14:01 -0400 Subject: [PATCH] ALttP: Fix Randomzie Enemy Damage (#6296) --- worlds/alttp/EnemizerPatches.py | 3 ++- worlds/alttp/test/TestEnemizerPatches.py | 9 +++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/worlds/alttp/EnemizerPatches.py b/worlds/alttp/EnemizerPatches.py index 9d7618c075..7b849c8e10 100644 --- a/worlds/alttp/EnemizerPatches.py +++ b/worlds/alttp/EnemizerPatches.py @@ -385,10 +385,11 @@ def _randomize_enemy_damage(rom: "LocalRom", rng: random.Random, allow_zero_dama for sprite_id in range(0xF3): if sprite_id in EXCLUDED_ENEMY_TABLE_SPRITE_IDS: continue + damage_address = ENEMY_DAMAGE_TABLE_ADDRESS + sprite_id new_damage = rng.randrange(8) if not allow_zero_damage and new_damage == 2: continue - rom.write_byte(ENEMY_DAMAGE_TABLE_ADDRESS + sprite_id, new_damage) + rom.write_byte(damage_address, (rom.read_byte(damage_address) & 0xF0) | new_damage) def _shuffle_damage_groups( diff --git a/worlds/alttp/test/TestEnemizerPatches.py b/worlds/alttp/test/TestEnemizerPatches.py index 4aa09bb62e..354688951a 100644 --- a/worlds/alttp/test/TestEnemizerPatches.py +++ b/worlds/alttp/test/TestEnemizerPatches.py @@ -106,10 +106,12 @@ class TestEnemizerPatches(unittest.TestCase): included_hp_sprite_id = 0x01 included_damage_sprite_id = 0x02 + boss_damage_sprite_id = 0x53 excluded_sprite_id = min(EXCLUDED_ENEMY_TABLE_SPRITE_IDS) rom.write_byte(ENEMY_HP_TABLE_ADDRESS + included_hp_sprite_id, 0x06) rom.write_byte(ENEMY_HP_TABLE_ADDRESS + excluded_sprite_id, 0x07) - rom.write_byte(ENEMY_DAMAGE_TABLE_ADDRESS + included_damage_sprite_id, 0x06) + rom.write_byte(ENEMY_DAMAGE_TABLE_ADDRESS + included_damage_sprite_id, 0x86) + rom.write_byte(ENEMY_DAMAGE_TABLE_ADDRESS + boss_damage_sprite_id, 0x17) rom.write_byte(ENEMY_DAMAGE_TABLE_ADDRESS + excluded_sprite_id, 0x05) world = self._build_world( @@ -133,7 +135,10 @@ class TestEnemizerPatches(unittest.TestCase): self.assertGreaterEqual(rom.read_byte(ENEMY_HP_TABLE_ADDRESS + included_hp_sprite_id), 2) self.assertLess(rom.read_byte(ENEMY_HP_TABLE_ADDRESS + included_hp_sprite_id), 25) self.assertEqual(rom.read_byte(ENEMY_HP_TABLE_ADDRESS + excluded_sprite_id), 0x07) - self.assertIn(rom.read_byte(ENEMY_DAMAGE_TABLE_ADDRESS + included_damage_sprite_id), range(8)) + randomized_damage = rom.read_byte(ENEMY_DAMAGE_TABLE_ADDRESS + included_damage_sprite_id) + self.assertEqual(randomized_damage & 0xF0, 0x80) + self.assertIn(randomized_damage & 0x0F, range(8)) + self.assertEqual(rom.read_byte(ENEMY_DAMAGE_TABLE_ADDRESS + boss_damage_sprite_id), 0x17) self.assertEqual(rom.read_byte(ENEMY_DAMAGE_TABLE_ADDRESS + excluded_sprite_id), 0x05) for group_id in range(10): group_address = DAMAGE_GROUP_TABLE_ADDRESS + (group_id * 3)