//  • ▌ ▄ ·.  ▄▄▄·  ▄▄ • ▪   ▄▄· ▄▄▄▄·  ▄▄▄·  ▐▄▄▄  ▄▄▄ .
//  ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
//  ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
//  ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
//  ▀▀  █▪▀▀▀ ▀  ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀  ▀  ▀ ▀▀  █▪ ▀▀▀
//      Magicbane Emulator Project © 2013 - 2026
//                https://www.magicbane.com

package engine.net.client.handlers;

import engine.gameManager.DispatchManager;
import engine.mbEnums;
import engine.mbEnums.DispatchChannel;
import engine.net.Dispatch;
import engine.net.client.ClientConnection;
import engine.net.client.msg.ClientNetMsg;
import engine.net.client.msg.ShowMsg;
import engine.objects.AbstractCharacter;
import engine.objects.Mob;
import engine.objects.NPC;
import engine.objects.PlayerCharacter;

public class ShowMsgHandler extends AbstractClientMsgHandler {

    public ShowMsgHandler() {
        super();
    }

    @Override
    protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) {

        PlayerCharacter playerCharacter = origin.getPlayerCharacter();

        // Member variable declaration

        ShowMsg msg;

        // Member variable assignment

        msg = (ShowMsg) baseMsg;

        if (playerCharacter == null)
            return true;

        int targetType = msg.getTargetType();
        AbstractCharacter tar = null;

        if (targetType == mbEnums.GameObjectType.PlayerCharacter.ordinal())
            tar = PlayerCharacter.getFromCache(msg.getTargetID());
        else if (targetType == mbEnums.GameObjectType.NPC.ordinal())
            tar = NPC.getFromCache(msg.getTargetID());
        else if (targetType == mbEnums.GameObjectType.Mob.ordinal())
            tar = Mob.getFromCache(msg.getTargetID());

        if (tar == null || !tar.isAlive() || !tar.isActive())
            return true;

        msg.setUnknown01(playerCharacter.getLoc());
        msg.setUnknown02(playerCharacter.getLoc());
        msg.setRange01(playerCharacter.getRange());
        msg.setUnknown03(tar.getLoc());
        msg.setUnknown04(tar.getLoc());
        msg.setRange01(tar.getRange());

        Dispatch dispatch = Dispatch.borrow(playerCharacter, msg);
        DispatchManager.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);

        return true;
    }

}