EchoCrystals.java 3.9 KB

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