Elpies.java 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. /*
  2. * Copyright (C) 2004-2015 L2J DataPack
  3. *
  4. * This file is part of L2J DataPack.
  5. *
  6. * L2J DataPack is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * L2J DataPack is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package custom.events.Elpies;
  20. import java.util.Set;
  21. import java.util.concurrent.ConcurrentHashMap;
  22. import java.util.concurrent.ScheduledFuture;
  23. import com.l2jserver.Config;
  24. import com.l2jserver.gameserver.ThreadPoolManager;
  25. import com.l2jserver.gameserver.model.actor.L2Npc;
  26. import com.l2jserver.gameserver.model.actor.instance.L2EventMonsterInstance;
  27. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  28. import com.l2jserver.gameserver.model.quest.Event;
  29. import com.l2jserver.gameserver.util.Broadcast;
  30. public final class Elpies extends Event
  31. {
  32. // NPC
  33. private static final int ELPY = 900100;
  34. // Amount of Elpies to spawn when the event starts
  35. private static final int ELPY_AMOUNT = 100;
  36. // Event duration in minutes
  37. private static final int EVENT_DURATION_MINUTES = 2;
  38. // @formatter:off
  39. private static final int[][] DROPLIST_CONSUMABLES =
  40. {
  41. // itemId, chance, min amount, max amount
  42. { 1540, 80, 10, 15 }, // Quick Healing Potion
  43. { 1538, 60, 5, 10 }, // Blessed Scroll of Escape
  44. { 3936, 40, 5, 10 }, // Blessed Scroll of Ressurection
  45. { 6387, 25, 5, 10 }, // Blessed Scroll of Ressurection Pets
  46. { 22025, 15, 5, 10 }, // Powerful Healing Potion
  47. { 6622, 10, 1, 1 }, // Giant's Codex
  48. { 20034, 5, 1, 1 }, // Revita Pop
  49. { 20004, 1, 1, 1 }, // Energy Ginseng
  50. { 20004, 0, 1, 1 } // Energy Ginseng
  51. };
  52. private static final int[][] DROPLIST_CRYSTALS =
  53. {
  54. { 1458, 80, 50, 100 }, // Crystal D-Grade
  55. { 1459, 60, 40, 80 }, // Crystal C-Grade
  56. { 1460, 40, 30, 60 }, // Crystal B-Grade
  57. { 1461, 20, 20, 30 }, // Crystal A-Grade
  58. { 1462, 0, 10, 20 } // Crystal S-Grade
  59. };
  60. // @formatter:on
  61. // Non-final variables
  62. private static boolean EVENT_ACTIVE = false;
  63. private ScheduledFuture<?> _eventTask = null;
  64. private final Set<L2Npc> _elpies = ConcurrentHashMap.newKeySet(ELPY_AMOUNT);
  65. private Elpies()
  66. {
  67. super(Elpies.class.getSimpleName(), "custom/events");
  68. addSpawnId(ELPY);
  69. addKillId(ELPY);
  70. }
  71. @Override
  72. public boolean eventBypass(L2PcInstance activeChar, String bypass)
  73. {
  74. return false;
  75. }
  76. @Override
  77. public boolean eventStart(L2PcInstance eventMaker)
  78. {
  79. if (EVENT_ACTIVE)
  80. {
  81. return false;
  82. }
  83. // Check Custom Table - we use custom NPC's
  84. if (!Config.CUSTOM_NPC_DATA)
  85. {
  86. _log.info(getName() + ": Event can't be started because custom NPC table is disabled!");
  87. eventMaker.sendMessage("Event " + getName() + " can't be started because custom NPC table is disabled!");
  88. return false;
  89. }
  90. EVENT_ACTIVE = true;
  91. EventLocation[] locations = EventLocation.values();
  92. EventLocation randomLoc = locations[getRandom(locations.length)];
  93. long despawnDelay = EVENT_DURATION_MINUTES * 60000;
  94. for (int i = 0; i < ELPY_AMOUNT; i++)
  95. {
  96. _elpies.add(addSpawn(ELPY, randomLoc.getRandomX(), randomLoc.getRandomY(), randomLoc.getZ(), 0, true, despawnDelay));
  97. }
  98. Broadcast.toAllOnlinePlayers("*Squeak Squeak*");
  99. Broadcast.toAllOnlinePlayers("Elpy invasion in " + randomLoc.getName());
  100. Broadcast.toAllOnlinePlayers("Help us exterminate them!");
  101. Broadcast.toAllOnlinePlayers("You have " + EVENT_DURATION_MINUTES + " minutes!");
  102. _eventTask = ThreadPoolManager.getInstance().scheduleGeneral(() ->
  103. {
  104. Broadcast.toAllOnlinePlayers("Time is up!");
  105. eventStop();
  106. }, despawnDelay);
  107. return true;
  108. }
  109. @Override
  110. public boolean eventStop()
  111. {
  112. if (!EVENT_ACTIVE)
  113. {
  114. return false;
  115. }
  116. EVENT_ACTIVE = false;
  117. if (_eventTask != null)
  118. {
  119. _eventTask.cancel(true);
  120. _eventTask = null;
  121. }
  122. for (L2Npc npc : _elpies)
  123. {
  124. npc.deleteMe();
  125. }
  126. _elpies.clear();
  127. Broadcast.toAllOnlinePlayers("*Squeak Squeak*");
  128. Broadcast.toAllOnlinePlayers("Elpy Event finished!");
  129. return true;
  130. }
  131. @Override
  132. public String onKill(L2Npc npc, L2PcInstance killer, boolean isSummon)
  133. {
  134. if (EVENT_ACTIVE)
  135. {
  136. _elpies.remove(npc);
  137. dropItem(npc, killer, DROPLIST_CONSUMABLES);
  138. dropItem(npc, killer, DROPLIST_CRYSTALS);
  139. if (_elpies.isEmpty())
  140. {
  141. Broadcast.toAllOnlinePlayers("All elpies have been killed!");
  142. eventStop();
  143. }
  144. }
  145. return super.onKill(npc, killer, isSummon);
  146. }
  147. @Override
  148. public String onSpawn(L2Npc npc)
  149. {
  150. ((L2EventMonsterInstance) npc).eventSetDropOnGround(true);
  151. ((L2EventMonsterInstance) npc).eventSetBlockOffensiveSkills(true);
  152. return super.onSpawn(npc);
  153. }
  154. private static enum EventLocation
  155. {
  156. ADEN("Aden", 146558, 148341, 26622, 28560, -2200),
  157. DION("Dion", 18564, 19200, 144377, 145782, -3081),
  158. GLUDIN("Gludin", -84040, -81420, 150257, 151175, -3125),
  159. HV("Hunters Village", 116094, 117141, 75776, 77072, -2700),
  160. OREN("Oren", 82048, 82940, 53240, 54126, -1490);
  161. private final String _name;
  162. private final int _minX;
  163. private final int _maxX;
  164. private final int _minY;
  165. private final int _maxY;
  166. private final int _z;
  167. EventLocation(String name, int minX, int maxX, int minY, int maxY, int z)
  168. {
  169. _name = name;
  170. _minX = minX;
  171. _maxX = maxX;
  172. _minY = minY;
  173. _maxY = maxY;
  174. _z = z;
  175. }
  176. public String getName()
  177. {
  178. return _name;
  179. }
  180. public int getRandomX()
  181. {
  182. return getRandom(_minX, _maxX);
  183. }
  184. public int getRandomY()
  185. {
  186. return getRandom(_minY, _maxY);
  187. }
  188. public int getZ()
  189. {
  190. return _z;
  191. }
  192. }
  193. private static final void dropItem(L2Npc mob, L2PcInstance player, int[][] droplist)
  194. {
  195. final int chance = getRandom(100);
  196. for (int[] drop : droplist)
  197. {
  198. if (chance >= drop[1])
  199. {
  200. mob.dropItem(player, drop[0], getRandom(drop[2], drop[3]));
  201. break;
  202. }
  203. }
  204. }
  205. public static void main(String[] args)
  206. {
  207. new Elpies();
  208. }
  209. }