eventmodElpies.java 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  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. import com.l2jserver.util.Rnd;
  28. public class eventmodElpies extends Event
  29. {
  30. // Event NPC's list
  31. private List<L2Npc> _npclist;
  32. // Event Task
  33. ScheduledFuture<?> _eventTask = null;
  34. // Event time
  35. public static final int _event_time = 2;
  36. // Event state
  37. private static boolean _isactive = false;
  38. // EVENT VARIABLES
  39. // NPc's
  40. private static final int _elpy = 900100;
  41. // How much Elpy's
  42. private static final int _option_howmuch = 100;
  43. // Elpy's count
  44. private static int _elpies_count = 0;
  45. private static final String[] _locations =
  46. {
  47. "Aden",
  48. "Gludin",
  49. "Hunters Village",
  50. "Dion",
  51. "Oren"
  52. };
  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. // Drop data
  63. private static final int[][] DROPLIST =
  64. {
  65. { 1540, 80, 10, 15 }, // Quick Healing Potion
  66. { 1538, 60, 5, 10 }, // Blessed Scroll of Escape
  67. { 3936, 40, 5, 10 }, // Blessed Scroll of Ressurection
  68. { 6387, 25, 5, 10 }, // Blessed Scroll of Ressurection Pets
  69. { 22025, 15, 5, 10 }, // Powerful Healing Potion
  70. { 6622, 10, 1, 1 }, // Giant's Codex
  71. { 20034, 5, 1, 1 }, // Revita Pop
  72. { 20004, 1, 1, 1 }, // Energy Ginseng
  73. { 20004, 0, 1, 1 } // Energy Ginseng
  74. };
  75. private static final int[][] DROPLIST_CRYSTALS =
  76. {
  77. { 1458, 80, 50, 100 }, // Crystal D-Grade
  78. { 1459, 60, 40, 80 }, // Crystal C-Grade
  79. { 1460, 40, 30, 60 }, // Crystal B-Grade
  80. { 1461, 20, 20, 30 }, // Crystal A-Grade
  81. { 1462, 0, 10, 20 }, // Crystal S-Grade
  82. };
  83. public static void main(String[] args)
  84. {
  85. new eventmodElpies(-1, "eventmodElpies", "mods");
  86. }
  87. public eventmodElpies(int questId, String name, String descr)
  88. {
  89. super(questId, name, descr);
  90. addSpawnId(_elpy);
  91. addKillId(_elpy);
  92. }
  93. @Override
  94. public String onSpawn(L2Npc npc)
  95. {
  96. ((L2EventMonsterInstance)npc).eventSetDropOnGround(true);
  97. ((L2EventMonsterInstance)npc).eventSetBlockOffensiveSkills(true);
  98. return super.onSpawn(npc);
  99. }
  100. @Override
  101. public String onKill(L2Npc npc, L2PcInstance killer, boolean isPet)
  102. {
  103. // Drop only if event is active
  104. if(_isactive)
  105. {
  106. dropItem(npc, killer, DROPLIST);
  107. dropItem(npc, killer, DROPLIST_CRYSTALS);
  108. _elpies_count--;
  109. if(_elpies_count <= 0)
  110. {
  111. Announcements.getInstance().announceToAll("No more elpies...");
  112. eventStop();
  113. }
  114. }
  115. return super.onKill(npc, killer, isPet);
  116. }
  117. @Override
  118. public boolean eventStart()
  119. {
  120. // Don't start event if its active
  121. if (_isactive)
  122. return false;
  123. // Check Custom Table - we use custom NPC's
  124. if (!Config.CUSTOM_NPC_TABLE)
  125. return false;
  126. // Initialize list
  127. _npclist = new FastList<L2Npc>();
  128. // Set Event active
  129. _isactive = true;
  130. // Spawn Elpy's
  131. int location = Rnd.get(0, _locations.length-1);
  132. int[] _spawndata = _spawns[location];
  133. _elpies_count = 0;
  134. for(int i=0; i < _option_howmuch; i++)
  135. {
  136. int x = Rnd.get(_spawndata[0], _spawndata[1]);
  137. int y = Rnd.get(_spawndata[2], _spawndata[3]);
  138. recordSpawn(_elpy, x, y, _spawndata[4], 0, true, _event_time*60*1000);
  139. _elpies_count++;
  140. }
  141. // Announce event start
  142. Announcements.getInstance().announceToAll("*Squeak Squeak*");
  143. Announcements.getInstance().announceToAll("Elpy invasion in "+_locations[location]);
  144. Announcements.getInstance().announceToAll("Help us exterminate them!");
  145. Announcements.getInstance().announceToAll("You have "+_event_time+" min...");
  146. // Schedule Event end
  147. _eventTask = ThreadPoolManager.getInstance().scheduleGeneral(new Runnable()
  148. {
  149. public void run()
  150. {
  151. timeUp();
  152. }
  153. }, _event_time*60*1000);
  154. return true;
  155. }
  156. private void timeUp()
  157. {
  158. Announcements.getInstance().announceToAll("Time up !");
  159. eventStop();
  160. }
  161. @Override
  162. public boolean eventStop()
  163. {
  164. // Don't stop inactive event
  165. if(!_isactive)
  166. return false;
  167. // Set inactive
  168. _isactive = false;
  169. // Cancel task if any
  170. if (_eventTask != null)
  171. {
  172. _eventTask.cancel(true);
  173. _eventTask = null;
  174. }
  175. // Despawn Npc's
  176. if(!_npclist.isEmpty())
  177. {
  178. for (L2Npc _npc : _npclist)
  179. if (_npc != null)
  180. _npc.deleteMe();
  181. }
  182. _npclist.clear();
  183. // Announce event end
  184. Announcements.getInstance().announceToAll("*Squeak Squeak*");
  185. Announcements.getInstance().announceToAll("Elpy's Event finished");
  186. return true;
  187. }
  188. private static final void dropItem(L2Npc mob, L2PcInstance player, int[][] droplist)
  189. {
  190. final int chance = Rnd.get(100);
  191. for (int i = 0; i < droplist.length; i++)
  192. {
  193. int[] drop = droplist[i];
  194. if (chance > drop[1])
  195. {
  196. ((L2MonsterInstance)mob).dropItem(player, drop[0], Rnd.get(drop[2], drop[3]));
  197. return;
  198. }
  199. }
  200. }
  201. private L2Npc recordSpawn(int npcId, int x, int y, int z, int heading, boolean randomOffSet, long despawnDelay)
  202. {
  203. L2Npc _tmp = addSpawn(npcId, x, y, z, heading, randomOffSet, despawnDelay);
  204. if(_tmp != null)
  205. _npclist.add(_tmp);
  206. return _tmp;
  207. }
  208. @Override
  209. public boolean eventBypass(L2PcInstance activeChar, String bypass)
  210. {
  211. return false;
  212. }
  213. }