Rename and clean up MapleQuickslotBinding

This commit is contained in:
P0nk
2021-09-09 20:59:45 +02:00
parent 280e28163c
commit 6ea9a57e9f
4 changed files with 21 additions and 30 deletions

View File

@@ -5,34 +5,25 @@ import net.packet.OutPacket;
import java.util.Arrays;
/**
*
* @author Shavit
*/
public class MapleQuickslotBinding
{
public class QuickslotBinding {
public static final int QUICKSLOT_SIZE = 8;
public static final byte[] DEFAULT_QUICKSLOTS = {0x2A, 0x52, 0x47, 0x49, 0x1D, 0x53, 0x4F, 0x51};
public static final byte[] DEFAULT_QUICKSLOTS =
{
0x2A, 0x52, 0x47, 0x49, 0x1D, 0x53, 0x4F, 0x51
};
private byte[] m_aQuickslotKeyMapped;
private final byte[] m_aQuickslotKeyMapped;
// Initializes quickslot object for the user.
// aKeys' length has to be 8.
public MapleQuickslotBinding(byte[] aKeys)
{
if(aKeys.length != QUICKSLOT_SIZE)
{
public QuickslotBinding(byte[] aKeys) {
if (aKeys.length != QUICKSLOT_SIZE) {
throw new IllegalArgumentException(String.format("aKeys' size should be %d", QUICKSLOT_SIZE));
}
this.m_aQuickslotKeyMapped = aKeys.clone();
}
public void encode(OutPacket p)
{
public void encode(OutPacket p) {
// Quickslots are default.
// The client will skip them and call CQuickslotKeyMappedMan::DefaultQuickslotKeyMap.
if (Arrays.equals(this.m_aQuickslotKeyMapped, DEFAULT_QUICKSLOTS)) {
@@ -42,16 +33,16 @@ public class MapleQuickslotBinding
p.writeBool(true);
for(byte nKey : this.m_aQuickslotKeyMapped) {
for (byte nKey : this.m_aQuickslotKeyMapped) {
// For some reason Nexon sends these as integers, similar to CFuncKeyMappedMan.
// However there's no evidence any key can be above 0xFF anyhow.
// Regardless, we need to encode an integer to avoid an error 38 crash; as CFuncKeyMapped::m_aQuickslotKeyMapped is int[8].
p.writeInt(nKey);
}
}
public byte[] GetKeybindings() {
return m_aQuickslotKeyMapped;
}
}