import { dinoList, dnaExtract, grittyDNAExtract, dnaExtractor } from "./constants";
import { isDinosaur, giveItemToPlayer, setItemDinoDNALore, damageItem, takeOneItem } from "./utilities";
import { NAMESPACE } from "./anvilConstants";
function getDinosaurDNA(player) {
    player.getEntitiesFromViewDirection({ maxDistance: 4 }).forEach((entity) => {
        let dinoName;
        if ([`${NAMESPACE}:trex_fragment_0`, `${NAMESPACE}:trex_fragment_1`, `${NAMESPACE}:trex_fragment_2`].includes(entity.entity.typeId)) {
            dinoName = Math.random() < 0.5 ? "Tyrannosaurus Rex" : "Apex Tyrannosaurus Rex";
        } else if (isDinosaur(entity.entity)) {
            dinoName = dinoList[entity.entity.typeId.replace(`${NAMESPACE}:`, "")].name;
        }
        if (dinoName) {
            giveItemToPlayer(player, setItemDinoDNALore(dnaExtract, dinoName));
        }
    });
}
function randomDinosaurDNA(player, ItemStack) {
    const dinoNames = Object.values(dinoList).map(dino => dino.name);
    const randomIndex = Math.floor(Math.random() * dinoNames.length);
    const dinoName = dinoNames[randomIndex];
    takeOneItem(player, ItemStack);
    giveItemToPlayer(player, setItemDinoDNALore(dnaExtract, dinoName));
}
export function dnaExtractorInteractEvent(eventData) {
    const itemStack = eventData.itemStack;
    const player = eventData.source;
    if (itemStack.typeId === dnaExtractor) {
        getDinosaurDNA(player);
        damageItem(player);
        player.playSound(`${NAMESPACE}:weapons.syringe`);
    }
}
export function grittyDNAExtractInteractEvent(eventData) {
    const ItemStack = eventData.itemStack;
    const player = eventData.source;
    if (ItemStack.typeId === grittyDNAExtract) {
        randomDinosaurDNA(player, ItemStack);
        player.playSound(`brush.generic`);
    }
}