Q00457_LostAndFound.java 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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 quests.Q00457_LostAndFound;
  20. import java.util.Set;
  21. import com.l2jserver.gameserver.ai.CtrlIntention;
  22. import com.l2jserver.gameserver.datatables.SpawnTable;
  23. import com.l2jserver.gameserver.enums.QuestType;
  24. import com.l2jserver.gameserver.model.L2Spawn;
  25. import com.l2jserver.gameserver.model.actor.L2Npc;
  26. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  27. import com.l2jserver.gameserver.model.quest.Quest;
  28. import com.l2jserver.gameserver.model.quest.QuestState;
  29. import com.l2jserver.gameserver.model.quest.State;
  30. import com.l2jserver.gameserver.network.NpcStringId;
  31. import com.l2jserver.gameserver.network.clientpackets.Say2;
  32. import com.l2jserver.gameserver.network.serverpackets.CreatureSay;
  33. import com.l2jserver.gameserver.network.serverpackets.NpcSay;
  34. /**
  35. * Lost and Found (457)
  36. * @author nonom
  37. */
  38. public final class Q00457_LostAndFound extends Quest
  39. {
  40. // NPCs
  41. private static final int GUMIEL = 32759;
  42. private static final int ESCORT_CHECKER = 32764;
  43. private static final int[] SOLINA_CLAN =
  44. {
  45. 22789, // Guide Solina
  46. 22790, // Seeker Solina
  47. 22791, // Savior Solina
  48. 22793, // Ascetic Solina
  49. };
  50. // Misc
  51. private static final int PACKAGED_BOOK = 15716;
  52. private static final int CHANCE_SPAWN = 1; // 1%
  53. private static final int MIN_LV = 82;
  54. private static Set<L2Spawn> _escortCheckers;
  55. public Q00457_LostAndFound()
  56. {
  57. super(457, Q00457_LostAndFound.class.getSimpleName(), "Lost and Found");
  58. addStartNpc(GUMIEL);
  59. addSpawnId(ESCORT_CHECKER);
  60. addFirstTalkId(GUMIEL);
  61. addTalkId(GUMIEL);
  62. addKillId(SOLINA_CLAN);
  63. }
  64. @Override
  65. public String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
  66. {
  67. final QuestState st = getQuestState(player, false);
  68. if (st == null)
  69. {
  70. return getNoQuestMsg(player);
  71. }
  72. String htmltext = null;
  73. switch (event)
  74. {
  75. case "32759-06.html":
  76. {
  77. npc.setScriptValue(0);
  78. st.startQuest();
  79. npc.setTarget(player);
  80. npc.setWalking();
  81. npc.getAI().setIntention(CtrlIntention.AI_INTENTION_FOLLOW, player);
  82. startQuestTimer("CHECK", 1000, npc, player, true);
  83. startQuestTimer("TIME_LIMIT", 600000, npc, player);
  84. startQuestTimer("TALK_TIME", 120000, npc, player);
  85. startQuestTimer("TALK_TIME2", 30000, npc, player);
  86. break;
  87. }
  88. case "TALK_TIME":
  89. {
  90. broadcastNpcSay(npc, player, NpcStringId.AH_I_THINK_I_REMEMBER_THIS_PLACE, false);
  91. break;
  92. }
  93. case "TALK_TIME2":
  94. {
  95. broadcastNpcSay(npc, player, NpcStringId.WHAT_WERE_YOU_DOING_HERE, false);
  96. startQuestTimer("TALK_TIME3", 10 * 1000, npc, player);
  97. break;
  98. }
  99. case "TALK_TIME3":
  100. {
  101. broadcastNpcSay(npc, player, NpcStringId.I_GUESS_YOURE_THE_SILENT_TYPE_THEN_ARE_YOU_LOOKING_FOR_TREASURE_LIKE_ME, false);
  102. break;
  103. }
  104. case "TIME_LIMIT":
  105. {
  106. startQuestTimer("STOP", 2000, npc, player);
  107. st.exitQuest(QuestType.DAILY);
  108. break;
  109. }
  110. case "CHECK":
  111. {
  112. final double distance = npc.calculateDistance(player, true, false);
  113. if (distance > 1000)
  114. {
  115. if (distance > 5000)
  116. {
  117. startQuestTimer("STOP", 2000, npc, player);
  118. st.exitQuest(QuestType.DAILY);
  119. }
  120. else if (npc.isScriptValue(0))
  121. {
  122. broadcastNpcSay(npc, player, NpcStringId.HEY_DONT_GO_SO_FAST, true);
  123. npc.setScriptValue(1);
  124. }
  125. else if (npc.isScriptValue(1))
  126. {
  127. broadcastNpcSay(npc, player, NpcStringId.ITS_HARD_TO_FOLLOW, true);
  128. npc.setScriptValue(2);
  129. }
  130. else if (npc.isScriptValue(2))
  131. {
  132. startQuestTimer("STOP", 2000, npc, player);
  133. st.exitQuest(QuestType.DAILY);
  134. }
  135. }
  136. for (L2Spawn escortSpawn : _escortCheckers)
  137. {
  138. final L2Npc escort = escortSpawn.getLastSpawn();
  139. if ((escort != null) && npc.isInsideRadius(escort, 1000, false, false))
  140. {
  141. startQuestTimer("STOP", 1000, npc, player);
  142. startQuestTimer("BYE", 3000, npc, player);
  143. cancelQuestTimer("CHECK", npc, player);
  144. npc.broadcastPacket(new CreatureSay(npc.getObjectId(), Say2.NPC_ALL, npc.getName(), NpcStringId.AH_FRESH_AIR));
  145. broadcastNpcSay(npc, player, NpcStringId.AH_FRESH_AIR, false);
  146. st.giveItems(PACKAGED_BOOK, 1);
  147. st.exitQuest(QuestType.DAILY, true);
  148. break;
  149. }
  150. }
  151. break;
  152. }
  153. case "STOP":
  154. {
  155. npc.setTarget(null);
  156. npc.getAI().stopFollow();
  157. npc.getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
  158. cancelQuestTimer("CHECK", npc, player);
  159. cancelQuestTimer("TIME_LIMIT", npc, player);
  160. cancelQuestTimer("TALK_TIME", npc, player);
  161. cancelQuestTimer("TALK_TIME2", npc, player);
  162. break;
  163. }
  164. case "BYE":
  165. {
  166. npc.deleteMe();
  167. break;
  168. }
  169. default:
  170. {
  171. htmltext = event;
  172. break;
  173. }
  174. }
  175. return htmltext;
  176. }
  177. @Override
  178. public String onFirstTalk(L2Npc npc, L2PcInstance player)
  179. {
  180. if (npc.getTarget() != null)
  181. {
  182. return npc.getTarget().equals(player) ? "32759-08.html" : "32759-01a.html";
  183. }
  184. return "32759.html";
  185. }
  186. @Override
  187. public String onKill(L2Npc npc, L2PcInstance player, boolean isSummon)
  188. {
  189. final QuestState st = getQuestState(player, true);
  190. if ((getRandom(100) < CHANCE_SPAWN) && st.isNowAvailable() && (player.getLevel() >= MIN_LV))
  191. {
  192. addSpawn(GUMIEL, npc);
  193. }
  194. return super.onKill(npc, player, isSummon);
  195. }
  196. @Override
  197. public String onTalk(L2Npc npc, L2PcInstance player)
  198. {
  199. String htmltext = getNoQuestMsg(player);
  200. QuestState st = getQuestState(player, true);
  201. if (st == null)
  202. {
  203. st = newQuestState(player);
  204. }
  205. switch (st.getState())
  206. {
  207. case State.CREATED:
  208. {
  209. htmltext = (player.getLevel() >= MIN_LV) ? "32759-01.htm" : "32759-03.html";
  210. break;
  211. }
  212. case State.COMPLETED:
  213. {
  214. if (st.isNowAvailable())
  215. {
  216. st.setState(State.CREATED);
  217. htmltext = (player.getLevel() >= MIN_LV) ? "32759-01.htm" : "32759-03.html";
  218. }
  219. else
  220. {
  221. htmltext = "32759-02.html";
  222. }
  223. break;
  224. }
  225. }
  226. return htmltext;
  227. }
  228. @Override
  229. public String onSpawn(L2Npc npc)
  230. {
  231. _escortCheckers = SpawnTable.getInstance().getSpawns(ESCORT_CHECKER);
  232. return super.onSpawn(npc);
  233. }
  234. public void broadcastNpcSay(L2Npc npc, L2PcInstance player, NpcStringId stringId, boolean whisper)
  235. {
  236. ((whisper) ? player : npc).sendPacket(new NpcSay(npc.getObjectId(), ((whisper) ? Say2.TELL : Say2.ALL), npc.getId(), stringId));
  237. }
  238. }