"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Routine = exports.InitRoutine = exports.getDefault = exports.recoverType = exports.diType = void 0;
const animation_1 = require("./animation");
const engine_1 = require("./engine");
const math_1 = require("./math");
var diType;
(function (diType) {
    diType[diType["none"] = 0] = "none";
    diType[diType["fullRandom"] = 1] = "fullRandom";
})(diType = exports.diType || (exports.diType = {}));
var recoverType;
(function (recoverType) {
    recoverType[recoverType["none"] = 0] = "none";
    recoverType[recoverType["in"] = 1] = "in";
})(recoverType = exports.recoverType || (exports.recoverType = {}));
const getDefault = () => {
    return {
        di: 0,
        recover: 0,
        tech: false,
        alwaysShield: false,
        shieldClose: false,
        shakeout: true,
        init: exports.InitRoutine.default,
        tick: exports.Routine.default,
        listeners: {
            listeners: {
                tech: (_entity) => {
                    const r = math_1.lqrandomSync();
                    if (r < 0.1) {
                        return 'miss';
                    }
                    if (r < 0.5) {
                        return 'tech';
                    }
                    if (r < 0.75) {
                        return 'techforth';
                    }
                    return 'techback';
                },
                walltech: (_entity) => {
                    return math_1.lqrandomSync() < 0.9;
                },
                di: (_entity, _angle) => {
                    return math_1.lqrandomSync() * 360;
                },
                shakeout: (_entity) => {
                    return true;
                },
            },
        },
    };
};
exports.getDefault = getDefault;
exports.InitRoutine = {
    default: (entity, _settings, _frame) => {
        entity.aidata = {
            undoNum: new Set(),
        };
    },
};
exports.Routine = {
    default: (entity, settings, frame) => {
        const aidata = entity.aidata;
        for (const prop of aidata.undoNum) {
            ;
            frame[prop] = 0;
        }
        aidata.undoNum.clear();
        if (entity.airborne && entity.hover === null && entity.animation !== 'airjump0') {
            frame.hmove = Math.sign(-entity.x);
            aidata.undoNum.add('hmove');
            if (entity.stun <= 0 && entity.lag <= 0
                && (entity.activeAnimation.type === animation_1.AnimationType.movement
                    || entity.activeAnimation.type === animation_1.AnimationType.passive)) {
                if (entity.dy < -3 && entity.y > 0) {
                    if (entity.animations['airjump' + entity.airjumps]
                        || (entity.animations['airjumpN']
                            && entity.animations['airjumpN'].data.get('jumps') > entity.airjumps)) {
                        if (math_1.lqrandomSync() > 0.5) {
                            frame.jump = 1;
                            aidata.undoNum.add('jump');
                        }
                    }
                    else {
                        if (math_1.lqrandomSync() > 0.5) {
                            frame.vmove = -0.78;
                            frame.hmove = 0.78 * entity.face;
                            frame.special = 1;
                            aidata.undoNum.add('special');
                        }
                    }
                }
            }
        }
        if (!entity.airborne) {
            if (settings.shieldClose) {
                for (let i = 0; i < engine_1.entities.length; i++) {
                    const e = engine_1.entities[i];
                    if (e !== entity && Math.abs(entity.x - e.x) < 100 && Math.abs(entity.y - e.y) < 200) {
                        frame.shield1 = 1;
                        aidata.undoNum.add('shield1');
                    }
                }
            }
            else if (settings.alwaysShield) {
                frame.shield1 = 1;
                aidata.undoNum.add('shield1');
            }
        }
    },
};
//# sourceMappingURL=ai.js.map