DemonPrince.java 3.9 KB

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