"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Entity = void 0;
class Entity {
    constructor(data, map, G) {
        this.moving = false;
        this.level = 1;
        this.s = {};
        this.abilities = {};
        this["1hp"] = false;
        this.aggro = 0;
        this.apiercing = 0;
        this.cooperative = false;
        this.evasion = 0;
        this.immune = false;
        this.lifesteal = 0;
        this.reflection = 0;
        this.rpiercing = 0;
        this.armor = 0;
        this.attack = 0;
        this.resistance = 0;
        this.rage = 0;
        this.G = G;
        this.max_hp = G.monsters[data.type]["hp"];
        this.max_mp = G.monsters[data.type]["mp"];
        this.map = map;
        for (const gDatum in G.monsters[data.type]) {
            this[gDatum] = G.monsters[data.type][gDatum];
        }
        this.updateData(data);
    }
    updateData(data) {
        if (this.id !== undefined && this.id !== data.id)
            throw Error("The entity's ID does not match");
        for (const key in data)
            this[key] = data[key];
    }
    isAttackingPartyMember(player) {
        if (this.target === undefined)
            return false;
        if (this.isAttackingUs(player))
            return true;
        if (player.partyData && player.partyData.list && player.partyData.list.includes(this.target))
            return true;
        return false;
    }
    isAttackingUs(player) {
        return this.target === player.id;
    }
    isTauntable(by) {
        if (this.target === undefined)
            return true;
        if (this.isAttackingPartyMember(by))
            return true;
        return false;
    }
    willBurnToDeath() {
        if (this["1hp"])
            return false;
        if (this.lifesteal !== undefined)
            return false;
        if (this.abilities && this.abilities.self_healing)
            return false;
        if (this.s.burned) {
            const burnTime = Math.max(0, (this.s.burned.ms - (this.G.conditions.burned.interval * 2))) / 1000;
            const burnDamage = burnTime * this.s.burned.intensity;
            if (burnDamage > this.hp)
                return true;
        }
        return false;
    }
    willDieToProjectiles(projectiles) {
        if (this["1hp"] || this.evasion || this.reflection)
            return false;
        let incomingProjectileDamage = 0;
        for (const projectile of projectiles.values()) {
            if (projectile.target == this.id)
                incomingProjectileDamage += projectile.damage * 0.9;
            if (incomingProjectileDamage > this.hp)
                return true;
        }
        return false;
    }
}
exports.Entity = Entity;
//# sourceMappingURL=Entity.js.map