Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Refactor] Rewrite Move Effect Phase #4887

Open
wants to merge 9 commits into
base: beta
Choose a base branch
from

Conversation

innerthunder
Copy link
Collaborator

@innerthunder innerthunder commented Nov 16, 2024

What are the changes the user will see?

What are the changes from a developer perspective?

I figure it's better to list the changes before justifying them...

  • phases/move-effect-phase:
    • hitCheck now returns a HitCheckEntry, which consists of a HitCheckResult and the type effectiveness multiplier of the phase's move against the given target. The HitCheckResults this function can now return are as follows:

      • HIT: The move successfully hit the target
      • NO_EFFECT: The target is immune to the move.
      • NO_EFFECT_NO_MESSAGE: The target is immune to the move, and the immunity effect plays its own message instead of the default "It doesn't affect {target}!"
      • PROTECTED: The target protected itself against the move.
      • MISS: The move failed the accuracy check and missed the target.
      • ERROR: The move failed unexpectedly (e.g. the move's user is undefined)

      Hit check entries against each of the move's targets are cached in the phase's new hitChecks field to be used throughout the phase's other functions. Hit check entries are initialized in a PENDING state, but each hit check should be overwritten before effects apply.

    • If no hit check results in a HIT, the phase will end without playing the move's animation (unless the move has a POST_TARGET effect like Explosion).

    • Pokemon.apply has been moved from the Pokemon class to MoveEffectPhase.applyMove. Critical hit resolution and damage calculations are still done within Pokemon methods. PRE_APPLY move effects are now triggered before this method is called (but only when the move successfully hits).

    • POST_APPLY and HIT move effect triggers have been condensed into a single POST_APPLY trigger (WIP). Target-facing secondary effects generally no longer trigger when the move hits a substitute (fixes [Bug] Certain Move and Ability Effects (BattlerTags) Work through Substitute #4764 )

    • Helper functions for different move effect trigger types have been generalized into a single triggerMoveEffect function.

    • Removed MoveEffectPhase.stopMultiHit and Pokemon.stopMultiHit. Multi-hit early stopping is now done with the help of added code in MEPhase.end (and modifications to hitCount and hitsLeft in some edge cases)

    • Other minor adjustments to field-targeting moves (not a complete fix), immunity checks, and general cleanup.

Why am I making these changes?

Aside from fixing the bugs listed above (among others), this should allow for cleaner implementations of moves and abilities that interact with the phase for several reasons:

  • Using a Pokemon function to apply move damage brought about unnecessary scope issues, especially having to do with type immunity checks and multi-hit logic. Moving this function to MoveEffectPhase allows developers to modify most, if not all, aspects of a move's effects in one place.
  • Move effect trigger types are needlessly convoluted, and the distinction between POST_APPLY and HIT move effect triggers has become increasingly unclear. It'd be nice to condense trigger types that are ultimately redundant.
  • PRE_APPLY move effects currently have no way of actually applying before the move's effectiveness and/or damage were calculated. This fixes that.
  • Condensing all hit checks (immunity, protection, and accuracy) into one place will help with some otherwise complicated implementations, including Dragon Darts and Sky Drop.
  • This should bring field effects closer to not requiring a target to apply

Screenshots/Videos

How to test the changes?

npm run test (still fixing some tests)

Checklist

  • I'm using beta as my base branch
  • There is no overlap with another PR?
  • The PR is self-contained and cannot be split into smaller PRs?
  • Have I provided a clear explanation of the changes?
  • Have I considered writing automated tests for the issue?
  • If I have text, did I make it translatable and add a key in the English locale file(s)?
  • Have I tested the changes (manually)?
    • Are all unit tests still passing? (npm run test)
  • [?] Are the changes visual?
    • [?] Have I provided screenshots/videos of the changes?

@DayKev
Copy link
Collaborator

DayKev commented Nov 17, 2024

@innerthunder innerthunder marked this pull request as ready for review November 18, 2024 00:03
@innerthunder innerthunder requested a review from a team as a code owner November 18, 2024 00:03
@DayKev DayKev modified the milestone: 1.4.0 Nov 18, 2024
src/data/move.ts Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In progress
3 participants