{
    num: 254,
    accuracy: true,
    basePower: 0,
    category: "Status",
    name: "Stockpile",
    pp: 20,
    priority: 0,
    flags: {snatch: 1, metronome: 1},
    onTry(source) {
        if (source.volatiles['stockpile'] && source.volatiles['stockpile'].layers >= 3) return false;
    },
    volatileStatus: 'stockpile',
    condition: {
        noCopy: true,
        onStart(target) {
            this.effectState.layers = 1;
            this.effectState.def = 0;
            this.effectState.spd = 0;
            this.add('-start', target, 'stockpile' + this.effectState.layers);
            const [curDef, curSpD] = [target.boosts.def, target.boosts.spd];
            this.boost({def: 1, spd: 1}, target, target);
            if (curDef !== target.boosts.def) this.effectState.def--;
            if (curSpD !== target.boosts.spd) this.effectState.spd--;
        },
        onRestart(target) {
            if (this.effectState.layers >= 3) return false;
            this.effectState.layers++;
            this.add('-start', target, 'stockpile' + this.effectState.layers);
            const curDef = target.boosts.def;
            const curSpD = target.boosts.spd;
            this.boost({def: 1, spd: 1}, target, target);
            if (curDef !== target.boosts.def) this.effectState.def--;
            if (curSpD !== target.boosts.spd) this.effectState.spd--;
        },
        onTryEatItem(item, pokemon) {
            if (item.isBerry) {
                if (pokemon.moveThisTurn === 'spitup') return true;
                return false;
            }
        },
        onTakeItem(item, pokemon, source) {
            if (!this.activeMove) throw new Error("Battle.activeMove is null");
            if (!pokemon.hp || pokemon.item === 'stickybarb') return;
            if (item.isBerry && ((source && source !== pokemon) || this.activeMove.id === 'knockoff')) {
                if (pokemon.moveThisTurn === 'spitup') return true;
                this.add('-activate', pokemon, 'move: Stockpile', 'Sticky Hold');
                return false;
            }
        },
        onEnd(target) {
            if (this.effectState.def || this.effectState.spd) {
                const boosts = {};
                if (this.effectState.def) boosts.def = this.effectState.def;
                if (this.effectState.spd) boosts.spd = this.effectState.spd;
                this.boost(boosts, target, target);
            }
            this.add('-end', target, 'Stockpile');
            if (this.effectState.def !== this.effectState.layers * -1 || this.effectState.spd !== this.effectState.layers * -1) {
                this.hint("In Gen 7, Stockpile keeps track of how many times it successfully altered each stat individually.");
            }
        },
    },
    secondary: null,
    target: "self",
    type: "Normal",
    zMove: {effect: 'heal'},
    contestType: "Tough",
}
