Significantly cleaned up RemoveArenaTrapAttr and RemoveScreensAttr

This commit is contained in:
Bertie690 2025-08-02 16:23:12 -04:00
parent 2439754aed
commit 1b9e4e05ee
2 changed files with 90 additions and 97 deletions

View File

@ -1307,15 +1307,13 @@ export class MoveEffectAttr extends MoveAttr {
* @param args Set of unique arguments needed by this attribute
* @returns true if basic application of the ability attribute should be possible
*/
canApply(user: Pokemon, target: Pokemon, move: Move, args?: any[]) {
return !! (this.selfTarget ? user.hp && !user.getTag(BattlerTagType.FRENZY) : target.hp)
&& (this.selfTarget || !target.getTag(BattlerTagType.PROTECTED) ||
move.doesFlagEffectApply({ flag: MoveFlags.IGNORE_PROTECT, user, target }));
canApply(user: Pokemon, target: Pokemon, move: Move, _args?: any[]) {
return (this.selfTarget ? user : target).hp > 0
}
/** Applies move effects so long as they are able based on {@linkcode canApply} */
apply(user: Pokemon, target: Pokemon, move: Move, args?: any[]): boolean {
return this.canApply(user, target, move, args);
apply(user: Pokemon, target: Pokemon, move: Move, _args?: any[]): boolean {
return this.canApply(user, target, move, _args);
}
/**
@ -5615,9 +5613,10 @@ export class AddBattlerTagAttr extends MoveEffectAttr {
return false;
}
// TODO: Do any moves actually use chance-based battler tag adding?
const moveChance = this.getMoveChance(user, target, move, this.selfTarget, true);
if (moveChance < 0 || moveChance === 100 || user.randBattleSeedInt(100) < moveChance) {
return (this.selfTarget ? user : target).addTag(this.tagType, user.randBattleSeedIntRange(this.turnCountMin, this.turnCountMax), move.id, user.id);
return (this.selfTarget ? user : target).addTag(this.tagType, user.randBattleSeedIntRange(this.turnCountMin, this.turnCountMax), move.id, user.id);
}
return false;
@ -5829,7 +5828,7 @@ export class CurseAttr extends MoveEffectAttr {
* Attribute to remove all {@linkcode BattlerTag}s matching one or more tag types.
*/
export class RemoveBattlerTagAttr extends MoveEffectAttr {
/** An array of {@linkcode BattlerTagType}s to clear. */
/** An array of {@linkcode BattlerTagType}s to clear. */
public tagTypes: [BattlerTagType, ...BattlerTagType[]];
constructor(tagTypes: [BattlerTagType, ...BattlerTagType[]], selfTarget = false) {
@ -5843,7 +5842,7 @@ export class RemoveBattlerTagAttr extends MoveEffectAttr {
return false;
}
(this.selfTarget ? user : target).findAndRemoveTags(t => this.tagTypes.includes(t.tagType));
(this.selfTarget ? user : target).findAndRemoveTags(t => this.tagTypes.includes(t.tagType));
return true;
}
@ -5910,6 +5909,8 @@ export class ProtectAttr extends AddBattlerTagAttr {
}
}
// TODO: Attributes should not exist solely to display a message
export class IgnoreAccuracyAttr extends AddBattlerTagAttr {
constructor() {
super(BattlerTagType.IGNORE_ACCURACY, true, false, 2);
@ -5981,14 +5982,13 @@ export class RemoveAllSubstitutesAttr extends MoveEffectAttr {
export class HitsTagAttr extends MoveAttr {
/** The {@linkcode BattlerTagType} this move hits */
public tagType: BattlerTagType;
/** Should this move deal double damage against {@linkcode HitsTagAttr.tagType}? */
/** Should this move deal double damage against {@linkcode this.tagType}? */
public doubleDamage: boolean;
constructor(tagType: BattlerTagType, doubleDamage: boolean = false) {
constructor(tagType: BattlerTagType) {
super();
this.tagType = tagType;
this.doubleDamage = !!doubleDamage;
}
getTargetBenefitScore(user: Pokemon, target: Pokemon, move: Move): number {
@ -6003,7 +6003,8 @@ export class HitsTagAttr extends MoveAttr {
*/
export class HitsTagForDoubleDamageAttr extends HitsTagAttr {
constructor(tagType: BattlerTagType) {
super(tagType, true);
super(tagType);
this.doubleDamage = true;
}
}
@ -6027,7 +6028,7 @@ export class AddArenaTagAttr extends MoveEffectAttr {
return false;
}
// TODO: Why does this check effect chance if nothing uses it?
// TODO: Why does this check effect chance if nothing uses it?
if ((move.chance < 0 || move.chance === 100 || user.randBattleSeedInt(100) < move.chance) && user.getLastXMoves(1)[0]?.result === MoveResult.SUCCESS) {
const side = ((this.selfSideTarget ? user : target).isPlayer() !== (move.hasAttr("AddArenaTrapTagAttr") && target === user)) ? ArenaTagSide.PLAYER : ArenaTagSide.ENEMY;
globalScene.arena.addTag(this.tagType, this.turnCount, move.id, user.id, side);
@ -6045,19 +6046,22 @@ export class AddArenaTagAttr extends MoveEffectAttr {
}
/**
* Generic class for removing arena tags
* @param tagTypes: The types of tags that can be removed
* @param selfSideTarget: Is the user removing tags from its own side?
* Attribute to remove one or more arena tags from the field.
*/
export class RemoveArenaTagsAttr extends MoveEffectAttr {
public tagTypes: ArenaTagType[];
public selfSideTarget: boolean;
/** An array containing the tags to be removed. */
private readonly tagTypes: readonly [ArenaTagType, ...ArenaTagType[]];
/**
* Whether to remove tags from both sides of the field (`true`) or
* the target's side of the field (`false`); default `false`
*/
private removeAllTags: boolean
constructor(tagTypes: ArenaTagType[], selfSideTarget: boolean) {
super(true);
constructor(tagTypes: readonly [ArenaTagType, ...ArenaTagType[]], removeAllTags = false, options?: MoveEffectAttrOptions) {
super(true, options);
this.tagTypes = tagTypes;
this.selfSideTarget = selfSideTarget;
this.removeAllTags = removeAllTags;
}
apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean {
@ -6065,11 +6069,9 @@ export class RemoveArenaTagsAttr extends MoveEffectAttr {
return false;
}
const side = (this.selfSideTarget ? user : target).isPlayer() ? ArenaTagSide.PLAYER : ArenaTagSide.ENEMY;
const side = this.removeAllTags ? ArenaTagSide.BOTH : target.isPlayer() ? ArenaTagSide.PLAYER : ArenaTagSide.ENEMY;
for (const tagType of this.tagTypes) {
globalScene.arena.removeTagOnSide(tagType, side);
}
globalScene.arena.removeTagsOnSide(this.tagTypes, side);
return true;
}
@ -6115,80 +6117,37 @@ export class AddArenaTrapTagHitAttr extends AddArenaTagAttr {
}
}
export class RemoveArenaTrapAttr extends MoveEffectAttr {
// TODO: Review if we can remove these attributes
const arenaTrapTags = [
ArenaTagType.SPIKES,
ArenaTagType.TOXIC_SPIKES,
ArenaTagType.STEALTH_ROCK,
ArenaTagType.STICKY_WEB,
] as const;
private targetBothSides: boolean;
constructor(targetBothSides: boolean = false) {
super(true, { trigger: MoveEffectTrigger.PRE_APPLY });
this.targetBothSides = targetBothSides;
}
apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean {
if (!super.apply(user, target, move, args)) {
return false;
}
if (this.targetBothSides) {
globalScene.arena.removeTagOnSide(ArenaTagType.SPIKES, ArenaTagSide.PLAYER);
globalScene.arena.removeTagOnSide(ArenaTagType.TOXIC_SPIKES, ArenaTagSide.PLAYER);
globalScene.arena.removeTagOnSide(ArenaTagType.STEALTH_ROCK, ArenaTagSide.PLAYER);
globalScene.arena.removeTagOnSide(ArenaTagType.STICKY_WEB, ArenaTagSide.PLAYER);
globalScene.arena.removeTagOnSide(ArenaTagType.SPIKES, ArenaTagSide.ENEMY);
globalScene.arena.removeTagOnSide(ArenaTagType.TOXIC_SPIKES, ArenaTagSide.ENEMY);
globalScene.arena.removeTagOnSide(ArenaTagType.STEALTH_ROCK, ArenaTagSide.ENEMY);
globalScene.arena.removeTagOnSide(ArenaTagType.STICKY_WEB, ArenaTagSide.ENEMY);
} else {
globalScene.arena.removeTagOnSide(ArenaTagType.SPIKES, target.isPlayer() ? ArenaTagSide.ENEMY : ArenaTagSide.PLAYER);
globalScene.arena.removeTagOnSide(ArenaTagType.TOXIC_SPIKES, target.isPlayer() ? ArenaTagSide.ENEMY : ArenaTagSide.PLAYER);
globalScene.arena.removeTagOnSide(ArenaTagType.STEALTH_ROCK, target.isPlayer() ? ArenaTagSide.ENEMY : ArenaTagSide.PLAYER);
globalScene.arena.removeTagOnSide(ArenaTagType.STICKY_WEB, target.isPlayer() ? ArenaTagSide.ENEMY : ArenaTagSide.PLAYER);
}
return true;
export class RemoveArenaTrapAttr extends RemoveArenaTagsAttr {
constructor(targetBothSides = false) {
// TODO: This triggers at a different time than {@linkcode RemoveArenaTagsAbAttr}...
super(arenaTrapTags, targetBothSides, { trigger: MoveEffectTrigger.PRE_APPLY });
}
}
export class RemoveScreensAttr extends MoveEffectAttr {
private targetBothSides: boolean;
constructor(targetBothSides: boolean = false) {
super(true, { trigger: MoveEffectTrigger.PRE_APPLY });
this.targetBothSides = targetBothSides;
}
apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean {
if (!super.apply(user, target, move, args)) {
return false;
}
if (this.targetBothSides) {
globalScene.arena.removeTagOnSide(ArenaTagType.REFLECT, ArenaTagSide.PLAYER);
globalScene.arena.removeTagOnSide(ArenaTagType.LIGHT_SCREEN, ArenaTagSide.PLAYER);
globalScene.arena.removeTagOnSide(ArenaTagType.AURORA_VEIL, ArenaTagSide.PLAYER);
globalScene.arena.removeTagOnSide(ArenaTagType.REFLECT, ArenaTagSide.ENEMY);
globalScene.arena.removeTagOnSide(ArenaTagType.LIGHT_SCREEN, ArenaTagSide.ENEMY);
globalScene.arena.removeTagOnSide(ArenaTagType.AURORA_VEIL, ArenaTagSide.ENEMY);
} else {
globalScene.arena.removeTagOnSide(ArenaTagType.REFLECT, target.isPlayer() ? ArenaTagSide.PLAYER : ArenaTagSide.ENEMY);
globalScene.arena.removeTagOnSide(ArenaTagType.LIGHT_SCREEN, target.isPlayer() ? ArenaTagSide.PLAYER : ArenaTagSide.ENEMY);
globalScene.arena.removeTagOnSide(ArenaTagType.AURORA_VEIL, target.isPlayer() ? ArenaTagSide.PLAYER : ArenaTagSide.ENEMY);
}
return true;
const screenTags = [
ArenaTagType.REFLECT,
ArenaTagType.LIGHT_SCREEN,
ArenaTagType.AURORA_VEIL
] as const;
export class RemoveScreensAttr extends RemoveArenaTagsAttr {
constructor(targetBothSides = false) {
// TODO: This triggers at a different time than {@linkcode RemoveArenaTagsAbAttr}...
super(arenaTrapTags, targetBothSides, { trigger: MoveEffectTrigger.PRE_APPLY });
}
}
/*Swaps arena effects between the player and enemy side
* @extends MoveEffectAttr
* @see {@linkcode apply}
*/
/**
* Swaps arena effects between the player and enemy side
*/
export class SwapArenaTagsAttr extends MoveEffectAttr {
public SwapTags: ArenaTagType[];
@ -6583,6 +6542,7 @@ export class ChillyReceptionAttr extends ForceSwitchOutAttr {
return (user, target, move) => globalScene.arena.weather?.weatherType !== WeatherType.SNOW || super.getSwitchOutCondition()(user, target, move);
}
}
export class RemoveTypeAttr extends MoveEffectAttr {
private removedType: PokemonType;
@ -8973,7 +8933,7 @@ export function initMoves() {
.attr(AddBattlerTagAttr, BattlerTagType.TRAPPED, false, true, 1)
.reflectable(),
new StatusMove(MoveId.MIND_READER, PokemonType.NORMAL, -1, 5, -1, 0, 2)
.attr(IgnoreAccuracyAttr),
.attr(AddBattlerTagAttr, BattlerTagType.IGNORE_ACCURACY, true, false, 2),
new StatusMove(MoveId.NIGHTMARE, PokemonType.GHOST, 100, 15, -1, 0, 2)
.attr(AddBattlerTagAttr, BattlerTagType.NIGHTMARE)
.condition(targetSleptOrComatoseCondition),
@ -9077,7 +9037,7 @@ export function initMoves() {
.attr(MultiHitAttr)
.makesContact(false),
new StatusMove(MoveId.LOCK_ON, PokemonType.NORMAL, -1, 5, -1, 0, 2)
.attr(IgnoreAccuracyAttr),
.attr(AddBattlerTagAttr, BattlerTagType.IGNORE_ACCURACY, true, false, 2),
new AttackMove(MoveId.OUTRAGE, PokemonType.DRAGON, MoveCategory.PHYSICAL, 120, 100, 10, -1, 0, 2)
.attr(FrenzyAttr)
.attr(MissEffectAttr, frenzyMissFunc)
@ -10581,7 +10541,7 @@ export function initMoves() {
.attr(StatStageChangeAttr, [ Stat.SPD ], -1)
.reflectable(),
new SelfStatusMove(MoveId.LASER_FOCUS, PokemonType.NORMAL, -1, 30, -1, 0, 7)
.attr(AddBattlerTagAttr, BattlerTagType.ALWAYS_CRIT, true, false),
.attr(AddBattlerTagAttr, BattlerTagType.ALWAYS_CRIT, true, false, 2),
new StatusMove(MoveId.GEAR_UP, PokemonType.STEEL, -1, 20, -1, 0, 7)
.attr(StatStageChangeAttr, [ Stat.ATK, Stat.SPATK ], 1, false, { condition: (user, target, move) => !![ AbilityId.PLUS, AbilityId.MINUS ].find(a => target.hasAbility(a, false)) })
.ignoresSubstitute()
@ -10670,7 +10630,7 @@ export function initMoves() {
new AttackMove(MoveId.MALICIOUS_MOONSAULT, PokemonType.DARK, MoveCategory.PHYSICAL, 180, -1, 1, -1, 0, 7)
.unimplemented()
.attr(AlwaysHitMinimizeAttr)
.attr(HitsTagAttr, BattlerTagType.MINIMIZED, true)
.attr(HitsTagForDoubleDamageAttr, BattlerTagType.MINIMIZED)
.edgeCase(), // I assume it's because it needs darkest lariat and incineroar
new AttackMove(MoveId.OCEANIC_OPERETTA, PokemonType.WATER, MoveCategory.SPECIAL, 195, -1, 1, -1, 0, 7)
.unimplemented()
@ -11298,6 +11258,7 @@ export function initMoves() {
.attr(AddBattlerTagAttr, BattlerTagType.ALWAYS_GET_HIT, true, false, 0, 0, true)
.attr(AddBattlerTagAttr, BattlerTagType.RECEIVE_DOUBLE_DAMAGE, true, false, 0, 0, true)
.condition((user, target, move) => {
// TODO: This is really really really janky
return !(target.getTag(BattlerTagType.PROTECTED)?.tagType === "PROTECTED" || globalScene.arena.getTag(ArenaTagType.MAT_BLOCK)?.tagType === "MAT_BLOCK");
}),
new StatusMove(MoveId.REVIVAL_BLESSING, PokemonType.NORMAL, -1, 1, -1, 0, 9)

View File

@ -718,7 +718,7 @@ export class Arena {
}
// creates a new tag object
const newTag = getArenaTag(tagType, turnCount || 0, sourceMove, sourceId, side);
const newTag = getArenaTag(tagType, turnCount, sourceMove, sourceId, side);
if (newTag) {
newTag.onAdd(this, quiet);
this.tags.push(newTag);
@ -834,6 +834,38 @@ export class Arena {
return !!tag;
}
/**
* Find and remove all {@linkcode ArenaTag}s with the given tag types on the given side of the field.
* @param tagTypes - The {@linkcode ArenaTagType}s to remove
* @param side - The {@linkcode ArenaTagSide} to remove the tags from (for side-based tags), or {@linkcode ArenaTagSide.BOTH}
* to clear all tags on either side of the field
* @param quiet - Whether to suppress removal messages from currently-present tags; default `false`
* @todo Review the other tag manipulation functions to see if they can be migrated towards using this (more efficient)
*/
public removeTagsOnSide(
tagTypes: ArenaTagType[] | ReadonlyArray<ArenaTagType>,
side: ArenaTagSide,
quiet = false,
): void {
const indicesToRemove: number[] = [];
for (const [i, tag] of this.tags.entries()) {
// Skip tags of different types or on the wrong side of the field
if (!tagTypes.includes(tag.tagType)) {
continue;
}
if (!(side === ArenaTagSide.BOTH || tag.side === ArenaTagSide.BOTH || tag.side === side)) {
continue;
}
indicesToRemove.push(i);
}
for (const index of indicesToRemove) {
this.tags[index].onRemove(this, quiet);
this.tags.splice(index, 1);
}
}
removeAllTags(): void {
while (this.tags.length) {
this.tags[0].onRemove(this);