Alarm.java 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  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 ai.npc.Alarm;
  20. import quests.Q00184_ArtOfPersuasion.Q00184_ArtOfPersuasion;
  21. import quests.Q00185_NikolasCooperation.Q00185_NikolasCooperation;
  22. import ai.npc.AbstractNpcAI;
  23. import com.l2jserver.gameserver.enums.QuestSound;
  24. import com.l2jserver.gameserver.model.actor.L2Npc;
  25. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  26. import com.l2jserver.gameserver.model.quest.QuestState;
  27. import com.l2jserver.gameserver.network.NpcStringId;
  28. import com.l2jserver.gameserver.network.clientpackets.Say2;
  29. /**
  30. * Alarm AI for quests Art of Persuasion (184) and Nikola's Cooperation (185).
  31. * @author Zoey76
  32. */
  33. public final class Alarm extends AbstractNpcAI
  34. {
  35. // NPC
  36. private static final int ALARM = 32367;
  37. // Misc
  38. private static final int ART_OF_PERSUASION_ID = 184;
  39. private static final int NIKOLAS_COOPERATION_ID = 185;
  40. private Alarm()
  41. {
  42. super(Alarm.class.getSimpleName(), "ai/npc");
  43. addStartNpc(ALARM);
  44. addTalkId(ALARM);
  45. addFirstTalkId(ALARM);
  46. addSpawnId(ALARM);
  47. }
  48. @Override
  49. public String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
  50. {
  51. String htmltext = null;
  52. final L2PcInstance player0 = npc.getVariables().getObject("player0", L2PcInstance.class);
  53. final L2Npc npc0 = npc.getVariables().getObject("npc0", L2Npc.class);
  54. switch (event)
  55. {
  56. case "SELF_DESTRUCT_IN_60":
  57. {
  58. startQuestTimer("SELF_DESTRUCT_IN_30", 30000, npc, null);
  59. broadcastNpcSay(npc, Say2.NPC_ALL, NpcStringId.THE_ALARM_WILL_SELF_DESTRUCT_IN_60_SECONDS_ENTER_PASSCODE_TO_OVERRIDE);
  60. break;
  61. }
  62. case "SELF_DESTRUCT_IN_30":
  63. {
  64. startQuestTimer("SELF_DESTRUCT_IN_10", 20000, npc, null);
  65. broadcastNpcSay(npc, Say2.NPC_ALL, NpcStringId.THE_ALARM_WILL_SELF_DESTRUCT_IN_30_SECONDS_ENTER_PASSCODE_TO_OVERRIDE);
  66. break;
  67. }
  68. case "SELF_DESTRUCT_IN_10":
  69. {
  70. startQuestTimer("RECORDER_CRUSHED", 10000, npc, null);
  71. broadcastNpcSay(npc, Say2.NPC_ALL, NpcStringId.THE_ALARM_WILL_SELF_DESTRUCT_IN_10_SECONDS_ENTER_PASSCODE_TO_OVERRIDE);
  72. break;
  73. }
  74. case "RECORDER_CRUSHED":
  75. {
  76. if (npc0 != null)
  77. {
  78. if (npc0.getVariables().getBoolean("SPAWNED"))
  79. {
  80. npc0.getVariables().set("SPAWNED", false);
  81. if (player0 != null)
  82. {
  83. broadcastNpcSay(npc, Say2.NPC_ALL, NpcStringId.RECORDER_CRUSHED);
  84. if (verifyMemoState(player0, ART_OF_PERSUASION_ID, -1))
  85. {
  86. setMemoState(player0, ART_OF_PERSUASION_ID, 5);
  87. }
  88. else if (verifyMemoState(player0, NIKOLAS_COOPERATION_ID, -1))
  89. {
  90. setMemoState(player0, NIKOLAS_COOPERATION_ID, 5);
  91. }
  92. }
  93. }
  94. }
  95. npc.deleteMe();
  96. break;
  97. }
  98. case "32367-184_04.html":
  99. case "32367-184_06.html":
  100. case "32367-184_08.html":
  101. {
  102. htmltext = event;
  103. break;
  104. }
  105. case "2":
  106. {
  107. if (player0 == player)
  108. {
  109. if (verifyMemoState(player, ART_OF_PERSUASION_ID, 3))
  110. {
  111. htmltext = "32367-184_02.html";
  112. }
  113. else if (verifyMemoState(player, NIKOLAS_COOPERATION_ID, 3))
  114. {
  115. htmltext = "32367-185_02.html";
  116. }
  117. }
  118. break;
  119. }
  120. case "3":
  121. {
  122. if (verifyMemoState(player, ART_OF_PERSUASION_ID, 3))
  123. {
  124. setMemoStateEx(player, ART_OF_PERSUASION_ID, 1, 1);
  125. htmltext = "32367-184_04.html";
  126. }
  127. else if (verifyMemoState(player, NIKOLAS_COOPERATION_ID, 3))
  128. {
  129. setMemoStateEx(player, NIKOLAS_COOPERATION_ID, 1, 1);
  130. htmltext = "32367-185_04.html";
  131. }
  132. break;
  133. }
  134. case "4":
  135. {
  136. if (verifyMemoState(player, ART_OF_PERSUASION_ID, 3))
  137. {
  138. setMemoStateEx(player, ART_OF_PERSUASION_ID, 1, getMemoStateEx(player, ART_OF_PERSUASION_ID, 1) + 1);
  139. htmltext = "32367-184_06.html";
  140. }
  141. else if (verifyMemoState(player, NIKOLAS_COOPERATION_ID, 3))
  142. {
  143. setMemoStateEx(player, NIKOLAS_COOPERATION_ID, 1, getMemoStateEx(player, NIKOLAS_COOPERATION_ID, 1) + 1);
  144. htmltext = "32367-185_06.html";
  145. }
  146. break;
  147. }
  148. case "5":
  149. {
  150. if (verifyMemoState(player, ART_OF_PERSUASION_ID, 3))
  151. {
  152. setMemoStateEx(player, ART_OF_PERSUASION_ID, 1, getMemoStateEx(player, ART_OF_PERSUASION_ID, 1) + 1);
  153. htmltext = "32367-184_08.html";
  154. }
  155. else if (verifyMemoState(player, NIKOLAS_COOPERATION_ID, 3))
  156. {
  157. setMemoStateEx(player, NIKOLAS_COOPERATION_ID, 1, getMemoStateEx(player, NIKOLAS_COOPERATION_ID, 1) + 1);
  158. htmltext = "32367-185_08.html";
  159. }
  160. break;
  161. }
  162. case "6":
  163. {
  164. if (verifyMemoState(player, ART_OF_PERSUASION_ID, 3))
  165. {
  166. int i0 = getMemoStateEx(player, ART_OF_PERSUASION_ID, 1);
  167. if (i0 >= 3)
  168. {
  169. if ((npc0 != null) && npc0.getVariables().getBoolean("SPAWNED"))
  170. {
  171. npc0.getVariables().set("SPAWNED", false);
  172. }
  173. npc.deleteMe();
  174. setMemoState(player, ART_OF_PERSUASION_ID, 4);
  175. htmltext = "32367-184_09.html";
  176. }
  177. else
  178. {
  179. setMemoStateEx(player, ART_OF_PERSUASION_ID, 1, 0);
  180. htmltext = "32367-184_10.html";
  181. }
  182. }
  183. else if (verifyMemoState(player, NIKOLAS_COOPERATION_ID, 3))
  184. {
  185. int i0 = getMemoStateEx(player, NIKOLAS_COOPERATION_ID, 1);
  186. if (i0 >= 3)
  187. {
  188. if ((npc0 != null) && npc0.getVariables().getBoolean("SPAWNED"))
  189. {
  190. npc0.getVariables().set("SPAWNED", false);
  191. }
  192. npc.deleteMe();
  193. setMemoState(player, NIKOLAS_COOPERATION_ID, 4);
  194. htmltext = "32367-185_09.html";
  195. }
  196. else
  197. {
  198. setMemoStateEx(player, NIKOLAS_COOPERATION_ID, 1, 0);
  199. htmltext = "32367-185_10.html";
  200. }
  201. }
  202. break;
  203. }
  204. }
  205. return htmltext;
  206. }
  207. @Override
  208. public String onFirstTalk(L2Npc npc, L2PcInstance talker)
  209. {
  210. String htmltext = getNoQuestMsg(talker);
  211. if (verifyMemoState(talker, ART_OF_PERSUASION_ID, 3) || verifyMemoState(talker, NIKOLAS_COOPERATION_ID, 3))
  212. {
  213. final L2PcInstance player = npc.getVariables().getObject("player0", L2PcInstance.class);
  214. if (player == talker)
  215. {
  216. htmltext = "32367-01.html";
  217. }
  218. else
  219. {
  220. htmltext = "32367-02.html";
  221. }
  222. }
  223. return htmltext;
  224. }
  225. @Override
  226. public String onSpawn(L2Npc npc)
  227. {
  228. startQuestTimer("SELF_DESTRUCT_IN_60", 60000, npc, null);
  229. broadcastNpcSay(npc, Say2.NPC_ALL, NpcStringId.INTRUDER_ALERT_THE_ALARM_WILL_SELF_DESTRUCT_IN_2_MINUTES);
  230. final L2PcInstance player = npc.getVariables().getObject("player0", L2PcInstance.class);
  231. if (player != null)
  232. {
  233. playSound(player, QuestSound.ITEMSOUND_SIREN);
  234. }
  235. return super.onSpawn(npc);
  236. }
  237. /**
  238. * Verifies if the given player has the require memo state.
  239. * @param player the player
  240. * @param questId the quest ID
  241. * @param memoState the memo state, if memo state is less than zero, only quest state is checked
  242. * @return {@code true} if the player has the memo state, {@code false} otherwise
  243. */
  244. private static final boolean verifyMemoState(L2PcInstance player, int questId, int memoState)
  245. {
  246. QuestState qs = null;
  247. switch (questId)
  248. {
  249. case ART_OF_PERSUASION_ID:
  250. {
  251. qs = player.getQuestState(Q00184_ArtOfPersuasion.class.getSimpleName());
  252. break;
  253. }
  254. case NIKOLAS_COOPERATION_ID:
  255. {
  256. qs = player.getQuestState(Q00185_NikolasCooperation.class.getSimpleName());
  257. break;
  258. }
  259. }
  260. return (qs != null) && ((memoState < 0) || qs.isMemoState(memoState));
  261. }
  262. /**
  263. * Sets the memo state for the given player and quest.
  264. * @param player the player
  265. * @param questId the quest ID
  266. * @param memoState the memo state
  267. */
  268. private static final void setMemoState(L2PcInstance player, int questId, int memoState)
  269. {
  270. QuestState qs = null;
  271. switch (questId)
  272. {
  273. case ART_OF_PERSUASION_ID:
  274. {
  275. qs = player.getQuestState(Q00184_ArtOfPersuasion.class.getSimpleName());
  276. break;
  277. }
  278. case NIKOLAS_COOPERATION_ID:
  279. {
  280. qs = player.getQuestState(Q00185_NikolasCooperation.class.getSimpleName());
  281. break;
  282. }
  283. }
  284. if (qs != null)
  285. {
  286. qs.setMemoState(memoState);
  287. }
  288. }
  289. /**
  290. * Gets the memo state ex for the given player, quest and slot.
  291. * @param player the player
  292. * @param questId the quest ID
  293. * @param slot the slot
  294. * @return the memo state ex
  295. */
  296. private static final int getMemoStateEx(L2PcInstance player, int questId, int slot)
  297. {
  298. QuestState qs = null;
  299. switch (questId)
  300. {
  301. case ART_OF_PERSUASION_ID:
  302. {
  303. qs = player.getQuestState(Q00184_ArtOfPersuasion.class.getSimpleName());
  304. break;
  305. }
  306. case NIKOLAS_COOPERATION_ID:
  307. {
  308. qs = player.getQuestState(Q00185_NikolasCooperation.class.getSimpleName());
  309. break;
  310. }
  311. }
  312. return (qs != null) ? qs.getMemoStateEx(slot) : -1;
  313. }
  314. /**
  315. * Sets the memo state ex for the given player and quest.
  316. * @param player the player
  317. * @param questId the quest ID
  318. * @param slot the slot
  319. * @param memoStateEx the memo state ex
  320. */
  321. private static final void setMemoStateEx(L2PcInstance player, int questId, int slot, int memoStateEx)
  322. {
  323. QuestState qs = null;
  324. switch (questId)
  325. {
  326. case ART_OF_PERSUASION_ID:
  327. {
  328. qs = player.getQuestState(Q00184_ArtOfPersuasion.class.getSimpleName());
  329. break;
  330. }
  331. case NIKOLAS_COOPERATION_ID:
  332. {
  333. qs = player.getQuestState(Q00185_NikolasCooperation.class.getSimpleName());
  334. break;
  335. }
  336. }
  337. if (qs != null)
  338. {
  339. qs.setMemoStateEx(slot, memoStateEx);
  340. }
  341. }
  342. public static void main(String[] args)
  343. {
  344. new Alarm();
  345. }
  346. }