eventmodRabbits.java 7.8 KB

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