BlackMarketeerOfMammon.java 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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 ai.npc.BlackMarketeerOfMammon;
  20. import java.util.Calendar;
  21. import ai.npc.AbstractNpcAI;
  22. import com.l2jserver.gameserver.enums.QuestType;
  23. import com.l2jserver.gameserver.model.actor.L2Npc;
  24. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  25. import com.l2jserver.gameserver.model.itemcontainer.Inventory;
  26. import com.l2jserver.gameserver.model.quest.QuestState;
  27. import com.l2jserver.gameserver.model.quest.State;
  28. /**
  29. * Black Marketeer of Mammon - Exchange Adena for AA.
  30. * @author Adry_85
  31. */
  32. public final class BlackMarketeerOfMammon extends AbstractNpcAI
  33. {
  34. // NPC
  35. private static final int BLACK_MARKETEER = 31092;
  36. // Misc
  37. private static final int MIN_LEVEL = 60;
  38. private BlackMarketeerOfMammon()
  39. {
  40. super(BlackMarketeerOfMammon.class.getSimpleName(), "ai/npc");
  41. addStartNpc(BLACK_MARKETEER);
  42. addTalkId(BLACK_MARKETEER);
  43. }
  44. @Override
  45. public String onTalk(L2Npc npc, L2PcInstance talker)
  46. {
  47. return exchangeAvailable() ? "31092-01.html" : "31092-02.html";
  48. }
  49. @Override
  50. public String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
  51. {
  52. String htmltext = event;
  53. if ("exchange".equals(event))
  54. {
  55. if (exchangeAvailable())
  56. {
  57. if (player.getLevel() >= MIN_LEVEL)
  58. {
  59. final QuestState qs = getQuestState(player, true);
  60. if (!qs.isNowAvailable())
  61. {
  62. htmltext = "31092-03.html";
  63. }
  64. else
  65. {
  66. if (player.getAdena() >= 2000000)
  67. {
  68. qs.setState(State.STARTED);
  69. takeItems(player, Inventory.ADENA_ID, 2000000);
  70. giveItems(player, Inventory.ANCIENT_ADENA_ID, 500000);
  71. htmltext = "31092-04.html";
  72. qs.exitQuest(QuestType.DAILY, false);
  73. }
  74. else
  75. {
  76. htmltext = "31092-05.html";
  77. }
  78. }
  79. }
  80. else
  81. {
  82. htmltext = "31092-06.html";
  83. }
  84. }
  85. else
  86. {
  87. htmltext = "31092-02.html";
  88. }
  89. }
  90. return htmltext;
  91. }
  92. private boolean exchangeAvailable()
  93. {
  94. Calendar currentTime = Calendar.getInstance();
  95. Calendar minTime = Calendar.getInstance();
  96. minTime.set(Calendar.HOUR_OF_DAY, 20);
  97. minTime.set(Calendar.MINUTE, 0);
  98. minTime.set(Calendar.SECOND, 0);
  99. Calendar maxtTime = Calendar.getInstance();
  100. maxtTime.set(Calendar.HOUR_OF_DAY, 23);
  101. maxtTime.set(Calendar.MINUTE, 59);
  102. maxtTime.set(Calendar.SECOND, 59);
  103. return (currentTime.compareTo(minTime) >= 0) && (currentTime.compareTo(maxtTime) <= 0);
  104. }
  105. public static void main(String[] args)
  106. {
  107. new BlackMarketeerOfMammon();
  108. }
  109. }