"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const JSONC = require("jsonc-parser");
const animation_1 = require("../src/animation");
const engine_1 = require("../src/engine");
const Utils = require("../src/utils");
const [character, anims] = Utils.getCharacterFiles('Helium', 'helium.json', 'helium_anim.json');
const build = (includeAnimations) => {
    const c = JSONC.parse(character.content);
    if (includeAnimations) {
        c.animations = JSONC.parse(anims.content);
    }
    return c;
};
engine_1.registerEntity('Helium', build, {
    airss: (entity, controller, animation) => {
        if (animation.keyframe > 5
            && !controller.special
            && animation.midframe >= animation.frameDuration - 1) {
            entity.setAnimation('airsidespecial2', true);
        }
        if (!Utils.objHas(animation.keyframeData, 'nodi')) {
            entity.dx = entity.dx * 0.9;
            if (!entity.airborne) {
                entity.dx = entity.dx + controller.hmove * 0.75;
            }
        }
    },
    airss1Start: (entity, controller, _animation) => {
        const diff = 4 - entity.dy;
        entity.dy
            = entity.dy + diff * (1 - (1 - 1 / Math.max(entity.pseudojumps, 1)) ** 2);
        entity.dx = 4 * controller.hmove + 4 * entity.face;
        entity.fastfall = false;
    },
    airds2Start: (entity, _controller, _animation) => {
        entity.airborne = true;
        entity.dy = 6;
        entity.dx = entity.face * 14;
    },
    airdsOnHit: (b, _hb) => {
        b.entity.dy = Math.min(b.entity.dy + 10, 8);
        b.entity.dx = b.entity.dx - b.entity.face * 4;
        b.entity.schedule('airdownspecial2', true);
    },
    airs1Handler: (entity, controller, _animation) => {
        entity.hurtbubbles[3].x2 = controller.hmove * 40;
        entity.hurtbubbles[3].y2 = controller.vmove * 25 - 10;
    },
    airs2Start: (entity, controller, animation) => {
        if (!animation.data.has('bubble')) {
            animation.data.set('bubble', animation_1.Hitbubble.from(entity, {
                type: 'special',
                radius: 12,
                damage: 7,
                knockback: 5,
                growth: 15,
                angle: 50,
            }));
        }
        animation.data.get('bubble').x = controller.hmove * 45 * entity.face;
        animation.data.get('bubble').y = controller.vmove * -25 + 10;
    },
    airs2Handler: (entity, _controller, animation) => {
        entity.hurtbubbles[3].x2 = animation.data.get('bubble').x * entity.face;
        entity.hurtbubbles[3].y2 = -animation.data.get('bubble').y;
        entity.addHitbubble(animation.data.get('bubble'));
    },
    airs3Handler: (entity, _controller, animation) => {
        entity.hurtbubbles[3].x2
            = entity.face
                * animation.data.get('bubble').x
                * (1 - animation.midframe / animation.frameDuration);
        entity.hurtbubbles[3].y2
            = -animation.data.get('bubble').y
                * (1 - animation.midframe / animation.frameDuration);
    },
    airusEnd: (entity, _controller, _animation) => {
        if (entity.airjumps >= entity.animations['airjumpN'].data.get('jumps')) {
            entity.schedule('helpless', true);
        }
        if (!entity.airborne) {
            entity.schedule('airborne-cancel', true);
        }
    },
    airus1Start: (entity, controller, _animation) => {
        const j = entity.animations['airjumpN'];
        entity.dy
            = j.data.get('upward')
                + 0.5
                - (j.data.get('jumpDecay') ? j.data.get('jumpDecay') * entity.airjumps : 0);
        if (controller.hmove > 0.5) {
            entity.face = 1;
        }
        if (controller.hmove < -0.5) {
            entity.face = -1;
        }
        entity.dx = entity.dx + entity.face * 7;
    },
    'airusHandler.2': (entity, controller, _animation) => {
        if (entity.airjumps < entity.animations['airjumpN'].data.get('jumps')
            && (controller.jumpPress || controller.specialPress)) {
            entity.airjumps++;
            entity.schedule('airupspecial', true);
        }
    },
    nairHandler: (entity, controller, animation) => {
        if (animation.frame > 12 && controller.attackPress) {
            entity.schedule('nair');
        }
    },
    dair1Handler: (entity, _controller, _animation) => {
        entity.dx *= 0.98;
        if (entity.dy < 0) {
            entity.dy *= 0.95;
        }
        else {
            entity.dy += 0.33;
        }
    },
    dair2Start: (entity, _controller, _animation) => {
        entity.dx *= 0.75;
    },
    dair2Handler: (entity, _controller, _animation) => {
        entity.dy = -12;
    },
    dair5Start: (entity, _controller, _animation) => {
        entity.dy *= 0.25;
    },
});
//# sourceMappingURL=helium.js.map