eventmodRabbits.java 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. /*
  2. * Copyright (C) 2004-2013 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.eventmodRabbits;
  20. import java.util.List;
  21. import java.util.concurrent.ScheduledFuture;
  22. import javolution.util.FastList;
  23. import com.l2jserver.Config;
  24. import com.l2jserver.gameserver.Announcements;
  25. import com.l2jserver.gameserver.ThreadPoolManager;
  26. import com.l2jserver.gameserver.datatables.SkillTable;
  27. import com.l2jserver.gameserver.model.L2Object;
  28. import com.l2jserver.gameserver.model.actor.L2Npc;
  29. import com.l2jserver.gameserver.model.actor.instance.L2EventChestInstance;
  30. import com.l2jserver.gameserver.model.actor.instance.L2EventMonsterInstance;
  31. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  32. import com.l2jserver.gameserver.model.quest.Event;
  33. import com.l2jserver.gameserver.model.quest.QuestState;
  34. import com.l2jserver.gameserver.model.skills.L2Skill;
  35. import com.l2jserver.gameserver.util.Util;
  36. public class eventmodRabbits extends Event
  37. {
  38. // Event NPC's list
  39. private List<L2Npc> _npclist;
  40. // Event Task
  41. ScheduledFuture<?> _eventTask = null;
  42. // Event time
  43. public static final int _event_time = 10;
  44. // Event state
  45. private static boolean _isactive = false;
  46. // Current Chest count
  47. private static int _chest_count = 0;
  48. // How much Chests
  49. private static final int _option_howmuch = 100;
  50. // NPc's
  51. public static final int _npc_snow = 900101;
  52. public static final int _npc_chest = 900102;
  53. // Skills
  54. public static final int _skill_tornado = 630;
  55. public static final int _skill_magic_eye = 629;
  56. /**
  57. * Drop data:<br>
  58. * Higher the chance harder the item.<br>
  59. * ItemId, chance in percent, min amount, max amount
  60. */
  61. // @formatter:off
  62. private static final int[][] DROPLIST =
  63. {
  64. { 1540, 80, 10, 15 }, // Quick Healing Potion
  65. { 1538, 60, 5, 10 }, // Blessed Scroll of Escape
  66. { 3936, 40, 5, 10 }, // Blessed Scroll of Ressurection
  67. { 6387, 25, 5, 10 }, // Blessed Scroll of Ressurection Pets
  68. { 22025, 15, 5, 10 }, // Powerful Healing Potion
  69. { 6622, 10, 1, 1 }, // Giant's Codex
  70. { 20034, 5, 1, 1 }, // Revita Pop
  71. { 20004, 1, 1, 1 }, // Energy Ginseng
  72. { 20004, 0, 1, 1 } // Energy Ginseng
  73. };
  74. // @formatter:on
  75. public static void main(String[] args)
  76. {
  77. new eventmodRabbits(-1, "eventmodRabbits", "mods");
  78. }
  79. public eventmodRabbits(int questId, String name, String descr)
  80. {
  81. super(questId, name, descr);
  82. addStartNpc(_npc_snow);
  83. addFirstTalkId(_npc_snow);
  84. addTalkId(_npc_snow);
  85. addFirstTalkId(_npc_chest);
  86. addSkillSeeId(_npc_chest);
  87. addSpawnId(_npc_chest);
  88. addAttackId(_npc_chest);
  89. }
  90. @Override
  91. public String onSpawn(L2Npc npc)
  92. {
  93. ((L2EventMonsterInstance) npc).eventSetDropOnGround(true);
  94. ((L2EventMonsterInstance) npc).eventSetBlockOffensiveSkills(true);
  95. npc.setIsImmobilized(true);
  96. npc.disableCoreAI(true);
  97. return super.onSpawn(npc);
  98. }
  99. @Override
  100. public boolean eventStart()
  101. {
  102. // Don't start event if its active
  103. if (_isactive)
  104. {
  105. return false;
  106. }
  107. // Check Custom Table - we use custom NPC's
  108. if (!Config.CUSTOM_NPC_TABLE)
  109. {
  110. _log.info(getName() + ": Event can't be started, because custom npc table is disabled!");
  111. return false;
  112. }
  113. // Initialize list
  114. _npclist = new FastList<>();
  115. // Set Event active
  116. _isactive = true;
  117. // Spawn Manager
  118. recordSpawn(_npc_snow, -59227, -56939, -2039, 64106, false, 0);
  119. // Spawn Chests
  120. for (int i = 0; i < _option_howmuch; i++)
  121. {
  122. int x = getRandom(-60653, -58772);
  123. int y = getRandom(-55830, -57718);
  124. recordSpawn(_npc_chest, x, y, -2030, 0, true, _event_time * 60 * 1000);
  125. _chest_count++;
  126. }
  127. // Announce event start
  128. Announcements.getInstance().announceToAll("Rabbit Event : Chests spawned!");
  129. Announcements.getInstance().announceToAll("Go to Fantasy Isle and grab some rewards!");
  130. Announcements.getInstance().announceToAll("You have " + _event_time + " min - after that time all chests will disappear...");
  131. // Schedule Event end
  132. _eventTask = ThreadPoolManager.getInstance().scheduleGeneral(new Runnable()
  133. {
  134. @Override
  135. public void run()
  136. {
  137. timeUp();
  138. }
  139. }, _event_time * 60 * 1000);
  140. return true;
  141. }
  142. protected void timeUp()
  143. {
  144. Announcements.getInstance().announceToAll("Time up !");
  145. eventStop();
  146. }
  147. @Override
  148. public boolean eventStop()
  149. {
  150. // Don't stop inactive event
  151. if (!_isactive)
  152. {
  153. return false;
  154. }
  155. // Set inactive
  156. _isactive = false;
  157. // Cancel task if any
  158. if (_eventTask != null)
  159. {
  160. _eventTask.cancel(true);
  161. _eventTask = null;
  162. }
  163. // Despawn Npc's
  164. if (!_npclist.isEmpty())
  165. {
  166. for (L2Npc _npc : _npclist)
  167. {
  168. if (_npc != null)
  169. {
  170. _npc.deleteMe();
  171. }
  172. }
  173. }
  174. _npclist.clear();
  175. // Announce event end
  176. Announcements.getInstance().announceToAll("Rabbit Event finished");
  177. return true;
  178. }
  179. @Override
  180. public String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
  181. {
  182. String htmltext = event;
  183. if (event.equalsIgnoreCase("transform"))
  184. {
  185. if (player.isTransformed() || player.isInStance())
  186. {
  187. player.untransform();
  188. }
  189. SkillTable.getInstance().getInfo(2428, 1).applyEffects(npc, player);
  190. return null;
  191. }
  192. return htmltext;
  193. }
  194. @Override
  195. public String onFirstTalk(L2Npc npc, L2PcInstance player)
  196. {
  197. QuestState st = player.getQuestState(getName());
  198. if (st == null)
  199. {
  200. st = newQuestState(player);
  201. }
  202. return npc.getId() + ".htm";
  203. }
  204. @Override
  205. public String onSkillSee(L2Npc npc, L2PcInstance caster, L2Skill skill, L2Object[] targets, boolean isSummon)
  206. {
  207. if (Util.contains(targets, npc))
  208. {
  209. if (skill.getId() == _skill_tornado)
  210. {
  211. dropItem(npc, caster, DROPLIST);
  212. npc.deleteMe();
  213. _chest_count--;
  214. if (_chest_count <= 0)
  215. {
  216. Announcements.getInstance().announceToAll("No more chests...");
  217. eventStop();
  218. }
  219. }
  220. else if (skill.getId() == _skill_magic_eye)
  221. {
  222. if (npc instanceof L2EventChestInstance)
  223. {
  224. ((L2EventChestInstance) npc).trigger();
  225. }
  226. }
  227. }
  228. return super.onSkillSee(npc, caster, skill, targets, isSummon);
  229. }
  230. @Override
  231. public String onAttack(L2Npc npc, L2PcInstance attacker, int damage, boolean isSummon, L2Skill skill)
  232. {
  233. // Some retards go to event and disturb it by breaking chests
  234. // So... Apply raid curse if player don't use skill on chest but attack it
  235. if (_isactive && (npc.getId() == _npc_chest))
  236. {
  237. SkillTable.getInstance().getInfo(4515, 1).applyEffects(npc, attacker);
  238. }
  239. return super.onAttack(npc, attacker, damage, isSummon);
  240. }
  241. private static final void dropItem(L2Npc mob, L2PcInstance player, int[][] droplist)
  242. {
  243. final int chance = getRandom(100);
  244. for (int[] drop : droplist)
  245. {
  246. if (chance > drop[1])
  247. {
  248. mob.dropItem(player, drop[0], getRandom(drop[2], drop[3]));
  249. return;
  250. }
  251. }
  252. }
  253. private L2Npc recordSpawn(int npcId, int x, int y, int z, int heading, boolean randomOffSet, long despawnDelay)
  254. {
  255. L2Npc _tmp = addSpawn(npcId, x, y, z, heading, randomOffSet, despawnDelay);
  256. if (_tmp != null)
  257. {
  258. _npclist.add(_tmp);
  259. }
  260. return _tmp;
  261. }
  262. @Override
  263. public boolean eventBypass(L2PcInstance activeChar, String bypass)
  264. {
  265. return false;
  266. }
  267. }