"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Priest = void 0;
const Constants_1 = require("./Constants");
const PingCompensatedCharacter_1 = require("./PingCompensatedCharacter");
class Priest extends PingCompensatedCharacter_1.PingCompensatedCharacter {
    absorbSins(target) {
        const absorbed = new Promise((resolve, reject) => {
            const cooldownCheck = (data) => {
                if (/skill_timeout\s*\(\s*['"]absorb['"]\s*,?\s*(\d+\.?\d+?)?\s*\)/.test(data.code)) {
                    this.socket.removeListener("eval", cooldownCheck);
                    resolve();
                }
            };
            setTimeout(() => {
                this.socket.removeListener("eval", cooldownCheck);
                reject(`curse timeout (${Constants_1.Constants.TIMEOUT}ms)`);
            }, Constants_1.Constants.TIMEOUT);
            this.socket.on("eval", cooldownCheck);
        });
        this.socket.emit("skill", { name: "absorb", id: target });
        return absorbed;
    }
    curse(target) {
        const curseStarted = new Promise((resolve, reject) => {
            const cooldownCheck = (data) => {
                if (/skill_timeout\s*\(\s*['"]curse['"]\s*,?\s*(\d+\.?\d+?)?\s*\)/.test(data.code)) {
                    this.socket.removeListener("eval", cooldownCheck);
                    resolve();
                }
            };
            setTimeout(() => {
                this.socket.removeListener("eval", cooldownCheck);
                reject(`curse timeout (${Constants_1.Constants.TIMEOUT}ms)`);
            }, Constants_1.Constants.TIMEOUT);
            this.socket.on("eval", cooldownCheck);
        });
        this.socket.emit("skill", { name: "curse", id: target });
        return curseStarted;
    }
    darkBlessing() {
        const darkBlessed = new Promise((resolve, reject) => {
            const cooldownCheck = (data) => {
                if (/skill_timeout\s*\(\s*['"]darkblessing['"]\s*,?\s*(\d+\.?\d+?)?\s*\)/.test(data.code)) {
                    this.socket.removeListener("eval", cooldownCheck);
                    resolve();
                }
            };
            setTimeout(() => {
                this.socket.removeListener("eval", cooldownCheck);
                reject(`darkblessing timeout (${Constants_1.Constants.TIMEOUT}ms)`);
            }, Constants_1.Constants.TIMEOUT);
            this.socket.on("eval", cooldownCheck);
        });
        this.socket.emit("skill", { name: "darkblessing" });
        return darkBlessed;
    }
    heal(id) {
        const healStarted = new Promise((resolve, reject) => {
            const deathCheck = (data) => {
                if (data.id == id) {
                    this.socket.removeListener("action", attackCheck);
                    this.socket.removeListener("game_response", failCheck);
                    this.socket.removeListener("death", deathCheck);
                    reject(`Entity ${id} not found`);
                }
            };
            const failCheck = (data) => {
                if (typeof data == "object") {
                    if (data.response == "disabled") {
                        this.socket.removeListener("action", attackCheck);
                        this.socket.removeListener("game_response", failCheck);
                        this.socket.removeListener("death", deathCheck);
                        reject(`Heal on ${id} failed (disabled).`);
                    }
                    else if (data.response == "attack_failed" && data.id == id) {
                        this.socket.removeListener("action", attackCheck);
                        this.socket.removeListener("game_response", failCheck);
                        this.socket.removeListener("death", deathCheck);
                        reject(`Heal on ${id} failed.`);
                    }
                    else if (data.response == "too_far" && data.id == id) {
                        this.socket.removeListener("action", attackCheck);
                        this.socket.removeListener("game_response", failCheck);
                        this.socket.removeListener("death", deathCheck);
                        reject(`${id} is too far away to heal (dist: ${data.dist}).`);
                    }
                    else if (data.response == "cooldown" && data.id == id) {
                        this.socket.removeListener("action", attackCheck);
                        this.socket.removeListener("game_response", failCheck);
                        this.socket.removeListener("death", deathCheck);
                        reject(`Heal on ${id} failed due to cooldown (ms: ${data.ms}).`);
                    }
                }
            };
            const attackCheck = (data) => {
                if (data.attacker == this.id && data.target == id && data.type == "heal") {
                    this.socket.removeListener("action", attackCheck);
                    this.socket.removeListener("game_response", failCheck);
                    this.socket.removeListener("death", deathCheck);
                    resolve(data.pid);
                }
            };
            setTimeout(() => {
                this.socket.removeListener("action", attackCheck);
                this.socket.removeListener("game_response", failCheck);
                this.socket.removeListener("death", deathCheck);
                reject(`heal timeout (${Constants_1.Constants.TIMEOUT}ms)`);
            }, Constants_1.Constants.TIMEOUT);
            this.socket.on("action", attackCheck);
            this.socket.on("game_response", failCheck);
            this.socket.on("death", deathCheck);
        });
        this.socket.emit("heal", { id: id });
        return healStarted;
    }
    partyHeal() {
        const healStarted = new Promise((resolve, reject) => {
            const cooldownCheck = (data) => {
                if (/skill_timeout\s*\(\s*['"]partyheal['"]\s*,?\s*(\d+\.?\d+?)?\s*\)/.test(data.code)) {
                    this.socket.removeListener("eval", cooldownCheck);
                    resolve();
                }
            };
            setTimeout(() => {
                this.socket.removeListener("eval", cooldownCheck);
                reject(`partyHeal timeout (${Constants_1.Constants.TIMEOUT}ms)`);
            }, Constants_1.Constants.TIMEOUT);
            this.socket.on("eval", cooldownCheck);
        });
        this.socket.emit("skill", { name: "partyheal" });
        return healStarted;
    }
    revive(target, essenceoflife = this.locateItem("essenceoflife")) {
        if (essenceoflife === undefined)
            return Promise.reject("We don't have any essenceoflife in our inventory.");
        const revived = new Promise((resolve, reject) => {
            const cooldownCheck = (data) => {
                if (/skill_timeout\s*\(\s*['"]revive['"]\s*,?\s*(\d+\.?\d+?)?\s*\)/.test(data.code)) {
                    this.socket.removeListener("eval", cooldownCheck);
                    resolve();
                }
            };
            setTimeout(() => {
                this.socket.removeListener("eval", cooldownCheck);
                reject(`revive timeout (${Constants_1.Constants.TIMEOUT}ms)`);
            }, Constants_1.Constants.TIMEOUT);
            this.socket.on("eval", cooldownCheck);
        });
        this.socket.emit("skill", { name: "revive", id: target, num: essenceoflife });
        return revived;
    }
}
exports.Priest = Priest;
//# sourceMappingURL=Priest.js.map