java.lang.Object
com.pixelmonmod.pixelmon.battles.attacks.Attack

public class Attack extends Object
A Pokémon's attack.
  • Field Details

    • ATTACK_PHYSICAL

      public static final int ATTACK_PHYSICAL
      attack categories.
      See Also:
    • ATTACK_SPECIAL

      public static final int ATTACK_SPECIAL
      attack categories.
      See Also:
    • ATTACK_STATUS

      public static final int ATTACK_STATUS
      attack categories.
      See Also:
    • NEVER_MISS

      public static final int NEVER_MISS
      Special accuracy cases.
      See Also:
    • IGNORE_SEMIINVULNERABLE

      public static final int IGNORE_SEMIINVULNERABLE
      Special accuracy cases.
      See Also:
    • pp

      public int pp
      The attack's PP.
    • ppLevel

      public int ppLevel
      The number of PP UP's that have been used, always 3 for a PP max
    • movePower

      public int movePower
      The base power of the attack.
    • overridePower

      public int overridePower
      Overridden base power of the attack.
    • moveAccuracy

      public int moveAccuracy
      The accuracy of the attack.
    • cantMiss

      public boolean cantMiss
      Whether the attack can never miss the target
    • moveResults

      public MoveResults moveResults
      The result of the attack.
    • damageResult

      public float damageResult
      The amount of damage dealt by the attack.
    • didCrit

      public boolean didCrit
      Whether the move critically hit or not.
    • savedAttack

      public ImmutableAttack savedAttack
      The original attack before modifications.
    • savedPower

      public int savedPower
      The original power of the attack before modifications.
    • savedAccuracy

      public int savedAccuracy
      The original accuracy of the attack before modifications.
    • hasPlayedAnimationOnce

      public transient boolean hasPlayedAnimationOnce
    • isZ

      public transient boolean isZ
    • isMax

      public transient boolean isMax
    • originalMove

      public transient Attack originalMove
    • fromDancer

      public transient boolean fromDancer
  • Constructor Details

    • Attack

      public Attack(ImmutableAttack base)
      Initializes an attack with its base attack stats.
      Parameters:
      base - The base attack stats of this attack.
    • Attack

      public Attack(String moveName)
      Initializes an attack with its base attack stats.
      Parameters:
      moveName - The name of the attack.
    • Attack

      public Attack(RegistryValue<ImmutableAttack> move)
    • Attack

      public Attack(Attack attack)
      Makes a deep copy of the Attack object
      Parameters:
      attack - The attack we are assigning
  • Method Details

    • initializeAttack

      public void initializeAttack(ImmutableAttack base)
      Initializes the attack's stats and PP.
      Parameters:
      base - The base attack to initialize the attack from.
    • getMove

      public ImmutableAttack getMove()
      The current attack.
    • getActualMove

      public ImmutableAttack getActualMove()
      The unmodified attack details.
    • getPP

      public int getPP()
      The attack's current PP.
    • setPP

      public void setPP(int pp)
      Sets this attack's current PP.
      Parameters:
      pp - A non-negative number.
    • getPPLevel

      public int getPPLevel()
      The amount of PP Ups that have been used to upgrade the maximum PP of the move.

      This should have a minimum value of 0 and a maximum value of 3.

    • setPPLevel

      public void setPPLevel(int ppLevel)
      Sets how many PP Ups have been used on the Pokémon to increase the maximum PP for this move.
      Parameters:
      ppLevel - An integer between 0 and 3.
    • getMaxPP

      public int getMaxPP()
      The attack's maximum PP with PP Ups.
    • overridePPMax

      public void overridePPMax(int pp)
      Replaces the maximum PP of a move, overriding any PP Up/PP Max used.

      Typically used for transforming into another Pokemon or into another form, such as during Dynamaxing.

      Parameters:
      pp - The number that the move's maximum PP will be set to.
    • getOverriddenPPMax

      public Integer getOverriddenPPMax()
      Returns:
      the overriddenPPMax. used for updating the client that there is a override.
    • getEffects

      public List<EffectBase> getEffects()
      Returns:
      The effects for the move, whether modified by the field or base.
    • getAttackCategory

      public AttackCategory getAttackCategory()
      The attack's category, Physical/Special/Status.
    • overrideAttackCategory

      public void overrideAttackCategory(AttackCategory category)
    • getType

      public net.minecraft.core.Holder<Type> getType()
    • getActualType

      public net.minecraft.core.Holder<Type> getActualType()
    • clearOverrideType

      public void clearOverrideType()
    • overrideType

      public void overrideType(net.minecraft.core.Holder<Type> type)
    • overrideType

      public void overrideType(net.minecraft.resources.ResourceKey<Type> type)
    • resetMove

      public void resetMove()
      Restores the base attack's details if they are modified during the attack.
    • resetOverridePower

      public void resetOverridePower()
    • use

      public boolean use(PixelmonWrapper user)
    • use

      public boolean use(PixelmonWrapper user, ZMove zMove)
      Executes the attack.
      Returns:
      boolean Whether the attack's PP will be lowered.
    • modifyMoveEffects

      public static void modifyMoveEffects(PixelmonWrapper user, PixelmonWrapper target, List<EffectBase> effects)
    • modifyPowerAndAccuracy

      public int[] modifyPowerAndAccuracy(PixelmonWrapper user, PixelmonWrapper target, Ability userAbility, Ability targetAbility, int livePower)
      Modify the attacker's power and accuracy based on abilities, items, and statuses.
      Parameters:
      user - The Pokémon using the move.
      target - The Pokémon being attacked.
      userAbility - The attacking Pokémon's ability.
      livePower - The current power of the move.
      Returns:
      Returns an integer array of size 2, with the first index representing the power of the move and the second index representing the accuracy of the move.
    • calculateMoveAccuracy

      public double calculateMoveAccuracy(PixelmonWrapper user, PixelmonWrapper target, Ability userAbility)
      Make the calculations on how accurate a move will be.
      Parameters:
      user - The Pokémon using the move.
      target - The Pokémon being attacked.
      userAbility - The user's ability.
      Returns:
      Whether a Pokémon self-targeted themselves with a move.
    • hasNoEffect

      public boolean hasNoEffect(PixelmonWrapper user, PixelmonWrapper target)
      Checks if the move has no effect on the target Pokémon.
      Parameters:
      user - The Pokémon using the move.
      target - The Pokémon being targeted by the move.
      Returns:
      Whether the move has no effect on the target Pokémon.
    • manageDealingDamage

      public void manageDealingDamage(PixelmonWrapper user, EffectBase critModifier, float damageMultiplier)
      A function for keeping together all the code that helps the attacking Pixelmon finally deal damage.

      Manages whether a critical hit occurs, how much damage will be dealt, notifying players of critical hits, dealing the damage, and the result of the damage.

      Parameters:
      user - The Pixelmon making an attack.
      critModifier - An effect for adjusting the power of critical hits.
      damageMultiplier - Adjust how much damage will be dealt.
    • playAnimation

      public void playAnimation(PixelmonWrapper user, PixelmonWrapper target)
      Does animation for the attack.
      Parameters:
      user - The attack's user.
      target - The attack's target.
    • doDamageCalc

      public int doDamageCalc(PixelmonWrapper userWrapper, PixelmonWrapper targetWrapper, double crit)
      Calculates the attack's damage.
      Parameters:
      userWrapper - The attack's user.
      targetWrapper - The attack's target.
      crit - The critical hit modifier.
      Returns:
      The calculated damage.
    • applySelfStatusMove

      public void applySelfStatusMove(PixelmonWrapper user, SingleInstanceMoveResult singleInstanceMoveResult)
      Triggered when a Pokémon uses a status move that targets itself.
      Parameters:
      user - The attack's user.
      singleInstanceMoveResult - The results of the attack.
    • executeAttackEffectsAfterDamage

      public void executeAttackEffectsAfterDamage(PixelmonWrapper user)
      Contains all the attack effects that are done after dealing damage.
      Parameters:
      user - The source of the attack or damage.
    • applyAttackEffect

      public AttackResult applyAttackEffect(PixelmonWrapper user)
      Applies status and stat modifiers.
      Parameters:
      user - The attack's user.
      Returns:
      The attack's result.
    • applyContactEarly

      public static void applyContactEarly(PixelmonWrapper user, PixelmonWrapper target)
      Triggered when a Pokémon makes contact.
      Parameters:
      user - The attack's user.
      target - The attack's target.
    • applyOnDamageAbilityLate

      public static void applyOnDamageAbilityLate(PixelmonWrapper user, PixelmonWrapper target)
      Triggered when a Pokémon makes has a move used on it. Occurs after other end-of-move effects.

      Guarantees for its effects that the target took damage this turn.

      Parameters:
      user - The move's user.
      target - The move's target.
    • applyEffectBeforeContactLate

      public static void applyEffectBeforeContactLate(PixelmonWrapper user, PixelmonWrapper target)
      Applies an ability effect after most attack effects, but before applyContactLate(PixelmonWrapper, PixelmonWrapper).

      Does not require the user or target to make contact.

      Parameters:
      user - The user with the ability that is attacking.
      target - The target of the attack.
    • applyContactLate

      public static void applyContactLate(PixelmonWrapper user, PixelmonWrapper target)
      Triggered when a Pokémon makes contact. Occurs after other end-of-move effects.

      Also handles the special interaction between Protective Pads and Pickpocket.

      Parameters:
      user - The move's user.
      target - The move's target.
    • applyEffectAfterContactEffects

      public static void applyEffectAfterContactEffects(PixelmonWrapper user, PixelmonWrapper target)
    • applyOppositeTeamStatusesAfterContactEffects

      public static void applyOppositeTeamStatusesAfterContactEffects(PixelmonWrapper user)
      Applies status that affect the opponent's entire team.

      This occurs after contact effects so that effect such as Ceaseless Edge's Spikes will only apply so long as the user has not fainted.

      Parameters:
      user - The Pixelmon using the move to apply an effect.
    • postProcessAttackAllHits

      public static void postProcessAttackAllHits(PixelmonWrapper user, PixelmonWrapper target, Attack attack, float totalDamage, DamageTypeEnum damageType, boolean onSubstitute)
      Applies any post-damage effects after all hits of a move.
      Parameters:
      user - The attack's user.
      target - The attack's target.
      attack - The attack.
      totalDamage - The total damage dealt by the attack.
      damageType - The type of damage dealt.
      onSubstitute - Whether the damage was done on a substitute.
    • onMiss

      public void onMiss(PixelmonWrapper user, PixelmonWrapper target, SingleInstanceMoveResult singleInstanceMoveResult, Object cause)
      Handles procedures when the attack misses.
      Parameters:
      user - The attack's user.
      singleInstanceMoveResult - The result of the move.
      cause - The cause of the attack missing.
    • hasSTAB

      public boolean hasSTAB(PixelmonWrapper user)
      Determines whether the attack has STAB.
      Parameters:
      user - The attack's user.
      Returns:
      Whether the attack has STAB.
    • setDisabled

      public void setDisabled(boolean value, PixelmonWrapper pixelmon)
      Disables or enables a move.
      Parameters:
      value - Whether the move is to be disabled (true) or enabled (false).
      pixelmon - The Pokémon with the move.
    • setDisabled

      public void setDisabled(boolean value, PixelmonWrapper pixelmon, boolean switching)
      Disables or enables a move.
      Parameters:
      value - Whether the move is to be disabled (true) or enabled (false).
      pixelmon - The Pokémon with the move.
      switching - Whether the Pokémon is switching out.
    • getDisabled

      public boolean getDisabled()
      Returns whether the move is disabled.
      Returns:
      Whether the move is disabled.
    • canUseMove

      public boolean canUseMove()
    • calcCriticalHit

      public static double calcCriticalHit(EffectBase e, PixelmonWrapper user, PixelmonWrapper target)
      Calculates whether the attack will land a critical hit.
      Parameters:
      e - An attack effect that influences critical hit calculation, if applicable.
      user - The attack's user.
      target - The attack's target.
      Returns:
      The critical hit modifier.
    • getChanceToCrit

      public static float getChanceToCrit(EffectBase e, PixelmonWrapper user, PixelmonWrapper target)
    • canHit

      public boolean canHit(PixelmonWrapper pixelmon1, PixelmonWrapper pixelmon2)
      Determines whether or not the attack can occur due to fainting.
      Parameters:
      pixelmon1 - The attack's user.
      pixelmon2 - The attack's target.
      Returns:
      Whether the attack can occur.
    • canReachTarget

      public boolean canReachTarget(PixelmonWrapper user, PixelmonWrapper target)
      Determines whether or not the attack can reach the target based on targeting info
      Parameters:
      user - The attack's user.
      target - The attack's target.
      Returns:
      Whether the attack can reach the opponent.
    • doesPersist

      public boolean doesPersist(PixelmonWrapper pw)
      Determines whether the attack continues between turns.
      Parameters:
      pw - The attack's user.
      Returns:
      Whether the attack continues between turns.
    • cantMiss

      public boolean cantMiss(PixelmonWrapper user, PixelmonWrapper target)
      Determines whether the move will never miss.
      Parameters:
      user - The move's user.
      target - The move's target.
      Returns:
      Whether the move will never miss.
    • sendEffectiveChat

      public void sendEffectiveChat(PixelmonWrapper user, PixelmonWrapper target)
      Sends a battle message about the type effectiveness of an attack.
      Parameters:
      user - The attack's user.
      target - The attack's target.
    • dealsDamage

      public static boolean dealsDamage(Attack attack)
      Determines whether the attack deals direct damage.
      Parameters:
      attack - The attack to check.
      Returns:
      Whether the attack deals direct damage.
    • hasMoreEffects

      public static boolean hasMoreEffects(Attack attack, EffectBase effect)
      Determines whether the attack has more possible effects to try.
      Parameters:
      attack - The attack to check.
      effect - The current effect.
      Returns:
      Whether the attack deals direct damage.
    • saveAttack

      public void saveAttack()
      Saves the base attack's details.
    • restoreAttack

      public void restoreAttack()
      Restores the base attack's details if they are modified during the attack.
    • isAttack

      public boolean isAttack(ImmutableAttack... attacks)
      Determines whether the attack is one of the specified attacks.
      Parameters:
      attacks - The attacks to compare this attack to.
      Returns:
      Whether the attack is one of the specified attacks.
    • isAttack

      @SafeVarargs public final boolean isAttack(Optional<ImmutableAttack>... attacks)
    • isAttack

      @SafeVarargs public final boolean isAttack(RegistryValue<ImmutableAttack>... attacks)
    • isAttack

      public final boolean isAttack(List<Supplier<ImmutableAttack>> attacks)
    • hasAttack

      @SafeVarargs public static boolean hasAttack(List<Attack> attackList, Optional<ImmutableAttack>... attacks)
      Checks if a list of attacks has certain attacks in it.
      Parameters:
      attackList - The list of attacks to search.
      attacks - The attacks to look for.
      Returns:
      Whether the attack list has at least one of the specified attacks.
    • hasAttack

      @SafeVarargs public static boolean hasAttack(List<Attack> attackList, RegistryValue<ImmutableAttack>... attacks)
      Checks if a list of attacks has certain attacks in it.
      Parameters:
      attackList - The list of attacks to search.
      attacks - The attacks to look for.
      Returns:
      Whether the attack list has at least one of the specified attacks.
    • hasOffensiveAttackType

      public static boolean hasOffensiveAttackType(List<Attack> attackList, net.minecraft.resources.ResourceKey<Type> type)
      Checks if a list of attacks has an offensive attack of a certain type.
      Parameters:
      attackList - The list of attacks to search.
      type - The type to look for.
      Returns:
      Whether the list of attacks has an offensive attack of the specified type.
    • createMoveChoices

      public void createMoveChoices(PixelmonWrapper pw, List<MoveChoice> choices, boolean includeAllies)
      Creates move choices out of an attack and adds them to a list.
      Parameters:
      pw - The Pokémon using the attack.
      choices - The list of choices to add the new choices to.
      includeAllies - Whether to include choices that only target teammates.
    • createMoveChoices

      public ArrayList<MoveChoice> createMoveChoices(PixelmonWrapper pw, boolean includeAllies)
      Creates a list of move choices for an attack.
      Parameters:
      pw - The Pokémon using the attack.
      includeAllies - Whether to include choices that only target teammates.
      Returns:
      A list of the move choices for an attack.
    • createList

      public ArrayList<Attack> createList()
      Creates a list containing the attack.
      Returns:
      A list containing the attack.
    • equals

      public boolean equals(Object compare)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • getTypeEffectiveness

      public double getTypeEffectiveness(PixelmonWrapper user, PixelmonWrapper target)
      Gets the type effectiveness of the move on its target.
      Parameters:
      user - The user of the move.
      target - The target of the move.
      Returns:
      The type effectiveness multiplier of the move on its target.
    • canRemoveBerry

      public boolean canRemoveBerry()
      Checks if the move is an offensive move that can remove a held Berry. Used to delay the potential activation of Berries for these moves.
      Returns:
      Whether the move is an offensive move that can remove a held Berry.
    • copy

      public Attack copy()
      Makes a copy of the move object.

      Creates a new Attack using Attack(Attack) and copies the current amount of PP the old Attack has, the old Attack's PP Level (PP Up usage), and whether it was activated by a Dancer ability.

      Returns:
      A copy of the move object.
    • deepCopy

      public Attack deepCopy()
      Makes a copy of the move object.

      As opposed to copy(), this function should copy every member variable of the current Attack.

      Returns:
      A copy of the move object.
    • canHitNoTarget

      public boolean canHitNoTarget()
      Checks if the move succeeds even if there is no target.
      Returns:
      Whether the move succeeds even if there is no target.
    • isSoundBased

      public boolean isSoundBased()
    • hasAttack

      public static boolean hasAttack(String moveName)
      Checks if there is a move with a certain name.
      Parameters:
      moveName - The name of the move to look for.
      Returns:
      Whether there is a move with the specified name.
    • getAttacks

      public static ImmutableAttack[] getAttacks(String[] nameList)
      Gets move details for an array of moves.
      Parameters:
      nameList - The names of the moves to get details for.
      Returns:
      An array of move details corresponding to the specified moves.
    • setOverridePower

      public void setOverridePower(int overridePower)
    • getOverridePower

      public int getOverridePower()
    • setMoveAccuracy

      public void setMoveAccuracy(int moveAccuracy)
    • ignoresWeather

      public boolean ignoresWeather(PixelmonWrapper pw)
      Whether the move has any effect that makes it ignore the weather.
      Parameters:
      pw - The user of the move.
      Returns:
      True if the move ignores the weather.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getMoveResultForPixelmonWrapper

      @Nonnull public SingleInstanceMoveResult getMoveResultForPixelmonWrapper(PixelmonWrapper pw)
      Iterates through the MoveResults.getMoveResultsList() backwards to grab the most recent SingleInstanceMoveResult that has the specified Pixelmon as its target and returns it. If one is not found, a new SingleInstanceMoveResult is created, added to that list, and returned.
      Parameters:
      pw - The Pixelmon that is the target of the attack.
      Returns:
      The most recent SingleInstanceMoveResult for the specified Pixelmon.
    • attackMakesContact

      public boolean attackMakesContact(PixelmonWrapper user, PixelmonWrapper target)
      Checks if the Pokémon's attack makes contact against the target.
      Parameters:
      user - The attacker
      target - The defender
      Returns:
      Whether the Pokémon's attack should be treated as making contact