Natives.java 5.0 KB

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