Q00238_SuccessFailureOfBusiness.java 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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.Q00238_SuccessFailureOfBusiness;
  20. import quests.Q00237_WindsOfChange.Q00237_WindsOfChange;
  21. import quests.Q00239_WontYouJoinUs.Q00239_WontYouJoinUs;
  22. import com.l2jserver.gameserver.enums.QuestSound;
  23. import com.l2jserver.gameserver.model.actor.L2Npc;
  24. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  25. import com.l2jserver.gameserver.model.quest.Quest;
  26. import com.l2jserver.gameserver.model.quest.QuestState;
  27. import com.l2jserver.gameserver.model.quest.State;
  28. /**
  29. * Success/Failure Of Business (238)<br>
  30. * Original Jython script by Bloodshed.
  31. * @author Joxit
  32. */
  33. public class Q00238_SuccessFailureOfBusiness extends Quest
  34. {
  35. // NPCs
  36. private static final int HELVETICA = 32641;
  37. // Mobs
  38. private static final int BRAZIER_OF_PURITY = 18806;
  39. private static final int EVIL_SPIRITS = 22658;
  40. private static final int GUARDIAN_SPIRITS = 22659;
  41. // Items
  42. private static final int VICINITY_OF_FOS = 14865;
  43. private static final int BROKEN_PIECE_OF_MAGIC_FORCE = 14867;
  44. private static final int GUARDIAN_SPIRIT_FRAGMENT = 14868;
  45. // Misc
  46. private static final int BROKEN_PIECE_OF_MAGIC_FORCE_NEEDED = 10;
  47. private static final int GUARDIAN_SPIRIT_FRAGMENT_NEEDED = 20;
  48. private static final int CHANCE_FOR_FRAGMENT = 80;
  49. private static final int MIN_LEVEL = 82;
  50. public Q00238_SuccessFailureOfBusiness()
  51. {
  52. super(238, Q00238_SuccessFailureOfBusiness.class.getSimpleName(), "Success/Failure Of Business");
  53. addStartNpc(HELVETICA);
  54. addTalkId(HELVETICA);
  55. addKillId(BRAZIER_OF_PURITY, EVIL_SPIRITS, GUARDIAN_SPIRITS);
  56. registerQuestItems(BROKEN_PIECE_OF_MAGIC_FORCE, GUARDIAN_SPIRIT_FRAGMENT);
  57. }
  58. @Override
  59. public String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
  60. {
  61. final QuestState st = getQuestState(player, false);
  62. if (st == null)
  63. {
  64. return null;
  65. }
  66. String htmltext = null;
  67. switch (event)
  68. {
  69. case "32461-02.htm":
  70. htmltext = event;
  71. break;
  72. case "32461-03.html":
  73. st.startQuest();
  74. htmltext = event;
  75. break;
  76. case "32461-06.html":
  77. if (st.isCond(2))
  78. {
  79. st.setCond(3, true);
  80. htmltext = event;
  81. }
  82. break;
  83. }
  84. return htmltext;
  85. }
  86. @Override
  87. public String onKill(L2Npc npc, L2PcInstance killer, boolean isSummon)
  88. {
  89. if (npc.getId() == BRAZIER_OF_PURITY)
  90. {
  91. final L2PcInstance partyMember = getRandomPartyMember(killer, 1);
  92. if (partyMember != null)
  93. {
  94. final QuestState st = getQuestState(partyMember, false);
  95. if (st.getQuestItemsCount(BROKEN_PIECE_OF_MAGIC_FORCE) < BROKEN_PIECE_OF_MAGIC_FORCE_NEEDED)
  96. {
  97. st.giveItems(BROKEN_PIECE_OF_MAGIC_FORCE, 1);
  98. }
  99. if (st.getQuestItemsCount(BROKEN_PIECE_OF_MAGIC_FORCE) == BROKEN_PIECE_OF_MAGIC_FORCE_NEEDED)
  100. {
  101. st.setCond(2, true);
  102. }
  103. else
  104. {
  105. st.playSound(QuestSound.ITEMSOUND_QUEST_ITEMGET);
  106. }
  107. }
  108. }
  109. else
  110. {
  111. final L2PcInstance partyMember = getRandomPartyMember(killer, 3);
  112. if ((partyMember != null) && (getRandom(100) < CHANCE_FOR_FRAGMENT))
  113. {
  114. final QuestState st = getQuestState(partyMember, false);
  115. if (st.getQuestItemsCount(GUARDIAN_SPIRIT_FRAGMENT) < GUARDIAN_SPIRIT_FRAGMENT_NEEDED)
  116. {
  117. st.giveItems(GUARDIAN_SPIRIT_FRAGMENT, 1);
  118. }
  119. if (st.getQuestItemsCount(GUARDIAN_SPIRIT_FRAGMENT) == GUARDIAN_SPIRIT_FRAGMENT_NEEDED)
  120. {
  121. st.setCond(4, true);
  122. }
  123. else
  124. {
  125. st.playSound(QuestSound.ITEMSOUND_QUEST_ITEMGET);
  126. }
  127. }
  128. }
  129. return super.onKill(npc, killer, isSummon);
  130. }
  131. @Override
  132. public String onTalk(L2Npc npc, L2PcInstance talker)
  133. {
  134. String htmltext = getNoQuestMsg(talker);
  135. final QuestState st = getQuestState(talker, true);
  136. if (st == null)
  137. {
  138. return htmltext;
  139. }
  140. switch (st.getState())
  141. {
  142. case State.COMPLETED:
  143. htmltext = "32461-09.html";
  144. break;
  145. case State.CREATED:
  146. final QuestState q237 = st.getPlayer().getQuestState(Q00237_WindsOfChange.class.getSimpleName());
  147. final QuestState q239 = st.getPlayer().getQuestState(Q00239_WontYouJoinUs.class.getSimpleName());
  148. if ((q239 != null) && q239.isCompleted())
  149. {
  150. htmltext = "32461-10.html";
  151. }
  152. else if ((q237 != null) && q237.isCompleted() && (talker.getLevel() >= MIN_LEVEL) && st.hasQuestItems(VICINITY_OF_FOS))
  153. {
  154. htmltext = "32461-01.htm";
  155. }
  156. else
  157. {
  158. htmltext = "32461-00.html";
  159. }
  160. break;
  161. case State.STARTED:
  162. switch (st.getCond())
  163. {
  164. case 1:
  165. htmltext = "32461-04.html";
  166. break;
  167. case 2:
  168. if (st.getQuestItemsCount(BROKEN_PIECE_OF_MAGIC_FORCE) == BROKEN_PIECE_OF_MAGIC_FORCE_NEEDED)
  169. {
  170. htmltext = "32461-05.html";
  171. st.takeItems(BROKEN_PIECE_OF_MAGIC_FORCE, -1);
  172. }
  173. break;
  174. case 3:
  175. htmltext = "32461-07.html";
  176. break;
  177. case 4:
  178. if (st.getQuestItemsCount(GUARDIAN_SPIRIT_FRAGMENT) == GUARDIAN_SPIRIT_FRAGMENT_NEEDED)
  179. {
  180. htmltext = "32461-08.html";
  181. st.giveAdena(283346, true);
  182. st.takeItems(VICINITY_OF_FOS, 1);
  183. st.addExpAndSp(1319736, 103553);
  184. st.exitQuest(false, true);
  185. }
  186. break;
  187. }
  188. break;
  189. }
  190. return htmltext;
  191. }
  192. }