Anais.java 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. /*
  2. * Copyright (C) 2004-2015 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. {
  80. if (!npc.isAttackingNow())
  81. {
  82. cancelQuestTimer("CHECK", npc, null);
  83. }
  84. if ((_current != null) || (_pot < 4))
  85. {
  86. final Map<Integer, L2PcInstance> players = npc.getKnownList().getKnownPlayers();
  87. final L2PcInstance target = players.get(getRandom(players.size() - 1));
  88. _nextTarget = target;
  89. if (_nextTarget == null)
  90. {
  91. _nextTarget = (L2PcInstance) npc.getTarget();
  92. }
  93. final L2Npc b = _divineBurners.get(_pot);
  94. _pot = _pot + 1;
  95. b.setDisplayEffect(1);
  96. b.setIsRunning(false);
  97. L2Npc ward = addSpawn(GRAIL_WARD, new Location(b.getX(), b.getY(), b.getZ()), true, 0);
  98. ((L2Attackable) ward).addDamageHate(_nextTarget, 0, 999);
  99. ward.setIsRunning(true);
  100. ward.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, _nextTarget, null);
  101. startQuestTimer("GUARD_ATTACK", 1000, ward, _nextTarget, true);
  102. startQuestTimer("SUICIDE", 20000, ward, null);
  103. ward.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, _nextTarget);
  104. }
  105. break;
  106. }
  107. case "GUARD_ATTACK":
  108. {
  109. if (_nextTarget != null)
  110. {
  111. final double distance = npc.calculateDistance(_nextTarget, false, false);
  112. if (distance < 100)
  113. {
  114. npc.doCast(DIVINE_NOVA.getSkill());
  115. }
  116. else if (distance > 2000)
  117. {
  118. npc.doDie(null);
  119. cancelQuestTimer("GUARD_ATTACK", npc, player);
  120. }
  121. }
  122. break;
  123. }
  124. case "SUICIDE":
  125. {
  126. npc.doCast(DIVINE_NOVA.getSkill());
  127. cancelQuestTimer("GUARD_ATTACK", npc, _nextTarget);
  128. if (_current != null)
  129. {
  130. _current.setDisplayEffect(2);
  131. _current.setIsRunning(false);
  132. _current = null;
  133. }
  134. npc.doDie(null);
  135. break;
  136. }
  137. }
  138. return super.onAdvEvent(event, npc, player);
  139. }
  140. @Override
  141. public String onAttack(L2Npc npc, L2PcInstance attacker, int damage, boolean isSummon)
  142. {
  143. if (_pot == 0)
  144. {
  145. burnerOnAttack(0, npc);
  146. }
  147. else if ((npc.getCurrentHp() <= (npc.getMaxRecoverableHp() * 0.75)) && (_pot == 1))
  148. {
  149. burnerOnAttack(1, npc);
  150. }
  151. else if ((npc.getCurrentHp() <= (npc.getMaxRecoverableHp() * 0.5)) && (_pot == 2))
  152. {
  153. burnerOnAttack(2, npc);
  154. }
  155. else if ((npc.getCurrentHp() <= (npc.getMaxRecoverableHp() * 0.25)) && (_pot == 3))
  156. {
  157. burnerOnAttack(3, npc);
  158. }
  159. return super.onAttack(npc, attacker, damage, isSummon);
  160. }
  161. /*
  162. * (non-Javadoc)
  163. * @see com.l2jserver.gameserver.model.quest.Quest#onSpawn(com.l2jserver.gameserver.model.actor.L2Npc)
  164. */
  165. @Override
  166. public String onSpawn(L2Npc npc)
  167. {
  168. _divineBurners.add(npc);
  169. return super.onSpawn(npc);
  170. }
  171. @Override
  172. public String onKill(L2Npc npc, L2PcInstance killer, boolean isSummon)
  173. {
  174. npc.doCast(DIVINE_NOVA.getSkill());
  175. cancelQuestTimer("GUARD_ATTACK", npc, _nextTarget);
  176. cancelQuestTimer("CHECK", npc, null);
  177. if (_current != null)
  178. {
  179. _current.setDisplayEffect(2);
  180. _current.setIsRunning(false);
  181. _current = null;
  182. }
  183. return super.onKill(npc, killer, isSummon);
  184. }
  185. public static void main(String[] args)
  186. {
  187. new Anais();
  188. }
  189. }