[Move] Implement Punishment (#1610)

* Implement Punishment and reopen pull request 373

* Fix console log and ()
This commit is contained in:
Ethan 2024-05-30 17:01:42 -04:00 committed by GitHub
parent 2fd87a3cad
commit d70ab3eaf6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -2704,12 +2704,57 @@ export class HitCountPowerAttr extends VariablePowerAttr {
} }
} }
/**
* Turning a once was (StatChangeCountPowerAttr) statement and making it available to call for any attribute.
* @param {Pokemon} pokemon The pokemon that is being used to calculate the count of positive stats
* @returns {number} Returns the amount of positive stats
*/
const countPositiveStats = (pokemon: Pokemon): number => {
return pokemon.summonData.battleStats.reduce((total, stat) => (stat && stat > 0) ? total + stat : total, 0);
};
/**
* Attribute that increases power based on the amount of positive stat increases.
*/
export class StatChangeCountPowerAttr extends VariablePowerAttr { export class StatChangeCountPowerAttr extends VariablePowerAttr {
/**
* @param {Pokemon} user The pokemon that is being used to calculate the amount of positive stats
* @param {Pokemon} target N/A
* @param {Move} move N/A
* @param {any[]} args The argument for VariablePowerAttr, accumulates and sets the amount of power multiplied by stats
* @returns {boolean} Returns true if attribute is applied
*/
apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean {
const positiveStats: number = user.summonData.battleStats.reduce((total, stat) => stat > 0 && stat ? total + stat : total, 0); const positiveStats: number = countPositiveStats(user);
(args[0] as Utils.NumberHolder).value += positiveStats * 20; (args[0] as Utils.NumberHolder).value += positiveStats * 20;
return true;
}
}
/**
* Punishment normally has a base power of 60,
* but gains 20 power for every increased stat stage the target has,
* up to a maximum of 200 base power in total.
*/
export class PunishmentPowerAttr extends VariablePowerAttr {
private PUNISHMENT_MIN_BASE_POWER = 60;
private PUNISHMENT_MAX_BASE_POWER = 200;
/**
* @param {Pokemon} user N/A
* @param {Pokemon} target The pokemon that the move is being used against, as well as calculating the stats for the min/max base power
* @param {Move} move N/A
* @param {any[]} args The value that is being changed due to VariablePowerAttr
* @returns Returns true if attribute is applied
*/
apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean {
const positiveStats: number = countPositiveStats(target);
(args[0] as Utils.NumberHolder).value = Math.min(
this.PUNISHMENT_MAX_BASE_POWER,
this.PUNISHMENT_MIN_BASE_POWER + positiveStats * 20
);
return true; return true;
} }
} }
@ -6065,7 +6110,8 @@ export function initMoves() {
new StatusMove(Moves.GUARD_SWAP, Type.PSYCHIC, -1, 10, -1, 0, 4) new StatusMove(Moves.GUARD_SWAP, Type.PSYCHIC, -1, 10, -1, 0, 4)
.unimplemented(), .unimplemented(),
new AttackMove(Moves.PUNISHMENT, Type.DARK, MoveCategory.PHYSICAL, -1, 100, 5, -1, 0, 4) new AttackMove(Moves.PUNISHMENT, Type.DARK, MoveCategory.PHYSICAL, -1, 100, 5, -1, 0, 4)
.unimplemented(), .makesContact(true)
.attr(PunishmentPowerAttr),
new AttackMove(Moves.LAST_RESORT, Type.NORMAL, MoveCategory.PHYSICAL, 140, 100, 5, -1, 0, 4) new AttackMove(Moves.LAST_RESORT, Type.NORMAL, MoveCategory.PHYSICAL, 140, 100, 5, -1, 0, 4)
.attr(LastResortAttr), .attr(LastResortAttr),
new StatusMove(Moves.WORRY_SEED, Type.GRASS, 100, 10, -1, 0, 4) new StatusMove(Moves.WORRY_SEED, Type.GRASS, 100, 10, -1, 0, 4)