📄 mapleiteminformationprovider.java
字号:
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation. You may not use, modify
or distribute this program under any other version of the
GNU Affero General Public License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*
* MapleItemInformationProvider.java
*
* Created on 26. November 2007, 21:58
*
* To change this template, choose Tools | Template Manager and open the template in the editor.
*/
package net.sf.odinms.server;
import java.io.File;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;
import net.sf.odinms.client.Equip;
import net.sf.odinms.client.IItem;
import net.sf.odinms.client.MapleInventoryType;
import net.sf.odinms.client.MapleWeaponType;
import net.sf.odinms.provider.MapleData;
import net.sf.odinms.provider.MapleDataDirectoryEntry;
import net.sf.odinms.provider.MapleDataFileEntry;
import net.sf.odinms.provider.MapleDataProvider;
import net.sf.odinms.provider.MapleDataProviderFactory;
import net.sf.odinms.provider.MapleDataTool;
/**
*
* @author Matze
*
* TODO: make faster
*
*/
public class MapleItemInformationProvider {
private static MapleItemInformationProvider instance = null;
protected MapleDataProvider itemData;
protected MapleDataProvider equipData;
protected MapleData stringData;
protected Map<Integer, MapleInventoryType> inventoryTypeCache = new HashMap<Integer, MapleInventoryType>();
protected Map<Integer, Short> slotMaxCache = new HashMap<Integer, Short>();
protected Map<Integer, MapleStatEffect> itemEffects = new HashMap<Integer, MapleStatEffect>();
protected Map<Integer, Map<String, Integer>> equipStatsCache = new HashMap<Integer, Map<String, Integer>>();
protected Map<Integer, Equip> equipCache = new HashMap<Integer, Equip>();
protected Map<Integer, Double> priceCache = new HashMap<Integer, Double>();
protected Map<Integer, Integer> wholePriceCache = new HashMap<Integer, Integer>();
protected Map<Integer, Integer> projectileWatkCache = new HashMap<Integer, Integer>();
protected Map<Integer, String> nameCache = new HashMap<Integer, String>();
protected Map<Integer, String> descCache = new HashMap<Integer, String>();
/** Creates a new instance of MapleItemInformationProvider */
protected MapleItemInformationProvider() {
itemData = MapleDataProviderFactory.getDataProvider(new File(System.getProperty("net.sf.odinms.wzpath") + "/Item.wz"));
equipData = MapleDataProviderFactory.getDataProvider(new File(System.getProperty("net.sf.odinms.wzpath") + "/Character.wz"));
stringData = MapleDataProviderFactory.getDataProvider(new File(System.getProperty("net.sf.odinms.wzpath") + "/String.wz")).getData("Item.img");
}
public static MapleItemInformationProvider getInstance() {
if (instance == null)
instance = new MapleItemInformationProvider();
return instance;
}
/* returns the inventory type for the specified item id */
public MapleInventoryType getInventoryType(int itemId) {
if (inventoryTypeCache.containsKey(itemId))
return inventoryTypeCache.get(itemId);
MapleInventoryType ret;
String idStr = "0" + String.valueOf(itemId);
// first look in items...
MapleDataDirectoryEntry root = itemData.getRoot();
for (MapleDataDirectoryEntry topDir : root.getSubdirectories()) {
// we should have .img files here beginning with the first 4 IID
for (MapleDataFileEntry iFile : topDir.getFiles()) {
if (iFile.getName().equals(idStr.substring(0, 4) + ".img")) {
ret = MapleInventoryType.getByWZName(topDir.getName());
inventoryTypeCache.put(itemId, ret);
return ret;
} else if (iFile.getName().equals(idStr.substring(1) + ".img")) {
ret = MapleInventoryType.getByWZName(topDir.getName());
inventoryTypeCache.put(itemId, ret);
return ret;
}
}
}
// not found? maybe its equip...
root = equipData.getRoot();
for (MapleDataDirectoryEntry topDir : root.getSubdirectories()) {
for (MapleDataFileEntry iFile : topDir.getFiles()) {
if (iFile.getName().equals(idStr + ".img")) {
ret = MapleInventoryType.EQUIP;
inventoryTypeCache.put(itemId, ret);
return ret;
}
}
}
ret = MapleInventoryType.UNDEFINED;
inventoryTypeCache.put(itemId, ret);
return ret;
}
protected MapleData getStringData(int itemId) {
String cat;
if (itemId >= 5010000)
cat = "Cash";
else if (itemId >= 2000000 && itemId < 3000000)
cat = "Con";
else if (itemId >= 1010000 && itemId < 1040000 || itemId >= 1122000 && itemId < 1123000)
cat = "Eqp/Accessory";
else if (itemId >= 1000000 && itemId < 1010000)
cat = "Eqp/Cap";
else if (itemId >= 1102000 && itemId < 1103000)
cat = "Eqp/Cape";
else if (itemId >= 1040000 && itemId < 1050000)
cat = "Eqp/Coat";
else if (itemId >= 20000 && itemId < 22000)
cat = "Eqp/Face";
else if (itemId >= 1080000 && itemId < 1090000)
cat = "Eqp/Glove";
else if (itemId >= 30000 && itemId < 32000)
cat = "Eqp/Hair";
else if (itemId >= 1050000 && itemId < 1060000)
cat = "Eqp/Longcoat";
else if (itemId >= 1060000 && itemId < 1070000)
cat = "Eqp/Pants";
else if (itemId >= 1802000 && itemId < 1810000)
cat = "Eqp/PetEquip";
else if (itemId >= 1112000 && itemId < 1120000)
cat = "Eqp/Ring";
else if (itemId >= 1092000 && itemId < 1100000)
cat = "Eqp/Shield";
else if (itemId >= 1070000 && itemId < 1080000)
cat = "Eqp/Shoes";
else if (itemId >= 1900000 && itemId < 2000000)
cat = "Eqp/Taming";
else if (itemId >= 1300000 && itemId < 1800000)
cat = "Eqp/Weapon";
else if (itemId >= 4000000 && itemId < 5000000)
cat = "Etc";
else if (itemId >= 3000000 && itemId < 4000000)
cat = "Ins";
else if (itemId >= 5000000 && itemId < 5010000)
cat = "Pet";
else return null;
return stringData.getChildByPath(cat + "/" + itemId);
}
protected MapleData getItemData(int itemId) {
MapleData ret = null;
String idStr = "0" + String.valueOf(itemId);
MapleDataDirectoryEntry root = itemData.getRoot();
for (MapleDataDirectoryEntry topDir : root.getSubdirectories()) {
// we should have .img files here beginning with the first 4 IID
for (MapleDataFileEntry iFile : topDir.getFiles()) {
if (iFile.getName().equals(idStr.substring(0, 4) + ".img")) {
ret = itemData.getData(topDir.getName() + "/" + iFile.getName());
if (ret == null)
return null;
ret = ret.getChildByPath(idStr);
return ret;
} else if (iFile.getName().equals(idStr.substring(1) + ".img")) {
return itemData.getData(topDir.getName() + "/" + iFile.getName());
}
}
}
root = equipData.getRoot();
for (MapleDataDirectoryEntry topDir : root.getSubdirectories()) {
for (MapleDataFileEntry iFile : topDir.getFiles()) {
if (iFile.getName().equals(idStr + ".img")) {
return equipData.getData(topDir.getName() + "/" + iFile.getName());
}
}
}
return ret;
}
/** returns the maximum of items in one slot */
public short getSlotMax(int itemId) {
if (slotMaxCache.containsKey(itemId))
return slotMaxCache.get(itemId);
short ret = 0;
MapleData item = getItemData(itemId);
if (item != null) {
MapleData smEntry = item.getChildByPath("info/slotMax");
if (smEntry == null) {
if (getInventoryType(itemId).getType() == MapleInventoryType.EQUIP.getType())
ret = 1;
else
ret = 100;
} else {
if (isThrowingStar(itemId))
ret = 1;
else if (MapleDataTool.getInt(smEntry) == 0)
ret = 1;
ret = (short) MapleDataTool.getInt(smEntry);
}
}
slotMaxCache.put(itemId, ret);
return ret;
}
public int getWholePrice(int itemId) {
if (wholePriceCache.containsKey(itemId))
return wholePriceCache.get(itemId);
MapleData item = getItemData(itemId);
if (item == null)
return -1;
int pEntry = 0;
MapleData pData = item.getChildByPath("info/price");
if (pData == null)
return -1;
pEntry = MapleDataTool.getInt(pData);
wholePriceCache.put(itemId, pEntry);
return pEntry;
}
public double getPrice(int itemId) {
if (priceCache.containsKey(itemId))
return priceCache.get(itemId);
MapleData item = getItemData(itemId);
if (item == null)
return -1;
//TODO ULTRAHACK - prevent players gaining miriads of mesars with orbis/eos scrolls
if (itemId == 4001019 || itemId == 4001020) {
return 0;
}
double pEntry = 0.0;
MapleData pData = item.getChildByPath("info/unitPrice");
if (pData != null) {
try {
pEntry = MapleDataTool.getDouble(pData);
} catch (Exception e) {
pEntry = (double) MapleDataTool.getInt(pData);
}
} else {
pData = item.getChildByPath("info/price");
if (pData == null)
return -1;
pEntry = (double) MapleDataTool.getInt(pData);
}
priceCache.put(itemId, pEntry);
return pEntry;
}
protected Map<String, Integer> getEquipStats(int itemId) {
if (equipStatsCache.containsKey(itemId))
return equipStatsCache.get(itemId);
Map<String, Integer> ret = new LinkedHashMap<String, Integer>();
MapleData item = getItemData(itemId);
if (item == null)
return null;
MapleData info = item.getChildByPath("info");
if (info == null)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -