Anais.java 5.4 KB

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