DemonPrince.java 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*
  2. * This program is free software: you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation, either version 3 of the License, or (at your option) any later
  5. * version.
  6. *
  7. * This program is distributed in the hope that it will be useful, but WITHOUT
  8. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10. * details.
  11. *
  12. * You should have received a copy of the GNU General Public License along with
  13. * this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. package ai.individual;
  16. import java.util.Map;
  17. import javolution.util.FastMap;
  18. import ai.npc.AbstractNpcAI;
  19. import com.l2jserver.gameserver.model.actor.L2Npc;
  20. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  21. import com.l2jserver.gameserver.model.holders.SkillHolder;
  22. import com.l2jserver.gameserver.model.skills.L2Skill;
  23. /**
  24. * @author GKR
  25. */
  26. public class DemonPrince extends AbstractNpcAI
  27. {
  28. private static final int DEMON_PRINCE = 25540;
  29. private static final int FIEND = 25541;
  30. private static final SkillHolder UD = new SkillHolder(5044, 2);
  31. private static final SkillHolder[] AOE =
  32. {
  33. new SkillHolder(5376, 4),
  34. new SkillHolder(5376, 5),
  35. new SkillHolder(5376, 6)
  36. };
  37. private static final Map<Integer, Boolean> _attackState = new FastMap<>();
  38. private DemonPrince(String name, String descr)
  39. {
  40. super(name, descr);
  41. addAttackId(DEMON_PRINCE);
  42. addKillId(DEMON_PRINCE);
  43. addSpawnId(FIEND);
  44. }
  45. @Override
  46. public String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
  47. {
  48. if (event.equalsIgnoreCase("cast") && (npc != null) && (npc.getNpcId() == FIEND) && !npc.isDead())
  49. {
  50. npc.doCast(AOE[getRandom(AOE.length)].getSkill());
  51. }
  52. return null;
  53. }
  54. @Override
  55. public String onAttack(L2Npc npc, L2PcInstance attacker, int damage, boolean isPet, L2Skill skill)
  56. {
  57. if (!npc.isDead())
  58. {
  59. if (!_attackState.containsKey(npc.getObjectId()) && (npc.getCurrentHp() < (npc.getMaxHp() * 0.5)))
  60. {
  61. npc.doCast(UD.getSkill());
  62. spawnMinions(npc);
  63. _attackState.put(npc.getObjectId(), false);
  64. }
  65. else if ((npc.getCurrentHp() < (npc.getMaxHp() * 0.1)) && _attackState.containsKey(npc.getObjectId()) && (_attackState.get(npc.getObjectId()) == false))
  66. {
  67. npc.doCast(UD.getSkill());
  68. spawnMinions(npc);
  69. _attackState.put(npc.getObjectId(), true);
  70. }
  71. if (getRandom(1000) < 10)
  72. {
  73. spawnMinions(npc);
  74. }
  75. }
  76. return super.onAttack(npc, attacker, damage, isPet, skill);
  77. }
  78. @Override
  79. public String onKill(L2Npc npc, L2PcInstance killer, boolean isPet)
  80. {
  81. _attackState.remove(npc.getObjectId());
  82. return super.onKill(npc, killer, isPet);
  83. }
  84. @Override
  85. public final String onSpawn(L2Npc npc)
  86. {
  87. if (npc.getNpcId() == FIEND)
  88. {
  89. startQuestTimer("cast", 15000, npc, null);
  90. }
  91. return super.onSpawn(npc);
  92. }
  93. private void spawnMinions(L2Npc master)
  94. {
  95. if ((master != null) && !master.isDead())
  96. {
  97. int instanceId = master.getInstanceId();
  98. int x = master.getX();
  99. int y = master.getY();
  100. int z = master.getZ();
  101. addSpawn(FIEND, x + 200, y, z, 0, false, 0, false, instanceId);
  102. addSpawn(FIEND, x - 200, y, z, 0, false, 0, false, instanceId);
  103. addSpawn(FIEND, x - 100, y - 140, z, 0, false, 0, false, instanceId);
  104. addSpawn(FIEND, x - 100, y + 140, z, 0, false, 0, false, instanceId);
  105. addSpawn(FIEND, x + 100, y - 140, z, 0, false, 0, false, instanceId);
  106. addSpawn(FIEND, x + 100, y + 140, z, 0, false, 0, false, instanceId);
  107. }
  108. }
  109. public static void main(String[] args)
  110. {
  111. new DemonPrince(DemonPrince.class.getSimpleName(), "ai");
  112. }
  113. }