DevWilliams

DropType

Apr 20th, 2021
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.41 KB | None | 0 0
  1. diff --git a/aCis/data/xml/dropType.xml b/aCis/data/xml/dropType.xml
  2. new file mode 100644
  3. index 0000000..a30f1f7
  4. --- /dev/null
  5. +++ b/aCis/data/xml/dropType.xml
  6. @@ -0,0 +1,12 @@
  7. +<?xml version="1.0" encoding="UTF-8"?>
  8. +<list>
  9. +<!--
  10. +@param Integer npcId - select the npc id to dropped the items
  11. +@param String type - select the npc type for items to be dropped.
  12. +@param Integer itemId - the id of the dropped item.
  13. +@param Integer minDrop - the minimum quantity of dropped items.
  14. +@param Integer maxDrop - the maximum quantity of dropped items.
  15. +@param Integer chance - the chance to have a drop, under a 1000000 chance.
  16. +-->
  17. + <drops type="Monster" itemId="3470" minDrop="1" maxDrop="1" chance="1000000"/>
  18. +</list>
  19. \ No newline at end of file
  20. diff --git a/aCis/java/net/sf/l2j/gameserver/GameServer.java b/aCis/java/net/sf/l2j/gameserver/GameServer.java
  21. index d10ac2b..3c23a09 100644
  22. --- a/aCis/java/net/sf/l2j/gameserver/GameServer.java
  23. +++ b/aCis/java/net/sf/l2j/gameserver/GameServer.java
  24. @@ -60,6 +60,7 @@
  25. import net.sf.l2j.gameserver.data.xml.AugmentationData;
  26. import net.sf.l2j.gameserver.data.xml.DoorData;
  27. import net.sf.l2j.gameserver.data.xml.DressMeData;
  28. +import net.sf.l2j.gameserver.data.xml.DropTypeData;
  29. import net.sf.l2j.gameserver.data.xml.FishData;
  30. import net.sf.l2j.gameserver.data.xml.HennaData;
  31. import net.sf.l2j.gameserver.data.xml.HerbDropData;
  32. @@ -238,6 +239,7 @@
  33.  
  34. StringUtil.printSection("NPCs");
  35. BufferManager.getInstance();
  36. + DropTypeData.getInstance();
  37. HerbDropData.getInstance();
  38. NpcData.getInstance();
  39. WalkerRouteData.getInstance();
  40. diff --git a/aCis/java/net/sf/l2j/gameserver/data/xml/DropTypeData.java b/aCis/java/net/sf/l2j/gameserver/data/xml/DropTypeData.java
  41. new file mode 100644
  42. index 0000000..2a6b225
  43. --- /dev/null
  44. +++ b/aCis/java/net/sf/l2j/gameserver/data/xml/DropTypeData.java
  45. @@ -0,0 +1,84 @@
  46. +package net.sf.l2j.gameserver.data.xml;
  47. +
  48. +import java.nio.file.Path;
  49. +import java.util.ArrayList;
  50. +import java.util.List;
  51. +
  52. +import net.sf.l2j.commons.data.xml.IXmlReader;
  53. +
  54. +import net.sf.l2j.gameserver.model.actor.template.NpcTemplate;
  55. +import net.sf.l2j.gameserver.model.item.DropCategory;
  56. +import net.sf.l2j.gameserver.model.item.DropType;
  57. +
  58. +import org.w3c.dom.Document;
  59. +
  60. +/**
  61. + * @author Williams
  62. + *
  63. + */
  64. +public class DropTypeData implements IXmlReader
  65. +{
  66. + private final List<DropType> _data = new ArrayList<>();
  67. +
  68. + public DropTypeData()
  69. + {
  70. + load();
  71. + }
  72. +
  73. + @Override
  74. + public void load()
  75. + {
  76. + parseFile("./data/xml/dropType.xml");
  77. + LOGGER.info("Loaded {} drop data.", _data.size());
  78. + }
  79. +
  80. + @Override
  81. + public void parseDocument(Document doc, Path path)
  82. + {
  83. + forEach(doc, "list", listNode ->
  84. + {
  85. + forEach(listNode, "drops", dropNode ->
  86. + {
  87. + final DropType data = new DropType(parseAttributes(dropNode));
  88. + final DropCategory category = new DropCategory(data.getItemId());
  89. +
  90. + if (ItemData.getInstance().getTemplate(data.getItemId()) == null)
  91. + {
  92. + LOGGER.warn("Droplist data for undefined itemId: {}.", data.getItemId());
  93. + return;
  94. + }
  95. +
  96. + category.addDropData(data, false);
  97. +
  98. + for (NpcTemplate template : NpcData.getInstance().getAllNpcs())
  99. + {
  100. + if (data.getType().equalsIgnoreCase(template.getType()) || data.getNpcId() == template.getNpcId())
  101. + template.addDropCategory(category);
  102. + }
  103. +
  104. + _data.add(data);
  105. + });
  106. + });
  107. + }
  108. +
  109. + public void reload()
  110. + {
  111. + _data.clear();
  112. + load();
  113. + }
  114. +
  115. + public List<DropType> getDrops()
  116. + {
  117. + return _data;
  118. + }
  119. +
  120. + public static DropTypeData getInstance()
  121. + {
  122. + return SingletonHolder.INSTANCE;
  123. + }
  124. +
  125. + private static class SingletonHolder
  126. + {
  127. + protected static final DropTypeData INSTANCE = new DropTypeData();
  128. + }
  129. +}
  130. \ No newline at end of file
  131. diff --git a/aCis/java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminReload.java b/aCis/java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminReload.java
  132. index f322922..2dc7f5c 100644
  133. --- a/aCis/java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminReload.java
  134. +++ b/aCis/java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminReload.java
  135. @@ -13,6 +13,7 @@
  136. import net.sf.l2j.gameserver.data.xml.AnnouncementData;
  137. import net.sf.l2j.gameserver.data.xml.DoorData;
  138. import net.sf.l2j.gameserver.data.xml.DressMeData;
  139. +import net.sf.l2j.gameserver.data.xml.DropTypeData;
  140. import net.sf.l2j.gameserver.data.xml.EnchantData;
  141. import net.sf.l2j.gameserver.data.xml.InstantTeleportData;
  142. import net.sf.l2j.gameserver.data.xml.ItemData;
  143. @@ -74,6 +75,11 @@
  144. CursedWeaponManager.getInstance().reload();
  145. player.sendMessage("Cursed weapons have been reloaded.");
  146. }
  147. + else if (type.startsWith("drop"))
  148. + {
  149. + DropTypeData.getInstance().reload();
  150. + player.sendMessage("Drop have been reloaded.");
  151. + }
  152. else if (type.startsWith("door"))
  153. {
  154. DoorData.getInstance().reload();
  155. @@ -160,7 +166,7 @@
  156. public void sendUsage(Player player)
  157. {
  158. player.sendMessage("Usage : //reload <admin|announcement|buylist|config>");
  159. - player.sendMessage("Usage : //reload <crest|cw|door|dress|enchant|htm|item|multisell|npc>");
  160. + player.sendMessage("Usage : //reload <crest|cw|drop|door|dress|enchant|htm|item|multisell|npc>");
  161. player.sendMessage("Usage : //reload <npcwalker|poly|script|skill|spree|teleport|zone>");
  162. }
  163.  
  164. diff --git a/aCis/java/net/sf/l2j/gameserver/model/actor/template/NpcTemplate.java b/aCis/java/net/sf/l2j/gameserver/model/actor/template/NpcTemplate.java
  165. index 2bf8cca..0944739 100644
  166. --- a/aCis/java/net/sf/l2j/gameserver/model/actor/template/NpcTemplate.java
  167. +++ b/aCis/java/net/sf/l2j/gameserver/model/actor/template/NpcTemplate.java
  168. @@ -340,7 +340,38 @@
  169. }
  170. return list;
  171. }
  172. +
  173. + public final void addDropCategory(DropCategory category)
  174. + {
  175. + synchronized (_categories)
  176. + {
  177. + if (_categories.isEmpty())
  178. + _categories = new ArrayList<>(); // empty means _categories is instance of Collections.emptyList(); - cannot add items to this container
  179. + else
  180. + {
  181. + // category already exists, return
  182. + for (DropCategory cat : _categories)
  183. + {
  184. + if (cat.getCategoryType() == category.getCategoryType())
  185. + return;
  186. + }
  187. + }
  188. +
  189. + _categories.add(category);
  190. + }
  191. + }
  192.  
  193. + public final void removeDropCategory(DropCategory category)
  194. + {
  195. + synchronized (_categories)
  196. + {
  197. + if (_categories.isEmpty())
  198. + return;
  199. +
  200. + _categories.remove(category);
  201. + }
  202. + }
  203. +
  204. /**
  205. * @return the {@link List} of all possible {@link DropData}s of this {@link NpcTemplate} linked to SPOIL behavior.
  206. */
  207. @@ -354,36 +385,7 @@
  208. }
  209. return list;
  210. }
  211. -
  212. - /**
  213. - * Add a {@link DropData} to a given category. If the category does not exist, create it.
  214. - * @param drop : The DropData to add.
  215. - * @param categoryType : The category type we refer.
  216. - */
  217. - public void addDropData(DropData drop, int categoryType)
  218. - {
  219. - final boolean isBossType = isType("RaidBoss") || isType("GrandBoss");
  220. -
  221. - synchronized (_categories)
  222. - {
  223. - // Category exists, stores the drop and return.
  224. - for (DropCategory cat : _categories)
  225. - {
  226. - if (cat.getCategoryType() == categoryType)
  227. - {
  228. - cat.addDropData(drop, isBossType);
  229. - return;
  230. - }
  231. - }
  232. -
  233. - // Category doesn't exist, create and store it.
  234. - final DropCategory cat = new DropCategory(categoryType);
  235. - cat.addDropData(drop, isBossType);
  236. -
  237. - _categories.add(cat);
  238. - }
  239. - }
  240. -
  241. +
  242. /**
  243. * @return the {@link List} of all {@link MinionData}.
  244. */
  245. diff --git a/aCis/java/net/sf/l2j/gameserver/model/item/DropType.java b/aCis/java/net/sf/l2j/gameserver/model/item/DropType.java
  246. new file mode 100644
  247. index 0000000..fa43cf8
  248. --- /dev/null
  249. +++ b/aCis/java/net/sf/l2j/gameserver/model/item/DropType.java
  250. @@ -0,0 +1,31 @@
  251. +package net.sf.l2j.gameserver.model.item;
  252. +
  253. +import net.sf.l2j.commons.data.StatSet;
  254. +
  255. +/**
  256. + * @author Williams
  257. + *
  258. + */
  259. +public class DropType extends DropData
  260. +{
  261. + private final String _type;
  262. + private final int _npcId;
  263. +
  264. + public DropType(StatSet set)
  265. + {
  266. + super(set.getInteger("itemId"), set.getInteger("minDrop"), set.getInteger("maxDrop"), set.getInteger("chance"));
  267. +
  268. + _npcId = set.getInteger("npcId", 0);
  269. + _type = set.getString("type", "");
  270. + }
  271. +
  272. + public int getNpcId()
  273. + {
  274. + return _npcId;
  275. + }
  276. +
  277. + public String getType()
  278. + {
  279. + return _type;
  280. + }
  281. +}
  282. \ No newline at end of file
Advertisement
Add Comment
Please, Sign In to add comment