QueenAnt.java 11 KB

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