{
    name: "Funeral",
    rating: 4.0,
    num: -356004,
    onModifyMovePriority: -5,
    onModifyMove(move) {
      if (!move.ignoreImmunity)
        move.ignoreImmunity = {};
      if (move.ignoreImmunity !== true) {
        move.ignoreImmunity["Ghost"] = true;
        move.ignoreImmunity["Normal"] = true;
      }
    },
    onAfterMoveSecondarySelf(source, target, move) {
        
        if (move.category === 'Status') return;
        
        
        if (this.randomChance(20, 100)) {
            
            if (target.volatiles['confusion'] || target.hasAbility(['owntempo', 'aromacase'])) {
                this.add('-immune', target, '[from] ability: Funeral');
                return;
            }
            
            
            target.addVolatile('confusion', source);
            this.add('-activate', source, 'ability: Funeral',);
        }
    },
    
    
    onBasePowerPriority: 21,
    onBasePower(basePower, attacker, defender, move) {
        if (move.category === 'Status') return;
        
        let shouldBoost = false;
        
        
        if (defender.volatiles['confusion']) {
            shouldBoost = true;
        }
        
        
        if (!shouldBoost && defender.hp && defender.maxhp) {
            const hpPercent = (defender.hp / defender.maxhp) * 100;
            if (hpPercent < 50) {
                shouldBoost = true;
            }
        }
        
        
        if (shouldBoost) {
            return this.chainModify(1.5);
        }
    },
    
    
    onBeforeMove(source, target, move) {
        if (move.category === 'Status') return;
        
        
        const isConfused = target.volatiles['confusion'];
        const isLowHP = target.hp && target.maxhp && (target.hp / target.maxhp * 100) < 50;
        
        if (isConfused || isLowHP) {
            this.add('-activate', source, 'ability: Funeral');
        }
    }
}