QueenAnt.java 11 KB

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