Skip to content

Fix berserked targeting after using Hermes#1

Open
cassidoxa wants to merge 2 commits intoHungryTenor:mainfrom
cassidoxa:hermes_berserk
Open

Fix berserked targeting after using Hermes#1
cassidoxa wants to merge 2 commits intoHungryTenor:mainfrom
cassidoxa:hermes_berserk

Conversation

@cassidoxa
Copy link

@cassidoxa cassidoxa commented Jan 25, 2024

This fixes a bug where berserked party members can target swooned enemies if they use the Hermes item before being berserked. We hook into the battle command execution routine at $03AE81, where the current actor's subcommand is loaded and compared to $BA, which is used for both the Hermes item and a "Life All" enemy spell. If the value is $BA, a "can hit swooned" flag is set (also used for things like Life potions.) Our code checks if the actor command is $C2, a monster white magic action. If the command is $C2, we load the subcommand, exit, and proceed with the comparison. If not $C2, we transfer Y (which will always hold $FFFF from a previous loop in this path) to A.

let Y = $FFFF
...
let A = actor_command
if A == MONSTER_WHITE_MAGIC_COMMAND:
    let A = actor_subcommand
    return A
else:
    let A = Y & 0x00FF
    return A

This works because the Life All command is only used during the Zeromus cutscene (when Palom and Porom revive the party.) So the subcommand can never be $BA except in this cutscene and therefore other enemy healing actions won't improperly target swooned characters. When a character is berserked, their command will never be $C2, the monster white magic command. Y = $FFFF is another invariant we can depend on, there are no branches between the decrement that sets it and our code.

Another avenue worth investigating is hooking into the vanilla "select berserk target" routine around $03ACA3 which is called during a "queue auto actions routine" that only loops through the five player characters. The former routine initializes some character data including setting the "main" command to zero. It may be possible to safely zero out the subcommand here as well (perhaps if the character is also not charmed.) But I am unsure if this may have other side effects. Could also look into zeroing out the subcommand when berserked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant