Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 24th, 2012  |  syntax: None  |  size: 1.60 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. package com.rs.utils;
  2.  
  3. import java.io.RandomAccessFile;
  4. import java.nio.ByteBuffer;
  5. import java.nio.channels.FileChannel;
  6. import java.nio.channels.FileChannel.MapMode;
  7. import java.util.HashMap;
  8.  
  9. import com.rs.game.npc.Drop;
  10.  
  11. public class NPCDrops {
  12.  
  13.         private final static String PACKED_PATH = "data/npcs/packedDrops.d";
  14.         private static HashMap<Integer, Drop[]> npcDrops;
  15.  
  16.         public static final void init() {
  17.                 loadPackedNPCDrops();
  18.         }
  19.  
  20.         public static Drop[] getDrops(int npcId) {
  21.                 return npcDrops.get(npcId);
  22.         }
  23.  
  24.         public static void loadPackedNPCDrops() {
  25.                 try {
  26.                         RandomAccessFile in = new RandomAccessFile(PACKED_PATH, "r");
  27.                         FileChannel channel = in.getChannel();
  28.                         ByteBuffer buffer = channel.map(MapMode.READ_ONLY, 0,
  29.                                         channel.size());
  30.                         int dropSize = buffer.getShort() & 0xffff;
  31.                         npcDrops = new HashMap<Integer, Drop[]>(dropSize);
  32.                         for (int i = 0; i < dropSize; i++) {
  33.                                 int npcId = buffer.getShort() & 0xffff;
  34.                                 Drop[] drops = new Drop[buffer.getShort() & 0xffff];
  35.                                 for (int d = 0; d < drops.length; d++) {
  36.                                         if (buffer.get() == 0)
  37.                                                 drops[d] = new Drop(buffer.getShort() & 0xffff,
  38.                                                                 buffer.getDouble(), buffer.getInt(),
  39.                                                                 buffer.getInt(), false);
  40.                                         else
  41.                                                 drops[d] = new Drop(0, 0, 0, 0, true);
  42.  
  43.                                 }
  44.                                 npcDrops.put(npcId, drops);
  45.                         }
  46.                         channel.close();
  47.                         in.close();
  48.                 } catch (Throwable e) {
  49.                         Logger.handle(e);
  50.                 }
  51.         }
  52.  
  53.         public HashMap<Integer, Drop[]> getDropMap() {
  54.                 return npcDrops;
  55.         }
  56.        
  57.         public Drop getDrop(int npcId) {
  58.                 switch(npcId) {
  59.                
  60.                 default:
  61.                         return new Drop(0, 0, 0, 0, true);
  62.                 }
  63.         }
  64. }