Antharas.java 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911
  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. import gnu.trove.TIntObjectHashMap;
  17. import java.util.Collection;
  18. import java.util.List;
  19. import java.util.concurrent.ScheduledFuture;
  20. import javolution.util.FastList;
  21. import ai.group_template.L2AttackableAIScript;
  22. import com.l2jserver.Config;
  23. import com.l2jserver.gameserver.GeoData;
  24. import com.l2jserver.gameserver.ThreadPoolManager;
  25. import com.l2jserver.gameserver.ai.CtrlIntention;
  26. import com.l2jserver.gameserver.datatables.NpcTable;
  27. import com.l2jserver.gameserver.datatables.SkillTable;
  28. import com.l2jserver.gameserver.datatables.SpawnTable;
  29. import com.l2jserver.gameserver.instancemanager.GrandBossManager;
  30. import com.l2jserver.gameserver.model.L2CharPosition;
  31. import com.l2jserver.gameserver.model.L2Skill;
  32. import com.l2jserver.gameserver.model.L2Spawn;
  33. import com.l2jserver.gameserver.model.L2World;
  34. import com.l2jserver.gameserver.model.actor.L2Character;
  35. import com.l2jserver.gameserver.model.actor.L2Npc;
  36. import com.l2jserver.gameserver.model.actor.instance.L2GrandBossInstance;
  37. import com.l2jserver.gameserver.model.actor.instance.L2MonsterInstance;
  38. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  39. import com.l2jserver.gameserver.model.zone.type.L2BossZone;
  40. import com.l2jserver.gameserver.network.serverpackets.Earthquake;
  41. import com.l2jserver.gameserver.network.serverpackets.L2GameServerPacket;
  42. import com.l2jserver.gameserver.network.serverpackets.PlaySound;
  43. import com.l2jserver.gameserver.network.serverpackets.SpecialCamera;
  44. import com.l2jserver.gameserver.templates.StatsSet;
  45. import com.l2jserver.gameserver.templates.chars.L2NpcTemplate;
  46. import com.l2jserver.util.Rnd;
  47. /**
  48. *
  49. * This class ... control for sequence of fight against Antharas.
  50. *
  51. * @version $Revision: $ $Date: $
  52. * @author L2J_JP SANDMAN
  53. */
  54. public class Antharas extends L2AttackableAIScript
  55. {
  56. // config
  57. private static final int FWA_ACTIVITYTIMEOFANTHARAS = 120;
  58. //private static final int FWA_APPTIMEOFANTHARAS = 1800000;
  59. private static final int FWA_INACTIVITYTIME = 900000;
  60. private static final boolean FWA_OLDANTHARAS = false;
  61. private static final boolean FWA_MOVEATRANDOM = true;
  62. private static final boolean FWA_DOSERVEREARTHQUAKE = true;
  63. private static final int FWA_LIMITOFWEAK = 45;
  64. private static final int FWA_LIMITOFNORMAL = 63;
  65. private static final int FWA_MAXMOBS = 10; // this includes Antharas itself
  66. private static final int FWA_INTERVALOFMOBSWEAK = 180000;
  67. private static final int FWA_INTERVALOFMOBSNORMAL = 150000;
  68. private static final int FWA_INTERVALOFMOBSSTRONG = 120000;
  69. private static final int FWA_PERCENTOFBEHEMOTH = 60;
  70. private static final int FWA_SELFDESTRUCTTIME = 15000;
  71. // Location of teleport cube.
  72. private final int _teleportCubeId = 31859;
  73. private final int _teleportCubeLocation[][] = { { 177615, 114941, -7709, 0 } };
  74. protected List<L2Spawn> _teleportCubeSpawn = new FastList<L2Spawn>();
  75. protected List<L2Npc> _teleportCube = new FastList<L2Npc>();
  76. // Spawn data of monsters.
  77. protected TIntObjectHashMap<L2Spawn> _monsterSpawn = new TIntObjectHashMap<L2Spawn>();
  78. // Instance of monsters.
  79. protected List<L2Npc> _monsters = new FastList<L2Npc>();
  80. protected L2GrandBossInstance _antharas = null;
  81. // monstersId
  82. private static final int ANTHARASOLDID = 29019;
  83. private static final int ANTHARASWEAKID = 29066;
  84. private static final int ANTHARASNORMALID = 29067;
  85. private static final int ANTHARASSTRONGID = 29068;
  86. // Tasks.
  87. protected ScheduledFuture<?> _cubeSpawnTask = null;
  88. protected ScheduledFuture<?> _monsterSpawnTask = null;
  89. protected ScheduledFuture<?> _activityCheckTask = null;
  90. protected ScheduledFuture<?> _socialTask = null;
  91. protected ScheduledFuture<?> _mobiliseTask = null;
  92. protected ScheduledFuture<?> _mobsSpawnTask = null;
  93. protected ScheduledFuture<?> _selfDestructionTask = null;
  94. protected ScheduledFuture<?> _moveAtRandomTask = null;
  95. protected ScheduledFuture<?> _movieTask = null;
  96. //Antharas Status Tracking :
  97. private static final byte DORMANT = 0; //Antharas is spawned and no one has entered yet. Entry is unlocked
  98. private static final byte WAITING = 1; //Antharas is spawend and someone has entered, triggering a 30 minute window for additional people to enter
  99. //before he unleashes his attack. Entry is unlocked
  100. private static final byte FIGHTING = 2; //Antharas is engaged in battle, annihilating his foes. Entry is locked
  101. private static final byte DEAD = 3; //Antharas has been killed. Entry is locked
  102. protected static long _LastAction = 0;
  103. protected static L2BossZone _Zone;
  104. public static void main(String[] args)
  105. {
  106. // now call the constructor (starts up the ai)
  107. new Antharas(-1,"antharas","ai");
  108. }
  109. // Boss: Antharas
  110. public Antharas(int id,String name,String descr)
  111. {
  112. super(id,name,descr);
  113. int[] mob = {ANTHARASOLDID,ANTHARASWEAKID,ANTHARASNORMALID,ANTHARASSTRONGID,29069,29070,29071,29072,29073,29074,29075,29076};
  114. this.registerMobs(mob);
  115. init();
  116. }
  117. // Initialize
  118. private void init()
  119. {
  120. // Setting spawn data of monsters.
  121. try
  122. {
  123. _Zone = GrandBossManager.getInstance().getZone(179700,113800,-7709);
  124. L2NpcTemplate template1;
  125. L2Spawn tempSpawn;
  126. // Old Antharas
  127. template1 = NpcTable.getInstance().getTemplate(ANTHARASOLDID);
  128. tempSpawn = new L2Spawn(template1);
  129. tempSpawn.setLocx(181323);
  130. tempSpawn.setLocy(114850);
  131. tempSpawn.setLocz(-7623);
  132. tempSpawn.setHeading(32542);
  133. tempSpawn.setAmount(1);
  134. tempSpawn.setRespawnDelay(FWA_ACTIVITYTIMEOFANTHARAS * 2);
  135. SpawnTable.getInstance().addNewSpawn(tempSpawn, false);
  136. _monsterSpawn.put(29019, tempSpawn);
  137. // Weak Antharas
  138. template1 = NpcTable.getInstance().getTemplate(ANTHARASWEAKID);
  139. tempSpawn = new L2Spawn(template1);
  140. tempSpawn.setLocx(181323);
  141. tempSpawn.setLocy(114850);
  142. tempSpawn.setLocz(-7623);
  143. tempSpawn.setHeading(32542);
  144. tempSpawn.setAmount(1);
  145. tempSpawn.setRespawnDelay(FWA_ACTIVITYTIMEOFANTHARAS * 2);
  146. SpawnTable.getInstance().addNewSpawn(tempSpawn, false);
  147. _monsterSpawn.put(29066, tempSpawn);
  148. // Normal Antharas
  149. template1 = NpcTable.getInstance().getTemplate(ANTHARASNORMALID);
  150. tempSpawn = new L2Spawn(template1);
  151. tempSpawn.setLocx(181323);
  152. tempSpawn.setLocy(114850);
  153. tempSpawn.setLocz(-7623);
  154. tempSpawn.setHeading(32542);
  155. tempSpawn.setAmount(1);
  156. tempSpawn.setRespawnDelay(FWA_ACTIVITYTIMEOFANTHARAS * 2);
  157. SpawnTable.getInstance().addNewSpawn(tempSpawn, false);
  158. _monsterSpawn.put(29067, tempSpawn);
  159. // Strong Antharas
  160. template1 = NpcTable.getInstance().getTemplate(ANTHARASSTRONGID);
  161. tempSpawn = new L2Spawn(template1);
  162. tempSpawn.setLocx(181323);
  163. tempSpawn.setLocy(114850);
  164. tempSpawn.setLocz(-7623);
  165. tempSpawn.setHeading(32542);
  166. tempSpawn.setAmount(1);
  167. tempSpawn.setRespawnDelay(FWA_ACTIVITYTIMEOFANTHARAS * 2);
  168. SpawnTable.getInstance().addNewSpawn(tempSpawn, false);
  169. _monsterSpawn.put(29068, tempSpawn);
  170. }
  171. catch (Exception e)
  172. {
  173. _log.warning(e.getMessage());
  174. }
  175. // Setting spawn data of teleport cube.
  176. try
  177. {
  178. L2NpcTemplate Cube = NpcTable.getInstance().getTemplate(_teleportCubeId);
  179. L2Spawn spawnDat;
  180. for (int[] element : _teleportCubeLocation)
  181. {
  182. spawnDat = new L2Spawn(Cube);
  183. spawnDat.setAmount(1);
  184. spawnDat.setLocx(element[0]);
  185. spawnDat.setLocy(element[1]);
  186. spawnDat.setLocz(element[2]);
  187. spawnDat.setHeading(element[3]);
  188. spawnDat.setRespawnDelay(60);
  189. spawnDat.setLocation(0);
  190. SpawnTable.getInstance().addNewSpawn(spawnDat, false);
  191. _teleportCubeSpawn.add(spawnDat);
  192. }
  193. }
  194. catch (Exception e)
  195. {
  196. _log.warning(e.getMessage());
  197. }
  198. int status = GrandBossManager.getInstance().getBossStatus(ANTHARASOLDID);
  199. if (FWA_OLDANTHARAS || status == WAITING)
  200. {
  201. StatsSet info = GrandBossManager.getInstance().getStatsSet(ANTHARASOLDID);
  202. Long respawnTime = info.getLong("respawn_time");
  203. if (status == DEAD && respawnTime <= System.currentTimeMillis())
  204. {
  205. // the time has already expired while the server was offline. Immediately spawn antharas in his cave.
  206. // also, the status needs to be changed to DORMANT
  207. GrandBossManager.getInstance().setBossStatus(ANTHARASOLDID,DORMANT);
  208. status = DORMANT;
  209. }
  210. else if (status == FIGHTING)
  211. {
  212. int loc_x = info.getInteger("loc_x");
  213. int loc_y = info.getInteger("loc_y");
  214. int loc_z = info.getInteger("loc_z");
  215. int heading = info.getInteger("heading");
  216. int hp = info.getInteger("currentHP");
  217. int mp = info.getInteger("currentMP");
  218. _antharas = (L2GrandBossInstance) addSpawn(ANTHARASOLDID,loc_x,loc_y,loc_z,heading,false,0);
  219. GrandBossManager.getInstance().addBoss(_antharas);
  220. _antharas.setCurrentHpMp(hp,mp);
  221. _LastAction = System.currentTimeMillis();
  222. // Start repeating timer to check for inactivity
  223. _activityCheckTask = ThreadPoolManager.getInstance().scheduleGeneralAtFixedRate(new CheckActivity(), 60000, 60000);
  224. }
  225. else if (status == DEAD)
  226. {
  227. ThreadPoolManager.getInstance().scheduleGeneral(new UnlockAntharas(ANTHARASOLDID), respawnTime - System.currentTimeMillis());
  228. }
  229. else
  230. {
  231. setAntharasSpawnTask();
  232. }
  233. }
  234. else
  235. {
  236. int statusWeak = GrandBossManager.getInstance().getBossStatus(ANTHARASWEAKID);
  237. int statusNormal = GrandBossManager.getInstance().getBossStatus(ANTHARASNORMALID);
  238. int statusStrong = GrandBossManager.getInstance().getBossStatus(ANTHARASSTRONGID);
  239. int antharasId = 0;
  240. if (statusWeak == FIGHTING || statusWeak == DEAD)
  241. {
  242. antharasId = ANTHARASWEAKID;
  243. status = statusWeak;
  244. }
  245. else if (statusNormal == FIGHTING || statusNormal == DEAD)
  246. {
  247. antharasId = ANTHARASNORMALID;
  248. status = statusNormal;
  249. }
  250. else if (statusStrong == FIGHTING || statusStrong == DEAD)
  251. {
  252. antharasId = ANTHARASSTRONGID;
  253. status = statusStrong;
  254. }
  255. if (antharasId != 0 && status == FIGHTING)
  256. {
  257. StatsSet info = GrandBossManager.getInstance().getStatsSet(antharasId);
  258. int loc_x = info.getInteger("loc_x");
  259. int loc_y = info.getInteger("loc_y");
  260. int loc_z = info.getInteger("loc_z");
  261. int heading = info.getInteger("heading");
  262. int hp = info.getInteger("currentHP");
  263. int mp = info.getInteger("currentMP");
  264. _antharas = (L2GrandBossInstance) addSpawn(antharasId,loc_x,loc_y,loc_z,heading,false,0);
  265. GrandBossManager.getInstance().addBoss(_antharas);
  266. _antharas.setCurrentHpMp(hp,mp);
  267. _LastAction = System.currentTimeMillis();
  268. // Start repeating timer to check for inactivity
  269. _activityCheckTask = ThreadPoolManager.getInstance().scheduleGeneralAtFixedRate(new CheckActivity(), 60000, 60000);
  270. }
  271. else if (antharasId != 0 && status == DEAD)
  272. {
  273. StatsSet info = GrandBossManager.getInstance().getStatsSet(antharasId);
  274. Long respawnTime = info.getLong("respawn_time");
  275. if (respawnTime <= System.currentTimeMillis())
  276. {
  277. // the time has already expired while the server was offline. Immediately spawn antharas in his cave.
  278. // also, the status needs to be changed to DORMANT
  279. GrandBossManager.getInstance().setBossStatus(antharasId,DORMANT);
  280. status = DORMANT;
  281. }
  282. else
  283. {
  284. ThreadPoolManager.getInstance().scheduleGeneral(new UnlockAntharas(antharasId), respawnTime - System.currentTimeMillis());
  285. }
  286. }
  287. }
  288. }
  289. // Do spawn teleport cube.
  290. public void spawnCube()
  291. {
  292. if (_mobsSpawnTask != null)
  293. {
  294. _mobsSpawnTask.cancel(true);
  295. _mobsSpawnTask = null;
  296. }
  297. if (_selfDestructionTask != null)
  298. {
  299. _selfDestructionTask.cancel(true);
  300. _selfDestructionTask = null;
  301. }
  302. if (_activityCheckTask != null)
  303. {
  304. _activityCheckTask.cancel(false);
  305. _activityCheckTask = null;
  306. }
  307. for (L2Spawn spawnDat : _teleportCubeSpawn)
  308. {
  309. _teleportCube.add(spawnDat.doSpawn());
  310. }
  311. }
  312. // Setting Antharas spawn task.
  313. public void setAntharasSpawnTask()
  314. {
  315. if (_monsterSpawnTask == null)
  316. {
  317. synchronized(this)
  318. {
  319. if (_monsterSpawnTask == null)
  320. {
  321. GrandBossManager.getInstance().setBossStatus(ANTHARASOLDID,WAITING);
  322. _monsterSpawnTask = ThreadPoolManager.getInstance().scheduleGeneral(new AntharasSpawn(1),Config.Antharas_Wait_Time);
  323. }
  324. }
  325. }
  326. }
  327. private void startMinionSpawns(int antharasId)
  328. {
  329. int intervalOfMobs;
  330. // Interval of minions is decided by the type of Antharas
  331. // that invaded the lair.
  332. switch (antharasId)
  333. {
  334. case ANTHARASWEAKID:
  335. intervalOfMobs = FWA_INTERVALOFMOBSWEAK;
  336. break;
  337. case ANTHARASNORMALID:
  338. intervalOfMobs = FWA_INTERVALOFMOBSNORMAL;
  339. break;
  340. default:
  341. intervalOfMobs = FWA_INTERVALOFMOBSSTRONG;
  342. break;
  343. }
  344. // Spawn mobs.
  345. _mobsSpawnTask = ThreadPoolManager.getInstance().scheduleGeneralAtFixedRate(new MobsSpawn(), intervalOfMobs, intervalOfMobs);
  346. }
  347. // Do spawn Antharas.
  348. private class AntharasSpawn implements Runnable
  349. {
  350. private int _taskId = 0;
  351. private final Collection<L2Character> _players = _Zone.getCharactersInside().values();
  352. public AntharasSpawn(int taskId)
  353. {
  354. _taskId = taskId;
  355. }
  356. @Override
  357. public void run()
  358. {
  359. int npcId;
  360. L2Spawn antharasSpawn = null;
  361. switch (_taskId)
  362. {
  363. case 1: // Spawn.
  364. // Strength of Antharas is decided by the number of players that
  365. // invaded the lair.
  366. _monsterSpawnTask.cancel(false);
  367. _monsterSpawnTask = null;
  368. if (FWA_OLDANTHARAS)
  369. npcId = 29019; // old
  370. else if (_players.size() <= FWA_LIMITOFWEAK)
  371. npcId = 29066; // weak
  372. else if (_players.size() > FWA_LIMITOFNORMAL)
  373. npcId = 29068; // strong
  374. else
  375. npcId = 29067; // normal
  376. // Do spawn.
  377. antharasSpawn = _monsterSpawn.get(npcId);
  378. _antharas = (L2GrandBossInstance) antharasSpawn.doSpawn();
  379. GrandBossManager.getInstance().addBoss(_antharas);
  380. _monsters.add(_antharas);
  381. _antharas.setIsImmobilized(true);
  382. GrandBossManager.getInstance().setBossStatus(ANTHARASOLDID,DORMANT);
  383. GrandBossManager.getInstance().setBossStatus(npcId,FIGHTING);
  384. _LastAction = System.currentTimeMillis();
  385. // Start repeating timer to check for inactivity
  386. _activityCheckTask = ThreadPoolManager.getInstance().scheduleGeneralAtFixedRate(new CheckActivity(), 60000, 60000);
  387. // Setting 1st time of minions spawn task.
  388. if (!FWA_OLDANTHARAS)
  389. {
  390. startMinionSpawns(npcId);
  391. }
  392. // Set next task.
  393. if (_socialTask != null)
  394. {
  395. _socialTask.cancel(true);
  396. _socialTask = null;
  397. }
  398. _socialTask = ThreadPoolManager.getInstance().scheduleGeneral(new AntharasSpawn(2), 16);
  399. break;
  400. case 2:
  401. // Set camera.
  402. broadcastPacket(new SpecialCamera(_antharas.getObjectId(),700,13,-19,0,20000,0,0,1,0));
  403. // Set next task.
  404. if (_socialTask != null)
  405. {
  406. _socialTask.cancel(true);
  407. _socialTask = null;
  408. }
  409. _socialTask = ThreadPoolManager.getInstance().scheduleGeneral(new AntharasSpawn(3), 3000);
  410. break;
  411. case 3:
  412. // Do social.
  413. broadcastPacket(new SpecialCamera(_antharas.getObjectId(),700,13,0,6000,20000,0,0,1,0));
  414. // Set next task.
  415. if (_socialTask != null)
  416. {
  417. _socialTask.cancel(true);
  418. _socialTask = null;
  419. }
  420. _socialTask = ThreadPoolManager.getInstance().scheduleGeneral(new AntharasSpawn(4), 10000);
  421. break;
  422. case 4:
  423. broadcastPacket(new SpecialCamera(_antharas.getObjectId(),3700,0,-3,0,10000,0,0,1,0));
  424. // Set next task.
  425. if (_socialTask != null)
  426. {
  427. _socialTask.cancel(true);
  428. _socialTask = null;
  429. }
  430. _socialTask = ThreadPoolManager.getInstance().scheduleGeneral(new AntharasSpawn(5), 200);
  431. break;
  432. case 5:
  433. // Do social.
  434. broadcastPacket(new SpecialCamera(_antharas.getObjectId(),1100,0,-3,22000,30000,0,0,1,0));
  435. // Set next task.
  436. if (_socialTask != null)
  437. {
  438. _socialTask.cancel(true);
  439. _socialTask = null;
  440. }
  441. _socialTask = ThreadPoolManager.getInstance().scheduleGeneral(new AntharasSpawn(6), 10800);
  442. break;
  443. case 6:
  444. // Set camera.
  445. broadcastPacket(new SpecialCamera(_antharas.getObjectId(),1100,0,-3,300,7000,0,0,1,0));
  446. // Set next task.
  447. if (_socialTask != null)
  448. {
  449. _socialTask.cancel(true);
  450. _socialTask = null;
  451. }
  452. _socialTask = ThreadPoolManager.getInstance().scheduleGeneral(new AntharasSpawn(7), 1900);
  453. break;
  454. case 7:
  455. _antharas.abortCast();
  456. _mobiliseTask = ThreadPoolManager.getInstance().scheduleGeneral(new SetMobilised(_antharas), 16);
  457. // Move at random.
  458. if (FWA_MOVEATRANDOM)
  459. {
  460. L2CharPosition pos = new L2CharPosition(Rnd.get(175000,178500), Rnd.get(112400, 116000), -7707, 0);
  461. _moveAtRandomTask = ThreadPoolManager.getInstance().scheduleGeneral(new MoveAtRandom(_antharas, pos),500);
  462. }
  463. if (_socialTask != null)
  464. {
  465. _socialTask.cancel(true);
  466. _socialTask = null;
  467. }
  468. break;
  469. }
  470. }
  471. }
  472. private void broadcastPacket(L2GameServerPacket mov)
  473. {
  474. if (_Zone != null)
  475. {
  476. for (L2Character characters : _Zone.getCharactersInside().values())
  477. {
  478. if (characters instanceof L2PcInstance)
  479. characters.sendPacket(mov);
  480. }
  481. }
  482. }
  483. // Do spawn Behemoth or Bomber.
  484. private class MobsSpawn implements Runnable
  485. {
  486. public MobsSpawn()
  487. {
  488. }
  489. @Override
  490. public void run()
  491. {
  492. L2NpcTemplate template1;
  493. L2Spawn tempSpawn;
  494. boolean isBehemoth = Rnd.get(100) < FWA_PERCENTOFBEHEMOTH;
  495. try
  496. {
  497. int mobNumber = (isBehemoth ? 2 : 3);
  498. // Set spawn.
  499. for(int i = 0; i < mobNumber; i++)
  500. {
  501. if (_monsters.size() >= FWA_MAXMOBS)
  502. break;
  503. int npcId;
  504. if (isBehemoth)
  505. npcId = 29069;
  506. else
  507. npcId = Rnd.get(29070, 29076);
  508. template1 = NpcTable.getInstance().getTemplate(npcId);
  509. tempSpawn = new L2Spawn(template1);
  510. // allocates it at random in the lair of Antharas.
  511. int tried = 0;
  512. boolean notFound = true;
  513. int x = 175000;
  514. int y = 112400;
  515. int dt = (_antharas.getX() - x) * (_antharas.getX() - x) + (_antharas.getY() - y) * (_antharas.getY() - y);
  516. while (tried++ < 25 && notFound)
  517. {
  518. int rx = Rnd.get(175000, 179900);
  519. int ry = Rnd.get(112400, 116000);
  520. int rdt = (_antharas.getX() - rx) * (_antharas.getX() - rx) + (_antharas.getY() - ry) * (_antharas.getY() - ry);
  521. if (GeoData.getInstance().canSeeTarget(_antharas.getX(), _antharas.getY(), -7704, rx, ry, -7704))
  522. if (rdt < dt)
  523. {
  524. x = rx;
  525. y = ry;
  526. dt = rdt;
  527. if (rdt <= 900000)
  528. notFound = false;
  529. }
  530. }
  531. tempSpawn.setLocx(x);
  532. tempSpawn.setLocy(y);
  533. tempSpawn.setLocz(-7704);
  534. tempSpawn.setHeading(0);
  535. tempSpawn.setAmount(1);
  536. tempSpawn.setRespawnDelay(FWA_ACTIVITYTIMEOFANTHARAS * 2);
  537. SpawnTable.getInstance().addNewSpawn(tempSpawn, false);
  538. // Do spawn.
  539. _monsters.add(tempSpawn.doSpawn());
  540. }
  541. }
  542. catch (Exception e)
  543. {
  544. _log.warning(e.getMessage());
  545. }
  546. }
  547. }
  548. @Override
  549. public String onAggroRangeEnter (L2Npc npc, L2PcInstance player, boolean isPet)
  550. {
  551. switch (npc.getNpcId())
  552. {
  553. case 29070:
  554. case 29071:
  555. case 29072:
  556. case 29073:
  557. case 29074:
  558. case 29075:
  559. case 29076:
  560. if (_selfDestructionTask == null && !npc.isDead())
  561. _selfDestructionTask = ThreadPoolManager.getInstance().scheduleGeneral(new SelfDestructionOfBomber(npc), FWA_SELFDESTRUCTTIME);
  562. break;
  563. }
  564. return super.onAggroRangeEnter(npc, player, isPet);
  565. }
  566. // Do self destruction.
  567. private class SelfDestructionOfBomber implements Runnable
  568. {
  569. private final L2Npc _bomber;
  570. public SelfDestructionOfBomber(L2Npc bomber)
  571. {
  572. _bomber = bomber;
  573. }
  574. @Override
  575. public void run()
  576. {
  577. L2Skill skill = null;
  578. switch (_bomber.getNpcId())
  579. {
  580. case 29070:
  581. case 29071:
  582. case 29072:
  583. case 29073:
  584. case 29074:
  585. case 29075:
  586. skill = SkillTable.getInstance().getInfo(5097, 1);
  587. break;
  588. case 29076:
  589. skill = SkillTable.getInstance().getInfo(5094, 1);
  590. break;
  591. }
  592. _bomber.doCast(skill);
  593. if (_selfDestructionTask != null)
  594. {
  595. _selfDestructionTask.cancel(false);
  596. _selfDestructionTask = null;
  597. }
  598. }
  599. }
  600. @Override
  601. public String onSpellFinished(L2Npc npc, L2PcInstance player, L2Skill skill)
  602. {
  603. if (npc.isInvul())
  604. {
  605. return null;
  606. }
  607. else if (skill != null && (skill.getId() == 5097 || skill.getId() == 5094))
  608. {
  609. switch (npc.getNpcId())
  610. {
  611. case 29070:
  612. case 29071:
  613. case 29072:
  614. case 29073:
  615. case 29074:
  616. case 29075:
  617. case 29076:
  618. npc.doDie(npc);
  619. break;
  620. }
  621. }
  622. return super.onSpellFinished(npc, player, skill);
  623. }
  624. // At end of activity time.
  625. private class CheckActivity implements Runnable
  626. {
  627. @Override
  628. public void run()
  629. {
  630. Long temp = (System.currentTimeMillis() - _LastAction);
  631. if (temp > FWA_INACTIVITYTIME)
  632. {
  633. GrandBossManager.getInstance().setBossStatus(_antharas.getNpcId(),DORMANT);
  634. setUnspawn();
  635. }
  636. }
  637. }
  638. // Clean Antharas's lair.
  639. public void setUnspawn()
  640. {
  641. // Eliminate players.
  642. _Zone.oustAllPlayers();
  643. // Not executed tasks is canceled.
  644. if (_cubeSpawnTask != null)
  645. {
  646. _cubeSpawnTask.cancel(true);
  647. _cubeSpawnTask = null;
  648. }
  649. if (_monsterSpawnTask != null)
  650. {
  651. _monsterSpawnTask.cancel(true);
  652. _monsterSpawnTask = null;
  653. }
  654. if (_activityCheckTask != null)
  655. {
  656. _activityCheckTask.cancel(false);
  657. _activityCheckTask = null;
  658. }
  659. if (_socialTask != null)
  660. {
  661. _socialTask.cancel(true);
  662. _socialTask = null;
  663. }
  664. if (_mobiliseTask != null)
  665. {
  666. _mobiliseTask.cancel(true);
  667. _mobiliseTask = null;
  668. }
  669. if (_mobsSpawnTask != null)
  670. {
  671. _mobsSpawnTask.cancel(true);
  672. _mobsSpawnTask = null;
  673. }
  674. if (_selfDestructionTask != null)
  675. {
  676. _selfDestructionTask.cancel(true);
  677. _selfDestructionTask = null;
  678. }
  679. if (_moveAtRandomTask != null)
  680. {
  681. _moveAtRandomTask.cancel(true);
  682. _moveAtRandomTask = null;
  683. }
  684. // Delete monsters.
  685. for (L2Npc mob : _monsters)
  686. {
  687. mob.getSpawn().stopRespawn();
  688. mob.deleteMe();
  689. }
  690. _monsters.clear();
  691. // Delete teleport cube.
  692. for (L2Npc cube : _teleportCube)
  693. {
  694. cube.getSpawn().stopRespawn();
  695. cube.deleteMe();
  696. }
  697. _teleportCube.clear();
  698. }
  699. // Do spawn teleport cube.
  700. private class CubeSpawn implements Runnable
  701. {
  702. private final int _type;
  703. public CubeSpawn(int type)
  704. {
  705. _type = type;
  706. }
  707. @Override
  708. public void run()
  709. {
  710. if (_type == 0)
  711. {
  712. spawnCube();
  713. _cubeSpawnTask = ThreadPoolManager.getInstance().scheduleGeneral(new CubeSpawn(1), 1800000);
  714. }
  715. else
  716. setUnspawn();
  717. }
  718. }
  719. // UnLock Antharas.
  720. private static class UnlockAntharas implements Runnable
  721. {
  722. private final int _bossId;
  723. public UnlockAntharas(int bossId)
  724. {
  725. _bossId = bossId;
  726. }
  727. @Override
  728. public void run()
  729. {
  730. GrandBossManager.getInstance().setBossStatus(_bossId,DORMANT);
  731. if (FWA_DOSERVEREARTHQUAKE)
  732. for(L2PcInstance p : L2World.getInstance().getAllPlayers().values())
  733. p.broadcastPacket(new Earthquake(185708,114298,-8221,20,10));
  734. }
  735. }
  736. // Action is enabled the boss.
  737. private class SetMobilised implements Runnable
  738. {
  739. private final L2GrandBossInstance _boss;
  740. public SetMobilised(L2GrandBossInstance boss)
  741. {
  742. _boss = boss;
  743. }
  744. @Override
  745. public void run()
  746. {
  747. _boss.setIsImmobilized(false);
  748. // When it is possible to act, a social action is canceled.
  749. if (_socialTask != null)
  750. {
  751. _socialTask.cancel(true);
  752. _socialTask = null;
  753. }
  754. }
  755. }
  756. // Move at random on after Antharas appears.
  757. private static class MoveAtRandom implements Runnable
  758. {
  759. private final L2Npc _npc;
  760. private final L2CharPosition _pos;
  761. public MoveAtRandom(L2Npc npc, L2CharPosition pos)
  762. {
  763. _npc = npc;
  764. _pos = pos;
  765. }
  766. @Override
  767. public void run()
  768. {
  769. _npc.getAI().setIntention(CtrlIntention.AI_INTENTION_MOVE_TO, _pos);
  770. }
  771. }
  772. @Override
  773. public String onAttack (L2Npc npc, L2PcInstance attacker, int damage, boolean isPet)
  774. {
  775. if (npc.getNpcId() == 29019 || npc.getNpcId() == 29066 || npc.getNpcId() == 29067 || npc.getNpcId() == 29068)
  776. {
  777. _LastAction = System.currentTimeMillis();
  778. if (GrandBossManager.getInstance().getBossStatus(_antharas.getNpcId()) != FIGHTING)
  779. {
  780. _Zone.oustAllPlayers();
  781. }
  782. else if (!FWA_OLDANTHARAS && _mobsSpawnTask == null)
  783. {
  784. startMinionSpawns(npc.getNpcId());
  785. }
  786. }
  787. else if (npc.getNpcId() > 29069 && npc.getNpcId() < 29077 && npc.getCurrentHp() <= damage)
  788. {
  789. L2Skill skill = null;
  790. switch (npc.getNpcId())
  791. {
  792. case 29070:
  793. case 29071:
  794. case 29072:
  795. case 29073:
  796. case 29074:
  797. case 29075:
  798. skill = SkillTable.getInstance().getInfo(5097, 1);
  799. break;
  800. case 29076:
  801. skill = SkillTable.getInstance().getInfo(5094, 1);
  802. break;
  803. }
  804. npc.doCast(skill);
  805. }
  806. return super.onAttack(npc, attacker, damage, isPet);
  807. }
  808. @Override
  809. public String onKill (L2Npc npc, L2PcInstance killer, boolean isPet)
  810. {
  811. if (npc.getNpcId() == 29019 || npc.getNpcId() == 29066 || npc.getNpcId() == 29067 || npc.getNpcId() == 29068)
  812. {
  813. npc.broadcastPacket(new PlaySound(1, "BS01_D", 1, npc.getObjectId(), npc.getX(), npc.getY(), npc.getZ()));
  814. _cubeSpawnTask = ThreadPoolManager.getInstance().scheduleGeneral(new CubeSpawn(0), 10000);
  815. GrandBossManager.getInstance().setBossStatus(npc.getNpcId(),DEAD);
  816. long respawnTime = (long)Config.Interval_Of_Antharas_Spawn + Rnd.get(Config.Random_Of_Antharas_Spawn);
  817. ThreadPoolManager.getInstance().scheduleGeneral(new UnlockAntharas(npc.getNpcId()), respawnTime);
  818. // also save the respawn time so that the info is maintained past reboots
  819. StatsSet info = GrandBossManager.getInstance().getStatsSet(npc.getNpcId());
  820. info.set("respawn_time",(System.currentTimeMillis() + respawnTime));
  821. GrandBossManager.getInstance().setStatsSet(npc.getNpcId(),info);
  822. }
  823. else if (npc.getNpcId() == 29069)
  824. {
  825. int countHPHerb = Rnd.get(6, 18);
  826. int countMPHerb = Rnd.get(6, 18);
  827. for (int i = 0; i < countHPHerb; i++)
  828. ((L2MonsterInstance)npc).dropItem(killer, 8602, 1);
  829. for (int i = 0; i < countMPHerb; i++)
  830. ((L2MonsterInstance)npc).dropItem(killer, 8605, 1);
  831. }
  832. if (_monsters.contains(npc))
  833. _monsters.remove(npc);
  834. return super.onKill(npc,killer,isPet);
  835. }
  836. }