"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Mage = void 0;
const Constants_1 = require("./Constants");
const index_1 = require("./index");
const PingCompensatedCharacter_1 = require("./PingCompensatedCharacter");
class Mage extends PingCompensatedCharacter_1.PingCompensatedCharacter {
    alchemy() {
        const alchemied = new Promise((resolve, reject) => {
            const cooldownCheck = (data) => {
                if (/skill_timeout\s*\(\s*['"]alchemy['"]\s*,?\s*(\d+\.?\d+?)?\s*\)/.test(data.code)) {
                    this.socket.removeListener("eval", cooldownCheck);
                    resolve();
                }
            };
            setTimeout(() => {
                this.socket.removeListener("eval", cooldownCheck);
                reject(`alchemy timeout (${Constants_1.Constants.TIMEOUT}ms)`);
            }, Constants_1.Constants.TIMEOUT);
            this.socket.on("eval", cooldownCheck);
        });
        this.socket.emit("skill", {
            name: "alchemy"
        });
        return alchemied;
    }
    blink(x, y) {
        if (index_1.Pathfinder.canStand({ map: this.map, x: x, y: y })) {
            this.socket.emit("skill", { name: "blink", x: x, y: y });
        }
        else {
            throw Error(`We cannot blink to ${this.map} ${x},${y}`);
        }
    }
    burst(target) {
        const bursted = new Promise((resolve, reject) => {
            const cooldownCheck = (data) => {
                if (/skill_timeout\s*\(\s*['"]burst['"]\s*,?\s*(\d+\.?\d+?)?\s*\)/.test(data.code)) {
                    this.socket.removeListener("eval", cooldownCheck);
                    resolve();
                }
            };
            setTimeout(() => {
                this.socket.removeListener("eval", cooldownCheck);
                reject(`burst timeout (${Constants_1.Constants.TIMEOUT}ms)`);
            }, Constants_1.Constants.TIMEOUT);
            this.socket.on("eval", cooldownCheck);
        });
        this.socket.emit("skill", { name: "burst", id: target });
        return bursted;
    }
    cburst(targets) {
        const cbursted = new Promise((resolve, reject) => {
            const cooldownCheck = (data) => {
                if (/skill_timeout\s*\(\s*['"]cburst['"]\s*,?\s*(\d+\.?\d+?)?\s*\)/.test(data.code)) {
                    this.socket.removeListener("eval", cooldownCheck);
                    resolve();
                }
            };
            setTimeout(() => {
                this.socket.removeListener("eval", cooldownCheck);
                reject(`cburst timeout (${Constants_1.Constants.TIMEOUT}ms)`);
            }, Constants_1.Constants.TIMEOUT);
            this.socket.on("eval", cooldownCheck);
        });
        this.socket.emit("skill", { name: "cburst", targets: targets });
        return cbursted;
    }
    energize(target) {
        const energized = new Promise((resolve, reject) => {
            const cooldownCheck = (data) => {
                if (/skill_timeout\s*\(\s*['"]energize['"]\s*,?\s*(\d+\.?\d+?)?\s*\)/.test(data.code)) {
                    this.socket.removeListener("eval", cooldownCheck);
                    resolve();
                }
            };
            setTimeout(() => {
                this.socket.removeListener("eval", cooldownCheck);
                reject(`energize timeout (${Constants_1.Constants.TIMEOUT}ms)`);
            }, Constants_1.Constants.TIMEOUT);
            this.socket.on("eval", cooldownCheck);
        });
        this.socket.emit("skill", { name: "energize", id: target });
        return energized;
    }
    entangle(target, essenceofnature = this.locateItem("essenceofnature")) {
        if (essenceofnature === undefined)
            return Promise.reject("We need an essenceofnature in order to entangle.");
        const tangled = new Promise((resolve, reject) => {
            const cooldownCheck = (data) => {
                if (/skill_timeout\s*\(\s*['"]entangle['"]\s*,?\s*(\d+\.?\d+?)?\s*\)/.test(data.code)) {
                    this.socket.removeListener("eval", cooldownCheck);
                    resolve();
                }
            };
            setTimeout(() => {
                this.socket.removeListener("eval", cooldownCheck);
                reject(`entangle timeout (${Constants_1.Constants.TIMEOUT}ms)`);
            }, Constants_1.Constants.TIMEOUT);
            this.socket.on("eval", cooldownCheck);
        });
        this.socket.emit("skill", {
            name: "entangle",
            id: target,
            num: essenceofnature
        });
        return tangled;
    }
    light() {
        const lit = new Promise((resolve, reject) => {
            const cooldownCheck = (data) => {
                if (/skill_timeout\s*\(\s*['"]light['"]\s*,?\s*(\d+\.?\d+?)?\s*\)/.test(data.code)) {
                    this.socket.removeListener("eval", cooldownCheck);
                    resolve();
                }
            };
            setTimeout(() => {
                this.socket.removeListener("eval", cooldownCheck);
                reject(`light timeout (${Constants_1.Constants.TIMEOUT}ms)`);
            }, Constants_1.Constants.TIMEOUT);
            this.socket.on("eval", cooldownCheck);
        });
        this.socket.emit("skill", {
            name: "light"
        });
        return lit;
    }
    magiport(target) {
        const magiportOfferSent = new Promise((resolve, reject) => {
            const magiportCheck = (data) => {
                if (typeof data == "object") {
                    if (data.response == "magiport_failed" && data.id == target) {
                        this.socket.removeListener("game_response", magiportCheck);
                        reject(`Magiport for '${target}' failed.`);
                    }
                    else if (data.response == "magiport_sent" && data.id == target) {
                        this.socket.removeListener("game_response", magiportCheck);
                        resolve();
                    }
                }
            };
            setTimeout(() => {
                this.socket.removeListener("game_response", magiportCheck);
                reject(`magiport timeout (${Constants_1.Constants.TIMEOUT}ms)`);
            }, Constants_1.Constants.TIMEOUT);
            this.socket.on("game_response", magiportCheck);
        });
        this.socket.emit("skill", { name: "magiport", id: target });
        return magiportOfferSent;
    }
    applyReflection(target) {
        const relectioned = new Promise((resolve, reject) => {
            const cooldownCheck = (data) => {
                if (/skill_timeout\s*\(\s*['"]reflection['"]\s*,?\s*(\d+\.?\d+?)?\s*\)/.test(data.code)) {
                    this.socket.removeListener("eval", cooldownCheck);
                    resolve();
                }
            };
            setTimeout(() => {
                this.socket.removeListener("eval", cooldownCheck);
                reject(`reflection timeout (${Constants_1.Constants.TIMEOUT}ms)`);
            }, Constants_1.Constants.TIMEOUT);
            this.socket.on("eval", cooldownCheck);
        });
        this.socket.emit("skill", {
            name: "reflection",
            id: target,
        });
        return relectioned;
    }
}
exports.Mage = Mage;
//# sourceMappingURL=Mage.js.map