Share Pastebin
Guest
Public paste!

Untitled

By: a guest | Mar 18th, 2010 | Syntax: None | Size: 3.77 KB | Hits: 59 | Expires: Never
Copy text to clipboard
  1. /*
  2.         This file is part of the OdinMS Maple Story Server
  3.     Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
  4.                        Matthias Butz <matze@odinms.de>
  5.                        Jan Christian Meyer <vimes@odinms.de>
  6.  
  7.     This program is free software: you can redistribute it and/or modify
  8.     it under the terms of the GNU Affero General Public License as
  9.     published by the Free Software Foundation version 3 as published by
  10.     the Free Software Foundation. You may not use, modify or distribute
  11.     this program under any other version of the GNU Affero General Public
  12.     License.
  13.  
  14.     This program is distributed in the hope that it will be useful,
  15.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  16.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17.     GNU Affero General Public License for more details.
  18.  
  19.     You should have received a copy of the GNU Affero General Public License
  20.     along with this program.  If not, see <http://www.gnu.org/licenses/>.
  21. */
  22. package server.life;
  23.  
  24. import java.sql.PreparedStatement;
  25. import java.sql.ResultSet;
  26. import java.sql.SQLException;
  27. import java.util.HashMap;
  28. import java.util.LinkedList;
  29. import java.util.List;
  30. import java.util.Map;
  31. import tools.DatabaseConnection;
  32.  
  33. /**
  34.  *
  35.  * @author Matze
  36.  */
  37. public class MapleMonsterInformationProvider {
  38.     public static class DropEntry {
  39.         public DropEntry(int itemId, int chance) {
  40.             this.itemId = itemId;
  41.             this.chance = chance;
  42.         }
  43.         public int itemId;
  44.         public int chance;
  45.         public int assignedRangeStart;
  46.         public int assignedRangeLength;
  47.     }
  48.     private static MapleMonsterInformationProvider instance = null;
  49.     private Map<Integer, List<DropEntry>> drops = new HashMap<Integer, List<DropEntry>>();
  50.  
  51.     public static MapleMonsterInformationProvider getInstance() {
  52.         if (instance == null) {
  53.             instance = new MapleMonsterInformationProvider();
  54.         }
  55.         return instance;
  56.     }
  57.  
  58.     public List<DropEntry> retrieveDropChances(int monsterId) {
  59.         if (drops.containsKey(monsterId)) {
  60.             return drops.get(monsterId);
  61.         }
  62.         List<DropEntry> ret = new LinkedList<DropEntry>();
  63.         if (monsterId > 9300183 && monsterId < 9300216) {
  64.             for (int i = 2022359; i < 2022367; i++) {
  65.                 ret.add(new DropEntry(i, 10));
  66.             }
  67.             drops.put(monsterId, ret);
  68.             return ret;
  69.         } else if (monsterId > 9300215 && monsterId < 9300269) {
  70.             for (int i = 2022430; i < 2022434; i++) {
  71.                 ret.add(new DropEntry(i, 3));
  72.             }
  73.             drops.put(monsterId, ret);
  74.             return ret;
  75.         }
  76.         try {
  77.             PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("SELECT itemid, chance, monsterid FROM monsterdrops WHERE (monsterid = ? AND chance >= 0) OR (monsterid <= 0)");
  78.             ps.setInt(1, monsterId);
  79.             ResultSet rs = ps.executeQuery();
  80.             MapleMonster theMonster = null;
  81.             while (rs.next()) {
  82.                 int rowMonsterId = rs.getInt("monsterid");
  83.                 int chance = rs.getInt("chance");
  84.                 if (rowMonsterId != monsterId && rowMonsterId != 0) {
  85.                     if (theMonster == null) {
  86.                         theMonster = MapleLifeFactory.getMonster(monsterId);
  87.                     }
  88.                     chance += theMonster.getLevel() * rowMonsterId;
  89.                 }
  90.                 ret.add(new DropEntry(rs.getInt("itemid"), chance));
  91.             }
  92.             rs.close();
  93.             ps.close();
  94.         } catch (SQLException e) {
  95.         }
  96.         drops.put(monsterId, ret);
  97.         return ret;
  98.     }
  99.  
  100.     public void clearDrops() {
  101.         drops.clear();
  102.     }
  103. }