refactoring solution to individual attr

This commit is contained in:
DustinLin 2024-09-05 09:54:41 -07:00
parent 0c7c3ba218
commit 47e0890265

View File

@ -111,7 +111,6 @@ export enum MoveFlags {
type MoveConditionFunc = (user: Pokemon, target: Pokemon, move: Move) => boolean;
type UserMoveConditionFunc = (user: Pokemon, move: Move) => boolean;
type MoveApplyFunc = (user:Pokemon, target: Pokemon, move: Move, args: any[]) => boolean| Promise<Boolean>;
export default class Move implements Localizable {
public id: Moves;
@ -5124,39 +5123,20 @@ export class ForceSwitchOutAttr extends MoveEffectAttr {
}
}
export class StatusForceSwitchOutAttr extends ForceSwitchOutAttr {
// inherit from ForceSwitchOutAttr
/** the extra apply function to be called */
private statusApplyFunc: MoveApplyFunc;
/** the extra status check to be called */
private statusCondFunc: MoveConditionFunc ;
export class ChillyReceptionAttr extends ForceSwitchOutAttr {
/**
* This class extends ForceSwitchOutAttr, we can think of this class as ForceSwitchOut with "something extra" in it's apply() and getConditions() functions
* @param user boolean for if this is the user switching out
* @param batonPass boolean if the switch is baton pass
* @param statusApplyFunc {@linkcode MoveApplyFunc} the additional apply() function to run
* @param statusCondFunc {@linkcode MoveConditionFunc} the additional move condition function to run
*/
constructor(user?: boolean, batonPass?: boolean, statusApplyFunc?, statusCondFunc? ) {
super(user, batonPass);
this.statusApplyFunc = statusApplyFunc;
this.statusCondFunc = statusCondFunc;
}
// using inherited constructor
apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): Promise<boolean> {
this.statusApplyFunc(user, target, move, args);
user.scene.arena.trySetWeather(WeatherType.SNOW, true);
return super.apply(user, target, move, args);
}
getCondition(): MoveConditionFunc {
// returns True/False for if the move should fail or not: currently logic is an OR. ie: if either condition returns true, then the move should be executed
return (user, target, move) => this.statusCondFunc(user, target, move) || super.getSwitchOutCondition()(user, target, move);
// chilly reception move will go through if the weather is change-able to snow, or the user can switch out, else move will fail
return (user, target, move) => user.scene.arena.trySetWeather(WeatherType.SNOW, true) || super.getSwitchOutCondition()(user, target, move);
}
}
export class RemoveTypeAttr extends MoveEffectAttr {
@ -9194,10 +9174,7 @@ export function initMoves() {
.unimplemented(),
new SelfStatusMove(Moves.CHILLY_RECEPTION, Type.ICE, -1, 10, -1, 0, 9)
.attr(PreMoveMessageAttr, (user, move) => i18next.t("moveTriggers:chillyReception", {pokemonName: getPokemonNameWithAffix(user)}))
.attr(StatusForceSwitchOutAttr, true, false,
(user: Pokemon, target: Pokemon, move: Move, args: any[]) => user.scene.arena.trySetWeather(WeatherType.SNOW, true),
(user, target, move) => (user.scene.arena.weather?.weatherType === WeatherType.SNOW) ? false : true
),
.attr(ChillyReceptionAttr, true, false),
new SelfStatusMove(Moves.TIDY_UP, Type.NORMAL, -1, 10, -1, 0, 9)
.attr(StatStageChangeAttr, [ Stat.ATK, Stat.SPD ], 1, true, null, true, true)
.attr(RemoveArenaTrapAttr, true),