HeavyMedal.java 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /*
  2. * This program is free software: you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation, either version 3 of the License, or (at your option) any later
  5. * version.
  6. *
  7. * This program is distributed in the hope that it will be useful, but WITHOUT
  8. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10. * details.
  11. *
  12. * You should have received a copy of the GNU General Public License along with
  13. * this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. package events.HeavyMedal;
  16. import com.l2jserver.gameserver.model.actor.L2Npc;
  17. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  18. import com.l2jserver.gameserver.model.event.LongTimeEvent;
  19. import com.l2jserver.gameserver.model.quest.QuestState;
  20. /**
  21. * Heavy Medals event AI.
  22. * @author Gnacik
  23. */
  24. public class HeavyMedal extends LongTimeEvent
  25. {
  26. private final static int CAT_ROY = 31228;
  27. private final static int CAT_WINNIE = 31229;
  28. private final static int GLITTERING_MEDAL = 6393;
  29. private final static int WIN_CHANCE = 50;
  30. private final static int[] MEDALS =
  31. {
  32. 5,
  33. 10,
  34. 20,
  35. 40
  36. };
  37. private final static int[] BADGES =
  38. {
  39. 6399,
  40. 6400,
  41. 6401,
  42. 6402
  43. };
  44. public HeavyMedal(int questId, String name, String descr)
  45. {
  46. super(questId, name, descr);
  47. addStartNpc(CAT_ROY);
  48. addStartNpc(CAT_WINNIE);
  49. addTalkId(CAT_ROY);
  50. addTalkId(CAT_WINNIE);
  51. addFirstTalkId(CAT_ROY);
  52. addFirstTalkId(CAT_WINNIE);
  53. }
  54. @Override
  55. public String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
  56. {
  57. final QuestState st = player.getQuestState(getName());
  58. if (st == null)
  59. {
  60. return getNoQuestMsg(player);
  61. }
  62. String htmltext = event;
  63. int level = checkLevel(st);
  64. if (event.equalsIgnoreCase("game"))
  65. {
  66. htmltext = st.getQuestItemsCount(GLITTERING_MEDAL) < MEDALS[level] ? "31229-no.htm" : "31229-game.htm";
  67. }
  68. else if (event.equalsIgnoreCase("heads") || event.equalsIgnoreCase("tails"))
  69. {
  70. if (st.getQuestItemsCount(GLITTERING_MEDAL) < MEDALS[level])
  71. {
  72. htmltext = "31229-" + event.toLowerCase() + "-10.htm";
  73. }
  74. else
  75. {
  76. st.takeItems(GLITTERING_MEDAL, MEDALS[level]);
  77. if (getRandom(100) > WIN_CHANCE)
  78. {
  79. level = 0;
  80. }
  81. else
  82. {
  83. if (level > 0)
  84. {
  85. st.takeItems(BADGES[level - 1], -1);
  86. }
  87. st.giveItems(BADGES[level], 1);
  88. st.playSound(QuestSound.ITEMSOUND_QUEST_ITEMGET);
  89. level++;
  90. }
  91. htmltext = "31229-" + event.toLowerCase() + "-" + String.valueOf(level) + ".htm";
  92. }
  93. }
  94. else if (event.equalsIgnoreCase("talk"))
  95. {
  96. htmltext = String.valueOf(npc.getNpcId()) + "-lvl-" + String.valueOf(level) + ".htm";
  97. }
  98. return htmltext;
  99. }
  100. @Override
  101. public String onFirstTalk(L2Npc npc, L2PcInstance player)
  102. {
  103. if (player.getQuestState(getName()) == null)
  104. {
  105. newQuestState(player);
  106. }
  107. return npc.getNpcId() + ".htm";
  108. }
  109. public int checkLevel(QuestState st)
  110. {
  111. int _lev = 0;
  112. if (st.hasQuestItems(6402))
  113. {
  114. _lev = 4;
  115. }
  116. else if (st.hasQuestItems(6401))
  117. {
  118. _lev = 3;
  119. }
  120. else if (st.hasQuestItems(6400))
  121. {
  122. _lev = 2;
  123. }
  124. else if (st.hasQuestItems(6399))
  125. {
  126. _lev = 1;
  127. }
  128. return _lev;
  129. }
  130. public static void main(String[] args)
  131. {
  132. new HeavyMedal(-1, "HeavyMedal", "events");
  133. }
  134. }