pret / pokeemerald

Decompilation of Pokémon Emerald
2.28k stars 2.57k forks source link

Counter and Mirror Coat have incorrect type category checks #2065

Open surtr-games opened 1 day ago

surtr-games commented 1 day ago

In battle_ai_scripts.s:

AI_CV_Counter6:
    get_target_type1
    if_in_bytes AI_CV_Counter_PhysicalTypeList, AI_CV_Counter_End
    get_target_type2
    if_in_bytes AI_CV_Counter_PhysicalTypeList, AI_CV_Counter_End
    if_random_less_than 50, AI_CV_Counter_End
AI_CV_Counter7:
    if_random_less_than 100, AI_CV_Counter8
    score +4
AI_CV_Counter8:
    end

Counter deals double the damage received if hit by a physical attack. So, in my opinion, it doesn't make sense to score +4 if none of the mon's types is physical. Mirror Coat has the same issue.

Do you agree that this should be considered a bug? If so, should we fix it in Pret (conditionally, with the BUGFIX define)? If so, any suggestions on how to fix it?

ketsuban commented 1 day ago

I think maybe you've misunderstood what get_target_type{1,2} do - it's checking the opponent, not the user, on the basis that (since this is Gen 3 and we don't have a physical/special split) they're likely to use moves of the same persuasion as their STAB types. Theoretically it could make better use of Counter/Mirror Coat (e.g. by "cheating" and looking at what move the player has used) but that's well out of the scope of the BUGFIX macro and more in the realm of "rewrite the AI entirely".

GriffinRichards commented 1 day ago

@ketsuban Follow that logic through the script and you'll see the bug. If the opponent is a physical type (and so as you noted more likely to use a physical move Counter would be good for) it ends the script with no further action. On the other hand if it's not a physical type it has a chance to reach score +4, increasing the likelihood that Counter is the chosen move.