tobaJK

Alternative Donation Manager

Jul 29th, 2018
287
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ### Eclipse Workspace Patch 1.0
  2. #P aCis_gameserver
  3. Index: java/net/sf/l2j/donation/DonationDyes.java
  4. ===================================================================
  5. --- java/net/sf/l2j/donation/DonationDyes.java  (nonexistent)
  6. +++ java/net/sf/l2j/donation/DonationDyes.java  (working copy)
  7. @@ -0,0 +1,78 @@
  8. +package net.sf.l2j.donation;
  9. +
  10. +import java.util.Arrays;
  11. +
  12. +/**
  13. + * @author Melron
  14. + */
  15. +class DonationDyes
  16. +{
  17. +   public enum AutoDyes
  18. +   {
  19. +       /** (id,symbolId,symbolId,symbolId) symbols can be found at data/xml/hennas.xml*/
  20. +       NONE(-1, -1, -1, -1),
  21. +       DUELIST(88, 158, 146, 172), // +3str -3dex / +2str -2dex / +4con -4dex
  22. +       DREADNOUGHT(89, 173, 171, -1), // +4dex -4str / +4con -4str
  23. +       PHOENIX_KNIGHT(90, 171, -1, -1), // +4con -4str
  24. +       HELL_KNIGHT(91, 170, 172, -1), // +4str -4dex / +4con -4dex
  25. +       SAGGITARIUS(92, 174, -1, -1), // +4dex -4con
  26. +       ADVENTURER(93, 173, 171, -1), // +4dex -4str / +4con -4str
  27. +       ARCHMAGE(94, 180, 175, 171), // +4wit -4men / +4int -4men / +4con -4str
  28. +       SOULTAKER(95, 180, 175, 171), // +4wit -4men / +4int -4men / +4con -4str
  29. +       ARCANA_LORD(96, 180, 175, 171), // +4wit -4men / +4int -4men / +4con -4str
  30. +       CARDINAL(97, 180, -1, 171), // +4wit -4men / +4con -4str
  31. +       HIEROPHANT(98, 180, -1, 171), // +4wit -4men / +4con -4str
  32. +      
  33. +       EVAS_TEMPLAR(99, 170, 172, -1), // +4str -4dex / +4con -4dex
  34. +       SWORD_MUSE(100, 170, 148, -1), // +4str -4dex / +2con -2dex
  35. +       WIND_RIDER(101, 171, 173, -1), // +4con -4str / +4dex -4str
  36. +       MOONLIGHT_SENTINEL(102, 169, 179, -1), // +4str -4con / +4wit -4int
  37. +       MYSTIC_MUSE(103, 180, 175, 171), // +4wit -4men / +4int -4men / +4con -4str
  38. +       ELEMENTAL_MASTER(104, 180, 175, -1), // +4wit -4men / +4int -4men
  39. +       EVAS_SAINT(105, 180, 171, -1), // +4wit -4men / +4con -4str
  40. +      
  41. +       SHILLIEN_TEMPLAR(106, 170, 172, -1), // +4str -4dex / +4con -4dex
  42. +       SPECTRAL_DANCER(107, 170, 172, -1), // +4str -4dex / +4con -4dex
  43. +       GHOST_HUNTER(108, 173, 171, -1), // +4dex -4str / +4con -4str
  44. +       GHOST_SENTINEL(109, 169, 174, -1), // +4str -4con / +4dex -4con
  45. +       STORM_SCREAMER(110, 180, 175, 171), // +4wit -4men / +4int -4men / +4con -4str
  46. +       SPECTRAL_MASTER(111, 180, 175, -1), // +4wit -4men / +4int -4men
  47. +       SHILLIEN_SAINT(112, 180, 171, -1), // +4wit -4men / +4con -4str
  48. +      
  49. +       TITAN(113, 170, -1, -1), // +4con -4dex
  50. +       GRAND_KHAVATARI(114, 169, -1, -1), // +4str -4con
  51. +       DOMINATOR(115, 180, 171, -1), // +4wit -4men / +4con -4str
  52. +       DOOMCRYER(116, 180, 171, -1), // +4wit -4men / +4con -4str
  53. +      
  54. +       FORTUNE_SEEKER(117, 174, -1, -1), // +4dex -4con
  55. +       MAESTRO(118, 174, -1, -1);// +4dex -4con
  56. +      
  57. +       private int _classId;
  58. +       private int[] _dyes = new int[3];
  59. +      
  60. +       private AutoDyes(int classId, int dye1, int dye2, int dye3)
  61. +       {
  62. +           _classId = classId;
  63. +           _dyes[0] = dye1;
  64. +           _dyes[1] = dye2;
  65. +           _dyes[2] = dye3;
  66. +       }
  67. +      
  68. +       public int getId()
  69. +       {
  70. +           return _classId;
  71. +       }
  72. +      
  73. +       public int[] getDyes()
  74. +       {
  75. +           return _dyes;
  76. +       }
  77. +      
  78. +       public static AutoDyes find(int val)
  79. +       {
  80. +           return Arrays.asList(AutoDyes.values()).stream().filter(e -> e.getId() == val).findFirst().orElse(AutoDyes.NONE);
  81. +       }
  82. +   }
  83. +  
  84. +}
  85. Index: java/net/sf/l2j/donation/DonationHolder.java
  86. ===================================================================
  87. --- java/net/sf/l2j/donation/DonationHolder.java    (nonexistent)
  88. +++ java/net/sf/l2j/donation/DonationHolder.java    (working copy)
  89. @@ -0,0 +1,41 @@
  90. +package net.sf.l2j.donation;
  91. +
  92. +import java.util.Collection;
  93. +import java.util.HashMap;
  94. +import java.util.Map;
  95. +
  96. +public enum DonationHolder
  97. +{
  98. +   INSTANCE;
  99. +   private Map<Integer, DonationPackage> donates;
  100. +  
  101. +   DonationHolder()
  102. +   {
  103. +       donates = new HashMap<>();
  104. +   }
  105. +  
  106. +   public void add(int pos, DonationPackage packet)
  107. +   {
  108. +       donates.put(pos, packet);
  109. +   }
  110. +  
  111. +   public int getSize()
  112. +   {
  113. +       return donates.size();
  114. +   }
  115. +  
  116. +   public DonationPackage get(int val)
  117. +   {
  118. +       return donates.get(val);
  119. +   }
  120. +  
  121. +   public Collection<DonationPackage> getPackages()
  122. +   {
  123. +       return donates.values();
  124. +   }
  125. +  
  126. +   public void clear()
  127. +   {
  128. +       donates.clear();
  129. +   }
  130. +}
  131. Index: java/net/sf/l2j/donation/DonationItem.java
  132. ===================================================================
  133. --- java/net/sf/l2j/donation/DonationItem.java  (nonexistent)
  134. +++ java/net/sf/l2j/donation/DonationItem.java  (working copy)
  135. @@ -0,0 +1,33 @@
  136. +package net.sf.l2j.donation;
  137. +
  138. +/**
  139. + * A generic int/int container.
  140. + */
  141. +public class DonationItem
  142. +{
  143. +   private final int _id;
  144. +   private final int _count;
  145. +   private final int _enchant;
  146. +
  147. +   public DonationItem(int id, int count, int enchant)
  148. +   {
  149. +       _id = id;
  150. +       _count = count;
  151. +       _enchant = enchant;
  152. +   }
  153. +
  154. +   public int getId()
  155. +   {
  156. +       return _id;
  157. +   }
  158. +
  159. +   public int getCount()
  160. +   {
  161. +       return _count;
  162. +   }
  163. +
  164. +   public int getEnchant()
  165. +   {
  166. +       return _enchant;
  167. +   }
  168. +}
  169. \ No newline at end of file
  170. Index: java/net/sf/l2j/donation/DonationMisc.java
  171. ===================================================================
  172. --- java/net/sf/l2j/donation/DonationMisc.java  (nonexistent)
  173. +++ java/net/sf/l2j/donation/DonationMisc.java  (working copy)
  174. @@ -0,0 +1,41 @@
  175. +package net.sf.l2j.donation;
  176. +
  177. +public class DonationMisc
  178. +{
  179. +   private final boolean _noblesse;
  180. +   private final boolean _autoDyes;
  181. +   private final int _rec;
  182. +
  183. +   public DonationMisc(boolean noblesse, boolean autoDyes, int rec)
  184. +   {
  185. +       _noblesse = noblesse;
  186. +       _autoDyes = autoDyes;
  187. +       _rec = rec;
  188. +   }
  189. +
  190. +   public boolean isEmpty()
  191. +   {
  192. +       return !_noblesse && _rec <= 0 && !_autoDyes;
  193. +   }
  194. +
  195. +   public boolean haveNoblesse()
  196. +   {
  197. +       return _noblesse;
  198. +   }
  199. +
  200. +   public boolean haveRec()
  201. +   {
  202. +       return _rec > 0;
  203. +   }
  204. +
  205. +   public boolean haveDyes()
  206. +   {
  207. +       return _autoDyes;
  208. +   }
  209. +
  210. +   public int getRecs()
  211. +   {
  212. +       return _rec;
  213. +   }
  214. +
  215. +}
  216. Index: java/net/sf/l2j/donation/DonationPackage.java
  217. ===================================================================
  218. --- java/net/sf/l2j/donation/DonationPackage.java   (nonexistent)
  219. +++ java/net/sf/l2j/donation/DonationPackage.java   (working copy)
  220. @@ -0,0 +1,136 @@
  221. +package net.sf.l2j.donation;
  222. +
  223. +import java.util.List;
  224. +
  225. +import net.sf.l2j.donation.DonationDyes.AutoDyes;
  226. +import net.sf.l2j.gameserver.data.ItemTable;
  227. +import net.sf.l2j.gameserver.data.xml.HennaData;
  228. +import net.sf.l2j.gameserver.model.actor.instance.Player;
  229. +import net.sf.l2j.gameserver.model.item.Henna;
  230. +import net.sf.l2j.gameserver.model.item.instance.ItemInstance;
  231. +import net.sf.l2j.gameserver.network.serverpackets.SocialAction;
  232. +
  233. +public abstract class DonationPackage
  234. +{
  235. +   private final int _cost;
  236. +   private final List<DonationItem> _items;
  237. +   private final DonationMisc _misc;
  238. +  
  239. +   public DonationPackage(int cost,List<DonationItem> items,DonationMisc misc)
  240. +   {
  241. +       _cost = cost;
  242. +       _items = items;
  243. +       _misc = misc;
  244. +   }
  245. +  
  246. +   public boolean haveMisc()
  247. +   {
  248. +       return !_misc.isEmpty();
  249. +   }
  250. +  
  251. +   public List<DonationItem> getItems()
  252. +   {
  253. +       return _items;
  254. +   }
  255. +  
  256. +   public int getCost()
  257. +   {
  258. +       return _cost;
  259. +   }
  260. +  
  261. +   public String getPackage()
  262. +   {
  263. +       return this.getClass().getSimpleName();
  264. +   }
  265. +  
  266. +   public void applyImprovements(Player player)
  267. +   {
  268. +       handleNoblessMisc(player);
  269. +       handleRecMisc(player);
  270. +       handleDyesMisc(player);
  271. +   }
  272. +  
  273. +   private void handleDyesMisc(Player player)
  274. +   {
  275. +       if (_misc.haveDyes())
  276. +           drawDyes(player);
  277. +   }
  278. +  
  279. +   private void handleRecMisc(Player player)
  280. +   {
  281. +       if (_misc.haveRec())
  282. +       {
  283. +           player.setRecomHave(_misc.getRecs());
  284. +           player.broadcastUserInfo();
  285. +       }
  286. +   }
  287. +  
  288. +   private void handleNoblessMisc(Player player)
  289. +   {
  290. +       if (!_misc.haveNoblesse())
  291. +           return;
  292. +      
  293. +       player.setNoble(true, true);
  294. +       player.broadcastPacket(new SocialAction(player, 16));
  295. +       player.sendMessage("You granted with noblesse status!");
  296. +   }
  297. +  
  298. +   public DonationMisc getMisc()
  299. +   {
  300. +       return _misc;
  301. +   }
  302. +  
  303. +   private static void drawDyes(Player player)
  304. +   {
  305. +       removeOldDyes(player);
  306. +       AutoDyes availableDyes = AutoDyes.find(player.getClassId().getId());
  307. +      
  308. +       if (availableDyes == AutoDyes.NONE)
  309. +           return;
  310. +      
  311. +       applyDyesToPlayer(player, availableDyes);
  312. +      
  313. +   }
  314. +  
  315. +   private static void applyDyesToPlayer(Player player, AutoDyes availableDyes)
  316. +   {
  317. +       for (final int symbolId : availableDyes.getDyes())
  318. +       {
  319. +           if (symbolId == -1)
  320. +               continue;
  321. +           final Henna henna = HennaData.getInstance().getHenna(symbolId);
  322. +           if (henna.canBeUsedBy(player))
  323. +               player.addHenna(henna);
  324. +       }
  325. +   }
  326. +  
  327. +   private static void removeOldDyes(Player player)
  328. +   {
  329. +       for (int i = 1; i <= 3; i++)
  330. +       {
  331. +           final Henna henna = player.getHenna(i);
  332. +           if (henna != null)
  333. +               player.removeHenna(i);
  334. +       }
  335. +   }
  336. +  
  337. +   public void reward(Player player)
  338. +   {
  339. +       for (final DonationItem itemInfo : getItems())
  340. +       {
  341. +           final ItemInstance item = ItemTable.getInstance().createItem("donation", itemInfo.getId(), itemInfo.getCount(), player, null);
  342. +           if (item == null)
  343. +           {
  344. +               System.out.println("Incorect item with id " + itemInfo.getId());
  345. +               continue;
  346. +           }
  347. +          
  348. +           if (itemInfo.getEnchant() > 0)
  349. +               item.setEnchantLevel(itemInfo.getEnchant());
  350. +           player.addItem("donation", item, null, true);
  351. +       }
  352. +       if (haveMisc())
  353. +           applyImprovements(player);
  354. +   }
  355. +  
  356. +}
  357. Index: java/net/sf/l2j/donation/DonationStats.java
  358. ===================================================================
  359. --- java/net/sf/l2j/donation/DonationStats.java (nonexistent)
  360. +++ java/net/sf/l2j/donation/DonationStats.java (working copy)
  361. @@ -0,0 +1,112 @@
  362. +package net.sf.l2j.donation;
  363. +
  364. +import java.io.File;
  365. +import java.lang.reflect.Constructor;
  366. +import java.util.ArrayList;
  367. +import java.util.List;
  368. +import java.util.logging.Level;
  369. +import java.util.logging.Logger;
  370. +
  371. +import net.sf.l2j.commons.data.xml.XMLDocument;
  372. +
  373. +import org.w3c.dom.Document;
  374. +import org.w3c.dom.NamedNodeMap;
  375. +import org.w3c.dom.Node;
  376. +
  377. +public class DonationStats extends XMLDocument
  378. +{
  379. +   private static Logger _log = Logger.getLogger(DonationStats.class.getName());
  380. +  
  381. +   public DonationStats()
  382. +   {
  383. +       load();
  384. +   }
  385. +  
  386. +   @Override
  387. +   protected void load()
  388. +   {
  389. +       loadDocument("./data/xml/donatePackets.xml");
  390. +   }
  391. +  
  392. +   @Override
  393. +   protected void parseDocument(Document doc, File f)
  394. +   {
  395. +       final Node n = doc.getFirstChild();
  396. +       int pos = 0;
  397. +       for (Node o = n.getFirstChild(); o != null; o = o.getNextSibling())
  398. +       {
  399. +           if (!"Donation".equalsIgnoreCase(o.getNodeName()))
  400. +               continue;
  401. +          
  402. +           final String category = o.getAttributes().getNamedItem("category").getNodeValue() + "Package";
  403. +           final int price = Integer.parseInt(o.getAttributes().getNamedItem("price").getNodeValue());
  404. +          
  405. +           assert price > 0 : " Price " + price;
  406. +          
  407. +           final List<DonationItem> items = new ArrayList<>();
  408. +           boolean noblesse = false;
  409. +           boolean autoDyes = false;
  410. +           int rec = 0;
  411. +          
  412. +           for (Node d = o.getFirstChild(); d != null; d = d.getNextSibling())
  413. +           {
  414. +               if (!d.getNodeName().equalsIgnoreCase("Package"))
  415. +                   continue;
  416. +              
  417. +               final NamedNodeMap attrs = d.getAttributes();
  418. +              
  419. +               if (attrs.getNamedItem("item") != null)
  420. +               {
  421. +                   final String[] item = attrs.getNamedItem("item").getNodeValue().split(",");
  422. +                   int enchant = 0;
  423. +                  
  424. +                   if (attrs.getNamedItem("enchant") != null)
  425. +                       enchant = Integer.parseInt(attrs.getNamedItem("enchant").getNodeValue());
  426. +                  
  427. +                   items.add(new DonationItem(Integer.parseInt(item[0]), Integer.parseInt(item[1]), enchant));
  428. +               }
  429. +              
  430. +               else if (attrs.getNamedItem("noblesse") != null)
  431. +                   noblesse = Boolean.parseBoolean(attrs.getNamedItem("noblesse").getNodeValue());
  432. +              
  433. +               else if (attrs.getNamedItem("autoDyes") != null)
  434. +                   autoDyes = Boolean.parseBoolean(attrs.getNamedItem("autoDyes").getNodeValue());
  435. +              
  436. +               else if (attrs.getNamedItem("rec") != null)
  437. +                   rec = Integer.parseInt(attrs.getNamedItem("rec").getNodeValue());
  438. +           }
  439. +           try
  440. +           {
  441. +               Constructor<?> _constructor = Class.forName("net.sf.l2j.donation.packages." + category).getConstructors()[0];
  442. +               DonationHolder.INSTANCE.add(pos++, (DonationPackage) _constructor.newInstance(price, items, new DonationMisc(noblesse, autoDyes, rec)));
  443. +              
  444. +           }
  445. +           catch (Exception e)
  446. +           {
  447. +               _log.log(Level.SEVERE, "Could not parse donatePackets.xml", e);
  448. +           }
  449. +       }
  450. +   }
  451. +  
  452. +   public static DonationStats getInstance()
  453. +   {
  454. +       return SingletonHolder._instance;
  455. +   }
  456. +  
  457. +   private static class SingletonHolder
  458. +   {
  459. +       protected static final DonationStats _instance = new DonationStats();
  460. +   }
  461. +  
  462. +   public int size()
  463. +   {
  464. +       return DonationHolder.INSTANCE.getSize();
  465. +   }
  466. +  
  467. +   public void reload()
  468. +   {
  469. +       DonationHolder.INSTANCE.clear();
  470. +       load();
  471. +   }
  472. +  
  473. +}
  474. Index: java/net/sf/l2j/donation/packages/BronzePackage.java
  475. ===================================================================
  476. --- java/net/sf/l2j/donation/packages/BronzePackage.java    (nonexistent)
  477. +++ java/net/sf/l2j/donation/packages/BronzePackage.java    (working copy)
  478. @@ -0,0 +1,15 @@
  479. +package net.sf.l2j.donation.packages;
  480. +
  481. +import java.util.List;
  482. +
  483. +import net.sf.l2j.donation.DonationItem;
  484. +import net.sf.l2j.donation.DonationMisc;
  485. +import net.sf.l2j.donation.DonationPackage;
  486. +
  487. +public class BronzePackage extends DonationPackage
  488. +{
  489. +   public BronzePackage(int cost, List<DonationItem> items, DonationMisc misc)
  490. +   {
  491. +       super(cost, items, misc);
  492. +   }
  493. +}
  494. Index: java/net/sf/l2j/donation/packages/DiamondPackage.java
  495. ===================================================================
  496. --- java/net/sf/l2j/donation/packages/DiamondPackage.java   (nonexistent)
  497. +++ java/net/sf/l2j/donation/packages/DiamondPackage.java   (working copy)
  498. @@ -0,0 +1,15 @@
  499. +package net.sf.l2j.donation.packages;
  500. +
  501. +import java.util.List;
  502. +
  503. +import net.sf.l2j.donation.DonationItem;
  504. +import net.sf.l2j.donation.DonationMisc;
  505. +import net.sf.l2j.donation.DonationPackage;
  506. +
  507. +public class DiamondPackage extends DonationPackage
  508. +{
  509. +   public DiamondPackage(int cost, List<DonationItem> items, DonationMisc misc)
  510. +   {
  511. +       super(cost, items, misc);
  512. +   }
  513. +}
  514. Index: java/net/sf/l2j/donation/packages/GoldPackage.java
  515. ===================================================================
  516. --- java/net/sf/l2j/donation/packages/GoldPackage.java  (nonexistent)
  517. +++ java/net/sf/l2j/donation/packages/GoldPackage.java  (working copy)
  518. @@ -0,0 +1,15 @@
  519. +package net.sf.l2j.donation.packages;
  520. +
  521. +import java.util.List;
  522. +
  523. +import net.sf.l2j.donation.DonationItem;
  524. +import net.sf.l2j.donation.DonationMisc;
  525. +import net.sf.l2j.donation.DonationPackage;
  526. +
  527. +public class GoldPackage extends DonationPackage
  528. +{
  529. +   public GoldPackage(int cost, List<DonationItem> items, DonationMisc misc)
  530. +   {
  531. +       super(cost, items, misc);
  532. +   }
  533. +}
  534. Index: java/net/sf/l2j/donation/packages/GrandmasterPackage.java
  535. ===================================================================
  536. --- java/net/sf/l2j/donation/packages/GrandmasterPackage.java   (nonexistent)
  537. +++ java/net/sf/l2j/donation/packages/GrandmasterPackage.java   (working copy)
  538. @@ -0,0 +1,15 @@
  539. +package net.sf.l2j.donation.packages;
  540. +
  541. +import java.util.List;
  542. +
  543. +import net.sf.l2j.donation.DonationItem;
  544. +import net.sf.l2j.donation.DonationMisc;
  545. +import net.sf.l2j.donation.DonationPackage;
  546. +
  547. +public class GrandmasterPackage extends DonationPackage
  548. +{
  549. +   public GrandmasterPackage(int cost, List<DonationItem> items, DonationMisc misc)
  550. +   {
  551. +       super(cost, items, misc);
  552. +   }
  553. +}
  554. Index: java/net/sf/l2j/donation/packages/MasterPackage.java
  555. ===================================================================
  556. --- java/net/sf/l2j/donation/packages/MasterPackage.java    (nonexistent)
  557. +++ java/net/sf/l2j/donation/packages/MasterPackage.java    (working copy)
  558. @@ -0,0 +1,15 @@
  559. +package net.sf.l2j.donation.packages;
  560. +
  561. +import java.util.List;
  562. +
  563. +import net.sf.l2j.donation.DonationItem;
  564. +import net.sf.l2j.donation.DonationMisc;
  565. +import net.sf.l2j.donation.DonationPackage;
  566. +
  567. +public class MasterPackage extends DonationPackage
  568. +{
  569. +   public MasterPackage(int cost, List<DonationItem> items, DonationMisc misc)
  570. +   {
  571. +       super(cost, items, misc);
  572. +   }
  573. +}
  574. Index: java/net/sf/l2j/donation/packages/PlatinumPackage.java
  575. ===================================================================
  576. --- java/net/sf/l2j/donation/packages/PlatinumPackage.java  (nonexistent)
  577. +++ java/net/sf/l2j/donation/packages/PlatinumPackage.java  (working copy)
  578. @@ -0,0 +1,15 @@
  579. +package net.sf.l2j.donation.packages;
  580. +
  581. +import java.util.List;
  582. +
  583. +import net.sf.l2j.donation.DonationItem;
  584. +import net.sf.l2j.donation.DonationMisc;
  585. +import net.sf.l2j.donation.DonationPackage;
  586. +
  587. +public class PlatinumPackage extends DonationPackage
  588. +{
  589. +   public PlatinumPackage(int cost, List<DonationItem> items, DonationMisc misc)
  590. +   {
  591. +       super(cost, items, misc);
  592. +   }
  593. +}
  594. Index: java/net/sf/l2j/donation/packages/SilverPackage.java
  595. ===================================================================
  596. --- java/net/sf/l2j/donation/packages/SilverPackage.java    (nonexistent)
  597. +++ java/net/sf/l2j/donation/packages/SilverPackage.java    (working copy)
  598. @@ -0,0 +1,15 @@
  599. +package net.sf.l2j.donation.packages;
  600. +
  601. +import java.util.List;
  602. +
  603. +import net.sf.l2j.donation.DonationItem;
  604. +import net.sf.l2j.donation.DonationMisc;
  605. +import net.sf.l2j.donation.DonationPackage;
  606. +
  607. +public class SilverPackage extends DonationPackage
  608. +{
  609. +   public SilverPackage(int cost, List<DonationItem> items, DonationMisc misc)
  610. +   {
  611. +       super(cost, items, misc);
  612. +   }
  613. +}
  614. Index: java/net/sf/l2j/gameserver/GameServer.java
  615. ===================================================================
  616. --- java/net/sf/l2j/gameserver/GameServer.java  (revision 2)
  617. +++ java/net/sf/l2j/gameserver/GameServer.java  (working copy)
  618. @@ -18,6 +18,7 @@
  619.  
  620.  import net.sf.l2j.Config;
  621.  import net.sf.l2j.L2DatabaseFactory;
  622. +import net.sf.l2j.donation.DonationStats;
  623.  import net.sf.l2j.gameserver.cache.CrestCache;
  624.  import net.sf.l2j.gameserver.cache.HtmCache;
  625.  import net.sf.l2j.gameserver.communitybbs.Manager.ForumsBBSManager;
  626. @@ -283,6 +284,9 @@
  627.         _log.config("SkillHandler: Loaded " + SkillHandler.getInstance().size() + " handlers.");
  628.         _log.config("UserCommandHandler: Loaded " + UserCommandHandler.getInstance().size() + " handlers.");
  629.        
  630. +       StringUtil.printSection("Donation Stats");
  631. +       _log.info("Loaded " + DonationStats.getInstance().size() + " Donation Packages.");
  632. +      
  633.         StringUtil.printSection("System");
  634.         Runtime.getRuntime().addShutdownHook(Shutdown.getInstance());
  635.         ForumsBBSManager.getInstance();
  636.  
  637. \ No newline at end of file
  638.  
  639.  
  640. Index: java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminAdmin.java
  641. ===================================================================
  642. --- java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminAdmin.java (revision 2)
  643. +++ java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminAdmin.java (working copy)
  644. @@ -5,6 +5,7 @@
  645.  import net.sf.l2j.commons.lang.StringUtil;
  646.  
  647.  import net.sf.l2j.Config;
  648. +import net.sf.l2j.donation.DonationStats;
  649.  import net.sf.l2j.gameserver.cache.CrestCache;
  650.  import net.sf.l2j.gameserver.cache.HtmCache;
  651.  import net.sf.l2j.gameserver.data.ItemTable;
  652. @@ -232,6 +233,11 @@
  653.                         ZoneManager.getInstance().reload();
  654.                         activeChar.sendMessage("Zones have been reloaded.");
  655.                     }
  656. +                   else if (type.startsWith("donations"))
  657. +                   {
  658. +                       DonationStats.getInstance().reload();
  659. +                       activeChar.sendMessage("Donations have been reloaded.");
  660. +                   }
  661.                     else
  662.                     {
  663.                         activeChar.sendMessage("Usage : //reload <acar|announcement|config|crest|door>");
  664.  
  665.  
  666.  
  667.  
  668. Index: java/net/sf/l2j/gameserver/model/actor/instance/DonationManager.java
  669. ===================================================================
  670. --- java/net/sf/l2j/gameserver/model/actor/instance/DonationManager.java    (nonexistent)
  671. +++ java/net/sf/l2j/gameserver/model/actor/instance/DonationManager.java    (working copy)
  672. @@ -0,0 +1,188 @@
  673. +package net.sf.l2j.gameserver.model.actor.instance;
  674. +
  675. +import java.util.Collection;
  676. +import java.util.StringTokenizer;
  677. +
  678. +import net.sf.l2j.commons.lang.StringUtil;
  679. +
  680. +import net.sf.l2j.donation.DonationHolder;
  681. +import net.sf.l2j.donation.DonationItem;
  682. +import net.sf.l2j.donation.DonationMisc;
  683. +import net.sf.l2j.donation.DonationPackage;
  684. +import net.sf.l2j.gameserver.data.ItemTable;
  685. +import net.sf.l2j.gameserver.model.actor.template.NpcTemplate;
  686. +import net.sf.l2j.gameserver.network.serverpackets.NpcHtmlMessage;
  687. +
  688. +public class DonationManager extends Folk
  689. +{
  690. +   private static final int donateItemId = 57;
  691. +  
  692. +   public DonationManager(int objectId, NpcTemplate template)
  693. +   {
  694. +       super(objectId, template);
  695. +   }
  696. +  
  697. +   @Override
  698. +   public void onBypassFeedback(Player player, String command)
  699. +   {
  700. +       StringTokenizer st = new StringTokenizer(command, " ");
  701. +       String currentCommand = st.nextToken();
  702. +      
  703. +       if (currentCommand.startsWith("showPackages"))
  704. +       {
  705. +           showPackages(player);
  706. +       }
  707. +       else if (currentCommand.startsWith("explore"))
  708. +       {
  709. +           if (!st.hasMoreTokens())
  710. +               return;
  711. +          
  712. +           final int val = tryParseInt(st.nextToken());
  713. +          
  714. +           if (val < 0)
  715. +               return;
  716. +          
  717. +           explorePackage(player, val);
  718. +       }
  719. +       else if (currentCommand.startsWith("buy"))
  720. +       {
  721. +           final int val = tryParseInt(st.nextToken());
  722. +          
  723. +           if (val <= 0)
  724. +               return;
  725. +          
  726. +           final DonationPackage packet = DonationHolder.INSTANCE.get(val);
  727. +          
  728. +           if (packet == null)
  729. +               return;
  730. +          
  731. +           if (player.destroyItemByItemId("donation", donateItemId, packet.getCost(), null, true))
  732. +               packet.reward(player);
  733. +       }
  734. +   }
  735. +  
  736. +   /**
  737. +    * @param player
  738. +    * @param val
  739. +    */
  740. +   private void explorePackage(Player player, int val)
  741. +   {
  742. +       DonationPackage currPackage = DonationHolder.INSTANCE.get(val);
  743. +      
  744. +       if (currPackage == null)
  745. +           return;
  746. +      
  747. +       final NpcHtmlMessage html = new NpcHtmlMessage(0);
  748. +       html.setFile("data/html/mods/donate/list.htm");
  749. +      
  750. +       final StringBuilder sb = new StringBuilder();
  751. +       generateHtmlForPackageItems(currPackage, sb);
  752. +       generateHtmlForMiscs(currPackage, sb);
  753. +       replacePackageHtmlPlaceholders(val, currPackage, html, sb);
  754. +       player.sendPacket(html);
  755. +   }
  756. +  
  757. +   private void replacePackageHtmlPlaceholders(int val, DonationPackage currPackage, NpcHtmlMessage html, StringBuilder sb)
  758. +   {
  759. +       html.replace("%package%", "<font color=\"LEVEL\">" + currPackage.getPackage().split("Package")[0] + " Package</font>");
  760. +       html.replace("%objectId%", getObjectId());
  761. +       html.replace("%items%", sb.toString());
  762. +       html.replace("%packetVal%", val);
  763. +   }
  764. +  
  765. +   private static void generateHtmlForMiscs(DonationPackage currPackage, StringBuilder sb)
  766. +   {
  767. +       if (!currPackage.haveMisc())
  768. +           return;
  769. +      
  770. +       final DonationMisc misc = currPackage.getMisc();
  771. +      
  772. +       if (misc.haveNoblesse())
  773. +           StringUtil.append(sb, "<tr><td align=\"center\">", "<font color=\"LEVEL\">Noblesse Status</font></td></tr>");
  774. +      
  775. +       if (misc.haveRec())
  776. +           StringUtil.append(sb, "<tr><td align=\"center\"><font color=\"LEVEL\">Recommends</font> (", misc.getRecs(), ")</font></td></tr>");
  777. +      
  778. +       if (misc.haveDyes())
  779. +           StringUtil.append(sb, "<tr><td align=\"center\"><font color=\"LEVEL\">Auto Dyes Picker</font></td></tr>");
  780. +   }
  781. +  
  782. +   private static void generateHtmlForPackageItems(DonationPackage currPackage, StringBuilder sb)
  783. +   {
  784. +       for (DonationItem donateItem : currPackage.getItems())
  785. +       {
  786. +           final String name = ItemTable.getInstance().getTemplate(donateItem.getId()).getName();
  787. +           final int count = donateItem.getCount();
  788. +           final int enchant = donateItem.getEnchant();
  789. +           StringUtil.append(sb, "<tr><td align=\"center\">", name, " (x", count, ")" + (enchant > 0 ? " <font color=\"LEVEL\">+" + enchant + "</font>" : "") + "</td></tr>");
  790. +       }
  791. +   }
  792. +  
  793. +   private void showPackages(Player player)
  794. +   {
  795. +       final Collection<DonationPackage> packages = DonationHolder.INSTANCE.getPackages();
  796. +       if (packages.isEmpty())
  797. +           return;
  798. +      
  799. +       final NpcHtmlMessage html = new NpcHtmlMessage(0);
  800. +       html.setFile(getHtmlPath(getNpcId(), 1));
  801. +      
  802. +       final StringBuilder sb = new StringBuilder();
  803. +       generateDonationPackageHtml(packages, sb);
  804. +       replaceHtmlPlaceholders(html, sb);
  805.  
  806. +       player.sendPacket(html);
  807. +   }
  808. +  
  809. +   private void replaceHtmlPlaceholders(NpcHtmlMessage html, StringBuilder sb)
  810. +   {
  811. +       html.replace("%packages%", sb.toString());
  812. +       html.replace("%objectId%", getObjectId());
  813. +   }
  814. +  
  815. +   private static void generateDonationPackageHtml(Collection<DonationPackage> packages, StringBuilder sb)
  816. +   {
  817. +       int pos = 0;
  818. +       for (final DonationPackage dp : packages)
  819. +       {
  820. +           final String name = dp.getPackage().split("Package")[0] + " Package";
  821. +           final int cost = dp.getCost();
  822. +           StringUtil.append(sb, "<tr><td align=\"center\"><a action=\"bypass -h npc_%objectId%_explore ", pos++, "\">", name, "</a></td><td>", "<font color=\"3399CC\">", cost, " ", ItemTable.getInstance().getTemplate(donateItemId).getName(), "</font></td></tr>");
  823. +       }
  824. +   }
  825. +  
  826. +   private static int tryParseInt(String val)
  827. +   {
  828. +       try
  829. +       {
  830. +           return Integer.parseInt(val);
  831. +       }
  832. +       catch (NumberFormatException e)
  833. +       {
  834. +           return 0;
  835. +       }
  836. +   }
  837. +  
  838. +   @Override
  839. +   public String getHtmlPath(int npcId, int val)
  840. +   {
  841. +       String filename = "";
  842. +       if (val == 0)
  843. +           filename = "" + npcId;
  844. +       else
  845. +           filename = npcId + "-" + val;
  846. +      
  847. +       return "data/html/mods/donate/" + filename + ".htm";
  848. +   }
  849. +  
  850. +}
  851. \ No newline at end of file
RAW Paste Data