123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359 |
- /*
- * Copyright (C) 2004-2015 L2J DataPack
- *
- * This file is part of L2J DataPack.
- *
- * L2J DataPack is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * L2J DataPack is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- package ai.npc.Alarm;
- import quests.Q00184_ArtOfPersuasion.Q00184_ArtOfPersuasion;
- import quests.Q00185_NikolasCooperation.Q00185_NikolasCooperation;
- import ai.npc.AbstractNpcAI;
- import com.l2jserver.gameserver.enums.QuestSound;
- import com.l2jserver.gameserver.model.actor.L2Npc;
- import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
- import com.l2jserver.gameserver.model.quest.QuestState;
- import com.l2jserver.gameserver.network.NpcStringId;
- import com.l2jserver.gameserver.network.clientpackets.Say2;
- /**
- * Alarm AI for quests Art of Persuasion (184) and Nikola's Cooperation (185).
- * @author Zoey76
- */
- public final class Alarm extends AbstractNpcAI
- {
- // NPC
- private static final int ALARM = 32367;
- // Misc
- private static final int ART_OF_PERSUASION_ID = 184;
- private static final int NIKOLAS_COOPERATION_ID = 185;
-
- private Alarm()
- {
- super(Alarm.class.getSimpleName(), "ai/npc");
- addStartNpc(ALARM);
- addTalkId(ALARM);
- addFirstTalkId(ALARM);
- addSpawnId(ALARM);
- }
-
- @Override
- public String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
- {
- String htmltext = null;
- final L2PcInstance player0 = npc.getVariables().getObject("player0", L2PcInstance.class);
- final L2Npc npc0 = npc.getVariables().getObject("npc0", L2Npc.class);
- switch (event)
- {
- case "SELF_DESTRUCT_IN_60":
- {
- startQuestTimer("SELF_DESTRUCT_IN_30", 30000, npc, null);
- broadcastNpcSay(npc, Say2.NPC_ALL, NpcStringId.THE_ALARM_WILL_SELF_DESTRUCT_IN_60_SECONDS_ENTER_PASSCODE_TO_OVERRIDE);
- break;
- }
- case "SELF_DESTRUCT_IN_30":
- {
- startQuestTimer("SELF_DESTRUCT_IN_10", 20000, npc, null);
- broadcastNpcSay(npc, Say2.NPC_ALL, NpcStringId.THE_ALARM_WILL_SELF_DESTRUCT_IN_30_SECONDS_ENTER_PASSCODE_TO_OVERRIDE);
- break;
- }
- case "SELF_DESTRUCT_IN_10":
- {
- startQuestTimer("RECORDER_CRUSHED", 10000, npc, null);
- broadcastNpcSay(npc, Say2.NPC_ALL, NpcStringId.THE_ALARM_WILL_SELF_DESTRUCT_IN_10_SECONDS_ENTER_PASSCODE_TO_OVERRIDE);
- break;
- }
- case "RECORDER_CRUSHED":
- {
- if (npc0 != null)
- {
- if (npc0.getVariables().getBoolean("SPAWNED"))
- {
- npc0.getVariables().set("SPAWNED", false);
- if (player0 != null)
- {
- broadcastNpcSay(npc, Say2.NPC_ALL, NpcStringId.RECORDER_CRUSHED);
- if (verifyMemoState(player0, ART_OF_PERSUASION_ID, -1))
- {
- setMemoState(player0, ART_OF_PERSUASION_ID, 5);
- }
- else if (verifyMemoState(player0, NIKOLAS_COOPERATION_ID, -1))
- {
- setMemoState(player0, NIKOLAS_COOPERATION_ID, 5);
- }
- }
- }
- }
- npc.deleteMe();
- break;
- }
- case "32367-184_04.html":
- case "32367-184_06.html":
- case "32367-184_08.html":
- {
- htmltext = event;
- break;
- }
- case "2":
- {
- if (player0 == player)
- {
- if (verifyMemoState(player, ART_OF_PERSUASION_ID, 3))
- {
- htmltext = "32367-184_02.html";
- }
- else if (verifyMemoState(player, NIKOLAS_COOPERATION_ID, 3))
- {
- htmltext = "32367-185_02.html";
- }
- }
- break;
- }
- case "3":
- {
- if (verifyMemoState(player, ART_OF_PERSUASION_ID, 3))
- {
- setMemoStateEx(player, ART_OF_PERSUASION_ID, 1, 1);
- htmltext = "32367-184_04.html";
- }
- else if (verifyMemoState(player, NIKOLAS_COOPERATION_ID, 3))
- {
- setMemoStateEx(player, NIKOLAS_COOPERATION_ID, 1, 1);
- htmltext = "32367-185_04.html";
- }
- break;
- }
- case "4":
- {
- if (verifyMemoState(player, ART_OF_PERSUASION_ID, 3))
- {
- setMemoStateEx(player, ART_OF_PERSUASION_ID, 1, getMemoStateEx(player, ART_OF_PERSUASION_ID, 1) + 1);
- htmltext = "32367-184_06.html";
- }
- else if (verifyMemoState(player, NIKOLAS_COOPERATION_ID, 3))
- {
- setMemoStateEx(player, NIKOLAS_COOPERATION_ID, 1, getMemoStateEx(player, NIKOLAS_COOPERATION_ID, 1) + 1);
- htmltext = "32367-185_06.html";
- }
- break;
- }
- case "5":
- {
- if (verifyMemoState(player, ART_OF_PERSUASION_ID, 3))
- {
- setMemoStateEx(player, ART_OF_PERSUASION_ID, 1, getMemoStateEx(player, ART_OF_PERSUASION_ID, 1) + 1);
- htmltext = "32367-184_08.html";
- }
- else if (verifyMemoState(player, NIKOLAS_COOPERATION_ID, 3))
- {
- setMemoStateEx(player, NIKOLAS_COOPERATION_ID, 1, getMemoStateEx(player, NIKOLAS_COOPERATION_ID, 1) + 1);
- htmltext = "32367-185_08.html";
- }
- break;
- }
- case "6":
- {
- if (verifyMemoState(player, ART_OF_PERSUASION_ID, 3))
- {
- int i0 = getMemoStateEx(player, ART_OF_PERSUASION_ID, 1);
- if (i0 >= 3)
- {
- if ((npc0 != null) && npc0.getVariables().getBoolean("SPAWNED"))
- {
- npc0.getVariables().set("SPAWNED", false);
- }
- npc.deleteMe();
- setMemoState(player, ART_OF_PERSUASION_ID, 4);
- htmltext = "32367-184_09.html";
- }
- else
- {
- setMemoStateEx(player, ART_OF_PERSUASION_ID, 1, 0);
- htmltext = "32367-184_10.html";
- }
- }
- else if (verifyMemoState(player, NIKOLAS_COOPERATION_ID, 3))
- {
- int i0 = getMemoStateEx(player, NIKOLAS_COOPERATION_ID, 1);
- if (i0 >= 3)
- {
- if ((npc0 != null) && npc0.getVariables().getBoolean("SPAWNED"))
- {
- npc0.getVariables().set("SPAWNED", false);
- }
-
- npc.deleteMe();
- setMemoState(player, NIKOLAS_COOPERATION_ID, 4);
- htmltext = "32367-185_09.html";
- }
- else
- {
- setMemoStateEx(player, NIKOLAS_COOPERATION_ID, 1, 0);
- htmltext = "32367-185_10.html";
- }
- }
- break;
- }
- }
- return htmltext;
- }
-
- @Override
- public String onFirstTalk(L2Npc npc, L2PcInstance talker)
- {
- String htmltext = getNoQuestMsg(talker);
- if (verifyMemoState(talker, ART_OF_PERSUASION_ID, 3) || verifyMemoState(talker, NIKOLAS_COOPERATION_ID, 3))
- {
- final L2PcInstance player = npc.getVariables().getObject("player0", L2PcInstance.class);
- if (player == talker)
- {
- htmltext = "32367-01.html";
- }
- else
- {
- htmltext = "32367-02.html";
- }
- }
- return htmltext;
- }
-
- @Override
- public String onSpawn(L2Npc npc)
- {
- startQuestTimer("SELF_DESTRUCT_IN_60", 60000, npc, null);
- broadcastNpcSay(npc, Say2.NPC_ALL, NpcStringId.INTRUDER_ALERT_THE_ALARM_WILL_SELF_DESTRUCT_IN_2_MINUTES);
- final L2PcInstance player = npc.getVariables().getObject("player0", L2PcInstance.class);
- if (player != null)
- {
- playSound(player, QuestSound.ITEMSOUND_SIREN);
- }
- return super.onSpawn(npc);
- }
-
- /**
- * Verifies if the given player has the require memo state.
- * @param player the player
- * @param questId the quest ID
- * @param memoState the memo state, if memo state is less than zero, only quest state is checked
- * @return {@code true} if the player has the memo state, {@code false} otherwise
- */
- private static final boolean verifyMemoState(L2PcInstance player, int questId, int memoState)
- {
- QuestState qs = null;
- switch (questId)
- {
- case ART_OF_PERSUASION_ID:
- {
- qs = player.getQuestState(Q00184_ArtOfPersuasion.class.getSimpleName());
- break;
- }
- case NIKOLAS_COOPERATION_ID:
- {
- qs = player.getQuestState(Q00185_NikolasCooperation.class.getSimpleName());
- break;
- }
- }
- return (qs != null) && ((memoState < 0) || qs.isMemoState(memoState));
- }
-
- /**
- * Sets the memo state for the given player and quest.
- * @param player the player
- * @param questId the quest ID
- * @param memoState the memo state
- */
- private static final void setMemoState(L2PcInstance player, int questId, int memoState)
- {
- QuestState qs = null;
- switch (questId)
- {
- case ART_OF_PERSUASION_ID:
- {
- qs = player.getQuestState(Q00184_ArtOfPersuasion.class.getSimpleName());
- break;
- }
- case NIKOLAS_COOPERATION_ID:
- {
- qs = player.getQuestState(Q00185_NikolasCooperation.class.getSimpleName());
- break;
- }
- }
- if (qs != null)
- {
- qs.setMemoState(memoState);
- }
- }
-
- /**
- * Gets the memo state ex for the given player, quest and slot.
- * @param player the player
- * @param questId the quest ID
- * @param slot the slot
- * @return the memo state ex
- */
- private static final int getMemoStateEx(L2PcInstance player, int questId, int slot)
- {
- QuestState qs = null;
- switch (questId)
- {
- case ART_OF_PERSUASION_ID:
- {
- qs = player.getQuestState(Q00184_ArtOfPersuasion.class.getSimpleName());
- break;
- }
- case NIKOLAS_COOPERATION_ID:
- {
- qs = player.getQuestState(Q00185_NikolasCooperation.class.getSimpleName());
- break;
- }
- }
- return (qs != null) ? qs.getMemoStateEx(slot) : -1;
- }
-
- /**
- * Sets the memo state ex for the given player and quest.
- * @param player the player
- * @param questId the quest ID
- * @param slot the slot
- * @param memoStateEx the memo state ex
- */
- private static final void setMemoStateEx(L2PcInstance player, int questId, int slot, int memoStateEx)
- {
- QuestState qs = null;
- switch (questId)
- {
- case ART_OF_PERSUASION_ID:
- {
- qs = player.getQuestState(Q00184_ArtOfPersuasion.class.getSimpleName());
- break;
- }
- case NIKOLAS_COOPERATION_ID:
- {
- qs = player.getQuestState(Q00185_NikolasCooperation.class.getSimpleName());
- break;
- }
- }
- if (qs != null)
- {
- qs.setMemoStateEx(slot, memoStateEx);
- }
- }
-
- public static void main(String[] args)
- {
- new Alarm();
- }
- }
|