eventmodElpies.java 6.6 KB

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