QueenAnt.java 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  1. /*
  2. * Copyright (C) 2004-2014 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 javolution.util.FastList;
  22. import ai.npc.AbstractNpcAI;
  23. import com.l2jserver.Config;
  24. import com.l2jserver.gameserver.ai.CtrlIntention;
  25. import com.l2jserver.gameserver.instancemanager.GrandBossManager;
  26. import com.l2jserver.gameserver.model.Location;
  27. import com.l2jserver.gameserver.model.StatsSet;
  28. import com.l2jserver.gameserver.model.actor.L2Attackable;
  29. import com.l2jserver.gameserver.model.actor.L2Npc;
  30. import com.l2jserver.gameserver.model.actor.L2Playable;
  31. import com.l2jserver.gameserver.model.actor.instance.L2GrandBossInstance;
  32. import com.l2jserver.gameserver.model.actor.instance.L2MonsterInstance;
  33. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  34. import com.l2jserver.gameserver.model.holders.SkillHolder;
  35. import com.l2jserver.gameserver.model.skills.CommonSkill;
  36. import com.l2jserver.gameserver.model.skills.Skill;
  37. import com.l2jserver.gameserver.model.zone.type.L2BossZone;
  38. import com.l2jserver.gameserver.network.serverpackets.MagicSkillUse;
  39. import com.l2jserver.gameserver.network.serverpackets.PlaySound;
  40. /**
  41. * Queen Ant's AI
  42. * @author Emperorc
  43. */
  44. public final class QueenAnt extends AbstractNpcAI
  45. {
  46. private static final int QUEEN = 29001;
  47. private static final int LARVA = 29002;
  48. private static final int NURSE = 29003;
  49. private static final int GUARD = 29004;
  50. private static final int ROYAL = 29005;
  51. private static final int[] MOBS =
  52. {
  53. QUEEN,
  54. LARVA,
  55. NURSE,
  56. GUARD,
  57. ROYAL
  58. };
  59. private static final Location OUST_LOC_1 = new Location(-19480, 187344, -5600);
  60. private static final Location OUST_LOC_2 = new Location(-17928, 180912, -5520);
  61. private static final Location OUST_LOC_3 = new Location(-23808, 182368, -5600);
  62. private static final int QUEEN_X = -21610;
  63. private static final int QUEEN_Y = 181594;
  64. private static final int QUEEN_Z = -5734;
  65. // QUEEN Status Tracking :
  66. private static final byte ALIVE = 0; // Queen Ant is spawned.
  67. private static final byte DEAD = 1; // Queen Ant has been killed.
  68. private static L2BossZone _zone;
  69. private static SkillHolder HEAL1 = new SkillHolder(4020, 1);
  70. private static SkillHolder HEAL2 = new SkillHolder(4024, 1);
  71. private L2MonsterInstance _queen = null;
  72. private L2MonsterInstance _larva = null;
  73. private final List<L2MonsterInstance> _nurses = new FastList<>(5);
  74. private QueenAnt()
  75. {
  76. super(QueenAnt.class.getSimpleName(), "ai/individual");
  77. addSpawnId(MOBS);
  78. addKillId(MOBS);
  79. addAggroRangeEnterId(MOBS);
  80. addFactionCallId(NURSE);
  81. _zone = GrandBossManager.getInstance().getZone(QUEEN_X, QUEEN_Y, QUEEN_Z);
  82. StatsSet info = GrandBossManager.getInstance().getStatsSet(QUEEN);
  83. int status = GrandBossManager.getInstance().getBossStatus(QUEEN);
  84. if (status == DEAD)
  85. {
  86. // load the unlock date and time for queen ant from DB
  87. long temp = info.getLong("respawn_time") - System.currentTimeMillis();
  88. // if queen ant is locked until a certain time, mark it so and start the unlock timer
  89. // the unlock time has not yet expired.
  90. if (temp > 0)
  91. {
  92. startQuestTimer("queen_unlock", temp, null, null);
  93. }
  94. else
  95. {
  96. // the time has already expired while the server was offline. Immediately spawn queen ant.
  97. L2GrandBossInstance queen = (L2GrandBossInstance) addSpawn(QUEEN, QUEEN_X, QUEEN_Y, QUEEN_Z, 0, false, 0);
  98. GrandBossManager.getInstance().setBossStatus(QUEEN, ALIVE);
  99. spawnBoss(queen);
  100. }
  101. }
  102. else
  103. {
  104. int loc_x = info.getInt("loc_x");
  105. int loc_y = info.getInt("loc_y");
  106. int loc_z = info.getInt("loc_z");
  107. int heading = info.getInt("heading");
  108. int hp = info.getInt("currentHP");
  109. int mp = info.getInt("currentMP");
  110. if (!_zone.isInsideZone(loc_x, loc_y, loc_z))
  111. {
  112. loc_x = QUEEN_X;
  113. loc_y = QUEEN_Y;
  114. loc_z = QUEEN_Z;
  115. }
  116. L2GrandBossInstance queen = (L2GrandBossInstance) addSpawn(QUEEN, loc_x, loc_y, loc_z, heading, false, 0);
  117. queen.setCurrentHpMp(hp, mp);
  118. spawnBoss(queen);
  119. }
  120. }
  121. private void spawnBoss(L2GrandBossInstance npc)
  122. {
  123. GrandBossManager.getInstance().addBoss(npc);
  124. if (getRandom(100) < 33)
  125. {
  126. _zone.movePlayersTo(OUST_LOC_1);
  127. }
  128. else if (getRandom(100) < 50)
  129. {
  130. _zone.movePlayersTo(OUST_LOC_2);
  131. }
  132. else
  133. {
  134. _zone.movePlayersTo(OUST_LOC_3);
  135. }
  136. GrandBossManager.getInstance().addBoss(npc);
  137. startQuestTimer("action", 10000, npc, null, true);
  138. startQuestTimer("heal", 1000, null, null, true);
  139. npc.broadcastPacket(new PlaySound(1, "BS01_A", 1, npc.getObjectId(), npc.getX(), npc.getY(), npc.getZ()));
  140. _queen = npc;
  141. _larva = (L2MonsterInstance) addSpawn(LARVA, -21600, 179482, -5846, getRandom(360), false, 0);
  142. }
  143. @Override
  144. public String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
  145. {
  146. if (event.equalsIgnoreCase("heal"))
  147. {
  148. boolean notCasting;
  149. final boolean larvaNeedHeal = (_larva != null) && (_larva.getCurrentHp() < _larva.getMaxHp());
  150. final boolean queenNeedHeal = (_queen != null) && (_queen.getCurrentHp() < _queen.getMaxHp());
  151. for (L2MonsterInstance nurse : _nurses)
  152. {
  153. if ((nurse == null) || nurse.isDead() || nurse.isCastingNow())
  154. {
  155. continue;
  156. }
  157. notCasting = nurse.getAI().getIntention() != CtrlIntention.AI_INTENTION_CAST;
  158. if (larvaNeedHeal)
  159. {
  160. if ((nurse.getTarget() != _larva) || notCasting)
  161. {
  162. nurse.setTarget(_larva);
  163. nurse.useMagic(getRandomBoolean() ? HEAL1.getSkill() : HEAL2.getSkill());
  164. }
  165. continue;
  166. }
  167. if (queenNeedHeal)
  168. {
  169. if (nurse.getLeader() == _larva)
  170. {
  171. continue;
  172. }
  173. if ((nurse.getTarget() != _queen) || notCasting)
  174. {
  175. nurse.setTarget(_queen);
  176. nurse.useMagic(HEAL1.getSkill());
  177. }
  178. continue;
  179. }
  180. // if nurse not casting - remove target
  181. if (notCasting && (nurse.getTarget() != null))
  182. {
  183. nurse.setTarget(null);
  184. }
  185. }
  186. }
  187. else if (event.equalsIgnoreCase("action") && (npc != null))
  188. {
  189. if (getRandom(3) == 0)
  190. {
  191. if (getRandom(2) == 0)
  192. {
  193. npc.broadcastSocialAction(3);
  194. }
  195. else
  196. {
  197. npc.broadcastSocialAction(4);
  198. }
  199. }
  200. }
  201. else if (event.equalsIgnoreCase("queen_unlock"))
  202. {
  203. L2GrandBossInstance queen = (L2GrandBossInstance) addSpawn(QUEEN, QUEEN_X, QUEEN_Y, QUEEN_Z, 0, false, 0);
  204. GrandBossManager.getInstance().setBossStatus(QUEEN, ALIVE);
  205. spawnBoss(queen);
  206. }
  207. return super.onAdvEvent(event, npc, player);
  208. }
  209. @Override
  210. public String onSpawn(L2Npc npc)
  211. {
  212. final L2MonsterInstance mob = (L2MonsterInstance) npc;
  213. switch (npc.getId())
  214. {
  215. case LARVA:
  216. mob.setIsImmobilized(true);
  217. mob.setIsMortal(false);
  218. mob.setIsRaidMinion(true);
  219. break;
  220. case NURSE:
  221. mob.disableCoreAI(true);
  222. mob.setIsRaidMinion(true);
  223. _nurses.add(mob);
  224. break;
  225. case ROYAL:
  226. case GUARD:
  227. mob.setIsRaidMinion(true);
  228. break;
  229. }
  230. return super.onSpawn(npc);
  231. }
  232. @Override
  233. public String onFactionCall(L2Npc npc, L2Npc caller, L2PcInstance attacker, boolean isSummon)
  234. {
  235. if ((caller == null) || (npc == null))
  236. {
  237. return super.onFactionCall(npc, caller, attacker, isSummon);
  238. }
  239. if (!npc.isCastingNow() && (npc.getAI().getIntention() != CtrlIntention.AI_INTENTION_CAST))
  240. {
  241. if (caller.getCurrentHp() < caller.getMaxHp())
  242. {
  243. npc.setTarget(caller);
  244. ((L2Attackable) npc).useMagic(HEAL1.getSkill());
  245. }
  246. }
  247. return null;
  248. }
  249. @Override
  250. public String onAggroRangeEnter(L2Npc npc, L2PcInstance player, boolean isSummon)
  251. {
  252. if ((npc == null) || (player.isGM() && player.isInvisible()))
  253. {
  254. return null;
  255. }
  256. final boolean isMage;
  257. final L2Playable character;
  258. if (isSummon)
  259. {
  260. isMage = false;
  261. character = player.getSummon();
  262. }
  263. else
  264. {
  265. isMage = player.isMageClass();
  266. character = player;
  267. }
  268. if (character == null)
  269. {
  270. return null;
  271. }
  272. if (!Config.RAID_DISABLE_CURSE && ((character.getLevel() - npc.getLevel()) > 8))
  273. {
  274. Skill curse = null;
  275. if (isMage)
  276. {
  277. if (!character.isMuted() && (getRandom(4) == 0))
  278. {
  279. curse = CommonSkill.RAID_CURSE.getSkill();
  280. }
  281. }
  282. else
  283. {
  284. if (!character.isParalyzed() && (getRandom(4) == 0))
  285. {
  286. curse = CommonSkill.RAID_CURSE2.getSkill();
  287. }
  288. }
  289. if (curse != null)
  290. {
  291. npc.broadcastPacket(new MagicSkillUse(npc, character, curse.getId(), curse.getLevel(), 300, 0));
  292. curse.applyEffects(npc, character);
  293. }
  294. ((L2Attackable) npc).stopHating(character); // for calling again
  295. return null;
  296. }
  297. return super.onAggroRangeEnter(npc, player, isSummon);
  298. }
  299. @Override
  300. public String onKill(L2Npc npc, L2PcInstance killer, boolean isSummon)
  301. {
  302. int npcId = npc.getId();
  303. if (npcId == QUEEN)
  304. {
  305. npc.broadcastPacket(new PlaySound(1, "BS02_D", 1, npc.getObjectId(), npc.getX(), npc.getY(), npc.getZ()));
  306. GrandBossManager.getInstance().setBossStatus(QUEEN, DEAD);
  307. // Calculate Min and Max respawn times randomly.
  308. long respawnTime = Config.QUEEN_ANT_SPAWN_INTERVAL + getRandom(-Config.QUEEN_ANT_SPAWN_RANDOM, Config.QUEEN_ANT_SPAWN_RANDOM);
  309. respawnTime *= 3600000;
  310. startQuestTimer("queen_unlock", respawnTime, null, null);
  311. cancelQuestTimer("action", npc, null);
  312. cancelQuestTimer("heal", null, null);
  313. // also save the respawn time so that the info is maintained past reboots
  314. StatsSet info = GrandBossManager.getInstance().getStatsSet(QUEEN);
  315. info.set("respawn_time", System.currentTimeMillis() + respawnTime);
  316. GrandBossManager.getInstance().setStatsSet(QUEEN, info);
  317. _nurses.clear();
  318. _larva.deleteMe();
  319. _larva = null;
  320. _queen = null;
  321. }
  322. else if ((_queen != null) && !_queen.isAlikeDead())
  323. {
  324. if (npcId == ROYAL)
  325. {
  326. L2MonsterInstance mob = (L2MonsterInstance) npc;
  327. if (mob.getLeader() != null)
  328. {
  329. mob.getLeader().getMinionList().onMinionDie(mob, (280 + getRandom(40)) * 1000);
  330. }
  331. }
  332. else if (npcId == NURSE)
  333. {
  334. L2MonsterInstance mob = (L2MonsterInstance) npc;
  335. _nurses.remove(mob);
  336. if (mob.getLeader() != null)
  337. {
  338. mob.getLeader().getMinionList().onMinionDie(mob, 10000);
  339. }
  340. }
  341. }
  342. return super.onKill(npc, killer, isSummon);
  343. }
  344. public static void main(String[] args)
  345. {
  346. new QueenAnt();
  347. }
  348. }