{
    onBeforeTurn(pokemon) {
        for (const side of this.sides) {
            if (side.hasAlly(pokemon)) continue;
            side.addSideCondition('arenatrap', pokemon);
            const data = side.getSideConditionData('arenatrap');
            if (!data.sources) {
                data.sources = [];
            }
            data.sources.push(pokemon);
        }
    },
    onBasePower(relayVar, source, target, move) {
        if ((target.beingCalledBack || target.switchFlag) && target.isGrounded()) {
            this.debug('arenatrap damage boost');
            return move.basePower * 2;
        }
        return move.basePower;
    },
    condition: {
        duration: 1,
        onBeforeSwitchOut(pokemon) {
            if (!pokemon.isGrounded()) return;

            const move = this.queue.willMove(pokemon.foes()[0]);
            const moveName = move?.moveid?.toString() || "";
            this.debug('arenatrap activation');
            let alreadyAdded = false;
            pokemon.removeVolatile('destinybond');

            for (const source of this.effectState.sources) {
                if (!source.isAdjacent(pokemon) || !this.queue.cancelMove(source) || !source.hp) continue;
                if (!alreadyAdded) {
                    this.add('-activate', pokemon.foes()[0], 'ability: Arena Trap');
                    alreadyAdded = true;
                }
                if (source.canMegaEvo || source.canUltraBurst) {
                    for (const [actionIndex, action] of this.queue.entries()) {
                        if (action.pokemon === source && action.choice === 'megaEvo') {
                            this.actions.runMegaEvo(source);
                            this.queue.list.splice(actionIndex, 1);
                            break;
                        }
                    }
                }
                this.actions.runMove(moveName, source, source.getLocOf(pokemon));
            }
        },
    },
    flags: {},
    name: "Arena Trap",
    rating: 5,
    num: 71
}
