Anais.java 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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.Map;
  21. import ai.npc.AbstractNpcAI;
  22. import com.l2jserver.gameserver.ai.CtrlIntention;
  23. import com.l2jserver.gameserver.datatables.SpawnTable;
  24. import com.l2jserver.gameserver.model.L2Spawn;
  25. import com.l2jserver.gameserver.model.Location;
  26. import com.l2jserver.gameserver.model.actor.L2Attackable;
  27. import com.l2jserver.gameserver.model.actor.L2Npc;
  28. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  29. import com.l2jserver.gameserver.model.holders.SkillHolder;
  30. import com.l2jserver.gameserver.model.quest.QuestTimer;
  31. /**
  32. * Anais AI.
  33. * @author nonom
  34. */
  35. public final class Anais extends AbstractNpcAI
  36. {
  37. // NPCs
  38. private static final int ANAIS = 25701;
  39. private static final int DIVINE_BURNER = 18915;
  40. private static final int GRAIL_WARD = 18929;
  41. // Skill
  42. private static SkillHolder DIVINE_NOVA = new SkillHolder(6326, 1);
  43. // Instances
  44. private final L2Npc[] _divineBurners = new L2Npc[4];
  45. private L2Npc _anais = null;
  46. private L2PcInstance _nextTarget = null;
  47. private L2Npc _current = null;
  48. private int _pot = 0;
  49. private Anais()
  50. {
  51. super(Anais.class.getSimpleName(), "ai/individual");
  52. addAttackId(ANAIS);
  53. addKillId(GRAIL_WARD);
  54. int i = 0;
  55. for (L2Spawn spawn : SpawnTable.getInstance().getSpawns(DIVINE_BURNER))
  56. {
  57. _divineBurners[i++] = spawn.getLastSpawn();
  58. }
  59. _anais = SpawnTable.getInstance().getFirstSpawn(ANAIS).getLastSpawn();
  60. }
  61. private void burnerOnAttack(int pot)
  62. {
  63. L2Npc npc = _divineBurners[pot];
  64. npc.setDisplayEffect(1);
  65. npc.setIsRunning(false);
  66. if (pot < 4)
  67. {
  68. _current = npc;
  69. QuestTimer checkAround = getQuestTimer("CHECK", _anais, null);
  70. if (checkAround == null) // || !checkAround.getIsActive()
  71. {
  72. startQuestTimer("CHECK", 3000, _anais, null);
  73. }
  74. }
  75. else
  76. {
  77. cancelQuestTimer("CHECK", _anais, null);
  78. }
  79. }
  80. @Override
  81. public String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
  82. {
  83. switch (event)
  84. {
  85. case "CHECK":
  86. if (!npc.isAttackingNow())
  87. {
  88. cancelQuestTimer("CHECK", npc, null);
  89. }
  90. if ((_current != null) || (_pot < 4))
  91. {
  92. Map<Integer, L2PcInstance> players = _anais.getKnownList().getKnownPlayers();
  93. L2PcInstance target = players.get(getRandom(players.size() - 1));
  94. _nextTarget = target;
  95. if (_nextTarget == null)
  96. {
  97. _nextTarget = (L2PcInstance) _anais.getTarget();
  98. }
  99. L2Npc b = _divineBurners[_pot];
  100. _pot = _pot + 1;
  101. b.setDisplayEffect(1);
  102. b.setIsRunning(false);
  103. L2Npc ward = addSpawn(GRAIL_WARD, new Location(b.getX(), b.getY(), b.getZ()), true, 0);
  104. ((L2Attackable) ward).addDamageHate(_nextTarget, 0, 999);
  105. ward.setIsRunning(true);
  106. ward.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, _nextTarget, null);
  107. startQuestTimer("GUARD_ATTACK", 1000, ward, _nextTarget, true);
  108. startQuestTimer("SUICIDE", 20000, ward, null);
  109. ward.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, _nextTarget);
  110. }
  111. break;
  112. case "GUARD_ATTACK":
  113. if (_nextTarget != null)
  114. {
  115. final double distance = npc.calculateDistance(_nextTarget, false, false);
  116. if (distance < 100)
  117. {
  118. npc.doCast(DIVINE_NOVA.getSkill());
  119. }
  120. else if (distance > 2000)
  121. {
  122. npc.doDie(null);
  123. cancelQuestTimer("GUARD_ATTACK", npc, player);
  124. }
  125. }
  126. break;
  127. case "SUICIDE":
  128. npc.doCast(DIVINE_NOVA.getSkill());
  129. cancelQuestTimer("GUARD_ATTACK", npc, _nextTarget);
  130. if (_current != null)
  131. {
  132. _current.setDisplayEffect(2);
  133. _current.setIsRunning(false);
  134. _current = null;
  135. }
  136. npc.doDie(null);
  137. break;
  138. }
  139. return null;
  140. }
  141. @Override
  142. public String onAttack(L2Npc npc, L2PcInstance attacker, int damage, boolean isSummon)
  143. {
  144. if (_pot == 0)
  145. {
  146. burnerOnAttack(0);
  147. }
  148. else if ((npc.getCurrentHp() <= (npc.getMaxRecoverableHp() * 0.75)) && (_pot == 1))
  149. {
  150. burnerOnAttack(1);
  151. }
  152. else if ((npc.getCurrentHp() <= (npc.getMaxRecoverableHp() * 0.5)) && (_pot == 2))
  153. {
  154. burnerOnAttack(2);
  155. }
  156. else if ((npc.getCurrentHp() <= (npc.getMaxRecoverableHp() * 0.25)) && (_pot == 3))
  157. {
  158. burnerOnAttack(3);
  159. }
  160. return super.onAttack(npc, attacker, damage, isSummon);
  161. }
  162. @Override
  163. public String onKill(L2Npc npc, L2PcInstance killer, boolean isSummon)
  164. {
  165. npc.doCast(DIVINE_NOVA.getSkill());
  166. cancelQuestTimer("GUARD_ATTACK", npc, _nextTarget);
  167. cancelQuestTimer("CHECK", npc, null);
  168. if (_current != null)
  169. {
  170. _current.setDisplayEffect(2);
  171. _current.setIsRunning(false);
  172. _current = null;
  173. }
  174. return super.onKill(npc, killer, isSummon);
  175. }
  176. public static void main(String[] args)
  177. {
  178. new Anais();
  179. }
  180. }