import * as mc from "@minecraft/server";
import * as utils from "../utils/index";
import { Achievement } from "./achievement";
export class FighterAchievement extends Achievement {
    constructor() {
        super(...arguments);
        this.SkinIndex = 6;
        this.total = 300;
    }
    onSetup() {
        mc.world.afterEvents.entityDie.subscribe(this.killMonster.bind(this));
    }
    killMonster(event) {
        if (event.damageSource.damagingEntity instanceof mc.Player && event.deadEntity.matches({ families: ["monster"] })) {
            const player = new utils.SafetyCheckedPlayer(event.damageSource.damagingEntity);
            const progress = this.getProgress(player);
            progress.count++;
            utils.mclog(`Killed ${progress.count}/${this.total} monsters`);
            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.fighter")) !== null && _a !== void 0 ? _a : { count: 0 };
    }
    setProgress(player, progress) {
        utils.writeDynamicProperty(player, utils.GlobalNamespace.Namespace + "achievement.fighter", 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 FighterAchievement();
