eventmodRabbits.java 8.1 KB

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