Alexandria.java 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /*
  2. * Copyright (C) 2004-2014 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.Alexandria;
  20. import java.util.Arrays;
  21. import java.util.HashMap;
  22. import java.util.List;
  23. import java.util.Map;
  24. import ai.npc.AbstractNpcAI;
  25. import com.l2jserver.gameserver.model.actor.L2Npc;
  26. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  27. import com.l2jserver.gameserver.model.holders.ItemHolder;
  28. import com.l2jserver.gameserver.model.holders.QuestItemHolder;
  29. /**
  30. * Alexandria (Armor Merchant) AI.
  31. * @author xban1x
  32. */
  33. public final class Alexandria extends AbstractNpcAI
  34. {
  35. // NPC
  36. private static final int ALEXANDRIA = 30098;
  37. // Items
  38. private static final ItemHolder[] REQUIRED_ITEMS = new ItemHolder[]
  39. {
  40. new ItemHolder(57, 3550000),
  41. new ItemHolder(5094, 400),
  42. new ItemHolder(6471, 200),
  43. new ItemHolder(9814, 40),
  44. new ItemHolder(9815, 30),
  45. new ItemHolder(9816, 50),
  46. new ItemHolder(9817, 50),
  47. };
  48. // Agathions
  49. private static final QuestItemHolder[] LITTLE_DEVILS = new QuestItemHolder[]
  50. {
  51. new AdditionalQuestItemHolder(10321, 600, 1, 10408),
  52. new QuestItemHolder(10322, 10),
  53. new QuestItemHolder(10323, 10),
  54. new QuestItemHolder(10324, 5),
  55. new QuestItemHolder(10325, 5),
  56. new QuestItemHolder(10326, 370),
  57. };
  58. private static final QuestItemHolder[] LITTLE_ANGELS = new QuestItemHolder[]
  59. {
  60. new AdditionalQuestItemHolder(10315, 600, 1, 10408),
  61. new QuestItemHolder(10316, 10),
  62. new QuestItemHolder(10317, 10),
  63. new QuestItemHolder(10318, 5),
  64. new QuestItemHolder(10319, 5),
  65. new QuestItemHolder(10320, 370),
  66. };
  67. private static final Map<String, List<QuestItemHolder>> AGATHIONS = new HashMap<>();
  68. static
  69. {
  70. AGATHIONS.put("littleAngel", Arrays.asList(LITTLE_ANGELS));
  71. AGATHIONS.put("littleDevil", Arrays.asList(LITTLE_DEVILS));
  72. }
  73. private Alexandria()
  74. {
  75. super(Alexandria.class.getSimpleName(), "ai/npc");
  76. addStartNpc(ALEXANDRIA);
  77. addTalkId(ALEXANDRIA);
  78. addFirstTalkId(ALEXANDRIA);
  79. }
  80. @Override
  81. public String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
  82. {
  83. String htmltext = null;
  84. if (event.equals("30098-02.html"))
  85. {
  86. htmltext = event;
  87. }
  88. else if (AGATHIONS.containsKey(event))
  89. {
  90. final int chance = getRandom(1000);
  91. int chance2 = 0;
  92. int chance3 = 0;
  93. for (QuestItemHolder agathion : AGATHIONS.get(event))
  94. {
  95. chance3 += agathion.getChance();
  96. if ((chance >= chance2) && (chance2 < chance3))
  97. {
  98. if (takeAllItems(player, REQUIRED_ITEMS))
  99. {
  100. giveItems(player, agathion);
  101. htmltext = "30098-03.html";
  102. if (agathion instanceof AdditionalQuestItemHolder)
  103. {
  104. giveItems(player, ((AdditionalQuestItemHolder) agathion).getAdditionalId(), 1);
  105. htmltext = "30098-03a.html";
  106. }
  107. }
  108. else
  109. {
  110. htmltext = "30098-04.html";
  111. }
  112. break;
  113. }
  114. chance2 += agathion.getChance();
  115. }
  116. }
  117. return htmltext;
  118. }
  119. public static class AdditionalQuestItemHolder extends QuestItemHolder
  120. {
  121. private final int _additionalId;
  122. public AdditionalQuestItemHolder(int id, int chance, long count, int additionalId)
  123. {
  124. super(id, chance, count);
  125. _additionalId = additionalId;
  126. }
  127. public int getAdditionalId()
  128. {
  129. return _additionalId;
  130. }
  131. }
  132. public static void main(String[] args)
  133. {
  134. new Alexandria();
  135. }
  136. }