Ranku.java 4.1 KB

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