EchoCrystals.java 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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 custom.EchoCrystals;
  20. import java.util.HashMap;
  21. import java.util.Map;
  22. import com.l2jserver.gameserver.model.actor.L2Npc;
  23. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  24. import com.l2jserver.gameserver.model.quest.Quest;
  25. import com.l2jserver.gameserver.model.quest.QuestState;
  26. import com.l2jserver.gameserver.util.Util;
  27. /**
  28. * Echo Crystals AI.
  29. * @author Plim
  30. */
  31. public final class EchoCrystals extends Quest
  32. {
  33. private final static int[] NPCs =
  34. {
  35. 31042,
  36. 31043
  37. };
  38. private static final int ADENA = 57;
  39. private static final int COST = 200;
  40. private static final Map<Integer, ScoreData> SCORES = new HashMap<>();
  41. private class ScoreData
  42. {
  43. private final int crystalId;
  44. private final String okMsg;
  45. private final String noAdenaMsg;
  46. private final String noScoreMsg;
  47. public ScoreData(int crystalId, String okMsg, String noAdenaMsg, String noScoreMsg)
  48. {
  49. super();
  50. this.crystalId = crystalId;
  51. this.okMsg = okMsg;
  52. this.noAdenaMsg = noAdenaMsg;
  53. this.noScoreMsg = noScoreMsg;
  54. }
  55. public int getCrystalId()
  56. {
  57. return crystalId;
  58. }
  59. public String getOkMsg()
  60. {
  61. return okMsg;
  62. }
  63. public String getNoAdenaMsg()
  64. {
  65. return noAdenaMsg;
  66. }
  67. public String getNoScoreMsg()
  68. {
  69. return noScoreMsg;
  70. }
  71. }
  72. private EchoCrystals()
  73. {
  74. super(-1, EchoCrystals.class.getSimpleName(), "custom");
  75. // Initialize Map
  76. SCORES.put(4410, new ScoreData(4411, "01", "02", "03"));
  77. SCORES.put(4409, new ScoreData(4412, "04", "05", "06"));
  78. SCORES.put(4408, new ScoreData(4413, "07", "08", "09"));
  79. SCORES.put(4420, new ScoreData(4414, "10", "11", "12"));
  80. SCORES.put(4421, new ScoreData(4415, "13", "14", "15"));
  81. SCORES.put(4419, new ScoreData(4417, "16", "05", "06"));
  82. SCORES.put(4418, new ScoreData(4416, "17", "05", "06"));
  83. for (int npc : NPCs)
  84. {
  85. addStartNpc(npc);
  86. addTalkId(npc);
  87. }
  88. }
  89. @Override
  90. public String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
  91. {
  92. String htmltext = "";
  93. QuestState st = player.getQuestState(EchoCrystals.class.getSimpleName());
  94. if ((st != null) && Util.isDigit(event))
  95. {
  96. int score = Integer.parseInt(event);
  97. if (SCORES.containsKey(score))
  98. {
  99. int crystal = SCORES.get(score).getCrystalId();
  100. String ok = SCORES.get(score).getOkMsg();
  101. String noadena = SCORES.get(score).getNoAdenaMsg();
  102. String noscore = SCORES.get(score).getNoScoreMsg();
  103. if (!hasQuestItems(player, score))
  104. {
  105. htmltext = npc.getId() + "-" + noscore + ".htm";
  106. }
  107. else if (getQuestItemsCount(player, ADENA) < COST)
  108. {
  109. htmltext = npc.getId() + "-" + noadena + ".htm";
  110. }
  111. else
  112. {
  113. takeItems(player, ADENA, COST);
  114. giveItems(player, crystal, 1);
  115. htmltext = npc.getId() + "-" + ok + ".htm";
  116. }
  117. }
  118. }
  119. else
  120. {
  121. return htmltext;
  122. }
  123. return htmltext;
  124. }
  125. @Override
  126. public String onTalk(L2Npc npc, L2PcInstance player)
  127. {
  128. return "1.htm";
  129. }
  130. public static void main(String[] args)
  131. {
  132. new EchoCrystals();
  133. }
  134. }