HeavyMedal.java 3.5 KB

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