import * as mc from "@minecraft/server";
import * as utils from "../utils/index";
import { Achievement } from "./achievement";
export class BackroomsAchievement extends Achievement {
    constructor() {
        super(...arguments);
        this.SkinIndex = 2;
    }
    onSetup() {
        mc.world.afterEvents.entityHurt.subscribe(this.onHurtEnderman.bind(this));
    }
    onHurtEnderman(event) {
        var _a;
        if (event.damageSource.damagingEntity instanceof mc.Player) {
            utils.writeDynamicProperty(event.hurtEntity, "last_hit", event.damageSource.damagingEntity.id);
        }
        else {
            if (event.damageSource.cause === mc.EntityDamageCause.void) {
                const id = utils.readDynamicProperty(event.hurtEntity, "last_hit");
                if (id) {
                    const player = (_a = utils.getEntitySafe(id)) === null || _a === void 0 ? void 0 : _a.getPlayer();
                    if (player) {
                        this.setStatus(player, true);
                    }
                }
            }
        }
    }
    getStatusText(player) {
        if (this.getStatus(player)) {
            return { rawtext: [
                    { translate: `ldz_crcomp:craftee.achievement.${this.TypeId}.title.completed` },
                    { text: "\n" },
                    { translate: `ldz_crcomp:craftee.achievement.${this.TypeId}.status.completed`, with: { rawtext: [
                                { translate: "entity.enderman.name" },
                            ] } },
                    { text: "\n\n" },
                ] };
        }
        else {
            return { rawtext: [
                    { translate: `ldz_crcomp:craftee.achievement.${this.TypeId}.title.in_progress` },
                    { text: "\n" },
                    { translate: `ldz_crcomp:craftee.achievement.${this.TypeId}.status.in_progress`, with: { rawtext: [
                                { translate: "entity.enderman.name" },
                            ] } },
                    { text: "\n\n" },
                ] };
        }
    }
}
new BackroomsAchievement();
