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


package engine.net.client.msg;


import engine.exception.SerializationException;
import engine.net.AbstractConnection;
import engine.net.ByteBufferReader;
import engine.net.ByteBufferWriter;
import engine.net.client.Protocol;

import java.util.ArrayList;


/**
 * Use item
 *
 * @author Eighty
 */
public class ObjectActionMsg extends ClientNetMsg {

    private int unknown01;
    private int unknown02;
    private ArrayList<Long> targetCompID;

    /**
     * This is the general purpose constructor
     */
    public ObjectActionMsg(int unknown01, int unknown02, ArrayList<Long> targetCompID) {
        super(Protocol.OBJECTACTION);
        this.unknown01 = unknown01;
        this.unknown02 = unknown02;
        this.targetCompID = targetCompID;
    }

    /**
     * This constructor is used by NetMsgFactory. It attempts to deserialize the ByteBuffer into a message. If a BufferUnderflow occurs (based on reading past the limit) then this constructor Throws that Exception to the caller.
     */
    public ObjectActionMsg(AbstractConnection origin, ByteBufferReader reader) {
        super(Protocol.OBJECTACTION, origin, reader);
    }

    /**
     * Deserializes the subclass specific items to the supplied NetMsgWriter.
     */
    @Override
    protected void _deserialize(ByteBufferReader reader) {
        if (targetCompID == null)
            targetCompID = new ArrayList<>();
        unknown01 = reader.getInt();
        unknown02 = reader.getInt();
        for (int i = 0; i < unknown01; i++)
            targetCompID.add(reader.getLong());
    }

    /**
     * Serializes the subclass specific items from the supplied NetMsgReader.
     */
    @Override
    protected void _serialize(ByteBufferWriter writer)
            throws SerializationException {
        writer.putInt(unknown01);
        writer.putInt(unknown02);
        for (int i = 0; i < unknown01; i++)
            writer.putLong(targetCompID.get(i));
    }

    /**
     * @return the unknown01
     */
    public int getUnknown01() {
        return unknown01;
    }

    /**
     * @param unknown01 the unknown01 to set
     */
    public void setUnknown01(int unknown01) {
        this.unknown01 = unknown01;
    }

    /**
     * @return the unknown02
     */
    public int getUnknown02() {
        return unknown02;
    }

    /**
     * @param unknown02 the unknown02 to set
     */
    public void setUnknown02(int unknown02) {
        this.unknown02 = unknown02;
    }

    /**
     * @return the targetCompID
     */
    public ArrayList<Long> getTargetCompID() {
        return targetCompID;
    }

    /**
     * @param targetCompID the targetCompID to set
     */
    public void setTargetCompID(ArrayList<Long> targetCompID) {
        this.targetCompID = targetCompID;
    }

}