Natives.java 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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 hellbound.Natives;
  20. import com.l2jserver.gameserver.datatables.DoorTable;
  21. import com.l2jserver.gameserver.instancemanager.HellboundManager;
  22. import com.l2jserver.gameserver.model.actor.L2Npc;
  23. import com.l2jserver.gameserver.model.actor.instance.L2DoorInstance;
  24. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  25. import com.l2jserver.gameserver.model.quest.Quest;
  26. import com.l2jserver.gameserver.model.quest.QuestState;
  27. import com.l2jserver.gameserver.network.NpcStringId;
  28. import com.l2jserver.gameserver.network.clientpackets.Say2;
  29. import com.l2jserver.gameserver.network.serverpackets.NpcSay;
  30. /**
  31. * This class manages Natives' behavior up to 9 level of Hellbound. 10 level are handled in Hellbound Town.
  32. * @author DS, GKR
  33. */
  34. public class Natives extends Quest
  35. {
  36. private static final int NATIVE = 32362;
  37. private static final int INSURGENT = 32363;
  38. private static final int TRAITOR = 32364;
  39. private static final int INCASTLE = 32357;
  40. private static final int MARK_OF_BETRAYAL = 9676;
  41. private static final int BADGES = 9674;
  42. private static final int[] doors =
  43. {
  44. 19250003,
  45. 19250004
  46. };
  47. @Override
  48. public final String onFirstTalk(L2Npc npc, L2PcInstance player)
  49. {
  50. String htmltext = "";
  51. final int hellboundLevel = HellboundManager.getInstance().getLevel();
  52. final int npcId = npc.getId();
  53. QuestState qs = player.getQuestState(getName());
  54. if (qs == null)
  55. {
  56. qs = newQuestState(player);
  57. }
  58. switch (npcId)
  59. {
  60. case NATIVE:
  61. htmltext = hellboundLevel > 5 ? "32362-01.htm" : "32362.htm";
  62. break;
  63. case INSURGENT:
  64. htmltext = hellboundLevel > 5 ? "32363-01.htm" : "32363.htm";
  65. break;
  66. case INCASTLE:
  67. if (hellboundLevel < 9)
  68. {
  69. htmltext = "32357-01a.htm";
  70. }
  71. else if (hellboundLevel == 9)
  72. {
  73. htmltext = npc.isBusy() ? "32357-02.htm" : "32357-01.htm";
  74. }
  75. else
  76. {
  77. htmltext = "32357-01b.htm";
  78. }
  79. break;
  80. }
  81. return htmltext;
  82. }
  83. @Override
  84. public final String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
  85. {
  86. String htmltext = null;
  87. if (npc.getId() == TRAITOR)
  88. {
  89. if (event.equalsIgnoreCase("open_door"))
  90. {
  91. final QuestState qs = player.getQuestState(getName());
  92. if (qs.getQuestItemsCount(MARK_OF_BETRAYAL) >= 10)
  93. {
  94. qs.takeItems(MARK_OF_BETRAYAL, 10);
  95. npc.broadcastPacket(new NpcSay(npc.getObjectId(), Say2.NPC_ALL, npc.getId(), NpcStringId.ALRIGHT_NOW_LEODAS_IS_YOURS));
  96. HellboundManager.getInstance().updateTrust(-50, true);
  97. for (int doorId : doors)
  98. {
  99. L2DoorInstance door = DoorTable.getInstance().getDoor(doorId);
  100. if (door != null)
  101. {
  102. door.openMe();
  103. }
  104. }
  105. cancelQuestTimers("close_doors");
  106. startQuestTimer("close_doors", 1800000, npc, player); // 30 min
  107. }
  108. else if (qs.hasQuestItems(MARK_OF_BETRAYAL))
  109. {
  110. htmltext = "32364-01.htm";
  111. }
  112. else
  113. {
  114. htmltext = "32364-02.htm";
  115. }
  116. }
  117. else if (event.equalsIgnoreCase("close_doors"))
  118. {
  119. for (int doorId : doors)
  120. {
  121. L2DoorInstance door = DoorTable.getInstance().getDoor(doorId);
  122. if (door != null)
  123. {
  124. door.closeMe();
  125. }
  126. }
  127. }
  128. }
  129. else if ((npc.getId() == NATIVE) && event.equalsIgnoreCase("hungry_death"))
  130. {
  131. npc.broadcastPacket(new NpcSay(npc.getObjectId(), Say2.NPC_ALL, npc.getId(), NpcStringId.HUN_HUNGRY));
  132. npc.doDie(null);
  133. }
  134. else if (npc.getId() == INCASTLE)
  135. {
  136. if (event.equalsIgnoreCase("FreeSlaves"))
  137. {
  138. final QuestState qs = player.getQuestState(getName());
  139. if (qs.getQuestItemsCount(BADGES) >= 5)
  140. {
  141. qs.takeItems(BADGES, 5);
  142. npc.setBusy(true); // Prevent Native from take items more, than once
  143. HellboundManager.getInstance().updateTrust(100, true);
  144. htmltext = "32357-02.htm";
  145. startQuestTimer("delete_me", 3000, npc, null);
  146. }
  147. else
  148. {
  149. htmltext = "32357-02a.htm";
  150. }
  151. }
  152. else if (event.equalsIgnoreCase("delete_me"))
  153. {
  154. npc.setBusy(false); // TODO: Does it really need?
  155. npc.deleteMe();
  156. npc.getSpawn().decreaseCount(npc);
  157. }
  158. }
  159. return htmltext;
  160. }
  161. @Override
  162. public final String onSpawn(L2Npc npc)
  163. {
  164. if ((npc.getId() == NATIVE) && (HellboundManager.getInstance().getLevel() < 6))
  165. {
  166. startQuestTimer("hungry_death", 600000, npc, null);
  167. }
  168. return super.onSpawn(npc);
  169. }
  170. public Natives(int questId, String name, String descr)
  171. {
  172. super(questId, name, descr);
  173. addFirstTalkId(NATIVE);
  174. addFirstTalkId(INSURGENT);
  175. addFirstTalkId(INCASTLE);
  176. addStartNpc(TRAITOR);
  177. addStartNpc(INCASTLE);
  178. addTalkId(TRAITOR);
  179. addTalkId(INCASTLE);
  180. addSpawnId(NATIVE);
  181. }
  182. public static void main(String[] args)
  183. {
  184. new Natives(-1, "Natives", "hellbound");
  185. }
  186. }