From bf7eb52f852de0e10f8d8d4316f4ebcbb4460d2b Mon Sep 17 00:00:00 2001 From: Philippe <56865723+prateau@users.noreply.github.com> Date: Sun, 16 Jun 2024 04:24:38 +0200 Subject: [PATCH] [Move] Implement poltergeist (#1726) * implement poltergeist * add comments * use string interpolation --- src/data/move.ts | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/src/data/move.ts b/src/data/move.ts index 85b93c2a289..96b7f370737 100644 --- a/src/data/move.ts +++ b/src/data/move.ts @@ -5291,6 +5291,32 @@ export class LastResortAttr extends MoveAttr { } } + +/** + * The move only works if the target has a transferable held item + * @extends MoveAttr + * @see {@linkcode getCondition} + */ +export class AttackedByItemAttr extends MoveAttr { + /** + * @returns the {@linkcode MoveConditionFunc} for this {@linkcode Move} + */ + getCondition(): MoveConditionFunc { + return (user: Pokemon, target: Pokemon, move: Move) => { + const heldItems = target.getHeldItems().filter(i => i.getTransferrable(true)); + if (heldItems.length === 0) { + return false; + } + + const itemName = heldItems[0]?.type?.name ?? "item"; + const attackedByItemString = ` is about to be attacked by its ${itemName}!`; + target.scene.queueMessage(getPokemonMessage(target, attackedByItemString)); + + return true; + }; + } +} + export class VariableTargetAttr extends MoveAttr { private targetChangeFunc: (user: Pokemon, target: Pokemon, move: Move) => number; @@ -7764,8 +7790,8 @@ export function initMoves() { new AttackMove(Moves.LASH_OUT, Type.DARK, MoveCategory.PHYSICAL, 75, 100, 5, -1, 0, 8) .partial(), new AttackMove(Moves.POLTERGEIST, Type.GHOST, MoveCategory.PHYSICAL, 110, 90, 5, -1, 0, 8) - .makesContact(false) - .partial(), + .attr(AttackedByItemAttr) + .makesContact(false), new StatusMove(Moves.CORROSIVE_GAS, Type.POISON, 100, 40, -1, 0, 8) .target(MoveTarget.ALL_NEAR_OTHERS) .unimplemented(),