Epidos.java 3.9 KB

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