Advertisement
xSweeTs

Hero Item

Jun 30th, 2016
1,112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 8.92 KB | None | 0 0
  1. ### Eclipse Workspace Patch 1.0
  2. #P aCis_gameserver
  3. Index: java/net/sf/l2j/gameserver/taskmanager/HeroTaskManager.java
  4. ===================================================================
  5. --- java/net/sf/l2j/gameserver/taskmanager/HeroTaskManager.java (nonexistent)
  6. +++ java/net/sf/l2j/gameserver/taskmanager/HeroTaskManager.java (working copy)
  7. @@ -0,0 +1,86 @@
  8. +/*
  9. + * This program is free software: you can redistribute it and/or modify it under
  10. + * the terms of the GNU General Public License as published by the Free Software
  11. + * Foundation, either version 3 of the License, or (at your option) any later
  12. + * version.
  13. + *
  14. + * This program is distributed in the hope that it will be useful, but WITHOUT
  15. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  16. + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  17. + * details.
  18. + *
  19. + * You should have received a copy of the GNU General Public License along with
  20. + * this program. If not, see <http://www.gnu.org/licenses/>.
  21. + */
  22. +package net.sf.l2j.gameserver.taskmanager;
  23. +
  24. +import java.util.Map;
  25. +import java.util.concurrent.ConcurrentHashMap;
  26. +
  27. +import net.sf.l2j.commons.concurrent.ThreadPool;
  28. +
  29. +import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  30. +import net.sf.l2j.gameserver.network.clientpackets.Say2;
  31. +import net.sf.l2j.gameserver.network.serverpackets.CreatureSay;
  32. +
  33. +public final class HeroTaskManager implements Runnable
  34. +{
  35. +   private final Map<L2PcInstance, Long> _players = new ConcurrentHashMap<>();
  36. +  
  37. +   protected HeroTaskManager()
  38. +   {
  39. +       ThreadPool.scheduleAtFixedRate(this, 1000, 1000);
  40. +   }
  41. +  
  42. +   /**
  43. +    * Adds {@link L2PcInstance} to the HeroTask.
  44. +    * @param player : L2PcInstance to be added and checked.
  45. +    */
  46. +   public final void add(L2PcInstance player)
  47. +   {
  48. +       _players.put(player, System.currentTimeMillis());
  49. +   }
  50. +  
  51. +   /**
  52. +    * Removes {@link L2PcInstance} from the HeroTask.
  53. +    * @param player : {@link L2PcInstance} to be removed.
  54. +    */
  55. +   public final void remove(L2PcInstance player)
  56. +   {
  57. +       _players.remove(player);
  58. +   }
  59. +  
  60. +   @Override
  61. +   public final void run()
  62. +   {
  63. +       // List is empty, skip.
  64. +       if (_players.isEmpty())
  65. +           return;
  66. +      
  67. +       // Loop all players.
  68. +       for (Map.Entry<L2PcInstance, Long> entry : _players.entrySet())
  69. +       {
  70. +           // Get player.
  71. +           final L2PcInstance player = entry.getKey();
  72. +          
  73. +           if (player.getMemos().getLong("heroTime") < System.currentTimeMillis())
  74. +           {
  75. +               player.setHero(false);
  76. +               player.broadcastUserInfo();
  77. +               player.sendPacket(new CreatureSay(0, Say2.HERO_VOICE, "System", "Dear player, your hero period is over."));
  78. +               player.getMemos().set("heroTime", 0);
  79. +               remove(player);
  80. +           }
  81. +       }
  82. +   }
  83. +  
  84. +   public static final HeroTaskManager getInstance()
  85. +   {
  86. +       return SingletonHolder._instance;
  87. +   }
  88. +  
  89. +   private static class SingletonHolder
  90. +   {
  91. +       protected static final HeroTaskManager _instance = new HeroTaskManager();
  92. +   }
  93. +}
  94. \ No newline at end of file
  95. Index: java/net/sf/l2j/gameserver/handler/ItemHandler.java
  96. ===================================================================
  97. --- java/net/sf/l2j/gameserver/handler/ItemHandler.java (revision 590)
  98. +++ java/net/sf/l2j/gameserver/handler/ItemHandler.java (working copy)
  99. @@ -27,6 +27,7 @@
  100.  import net.sf.l2j.gameserver.handler.itemhandlers.EnchantScrolls;
  101.  import net.sf.l2j.gameserver.handler.itemhandlers.FishShots;
  102.  import net.sf.l2j.gameserver.handler.itemhandlers.Harvester;
  103. +import net.sf.l2j.gameserver.handler.itemhandlers.HeroItem;
  104.  import net.sf.l2j.gameserver.handler.itemhandlers.ItemSkills;
  105.  import net.sf.l2j.gameserver.handler.itemhandlers.Keys;
  106.  import net.sf.l2j.gameserver.handler.itemhandlers.Maps;
  107. @@ -66,6 +67,7 @@
  108.         registerItemHandler(new EnchantScrolls());
  109.         registerItemHandler(new FishShots());
  110.         registerItemHandler(new Harvester());
  111. +       registerItemHandler(new HeroItem());
  112.         registerItemHandler(new ItemSkills());
  113.         registerItemHandler(new Keys());
  114.         registerItemHandler(new Maps());
  115. Index: java/net/sf/l2j/gameserver/model/actor/instance/L2PcInstance.java
  116. ===================================================================
  117. --- java/net/sf/l2j/gameserver/model/actor/instance/L2PcInstance.java   (revision 590)
  118. +++ java/net/sf/l2j/gameserver/model/actor/instance/L2PcInstance.java   (working copy)
  119. @@ -241,6 +241,7 @@
  120.  import net.sf.l2j.gameserver.skills.l2skills.L2SkillSummon;
  121.  import net.sf.l2j.gameserver.taskmanager.AttackStanceTaskManager;
  122.  import net.sf.l2j.gameserver.taskmanager.GameTimeTaskManager;
  123. +import net.sf.l2j.gameserver.taskmanager.HeroTaskManager;
  124.  import net.sf.l2j.gameserver.taskmanager.ItemsOnGroundTaskManager;
  125.  import net.sf.l2j.gameserver.taskmanager.PvpFlagTaskManager;
  126.  import net.sf.l2j.gameserver.taskmanager.ShadowItemTaskManager;
  127. @@ -4267,6 +4268,7 @@
  128.         PvpFlagTaskManager.getInstance().remove(this);
  129.         GameTimeTaskManager.getInstance().remove(this);
  130.         ShadowItemTaskManager.getInstance().remove(this);
  131. +       HeroTaskManager.getInstance().remove(this);
  132.     }
  133.    
  134.     /**
  135. @@ -8366,6 +8368,12 @@
  136.         if (isCursedWeaponEquipped())
  137.             CursedWeaponsManager.getInstance().getCursedWeapon(getCursedWeaponEquippedId()).cursedOnLogin();
  138.        
  139. +       if (getMemos().getLong("heroTime", 0) > 0)
  140. +       {
  141. +           setHero(true);
  142. +           HeroTaskManager.getInstance().add(this);
  143. +       }
  144. +      
  145.         // Add to the GameTimeTask to keep inform about activity time.
  146.         GameTimeTaskManager.getInstance().add(this);
  147.        
  148. Index: java/net/sf/l2j/gameserver/handler/itemhandlers/HeroItem.java
  149. ===================================================================
  150. --- java/net/sf/l2j/gameserver/handler/itemhandlers/HeroItem.java   (nonexistent)
  151. +++ java/net/sf/l2j/gameserver/handler/itemhandlers/HeroItem.java   (working copy)
  152. @@ -0,0 +1,61 @@
  153. +/*
  154. + * This program is free software: you can redistribute it and/or modify it under
  155. + * the terms of the GNU General Public License as published by the Free Software
  156. + * Foundation, either version 3 of the License, or (at your option) any later
  157. + * version.
  158. + *
  159. + * This program is distributed in the hope that it will be useful, but WITHOUT
  160. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  161. + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  162. + * details.
  163. + *
  164. + * You should have received a copy of the GNU General Public License along with
  165. + * this program. If not, see <http://www.gnu.org/licenses/>.
  166. + */
  167. +package net.sf.l2j.gameserver.handler.itemhandlers;
  168. +
  169. +import java.util.concurrent.TimeUnit;
  170. +
  171. +import net.sf.l2j.gameserver.handler.IItemHandler;
  172. +import net.sf.l2j.gameserver.model.actor.L2Playable;
  173. +import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  174. +import net.sf.l2j.gameserver.model.item.instance.ItemInstance;
  175. +import net.sf.l2j.gameserver.network.clientpackets.Say2;
  176. +import net.sf.l2j.gameserver.network.serverpackets.CreatureSay;
  177. +import net.sf.l2j.gameserver.network.serverpackets.SocialAction;
  178. +import net.sf.l2j.gameserver.taskmanager.HeroTaskManager;
  179. +
  180. +public class HeroItem implements IItemHandler
  181. +{
  182. +   @Override
  183. +   public void useItem(L2Playable playable, ItemInstance item, boolean forceUse)
  184. +   {
  185. +       if (!(playable instanceof L2PcInstance))
  186. +           return;
  187. +      
  188. +       L2PcInstance activeChar = (L2PcInstance) playable;
  189. +      
  190. +       long remainingTime = activeChar.getMemos().getLong("heroTime", 0);
  191. +       int days = 7;
  192. +      
  193. +       if (remainingTime > 0)
  194. +       {
  195. +           activeChar.getMemos().set("heroTime", remainingTime + TimeUnit.DAYS.toMillis(days));
  196. +           activeChar.sendPacket(new CreatureSay(0, Say2.HERO_VOICE, "System", "Dear player, your hero status has been extended by " + days + " day(s)."));
  197. +       }
  198. +       else
  199. +       {
  200. +           activeChar.setHero(true);
  201. +           if (activeChar.getInventory().getItemByItemId(6842) == null)
  202. +               activeChar.addItem("circlet", 6842, 1, activeChar, true);
  203. +          
  204. +           activeChar.getMemos().set("heroTime", System.currentTimeMillis() + TimeUnit.DAYS.toMillis(days));
  205. +           activeChar.sendPacket(new CreatureSay(0, Say2.HERO_VOICE, "System", "Dear player, you are now a hero, congratulations."));
  206. +           activeChar.broadcastUserInfo();
  207. +       }
  208. +      
  209. +       activeChar.destroyItem("Consume", item.getObjectId(), 1, null, true);
  210. +       activeChar.broadcastPacket(new SocialAction(activeChar, 16));
  211. +       HeroTaskManager.getInstance().add(activeChar);
  212. +   }
  213. +}
  214. \ No newline at end of file
  215. #P aCis_datapack
  216. Index: data/xml/items/9200-9299.xml
  217. ===================================================================
  218. --- data/xml/items/9200-9299.xml    (revision 590)
  219. +++ data/xml/items/9200-9299.xml    (working copy)
  220. @@ -102,4 +102,12 @@
  221.         <set name="is_dropable" val="false" />
  222.         <set name="is_sellable" val="false" />
  223.     </item>
  224. +   <item id="9209" type="EtcItem" name="Hero Item">
  225. +       <set name="material" val="PAPER" />
  226. +       <set name="is_tradable" val="true" />
  227. +       <set name="is_dropable" val="false" />
  228. +       <set name="is_sellable" val="false" />
  229. +       <set name="is_depositable" val="false" />
  230. +       <set name="handler" val="HeroItem" />
  231. +   </item>
  232.  </list>
  233. \ No newline at end of file
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement