
Untitled
By: a guest on
Apr 24th, 2012 | syntax:
None | size: 1.60 KB | hits: 12 | expires: Never
package com.rs.utils;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.channels.FileChannel.MapMode;
import java.util.HashMap;
import com.rs.game.npc.Drop;
public class NPCDrops {
private final static String PACKED_PATH = "data/npcs/packedDrops.d";
private static HashMap<Integer, Drop[]> npcDrops;
public static final void init() {
loadPackedNPCDrops();
}
public static Drop[] getDrops(int npcId) {
return npcDrops.get(npcId);
}
public static void loadPackedNPCDrops() {
try {
RandomAccessFile in = new RandomAccessFile(PACKED_PATH, "r");
FileChannel channel = in.getChannel();
ByteBuffer buffer = channel.map(MapMode.READ_ONLY, 0,
channel.size());
int dropSize = buffer.getShort() & 0xffff;
npcDrops = new HashMap<Integer, Drop[]>(dropSize);
for (int i = 0; i < dropSize; i++) {
int npcId = buffer.getShort() & 0xffff;
Drop[] drops = new Drop[buffer.getShort() & 0xffff];
for (int d = 0; d < drops.length; d++) {
if (buffer.get() == 0)
drops[d] = new Drop(buffer.getShort() & 0xffff,
buffer.getDouble(), buffer.getInt(),
buffer.getInt(), false);
else
drops[d] = new Drop(0, 0, 0, 0, true);
}
npcDrops.put(npcId, drops);
}
channel.close();
in.close();
} catch (Throwable e) {
Logger.handle(e);
}
}
public HashMap<Integer, Drop[]> getDropMap() {
return npcDrops;
}
public Drop getDrop(int npcId) {
switch(npcId) {
default:
return new Drop(0, 0, 0, 0, true);
}
}
}