import * as mc from "@minecraft/server";
import * as utils from "../../utils/index";
import { DrillBot } from "./drill";
mc.system.afterEvents.scriptEventReceive.subscribe(event => {
    if (event.id === "ldz_240927:player_hit" &&
        event.sourceEntity &&
        event.sourceEntity.typeId === utils.addName("drill_bot_seat")) {
        const seat = new utils.SafetyCheckedEntity(event.sourceEntity);
        const playerEventListener = mc.system.afterEvents.scriptEventReceive.subscribe(event => {
            if (event.id === "ldz_240927:player_hit" &&
                event.message === "player" &&
                event.sourceEntity) {
                mc.system.afterEvents.scriptEventReceive.unsubscribe(playerEventListener);
                const player = new utils.SafetyCheckedPlayer(event.sourceEntity);
                onSeatHitByPlayer(seat, player);
            }
        });
    }
});
function onSeatHitByPlayer(seat, player) {
    var _a;
    const drillRider = (_a = seat.getComponent("rideable")) === null || _a === void 0 ? void 0 : _a.getRiders()[0];
    if (!drillRider)
        return;
    const drill = utils.Actor.getActor(drillRider.id, DrillBot);
    if (!drill)
        return;
    drill.runCommand("scriptevent ldz_240927:player_hit victim");
    player.runCommand("scriptevent ldz_240927:player_hit player");
}
