eventmodElpies.java 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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. /**
  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. public static void main(String[] args)
  88. {
  89. new eventmodElpies(-1, "eventmodElpies", "mods");
  90. }
  91. public eventmodElpies(int questId, String name, String descr)
  92. {
  93. super(questId, name, descr);
  94. addSpawnId(_elpy);
  95. addKillId(_elpy);
  96. }
  97. @Override
  98. public String onSpawn(L2Npc npc)
  99. {
  100. ((L2EventMonsterInstance)npc).eventSetDropOnGround(true);
  101. ((L2EventMonsterInstance)npc).eventSetBlockOffensiveSkills(true);
  102. return super.onSpawn(npc);
  103. }
  104. @Override
  105. public String onKill(L2Npc npc, L2PcInstance killer, boolean isPet)
  106. {
  107. // Drop only if event is active
  108. if(_isactive)
  109. {
  110. dropItem(npc, killer, DROPLIST);
  111. dropItem(npc, killer, DROPLIST_CRYSTALS);
  112. _elpies_count--;
  113. if(_elpies_count <= 0)
  114. {
  115. Announcements.getInstance().announceToAll("No more elpies...");
  116. eventStop();
  117. }
  118. }
  119. return super.onKill(npc, killer, isPet);
  120. }
  121. @Override
  122. public boolean eventStart()
  123. {
  124. // Don't start event if its active
  125. if (_isactive)
  126. return false;
  127. // Check Custom Table - we use custom NPC's
  128. if (!Config.CUSTOM_NPC_TABLE)
  129. return false;
  130. // Initialize list
  131. _npclist = new FastList<L2Npc>();
  132. // Set Event active
  133. _isactive = true;
  134. // Spawn Elpy's
  135. int location = Rnd.get(0, _locations.length-1);
  136. int[] _spawndata = _spawns[location];
  137. _elpies_count = 0;
  138. for(int i=0; i < _option_howmuch; i++)
  139. {
  140. int x = Rnd.get(_spawndata[0], _spawndata[1]);
  141. int y = Rnd.get(_spawndata[2], _spawndata[3]);
  142. recordSpawn(_elpy, x, y, _spawndata[4], 0, true, _event_time*60*1000);
  143. _elpies_count++;
  144. }
  145. // Announce event start
  146. Announcements.getInstance().announceToAll("*Squeak Squeak*");
  147. Announcements.getInstance().announceToAll("Elpy invasion in "+_locations[location]);
  148. Announcements.getInstance().announceToAll("Help us exterminate them!");
  149. Announcements.getInstance().announceToAll("You have "+_event_time+" min...");
  150. // Schedule Event end
  151. _eventTask = ThreadPoolManager.getInstance().scheduleGeneral(new Runnable()
  152. {
  153. @Override
  154. public void run()
  155. {
  156. timeUp();
  157. }
  158. }, _event_time*60*1000);
  159. return true;
  160. }
  161. private void timeUp()
  162. {
  163. Announcements.getInstance().announceToAll("Time up !");
  164. eventStop();
  165. }
  166. @Override
  167. public boolean eventStop()
  168. {
  169. // Don't stop inactive event
  170. if(!_isactive)
  171. return false;
  172. // Set inactive
  173. _isactive = false;
  174. // Cancel task if any
  175. if (_eventTask != null)
  176. {
  177. _eventTask.cancel(true);
  178. _eventTask = null;
  179. }
  180. // Despawn Npc's
  181. if(!_npclist.isEmpty())
  182. {
  183. for (L2Npc _npc : _npclist)
  184. if (_npc != null)
  185. _npc.deleteMe();
  186. }
  187. _npclist.clear();
  188. // Announce event end
  189. Announcements.getInstance().announceToAll("*Squeak Squeak*");
  190. Announcements.getInstance().announceToAll("Elpy's Event finished");
  191. return true;
  192. }
  193. private static final void dropItem(L2Npc mob, L2PcInstance player, int[][] droplist)
  194. {
  195. final int chance = Rnd.get(100);
  196. for (int[] drop : droplist)
  197. {
  198. if (chance > drop[1])
  199. {
  200. ((L2MonsterInstance)mob).dropItem(player, drop[0], Rnd.get(drop[2], drop[3]));
  201. return;
  202. }
  203. }
  204. }
  205. private L2Npc recordSpawn(int npcId, int x, int y, int z, int heading, boolean randomOffSet, long despawnDelay)
  206. {
  207. L2Npc _tmp = addSpawn(npcId, x, y, z, heading, randomOffSet, despawnDelay);
  208. if(_tmp != null)
  209. _npclist.add(_tmp);
  210. return _tmp;
  211. }
  212. @Override
  213. public boolean eventBypass(L2PcInstance activeChar, String bypass)
  214. {
  215. return false;
  216. }
  217. }