Natives.java 5.5 KB

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