Core.java 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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.individual;
  20. import java.util.List;
  21. import java.util.concurrent.CopyOnWriteArrayList;
  22. import ai.npc.AbstractNpcAI;
  23. import com.l2jserver.Config;
  24. import com.l2jserver.gameserver.instancemanager.GrandBossManager;
  25. import com.l2jserver.gameserver.model.StatsSet;
  26. import com.l2jserver.gameserver.model.actor.L2Attackable;
  27. import com.l2jserver.gameserver.model.actor.L2Npc;
  28. import com.l2jserver.gameserver.model.actor.instance.L2GrandBossInstance;
  29. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  30. import com.l2jserver.gameserver.network.NpcStringId;
  31. import com.l2jserver.gameserver.network.clientpackets.Say2;
  32. import com.l2jserver.gameserver.network.serverpackets.NpcSay;
  33. import com.l2jserver.gameserver.network.serverpackets.PlaySound;
  34. /**
  35. * Core AI.
  36. * @author DrLecter, Emperorc
  37. */
  38. public final class Core extends AbstractNpcAI
  39. {
  40. private static final int CORE = 29006;
  41. private static final int DEATH_KNIGHT = 29007;
  42. private static final int DOOM_WRAITH = 29008;
  43. // private static final int DICOR = 29009;
  44. // private static final int VALIDUS = 29010;
  45. private static final int SUSCEPTOR = 29011;
  46. // private static final int PERUM = 29012;
  47. // private static final int PREMO = 29013;
  48. // Core Status Tracking :
  49. private static final byte ALIVE = 0; // Core is spawned.
  50. private static final byte DEAD = 1; // Core has been killed.
  51. private static boolean _firstAttacked;
  52. private final List<L2Attackable> _minions = new CopyOnWriteArrayList<>();
  53. private Core()
  54. {
  55. super(Core.class.getSimpleName(), "ai/individual");
  56. registerMobs(CORE, DEATH_KNIGHT, DOOM_WRAITH, SUSCEPTOR);
  57. _firstAttacked = false;
  58. final StatsSet info = GrandBossManager.getInstance().getStatsSet(CORE);
  59. final int status = GrandBossManager.getInstance().getBossStatus(CORE);
  60. if (status == DEAD)
  61. {
  62. // load the unlock date and time for Core from DB
  63. long temp = (info.getLong("respawn_time") - System.currentTimeMillis());
  64. // if Core is locked until a certain time, mark it so and start the unlock timer
  65. // the unlock time has not yet expired.
  66. if (temp > 0)
  67. {
  68. startQuestTimer("core_unlock", temp, null, null);
  69. }
  70. else
  71. {
  72. // the time has already expired while the server was offline. Immediately spawn Core.
  73. L2GrandBossInstance core = (L2GrandBossInstance) addSpawn(CORE, 17726, 108915, -6480, 0, false, 0);
  74. GrandBossManager.getInstance().setBossStatus(CORE, ALIVE);
  75. spawnBoss(core);
  76. }
  77. }
  78. else
  79. {
  80. final String test = loadGlobalQuestVar("Core_Attacked");
  81. if (test.equalsIgnoreCase("true"))
  82. {
  83. _firstAttacked = true;
  84. }
  85. final int loc_x = info.getInt("loc_x");
  86. final int loc_y = info.getInt("loc_y");
  87. final int loc_z = info.getInt("loc_z");
  88. final int heading = info.getInt("heading");
  89. final int hp = info.getInt("currentHP");
  90. final int mp = info.getInt("currentMP");
  91. final L2GrandBossInstance core = (L2GrandBossInstance) addSpawn(CORE, loc_x, loc_y, loc_z, heading, false, 0);
  92. core.setCurrentHpMp(hp, mp);
  93. spawnBoss(core);
  94. }
  95. }
  96. @Override
  97. public void saveGlobalData()
  98. {
  99. saveGlobalQuestVar("Core_Attacked", Boolean.toString(_firstAttacked));
  100. }
  101. public void spawnBoss(L2GrandBossInstance npc)
  102. {
  103. GrandBossManager.getInstance().addBoss(npc);
  104. npc.broadcastPacket(new PlaySound(1, "BS01_A", 1, npc.getObjectId(), npc.getX(), npc.getY(), npc.getZ()));
  105. // Spawn minions
  106. L2Attackable mob;
  107. for (int i = 0; i < 5; i++)
  108. {
  109. final int x = 16800 + (i * 360);
  110. mob = (L2Attackable) addSpawn(DEATH_KNIGHT, x, 110000, npc.getZ(), 280 + getRandom(40), false, 0);
  111. mob.setIsRaidMinion(true);
  112. _minions.add(mob);
  113. mob = (L2Attackable) addSpawn(DEATH_KNIGHT, x, 109000, npc.getZ(), 280 + getRandom(40), false, 0);
  114. mob.setIsRaidMinion(true);
  115. _minions.add(mob);
  116. final int x2 = 16800 + (i * 600);
  117. mob = (L2Attackable) addSpawn(DOOM_WRAITH, x2, 109300, npc.getZ(), 280 + getRandom(40), false, 0);
  118. mob.setIsRaidMinion(true);
  119. _minions.add(mob);
  120. }
  121. for (int i = 0; i < 4; i++)
  122. {
  123. int x = 16800 + (i * 450);
  124. mob = (L2Attackable) addSpawn(SUSCEPTOR, x, 110300, npc.getZ(), 280 + getRandom(40), false, 0);
  125. mob.setIsRaidMinion(true);
  126. _minions.add(mob);
  127. }
  128. }
  129. @Override
  130. public String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
  131. {
  132. if (event.equalsIgnoreCase("core_unlock"))
  133. {
  134. L2GrandBossInstance core = (L2GrandBossInstance) addSpawn(CORE, 17726, 108915, -6480, 0, false, 0);
  135. GrandBossManager.getInstance().setBossStatus(CORE, ALIVE);
  136. spawnBoss(core);
  137. }
  138. else if (event.equalsIgnoreCase("spawn_minion"))
  139. {
  140. L2Attackable mob = (L2Attackable) addSpawn(npc.getId(), npc.getX(), npc.getY(), npc.getZ(), npc.getHeading(), false, 0);
  141. mob.setIsRaidMinion(true);
  142. _minions.add(mob);
  143. }
  144. else if (event.equalsIgnoreCase("despawn_minions"))
  145. {
  146. _minions.forEach(m -> m.decayMe());
  147. _minions.clear();
  148. }
  149. return super.onAdvEvent(event, npc, player);
  150. }
  151. @Override
  152. public String onAttack(L2Npc npc, L2PcInstance attacker, int damage, boolean isSummon)
  153. {
  154. if (npc.getId() == CORE)
  155. {
  156. if (_firstAttacked)
  157. {
  158. if (getRandom(100) == 0)
  159. {
  160. npc.broadcastPacket(new NpcSay(npc.getObjectId(), Say2.NPC_ALL, npc.getId(), NpcStringId.REMOVING_INTRUDERS));
  161. }
  162. }
  163. else
  164. {
  165. _firstAttacked = true;
  166. npc.broadcastPacket(new NpcSay(npc.getObjectId(), Say2.NPC_ALL, npc.getId(), NpcStringId.A_NON_PERMITTED_TARGET_HAS_BEEN_DISCOVERED));
  167. npc.broadcastPacket(new NpcSay(npc.getObjectId(), Say2.NPC_ALL, npc.getId(), NpcStringId.INTRUDER_REMOVAL_SYSTEM_INITIATED));
  168. }
  169. }
  170. return super.onAttack(npc, attacker, damage, isSummon);
  171. }
  172. @Override
  173. public String onKill(L2Npc npc, L2PcInstance killer, boolean isSummon)
  174. {
  175. if (npc.getId() == CORE)
  176. {
  177. int objId = npc.getObjectId();
  178. npc.broadcastPacket(new PlaySound(1, "BS02_D", 1, objId, npc.getX(), npc.getY(), npc.getZ()));
  179. npc.broadcastPacket(new NpcSay(objId, Say2.NPC_ALL, npc.getId(), NpcStringId.A_FATAL_ERROR_HAS_OCCURRED));
  180. npc.broadcastPacket(new NpcSay(objId, Say2.NPC_ALL, npc.getId(), NpcStringId.SYSTEM_IS_BEING_SHUT_DOWN));
  181. npc.broadcastPacket(new NpcSay(objId, Say2.NPC_ALL, npc.getId(), NpcStringId.DOT_DOT_DOT_DOT_DOT_DOT));
  182. _firstAttacked = false;
  183. GrandBossManager.getInstance().setBossStatus(CORE, DEAD);
  184. // Calculate Min and Max respawn times randomly.
  185. long respawnTime = (Config.CORE_SPAWN_INTERVAL + getRandom(-Config.CORE_SPAWN_RANDOM, Config.CORE_SPAWN_RANDOM)) * 3600000;
  186. startQuestTimer("core_unlock", respawnTime, null, null);
  187. // also save the respawn time so that the info is maintained past reboots
  188. StatsSet info = GrandBossManager.getInstance().getStatsSet(CORE);
  189. info.set("respawn_time", (System.currentTimeMillis() + respawnTime));
  190. GrandBossManager.getInstance().setStatsSet(CORE, info);
  191. startQuestTimer("despawn_minions", 20000, null, null);
  192. cancelQuestTimers("spawn_minion");
  193. }
  194. else if ((GrandBossManager.getInstance().getBossStatus(CORE) == ALIVE) && _minions.contains(npc))
  195. {
  196. _minions.remove(npc);
  197. startQuestTimer("spawn_minion", 60000, npc, null);
  198. }
  199. return super.onKill(npc, killer, isSummon);
  200. }
  201. @Override
  202. public String onSpawn(L2Npc npc)
  203. {
  204. if (npc.getId() == CORE)
  205. {
  206. npc.setIsImmobilized(true);
  207. }
  208. return super.onSpawn(npc);
  209. }
  210. public static void main(String[] args)
  211. {
  212. new Core();
  213. }
  214. }