Lindvior.java 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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 gracia.AI;
  20. import java.util.Calendar;
  21. import java.util.GregorianCalendar;
  22. import ai.npc.AbstractNpcAI;
  23. import com.l2jserver.gameserver.datatables.SpawnTable;
  24. import com.l2jserver.gameserver.model.actor.L2Npc;
  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. * Lindvior Scene AI.
  30. * @author nonom
  31. */
  32. public class Lindvior extends AbstractNpcAI
  33. {
  34. private static final int LINDVIOR_CAMERA = 18669;
  35. private static final int TOMARIS = 32552;
  36. private static final int ARTIUS = 32559;
  37. private static int LINDVIOR_SCENE_ID = 1;
  38. private static final int RESET_HOUR = 18;
  39. private static final int RESET_MIN = 58;
  40. private static final int RESET_DAY_1 = Calendar.TUESDAY;
  41. private static final int RESET_DAY_2 = Calendar.FRIDAY;
  42. private static boolean ALT_MODE = false;
  43. private static int ALT_MODE_MIN = 60; // schedule delay in minutes if ALT_MODE enabled
  44. private L2Npc _lindviorCamera = null;
  45. private L2Npc _tomaris = null;
  46. private L2Npc _artius = null;
  47. public Lindvior()
  48. {
  49. super(Lindvior.class.getSimpleName(), "gracia/AI");
  50. scheduleNextLindviorVisit();
  51. }
  52. @Override
  53. public String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
  54. {
  55. switch (event)
  56. {
  57. case "tomaris_shout1":
  58. broadcastNpcSay(npc, Say2.NPC_SHOUT, NpcStringId.HUH_THE_SKY_LOOKS_FUNNY_WHATS_THAT);
  59. break;
  60. case "artius_shout":
  61. broadcastNpcSay(npc, Say2.NPC_SHOUT, NpcStringId.A_POWERFUL_SUBORDINATE_IS_BEING_HELD_BY_THE_BARRIER_ORB_THIS_REACTION_MEANS);
  62. break;
  63. case "tomaris_shout2":
  64. broadcastNpcSay(npc, Say2.NPC_SHOUT, NpcStringId.BE_CAREFUL_SOMETHINGS_COMING);
  65. break;
  66. case "lindvior_scene":
  67. if (npc != null)
  68. {
  69. for (L2PcInstance pl : npc.getKnownList().getKnownPlayersInRadius(4000))
  70. {
  71. if ((pl.getZ() >= 1100) && (pl.getZ() <= 3100))
  72. {
  73. pl.showQuestMovie(LINDVIOR_SCENE_ID);
  74. }
  75. }
  76. }
  77. break;
  78. case "start":
  79. _lindviorCamera = SpawnTable.getInstance().findAny(LINDVIOR_CAMERA).getLastSpawn();
  80. _tomaris = SpawnTable.getInstance().findAny(TOMARIS).getLastSpawn();
  81. _artius = SpawnTable.getInstance().findAny(ARTIUS).getLastSpawn();
  82. startQuestTimer("tomaris_shout1", 1000, _tomaris, null);
  83. startQuestTimer("artius_shout", 60000, _artius, null);
  84. startQuestTimer("tomaris_shout2", 90000, _tomaris, null);
  85. startQuestTimer("lindvior_scene", 120000, _lindviorCamera, null);
  86. scheduleNextLindviorVisit();
  87. break;
  88. }
  89. return super.onAdvEvent(event, npc, player);
  90. }
  91. public void scheduleNextLindviorVisit()
  92. {
  93. long delay = (ALT_MODE) ? ALT_MODE_MIN * 60000 : scheduleNextLindviorDate();
  94. startQuestTimer("start", delay, null, null);
  95. }
  96. protected long scheduleNextLindviorDate()
  97. {
  98. GregorianCalendar date = new GregorianCalendar();
  99. date.set(Calendar.MINUTE, RESET_MIN);
  100. date.set(Calendar.HOUR_OF_DAY, RESET_HOUR);
  101. if (System.currentTimeMillis() >= date.getTimeInMillis())
  102. {
  103. date.add(Calendar.DAY_OF_WEEK, 1);
  104. }
  105. int dayOfWeek = date.get(Calendar.DAY_OF_WEEK);
  106. if (dayOfWeek <= RESET_DAY_1)
  107. {
  108. date.add(Calendar.DAY_OF_WEEK, RESET_DAY_1 - dayOfWeek);
  109. }
  110. else if (dayOfWeek <= RESET_DAY_2)
  111. {
  112. date.add(Calendar.DAY_OF_WEEK, RESET_DAY_2 - dayOfWeek);
  113. }
  114. else
  115. {
  116. date.add(Calendar.DAY_OF_WEEK, 1 + RESET_DAY_1);
  117. }
  118. return date.getTimeInMillis() - System.currentTimeMillis();
  119. }
  120. }