Advertisement
tensador125

randomcraftsystem mobius interlude

Jul 1st, 2023 (edited)
1,205
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 44.69 KB | Gaming | 0 0
  1. ### Eclipse Workspace Patch 1.0
  2. #P L2J_Mobius_C6_Interlude
  3. diff --git dist/game/config/General.ini dist/game/config/General.ini
  4. index 3d04989..2c9ca99 100644
  5. --- dist/game/config/General.ini
  6. +++ dist/game/config/General.ini
  7. @@ -700,3 +700,14 @@
  8.  # Excluded packet list.
  9.  # Packet names that are excluded from debugging, separated by commas.
  10.  ExcludedPacketList = Attack, AutoAttackStart, AutoAttackStop, DeleteObject, ExAutoSoulShot, ExPacket, ExStorageMaxCount, MoveToLocation, NpcInfo, NpcSay, SkillCoolTime, SocialAction, StatusUpdate, UserInfo, ValidatePosition
  11. +
  12. +
  13. +#==========================================================================
  14. +#   RANDOM CRAFT SYSTEM NPC - ID - CONSUME - REFRESH - CREATE - ITEMS
  15. +#==========================================================================
  16. +
  17. +RandomCraftItemId = 57
  18. +
  19. +RandomCraftConsumeRefresh = 50000
  20. +
  21. +RandromCraftConsumeCreate = 300000
  22. diff --git dist/game/data/RandomCraft.xml dist/game/data/RandomCraft.xml
  23. new file mode 100644
  24. index 0000000..7ab3417
  25. --- /dev/null
  26. +++ dist/game/data/RandomCraft.xml
  27. @@ -0,0 +1,190 @@
  28. +<?xml version="1.0" encoding="UTF-8"?>
  29. +<rewards>
  30. + <item id="8762" count="1" chance="20" announce="false"/>
  31. + <item id="8790" count="1" chance="40" announce="true"/>
  32. + <item id="8793" count="1" chance="40" announce="true"/>
  33. + <item id="8794" count="1" chance="40" announce="true"/>
  34. + <item id="8798" count="1" chance="40" announce="true"/>
  35. + <item id="8801" count="1" chance="40" announce="true"/>
  36. + <item id="8803" count="1" chance="40" announce="true"/>
  37. + <item id="8807" count="1" chance="40" announce="true"/>
  38. + <item id="8811" count="1" chance="40" announce="true"/>
  39. + <item id="8809" count="1" chance="40" announce="true"/>
  40. + <item id="8810" count="1" chance="40" announce="true"/>
  41. + <item id="8812" count="1" chance="40" announce="true"/>
  42. + <item id="8813" count="1" chance="40" announce="true"/>
  43. + <item id="8814" count="1" chance="40" announce="true"/>
  44. + <item id="8815" count="1" chance="40" announce="true"/>
  45. + <item id="8816" count="1" chance="40" announce="true"/>
  46. + <item id="8817" count="1" chance="40" announce="true"/>
  47. + <item id="8818" count="1" chance="40" announce="true"/>
  48. + <item id="8819" count="1" chance="40" announce="true"/>
  49. + <item id="8820" count="1" chance="40" announce="true"/>
  50. + <item id="8752" count="3" chance="58" announce="false"/>
  51. + <item id="8742" count="5" chance="65" announce="false"/>
  52. + <item id="8732" count="8" chance="75" announce="false"/>
  53. + <item id="7577" count="1" chance="5" announce="true"/>
  54. + <item id="6373" count="1" chance="8" announce="true"/>
  55. + <item id="6374" count="1" chance="8" announce="true"/>
  56. + <item id="6375" count="1" chance="8" announce="true"/>
  57. + <item id="6376" count="1" chance="8" announce="true"/>
  58. + <item id="6377" count="1" chance="8" announce="true"/>
  59. + <item id="6378" count="1" chance="8" announce="true"/>
  60. + <item id="6587" count="1" chance="5" announce="true"/>
  61. + <item id="6379" count="1" chance="8" announce="true"/>
  62. + <item id="6380" count="1" chance="8" announce="true"/>
  63. + <item id="6381" count="1" chance="8" announce="true"/>
  64. + <item id="6382" count="1" chance="8" announce="true"/>
  65. + <item id="6383" count="1" chance="8" announce="true"/>
  66. + <item id="6384" count="1" chance="8" announce="true"/>
  67. + <item id="6385" count="1" chance="8" announce="true"/>
  68. + <item id="6386" count="1" chance="8" announce="true"/>
  69. + <item id="2383" count="1" chance="40" announce="false"/>
  70. + <item id="2395" count="1" chance="40" announce="false"/>
  71. + <item id="2409" count="1" chance="40" announce="false"/>
  72. + <item id="2419" count="1" chance="40" announce="false"/>
  73. + <item id="5774" count="1" chance="40" announce="false"/>
  74. + <item id="5775" count="1" chance="40" announce="false"/>
  75. + <item id="5776" count="1" chance="40" announce="false"/>
  76. + <item id="5786" count="1" chance="40" announce="false"/>
  77. + <item id="5787" count="1" chance="40" announce="false"/>
  78. + <item id="5788" count="1" chance="40" announce="false"/>
  79. + <item id="365" count="1" chance="40" announce="false"/>
  80. + <item id="388" count="1" chance="40" announce="false"/>
  81. + <item id="512" count="1" chance="40" announce="false"/>
  82. + <item id="641" count="1" chance="40" announce="false"/>
  83. + <item id="2385" count="1" chance="40" announce="false"/>
  84. + <item id="2389" count="1" chance="40" announce="false"/>
  85. + <item id="2407" count="1" chance="40" announce="false"/>
  86. + <item id="5765" count="1" chance="40" announce="false"/>
  87. + <item id="5766" count="1" chance="40" announce="false"/>
  88. + <item id="5767" count="1" chance="40" announce="false"/>
  89. + <item id="5777" count="1" chance="40" announce="false"/>
  90. + <item id="5778" count="1" chance="40" announce="false"/>
  91. + <item id="5779" count="1" chance="40" announce="false"/>
  92. + <item id="6608" count="1" chance="5" announce="true"/>
  93. + <item id="6604" count="1" chance="5" announce="true"/>
  94. + <item id="6599" count="1" chance="5" announce="true"/>
  95. + <item id="6590" count="1" chance="5" announce="true"/>
  96. + <item id="6606" count="1" chance="5" announce="true"/>
  97. + <item id="6580" count="1" chance="5" announce="true"/>
  98. + <item id="6597" count="1" chance="5" announce="true"/>
  99. + <item id="6585" count="1" chance="5" announce="true"/>
  100. + <item id="6594" count="1" chance="5" announce="true"/>
  101. + <item id="6582" count="1" chance="5" announce="true"/>
  102. + <item id="959" count="10" chance="60" announce="false"/>
  103. + <item id="960" count="10" chance="60" announce="false"/>
  104. + <item id="6577" count="3" chance="45" announce="false"/>
  105. + <item id="6578" count="3" chance="45" announce="false"/>
  106. + <item id="961" count="1" chance="10" announce="true"/>
  107. + <item id="962" count="1" chance="10" announce="true"/>
  108. + <item id="4686" count="1" chance="70" announce="false"/>
  109. + <item id="4682" count="1" chance="70" announce="false"/>
  110. + <item id="4697" count="1" chance="70" announce="false"/>
  111. + <item id="4702" count="1" chance="70" announce="false"/>
  112. + <item id="4700" count="1" chance="70" announce="false"/>
  113. + <item id="4709" count="1" chance="70" announce="false"/>
  114. + <item id="4705" count="1" chance="70" announce="false"/>
  115. + <item id="6310" count="1" chance="70" announce="false"/>
  116. + <item id="6313" count="1" chance="70" announce="false"/>
  117. + <item id="6348" count="1" chance="70" announce="false"/>
  118. + <item id="4711" count="1" chance="70" announce="false"/>
  119. + <item id="2599" count="1" chance="70" announce="false"/>
  120. + <item id="2591" count="1" chance="70" announce="false"/>
  121. + <item id="2582" count="1" chance="70" announce="false"/>
  122. + <item id="4776" count="1" chance="70" announce="false"/>
  123. + <item id="4824" count="1" chance="70" announce="false"/>
  124. + <item id="4795" count="1" chance="70" announce="false"/>
  125. + <item id="4852" count="1" chance="70" announce="false"/>
  126. + <item id="4745" count="1" chance="70" announce="false"/>
  127. + <item id="4896" count="1" chance="70" announce="false"/>
  128. + <item id="439" count="1" chance="70" announce="false"/>
  129. + <item id="471" count="1" chance="70" announce="false"/>
  130. + <item id="2430" count="1" chance="70" announce="false"/>
  131. + <item id="2454" count="1" chance="70" announce="false"/>
  132. + <item id="356" count="1" chance="70" announce="false"/>
  133. + <item id="2414" count="1" chance="70" announce="false"/>
  134. + <item id="2438" count="1" chance="70" announce="false"/>
  135. + <item id="2462" count="1" chance="70" announce="false"/>
  136. + <item id="2497" count="1" chance="70" announce="false"/>
  137. + <item id="400" count="1" chance="70" announce="false"/>
  138. + <item id="420" count="1" chance="70" announce="false"/>
  139. + <item id="2436" count="1" chance="70" announce="false"/>
  140. + <item id="2460" count="1" chance="70" announce="false"/>
  141. + <item id="2415" count="1" chance="58" announce="false"/>
  142. +<item id="2406" count="1" chance="58" announce="false"/>
  143. +<item id="4718" count="1" chance="58" announce="false"/>
  144. +<item id="4724" count="1" chance="58" announce="false"/>
  145. +<item id="2624" count="1" chance="58" announce="false"/>
  146. +<item id="2626" count="1" chance="58" announce="false"/>
  147. +<item id="2621" count="1" chance="58" announce="false"/>
  148. +<item id="4782" count="1" chance="58" announce="false"/>
  149. +<item id="4830" count="1" chance="58" announce="false"/>
  150. +<item id="4804" count="1" chance="58" announce="false"/>
  151. +<item id="4856" count="1" chance="58" announce="false"/>
  152. +<item id="4753" count="1" chance="58" announce="false"/>
  153. +<item id="4897" count="1" chance="58" announce="false"/>
  154. +<item id="4898" count="1" chance="58" announce="false"/>
  155. +<item id="4899" count="1" chance="58" announce="false"/>
  156. +<item id="4902" count="1" chance="58" announce="false"/>
  157. +<item id="4901" count="1" chance="58" announce="false"/>
  158. +<item id="4900" count="1" chance="58" announce="false"/>
  159. +<item id="5716" count="1" chance="58" announce="false"/>
  160. +<item id="5732" count="1" chance="58" announce="false"/>
  161. +<item id="2390" count="1" chance="58" announce="false"/>
  162. +<item id="5715" count="1" chance="58" announce="false"/>
  163. +<item id="5731" count="1" chance="58" announce="false"/>
  164. +<item id="2376" count="1" chance="58" announce="false"/>
  165. +<item id="2379" count="1" chance="58" announce="false"/>
  166. +<item id="5714" count="1" chance="58" announce="false"/>
  167. +<item id="5730" count="1" chance="58" announce="false"/>
  168. +<item id="2416" count="1" chance="58" announce="false"/>
  169. +<item id="2403" count="1" chance="58" announce="false"/>
  170. +<item id="5720" count="1" chance="58" announce="false"/>
  171. +<item id="5736" count="1" chance="58" announce="false"/>
  172. +<item id="358" count="1" chance="58" announce="false"/>
  173. +<item id="2380" count="1" chance="58" announce="false"/>
  174. +<item id="5718" count="1" chance="58" announce="false"/>
  175. +<item id="5734" count="1" chance="58" announce="false"/>
  176. +<item id="2391" count="1" chance="58" announce="false"/>
  177. +<item id="5719" count="1" chance="58" announce="false"/>
  178. +<item id="5735" count="1" chance="58" announce="false"/>
  179. +<item id="2417" count="1" chance="58" announce="false"/>
  180. +<item id="2381" count="1" chance="58" announce="false"/>
  181. +<item id="5722" count="1" chance="58" announce="false"/>
  182. +<item id="5738" count="1" chance="58" announce="false"/>
  183. +<item id="2392" count="1" chance="58" announce="false"/>
  184. +<item id="5723" count="1" chance="58" announce="false"/>
  185. +<item id="5739" count="1" chance="58" announce="false"/>
  186. +<item id="2399" count="1" chance="58" announce="false"/>
  187. +<item id="2404" count="1" chance="58" announce="false"/>
  188. +<item id="5724" count="1" chance="58" announce="false"/>
  189. +<item id="5740" count="1" chance="58" announce="false"/>
  190. +<item id="2418" count="1" chance="58" announce="false"/>
  191. +<item id="374" count="1" chance="58" announce="false"/>
  192. +<item id="5771" count="1" chance="58" announce="false"/>
  193. +<item id="5783" count="1" chance="58" announce="false"/>
  194. +<item id="2408" count="1" chance="58" announce="false"/>
  195. +<item id="5773" count="1" chance="58" announce="false"/>
  196. +<item id="5785" count="1" chance="58" announce="false"/>
  197. +<item id="2394" count="1" chance="58" announce="false"/>
  198. +<item id="5772" count="1" chance="58" announce="false"/>
  199. +<item id="5784" count="1" chance="58" announce="false"/>
  200. +<item id="547" count="1" chance="58" announce="false"/>
  201. +<item id="2405" count="1" chance="58" announce="false"/>
  202. +<item id="2400" count="1" chance="58" announce="false"/>
  203. +<item id="5770" count="1" chance="58" announce="false"/>
  204. +<item id="5782" count="1" chance="58" announce="false"/>
  205. +<item id="2393" count="1" chance="58" announce="false"/>
  206. +<item id="5769" count="1" chance="58" announce="false"/>
  207. +<item id="5781" count="1" chance="58" announce="false"/>
  208. +<item id="2382" count="1" chance="58" announce="false"/>
  209. +<item id="5768" count="1" chance="58" announce="false"/>
  210. +<item id="5780" count="1" chance="58" announce="false"/>
  211. +<item id="6660" count="1" chance="4" announce="true"/>
  212. +<item id="6657" count="1" chance="4" announce="true"/>
  213. +<item id="6656" count="1" chance="4" announce="true"/>
  214. +<item id="6658" count="1" chance="4" announce="true"/>
  215. +<item id="6659" count="1" chance="4" announce="true"/>
  216. +
  217. +</rewards>
  218. \ No newline at end of file
  219. diff --git java/Base/Data/IconTable.java java/Base/Data/IconTable.java
  220. new file mode 100644
  221. index 0000000..03b2c05
  222. --- /dev/null
  223. +++ java/Base/Data/IconTable.java
  224. @@ -0,0 +1,97 @@
  225. +/*
  226. + * This program is free software: you can redistribute it and/or modify it under
  227. + * the terms of the GNU General Public License as published by the Free Software
  228. + * Foundation, either version 3 of the License, or (at your option) any later
  229. + * version.
  230. + *
  231. + * This program is distributed in the hope that it will be useful, but WITHOUT
  232. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  233. + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  234. + * details.
  235. + *
  236. + * You should have received a copy of the GNU General Public License along with
  237. + * this program. If not, see <http://www.gnu.org/licenses/>.
  238. + */
  239. +package Base.Data;
  240. +
  241. +import java.io.File;
  242. +import java.util.Map;
  243. +import java.util.concurrent.ConcurrentHashMap;
  244. +import java.util.logging.Level;
  245. +import java.util.logging.Logger;
  246. +
  247. +import org.w3c.dom.Document;
  248. +import org.w3c.dom.NamedNodeMap;
  249. +import org.w3c.dom.Node;
  250. +
  251. +import Base.XML.XMLDocumentFactory;
  252. +
  253. +/**
  254. + * @author Tayran.JavaDev
  255. + */
  256. +public class IconTable
  257. +{
  258. +   private static final Logger _log = Logger.getLogger(IconTable.class.getName());
  259. +  
  260. +   public static Map<Integer, String> _icons = new ConcurrentHashMap<>();
  261. +  
  262. +   public static final IconTable getInstance()
  263. +   {
  264. +       return SingletonHolder._instance;
  265. +   }
  266. +  
  267. +   protected IconTable()
  268. +   {
  269. +      
  270. +       load();
  271. +   }
  272. +  
  273. +   private static void load()
  274. +   {
  275. +       try
  276. +       {
  277. +           File f = new File("./data/icons.xml");
  278. +           Document doc = XMLDocumentFactory.getInstance().loadDocument(f);
  279. +          
  280. +           Node n = doc.getFirstChild();
  281. +           for (Node d = n.getFirstChild(); d != null; d = d.getNextSibling())
  282. +           {
  283. +               if (d.getNodeName().equalsIgnoreCase("icon"))
  284. +               {
  285. +                   NamedNodeMap attrs = d.getAttributes();
  286. +                  
  287. +                   int itemId = Integer.valueOf(attrs.getNamedItem("itemId").getNodeValue());
  288. +                   String iconName = attrs.getNamedItem("iconName").getNodeValue();
  289. +                  
  290. +                   if ((itemId == 0) && (itemId < 0))
  291. +                   {
  292. +                       _log.log(Level.WARNING, "Icon Table: itemId=\"" + itemId + "\" is not item ID, Ignoring it!");
  293. +                       continue;
  294. +                   }
  295. +                   _icons.put(itemId, iconName);
  296. +               }
  297. +           }
  298. +       }
  299. +       catch (Exception e)
  300. +       {
  301. +           _log.log(Level.WARNING, "Icon Table: Error loading from database: " + e.getMessage(), e);
  302. +       }
  303. +      
  304. +       _log.info("Icon Table: Loaded " + _icons.size() + " icons.");
  305. +   }
  306. +  
  307. +   public static String getIcon(int id)
  308. +   {
  309. +       if (_icons.get(id) == null)
  310. +       {
  311. +           return "icon.NOIMAGE";
  312. +       }
  313. +      
  314. +       return _icons.get(id);
  315. +   }
  316. +  
  317. +   private static class SingletonHolder
  318. +   {
  319. +       protected static final IconTable _instance = new IconTable();
  320. +   }
  321. +}
  322. \ No newline at end of file
  323. diff --git java/Base/RandomCraft/RandomCraftItem.java java/Base/RandomCraft/RandomCraftItem.java
  324. new file mode 100644
  325. index 0000000..835bafa
  326. --- /dev/null
  327. +++ java/Base/RandomCraft/RandomCraftItem.java
  328. @@ -0,0 +1,50 @@
  329. +package Base.RandomCraft;
  330. +
  331. +import org.l2jmobius.gameserver.data.ItemTable;
  332. +import org.l2jmobius.gameserver.model.item.ItemTemplate;
  333. +
  334. +public class RandomCraftItem
  335. +{
  336. +   private final int id;
  337. +   private final int cantidad;
  338. +   private final double probabilidad;
  339. +   private final boolean announce;
  340. +  
  341. +   public RandomCraftItem(int id, int cantidad, double probabilidad, boolean announce)
  342. +   {
  343. +       this.id = id;
  344. +       this.cantidad = cantidad;
  345. +       this.probabilidad = probabilidad;
  346. +       this.announce = announce;
  347. +   }
  348. +  
  349. +   public int getId()
  350. +   {
  351. +       return id;
  352. +   }
  353. +  
  354. +   public int getCantidad()
  355. +   {
  356. +       return cantidad;
  357. +   }
  358. +  
  359. +   public double getProbabilidad()
  360. +   {
  361. +       return probabilidad;
  362. +   }
  363. +  
  364. +   public boolean getAnnounce()
  365. +   {
  366. +       return announce;
  367. +   }
  368. +  
  369. +   public String getIcon()
  370. +   {
  371. +       return getItem().getIcon(id);
  372. +   }
  373. +  
  374. +   public ItemTemplate getItem()
  375. +   {
  376. +       return ItemTable.getInstance().getTemplate(id);
  377. +   }
  378. +}
  379. diff --git java/Base/RandomCraft/RandomCraftXML.java java/Base/RandomCraft/RandomCraftXML.java
  380. new file mode 100644
  381. index 0000000..4e9f84b
  382. --- /dev/null
  383. +++ java/Base/RandomCraft/RandomCraftXML.java
  384. @@ -0,0 +1,86 @@
  385. +package Base.RandomCraft;
  386. +
  387. +import java.io.File;
  388. +import java.util.HashMap;
  389. +import java.util.Map;
  390. +
  391. +import org.w3c.dom.Document;
  392. +import org.w3c.dom.NamedNodeMap;
  393. +import org.w3c.dom.Node;
  394. +
  395. +import Base.XML.XMLDocument;
  396. +
  397. +public class RandomCraftXML extends XMLDocument
  398. +{
  399. +   private final Map<Integer, RandomCraftItem> items;
  400. +  
  401. +   public RandomCraftXML()
  402. +   {
  403. +       items = new HashMap<>();
  404. +       load();
  405. +   }
  406. +  
  407. +   public void reload()
  408. +   {
  409. +       items.clear();
  410. +       load();
  411. +   }
  412. +  
  413. +   public static RandomCraftXML getInstance()
  414. +   {
  415. +       return SingletonHolder.INSTANCE;
  416. +   }
  417. +  
  418. +   private static class SingletonHolder
  419. +   {
  420. +       protected static final RandomCraftXML INSTANCE = new RandomCraftXML();
  421. +   }
  422. +  
  423. +   @Override
  424. +   protected void load()
  425. +   {
  426. +       loadDocument("./data/RandomCraft.xml");
  427. +       LOG.info("RandomCraftItemData: Loaded " + items.size() + " items.");
  428. +   }
  429. +  
  430. +   @Override
  431. +   protected void parseDocument(Document doc, File file)
  432. +   {
  433. +       try
  434. +       {
  435. +           final Node root = doc.getFirstChild();
  436. +          
  437. +           for (Node node = root.getFirstChild(); node != null; node = node.getNextSibling())
  438. +           {
  439. +               if (!"item".equalsIgnoreCase(node.getNodeName()))
  440. +               {
  441. +                   continue;
  442. +               }
  443. +              
  444. +               NamedNodeMap attrs = node.getAttributes();
  445. +               int id = Integer.parseInt(attrs.getNamedItem("id").getNodeValue());
  446. +               int cantidad = Integer.parseInt(attrs.getNamedItem("count").getNodeValue());
  447. +               double probabilidad = Double.parseDouble(attrs.getNamedItem("chance").getNodeValue());
  448. +               boolean announce = Boolean.parseBoolean(attrs.getNamedItem("announce").getNodeValue());
  449. +              
  450. +               RandomCraftItem item = new RandomCraftItem(id, cantidad, probabilidad, announce);
  451. +               items.put(id, item);
  452. +           }
  453. +       }
  454. +       catch (Exception e)
  455. +       {
  456. +           // LOG.warning("RandomCraftItemData: Error while loading items: " + e);
  457. +           e.printStackTrace();
  458. +       }
  459. +   }
  460. +  
  461. +   public Map<Integer, RandomCraftItem> getItems()
  462. +   {
  463. +       return items;
  464. +   }
  465. +  
  466. +   public RandomCraftItem getItemById(int id)
  467. +   {
  468. +       return items.get(id);
  469. +   }
  470. +}
  471. diff --git java/Base/XML/XMLDocument.java java/Base/XML/XMLDocument.java
  472. new file mode 100644
  473. index 0000000..756a5ee
  474. --- /dev/null
  475. +++ java/Base/XML/XMLDocument.java
  476. @@ -0,0 +1,119 @@
  477. +package Base.XML;
  478. +
  479. +import java.io.File;
  480. +import java.util.logging.Level;
  481. +import java.util.logging.Logger;
  482. +
  483. +import javax.xml.parsers.DocumentBuilderFactory;
  484. +import javax.xml.transform.OutputKeys;
  485. +import javax.xml.transform.Transformer;
  486. +import javax.xml.transform.TransformerException;
  487. +import javax.xml.transform.TransformerFactory;
  488. +import javax.xml.transform.dom.DOMSource;
  489. +import javax.xml.transform.stream.StreamResult;
  490. +
  491. +import org.w3c.dom.Document;
  492. +import org.w3c.dom.NamedNodeMap;
  493. +import org.w3c.dom.Node;
  494. +
  495. +import org.l2jmobius.gameserver.model.StatSet;
  496. +
  497. +/**
  498. + * An XML document, relying on a static and single DocumentBuilderFactory.
  499. + */
  500. +public abstract class XMLDocument
  501. +{
  502. +   protected static final Logger LOG = Logger.getLogger(XMLDocument.class.getName());
  503. +  
  504. +   protected Document document;
  505. +  
  506. +   private static final DocumentBuilderFactory BUILDER;
  507. +   static
  508. +   {
  509. +       BUILDER = DocumentBuilderFactory.newInstance();
  510. +       BUILDER.setValidating(false);
  511. +       BUILDER.setIgnoringComments(true);
  512. +   }
  513. +  
  514. +   abstract protected void load();
  515. +  
  516. +   abstract protected void parseDocument(Document doc, File f);
  517. +  
  518. +   public void loadDocument(String filePath)
  519. +   {
  520. +       loadDocument(new File(filePath));
  521. +   }
  522. +  
  523. +   public void writeDocument(Document doc, String fileName)
  524. +   {
  525. +       try
  526. +       {
  527. +           TransformerFactory transformerFactory = TransformerFactory.newInstance();
  528. +           Transformer transformer = transformerFactory.newTransformer();
  529. +           transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
  530. +           transformer.setOutputProperty(OutputKeys.INDENT, "yes");
  531. +           transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
  532. +          
  533. +           DOMSource source = new DOMSource(doc);
  534. +           StreamResult result = new StreamResult(new File(fileName));
  535. +          
  536. +           transformer.transform(source, result);
  537. +           LOG.info("XML file saved to " + fileName);
  538. +       }
  539. +       catch (TransformerException e)
  540. +       {
  541. +           LOG.warning("Error saving XML file: " + e.getMessage());
  542. +       }
  543. +   }
  544. +  
  545. +   /**
  546. +    * Parse an entire directory or file if found.
  547. +    * @param file
  548. +    */
  549. +   public void loadDocument(File file)
  550. +   {
  551. +       if (!file.exists())
  552. +       {
  553. +           LOG.severe("The following file or directory doesn't exist: " + file.getName());
  554. +           return;
  555. +       }
  556. +      
  557. +       if (file.isDirectory())
  558. +       {
  559. +           for (File f : file.listFiles())
  560. +           {
  561. +               loadDocument(f);
  562. +           }
  563. +       }
  564. +       else if (file.isFile())
  565. +       {
  566. +           try
  567. +           {
  568. +               parseDocument(BUILDER.newDocumentBuilder().parse(file), file);
  569. +           }
  570. +           catch (Exception e)
  571. +           {
  572. +               LOG.log(Level.SEVERE, "Error loading XML file " + file.getName(), e);
  573. +           }
  574. +       }
  575. +   }
  576. +  
  577. +   public Document getDocument()
  578. +   {
  579. +       return document;
  580. +   }
  581. +  
  582. +   /**
  583. +    * This method parses the content of a NamedNodeMap and feed the given StatsSet.
  584. +    * @param attrs : The NamedNodeMap to parse.
  585. +    * @param set : The StatsSet to feed.
  586. +    */
  587. +   public static void parseAndFeed(NamedNodeMap attrs, StatSet set)
  588. +   {
  589. +       for (int i = 0; i < attrs.getLength(); i++)
  590. +       {
  591. +           final Node attr = attrs.item(i);
  592. +           set.set(attr.getNodeName(), attr.getNodeValue());
  593. +       }
  594. +   }
  595. +}
  596. diff --git java/Base/XML/XMLDocumentFactory.java java/Base/XML/XMLDocumentFactory.java
  597. new file mode 100644
  598. index 0000000..9594e19
  599. --- /dev/null
  600. +++ java/Base/XML/XMLDocumentFactory.java
  601. @@ -0,0 +1,74 @@
  602. +package Base.XML;
  603. +
  604. +import java.io.File;
  605. +
  606. +import javax.xml.parsers.DocumentBuilder;
  607. +import javax.xml.parsers.DocumentBuilderFactory;
  608. +
  609. +import org.w3c.dom.Document;
  610. +
  611. +/**
  612. + * @author Forsaiken
  613. + */
  614. +public final class XMLDocumentFactory
  615. +{
  616. +   public static final XMLDocumentFactory getInstance()
  617. +   {
  618. +       return SingletonHolder._instance;
  619. +   }
  620. +  
  621. +   private final DocumentBuilder _builder;
  622. +  
  623. +   protected XMLDocumentFactory() throws Exception
  624. +   {
  625. +       try
  626. +       {
  627. +           final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
  628. +           factory.setValidating(false);
  629. +           factory.setIgnoringComments(true);
  630. +          
  631. +           _builder = factory.newDocumentBuilder();
  632. +       }
  633. +       catch (Exception e)
  634. +       {
  635. +           throw new Exception("Failed initializing", e);
  636. +       }
  637. +   }
  638. +  
  639. +   public final Document loadDocument(final String filePath) throws Exception
  640. +   {
  641. +       return loadDocument(new File(filePath));
  642. +   }
  643. +  
  644. +   public final Document loadDocument(final File file) throws Exception
  645. +   {
  646. +       if (!file.exists() || !file.isFile())
  647. +       {
  648. +           throw new Exception("File: " + file.getAbsolutePath() + " doesn't exist and/or is not a file.");
  649. +       }
  650. +      
  651. +       return _builder.parse(file);
  652. +   }
  653. +  
  654. +   public final Document newDocument()
  655. +   {
  656. +       return _builder.newDocument();
  657. +   }
  658. +  
  659. +   private static class SingletonHolder
  660. +   {
  661. +       protected static final XMLDocumentFactory _instance;
  662. +      
  663. +       static
  664. +       {
  665. +           try
  666. +           {
  667. +               _instance = new XMLDocumentFactory();
  668. +           }
  669. +           catch (Exception e)
  670. +           {
  671. +               throw new ExceptionInInitializerError(e);
  672. +           }
  673. +       }
  674. +   }
  675. +}
  676. \ No newline at end of file
  677. diff --git java/org/l2jmobius/Config.java java/org/l2jmobius/Config.java
  678. index 1c8442b..66735d1 100644
  679. --- java/org/l2jmobius/Config.java
  680. +++ java/org/l2jmobius/Config.java
  681. @@ -124,6 +124,10 @@
  682.     public static ServerMode SERVER_MODE = ServerMode.NONE;
  683.    
  684.     public static boolean EVERYBODY_HAS_ADMIN_RIGHTS;
  685. +  
  686. +   public static int RANDOM_CRAFT_ITEM_ID_CONSUME;
  687. +   public static int RANDOM_CRAFT_ITEM_CONSUME_REFRESH;
  688. +   public static int RANDOM_CRAFT_ITEM_CONSUME_CREATE;
  689.     public static boolean SHOW_GM_LOGIN;
  690.     public static boolean GM_STARTUP_INVISIBLE;
  691.     public static boolean GM_SPECIAL_EFFECT;
  692. @@ -1292,6 +1296,12 @@
  693.         final PropertiesParser generalConfig = new PropertiesParser(GENERAL_CONFIG_FILE);
  694.         SERVER_LIST_TESTSERVER = generalConfig.getBoolean("TestServer", false);
  695.         SERVER_GMONLY = generalConfig.getBoolean("ServerGMOnly", false);
  696. +       RANDOM_CRAFT_ITEM_ID_CONSUME = generalConfig.getInt("RandomCraftItemId", 57);
  697. +      
  698. +       RANDOM_CRAFT_ITEM_CONSUME_REFRESH = generalConfig.getInt("RandomCraftConsumeRefresh", 50000);
  699. +      
  700. +       RANDOM_CRAFT_ITEM_CONSUME_CREATE = generalConfig.getInt("RandromCraftConsumeCreate", 300000);
  701. +      
  702.         ALT_DEV_NO_QUESTS = generalConfig.getBoolean("AltDevNoQuests", false);
  703.         ALT_DEV_NO_SPAWNS = generalConfig.getBoolean("AltDevNoSpawns", false);
  704.         ALT_DEV_NO_SCRIPT = generalConfig.getBoolean("AltDevNoScript", false);
  705. diff --git java/org/l2jmobius/gameserver/GameServer.java java/org/l2jmobius/gameserver/GameServer.java
  706. index c6459e3..e2e3e26 100644
  707. --- java/org/l2jmobius/gameserver/GameServer.java
  708. +++ java/org/l2jmobius/gameserver/GameServer.java
  709. @@ -128,6 +128,9 @@
  710.  import org.l2jmobius.gameserver.taskmanager.TaskManager;
  711.  import org.l2jmobius.gameserver.ui.Gui;
  712.  
  713. +import Base.Data.IconTable;
  714. +import Base.RandomCraft.RandomCraftXML;
  715. +
  716.  public class GameServer
  717.  {
  718.     private static final Logger LOGGER = Logger.getLogger(GameServer.class.getName());
  719. @@ -339,6 +342,10 @@
  720.         printSection("Access Levels");
  721.         AdminData.getInstance();
  722.        
  723. +       IconTable.getInstance();
  724. +       printSection("RandomCraft - Terius");
  725. +       RandomCraftXML.getInstance();
  726. +       XMLDocumentFactory.getInstance();
  727.  
  728.         printSection("Handlers");
  729.         ItemHandler.getInstance();
  730.         SkillHandler.getInstance();
  731. diff --git java/org/l2jmobius/gameserver/handler/admincommandhandlers/AdminReload.java java/org/l2jmobius/gameserver/handler/admincommandhandlers/AdminReload.java
  732. index 1fbeade..36a2a98 100644
  733. --- java/org/l2jmobius/gameserver/handler/admincommandhandlers/AdminReload.java
  734. +++ java/org/l2jmobius/gameserver/handler/admincommandhandlers/AdminReload.java
  735. @@ -33,6 +33,8 @@
  736.  import org.l2jmobius.gameserver.model.actor.Player;
  737.  import org.l2jmobius.gameserver.util.BuilderUtil;
  738.  
  739. +import Base.RandomCraft.RandomCraftXML;
  740. +
  741.  /**
  742.   * @author KidZor
  743.   */
  744. @@ -110,12 +112,19 @@
  745.                     sendReloadPage(activeChar);
  746.                     BuilderUtil.sendSysMessage(activeChar, "Quests Reloaded.");
  747.                 }
  748. +               else if (type.equals("craft"))
  749. +               {
  750. +                   RandomCraftXML.getInstance().reload();
  751. +                   sendReloadPage(activeChar);
  752. +                   BuilderUtil.sendSysMessage(activeChar, "RandomCraftSystem Reloaded.");
  753. +               }
  754.                 else if (type.equals("configs"))
  755.                 {
  756.                     Config.load(ServerMode.GAME);
  757.                     sendReloadPage(activeChar);
  758.                     BuilderUtil.sendSysMessage(activeChar, "Server Config Reloaded.");
  759.                 }
  760. +              
  761.                 else if (type.equals("tradelist"))
  762.                 {
  763.                     TradeManager.getInstance();
  764. diff --git java/org/l2jmobius/gameserver/model/actor/Player.java java/org/l2jmobius/gameserver/model/actor/Player.java
  765. index 85eb611..acdedfa 100644
  766. --- java/org/l2jmobius/gameserver/model/actor/Player.java
  767. +++ java/org/l2jmobius/gameserver/model/actor/Player.java
  768. @@ -237,6 +237,8 @@
  769.  import org.l2jmobius.gameserver.util.Broadcast;
  770.  import org.l2jmobius.gameserver.util.Util;
  771.  
  772. +import Base.RandomCraft.RandomCraftItem;
  773. +
  774.  /**
  775.   * This class represents all player characters in the world.<br>
  776.   * There is always a client-thread connected to this (except if a player-store is activated upon logout).
  777. @@ -15619,6 +15621,23 @@
  778.         _currentPetSkill = new SkillUseHolder(currentSkill, ctrlPressed, shiftPressed);
  779.     }
  780.    
  781. +   private List<RandomCraftItem> generatedCraftItems;
  782. +  
  783. +   public List<RandomCraftItem> getGeneratedCraftItems()
  784. +   {
  785. +       return generatedCraftItems;
  786. +   }
  787. +  
  788. +   public void setGeneratedCraftItems(List<RandomCraftItem> items)
  789. +   {
  790. +       generatedCraftItems = items;
  791. +   }
  792. +  
  793. +   public void clearGeneratedCraftItems()
  794. +   {
  795. +       generatedCraftItems.clear();
  796. +   }
  797. +  
  798.     @Override
  799.     public Player getActingPlayer()
  800.     {
  801. diff --git java/org/l2jmobius/gameserver/model/actor/instance/RandomCraft.java java/org/l2jmobius/gameserver/model/actor/instance/RandomCraft.java
  802. new file mode 100644
  803. index 0000000..cc5056f
  804. --- /dev/null
  805. +++ java/org/l2jmobius/gameserver/model/actor/instance/RandomCraft.java
  806. @@ -0,0 +1,495 @@
  807. +package org.l2jmobius.gameserver.model.actor.instance;
  808. +
  809. +import java.sql.Connection;
  810. +import java.sql.PreparedStatement;
  811. +import java.sql.ResultSet;
  812. +import java.sql.SQLException;
  813. +import java.util.ArrayList;
  814. +import java.util.LinkedList;
  815. +import java.util.List;
  816. +import java.util.Map;
  817. +import java.util.Random;
  818. +
  819. +import org.l2jmobius.Config;
  820. +import org.l2jmobius.commons.database.DatabaseFactory;
  821. +import org.l2jmobius.gameserver.ai.CtrlIntention;
  822. +import org.l2jmobius.gameserver.model.World;
  823. +import org.l2jmobius.gameserver.model.actor.Npc;
  824. +import org.l2jmobius.gameserver.model.actor.Player;
  825. +import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate;
  826. +import org.l2jmobius.gameserver.model.item.instance.Item;
  827. +import org.l2jmobius.gameserver.network.serverpackets.ActionFailed;
  828. +import org.l2jmobius.gameserver.network.serverpackets.ExShowScreenMessage;
  829. +import org.l2jmobius.gameserver.network.serverpackets.MagicSkillUse;
  830. +import org.l2jmobius.gameserver.network.serverpackets.MoveToPawn;
  831. +import org.l2jmobius.gameserver.network.serverpackets.MyTargetSelected;
  832. +import org.l2jmobius.gameserver.network.serverpackets.NpcHtmlMessage;
  833. +import org.l2jmobius.gameserver.network.serverpackets.ValidateLocation;
  834. +
  835. +import Base.RandomCraft.RandomCraftItem;
  836. +import Base.RandomCraft.RandomCraftXML;
  837. +
  838. +/**
  839. + * @author Terius
  840. + */
  841. +
  842. +public class RandomCraft extends Npc
  843. +{
  844. +   private boolean hasGeneratedItems;
  845. +   List<RandomCraftItem> items = new LinkedList<>();
  846. +  
  847. +   public RandomCraft(int objectId, NpcTemplate template)
  848. +   {
  849. +       super(objectId, template);
  850. +       setHasGeneratedItems(false);
  851. +   }
  852. +  
  853. +   @Override
  854. +   public void onAction(Player player)
  855. +   {
  856. +       if (this != player.getTarget())
  857. +       {
  858. +           player.setTarget(this);
  859. +           player.sendPacket(new MyTargetSelected(getObjectId(), 0));
  860. +           player.sendPacket(new ValidateLocation(this));
  861. +       }
  862. +       else
  863. +       {
  864. +           if (!canInteract(player))
  865. +           {
  866. +               player.getAI().setIntention(CtrlIntention.AI_INTENTION_INTERACT, this);
  867. +           }
  868. +           else
  869. +           {
  870. +               // Gira el jugador para enfrentar la instancia
  871. +               player.sendPacket(new MoveToPawn(player, this, Npc.INTERACTION_DISTANCE));
  872. +              
  873. +               onRandomAnimation(1);
  874. +              
  875. +               loadGeneratedItems(player);
  876. +              
  877. +               showHtmlWindow(player);
  878. +              
  879. +               // Enviar ActionFailed al jugador para evitar quedarse atascado
  880. +               player.sendPacket(ActionFailed.STATIC_PACKET);
  881. +           }
  882. +       }
  883. +   }
  884. +  
  885. +   @Override
  886. +   public void onBypassFeedback(Player player, String command)
  887. +   {
  888. +       if (command.startsWith("refresh"))
  889. +       {
  890. +           // Verifique si el jugador tiene el artículo requerido (ID 57) y la cantidad (50000)
  891. +           Item item57 = player.getInventory().getItemByItemId(Config.RANDOM_CRAFT_ITEM_ID_CONSUME);
  892. +           if ((item57 != null) && (item57.getCount() >= Config.RANDOM_CRAFT_ITEM_CONSUME_REFRESH))
  893. +           {
  894. +               // Cargue al jugador el artículo requerido (ID 57) y la cantidad (50000)
  895. +               player.destroyItemByItemId("Random Craft", Config.RANDOM_CRAFT_ITEM_ID_CONSUME, Config.RANDOM_CRAFT_ITEM_CONSUME_REFRESH, null, true);
  896. +              
  897. +               generateItems(player);
  898. +              
  899. +               showHtmlWindow(player);
  900. +              
  901. +               // Almacene los elementos generados en la base de datos para el jugador
  902. +               saveGeneratedItems(player);
  903. +           }
  904. +           else
  905. +           {
  906. +               player.sendMessage("Necesitas al menos 50000 Adena para actualizar Random Craft.");
  907. +               showHtmlWindow(player);
  908. +           }
  909. +       }
  910. +       else if (command.startsWith("create"))
  911. +       {
  912. +          
  913. +           // Carga al jugador el artículo con ID 57 y cantidad 300000
  914. +           Item item57 = player.getInventory().getItemByItemId(Config.RANDOM_CRAFT_ITEM_ID_CONSUME);
  915. +           if ((item57 != null) && (item57.getCount() >= Config.RANDOM_CRAFT_ITEM_CONSUME_CREATE))
  916. +           {
  917. +               // Eliminar los elementos generados para el jugador de la tabla RandomCraftItem
  918. +               deleteGeneratedItems(player);
  919. +              
  920. +               createItem(player);
  921. +           }
  922. +           else
  923. +           {
  924. +               player.sendMessage("Necesitas al menos 300000 Adena para crear un elemento aleatorio.");
  925. +               showHtmlWindow(player);
  926. +           }
  927. +          
  928. +       }
  929. +      
  930. +       else if (command.startsWith("back"))
  931. +       {
  932. +          
  933. +           showHtmlWindow(player);
  934. +       }
  935. +      
  936. +   }
  937. +  
  938. +   private void generateItems(Player player)
  939. +   {
  940. +       List<RandomCraftItem> items = new LinkedList<>();
  941. +       RandomCraftXML randomCraftXML = RandomCraftXML.getInstance();
  942. +       Map<Integer, RandomCraftItem> craftItems = randomCraftXML.getItems();
  943. +      
  944. +       // Genera 4 elementos únicos para cada jugador en función de la probabilidad
  945. +       List<Integer> selectedItems = new ArrayList<>();
  946. +       while (selectedItems.size() < 5)
  947. +       {
  948. +           int itemId = getRandomItem(craftItems);
  949. +           if (!selectedItems.contains(itemId))
  950. +           {
  951. +               selectedItems.add(itemId);
  952. +               items.add(craftItems.get(itemId));
  953. +           }
  954. +       }
  955. +      
  956. +       // Asignar los elementos generados al jugador
  957. +       player.setGeneratedCraftItems(items);
  958. +       setHasGeneratedItems(true);
  959. +      
  960. +   }
  961. +  
  962. +   private static void deleteGeneratedItems(Player player)
  963. +   {
  964. +       try (Connection con = DatabaseFactory.getConnection();
  965. +           PreparedStatement stmt = con.prepareStatement("DELETE FROM RandomCraftItem WHERE object_id = ?"))
  966. +       {
  967. +           stmt.setInt(1, player.getObjectId());
  968. +           stmt.execute();
  969. +       }
  970. +       catch (SQLException e)
  971. +       {
  972. +           e.printStackTrace();
  973. +       }
  974. +   }
  975. +  
  976. +   private static void saveGeneratedItems(Player player)
  977. +   {
  978. +       try (Connection con = DatabaseFactory.getConnection();
  979. +           PreparedStatement stmt = con.prepareStatement("DELETE FROM RandomCraftItem WHERE object_id = ?"))
  980. +       {
  981. +           stmt.setInt(1, player.getObjectId());
  982. +           stmt.execute();
  983. +          
  984. +           try (PreparedStatement insertStmt = con.prepareStatement("INSERT INTO RandomCraftItem (object_id, item_id, amount, chance, announce) VALUES (?, ?, ?, ?, ?)"))
  985. +           {
  986. +               insertStmt.setInt(1, player.getObjectId());
  987. +               List<RandomCraftItem> items = player.getGeneratedCraftItems();
  988. +               if (items != null)
  989. +               {
  990. +                   for (RandomCraftItem item : items)
  991. +                   {
  992. +                       insertStmt.setInt(2, item.getId());
  993. +                       insertStmt.setInt(3, item.getCantidad());
  994. +                       insertStmt.setDouble(4, item.getProbabilidad());
  995. +                       insertStmt.setBoolean(5, item.getAnnounce());
  996. +                       insertStmt.addBatch(); // Agregar la consulta al lote (batch)
  997. +                   }
  998. +                   insertStmt.executeBatch(); // Ejecutar el lote de consultas
  999. +               }
  1000. +           }
  1001. +       }
  1002. +       catch (SQLException e)
  1003. +       {
  1004. +           e.printStackTrace();
  1005. +       }
  1006. +   }
  1007. +  
  1008. +   private void loadGeneratedItems(Player player)
  1009. +   {
  1010. +       try (Connection con = DatabaseFactory.getConnection();
  1011. +           PreparedStatement stmt = con.prepareStatement("SELECT item_id, amount, chance, announce FROM RandomCraftItem WHERE object_id = ?"))
  1012. +       {
  1013. +           stmt.setInt(1, player.getObjectId());
  1014. +          
  1015. +           try (ResultSet rset = stmt.executeQuery())
  1016. +           {
  1017. +               List<RandomCraftItem> items = new LinkedList<>();
  1018. +               while (rset.next())
  1019. +               {
  1020. +                   int itemId = rset.getInt("item_id");
  1021. +                   int amount = rset.getInt("amount");
  1022. +                   int chance = rset.getInt("chance");
  1023. +                   boolean announce = rset.getBoolean("announce");
  1024. +                   RandomCraftItem item = new RandomCraftItem(itemId, amount, chance, announce);
  1025. +                   items.add(item);
  1026. +               }
  1027. +              
  1028. +               player.setGeneratedCraftItems(items);
  1029. +               setHasGeneratedItems(!items.isEmpty());
  1030. +           }
  1031. +       }
  1032. +       catch (SQLException e)
  1033. +       {
  1034. +           e.printStackTrace();
  1035. +       }
  1036. +   }
  1037. +  
  1038. +   private static int getRandomItem(Map<Integer, RandomCraftItem> craftItems)
  1039. +   {
  1040. +       // Calcular la suma de probabilidad total
  1041. +       double totalProbability = 0;
  1042. +       for (RandomCraftItem item : craftItems.values())
  1043. +       {
  1044. +           totalProbability += item.getProbabilidad();
  1045. +       }
  1046. +      
  1047. +       // Generar un valor aleatorio entre 0 y la probabilidad total
  1048. +       Random random = new Random();
  1049. +       double randomValue = random.nextDouble() * totalProbability;
  1050. +      
  1051. +       // Seleccione el elemento en función de la probabilidad
  1052. +       double cumulativeProbability = 0;
  1053. +       for (RandomCraftItem item : craftItems.values())
  1054. +       {
  1055. +           cumulativeProbability += item.getProbabilidad();
  1056. +           if (randomValue <= cumulativeProbability)
  1057. +           {
  1058. +               return item.getId();
  1059. +           }
  1060. +       }
  1061. +      
  1062. +       // Si no se selecciona ningún artículo, devolver un artículo al azar
  1063. +       List<Integer> itemIds = new ArrayList<>(craftItems.keySet());
  1064. +       int index = random.nextInt(itemIds.size());
  1065. +       return itemIds.get(index);
  1066. +   }
  1067. +  
  1068. +   private void createItem(Player player)
  1069. +   {
  1070. +       // Comprueba si la lista de elementos está vacía
  1071. +       List<RandomCraftItem> items = player.getGeneratedCraftItems();
  1072. +       if ((items == null) || items.isEmpty())
  1073. +       {
  1074. +           player.sendMessage("Necesita actualizar para poder crear un elemento aleatorio.");
  1075. +           return;
  1076. +       }
  1077. +      
  1078. +       // Obtén un elemento aleatorio de la lista de elementos generados
  1079. +       Random random = new Random();
  1080. +       int index = random.nextInt(items.size());
  1081. +       RandomCraftItem craftItem = items.get(index);
  1082. +      
  1083. +       // Carga al jugador el artículo con ID 57 y cantidad 300000
  1084. +       Item item57 = player.getInventory().getItemByItemId(Config.RANDOM_CRAFT_ITEM_ID_CONSUME);
  1085. +       if ((item57 != null) && (item57.getCount() >= Config.RANDOM_CRAFT_ITEM_CONSUME_CREATE))
  1086. +       {
  1087. +          
  1088. +           // Da el artículo al jugador
  1089. +           Item Item = player.getInventory().addItem("Random Craft", craftItem.getId(), craftItem.getCantidad(), player, this);
  1090. +           if (Item != null)
  1091. +           {
  1092. +              
  1093. +               player.destroyItemByItemId("Random Craft", Config.RANDOM_CRAFT_ITEM_ID_CONSUME, Config.RANDOM_CRAFT_ITEM_CONSUME_CREATE, null, true);
  1094. +              
  1095. +               // Envía un mensaje al jugador con el nombre del artículo y la cantidad.
  1096. +               String message = "¡Felicidades! Has recibido " + craftItem.getItem().getName() + " (Cantidad: " + craftItem.getCantidad() + ")";
  1097. +               player.sendMessage(message);
  1098. +              
  1099. +               // Obtén el nombre del jugador que creó el elemento
  1100. +               String creatorName = player.getName();
  1101. +              
  1102. +               // Comprueba si el artículo tiene announce en true en el archivo XML
  1103. +               if (craftItem.getAnnounce())
  1104. +               {
  1105. +                  
  1106. +                   for (Player players : World.getInstance().getAllPlayers())
  1107. +                   {
  1108. +                      
  1109. +                       String text = creatorName + " Ha Crafteado: " + craftItem.getItem().getName() + " En el RandomCraft System";
  1110. +                      
  1111. +                       players.sendPacket(new ExShowScreenMessage(text, 5000));
  1112. +                      
  1113. +                   }
  1114. +                  
  1115. +               }
  1116. +              
  1117. +               // Agrega un efecto al jugador si el artículo lo permite
  1118. +               if (craftItem.getAnnounce())
  1119. +               {
  1120. +                   MagicSkillUse MSU = new MagicSkillUse(player, player, 2024, 1, 1, 0);
  1121. +                   player.broadcastPacket(MSU);
  1122. +               }
  1123. +              
  1124. +               // Borra la lista de elementos para el jugador
  1125. +               player.clearGeneratedCraftItems();
  1126. +               setHasGeneratedItems(false);
  1127. +              
  1128. +               // Muestra la ventana de felicitaciones con el item ganador
  1129. +               showCongratulationsWindow(player, craftItem);
  1130. +              
  1131. +               return;
  1132. +           }
  1133. +       }
  1134. +      
  1135. +       player.sendMessage("Necesitas al menos 300000 Adena para crear un elemento aleatorio.");
  1136. +   }
  1137. +  
  1138. +   private void showHtmlWindow(Player player)
  1139. +   {
  1140. +       StringBuilder html = new StringBuilder();
  1141. +       html.append("<html><body>");
  1142. +       html.append("<center>Bienvenido a Random Craft System!</center>");
  1143. +       html.append("<br>");
  1144. +       html.append("<center>Podras Crear 1 item entre los 5 que salgan random!</center>");
  1145. +       html.append("<br>");
  1146. +       html.append("<center>Les Deseo Mucha Suerte</center>");
  1147. +       html.append("<br>");
  1148. +       html.append("<br>");
  1149. +      
  1150. +       List<RandomCraftItem> items = player.getGeneratedCraftItems();
  1151. +       if ((items == null) || items.isEmpty())
  1152. +       {
  1153. +           html.append("<center>La Lista Esta Vacia. Dale a Refresh</center>");
  1154. +       }
  1155. +       else
  1156. +       {
  1157. +           // Generar los iconos de los artículos en forma horizontal
  1158. +           for (RandomCraftItem item : items)
  1159. +           {
  1160. +               html.append("<img src=\"L2UI.SquareGray\" width=295 height=1>");
  1161. +               html.append("<div align=center>");
  1162. +               html.append("<table>");
  1163. +               html.append("<tr>");
  1164. +               html.append("<td>");
  1165. +               html.append("<img src=").append(item.getIcon()).append(" width=32 height=32>");
  1166. +               html.append("</td>");
  1167. +               html.append("<td width=260>");
  1168. +              
  1169. +               double chance = item.getProbabilidad();
  1170. +               String color;
  1171. +               String additionalInfo;
  1172. +              
  1173. +               if (chance <= 25)
  1174. +               {
  1175. +                   color = "FF0000"; // Rojo
  1176. +                   additionalInfo = " - Legendary";
  1177. +               }
  1178. +               else if (chance <= 50)
  1179. +               {
  1180. +                   color = "9932CC"; // Violeta
  1181. +                   additionalInfo = " - Epic";
  1182. +               }
  1183. +               else
  1184. +               {
  1185. +                   color = "FFFF00"; // Amarillo
  1186. +                   additionalInfo = " - Normal";
  1187. +               }
  1188. +              
  1189. +               html.append("<font color=").append(color).append(">").append(item.getItem().getName()).append(" x").append(item.getCantidad()).append(additionalInfo).append("</font>");
  1190. +              
  1191. +               html.append("</td>");
  1192. +               html.append("</tr>");
  1193. +               html.append("</table>");
  1194. +               html.append("</div>");
  1195. +               html.append("<img src=\"L2UI.SquareGray\" width=295 height=1>");
  1196. +               html.append("<br>");
  1197. +           }
  1198. +       }
  1199. +      
  1200. +       html.append("<br>");
  1201. +       html.append("<br>");
  1202. +       html.append("<center>");
  1203. +       html.append("<table>");
  1204. +       html.append("<tr>");
  1205. +       html.append("<td width=75 height=21>");
  1206. +       html.append("<button value=\"Refresh\" action=\"bypass -h npc_").append(getObjectId()).append("_refresh\" width=75 height=21 back=\"L2UI.DefaultButton_click\" fore=\"L2UI.DefaultButton\">");
  1207. +       html.append("</td>");
  1208. +       html.append("<td width=75 height=21>");
  1209. +       html.append("<button value=\"Create\" action=\"bypass -h npc_").append(getObjectId()).append("_create\" width=75 height=21 back=\"L2UI.DefaultButton_click\" fore=\"L2UI.DefaultButton\">");
  1210. +       html.append("</td>");
  1211. +       html.append("</tr>");
  1212. +       html.append("</table>");
  1213. +       html.append("</center>");
  1214. +      
  1215. +       html.append("</body></html>");
  1216. +      
  1217. +       showHtmlWindow(player, html.toString());
  1218. +   }
  1219. +  
  1220. +   private void showHtmlWindow(Player player, String htmlContent)
  1221. +   {
  1222. +       NpcHtmlMessage html = new NpcHtmlMessage(getObjectId());
  1223. +       html.setHtml(htmlContent);
  1224. +      
  1225. +       player.sendPacket(html);
  1226. +   }
  1227. +  
  1228. +   private void showCongratulationsWindow(Player player, RandomCraftItem craftItem)
  1229. +   {
  1230. +       StringBuilder html = new StringBuilder();
  1231. +      
  1232. +       html.append("<html><body>");
  1233. +       html.append("<center>Felicidades, has ganado un item</center>");
  1234. +       html.append("<br>");
  1235. +       html.append("<center>¡Has recibido</center>");
  1236. +       html.append("<br>");
  1237. +       html.append("<br>");
  1238. +       html.append("<img src=\"L2UI.SquareGray\" width=295 height=1>");
  1239. +       html.append("<center>");
  1240. +       html.append("<table>");
  1241. +       html.append("<tr>");
  1242. +       html.append("<td>");
  1243. +       html.append("<img src=").append(craftItem.getIcon()).append(" width=32 height=32>");
  1244. +       html.append("</td>");
  1245. +       html.append("<td width=260>");
  1246. +      
  1247. +       double chance = craftItem.getProbabilidad();
  1248. +       String color;
  1249. +       String additionalInfo;
  1250. +      
  1251. +       if (chance <= 25)
  1252. +       {
  1253. +           color = "FF0000"; // Rojo
  1254. +           additionalInfo = " - Legendary";
  1255. +       }
  1256. +       else if (chance <= 50)
  1257. +       {
  1258. +           color = "9932CC"; // Violeta
  1259. +           additionalInfo = " - Epic";
  1260. +       }
  1261. +       else
  1262. +       {
  1263. +           color = "FFFF00"; // Amarillo
  1264. +           additionalInfo = " - Normal";
  1265. +       }
  1266. +      
  1267. +       html.append("<font color=").append(color).append(">").append(craftItem.getItem().getName()).append(" x").append(craftItem.getCantidad()).append(additionalInfo).append("</font>");
  1268. +      
  1269. +       html.append("</td>");
  1270. +       html.append("</tr>");
  1271. +       html.append("</table>");
  1272. +       html.append("</center>");
  1273. +       html.append("<img src=\"L2UI.SquareGray\" width=295 height=1>");
  1274. +       html.append("<br>");
  1275. +       html.append("<br>");
  1276. +       html.append("<br>");
  1277. +       html.append("<br>");
  1278. +       html.append("<center>");
  1279. +       html.append("<button value=\"Back\" action=\"bypass -h npc_").append(getObjectId()).append("_back\" width=75 height=21 back=\"L2UI.DefaultButton_click\" fore=\"L2UI.DefaultButton\">");
  1280. +       html.append("</center>");
  1281. +       html.append("</body></html>");
  1282. +      
  1283. +       showHtmlWindow(player, html.toString());
  1284. +   }
  1285. +  
  1286. +   /**
  1287. +    * @return the hasGeneratedItems
  1288. +    */
  1289. +   public boolean isHasGeneratedItems()
  1290. +   {
  1291. +       return hasGeneratedItems;
  1292. +   }
  1293. +  
  1294. +   /**
  1295. +    * @param hasGeneratedItems the hasGeneratedItems to set
  1296. +    */
  1297. +   public void setHasGeneratedItems(boolean hasGeneratedItems)
  1298. +   {
  1299. +       this.hasGeneratedItems = hasGeneratedItems;
  1300. +   }
  1301. +}
  1302. diff --git java/org/l2jmobius/gameserver/model/item/ItemTemplate.java java/org/l2jmobius/gameserver/model/item/ItemTemplate.java
  1303. index 3608c32..3baf3b9 100644
  1304. --- java/org/l2jmobius/gameserver/model/item/ItemTemplate.java
  1305. +++ java/org/l2jmobius/gameserver/model/item/ItemTemplate.java
  1306. @@ -32,6 +32,8 @@
  1307.  import org.l2jmobius.gameserver.model.skill.funcs.Func;
  1308.  import org.l2jmobius.gameserver.model.skill.funcs.FuncTemplate;
  1309.  
  1310. +import Base.Data.IconTable;
  1311. +
  1312.  /**
  1313.   * This class contains all informations concerning the item (weapon, armor, etc).<br>
  1314.   * Mother class of :
  1315. @@ -670,6 +672,16 @@
  1316.         }
  1317.     }
  1318.    
  1319. +   public String getIcon(int id)
  1320. +   {
  1321. +       if (IconTable._icons.get(id) == null)
  1322. +       {
  1323. +           return "icon.NOIMAGE";
  1324. +       }
  1325. +      
  1326. +       return IconTable._icons.get(id);
  1327. +   }
  1328. +  
  1329.     /**
  1330.      * Returns the name of the item
  1331.      * @return String
  1332.  
Advertisement
Comments
  • tensador125
    306 days
    # text 0.11 KB | 0 0
    1. If you place between 1 and 25 chance the item will come out as Legendary, in 26 to 50 Epic, 51 to 100 Normal
Add Comment
Please, Sign In to add comment
Advertisement