Added Comments to Base Classes (#860)

pull/895/head
Benjamin Odom 2024-05-14 23:19:12 -05:00 committed by GitHub
parent 6bed21770d
commit 835b00d457
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 74 additions and 14 deletions

View File

@ -434,29 +434,66 @@ export class SelfStatusMove extends Move {
} }
} }
/**
* Base class defining all {@link Move} Attributes
* @abstract
*/
export abstract class MoveAttr { export abstract class MoveAttr {
/** Should this {@link Move} target the user? */
public selfTarget: boolean; public selfTarget: boolean;
constructor(selfTarget: boolean = false) { constructor(selfTarget: boolean = false) {
this.selfTarget = selfTarget; this.selfTarget = selfTarget;
} }
/**
* Applies move attributes
* @see {@link applyMoveAttrsInternal}
* @virtual
* @param user The {@link Pokemon} using the move
* @param target The target {@link Pokemon} of the move
* @param move The {@link Move} being used
* @param args Set of unique arguments needed by this attribute
* @returns true if the application succeeds
*/
apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean | Promise<boolean> { apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean | Promise<boolean> {
return true; return true;
} }
/**
* @virtual
* @returns the {@link MoveCondition} or {@link MoveConditionFunc} for this {@link Move}
*/
getCondition(): MoveCondition | MoveConditionFunc { getCondition(): MoveCondition | MoveConditionFunc {
return null; return null;
} }
/**
* @virtual
* @param user The {@link Pokemon} using the move
* @param target The target {@link Pokemon} of the move
* @param move The {@link Move} being used
* @param cancelled A {@link Utils.BooleanHolder} which stores if the move should fail
* @returns the string representing failure of this {@link Move}
*/
getFailedText(user: Pokemon, target: Pokemon, move: Move, cancelled: Utils.BooleanHolder): string | null { getFailedText(user: Pokemon, target: Pokemon, move: Move, cancelled: Utils.BooleanHolder): string | null {
return null; return null;
} }
/**
* Used by the Enemy AI to rank an attack based on a given user
* @see {@link EnemyPokemon.getNextMove}
* @virtual
*/
getUserBenefitScore(user: Pokemon, target: Pokemon, move: Move): integer { getUserBenefitScore(user: Pokemon, target: Pokemon, move: Move): integer {
return 0; return 0;
} }
/**
* Used by the Enemy AI to rank an attack based on a given target
* @see {@link EnemyPokemon.getNextMove}
* @virtual
*/
getTargetBenefitScore(user: Pokemon, target: Pokemon, move: Move): integer { getTargetBenefitScore(user: Pokemon, target: Pokemon, move: Move): integer {
return 0; return 0;
} }
@ -470,6 +507,9 @@ export enum MoveEffectTrigger {
POST_TARGET, POST_TARGET,
} }
/** Base class defining all Move Effect Attributes
* @extends MoveAttr
*/
export class MoveEffectAttr extends MoveAttr { export class MoveEffectAttr extends MoveAttr {
public trigger: MoveEffectTrigger; public trigger: MoveEffectTrigger;
public firstHitOnly: boolean; public firstHitOnly: boolean;
@ -480,11 +520,21 @@ export class MoveEffectAttr extends MoveAttr {
this.firstHitOnly = firstHitOnly; this.firstHitOnly = firstHitOnly;
} }
/**
* Determines whether the {@link Move}'s effects are valid to {@link apply}
* @virtual
* @param user The {@link Pokemon} using the move
* @param target The target {@link Pokemon} of the move
* @param move The {@link Move} being used
* @param args Set of unique arguments needed by this attribute
* @returns true if the application succeeds
*/
canApply(user: Pokemon, target: Pokemon, move: Move, args: any[]) { canApply(user: Pokemon, target: Pokemon, move: Move, args: any[]) {
return !!(this.selfTarget ? user.hp && !user.getTag(BattlerTagType.FRENZY) : target.hp) return !!(this.selfTarget ? user.hp && !user.getTag(BattlerTagType.FRENZY) : target.hp)
&& (this.selfTarget || !target.getTag(BattlerTagType.PROTECTED) || move.hasFlag(MoveFlags.IGNORE_PROTECT)); && (this.selfTarget || !target.getTag(BattlerTagType.PROTECTED) || move.hasFlag(MoveFlags.IGNORE_PROTECT));
} }
/** Applies move effects so long as they are able based on {@link canApply} */
apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean | Promise<boolean> { apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean | Promise<boolean> {
return this.canApply(user, target, move, args); return this.canApply(user, target, move, args);
} }
@ -806,8 +856,15 @@ export enum MultiHitType {
_1_TO_10, _1_TO_10,
} }
/**
* Heals the user or target by {@link healRatio} depending on the value of {@link selfTarget}
* @extends MoveEffectAttr
* @see {@link apply}
*/
export class HealAttr extends MoveEffectAttr { export class HealAttr extends MoveEffectAttr {
/** The percentage of {@link Stat.HP} to heal */
private healRatio: number; private healRatio: number;
/** Should an animation be shown? */
private showAnim: boolean; private showAnim: boolean;
constructor(healRatio?: number, showAnim?: boolean, selfTarget?: boolean) { constructor(healRatio?: number, showAnim?: boolean, selfTarget?: boolean) {
@ -822,6 +879,10 @@ export class HealAttr extends MoveEffectAttr {
return true; return true;
} }
/**
* Creates a new {@link PokemonHealPhase}.
* This heals the target and shows the appropriate message.
*/
addHealPhase(target: Pokemon, healRatio: number) { addHealPhase(target: Pokemon, healRatio: number) {
target.scene.unshiftPhase(new PokemonHealPhase(target.scene, target.getBattlerIndex(), target.scene.unshiftPhase(new PokemonHealPhase(target.scene, target.getBattlerIndex(),
Math.max(Math.floor(target.getMaxHp() * healRatio), 1), getPokemonMessage(target, ' \nhad its HP restored.'), true, !this.showAnim)); Math.max(Math.floor(target.getMaxHp() * healRatio), 1), getPokemonMessage(target, ' \nhad its HP restored.'), true, !this.showAnim));
@ -903,7 +964,7 @@ export class IgnoreWeatherTypeDebuffAttr extends MoveAttr {
* @param user Pokemon that used the move * @param user Pokemon that used the move
* @param target N/A * @param target N/A
* @param move Move with this attribute * @param move Move with this attribute
* @param args Utils.NumberHolder for arenaAttackTypeMultiplier * @param args [0] Utils.NumberHolder for arenaAttackTypeMultiplier
* @returns true if the function succeeds * @returns true if the function succeeds
*/ */
apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean {
@ -963,27 +1024,19 @@ export class SandHealAttr extends WeatherHealAttr {
} }
/** /**
* Heals the target by either {@link normalHealRatio} or {@link boostedHealRatio} * Heals the target or the user by either {@link normalHealRatio} or {@link boostedHealRatio}
* depending on the evaluation of {@link condition} * depending on the evaluation of {@link condition}
* @extends HealAttr
* @see {@link apply} * @see {@link apply}
* @param user The Pokemon using this move
* @param target The target Pokemon of this move
* @param move This move
* @param args N/A
* @returns if the move was successful
*/ */
export class BoostHealAttr extends HealAttr { export class BoostHealAttr extends HealAttr {
/** Healing received when {@link condition} is false */
private normalHealRatio?: number; private normalHealRatio?: number;
/** Healing received when {@link condition} is true */
private boostedHealRatio?: number; private boostedHealRatio?: number;
/** The lambda expression to check against when boosting the healing value */
private condition?: MoveConditionFunc; private condition?: MoveConditionFunc;
/**
* @param normalHealRatio Healing received when {@link condition} is false
* @param boostedHealRatio Healing received when {@link condition} is true
* @param showAnim Should a healing animation be showed?
* @param selfTarget Should the move target the user?
* @param condition The condition to check against when boosting the healing value
*/
constructor(normalHealRatio?: number, boostedHealRatio?: number, showAnim?: boolean, selfTarget?: boolean, condition?: MoveConditionFunc) { constructor(normalHealRatio?: number, boostedHealRatio?: number, showAnim?: boolean, selfTarget?: boolean, condition?: MoveConditionFunc) {
super(normalHealRatio, showAnim, selfTarget); super(normalHealRatio, showAnim, selfTarget);
this.normalHealRatio = normalHealRatio; this.normalHealRatio = normalHealRatio;
@ -991,6 +1044,13 @@ export class BoostHealAttr extends HealAttr {
this.condition = condition; this.condition = condition;
} }
/**
* @param user The Pokemon using this move
* @param target The target Pokemon of this move
* @param move This move
* @param args N/A
* @returns true if the move was successful
*/
apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean {
const healRatio = this.condition(user, target, move) ? this.boostedHealRatio : this.normalHealRatio; const healRatio = this.condition(user, target, move) ? this.boostedHealRatio : this.normalHealRatio;
this.addHealPhase(target, healRatio); this.addHealPhase(target, healRatio);