Q00552_OlympiadVeteran.java 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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.Q00552_OlympiadVeteran;
  20. import com.l2jserver.gameserver.enums.QuestType;
  21. import com.l2jserver.gameserver.model.actor.L2Npc;
  22. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  23. import com.l2jserver.gameserver.model.olympiad.CompetitionType;
  24. import com.l2jserver.gameserver.model.olympiad.Participant;
  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. * Olympiad Veteran (552)
  30. * @author lion
  31. */
  32. public class Q00552_OlympiadVeteran extends Quest
  33. {
  34. // NPC
  35. private static final int MANAGER = 31688;
  36. // Items
  37. private static final int TEAM_EVENT_CERTIFICATE = 17241;
  38. private static final int CLASS_FREE_BATTLE_CERTIFICATE = 17242;
  39. private static final int CLASS_BATTLE_CERTIFICATE = 17243;
  40. private static final int OLY_CHEST = 17169;
  41. public Q00552_OlympiadVeteran()
  42. {
  43. super(552, Q00552_OlympiadVeteran.class.getSimpleName(), "Olympiad Veteran");
  44. addStartNpc(MANAGER);
  45. addTalkId(MANAGER);
  46. registerQuestItems(TEAM_EVENT_CERTIFICATE, CLASS_FREE_BATTLE_CERTIFICATE, CLASS_BATTLE_CERTIFICATE);
  47. addOlympiadMatchFinishId();
  48. }
  49. @Override
  50. public String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
  51. {
  52. final QuestState st = getQuestState(player, false);
  53. if (st == null)
  54. {
  55. return getNoQuestMsg(player);
  56. }
  57. String htmltext = event;
  58. if (event.equalsIgnoreCase("31688-03.html"))
  59. {
  60. st.startQuest();
  61. }
  62. else if (event.equalsIgnoreCase("31688-04.html"))
  63. {
  64. final long count = st.getQuestItemsCount(TEAM_EVENT_CERTIFICATE) + st.getQuestItemsCount(CLASS_FREE_BATTLE_CERTIFICATE) + st.getQuestItemsCount(CLASS_BATTLE_CERTIFICATE);
  65. if (count > 0)
  66. {
  67. st.giveItems(OLY_CHEST, count);
  68. st.exitQuest(QuestType.DAILY, true);
  69. }
  70. else
  71. {
  72. htmltext = getNoQuestMsg(player);
  73. }
  74. }
  75. return htmltext;
  76. }
  77. @Override
  78. public void onOlympiadMatchFinish(Participant winner, Participant looser, CompetitionType type)
  79. {
  80. if (winner != null)
  81. {
  82. final L2PcInstance player = winner.getPlayer();
  83. if (player == null)
  84. {
  85. return;
  86. }
  87. final QuestState st = getQuestState(player, false);
  88. if ((st != null) && st.isStarted())
  89. {
  90. int matches;
  91. switch (type)
  92. {
  93. case CLASSED:
  94. {
  95. matches = st.getInt("classed") + 1;
  96. st.set("classed", String.valueOf(matches));
  97. if ((matches == 5) && !st.hasQuestItems(CLASS_BATTLE_CERTIFICATE))
  98. {
  99. st.giveItems(CLASS_BATTLE_CERTIFICATE, 1);
  100. }
  101. break;
  102. }
  103. case NON_CLASSED:
  104. {
  105. matches = st.getInt("nonclassed") + 1;
  106. st.set("nonclassed", String.valueOf(matches));
  107. if ((matches == 5) && !st.hasQuestItems(CLASS_FREE_BATTLE_CERTIFICATE))
  108. {
  109. st.giveItems(CLASS_FREE_BATTLE_CERTIFICATE, 1);
  110. }
  111. break;
  112. }
  113. case TEAMS:
  114. {
  115. matches = st.getInt("teams") + 1;
  116. st.set("teams", String.valueOf(matches));
  117. if ((matches == 5) && !st.hasQuestItems(TEAM_EVENT_CERTIFICATE))
  118. {
  119. st.giveItems(TEAM_EVENT_CERTIFICATE, 1);
  120. }
  121. break;
  122. }
  123. }
  124. }
  125. }
  126. if (looser != null)
  127. {
  128. final L2PcInstance player = looser.getPlayer();
  129. if (player == null)
  130. {
  131. return;
  132. }
  133. final QuestState st = getQuestState(player, false);
  134. if ((st != null) && st.isStarted())
  135. {
  136. int matches;
  137. switch (type)
  138. {
  139. case CLASSED:
  140. {
  141. matches = st.getInt("classed") + 1;
  142. st.set("classed", String.valueOf(matches));
  143. if (matches == 5)
  144. {
  145. st.giveItems(CLASS_BATTLE_CERTIFICATE, 1);
  146. }
  147. break;
  148. }
  149. case NON_CLASSED:
  150. {
  151. matches = st.getInt("nonclassed") + 1;
  152. st.set("nonclassed", String.valueOf(matches));
  153. if (matches == 5)
  154. {
  155. st.giveItems(CLASS_FREE_BATTLE_CERTIFICATE, 1);
  156. }
  157. break;
  158. }
  159. case TEAMS:
  160. {
  161. matches = st.getInt("teams") + 1;
  162. st.set("teams", String.valueOf(matches));
  163. if (matches == 5)
  164. {
  165. st.giveItems(TEAM_EVENT_CERTIFICATE, 1);
  166. }
  167. break;
  168. }
  169. }
  170. }
  171. }
  172. }
  173. @Override
  174. public String onTalk(L2Npc npc, L2PcInstance player)
  175. {
  176. String htmltext = getNoQuestMsg(player);
  177. final QuestState st = getQuestState(player, true);
  178. if (st == null)
  179. {
  180. return htmltext;
  181. }
  182. if ((player.getLevel() < 75) || !player.isNoble())
  183. {
  184. htmltext = "31688-00.htm";
  185. }
  186. else if (st.isCreated())
  187. {
  188. htmltext = "31688-01.htm";
  189. }
  190. else if (st.isCompleted())
  191. {
  192. if (st.isNowAvailable())
  193. {
  194. st.setState(State.CREATED);
  195. htmltext = (player.getLevel() < 75) || !player.isNoble() ? "31688-00.htm" : "31688-01.htm";
  196. }
  197. else
  198. {
  199. htmltext = "31688-05.html";
  200. }
  201. }
  202. else if (st.isStarted())
  203. {
  204. final long count = st.getQuestItemsCount(TEAM_EVENT_CERTIFICATE) + st.getQuestItemsCount(CLASS_FREE_BATTLE_CERTIFICATE) + st.getQuestItemsCount(CLASS_BATTLE_CERTIFICATE);
  205. if (count == 3)
  206. {
  207. htmltext = "31688-04.html";
  208. st.giveItems(OLY_CHEST, 4);
  209. st.exitQuest(QuestType.DAILY, true);
  210. }
  211. else
  212. {
  213. htmltext = "31688-s" + count + ".html";
  214. }
  215. }
  216. return htmltext;
  217. }
  218. }