Quarry.java 5.7 KB

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