Quarry.java 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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 hellbound.Quarry;
  20. import com.l2jserver.Config;
  21. import com.l2jserver.gameserver.ThreadPoolManager;
  22. import com.l2jserver.gameserver.ai.CtrlIntention;
  23. import com.l2jserver.gameserver.instancemanager.HellboundManager;
  24. import com.l2jserver.gameserver.instancemanager.ZoneManager;
  25. import com.l2jserver.gameserver.model.actor.L2Attackable;
  26. import com.l2jserver.gameserver.model.actor.L2Character;
  27. import com.l2jserver.gameserver.model.actor.L2Npc;
  28. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  29. import com.l2jserver.gameserver.model.actor.instance.L2QuestGuardInstance;
  30. import com.l2jserver.gameserver.model.quest.Quest;
  31. import com.l2jserver.gameserver.model.zone.L2ZoneType;
  32. import com.l2jserver.gameserver.network.NpcStringId;
  33. import com.l2jserver.gameserver.network.clientpackets.Say2;
  34. import com.l2jserver.gameserver.network.serverpackets.NpcSay;
  35. /**
  36. * @author DS, GKR
  37. */
  38. public class Quarry extends Quest
  39. {
  40. private static final int SLAVE = 32299;
  41. private static final int TRUST = 50;
  42. private static final int ZONE = 40107;
  43. // Id, chance (n from 10000)
  44. protected static final int[][] DROPLIST =
  45. {
  46. {
  47. 9628,
  48. 261
  49. }, // Leonard
  50. {
  51. 9630,
  52. 175
  53. }, // Orichalcum
  54. {
  55. 9629,
  56. 145
  57. }, // Adamantine
  58. {
  59. 1876,
  60. 6667
  61. }, // Mithril ore
  62. {
  63. 1877,
  64. 1333
  65. }, // Adamantine nugget
  66. {
  67. 1874,
  68. 2222
  69. }
  70. // Oriharukon ore
  71. };
  72. @Override
  73. public final String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
  74. {
  75. if (event.equalsIgnoreCase("time_limit"))
  76. {
  77. for (L2ZoneType zone : ZoneManager.getInstance().getZones(npc))
  78. {
  79. if (zone.getId() == 40108)
  80. {
  81. npc.setTarget(null);
  82. npc.getAI().setIntention(CtrlIntention.AI_INTENTION_ACTIVE);
  83. npc.setAutoAttackable(false);
  84. npc.setRHandId(0);
  85. npc.teleToLocation(npc.getSpawn().getLocation());
  86. return null;
  87. }
  88. }
  89. npc.broadcastPacket(new NpcSay(npc.getObjectId(), Say2.NPC_ALL, npc.getId(), NpcStringId.HUN_HUNGRY));
  90. npc.doDie(npc);
  91. return null;
  92. }
  93. else if (event.equalsIgnoreCase("FollowMe"))
  94. {
  95. npc.getAI().setIntention(CtrlIntention.AI_INTENTION_FOLLOW, player);
  96. npc.setTarget(player);
  97. npc.setAutoAttackable(true);
  98. npc.setRHandId(9136);
  99. npc.setWalking();
  100. if (getQuestTimer("time_limit", npc, null) == null)
  101. {
  102. startQuestTimer("time_limit", 900000, npc, null); // 15 min limit for save
  103. }
  104. return "32299-02.htm";
  105. }
  106. return event;
  107. }
  108. @Override
  109. public final String onSpawn(L2Npc npc)
  110. {
  111. npc.setAutoAttackable(false);
  112. if (npc instanceof L2QuestGuardInstance)
  113. {
  114. ((L2QuestGuardInstance) npc).setPassive(true);
  115. }
  116. return super.onSpawn(npc);
  117. }
  118. @Override
  119. public final String onFirstTalk(L2Npc npc, L2PcInstance player)
  120. {
  121. if (HellboundManager.getInstance().getLevel() != 5)
  122. {
  123. return "32299.htm";
  124. }
  125. if (player.getQuestState(getName()) == null)
  126. {
  127. newQuestState(player);
  128. }
  129. return "32299-01.htm";
  130. }
  131. // Let's manage kill points in Engine
  132. @Override
  133. public final String onKill(L2Npc npc, L2PcInstance killer, boolean isSummon)
  134. {
  135. npc.setAutoAttackable(false);
  136. return super.onKill(npc, killer, isSummon);
  137. }
  138. @Override
  139. public final String onEnterZone(L2Character character, L2ZoneType zone)
  140. {
  141. if (character instanceof L2Attackable)
  142. {
  143. final L2Attackable npc = (L2Attackable) character;
  144. if (npc.getId() == SLAVE)
  145. {
  146. if (!npc.isDead() && !npc.isDecayed() && (npc.getAI().getIntention() == CtrlIntention.AI_INTENTION_FOLLOW))
  147. {
  148. if (HellboundManager.getInstance().getLevel() == 5)
  149. {
  150. ThreadPoolManager.getInstance().scheduleGeneral(new Decay(npc), 1000);
  151. try
  152. {
  153. npc.broadcastPacket(new NpcSay(npc.getObjectId(), Say2.NPC_ALL, npc.getId(), NpcStringId.THANK_YOU_FOR_THE_RESCUE_ITS_A_SMALL_GIFT));
  154. }
  155. catch (Exception e)
  156. {
  157. //
  158. }
  159. }
  160. }
  161. }
  162. }
  163. return null;
  164. }
  165. private final class Decay implements Runnable
  166. {
  167. private final L2Npc _npc;
  168. public Decay(L2Npc npc)
  169. {
  170. _npc = npc;
  171. }
  172. @Override
  173. public void run()
  174. {
  175. if ((_npc != null) && !_npc.isDead())
  176. {
  177. if (_npc.getTarget() instanceof L2PcInstance)
  178. {
  179. for (int[] i : DROPLIST)
  180. {
  181. if (getRandom(10000) < i[1])
  182. {
  183. _npc.dropItem((L2PcInstance) _npc.getTarget(), i[0], (int) Config.RATE_DROP_ITEMS);
  184. break;
  185. }
  186. }
  187. }
  188. _npc.setAutoAttackable(false);
  189. _npc.deleteMe();
  190. _npc.getSpawn().decreaseCount(_npc);
  191. HellboundManager.getInstance().updateTrust(TRUST, true);
  192. }
  193. }
  194. }
  195. public Quarry(int questId, String name, String descr)
  196. {
  197. super(questId, name, descr);
  198. addSpawnId(SLAVE);
  199. addFirstTalkId(SLAVE);
  200. addStartNpc(SLAVE);
  201. addTalkId(SLAVE);
  202. addKillId(SLAVE);
  203. addEnterZoneId(ZONE);
  204. }
  205. public static void main(String[] args)
  206. {
  207. new Quarry(-1, "Quarry", "hellbound");
  208. }
  209. }