EchoCrystals.java 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /*
  2. * Copyright (C) 2004-2013 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 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. @Override
  74. public String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
  75. {
  76. String htmltext = "";
  77. QuestState st = player.getQuestState(EchoCrystals.class.getSimpleName());
  78. if ((st != null) && Util.isDigit(event))
  79. {
  80. int score = Integer.parseInt(event);
  81. if (SCORES.containsKey(score))
  82. {
  83. int crystal = SCORES.get(score).getCrystalId();
  84. String ok = SCORES.get(score).getOkMsg();
  85. String noadena = SCORES.get(score).getNoAdenaMsg();
  86. String noscore = SCORES.get(score).getNoScoreMsg();
  87. if (!st.hasQuestItems(score))
  88. {
  89. htmltext = npc.getNpcId() + "-" + noscore + ".htm";
  90. }
  91. else if (st.getQuestItemsCount(ADENA) < COST)
  92. {
  93. htmltext = npc.getNpcId() + "-" + noadena + ".htm";
  94. }
  95. else
  96. {
  97. st.takeItems(ADENA, COST);
  98. st.giveItems(crystal, 1);
  99. htmltext = npc.getNpcId() + "-" + ok + ".htm";
  100. }
  101. }
  102. }
  103. else
  104. {
  105. return htmltext;
  106. }
  107. return htmltext;
  108. }
  109. @Override
  110. public String onTalk(L2Npc npc, L2PcInstance player)
  111. {
  112. return "1.htm";
  113. }
  114. public EchoCrystals(int questId, String name, String descr)
  115. {
  116. super(questId, name, descr);
  117. // Initialize Map
  118. SCORES.put(4410, new ScoreData(4411, "01", "02", "03"));
  119. SCORES.put(4409, new ScoreData(4412, "04", "05", "06"));
  120. SCORES.put(4408, new ScoreData(4413, "07", "08", "09"));
  121. SCORES.put(4420, new ScoreData(4414, "10", "11", "12"));
  122. SCORES.put(4421, new ScoreData(4415, "13", "14", "15"));
  123. SCORES.put(4419, new ScoreData(4417, "16", "05", "06"));
  124. SCORES.put(4418, new ScoreData(4416, "17", "05", "06"));
  125. for (int npc : NPCs)
  126. {
  127. addStartNpc(npc);
  128. addTalkId(npc);
  129. }
  130. }
  131. public static void main(String[] args)
  132. {
  133. new EchoCrystals(-1, EchoCrystals.class.getSimpleName(), "custom");
  134. }
  135. }