eventmodElpies.java 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. /*
  2. * This program is free software: you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation, either version 3 of the License, or (at your option) any later
  5. * version.
  6. *
  7. * This program is distributed in the hope that it will be useful, but WITHOUT
  8. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10. * details.
  11. *
  12. * You should have received a copy of the GNU General Public License along with
  13. * this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. package mods.eventmodElpies;
  16. import java.util.List;
  17. import java.util.concurrent.ScheduledFuture;
  18. import javolution.util.FastList;
  19. import com.l2jserver.Config;
  20. import com.l2jserver.gameserver.Announcements;
  21. import com.l2jserver.gameserver.ThreadPoolManager;
  22. import com.l2jserver.gameserver.model.actor.L2Npc;
  23. import com.l2jserver.gameserver.model.actor.instance.L2EventMonsterInstance;
  24. import com.l2jserver.gameserver.model.actor.instance.L2MonsterInstance;
  25. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  26. import com.l2jserver.gameserver.model.quest.Event;
  27. public class eventmodElpies extends Event
  28. {
  29. // Event NPC's list
  30. private List<L2Npc> _npclist;
  31. // Event Task
  32. ScheduledFuture<?> _eventTask = null;
  33. // Event time
  34. public static final int _event_time = 2;
  35. // Event state
  36. private static boolean _isactive = false;
  37. // EVENT VARIABLES
  38. // NPc's
  39. private static final int _elpy = 900100;
  40. // How much Elpy's
  41. private static final int _option_howmuch = 100;
  42. // Elpy's count
  43. private static int _elpies_count = 0;
  44. private static final String[] _locations =
  45. {
  46. "Aden",
  47. "Gludin",
  48. "Hunters Village",
  49. "Dion",
  50. "Oren"
  51. };
  52. // @formatter:off
  53. private static final int[][] _spawns =
  54. {
  55. // minx, maxx, miny, maxy, zspawn
  56. { 146558, 148341, 26622, 28560, -2200 },
  57. { -84040, -81420, 150257, 151175, -3125 },
  58. { 116094, 117141, 75776, 77072, -2700 },
  59. { 18564, 19200, 144377, 145782, -3081 },
  60. { 82048, 82940, 53240, 54126, -1490 }
  61. };
  62. /**
  63. * Drop data:<br>
  64. * Higher the chance harder the item.<br>
  65. * ItemId, chance in percent, min amount, max amount
  66. */
  67. private static final int[][] DROPLIST =
  68. {
  69. { 1540, 80, 10, 15 }, // Quick Healing Potion
  70. { 1538, 60, 5, 10 }, // Blessed Scroll of Escape
  71. { 3936, 40, 5, 10 }, // Blessed Scroll of Ressurection
  72. { 6387, 25, 5, 10 }, // Blessed Scroll of Ressurection Pets
  73. { 22025, 15, 5, 10 }, // Powerful Healing Potion
  74. { 6622, 10, 1, 1 }, // Giant's Codex
  75. { 20034, 5, 1, 1 }, // Revita Pop
  76. { 20004, 1, 1, 1 }, // Energy Ginseng
  77. { 20004, 0, 1, 1 } // Energy Ginseng
  78. };
  79. private static final int[][] DROPLIST_CRYSTALS =
  80. {
  81. { 1458, 80, 50, 100 }, // Crystal D-Grade
  82. { 1459, 60, 40, 80 }, // Crystal C-Grade
  83. { 1460, 40, 30, 60 }, // Crystal B-Grade
  84. { 1461, 20, 20, 30 }, // Crystal A-Grade
  85. { 1462, 0, 10, 20 }, // Crystal S-Grade
  86. };
  87. // @formatter:on
  88. public static void main(String[] args)
  89. {
  90. new eventmodElpies(-1, "eventmodElpies", "mods");
  91. }
  92. public eventmodElpies(int questId, String name, String descr)
  93. {
  94. super(questId, name, descr);
  95. addSpawnId(_elpy);
  96. addKillId(_elpy);
  97. }
  98. @Override
  99. public String onSpawn(L2Npc npc)
  100. {
  101. ((L2EventMonsterInstance) npc).eventSetDropOnGround(true);
  102. ((L2EventMonsterInstance) npc).eventSetBlockOffensiveSkills(true);
  103. return super.onSpawn(npc);
  104. }
  105. @Override
  106. public String onKill(L2Npc npc, L2PcInstance killer, boolean isPet)
  107. {
  108. // Drop only if event is active
  109. if (_isactive)
  110. {
  111. dropItem(npc, killer, DROPLIST);
  112. dropItem(npc, killer, DROPLIST_CRYSTALS);
  113. _elpies_count--;
  114. if (_elpies_count <= 0)
  115. {
  116. Announcements.getInstance().announceToAll("No more elpies...");
  117. eventStop();
  118. }
  119. }
  120. return super.onKill(npc, killer, isPet);
  121. }
  122. @Override
  123. public boolean eventStart()
  124. {
  125. // Don't start event if its active
  126. if (_isactive)
  127. {
  128. return false;
  129. }
  130. // Check Custom Table - we use custom NPC's
  131. if (!Config.CUSTOM_NPC_TABLE)
  132. {
  133. return false;
  134. }
  135. // Initialize list
  136. _npclist = new FastList<L2Npc>();
  137. // Set Event active
  138. _isactive = true;
  139. // Spawn Elpy's
  140. int location = getRandom(0, _locations.length - 1);
  141. int[] _spawndata = _spawns[location];
  142. _elpies_count = 0;
  143. for (int i = 0; i < _option_howmuch; i++)
  144. {
  145. int x = getRandom(_spawndata[0], _spawndata[1]);
  146. int y = getRandom(_spawndata[2], _spawndata[3]);
  147. recordSpawn(_elpy, x, y, _spawndata[4], 0, true, _event_time * 60 * 1000);
  148. _elpies_count++;
  149. }
  150. // Announce event start
  151. Announcements.getInstance().announceToAll("*Squeak Squeak*");
  152. Announcements.getInstance().announceToAll("Elpy invasion in " + _locations[location]);
  153. Announcements.getInstance().announceToAll("Help us exterminate them!");
  154. Announcements.getInstance().announceToAll("You have " + _event_time + " min...");
  155. // Schedule Event end
  156. _eventTask = ThreadPoolManager.getInstance().scheduleGeneral(new Runnable()
  157. {
  158. @Override
  159. public void run()
  160. {
  161. timeUp();
  162. }
  163. }, _event_time * 60 * 1000);
  164. return true;
  165. }
  166. private void timeUp()
  167. {
  168. Announcements.getInstance().announceToAll("Time up !");
  169. eventStop();
  170. }
  171. @Override
  172. public boolean eventStop()
  173. {
  174. // Don't stop inactive event
  175. if (!_isactive)
  176. {
  177. return false;
  178. }
  179. // Set inactive
  180. _isactive = false;
  181. // Cancel task if any
  182. if (_eventTask != null)
  183. {
  184. _eventTask.cancel(true);
  185. _eventTask = null;
  186. }
  187. // Despawn Npc's
  188. if (!_npclist.isEmpty())
  189. {
  190. for (L2Npc _npc : _npclist)
  191. {
  192. if (_npc != null)
  193. {
  194. _npc.deleteMe();
  195. }
  196. }
  197. }
  198. _npclist.clear();
  199. // Announce event end
  200. Announcements.getInstance().announceToAll("*Squeak Squeak*");
  201. Announcements.getInstance().announceToAll("Elpy's Event finished");
  202. return true;
  203. }
  204. private static final void dropItem(L2Npc mob, L2PcInstance player, int[][] droplist)
  205. {
  206. final int chance = getRandom(100);
  207. for (int[] drop : droplist)
  208. {
  209. if (chance > drop[1])
  210. {
  211. ((L2MonsterInstance) mob).dropItem(player, drop[0], getRandom(drop[2], drop[3]));
  212. return;
  213. }
  214. }
  215. }
  216. private L2Npc recordSpawn(int npcId, int x, int y, int z, int heading, boolean randomOffSet, long despawnDelay)
  217. {
  218. L2Npc _tmp = addSpawn(npcId, x, y, z, heading, randomOffSet, despawnDelay);
  219. if (_tmp != null)
  220. {
  221. _npclist.add(_tmp);
  222. }
  223. return _tmp;
  224. }
  225. @Override
  226. public boolean eventBypass(L2PcInstance activeChar, String bypass)
  227. {
  228. return false;
  229. }
  230. }