HeroWeapon.java 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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.HeroWeapon;
  16. import com.l2jserver.gameserver.model.actor.L2Npc;
  17. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  18. import com.l2jserver.gameserver.model.quest.Quest;
  19. import com.l2jserver.gameserver.model.quest.QuestState;
  20. import com.l2jserver.gameserver.util.Util;
  21. /**
  22. * Herro Weapon AI.
  23. */
  24. public class HeroWeapon extends Quest
  25. {
  26. private final static int[] npcIds =
  27. {
  28. 31690,31769,31770,31771,31772
  29. };
  30. private final static int[] weaponIds =
  31. {
  32. 6611,6612,6613,6614,6615,6616,6617,6618,6619,6620,6621,9388,9389,9390
  33. };
  34. public HeroWeapon(int questId, String name, String descr)
  35. {
  36. super(questId, name, descr);
  37. for (int i : npcIds)
  38. {
  39. addStartNpc(i);
  40. addTalkId(i);
  41. }
  42. }
  43. @Override
  44. public String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
  45. {
  46. QuestState st = player.getQuestState(getName());
  47. int weaponId = Integer.valueOf(event);
  48. if (Util.contains(weaponIds, weaponId))
  49. st.giveItems(weaponId, 1);
  50. st.exitQuest(true);
  51. return null;
  52. }
  53. @Override
  54. public String onTalk(L2Npc npc, L2PcInstance player)
  55. {
  56. String htmltext = "";
  57. QuestState st = player.getQuestState(getName());
  58. if (st == null)
  59. {
  60. st = newQuestState(player);
  61. }
  62. if (player.isHero())
  63. {
  64. if (hasHeroWeapon(player))
  65. {
  66. htmltext = "already_have_weapon.htm";
  67. st.exitQuest(true);
  68. }
  69. else
  70. htmltext = "weapon_list.htm";
  71. }
  72. else
  73. {
  74. htmltext = "no_hero.htm";
  75. st.exitQuest(true);
  76. }
  77. return htmltext;
  78. }
  79. private boolean hasHeroWeapon(L2PcInstance player)
  80. {
  81. for (int i : weaponIds)
  82. {
  83. if (player.getInventory().getItemByItemId(i) != null)
  84. return true;
  85. }
  86. return false;
  87. }
  88. public static void main(String[] args)
  89. {
  90. new HeroWeapon(-1, "HeroWeapon", "custom");
  91. }
  92. }