NewbieTravelToken.java 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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 teleports.NewbieTravelToken;
  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.network.SystemMessageId;
  23. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  24. /**
  25. * @author Plim
  26. * Original python script by DrLecter
  27. */
  28. public class NewbieTravelToken extends Quest
  29. {
  30. private static final int TOKEN = 8542;
  31. private static final Map<Integer, int[]> DATA = new FastMap<Integer, int[]>();
  32. @Override
  33. public String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
  34. {
  35. QuestState st = player.getQuestState(getName());
  36. if (st == null)
  37. st = newQuestState(player);
  38. try
  39. {
  40. if (DATA.keySet().contains(new Integer(event)))
  41. {
  42. if (st.hasQuestItems(TOKEN))
  43. {
  44. st.takeItems(TOKEN,1);
  45. st.getPlayer().teleToLocation(DATA.get(event)[0], DATA.get(event)[1], DATA.get(event)[2]);
  46. }
  47. else
  48. {
  49. st.exitQuest(true);
  50. player.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.INCORRECT_ITEM_COUNT));
  51. return "";
  52. }
  53. }
  54. }
  55. catch(NumberFormatException e)
  56. {
  57. //not a number
  58. }
  59. return event;
  60. }
  61. @Override
  62. public String onTalk(L2Npc npc, L2PcInstance player)
  63. {
  64. String htmltext = "";
  65. QuestState st = player.getQuestState(getName());
  66. if (st == null)
  67. return null;
  68. if (player.getLevel() >= 20)
  69. {
  70. htmltext="cant-travel.htm";
  71. st.exitQuest(true);
  72. }
  73. else
  74. htmltext = String.valueOf(npc.getNpcId())+".htm";
  75. return htmltext;
  76. }
  77. public NewbieTravelToken(int questId, String name, String descr)
  78. {
  79. super(questId, name, descr);
  80. // Initialize Map
  81. DATA.put(30600, new int[]{12160, 16554,-4583}); //DE
  82. DATA.put(30601, new int[]{115594,-177993, -912}); //DW
  83. DATA.put(30599, new int[]{45470, 48328,-3059}); //EV
  84. DATA.put(30602, new int[]{-45067,-113563, -199}); //OV
  85. DATA.put(30598, new int[]{-84053, 243343,-3729}); //TI
  86. DATA.put(32135, new int[]{-119712, 44519,368}); //SI
  87. for (int npcId : DATA.keySet())
  88. {
  89. addStartNpc(npcId);
  90. addTalkId(npcId);
  91. }
  92. }
  93. public static void main(String[] args)
  94. {
  95. new NewbieTravelToken(-1, NewbieTravelToken.class.getSimpleName(), "teleports");
  96. }
  97. }