eventmodRabbits.java 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  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.eventmodRabbits;
  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.datatables.SkillTable;
  23. import com.l2jserver.gameserver.model.L2Object;
  24. import com.l2jserver.gameserver.model.actor.L2Npc;
  25. import com.l2jserver.gameserver.model.actor.instance.L2EventChestInstance;
  26. import com.l2jserver.gameserver.model.actor.instance.L2EventMonsterInstance;
  27. import com.l2jserver.gameserver.model.actor.instance.L2MonsterInstance;
  28. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  29. import com.l2jserver.gameserver.model.quest.Event;
  30. import com.l2jserver.gameserver.model.quest.QuestState;
  31. import com.l2jserver.gameserver.model.skills.L2Skill;
  32. import com.l2jserver.gameserver.util.Util;
  33. public class eventmodRabbits extends Event
  34. {
  35. // Event NPC's list
  36. private List<L2Npc> _npclist;
  37. // Event Task
  38. ScheduledFuture<?> _eventTask = null;
  39. // Event time
  40. public static final int _event_time = 10;
  41. // Event state
  42. private static boolean _isactive = false;
  43. // Current Chest count
  44. private static int _chest_count = 0;
  45. // How much Chests
  46. private static final int _option_howmuch = 100;
  47. // NPc's
  48. public static final int _npc_snow = 900101;
  49. public static final int _npc_chest = 900102;
  50. // Skills
  51. public static final int _skill_tornado = 630;
  52. public static final int _skill_magic_eye = 629;
  53. /**
  54. * Drop data:<br>
  55. * Higher the chance harder the item.<br>
  56. * ItemId, chance in percent, min amount, max amount
  57. */
  58. // @formatter:off
  59. private static final int[][] DROPLIST =
  60. {
  61. { 1540, 80, 10, 15 }, // Quick Healing Potion
  62. { 1538, 60, 5, 10 }, // Blessed Scroll of Escape
  63. { 3936, 40, 5, 10 }, // Blessed Scroll of Ressurection
  64. { 6387, 25, 5, 10 }, // Blessed Scroll of Ressurection Pets
  65. { 22025, 15, 5, 10 }, // Powerful Healing Potion
  66. { 6622, 10, 1, 1 }, // Giant's Codex
  67. { 20034, 5, 1, 1 }, // Revita Pop
  68. { 20004, 1, 1, 1 }, // Energy Ginseng
  69. { 20004, 0, 1, 1 } // Energy Ginseng
  70. };
  71. // @formatter:on
  72. public static void main(String[] args)
  73. {
  74. new eventmodRabbits(-1, "eventmodRabbits", "mods");
  75. }
  76. public eventmodRabbits(int questId, String name, String descr)
  77. {
  78. super(questId, name, descr);
  79. addStartNpc(_npc_snow);
  80. addFirstTalkId(_npc_snow);
  81. addTalkId(_npc_snow);
  82. addFirstTalkId(_npc_chest);
  83. addSkillSeeId(_npc_chest);
  84. addSpawnId(_npc_chest);
  85. addAttackId(_npc_chest);
  86. }
  87. @Override
  88. public String onSpawn(L2Npc npc)
  89. {
  90. ((L2EventMonsterInstance) npc).eventSetDropOnGround(true);
  91. ((L2EventMonsterInstance) npc).eventSetBlockOffensiveSkills(true);
  92. npc.setIsImmobilized(true);
  93. npc.disableCoreAI(true);
  94. return super.onSpawn(npc);
  95. }
  96. @Override
  97. public boolean eventStart()
  98. {
  99. // Don't start event if its active
  100. if (_isactive)
  101. {
  102. return false;
  103. }
  104. // Check Custom Table - we use custom NPC's
  105. if (!Config.CUSTOM_NPC_TABLE)
  106. {
  107. return false;
  108. }
  109. // Initialize list
  110. _npclist = new FastList<L2Npc>();
  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. private 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 Npc's
  160. if (!_npclist.isEmpty())
  161. {
  162. for (L2Npc _npc : _npclist)
  163. {
  164. if (_npc != null)
  165. {
  166. _npc.deleteMe();
  167. }
  168. }
  169. }
  170. _npclist.clear();
  171. // Announce event end
  172. Announcements.getInstance().announceToAll("Rabbit Event finished");
  173. return true;
  174. }
  175. @Override
  176. public String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
  177. {
  178. String htmltext = event;
  179. if (event.equalsIgnoreCase("transform"))
  180. {
  181. if (player.isTransformed() || player.isInStance())
  182. {
  183. player.untransform();
  184. }
  185. SkillTable.getInstance().getInfo(2428, 1).getEffects(npc, player);
  186. return null;
  187. }
  188. return htmltext;
  189. }
  190. @Override
  191. public String onFirstTalk(L2Npc npc, L2PcInstance player)
  192. {
  193. QuestState st = player.getQuestState(getName());
  194. if (st == null)
  195. {
  196. st = newQuestState(player);
  197. }
  198. return npc.getNpcId() + ".htm";
  199. }
  200. @Override
  201. public String onSkillSee(L2Npc npc, L2PcInstance caster, L2Skill skill, L2Object[] targets, boolean isPet)
  202. {
  203. if (Util.contains(targets, npc))
  204. {
  205. if (skill.getId() == _skill_tornado)
  206. {
  207. dropItem(npc, caster, DROPLIST);
  208. npc.deleteMe();
  209. _chest_count--;
  210. if (_chest_count <= 0)
  211. {
  212. Announcements.getInstance().announceToAll("No more chests...");
  213. eventStop();
  214. }
  215. }
  216. else if (skill.getId() == _skill_magic_eye)
  217. {
  218. if (npc instanceof L2EventChestInstance)
  219. {
  220. ((L2EventChestInstance) npc).trigger();
  221. }
  222. }
  223. }
  224. return super.onSkillSee(npc, caster, skill, targets, isPet);
  225. }
  226. @Override
  227. public String onAttack(L2Npc npc, L2PcInstance attacker, int damage, boolean isPet, L2Skill skill)
  228. {
  229. // Some retards go to event and disturb it by breaking chests
  230. // So... Apply raid curse if player don't use skill on chest but attack it
  231. if (_isactive && (npc.getNpcId() == _npc_chest))
  232. {
  233. SkillTable.getInstance().getInfo(4515, 1).getEffects(npc, attacker);
  234. }
  235. return super.onAttack(npc, attacker, damage, isPet);
  236. }
  237. private static final void dropItem(L2Npc mob, L2PcInstance player, int[][] droplist)
  238. {
  239. final int chance = getRandom(100);
  240. for (int[] drop : droplist)
  241. {
  242. if (chance > drop[1])
  243. {
  244. ((L2MonsterInstance) mob).dropItem(player, drop[0], getRandom(drop[2], drop[3]));
  245. return;
  246. }
  247. }
  248. }
  249. private L2Npc recordSpawn(int npcId, int x, int y, int z, int heading, boolean randomOffSet, long despawnDelay)
  250. {
  251. L2Npc _tmp = addSpawn(npcId, x, y, z, heading, randomOffSet, despawnDelay);
  252. if (_tmp != null)
  253. {
  254. _npclist.add(_tmp);
  255. }
  256. return _tmp;
  257. }
  258. @Override
  259. public boolean eventBypass(L2PcInstance activeChar, String bypass)
  260. {
  261. return false;
  262. }
  263. }