import * as utils from "../utils/index";
import { Achievement } from "./achievement";
import { NPCBase } from "../npc/index";
import { PlayerCompanion } from "../playerCompanion/index";
export class MinerAchievement extends Achievement {
    constructor() {
        super(...arguments);
        this.SkinIndex = 11;
        this.total = 1000;
        this.miningEvents = [
            "mined.cobblestone",
            "mined.coal",
            "mined.copper",
            "mined.iron",
            "mined.gold",
            "mined.redstone",
            "mined.lapis",
            "mined.emerald",
            "mined.diamond",
            "mined.andesite",
            "mined.diorite",
            "mined.granite",
            "mined.deepslate",
            "mined.netherrack",
            "mined.nether_gold",
            "mined.quartz",
            "mined.ancient_debris",
        ];
    }
    onSetup() {
        for (const event of this.miningEvents) {
            NPCBase.npcEvents.broadcast.subscribe(event, (npc) => {
                if (npc instanceof PlayerCompanion) {
                    this.addCount(npc.Owner);
                }
            });
        }
    }
    addCount(player) {
        const progress = this.getProgress(player);
        progress.count++;
        utils.mclog(`Mined ${progress.count}/${this.total} blocks`);
        if (progress.count >= this.total) {
            this.setStatus(player, true);
        }
        this.setProgress(player, progress);
    }
    getProgress(player) {
        var _a;
        return (_a = utils.readDynamicProperty(player, utils.GlobalNamespace.Namespace + "achievement.miner")) !== null && _a !== void 0 ? _a : { count: 0 };
    }
    setProgress(player, progress) {
        utils.writeDynamicProperty(player, utils.GlobalNamespace.Namespace + "achievement.miner", progress);
    }
    onReset(player) {
        super.onReset(player);
        this.setProgress(player, { count: 0 });
    }
    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: [
                                { text: String(this.total) },
                            ] } },
                    { 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: [
                                { text: String(this.total - this.getProgress(player).count) },
                            ] } },
                    { text: "\n\n" },
                ] };
        }
    }
}
new MinerAchievement();
