import { system, world, Player, EasingType } from "@minecraft/server";
import { boss, dsEntity, removerPrefixo, scanerMobs } from "./communs";
import { viewLife } from "../assistant/view";
import "./hit_player";
import "./projetil";

function antAfk() {
    dsEntity.forEach((dimension) => {
        world
            .getDimension(dimension)
            .getEntities()
            .forEach((entity) => {
                const typeId = entity.typeId;
                if (!entity.hasTag('tamed') || !entity.hasTag('die')) {
                    if (boss[removerPrefixo(typeId)]) {
                        entity.runCommand(`fill ~-3~-3~-3 ~3~3~3 air replace fire`)
                        scanerMobs(entity, {
                            families: ["player"],
                            maxDistance: 1.5,
                            location: entity.location,
                        }).forEach((victim) => {
                            if (victim.typeId == "minecraft:player") {
                                const view = victim.getViewDirection();
                                
                                victim.applyKnockback(
                                    -0.2 * view.x,
                                    -0.2 * view.z,
                                    1.5,
                                    0
                                );
                            }
                        });
                    }
                }
                
            });
    });
}

function fire() {
    dsEntity.forEach((dimension) => {
        world
            .getDimension(dimension)
            .getEntities()
            .forEach((entity) => {
                const typeId = entity.typeId;
                if (!entity.hasTag('tamed') || !entity.hasTag('die')) {
                    if (boss[removerPrefixo(typeId)]) {
                        entity.runCommand(`fill ~-3~-3~-3 ~3~3~3 air replace fire`)
                    }
                }
                
            });
    });
}

system.runInterval(() => {
    fire()
})

system.runInterval(()=>{
    // antAfk()
},20*1.5)