Quarry.java 5.6 KB

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