DemonPrince.java 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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 hellbound.AI;
  20. import java.util.Map;
  21. import javolution.util.FastMap;
  22. import ai.npc.AbstractNpcAI;
  23. import com.l2jserver.gameserver.model.actor.L2Npc;
  24. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  25. import com.l2jserver.gameserver.model.holders.SkillHolder;
  26. import com.l2jserver.gameserver.model.skills.Skill;
  27. /**
  28. * Demon Prince's AI.
  29. * @author GKR
  30. */
  31. public final class DemonPrince extends AbstractNpcAI
  32. {
  33. // NPCs
  34. private static final int DEMON_PRINCE = 25540;
  35. private static final int FIEND = 25541;
  36. // Skills
  37. private static final SkillHolder UD = new SkillHolder(5044, 2);
  38. private static final SkillHolder[] AOE =
  39. {
  40. new SkillHolder(5376, 4),
  41. new SkillHolder(5376, 5),
  42. new SkillHolder(5376, 6),
  43. };
  44. private static final Map<Integer, Boolean> ATTACK_STATE = new FastMap<>();
  45. public DemonPrince()
  46. {
  47. super(DemonPrince.class.getSimpleName(), "hellbound/AI");
  48. addAttackId(DEMON_PRINCE);
  49. addKillId(DEMON_PRINCE);
  50. addSpawnId(FIEND);
  51. }
  52. @Override
  53. public String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
  54. {
  55. if (event.equalsIgnoreCase("cast") && (npc != null) && (npc.getId() == FIEND) && !npc.isDead())
  56. {
  57. npc.doCast(AOE[getRandom(AOE.length)].getSkill());
  58. }
  59. return super.onAdvEvent(event, npc, player);
  60. }
  61. @Override
  62. public String onAttack(L2Npc npc, L2PcInstance attacker, int damage, boolean isSummon, Skill skill)
  63. {
  64. if (!npc.isDead())
  65. {
  66. if (!ATTACK_STATE.containsKey(npc.getObjectId()) && (npc.getCurrentHp() < (npc.getMaxHp() * 0.5)))
  67. {
  68. npc.doCast(UD.getSkill());
  69. spawnMinions(npc);
  70. ATTACK_STATE.put(npc.getObjectId(), false);
  71. }
  72. else if ((npc.getCurrentHp() < (npc.getMaxHp() * 0.1)) && ATTACK_STATE.containsKey(npc.getObjectId()) && (ATTACK_STATE.get(npc.getObjectId()) == false))
  73. {
  74. npc.doCast(UD.getSkill());
  75. spawnMinions(npc);
  76. ATTACK_STATE.put(npc.getObjectId(), true);
  77. }
  78. if (getRandom(1000) < 10)
  79. {
  80. spawnMinions(npc);
  81. }
  82. }
  83. return super.onAttack(npc, attacker, damage, isSummon, skill);
  84. }
  85. @Override
  86. public String onKill(L2Npc npc, L2PcInstance killer, boolean isSummon)
  87. {
  88. ATTACK_STATE.remove(npc.getObjectId());
  89. return super.onKill(npc, killer, isSummon);
  90. }
  91. @Override
  92. public final String onSpawn(L2Npc npc)
  93. {
  94. if (npc.getId() == FIEND)
  95. {
  96. startQuestTimer("cast", 15000, npc, null);
  97. }
  98. return super.onSpawn(npc);
  99. }
  100. private void spawnMinions(L2Npc master)
  101. {
  102. if ((master != null) && !master.isDead())
  103. {
  104. final int instanceId = master.getInstanceId();
  105. final int x = master.getX();
  106. final int y = master.getY();
  107. final int z = master.getZ();
  108. addSpawn(FIEND, x + 200, y, z, 0, false, 0, false, instanceId);
  109. addSpawn(FIEND, x - 200, y, z, 0, false, 0, false, instanceId);
  110. addSpawn(FIEND, x - 100, y - 140, z, 0, false, 0, false, instanceId);
  111. addSpawn(FIEND, x - 100, y + 140, z, 0, false, 0, false, instanceId);
  112. addSpawn(FIEND, x + 100, y - 140, z, 0, false, 0, false, instanceId);
  113. addSpawn(FIEND, x + 100, y + 140, z, 0, false, 0, false, instanceId);
  114. }
  115. }
  116. }