eventmodRabbits.java 7.9 KB

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