QueenAnt.java 11 KB

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