"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const JSONC = require("jsonc-parser");
const engine_1 = require("../src/engine");
const Utils = require("../src/utils");
const [character, anims] = Utils.getCharacterFiles('Iron', 'iron.json', 'iron_anim.json');
const build = (includeAnimations) => {
    const c = JSONC.parse(character.content);
    if (includeAnimations) {
        c.animations = JSONC.parse(anims.content);
    }
    return c;
};
engine_1.registerEntity('Iron', build, {
    gsHandler: (entity, controller, _animation) => {
        if (!controller.special) {
            entity.schedule('groundspecial3');
        }
    },
    airssStart: (entity, _controller, _animation) => {
        entity.dy = Math.max(entity.dy, 6 * (1 / Math.max(entity.pseudojumps, 1)));
        entity.fastfall = false;
    },
    usHandler: (entity, controller, animation) => {
        if (animation.keyframe === 3) {
            entity.dx
                = entity.dx
                    + 0.666 * controller.hmove * (animation.midframe / animation.frameDuration);
        }
    },
    asHandler: (entity, controller, _animation) => {
        if (!controller.special) {
            entity.schedule('airspecial3');
        }
    },
    asEndStart: (entity, _controller, _animation) => {
        if (entity.airborne) {
            entity.dy = 9;
        }
    },
    adStart: (entity, _controller, _animation) => {
        entity.fastfall = false;
    },
    adJump: (entity, _controller, _animation) => {
        entity.dy = Math.max(entity.dy, 3 * (1 / Math.max(entity.pseudojumps, 1)));
        entity.fastfall = false;
    },
    adTurn: (entity, controller, _animation) => {
        if (Math.abs(controller.hmove) > 0.2) {
            entity.face = Math.sign(controller.hmove);
        }
    },
    airusHandler: (entity, controller, animation) => {
        const controllerHorizontal = Math.abs(controller.hmove) * controller.hmove;
        const controllerVertical = -Math.abs(controller.vmove) * controller.vmove;
        if (animation.keyframe === 0) {
            entity.dy = entity.dx * 0.5;
            entity.dx = entity.dy * 0.9;
        }
        else if (animation.keyframe === 1 || animation.keyframe === 2) {
            if (!entity.airborne) {
                entity.airborne = true;
            }
            entity.dy
                = entity.dy * 0.9 + 0.8 * (animation.midframe / animation.frameDuration);
            entity.dx = entity.dx * 0.9;
        }
        else if (animation.keyframe === 3 && animation.midframe === 0) {
            entity.dx
                = entity.dx
                    + 3 * entity.face
                    + controllerHorizontal * 2.5
                    + 3 * controllerVertical * entity.face;
        }
        else if (animation.keyframe === 4 && animation.midframe === 0) {
            if (!entity.airborne) {
                entity.airborne = true;
            }
            entity.dy
                = 8 + 7 * controllerVertical - 2.5 * controllerHorizontal * entity.face;
            entity.dx
                = 4 * entity.face
                    + controllerHorizontal * 9
                    + 1.5 * controllerVertical * entity.face;
        }
    },
});
//# sourceMappingURL=iron.js.map