Epidos.java 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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.Arrays;
  17. import java.util.Map;
  18. import javolution.util.FastMap;
  19. import ai.group_template.L2AttackableAIScript;
  20. import com.l2jserver.gameserver.ai.CtrlIntention;
  21. import com.l2jserver.gameserver.model.actor.L2Npc;
  22. import com.l2jserver.gameserver.model.actor.instance.L2MonsterInstance;
  23. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  24. import com.l2jserver.gameserver.util.MinionList;
  25. import com.l2jserver.util.Rnd;
  26. /**
  27. * Manages minion's spawn, idle despawn and Teleportation Cube spawn.
  28. * @author GKR
  29. */
  30. public class Epidos extends L2AttackableAIScript
  31. {
  32. private static final int[] EPIDOSES =
  33. {
  34. 25609, 25610, 25611, 25612
  35. };
  36. private static final int[] MINIONS =
  37. {
  38. 25605, 25606, 25607, 25608
  39. };
  40. private static final int[] MINIONS_COUNT =
  41. {
  42. 3, 6, 11
  43. };
  44. private final Map<Integer, Double> _lastHp = new FastMap<Integer, Double>();
  45. @Override
  46. public final String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
  47. {
  48. if (event.equalsIgnoreCase("check_minions"))
  49. {
  50. if ((Rnd.get(1000) > 250) && _lastHp.containsKey(npc.getObjectId()))
  51. {
  52. int hpDecreasePercent = (int) (((_lastHp.get(npc.getObjectId()) - npc.getCurrentHp()) * 100) / npc.getMaxHp());
  53. int minionsCount = 0;
  54. int spawnedMinions = ((L2MonsterInstance) npc).getMinionList().countSpawnedMinions();
  55. if ((hpDecreasePercent > 5) && (hpDecreasePercent <= 15) && (spawnedMinions <= 9))
  56. {
  57. minionsCount = MINIONS_COUNT[0];
  58. }
  59. else if ((((hpDecreasePercent > 1) && (hpDecreasePercent <= 5)) || ((hpDecreasePercent > 15) && (hpDecreasePercent <= 30))) && (spawnedMinions <= 6))
  60. {
  61. minionsCount = MINIONS_COUNT[1];
  62. }
  63. else if (spawnedMinions == 0)
  64. {
  65. minionsCount = MINIONS_COUNT[2];
  66. }
  67. for (int i = 0; i < minionsCount; i++)
  68. {
  69. MinionList.spawnMinion((L2MonsterInstance) npc, MINIONS[Arrays.binarySearch(EPIDOSES, npc.getNpcId())]);
  70. }
  71. _lastHp.put(npc.getObjectId(), npc.getCurrentHp());
  72. }
  73. startQuestTimer("check_minions", 10000, npc, null);
  74. }
  75. else if (event.equalsIgnoreCase("check_idle"))
  76. {
  77. if (npc.getAI().getIntention() == CtrlIntention.AI_INTENTION_ACTIVE)
  78. {
  79. npc.deleteMe();
  80. }
  81. else
  82. {
  83. startQuestTimer("check_idle", 600000, npc, null);
  84. }
  85. }
  86. return null;
  87. }
  88. @Override
  89. public String onKill(L2Npc npc, L2PcInstance killer, boolean isPet)
  90. {
  91. if (npc.isInsideRadius(-45474, 247450, -13994, 2000, true, false))
  92. {
  93. addSpawn(32376, -45482, 246277, -14184, 0, false, 0, false);
  94. }
  95. _lastHp.remove(npc.getObjectId());
  96. return super.onKill(npc, killer, isPet);
  97. }
  98. @Override
  99. public final String onSpawn(L2Npc npc)
  100. {
  101. startQuestTimer("check_minions", 10000, npc, null);
  102. startQuestTimer("check_idle", 600000, npc, null);
  103. _lastHp.put(npc.getObjectId(), (double) npc.getMaxHp());
  104. return super.onSpawn(npc);
  105. }
  106. public Epidos(int id, String name, String descr)
  107. {
  108. super(id, name, descr);
  109. for (int i : EPIDOSES)
  110. {
  111. addKillId(i);
  112. addSpawnId(i);
  113. }
  114. }
  115. public static void main(String[] args)
  116. {
  117. new Epidos(-1, "Epidos", "ai");
  118. }
  119. }