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

package engine.net.client.handlers;

import engine.gameManager.DispatchManager;
import engine.mbEnums;
import engine.net.client.ClientConnection;
import engine.net.client.msg.ClientNetMsg;
import engine.net.client.msg.SetCombatModeMsg;
import engine.net.client.msg.UpdateStateMsg;
import engine.objects.PlayerCharacter;
import engine.server.MBServerStatics;

public class SetCombatModeMsgHandler extends AbstractClientMsgHandler {

    public SetCombatModeMsgHandler() {
        super();
    }

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

        PlayerCharacter playerCharacter = origin.getPlayerCharacter();

        // Member variable declaration

        SetCombatModeMsg msg;
        boolean toggle;

        // Member variable assignment

        msg = (SetCombatModeMsg) baseMsg;

        if (playerCharacter == null)
            return true;

        toggle = msg.getToggle();
        playerCharacter.setCombat(toggle);

        if (!toggle) // toggle is move it to false so clear combat target
            playerCharacter.setCombatTarget(null); //clear last combat target

        UpdateStateMsg rwss = new UpdateStateMsg();
        rwss.setPlayer(playerCharacter);
        DispatchManager.dispatchMsgToInterestArea(playerCharacter, rwss, mbEnums.DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, false, false);

        return true;
    }

}