Beispiel #1
0
 private static final void loadItemBonuses() {
   try {
     RandomAccessFile in = new RandomAccessFile(PACKED_PATH, "r");
     FileChannel channel = in.getChannel();
     ByteBuffer buffer = channel.map(MapMode.READ_ONLY, 0, channel.size());
     itemBonuses = new HashMap<Integer, int[]>(buffer.remaining() / 38);
     while (buffer.hasRemaining()) {
       int itemId = buffer.getShort() & 0xffff;
       int[] bonuses = new int[18];
       for (int index = 0; index < bonuses.length; index++) bonuses[index] = buffer.getShort();
       itemBonuses.put(itemId, bonuses);
     }
     channel.close();
     in.close();
   } catch (Throwable e) {
     Logger.handle(e);
   }
 }
 private static void loadUnpackedShops() {
   Logger.log("ShopsHandler", "Packing shops...");
   try {
     BufferedReader in = new BufferedReader(new FileReader(UNPACKED_PATH));
     DataOutputStream out = new DataOutputStream(new FileOutputStream(PACKED_PATH));
     while (true) {
       String line = in.readLine();
       if (line == null) break;
       if (line.startsWith("//")) continue;
       if (line.isEmpty()) continue;
       String[] splitedLine = line.split(" - ", 3);
       if (splitedLine.length != 3)
         throw new RuntimeException("Invalid list for shop line: " + line);
       String[] splitedInform = splitedLine[0].split(" ", 3);
       if (splitedInform.length != 3)
         throw new RuntimeException("Invalid list for shop line: " + line);
       String[] splitedItems = splitedLine[2].split(" ");
       int key = Integer.valueOf(splitedInform[0]);
       int money = Integer.valueOf(splitedInform[1]);
       boolean generalStore = Boolean.valueOf(splitedInform[2]);
       Item[] items = new Item[splitedItems.length / 2];
       int count = 0;
       for (int i = 0; i < items.length; i++)
         items[i] =
             new Item(
                 Integer.valueOf(splitedItems[count++]), Integer.valueOf(splitedItems[count++]));
       out.writeInt(key);
       writeAlexString(out, splitedLine[1]);
       out.writeShort(money);
       out.writeBoolean(generalStore);
       out.writeByte(items.length);
       for (Item item : items) {
         out.writeShort(item.getId());
         out.writeInt(item.getAmount());
       }
       addShop(key, new Shop(splitedLine[1], money, items, generalStore));
     }
     in.close();
     out.close();
   } catch (Throwable e) {
     Logger.handle(e);
   }
 }
  private static void loadPackedShops() {
    try {
      RandomAccessFile in = new RandomAccessFile(PACKED_PATH, "r");
      FileChannel channel = in.getChannel();
      ByteBuffer buffer = channel.map(MapMode.READ_ONLY, 0, channel.size());
      while (buffer.hasRemaining()) {
        int key = buffer.getInt();
        String name = readAlexString(buffer);
        int money = buffer.getShort() & 0xffff;
        boolean generalStore = buffer.get() == 1;
        Item[] items = new Item[buffer.get() & 0xff];
        for (int i = 0; i < items.length; i++)
          items[i] = new Item(buffer.getShort() & 0xffff, buffer.getInt());

        addShop(key, new Shop(name, money, items, generalStore));
      }
      channel.close();
      in.close();
    } catch (Throwable e) {
      Logger.handle(e);
    }
  }