EchoCrystals.java 3.8 KB

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