Ranku.java 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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 hellbound.AI;
  20. import java.util.Set;
  21. import javolution.util.FastSet;
  22. import ai.npc.AbstractNpcAI;
  23. import com.l2jserver.gameserver.model.actor.L2Npc;
  24. import com.l2jserver.gameserver.model.actor.instance.L2MonsterInstance;
  25. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  26. import com.l2jserver.gameserver.model.skills.Skill;
  27. import com.l2jserver.gameserver.network.NpcStringId;
  28. import com.l2jserver.gameserver.network.clientpackets.Say2;
  29. import com.l2jserver.gameserver.util.MinionList;
  30. /**
  31. * Ranku's AI.
  32. * @author GKR
  33. */
  34. public final class Ranku extends AbstractNpcAI
  35. {
  36. // NPCs
  37. private static final int RANKU = 25542;
  38. private static final int MINION = 32305;
  39. private static final int MINION_2 = 25543;
  40. // Misc
  41. private static final Set<Integer> MY_TRACKING_SET = new FastSet<Integer>().shared();
  42. public Ranku()
  43. {
  44. super(Ranku.class.getSimpleName(), "hellbound/AI");
  45. addAttackId(RANKU);
  46. addKillId(RANKU, MINION);
  47. }
  48. @Override
  49. public final String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
  50. {
  51. if (event.equalsIgnoreCase("checkup") && (npc.getId() == RANKU) && !npc.isDead())
  52. {
  53. for (L2MonsterInstance minion : ((L2MonsterInstance) npc).getMinionList().getSpawnedMinions())
  54. {
  55. if ((minion != null) && !minion.isDead() && MY_TRACKING_SET.contains(minion.getObjectId()))
  56. {
  57. final L2PcInstance[] players = minion.getKnownList().getKnownPlayers().values().toArray(new L2PcInstance[minion.getKnownList().getKnownPlayers().size()]);
  58. final L2PcInstance killer = players[getRandom(players.length)];
  59. minion.reduceCurrentHp(minion.getMaxHp() / 100, killer, null);
  60. }
  61. }
  62. startQuestTimer("checkup", 1000, npc, null);
  63. }
  64. return super.onAdvEvent(event, npc, player);
  65. }
  66. @Override
  67. public String onAttack(L2Npc npc, L2PcInstance attacker, int damage, boolean isSummon, Skill skill)
  68. {
  69. if (npc.getId() == RANKU)
  70. {
  71. for (L2MonsterInstance minion : ((L2MonsterInstance) npc).getMinionList().getSpawnedMinions())
  72. {
  73. if ((minion != null) && !minion.isDead() && !MY_TRACKING_SET.contains(minion.getObjectId()))
  74. {
  75. broadcastNpcSay(minion, Say2.NPC_ALL, NpcStringId.DONT_KILL_ME_PLEASE_SOMETHINGS_STRANGLING_ME);
  76. startQuestTimer("checkup", 1000, npc, null);
  77. MY_TRACKING_SET.add(minion.getObjectId());
  78. }
  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. if (npc.getId() == MINION)
  87. {
  88. if (MY_TRACKING_SET.contains(npc.getObjectId()))
  89. {
  90. MY_TRACKING_SET.remove(npc.getObjectId());
  91. }
  92. final L2MonsterInstance master = ((L2MonsterInstance) npc).getLeader();
  93. if ((master != null) && !master.isDead())
  94. {
  95. L2MonsterInstance minion2 = MinionList.spawnMinion(master, MINION_2);
  96. minion2.teleToLocation(npc.getLocation());
  97. }
  98. }
  99. else if (npc.getId() == RANKU)
  100. {
  101. for (L2MonsterInstance minion : ((L2MonsterInstance) npc).getMinionList().getSpawnedMinions())
  102. {
  103. if (MY_TRACKING_SET.contains(minion.getObjectId()))
  104. {
  105. MY_TRACKING_SET.remove(minion.getObjectId());
  106. }
  107. }
  108. }
  109. return super.onKill(npc, killer, isSummon);
  110. }
  111. }