Advertisement
Guest User

kapuk99

a guest
Jan 1st, 2010
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.03 KB | None | 0 0
  1. package net.sf.odinms.server;
  2.  
  3. import java.io.File;
  4. import java.util.HashMap;
  5. import java.util.Map;
  6. import net.sf.odinms.provider.MapleData;
  7. import net.sf.odinms.provider.MapleDataProvider;
  8. import net.sf.odinms.provider.MapleDataProviderFactory;
  9. import net.sf.odinms.provider.MapleDataTool;
  10. import net.sf.odinms.tools.StringUtil;
  11.  
  12. public class CashItemFactory {
  13.     private static Map<Integer, Integer> snLookup = new HashMap<Integer,Integer>();
  14.     private static Map<Integer, CashItemInfo> itemStats = new HashMap<Integer, CashItemInfo>();
  15.     private static MapleDataProvider data = MapleDataProviderFactory.getDataProvider(new File(System.getProperty("net.sf.odinms.wzpath") + "/Etc.wz"));
  16.     private static MapleData commodities = data.getData(StringUtil.getLeftPaddedStr("Commodity.img", '0', 11));
  17.     private static CashItemFactory instance = null;
  18.  
  19.     public static CashItemInfo getItem(int sn) {
  20.         CashItemInfo stats = itemStats.get(sn);
  21.         if (stats == null) {
  22.             int cid = getCommodityFromSN(sn);
  23.            
  24.             int itemId = MapleDataTool.getIntConvert(cid + "/ItemId",commodities);
  25.             int count = MapleDataTool.getIntConvert(cid + "/Count",commodities,1);
  26.             int price = MapleDataTool.getIntConvert(cid + "/Price",commodities,0);
  27.            
  28.             stats = new CashItemInfo(itemId, count, price);
  29.            
  30.             itemStats.put(sn, stats);
  31.         }
  32.        
  33.         return stats;
  34.     }
  35.  
  36.     public static CashItemFactory getInstance() {
  37.         if (instance == null)
  38.             instance = new CashItemFactory();
  39.         return instance;
  40.     }
  41.        
  42.     private static int getCommodityFromSN(int sn) {
  43.         int cid;
  44.        
  45.         if (snLookup.get(sn) == null) {
  46.             int curr = snLookup.size() - 1;
  47.             int currSN = 0;
  48.             if (curr == -1) {
  49.                 curr = 0;
  50.                 currSN = MapleDataTool.getIntConvert("0/SN",commodities);
  51.                 snLookup.put(currSN, curr);
  52.                
  53.             }
  54.             for (int i = snLookup.size() - 1; currSN != sn; i++) {
  55.                 curr = i;
  56.                 currSN = MapleDataTool.getIntConvert(curr + "/SN",commodities);
  57.                 snLookup.put(currSN, curr);
  58.             }
  59.             cid = curr;
  60.         } else {
  61.             cid = snLookup.get(sn);
  62.         }
  63.         return cid;
  64.     }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement