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

package engine.net.client.handlers;

import engine.gameManager.DispatchManager;
import engine.mbEnums;
import engine.net.Dispatch;
import engine.net.client.ClientConnection;
import engine.net.client.msg.ClientNetMsg;
import engine.net.client.msg.TrainerInfoMsg;
import engine.objects.NPC;
import engine.objects.PlayerCharacter;

public class TrainerInfoMsgHandler extends AbstractClientMsgHandler {

    public TrainerInfoMsgHandler() {
        super();
    }

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

        PlayerCharacter playerCharacter = origin.getPlayerCharacter();

        // Member variable declaration

        TrainerInfoMsg msg;

        // Member variable assignment

        msg = (TrainerInfoMsg) baseMsg;

        NPC npc = NPC.getFromCache(msg.getObjectID());
        float sellPercent = 1;

        if (npc != null) {

            if (origin.getPlayerCharacter() != null)
                sellPercent = npc.getSellPercent(origin.getPlayerCharacter());
            else
                sellPercent = npc.getSellPercent();

            msg.setTrainPercent(sellPercent); //TrainMsg.getTrainPercent(npc));
        }

        Dispatch dispatch = Dispatch.borrow(origin.getPlayerCharacter(), msg);
        DispatchManager.dispatchMsgDispatch(dispatch, mbEnums.DispatchChannel.SECONDARY);

        return true;
    }

}