HeavyMedal.java 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /*
  2. * Copyright (C) 2004-2014 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 events.HeavyMedal;
  20. import com.l2jserver.gameserver.enums.QuestSound;
  21. import com.l2jserver.gameserver.model.actor.L2Npc;
  22. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  23. import com.l2jserver.gameserver.model.event.LongTimeEvent;
  24. import com.l2jserver.gameserver.model.quest.QuestState;
  25. /**
  26. * Heavy Medals event AI.
  27. * @author Gnacik
  28. */
  29. public final class HeavyMedal extends LongTimeEvent
  30. {
  31. private final static int CAT_ROY = 31228;
  32. private final static int CAT_WINNIE = 31229;
  33. private final static int GLITTERING_MEDAL = 6393;
  34. private final static int WIN_CHANCE = 50;
  35. private final static int[] MEDALS =
  36. {
  37. 5,
  38. 10,
  39. 20,
  40. 40
  41. };
  42. private final static int[] BADGES =
  43. {
  44. 6399,
  45. 6400,
  46. 6401,
  47. 6402
  48. };
  49. private HeavyMedal()
  50. {
  51. super(HeavyMedal.class.getSimpleName(), "events");
  52. addStartNpc(CAT_ROY);
  53. addStartNpc(CAT_WINNIE);
  54. addTalkId(CAT_ROY);
  55. addTalkId(CAT_WINNIE);
  56. addFirstTalkId(CAT_ROY);
  57. addFirstTalkId(CAT_WINNIE);
  58. }
  59. @Override
  60. public String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
  61. {
  62. final QuestState st = getQuestState(player, false);
  63. if (st == null)
  64. {
  65. return getNoQuestMsg(player);
  66. }
  67. String htmltext = event;
  68. int level = checkLevel(st);
  69. if (event.equalsIgnoreCase("game"))
  70. {
  71. htmltext = st.getQuestItemsCount(GLITTERING_MEDAL) < MEDALS[level] ? "31229-no.htm" : "31229-game.htm";
  72. }
  73. else if (event.equalsIgnoreCase("heads") || event.equalsIgnoreCase("tails"))
  74. {
  75. if (st.getQuestItemsCount(GLITTERING_MEDAL) < MEDALS[level])
  76. {
  77. htmltext = "31229-" + event.toLowerCase() + "-10.htm";
  78. }
  79. else
  80. {
  81. st.takeItems(GLITTERING_MEDAL, MEDALS[level]);
  82. if (getRandom(100) > WIN_CHANCE)
  83. {
  84. level = 0;
  85. }
  86. else
  87. {
  88. if (level > 0)
  89. {
  90. st.takeItems(BADGES[level - 1], -1);
  91. }
  92. st.giveItems(BADGES[level], 1);
  93. st.playSound(QuestSound.ITEMSOUND_QUEST_ITEMGET);
  94. level++;
  95. }
  96. htmltext = "31229-" + event.toLowerCase() + "-" + String.valueOf(level) + ".htm";
  97. }
  98. }
  99. else if (event.equalsIgnoreCase("talk"))
  100. {
  101. htmltext = String.valueOf(npc.getId()) + "-lvl-" + String.valueOf(level) + ".htm";
  102. }
  103. return htmltext;
  104. }
  105. @Override
  106. public String onFirstTalk(L2Npc npc, L2PcInstance player)
  107. {
  108. if (player.getQuestState(getName()) == null)
  109. {
  110. newQuestState(player);
  111. }
  112. return npc.getId() + ".htm";
  113. }
  114. public int checkLevel(QuestState st)
  115. {
  116. int _lev = 0;
  117. if (st.hasQuestItems(6402))
  118. {
  119. _lev = 4;
  120. }
  121. else if (st.hasQuestItems(6401))
  122. {
  123. _lev = 3;
  124. }
  125. else if (st.hasQuestItems(6400))
  126. {
  127. _lev = 2;
  128. }
  129. else if (st.hasQuestItems(6399))
  130. {
  131. _lev = 1;
  132. }
  133. return _lev;
  134. }
  135. public static void main(String[] args)
  136. {
  137. new HeavyMedal();
  138. }
  139. }