From 2a666ef3a9abe36cc49a19138d6f65b8b64bec49 Mon Sep 17 00:00:00 2001 From: Marek Sison Date: Wed, 22 May 2024 14:43:14 +0800 Subject: [PATCH] UPDATE: cleaned up code and added details to documentation --- src/data/move.ts | 130 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 91 insertions(+), 39 deletions(-) diff --git a/src/data/move.ts b/src/data/move.ts index 371851094be..430a4cacde9 100644 --- a/src/data/move.ts +++ b/src/data/move.ts @@ -949,8 +949,13 @@ export class HealAttr extends MoveEffectAttr { Math.max(Math.floor(target.getMaxHp() * healRatio), 1), getPokemonMessage(target, ' \nhad its HP restored.'), true, !this.showAnim)); } + /** + * Returns the healRatio. If h is greater than -1, healRatio is set as h first. + * @param h this is the int the healRatio is set to @default -1 + * @returns this class' {@link this.healRatio} + */ getHealRatio(h: number = -1){ - if (h > 0) + if (h > -1) this.healRatio = h; return this.healRatio; @@ -963,24 +968,37 @@ export class HealAttr extends MoveEffectAttr { } /** - * Attribute used by the {@link Moves.STOCKPILE} to heal based on STOCKPILE stored + * Attribute used by the {@link Moves.STOCKPILE} to heal based on STOCKPILE BattlerTags stored * @extends HealAttr + * @see {@linkcode apply} */ export class SwallowHealAttr extends HealAttr { + + /** + * @construct HealAttr as normal. Variable heal will be set in {@linkcode apply} + */ constructor() { super(1, true, true); } - + + /** + * Sets the healing ratio based on amount of STOCKPILE BattlerTags stored + * + * Amount of STOCKPILE BattlerTags on user is stored in the variable stock + * Then stock is checked; if stock is: + * 1, then healing is 0.25 of health + * 2, then healing is 0.50 of health + * 3, then healing is 1.00 of health + * + * @param user {@linkcode Pokemon} using this move + * @param target {@linkcode Pokemon} target of this move + * @param move {@linkcode Move} being used + * @param args [0] {@linkcode Utils.NumberHolder} for arenaAttackTypeMultiplier + * @returns true if the function succeeds + */ apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { - // uses the getStockpiles function to get number of STOCKPILE's stored const stock = getStockpiles(user); - /** - * if stock is: - * 1, then healing is 0.25 of health - * 2, then healing is 0.50 of health - * 3, then healing is 1.00 of health - */ this.getHealRatio(stock >= 3 ? 1 : (stock * 0.25)); super.apply(user, target, move, args); @@ -1891,29 +1909,47 @@ export class GrowthStatChangeAttr extends StatChangeAttr { /** * Attribute for the stat changes for {@link Move.STOCKPILE}, {@link Move.SPIT_UP}, and {@link Move.SWALLOW} + * + * @prop @private tagTypes - an array of the 3 STOCKPILE BattleTags + * * @extends StatChangeAttr + * @see {@linkcode apply} */ export class StockpileStatChangeAttr extends StatChangeAttr { private tagTypes = [BattlerTagType.STOCKPILE_ONE, BattlerTagType.STOCKPILE_TWO, BattlerTagType.STOCKPILE_THREE]; - // this will show if we will gain 1 stack of stats with Stockpile - // or lose stacks of stats with Spit Up or Swallow - private gainStats:boolean; + /** + * @construct StatChangeAttr with BattleStat.DEF and BattleStat.SPDEF + * for moves associated with the STOCKPILE Battler Tags + * + * @param gainsStats - boolean serving as a switch for this Attr: + * - if true, we save 1 under levels + * - if false, we save -1 under levels + */ constructor(gainStats:boolean = true) { - super([ BattleStat.DEF, BattleStat.SPDEF ], 1, true); - - this.gainStats = gainStats; + super( + [ BattleStat.DEF, BattleStat.SPDEF ], + gainStats ? 1 : -1, + true); } + /** + * This applies the state changes as normal in {@link StatChangeAttr} + * if this.levels is negative, however: + * first, multiply this.levels by stock (so that stats get removed based on number of stock) + * second, this goes through the class @prop tagTypes and removes them from the user + * + * @param user {@linkcode Pokemon} using this move + * @param target {@linkcode Pokemon} target of this move + * @param move {@linkcode Move} being used + * @param args [0] {@linkcode Utils.NumberHolder} for arenaAttackTypeMultiplier + * @returns true if the function succeeds + */ apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean | Promise { const stock = getStockpiles(user); - if (!this.gainStats) { - /** - * since the Pokemon will be losing stats in this if statement, - * {@link this.levels} become equal to the negative of stock - */ - this.levels = stock * -1; + if (this.levels < 0) { + this.levels *= stock; // remove the stats equal to the number of stocks for (let tagType of this.tagTypes) @@ -2492,19 +2528,23 @@ export class WaterShurikenPowerAttr extends VariablePowerAttr { /** * Attribute used by the {@link Moves.SPIT_UP} based on the number of stored STOCKPILE BattlerTagTypes * @extends VariablePowerAttr + * @see {@linkcode apply} */ export class SpitUpPowerAttr extends VariablePowerAttr { + + /** + * This sets the power based on number of STOCKPILE BattlerTags on the user + * Power is number of stock multiplied by 100 + * + * @param user {@linkcode Pokemon} using this move + * @param target {@linkcode Pokemon} target of this move + * @param move {@linkcode Move} being used + * @param args [0] {@linkcode Utils.NumberHolder} for arenaAttackTypeMultiplier + * @returns true if the function succeeds + */ apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { const power = args[0] as Utils.NumberHolder; - - /** - * if stock is: - * 1, then power is 100 - * 2, then power is 100 - * 3, then power is 100 - */ power.value = getStockpiles(user)*100; - return true; } } @@ -3380,24 +3420,37 @@ export class FaintCountdownAttr extends AddBattlerTagAttr { /** * Attribute used by the {@link Moves.STOCKPILE} to add the STOCKPILE BattlerTagTypes * @extends AddBattlerTagTypeAttr + * {@linkcode apply} */ export class StockpileAttr extends AddBattlerTagAttr { + + /** + * @construct StockpileChangeAttr as an AddBattlerTagAttr + * @prop tagType is @default BattlerTagType.STOCKPILE_THREE + */ constructor() { super(BattlerTagType.STOCKPILE_THREE, true, false, 20, 20); } /** - * This changes {@link this.tagType} based on the {@link stock} of the user - * @param user is needed to retrieve how much stockpile the Pokemon has - * as well as its name for the message + * This changes the @prop tagType based on the {@link stock} of the user + * if stock is: + * 0 - tagType should be BattlerTagType.STOCKPILE_ONE + * 1 - tagType should be BattlerTagType.STOCKPILE_TWO + * 2 - tagType should be BattlerTagType.STOCKPILE_THREE + * + * a localised message is then queued + * + * @param user {@linkcode Pokemon} using this move. It's needed to retrieve + * how much stockpile the Pokemon has as well as its name for the message + * @param target {@linkcode Pokemon} target of this move + * @param move {@linkcode Move} being used + * @param args [0] {@linkcode Utils.NumberHolder} for arenaAttackTypeMultiplier + * @returns true if the function succeeds */ apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { const stock = getStockpiles(user); - // boolean failsafe that the tag will not apply when inappropriate - let willFail = false; - // check how many stock the user has then change the tag based on that - // keep the STOCKPILE_THREE tag if the stock is 2 or more switch (stock){ case 0: this.tagType = BattlerTagType.STOCKPILE_ONE; @@ -3406,8 +3459,7 @@ export class StockpileAttr extends AddBattlerTagAttr { this.tagType = BattlerTagType.STOCKPILE_TWO; break; default: - if (stock == 3) - willFail = true; + // keep tagType at default break; }