CharacterBirthday.java 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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 events.CharacterBirthday;
  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.model.quest.State;
  21. import com.l2jserver.gameserver.util.Util;
  22. /**
  23. * @author Gnacik. Updated to H5 by Nyaran
  24. */
  25. public class CharacterBirthday extends Quest
  26. {
  27. private static final int _npc = 32600;
  28. private static int _spawns = 0;
  29. private final static int[] _gk =
  30. {
  31. 30006, 30059, 30080, 30134, 30146, 30177, 30233, 30256, 30320, 30540, 30576, 30836, 30848, 30878, 30899, 31275, 31320, 31964, 32163
  32. };
  33. public CharacterBirthday(int questId, String name, String descr)
  34. {
  35. super(questId, name, descr);
  36. addStartNpc(_npc);
  37. addTalkId(_npc);
  38. for (int id : _gk)
  39. {
  40. addStartNpc(id);
  41. addTalkId(id);
  42. }
  43. }
  44. @Override
  45. public String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
  46. {
  47. String htmltext = event;
  48. QuestState st = player.getQuestState(getName());
  49. if (event.equalsIgnoreCase("despawn_npc"))
  50. {
  51. npc.doDie(player);
  52. _spawns--;
  53. htmltext = null;
  54. }
  55. else if (event.equalsIgnoreCase("change"))
  56. {
  57. // Change Hat
  58. if (st.hasQuestItems(10250))
  59. {
  60. st.takeItems(10250, 1); // Adventurer Hat (Event)
  61. st.giveItems(21594, 1); // Birthday Hat
  62. htmltext = null; // FIXME: Probably has html
  63. // Despawn npc
  64. npc.doDie(player);
  65. _spawns--;
  66. }
  67. else
  68. {
  69. htmltext = "32600-nohat.htm";
  70. }
  71. }
  72. return htmltext;
  73. }
  74. @Override
  75. public String onTalk(L2Npc npc, L2PcInstance player)
  76. {
  77. if (_spawns >= 3)
  78. {
  79. return "busy.htm";
  80. }
  81. QuestState st = player.getQuestState(getName());
  82. if (st == null)
  83. {
  84. st = newQuestState(player);
  85. }
  86. if (!Util.checkIfInRange(10, npc, player, true))
  87. {
  88. L2Npc spawned = st.addSpawn(32600, player.getX() + 10, player.getY() + 10, player.getZ() + 10, 0, false, 0, true);
  89. st.setState(State.STARTED);
  90. st.startQuestTimer("despawn_npc", 180000, spawned);
  91. _spawns++;
  92. }
  93. else
  94. {
  95. return "tooclose.htm";
  96. }
  97. return null;
  98. }
  99. public static void main(String[] args)
  100. {
  101. new CharacterBirthday(-1, "CharacterBirthday", "events");
  102. }
  103. }