Elpies.java 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. /*
  2. * Copyright (C) 2004-2014 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.concurrent.ScheduledFuture;
  21. import com.l2jserver.Config;
  22. import com.l2jserver.gameserver.ThreadPoolManager;
  23. import com.l2jserver.gameserver.datatables.SpawnTable;
  24. import com.l2jserver.gameserver.model.L2Spawn;
  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 static int CURRENT_ELPY_COUNT = 0;
  64. private ScheduledFuture<?> _eventTask = null;
  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. CURRENT_ELPY_COUNT = 0;
  94. long despawnDelay = EVENT_DURATION_MINUTES * 60000;
  95. for (int i = 0; i < ELPY_AMOUNT; i++)
  96. {
  97. addSpawn(ELPY, randomLoc.getRandomX(), randomLoc.getRandomY(), randomLoc.getZ(), 0, true, despawnDelay);
  98. CURRENT_ELPY_COUNT++;
  99. }
  100. Broadcast.toAllOnlinePlayers("*Squeak Squeak*");
  101. Broadcast.toAllOnlinePlayers("Elpy invasion in " + randomLoc.getName());
  102. Broadcast.toAllOnlinePlayers("Help us exterminate them!");
  103. Broadcast.toAllOnlinePlayers("You have " + EVENT_DURATION_MINUTES + " minutes!");
  104. _eventTask = ThreadPoolManager.getInstance().scheduleGeneral(() ->
  105. {
  106. Broadcast.toAllOnlinePlayers("Time is up!");
  107. eventStop();
  108. }, despawnDelay);
  109. return true;
  110. }
  111. @Override
  112. public boolean eventStop()
  113. {
  114. if (!EVENT_ACTIVE)
  115. {
  116. return false;
  117. }
  118. EVENT_ACTIVE = false;
  119. if (_eventTask != null)
  120. {
  121. _eventTask.cancel(true);
  122. _eventTask = null;
  123. }
  124. for (L2Spawn spawn : SpawnTable.getInstance().getSpawns(ELPY))
  125. {
  126. L2Npc npc = spawn.getLastSpawn();
  127. if (npc != null)
  128. {
  129. npc.deleteMe();
  130. }
  131. }
  132. Broadcast.toAllOnlinePlayers("*Squeak Squeak*");
  133. Broadcast.toAllOnlinePlayers("Elpy Event finished!");
  134. return true;
  135. }
  136. @Override
  137. public String onKill(L2Npc npc, L2PcInstance killer, boolean isSummon)
  138. {
  139. if (EVENT_ACTIVE)
  140. {
  141. dropItem(npc, killer, DROPLIST_CONSUMABLES);
  142. dropItem(npc, killer, DROPLIST_CRYSTALS);
  143. CURRENT_ELPY_COUNT--;
  144. if (CURRENT_ELPY_COUNT <= 0)
  145. {
  146. Broadcast.toAllOnlinePlayers("All elpies have been killed!");
  147. eventStop();
  148. }
  149. }
  150. return super.onKill(npc, killer, isSummon);
  151. }
  152. @Override
  153. public String onSpawn(L2Npc npc)
  154. {
  155. ((L2EventMonsterInstance) npc).eventSetDropOnGround(true);
  156. ((L2EventMonsterInstance) npc).eventSetBlockOffensiveSkills(true);
  157. return super.onSpawn(npc);
  158. }
  159. private static enum EventLocation
  160. {
  161. ADEN("Aden", 146558, 148341, 26622, 28560, -2200),
  162. DION("Dion", 18564, 19200, 144377, 145782, -3081),
  163. GLUDIN("Gludin", -84040, -81420, 150257, 151175, -3125),
  164. HV("Hunters Village", 116094, 117141, 75776, 77072, -2700),
  165. OREN("Oren", 82048, 82940, 53240, 54126, -1490);
  166. private final String _name;
  167. private final int _minX;
  168. private final int _maxX;
  169. private final int _minY;
  170. private final int _maxY;
  171. private final int _z;
  172. EventLocation(String name, int minX, int maxX, int minY, int maxY, int z)
  173. {
  174. _name = name;
  175. _minX = minX;
  176. _maxX = maxX;
  177. _minY = minY;
  178. _maxY = maxY;
  179. _z = z;
  180. }
  181. public String getName()
  182. {
  183. return _name;
  184. }
  185. public int getRandomX()
  186. {
  187. return getRandom(_minX, _maxX);
  188. }
  189. public int getRandomY()
  190. {
  191. return getRandom(_minY, _maxY);
  192. }
  193. public int getZ()
  194. {
  195. return _z;
  196. }
  197. }
  198. private static final void dropItem(L2Npc mob, L2PcInstance player, int[][] droplist)
  199. {
  200. final int chance = getRandom(100);
  201. for (int[] drop : droplist)
  202. {
  203. if (chance >= drop[1])
  204. {
  205. mob.dropItem(player, drop[0], getRandom(drop[2], drop[3]));
  206. break;
  207. }
  208. }
  209. }
  210. public static void main(String[] args)
  211. {
  212. new Elpies();
  213. }
  214. }