HeroWeapon.java 2.4 KB

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