"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Ranger = void 0;
const Constants_1 = require("./Constants");
const PingCompensatedCharacter_1 = require("./PingCompensatedCharacter");
class Ranger extends PingCompensatedCharacter_1.PingCompensatedCharacter {
    fiveShot(target1, target2, target3, target4, target5) {
        const attackStarted = new Promise((resolve, reject) => {
            const projectiles = [];
            const attackCheck = (data) => {
                if (data.attacker == this.id
                    && data.type == "5shot"
                    && (data.target == target1 || data.target == target2 || data.target == target3 || data.target == target4 || data.target == target5)) {
                    projectiles.push(data.pid);
                }
            };
            const cooldownCheck = (data) => {
                if (/skill_timeout\s*\(\s*['"]5shot['"]\s*,?\s*(\d+\.?\d+?)?\s*\)/.test(data.code)) {
                    this.socket.removeListener("action", attackCheck);
                    this.socket.removeListener("eval", cooldownCheck);
                    resolve(projectiles);
                }
            };
            setTimeout(() => {
                this.socket.removeListener("action", attackCheck);
                this.socket.removeListener("eval", cooldownCheck);
                reject(`5shot timeout (${Constants_1.Constants.TIMEOUT}ms)`);
            }, Constants_1.Constants.TIMEOUT);
            this.socket.on("action", attackCheck);
            this.socket.on("eval", cooldownCheck);
        });
        this.socket.emit("skill", {
            name: "5shot",
            ids: [target1, target2, target3, target4, target5]
        });
        return attackStarted;
    }
    fourFinger(target) {
        const marked = new Promise((resolve, reject) => {
            const cooldownCheck = (data) => {
                if (/skill_timeout\s*\(\s*['"]4fingers['"]\s*,?\s*(\d+\.?\d+?)?\s*\)/.test(data.code)) {
                    this.socket.removeListener("eval", cooldownCheck);
                    resolve();
                }
            };
            setTimeout(() => {
                this.socket.removeListener("eval", cooldownCheck);
                reject(`fourfinger timeout (${Constants_1.Constants.TIMEOUT}ms)`);
            }, Constants_1.Constants.TIMEOUT);
            this.socket.on("eval", cooldownCheck);
        });
        this.socket.emit("skill", {
            name: "4fingers",
            id: target
        });
        return marked;
    }
    huntersMark(target) {
        const marked = new Promise((resolve, reject) => {
            const cooldownCheck = (data) => {
                if (/skill_timeout\s*\(\s*['"]huntersmark['"]\s*,?\s*(\d+\.?\d+?)?\s*\)/.test(data.code)) {
                    this.socket.removeListener("eval", cooldownCheck);
                    resolve();
                }
            };
            setTimeout(() => {
                this.socket.removeListener("eval", cooldownCheck);
                reject(`huntersmark timeout (${Constants_1.Constants.TIMEOUT}ms)`);
            }, Constants_1.Constants.TIMEOUT);
            this.socket.on("eval", cooldownCheck);
        });
        this.socket.emit("skill", {
            name: "huntersmark",
            id: target
        });
        return marked;
    }
    piercingShot(target) {
        if (this.G.skills.piercingshot.mp > this.mp)
            return Promise.reject("Not enough MP to use piercingShot");
        const piercingShotStarted = new Promise((resolve, reject) => {
            let projectile;
            const attackCheck = (data) => {
                if (data.attacker == this.id
                    && data.type == "piercingshot"
                    && data.target == target) {
                    projectile = data.pid;
                }
            };
            const cooldownCheck = (data) => {
                if (/skill_timeout\s*\(\s*['"]piercingshot['"]\s*,?\s*(\d+\.?\d+?)?\s*\)/.test(data.code)) {
                    this.socket.removeListener("action", attackCheck);
                    this.socket.removeListener("eval", cooldownCheck);
                    resolve(projectile);
                }
            };
            setTimeout(() => {
                this.socket.removeListener("action", attackCheck);
                this.socket.removeListener("eval", cooldownCheck);
                reject(`piercingshot timeout (${Constants_1.Constants.TIMEOUT}ms)`);
            }, Constants_1.Constants.TIMEOUT);
            this.socket.on("action", attackCheck);
            this.socket.on("eval", cooldownCheck);
        });
        this.socket.emit("skill", { name: "piercingshot", id: target });
        return piercingShotStarted;
    }
    poisonArrow(target, poison = this.locateItem("poison")) {
        if (poison === undefined)
            return Promise.reject("We need poison to use this skill.");
        const poisonArrowed = new Promise((resolve, reject) => {
            let projectile;
            const attackCheck = (data) => {
                if (data.attacker == this.id
                    && data.type == "poisonarrow"
                    && data.target == target) {
                    projectile = data.pid;
                }
            };
            const cooldownCheck = (data) => {
                if (/skill_timeout\s*\(\s*['"]poisonarrow['"]\s*,?\s*(\d+\.?\d+?)?\s*\)/.test(data.code)) {
                    this.socket.removeListener("action", attackCheck);
                    this.socket.removeListener("eval", cooldownCheck);
                    resolve(projectile);
                }
            };
            setTimeout(() => {
                this.socket.removeListener("action", attackCheck);
                this.socket.removeListener("eval", cooldownCheck);
                reject(`poisonarrow timeout (${Constants_1.Constants.TIMEOUT}ms)`);
            }, Constants_1.Constants.TIMEOUT);
            this.socket.on("action", attackCheck);
            this.socket.on("eval", cooldownCheck);
        });
        this.socket.emit("skill", { name: "poisonarrow", num: poison, id: target });
        return poisonArrowed;
    }
    superShot(target) {
        if (this.G.skills.supershot.mp > this.mp)
            return Promise.reject("Not enough MP to use superShot");
        const superShotStarted = new Promise((resolve, reject) => {
            let projectile;
            const attackCheck = (data) => {
                if (data.attacker == this.id
                    && data.type == "supershot"
                    && data.target == target) {
                    projectile = data.pid;
                }
            };
            const cooldownCheck = (data) => {
                if (/skill_timeout\s*\(\s*['"]supershot['"]\s*,?\s*(\d+\.?\d+?)?\s*\)/.test(data.code)) {
                    this.socket.removeListener("action", attackCheck);
                    this.socket.removeListener("eval", cooldownCheck);
                    resolve(projectile);
                }
            };
            setTimeout(() => {
                this.socket.removeListener("action", attackCheck);
                this.socket.removeListener("eval", cooldownCheck);
                reject(`supershot timeout (${Constants_1.Constants.TIMEOUT}ms)`);
            }, Constants_1.Constants.TIMEOUT);
            this.socket.on("action", attackCheck);
            this.socket.on("eval", cooldownCheck);
        });
        this.socket.emit("skill", { name: "supershot", id: target });
        return superShotStarted;
    }
    threeShot(target1, target2, target3) {
        const attackStarted = new Promise((resolve, reject) => {
            const projectiles = [];
            const attackCheck = (data) => {
                if (data.attacker == this.id
                    && data.type == "3shot"
                    && (data.target == target1 || data.target == target2 || data.target == target3)) {
                    projectiles.push(data.pid);
                }
            };
            const cooldownCheck = (data) => {
                if (/skill_timeout\s*\(\s*['"]3shot['"]\s*,?\s*(\d+\.?\d+?)?\s*\)/.test(data.code)) {
                    this.socket.removeListener("action", attackCheck);
                    this.socket.removeListener("eval", cooldownCheck);
                    resolve(projectiles);
                }
            };
            setTimeout(() => {
                this.socket.removeListener("action", attackCheck);
                this.socket.removeListener("eval", cooldownCheck);
                reject(`3shot timeout (${Constants_1.Constants.TIMEOUT}ms)`);
            }, Constants_1.Constants.TIMEOUT);
            this.socket.on("action", attackCheck);
            this.socket.on("eval", cooldownCheck);
        });
        this.socket.emit("skill", {
            name: "3shot",
            ids: [target1, target2, target3]
        });
        return attackStarted;
    }
}
exports.Ranger = Ranger;
//# sourceMappingURL=Ranger.js.map