QueenAnt.java 11 KB

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