DemonPrince.java 3.9 KB

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