Quarry.java 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. /*
  2. * Copyright (C) 2004-2015 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.AI.NPC.Quarry;
  20. import hellbound.HellboundEngine;
  21. import ai.npc.AbstractNpcAI;
  22. import com.l2jserver.Config;
  23. import com.l2jserver.gameserver.ai.CtrlIntention;
  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.holders.ItemChanceHolder;
  31. import com.l2jserver.gameserver.model.zone.L2ZoneType;
  32. import com.l2jserver.gameserver.network.NpcStringId;
  33. import com.l2jserver.gameserver.network.clientpackets.Say2;
  34. /**
  35. * Quarry AI.
  36. * @author DS, GKR
  37. */
  38. public final class Quarry extends AbstractNpcAI
  39. {
  40. // NPCs
  41. private static final int SLAVE = 32299;
  42. // Items
  43. protected static final ItemChanceHolder[] DROP_LIST =
  44. {
  45. new ItemChanceHolder(9628, 261), // Leonard
  46. new ItemChanceHolder(9630, 175), // Orichalcum
  47. new ItemChanceHolder(9629, 145), // Adamantine
  48. new ItemChanceHolder(1876, 6667), // Mithril ore
  49. new ItemChanceHolder(1877, 1333), // Adamantine nugget
  50. new ItemChanceHolder(1874, 2222), // Oriharukon ore
  51. };
  52. // Zone
  53. private static final int ZONE = 40107;
  54. // Misc
  55. private static final int TRUST = 50;
  56. public Quarry()
  57. {
  58. super(Quarry.class.getSimpleName(), "hellbound/AI/NPC");
  59. addSpawnId(SLAVE);
  60. addFirstTalkId(SLAVE);
  61. addStartNpc(SLAVE);
  62. addTalkId(SLAVE);
  63. addKillId(SLAVE);
  64. addEnterZoneId(ZONE);
  65. }
  66. @Override
  67. public final String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
  68. {
  69. String htmltext = null;
  70. switch (event)
  71. {
  72. case "FollowMe":
  73. {
  74. npc.getAI().setIntention(CtrlIntention.AI_INTENTION_FOLLOW, player);
  75. npc.setTarget(player);
  76. npc.setAutoAttackable(true);
  77. npc.setRHandId(9136);
  78. npc.setWalking();
  79. if (getQuestTimer("TIME_LIMIT", npc, null) == null)
  80. {
  81. startQuestTimer("TIME_LIMIT", 900000, npc, null); // 15 min limit for save
  82. }
  83. htmltext = "32299-02.htm";
  84. break;
  85. }
  86. case "TIME_LIMIT":
  87. {
  88. for (L2ZoneType zone : ZoneManager.getInstance().getZones(npc))
  89. {
  90. if (zone.getId() == 40108)
  91. {
  92. npc.setTarget(null);
  93. npc.getAI().setIntention(CtrlIntention.AI_INTENTION_ACTIVE);
  94. npc.setAutoAttackable(false);
  95. npc.setRHandId(0);
  96. npc.teleToLocation(npc.getSpawn().getLocation());
  97. return null;
  98. }
  99. }
  100. broadcastNpcSay(npc, Say2.NPC_ALL, NpcStringId.HUN_HUNGRY);
  101. npc.doDie(npc);
  102. break;
  103. }
  104. case "DECAY":
  105. {
  106. if ((npc != null) && !npc.isDead())
  107. {
  108. if (npc.getTarget().isPlayer())
  109. {
  110. for (ItemChanceHolder item : DROP_LIST)
  111. {
  112. if (getRandom(10000) < item.getChance())
  113. {
  114. npc.dropItem((L2PcInstance) npc.getTarget(), item.getId(), (int) (item.getCount() * Config.RATE_QUEST_DROP));
  115. break;
  116. }
  117. }
  118. }
  119. npc.setAutoAttackable(false);
  120. npc.deleteMe();
  121. npc.getSpawn().decreaseCount(npc);
  122. HellboundEngine.getInstance().updateTrust(TRUST, true);
  123. }
  124. }
  125. }
  126. return htmltext;
  127. }
  128. @Override
  129. public final String onSpawn(L2Npc npc)
  130. {
  131. npc.setAutoAttackable(false);
  132. if (npc instanceof L2QuestGuardInstance)
  133. {
  134. ((L2QuestGuardInstance) npc).setPassive(true);
  135. }
  136. return super.onSpawn(npc);
  137. }
  138. @Override
  139. public final String onFirstTalk(L2Npc npc, L2PcInstance player)
  140. {
  141. if (HellboundEngine.getInstance().getLevel() != 5)
  142. {
  143. return "32299.htm";
  144. }
  145. return "32299-01.htm";
  146. }
  147. @Override
  148. public final String onKill(L2Npc npc, L2PcInstance killer, boolean isSummon)
  149. {
  150. npc.setAutoAttackable(false);
  151. return super.onKill(npc, killer, isSummon);
  152. }
  153. @Override
  154. public final String onEnterZone(L2Character character, L2ZoneType zone)
  155. {
  156. if (character.isAttackable())
  157. {
  158. final L2Attackable npc = (L2Attackable) character;
  159. if (npc.getId() == SLAVE)
  160. {
  161. if (!npc.isDead() && !npc.isDecayed() && (npc.getAI().getIntention() == CtrlIntention.AI_INTENTION_FOLLOW))
  162. {
  163. if (HellboundEngine.getInstance().getLevel() == 5)
  164. {
  165. startQuestTimer("DECAY", 1000, npc, null);
  166. try
  167. {
  168. broadcastNpcSay(npc, Say2.NPC_ALL, NpcStringId.THANK_YOU_FOR_THE_RESCUE_ITS_A_SMALL_GIFT);
  169. }
  170. catch (Exception e)
  171. {
  172. //
  173. }
  174. }
  175. }
  176. }
  177. }
  178. return super.onEnterZone(character, zone);
  179. }
  180. }