Guest User

Untitled

a guest
Nov 29th, 2013
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.81 KB | None | 0 0
  1. package org.classified;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.FileReader;
  5. import java.io.IOException;
  6. import java.io.RandomAccessFile;
  7. import java.nio.ByteBuffer;
  8. import java.nio.channels.FileChannel;
  9. import java.nio.channels.FileChannel.MapMode;
  10. import java.util.ArrayList;
  11. import java.util.List;
  12.  
  13. /**
  14. * @author classified
  15. */
  16. public final class ItemDefinition {
  17.  
  18. public static int MAX_SIZE = 20792;
  19. private static ItemDefinition[] definitions;
  20.  
  21. public static void init() throws IOException {
  22. System.out.println("Loading item definitions...");
  23. FileChannel channel = new RandomAccessFile("data/item/itemDefinitions.bin", "r").getChannel();
  24.  
  25. ByteBuffer buffer = channel.map(MapMode.READ_ONLY, 0, channel.size());
  26.  
  27. int length = buffer.getShort();
  28.  
  29. definitions = new ItemDefinition[MAX_SIZE];
  30.  
  31. for (int i = 0; i < length; i++) {
  32. int id = buffer.getShort();
  33. if (id == -1) {
  34. continue;
  35. }
  36. int equipId = buffer.getShort();
  37. int renderEmote = buffer.getShort();
  38. String name = BufferUtils.readRS2String(buffer);
  39. boolean noted = buffer.get() == 0;
  40. int[] bonus = new int[15];
  41. int[] absorptionBonus = new int[3];
  42. boolean tradeable = true;
  43. int attackSpeed = 5;
  44. int equipmentSlot = -1;
  45. String examine = BufferUtils.readRS2String(buffer);
  46. double weight = 0;
  47. int highAlchPrice = 0, lowAlchPrice = 0, storePrice = 0, exchangePrice = 0;
  48. if (!noted) {
  49. weight = buffer.getDouble();
  50. equipmentSlot = buffer.get();
  51. tradeable = buffer.get() == 1;
  52. attackSpeed = buffer.get();
  53. if (buffer.get() == 1) {
  54. for (int x = 0; x < 15; x++) {
  55. bonus[x] = buffer.getShort();
  56. }
  57. }
  58. if (buffer.get() == 1) {
  59. for (int x = 0; x < 3; x++) {
  60. absorptionBonus[x] = buffer.getShort();
  61. }
  62. }
  63. }
  64. highAlchPrice = buffer.getInt();
  65. lowAlchPrice = buffer.getInt();
  66. storePrice = buffer.getInt();
  67. exchangePrice = buffer.getInt();
  68. boolean stackable = buffer.get() == 1;
  69. boolean hasReq = buffer.get() == 1;
  70. ArrayList<Integer> skillRequirementId = null;
  71. ArrayList<Integer> skillRequirementLvl = null;
  72. if (hasReq) {
  73. skillRequirementId = new ArrayList<Integer>();
  74. skillRequirementLvl = new ArrayList<Integer>();
  75. int size = buffer.get();
  76. for (int j = 0; j < size; j++) {
  77. skillRequirementId.add((int) buffer.get());
  78. skillRequirementLvl.add((int) buffer.get());
  79. }
  80. }
  81. boolean dropable = buffer.get() == 1;
  82. boolean twoHanded = buffer.get() == 1;
  83. if(id == 4718) {
  84. twoHanded = true;
  85. }
  86. if (id == 15220) {
  87. bonus[11] = 8;
  88. }
  89. if (id == 18819) {
  90. for (int ii = 0; ii < 15; ii++) {
  91. if (ii == 11) continue;
  92. bonus[ii] = 0;
  93. }
  94. bonus[11] = 0;
  95. }
  96. definitions[id] = new ItemDefinition(id, name, examine, equipId, renderEmote, bonus, stackable, noted, tradeable, skillRequirementId, skillRequirementLvl, weight, highAlchPrice, lowAlchPrice, storePrice, exchangePrice, attackSpeed, equipmentSlot, absorptionBonus, dropable, twoHanded);
  97. // definitions[id].setExtraDefinitions(extraDefinition);
  98. }
  99. loadMiscData();
  100. System.out.println("Loaded " + definitions.length + " item definitions.");
  101. channel.close();
  102. channel = null;
  103. RangeWeapon.initialize();
  104. Ammunition.initialize();
  105. }
  106.  
  107. private static void loadMiscData() throws IOException {
  108. BufferedReader reader = new BufferedReader(new FileReader("data/item/poisoningitems.txt"));
  109. String string;
  110. while ((string = reader.readLine()) != null) {
  111. String[] data = string.split(":");
  112. int id = Integer.parseInt(data[0]);
  113. int amount = Integer.parseInt(data[1]);
  114. definitions[id].setPoisonAmount(amount);
  115. }
  116. reader = new BufferedReader(new FileReader("data/item/equipIds.txt"));
  117. while ((string = reader.readLine()) != null) {
  118. String[] data = string.split(":");
  119. int id = Integer.parseInt(data[0]);
  120. int equipId = Integer.parseInt(data[1]);
  121. definitions[id].setEquipId(equipId);
  122. }
  123. }
  124.  
  125.  
  126. public static ItemDefinition forId(int id) {
  127. if (id == -1)
  128. return null;
  129. ItemDefinition def = definitions[id];
  130. if (def == null) {
  131. definitions[id] = new ItemDefinition(id, "", "", -1, -1, new int[15], false, false, true, null, null, 0.0, 0, 0, 0, 0, 0, 0, null, true, false);
  132. }
  133. return definitions[id];
  134. }
  135.  
  136. public static ItemDefinition forName(String name) {
  137. for (ItemDefinition definition : definitions) {
  138. if (definition.name.equalsIgnoreCase(name)) {
  139. return definition;
  140. }
  141. }
  142. return null;
  143. }
  144.  
  145. public static void clear() {
  146. definitions = new ItemDefinition[MAX_SIZE];
  147. }
  148.  
  149. private boolean dropable;
  150. private boolean twoHanded;
  151. private String name;
  152. private String examine;
  153. private int id;
  154. private int equipId;
  155. private int renderId;
  156. private int[] bonus;
  157. private boolean stackable;
  158. private boolean noted;
  159. private boolean tradeable;
  160. private List<Integer> skillRequirementId;
  161. private List<Integer> skillRequirementLvl;
  162. private double weight;
  163. private boolean members;
  164. private int highAlchPrice, lowAlchPrice, storePrice, exchangePrice, attackSpeed, equipmentSlot;
  165. private int poisonAmount;
  166.  
  167. private boolean extraDefinitions;
  168. private CacheItemDefinition cacheDefinition;
  169. private int[] absorptionBonus;
  170.  
  171. public ItemDefinition(int id, String name, String examine, int equipId, int renderId, int[] bonus, boolean stackable, boolean noted, boolean tradeable, List<Integer> skillRequirementId, List<Integer> skillRequirementLvl, double weight, int highAlchPrice, int lowAlchPrice, int storePrice, int exchangePrice, int attackSpeed, int equipmentSlot, int[] absorptionBonus, boolean dropable, boolean twoHanded) {
  172. this.id = id;
  173. this.name = name;
  174. if (examine.length() == 0 || examine == null) {
  175. if (name.length() > 0) {
  176. StringBuilder sb = new StringBuilder();
  177. sb.append("It's a");
  178. char c = name.charAt(0);
  179. if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') {
  180. sb.append("n");
  181. }
  182. sb.append(" ");
  183. sb.append(name);
  184. this.examine = sb.toString();
  185. }
  186. } else {
  187. this.examine = examine;
  188. }
  189. this.twoHanded = twoHanded;
  190. this.dropable = dropable;
  191. this.equipId = equipId;
  192. this.renderId = renderId;
  193. this.bonus = bonus;
  194. this.stackable = stackable;
  195. this.noted = noted;
  196. this.tradeable = tradeable;
  197. this.skillRequirementId = skillRequirementId;
  198. this.skillRequirementLvl = skillRequirementLvl;
  199. this.weight = weight;
  200. this.highAlchPrice = highAlchPrice;
  201. this.lowAlchPrice = lowAlchPrice;
  202. this.storePrice = storePrice;
  203. this.exchangePrice = exchangePrice;
  204. this.attackSpeed = attackSpeed;
  205. this.equipmentSlot = equipmentSlot;
  206. this.absorptionBonus = absorptionBonus;
  207. }
  208.  
  209. public String getName() {
  210. return name;
  211. }
  212.  
  213. public int getId() {
  214. return id;
  215. }
  216.  
  217. public int getEquipId() {
  218. return equipId;
  219. }
  220.  
  221. public int getRenderId() {
  222. return renderId;
  223. }
  224.  
  225. public int[] getBonus() {
  226. return bonus;
  227. }
  228.  
  229. public boolean isStackable() {
  230. return stackable || noted;
  231. }
  232.  
  233. public boolean isNoted() {
  234. return noted;
  235. }
  236.  
  237. public List<Integer> getSkillRequirementId() {
  238. return skillRequirementId;
  239. }
  240.  
  241. public List<Integer> getSkillRequirementLvl() {
  242. return skillRequirementLvl;
  243. }
  244.  
  245. public String getExamine() {
  246. return examine;
  247. }
  248.  
  249. public boolean isTradeable() {
  250. return tradeable;
  251. }
  252.  
  253. public double getWeight() {
  254. return weight;
  255. }
  256.  
  257. public int getHighAlchPrice() {
  258. return highAlchPrice;
  259. }
  260.  
  261. public int getLowAlchPrice() {
  262. return lowAlchPrice;
  263. }
  264.  
  265. public int getStorePrice() {
  266. return storePrice;
  267. }
  268.  
  269. public int getExchangePrice() {
  270. if (exchangePrice < 1 && storePrice < 1)
  271. return getCacheDefinition().getValue();
  272. return exchangePrice == 0 ? storePrice : exchangePrice;
  273. }
  274.  
  275. public int getAttackSpeed() {
  276. return attackSpeed;
  277. }
  278.  
  279. public int getEquipmentSlot() {
  280. return equipmentSlot;
  281. }
  282.  
  283. public void setName(String name) {
  284. this.name = name;
  285. }
  286.  
  287. public void setExamine(String examine) {
  288. this.examine = examine;
  289. }
  290.  
  291. public void setId(int id) {
  292. this.id = id;
  293. }
  294.  
  295. public void setEquipId(int equipId) {
  296. this.equipId = equipId;
  297. }
  298.  
  299. public void setRenderId(int renderId) {
  300. this.renderId = renderId;
  301. }
  302.  
  303. public void setBonus(int[] bonus) {
  304. this.bonus = bonus;
  305. }
  306.  
  307. public void setBonusAtIndex(int index, int value) {
  308. this.bonus[index] = value;
  309. }
  310.  
  311. public void setStackable(boolean stackable) {
  312. this.stackable = stackable;
  313. }
  314.  
  315. public void setNoted(boolean noted) {
  316. this.noted = noted;
  317. }
  318.  
  319. public void setTradeable(boolean tradeable) {
  320. this.tradeable = tradeable;
  321. }
  322.  
  323. public void setSkillRequirementId(List<Integer> skillRequirementId) {
  324. this.skillRequirementId = skillRequirementId;
  325. }
  326.  
  327. public void setSkillRequirementLvl(List<Integer> skillRequirementLvl) {
  328. this.skillRequirementLvl = skillRequirementLvl;
  329. }
  330.  
  331. public void setWeight(double weight) {
  332. this.weight = weight;
  333. }
  334.  
  335. public void setHighAlchPrice(int highAlchPrice) {
  336. this.highAlchPrice = highAlchPrice;
  337. }
  338.  
  339. public void setLowAlchPrice(int lowAlchPrice) {
  340. this.lowAlchPrice = lowAlchPrice;
  341. }
  342.  
  343. public void setStorePrice(int storePrice) {
  344. this.storePrice = storePrice;
  345. }
  346.  
  347. public void setExchangePrice(int exchangePrice) {
  348. this.exchangePrice = exchangePrice;
  349. }
  350.  
  351. public void setAttackSpeed(int attackSpeed) {
  352. this.attackSpeed = attackSpeed;
  353. }
  354.  
  355. public void setEquipmentSlot(int equipmentSlot) {
  356. this.equipmentSlot = equipmentSlot;
  357. }
  358.  
  359. public void setMembers(boolean members) {
  360. this.members = members;
  361. }
  362.  
  363. public boolean isMembers() {
  364. return members;
  365. }
  366.  
  367. public void setExtraDefinitions(boolean extraDefinition) {
  368. this.extraDefinitions = extraDefinition;
  369. }
  370.  
  371. public boolean isExtraDefinitions() {
  372. return extraDefinitions;
  373. }
  374.  
  375. public CacheItemDefinition getCacheDefinition() {
  376. if (cacheDefinition == null) {
  377. cacheDefinition = CacheItemDefinition.getItemDefinition(id);
  378. }
  379. return cacheDefinition;
  380. }
  381.  
  382. public static ItemDefinition[] getDefinitions() {
  383. return definitions;
  384. }
  385.  
  386. public void setAbsorptionBonus(int[] absorptionBonus) {
  387. this.absorptionBonus = absorptionBonus;
  388. }
  389.  
  390. public int[] getAbsorptionBonus() {
  391. return absorptionBonus;
  392. }
  393.  
  394. private void setPoisonAmount(int amount) {
  395. this.poisonAmount = amount;
  396.  
  397. }
  398.  
  399. public boolean doesPoison() {
  400. return poisonAmount > 0;
  401. }
  402.  
  403. public int getPoisonAmount() {
  404. return poisonAmount;
  405. }
  406.  
  407. /**
  408. * @return the dropable
  409. */
  410. public boolean isDropable() {
  411. return dropable;
  412. }
  413.  
  414. /**
  415. * @param dropable the dropable to set
  416. */
  417. public void setDropable(boolean dropable) {
  418. this.dropable = dropable;
  419. }
  420.  
  421. /**
  422. * @return the twoHanded
  423. */
  424. public boolean isTwoHanded() {
  425. return twoHanded;
  426. }
  427.  
  428. /**
  429. * @param twoHanded the twoHanded to set
  430. */
  431. public void setTwoHanded(boolean twoHanded) {
  432. this.twoHanded = twoHanded;
  433. }
  434.  
  435. }
Advertisement
Add Comment
Please, Sign In to add comment