Advertisement
Guest User

Untitled

a guest
Jul 24th, 2013
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.88 KB | None | 0 0
  1. /*
  2. * This program is free software: you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation, either version 3 of the License, or (at your option) any later
  5. * version.
  6. *
  7. * This program is distributed in the hope that it will be useful, but WITHOUT
  8. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10. * details.
  11. *
  12. * You should have received a copy of the GNU General Public License along with
  13. * this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. package ai.individual;
  16.  
  17. import ai.AbstractNpcAI;
  18.  
  19. import java.util.ArrayList;
  20. import java.util.List;
  21.  
  22. import net.sf.l2j.Config;
  23. import net.sf.l2j.gameserver.instancemanager.GrandBossManager;
  24. import net.sf.l2j.gameserver.model.actor.L2Attackable;
  25. import net.sf.l2j.gameserver.model.actor.L2Npc;
  26. import net.sf.l2j.gameserver.model.actor.instance.L2GrandBossInstance;
  27. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  28. import net.sf.l2j.gameserver.network.serverpackets.PlaySound;
  29. import net.sf.l2j.gameserver.templates.StatsSet;
  30. import net.sf.l2j.util.Rnd;
  31.  
  32. /**
  33. * Core AI
  34. * @author DrLecter Revised By Emperorc
  35. */
  36. public class Core extends AbstractNpcAI
  37. {
  38. private static final int CORE = 29006;
  39. private static final int DEATH_KNIGHT = 29007;
  40. private static final int DOOM_WRAITH = 29008;
  41. private static final int SUSCEPTOR = 29011;
  42.  
  43. private static final byte ALIVE = 0; // Core is spawned.
  44. private static final byte DEAD = 1; // Core has been killed.
  45.  
  46. List<L2Attackable> _minions = new ArrayList<>();
  47.  
  48. public Core(String name, String descr)
  49. {
  50. super(name, descr);
  51.  
  52. addAttackId(CORE);
  53. addKillId(CORE, DEATH_KNIGHT, DOOM_WRAITH, SUSCEPTOR);
  54.  
  55. final StatsSet info = GrandBossManager.getStatsSet(CORE);
  56. final int status = GrandBossManager.getBossStatus(CORE);
  57. if (status == DEAD)
  58. {
  59. // load the unlock date and time for Core from DB
  60. final long temp = (info.getLong("respawn_time") - System.currentTimeMillis());
  61. if (temp > 0)
  62. {
  63. // The time has not yet expired. Mark Core as currently locked (dead).
  64. startQuestTimer("core_unlock", temp, null, null, false);
  65. }
  66. else
  67. {
  68. // The time has expired while the server was offline. Spawn Core.
  69. final L2GrandBossInstance core = (L2GrandBossInstance) addSpawn(CORE, 17726, 108915, -6480, 0, false, 0, false);
  70. GrandBossManager.setBossStatus(CORE, ALIVE);
  71. spawnBoss(core);
  72. }
  73. }
  74. else
  75. {
  76. final int loc_x = info.getInteger("loc_x");
  77. final int loc_y = info.getInteger("loc_y");
  78. final int loc_z = info.getInteger("loc_z");
  79. final int heading = info.getInteger("heading");
  80. final int hp = info.getInteger("currentHP");
  81. final int mp = info.getInteger("currentMP");
  82.  
  83. final L2GrandBossInstance core = (L2GrandBossInstance) addSpawn(CORE, loc_x, loc_y, loc_z, heading, false, 0, false);
  84. core.setCurrentHpMp(hp, mp);
  85. spawnBoss(core);
  86. }
  87. }
  88.  
  89. public void spawnBoss(L2GrandBossInstance npc)
  90. {
  91. GrandBossManager.addBoss(npc);
  92. npc.broadcastPacket(new PlaySound(1, "BS01_A", 1, npc.getObjectId(), npc.getX(), npc.getY(), npc.getZ()));
  93.  
  94. // Spawn minions
  95. L2Attackable mob;
  96. for (int i = 0; i < 5; i++)
  97. {
  98. int x = 16800 + i * 360;
  99. mob = (L2Attackable) addSpawn(DEATH_KNIGHT, x, 110000, npc.getZ(), 280 + Rnd.get(40), false, 0, false);
  100. mob.setIsRaidMinion(true);
  101. _minions.add(mob);
  102. mob = (L2Attackable) addSpawn(DEATH_KNIGHT, x, 109000, npc.getZ(), 280 + Rnd.get(40), false, 0, false);
  103. mob.setIsRaidMinion(true);
  104. _minions.add(mob);
  105. int x2 = 16800 + i * 600;
  106. mob = (L2Attackable) addSpawn(DOOM_WRAITH, x2, 109300, npc.getZ(), 280 + Rnd.get(40), false, 0, false);
  107. mob.setIsRaidMinion(true);
  108. _minions.add(mob);
  109. }
  110.  
  111. for (int i = 0; i < 4; i++)
  112. {
  113. int x = 16800 + i * 450;
  114. mob = (L2Attackable) addSpawn(SUSCEPTOR, x, 110300, npc.getZ(), 280 + Rnd.get(40), false, 0, false);
  115. mob.setIsRaidMinion(true);
  116. _minions.add(mob);
  117. }
  118. }
  119.  
  120. @Override
  121. public String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
  122. {
  123. if (event.equalsIgnoreCase("core_unlock"))
  124. {
  125. final L2GrandBossInstance core = (L2GrandBossInstance) addSpawn(CORE, 17726, 108915, -6480, 0, false, 0, false);
  126. GrandBossManager.setBossStatus(CORE, ALIVE);
  127. spawnBoss(core);
  128. }
  129. else if (event.equalsIgnoreCase("spawn_minion"))
  130. {
  131. final L2Attackable mob = (L2Attackable) addSpawn(npc.getNpcId(), npc.getX(), npc.getY(), npc.getZ(), npc.getHeading(), false, 0, false);
  132. mob.setIsRaidMinion(true);
  133. _minions.add(mob);
  134. }
  135. else if (event.equalsIgnoreCase("despawn_minions"))
  136. {
  137. for (int i = 0; i < _minions.size(); i++)
  138. {
  139. final L2Attackable mob = _minions.get(i);
  140. if (mob != null)
  141. mob.decayMe();
  142. }
  143. _minions.clear();
  144. }
  145. return super.onAdvEvent(event, npc, player);
  146. }
  147.  
  148. @Override
  149. public String onAttack(L2Npc npc, L2PcInstance attacker, int damage, boolean isPet)
  150. {
  151. if (npc.isScriptValue(1))
  152. {
  153. if (Rnd.get(100) == 0)
  154. npc.broadcastNpcSay("Removing intruders.");
  155. }
  156. else
  157. {
  158. npc.setScriptValue(1);
  159. npc.broadcastNpcSay("A non-permitted target has been discovered.");
  160. npc.broadcastNpcSay("Starting intruder removal system.");
  161. }
  162. return super.onAttack(npc, attacker, damage, isPet);
  163. }
  164.  
  165. @Override
  166. public String onKill(L2Npc npc, L2PcInstance killer, boolean isPet)
  167. {
  168. if (npc.getNpcId() == CORE)
  169. {
  170. npc.broadcastPacket(new PlaySound(1, "BS02_D", 1, npc.getObjectId(), npc.getX(), npc.getY(), npc.getZ()));
  171. npc.broadcastNpcSay("A fatal error has occurred.");
  172. npc.broadcastNpcSay("System is being shut down...");
  173. npc.broadcastNpcSay("......");
  174.  
  175. addSpawn(31842, 16502, 110165, -6394, 0, false, 900000, false);
  176. addSpawn(31842, 18948, 110166, -6397, 0, false, 900000, false);
  177. GrandBossManager.setBossStatus(CORE, DEAD);
  178.  
  179. // time is 60hour +/- 23hour
  180. final long respawnTime = (long) Config.SPAWN_INTERVAL_CORE + Rnd.get(Config.RANDOM_SPAWN_TIME_CORE);
  181. startQuestTimer("core_unlock", respawnTime, null, null, false);
  182.  
  183. // also save the respawn time so that the info is maintained past reboots
  184. final StatsSet info = GrandBossManager.getStatsSet(CORE);
  185. info.set("respawn_time", (System.currentTimeMillis() + respawnTime));
  186. GrandBossManager.setStatsSet(CORE, info);
  187. startQuestTimer("despawn_minions", 20000, null, null, false);
  188. cancelQuestTimers("spawn_minion");
  189. }
  190. else if (GrandBossManager.getBossStatus(CORE) == ALIVE && _minions != null && _minions.contains(npc))
  191. {
  192. _minions.remove(npc);
  193. startQuestTimer("spawn_minion", 60000, npc, null, false);
  194. }
  195. return super.onKill(npc, killer, isPet);
  196. }
  197.  
  198. public static void main(String[] args)
  199. {
  200. new Core(Core.class.getSimpleName(), "ai/individual");
  201. }
  202. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement