Advertisement
tensador125

capsule_box l2jmega for lvl

Jun 30th, 2023
1,094
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 12.47 KB | Gaming | 1 0
  1. ### Eclipse Workspace Patch 1.0
  2. #P L2jMega_Interlude
  3. +data/xml/CapsuleBox.xml
  4. +<?xml version="1.0" encoding="utf-8"?>
  5. +<CapsuleBox>
  6. +   <capsuled_items ID="6393"  PlayerLevel="1"> <!-- Mage Starter Pack LVL 1-->
  7. +       <item itemId="177" min="1" max="1" enchantLevel="0"  chance="100"/>
  8. +       <item itemId="1101" min="1" max="1" enchantLevel="0" chance="100"/>
  9. +       <item itemId="1104" min="1" max="1" enchantLevel="0" chance="100"/>
  10. +       <item itemId="908" min="1" max="1" enchantLevel="0" chance="100"/>
  11. +       <item itemId="115" min="1" max="1" enchantLevel="0" chance="100"/>
  12. +       <item itemId="115" min="1" max="1" enchantLevel="0" chance="100"/>
  13. +       <item itemId="877" min="1" max="1" enchantLevel="0" chance="100"/>
  14. +       <item itemId="877" min="1" max="1" enchantLevel="0" chance="100"/>
  15. +       <item itemId="3948" min="1" max="10" enchantLevel="0" chance="100"/>
  16. +   </capsuled_items>
  17. +   <capsuled_items ID="6388"  PlayerLevel="1"> <!-- Fighter Starter Pack LVL 1-->
  18. +       <item itemId="68" min="1" max="1" enchantLevel="0" chance="100"/>
  19. +       <item itemId="711" min="1" max="1" enchantLevel="0" chance="100"/>
  20. +       <item itemId="715" min="1" max="1" enchantLevel="0" chance="100"/>
  21. +       <item itemId="908" min="1" max="1" enchantLevel="0" chance="100"/>
  22. +       <item itemId="115" min="1" max="1" enchantLevel="0" chance="100"/>
  23. +       <item itemId="115" min="1" max="1" enchantLevel="0" chance="100"/>
  24. +       <item itemId="877" min="1" max="1" enchantLevel="0" chance="100"/>
  25. +       <item itemId="877" min="1" max="1" enchantLevel="0" chance="100"/>
  26. +       <item itemId="1463" min="1" max="5" enchantLevel="0" chance="100"/>
  27. +   </capsuled_items>
  28. +</CapsuleBox>
  29. diff --git java/Base/CapsuleBox/CapsuleBoxData.java java/Base/CapsuleBox/CapsuleBoxData.java
  30. new file mode 100644
  31. index 0000000..2e76b8f
  32. --- /dev/null
  33. +++ java/Base/CapsuleBox/CapsuleBoxData.java
  34. @@ -0,0 +1,97 @@
  35. +package Base.CapsuleBox;
  36. +
  37. +import java.io.File;
  38. +import java.util.HashMap;
  39. +import java.util.Map;
  40. +
  41. +import org.w3c.dom.Document;
  42. +import org.w3c.dom.NamedNodeMap;
  43. +import org.w3c.dom.Node;
  44. +
  45. +import Base.Data.XMLDocument;
  46. +
  47. +public class CapsuleBoxData extends XMLDocument {
  48. +    private Map<Integer, CapsuleBoxItem> capsuleBoxItems;
  49. +
  50. +    public CapsuleBoxData() {
  51. +        capsuleBoxItems = new HashMap<>();
  52. +        load();
  53. +    }
  54. +
  55. +   public void reload()
  56. +   {
  57. +       capsuleBoxItems.clear();
  58. +       load();
  59. +   }  
  60. +    
  61. +    
  62. +    public static CapsuleBoxData getInstance() {
  63. +        return SingletonHolder.INSTANCE;
  64. +    }
  65. +
  66. +    private static class SingletonHolder {
  67. +        protected static final CapsuleBoxData INSTANCE = new CapsuleBoxData();
  68. +    }
  69. +
  70. +    @Override
  71. +    protected void load() {
  72. +        loadDocument("./data/xml/CapsuleBox.xml");
  73. +        LOG.info("CapsuleBoxData: Loaded " + capsuleBoxItems.size() + " items.");
  74. +    }
  75. +
  76. +    @Override
  77. +    protected void parseDocument(Document doc, File file) {
  78. +        try {
  79. +            final Node root = doc.getFirstChild();
  80. +
  81. +            for (Node node = root.getFirstChild(); node != null; node = node.getNextSibling()) {
  82. +                if (!"capsuled_items".equalsIgnoreCase(node.getNodeName())) {
  83. +                    continue;
  84. +                }
  85. +
  86. +                NamedNodeMap attrs = node.getAttributes();
  87. +                int id = Integer.parseInt(attrs.getNamedItem("ID").getNodeValue());
  88. +                int playerLevel = Integer.parseInt(attrs.getNamedItem("PlayerLevel").getNodeValue());
  89. +
  90. +                CapsuleBoxItem capsuleBoxItem = new CapsuleBoxItem(id, playerLevel);
  91. +
  92. +                for (Node itemNode = node.getFirstChild(); itemNode != null; itemNode = itemNode.getNextSibling()) {
  93. +                    if (!"item".equalsIgnoreCase(itemNode.getNodeName())) {
  94. +                        continue;
  95. +                    }
  96. +
  97. +                    NamedNodeMap itemAttrs = itemNode.getAttributes();
  98. +                    int itemId = Integer.parseInt(itemAttrs.getNamedItem("itemId").getNodeValue());
  99. +                    int amount = 1; // Default amount is 1
  100. +                    if (itemAttrs.getNamedItem("min") != null && itemAttrs.getNamedItem("max") != null) {
  101. +                        int min = Integer.parseInt(itemAttrs.getNamedItem("min").getNodeValue());
  102. +                        int max = Integer.parseInt(itemAttrs.getNamedItem("max").getNodeValue());
  103. +                        amount = getRandomAmount(min, max);
  104. +                    }
  105. +                    int enchantLevel = Integer.parseInt(itemAttrs.getNamedItem("enchantLevel").getNodeValue());
  106. +                    int chance = Integer.parseInt(itemAttrs.getNamedItem("chance").getNodeValue());
  107. +
  108. +                    CapsuleBoxItem.Item item = new CapsuleBoxItem.Item(itemId, amount, enchantLevel, chance);
  109. +                    capsuleBoxItem.addItem(item);
  110. +                }
  111. +
  112. +                capsuleBoxItems.put(id, capsuleBoxItem);
  113. +            }
  114. +        } catch (Exception e) {
  115. +            // LOG.warning("CapsuleBoxData: Error while loading items: " + e);
  116. +            e.printStackTrace();
  117. +        }
  118. +    }
  119. +
  120. +    public Map<Integer, CapsuleBoxItem> getCapsuleBoxItems() {
  121. +        return capsuleBoxItems;
  122. +    }
  123. +
  124. +    public CapsuleBoxItem getCapsuleBoxItemById(int id) {
  125. +        return capsuleBoxItems.get(id);
  126. +    }
  127. +
  128. +    private static int getRandomAmount(int min, int max) {
  129. +        return min + (int) (Math.random() * ((max - min) + 1));
  130. +    }
  131. +}
  132. diff --git java/Base/CapsuleBox/CapsuleBoxItem.java java/Base/CapsuleBox/CapsuleBoxItem.java
  133. new file mode 100644
  134. index 0000000..93c0cc6
  135. --- /dev/null
  136. +++ java/Base/CapsuleBox/CapsuleBoxItem.java
  137. @@ -0,0 +1,64 @@
  138. +package Base.CapsuleBox;
  139. +
  140. +import java.util.ArrayList;
  141. +import java.util.List;
  142. +
  143. +public class CapsuleBoxItem {
  144. +    private int id;
  145. +    private int playerLevel;
  146. +    private List<Item> items;
  147. +
  148. +    public CapsuleBoxItem(int id, int playerLevel) {
  149. +        this.id = id;
  150. +        this.playerLevel = playerLevel;
  151. +        items = new ArrayList<>();
  152. +    }
  153. +
  154. +    public int getId() {
  155. +        return id;
  156. +    }
  157. +
  158. +    public int getPlayerLevel() {
  159. +        return playerLevel;
  160. +    }
  161. +
  162. +    public List<Item> getItems() {
  163. +        return items;
  164. +    }
  165. +
  166. +    public void addItem(Item item) {
  167. +        items.add(item);
  168. +    }
  169. +
  170. +    public static class Item {
  171. +        private int itemId;
  172. +        private int amount;
  173. +        private int enchantLevel;
  174. +        private int chance;
  175. +
  176. +        public Item(int itemId, int amount, int enchantLevel, int chance) {
  177. +            this.itemId = itemId;
  178. +            this.amount = amount;
  179. +            this.enchantLevel = enchantLevel;
  180. +            this.chance = chance;
  181. +        }
  182. +
  183. +        public int getItemId() {
  184. +            return itemId;
  185. +        }
  186. +
  187. +        public int getAmount() {
  188. +            return amount;
  189. +        }
  190. +
  191. +        public int getEnchantLevel() {
  192. +            return enchantLevel;
  193. +        }
  194. +
  195. +        public int getChance() {
  196. +            return chance;
  197. +        }
  198. +
  199. +
  200. +    }
  201. +}
  202. diff --git java/com/l2jmega/gameserver/GameServer.java java/com/l2jmega/gameserver/GameServer.java
  203. index 948d4e4..12b0956 100644
  204. --- java/com/l2jmega/gameserver/GameServer.java
  205. +++ java/com/l2jmega/gameserver/GameServer.java
  206. @@ -133,6 +133,7 @@
  207.  import com.l2jmega.commons.mmocore.SelectorThread;
  208.  import com.l2jmega.commons.util.SysUtil;
  209.  
  210. +import Base.CapsuleBox.CapsuleBoxData;
  211.  import Base.RandomCraft.RandomCraftXML;
  212.  import Base.Skin.DressMeData;
  213.  import hwid.Hwid;
  214. @@ -489,6 +490,10 @@
  215.             DressMeData.getInstance();
  216.         }
  217.        
  218. +       StringUtil.printSection("CapsuleBox - Terius");
  219. +       CapsuleBoxData.getInstance();
  220. +      
  221. +      
  222.         StringUtil.printSection("RandomCraft - Terius");
  223.         RandomCraftXML.getInstance();
  224.        
  225. diff --git java/com/l2jmega/gameserver/handler/ItemHandler.java java/com/l2jmega/gameserver/handler/ItemHandler.java
  226. index 8f41315..862cf95 100644
  227. --- java/com/l2jmega/gameserver/handler/ItemHandler.java
  228. +++ java/com/l2jmega/gameserver/handler/ItemHandler.java
  229. @@ -58,6 +58,7 @@
  230.  import com.l2jmega.gameserver.handler.itemhandlers.clan.SkillVitality;
  231.  import com.l2jmega.gameserver.handler.itemhandlers.clan.SkillWithstandAttack;
  232.  import com.l2jmega.gameserver.handler.itemhandlers.custom.AllyNameChange;
  233. +import com.l2jmega.gameserver.handler.itemhandlers.custom.CapsuleBox_System;
  234.  import com.l2jmega.gameserver.handler.itemhandlers.custom.ClanFull;
  235.  import com.l2jmega.gameserver.handler.itemhandlers.custom.ClanNameChange;
  236.  import com.l2jmega.gameserver.handler.itemhandlers.custom.ClassItem;
  237. @@ -131,6 +132,7 @@
  238.         registerItemHandler(new Aio30days());
  239.         registerItemHandler(new AioEterno());
  240.         registerItemHandler(new LuckBox());
  241. +       registerItemHandler(new CapsuleBox_System());
  242.         registerItemHandler(new ClanFull());
  243.         registerItemHandler(new NoblesItem());
  244.         registerItemHandler(new Vip24h());
  245. diff --git java/com/l2jmega/gameserver/handler/admincommandhandlers/AdminAdmin.java java/com/l2jmega/gameserver/handler/admincommandhandlers/AdminAdmin.java
  246. index 9bf868d..1d0907c 100644
  247. --- java/com/l2jmega/gameserver/handler/admincommandhandlers/AdminAdmin.java
  248. +++ java/com/l2jmega/gameserver/handler/admincommandhandlers/AdminAdmin.java
  249. @@ -4,6 +4,7 @@
  250.  
  251.  import com.l2jmega.commons.lang.StringUtil;
  252.  
  253. +import Base.CapsuleBox.CapsuleBoxData;
  254.  import Base.RandomCraft.RandomCraftXML;
  255.  import Base.Skin.DressMeData;
  256.  
  257. @@ -210,6 +211,11 @@
  258.                         RandomCraftXML.getInstance().reload();
  259.                         activeChar.sendMessage("Random Craft have been reloaded.");
  260.                     }
  261. +                   else if (type.startsWith("capsule"))
  262. +                   {
  263. +                       CapsuleBoxData.getInstance().reload();
  264. +                       activeChar.sendMessage("Capsule Box have been reloaded.");
  265. +                   }
  266.                     else if (type.startsWith("olly"))
  267.                     {
  268.                         OlyClassDamageManager.loadConfig();
  269. diff --git java/com/l2jmega/gameserver/handler/itemhandlers/custom/CapsuleBox_System.java java/com/l2jmega/gameserver/handler/itemhandlers/custom/CapsuleBox_System.java
  270. new file mode 100644
  271. index 0000000..ebe42bf
  272. --- /dev/null
  273. +++ java/com/l2jmega/gameserver/handler/itemhandlers/custom/CapsuleBox_System.java
  274. @@ -0,0 +1,58 @@
  275. +package com.l2jmega.gameserver.handler.itemhandlers.custom;
  276. +
  277. +import com.l2jmega.gameserver.handler.IItemHandler;
  278. +import com.l2jmega.gameserver.idfactory.IdFactory;
  279. +import com.l2jmega.gameserver.model.actor.Playable;
  280. +import com.l2jmega.gameserver.model.actor.instance.Player;
  281. +import com.l2jmega.gameserver.model.item.instance.ItemInstance;
  282. +import com.l2jmega.gameserver.network.serverpackets.MagicSkillUse;
  283. +
  284. +import com.l2jmega.commons.random.Rnd;
  285. +
  286. +import Base.CapsuleBox.CapsuleBoxData;
  287. +import Base.CapsuleBox.CapsuleBoxItem;
  288. +import Base.CapsuleBox.CapsuleBoxItem.Item;
  289. +
  290. +public class CapsuleBox_System implements IItemHandler {
  291. +
  292. +    @Override
  293. +    public void useItem(Playable playable, ItemInstance item, boolean forceUse) {
  294. +        if (!(playable instanceof Player))
  295. +            return;
  296. +
  297. +        final Player activeChar = (Player) playable;
  298. +        final int itemId = item.getItemId();
  299. +
  300. +        CapsuleBoxItem capsuleBoxItem = CapsuleBoxData.getInstance().getCapsuleBoxItemById(itemId);
  301. +        if (capsuleBoxItem != null) {
  302. +            if (activeChar.getLevel() < capsuleBoxItem.getPlayerLevel()) {
  303. +                activeChar.sendMessage("Para Usar Esta Capsule Box Necesitas El LvL." + capsuleBoxItem.getPlayerLevel());
  304. +                return;
  305. +            }
  306. +
  307. +            ItemInstance toGive = null;
  308. +            for (Item boxItem : capsuleBoxItem.getItems()) {
  309. +                toGive = new ItemInstance(IdFactory.getInstance().getNextId(), boxItem.getItemId());
  310. +                int random = Rnd.get(100);
  311. +                if (random < boxItem.getChance()) {
  312. +                    if (!toGive.isStackable()) {
  313. +                        toGive.setEnchantLevel(boxItem.getEnchantLevel());
  314. +                        activeChar.addItem("CapsuleBox", toGive, activeChar, true);
  315. +                    } else {
  316. +                        activeChar.addItem("CapsuleBox", boxItem.getItemId(), boxItem.getAmount(), activeChar, true);
  317. +                    }
  318. +                } else {
  319. +                    
  320. +                }
  321. +                MagicSkillUse MSU = new MagicSkillUse(activeChar, activeChar, 2024, 1, 1, 0);
  322. +                activeChar.broadcastPacket(MSU);
  323. +              
  324. +            }
  325. +          
  326. +        } else {
  327. +            activeChar.sendMessage("This Capsule box expired or is invalid!");
  328. +        }
  329. +
  330. +        playable.destroyItem("Consume", item.getObjectId(), 1, null, false);
  331. +    }
  332. +}
  333.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement