Ranku.java 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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.HashSet;
  17. import java.util.Set;
  18. import ai.group_template.L2AttackableAIScript;
  19. import com.l2jserver.gameserver.model.actor.L2Npc;
  20. import com.l2jserver.gameserver.model.actor.instance.L2MonsterInstance;
  21. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  22. import com.l2jserver.gameserver.model.skills.L2Skill;
  23. import com.l2jserver.gameserver.network.NpcStringId;
  24. import com.l2jserver.gameserver.network.clientpackets.Say2;
  25. import com.l2jserver.gameserver.network.serverpackets.NpcSay;
  26. import com.l2jserver.gameserver.util.MinionList;
  27. /**
  28. * Ranku's AI.
  29. * @author GKR
  30. */
  31. public class Ranku extends L2AttackableAIScript
  32. {
  33. private static final int RANKU = 25542;
  34. private static final int MINION = 32305;
  35. private static final int MINION_2 = 25543;
  36. private static Set<Integer> myTrackingSet = new HashSet<>();
  37. @Override
  38. public final String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
  39. {
  40. if (event.equalsIgnoreCase("checkup") && (npc.getNpcId() == RANKU) && !npc.isDead())
  41. {
  42. for (L2MonsterInstance minion : ((L2MonsterInstance) npc).getMinionList().getSpawnedMinions())
  43. {
  44. if ((minion != null) && !minion.isDead() && myTrackingSet.contains(minion.getObjectId()))
  45. {
  46. L2PcInstance[] players = minion.getKnownList().getKnownPlayers().values().toArray(new L2PcInstance[minion.getKnownList().getKnownPlayers().size()]);
  47. L2PcInstance killer = players[getRandom(players.length)];
  48. minion.reduceCurrentHp(minion.getMaxHp() / 100, killer, null);
  49. }
  50. }
  51. startQuestTimer("checkup", 1000, npc, null);
  52. }
  53. return null;
  54. }
  55. @Override
  56. public String onAttack(L2Npc npc, L2PcInstance attacker, int damage, boolean isPet, L2Skill skill)
  57. {
  58. if (npc.getNpcId() == RANKU)
  59. {
  60. for (L2MonsterInstance minion : ((L2MonsterInstance) npc).getMinionList().getSpawnedMinions())
  61. {
  62. if ((minion != null) && !minion.isDead() && !myTrackingSet.contains(minion.getObjectId()))
  63. {
  64. minion.broadcastPacket(new NpcSay(minion.getObjectId(), Say2.ALL, minion.getNpcId(), NpcStringId.DONT_KILL_ME_PLEASE_SOMETHINGS_STRANGLING_ME));
  65. startQuestTimer("checkup", 1000, npc, null);
  66. synchronized (myTrackingSet)
  67. {
  68. myTrackingSet.add(minion.getObjectId());
  69. }
  70. }
  71. }
  72. }
  73. return super.onAttack(npc, attacker, damage, isPet, skill);
  74. }
  75. @Override
  76. public String onKill(L2Npc npc, L2PcInstance killer, boolean isPet)
  77. {
  78. if (npc.getNpcId() == MINION)
  79. {
  80. if (myTrackingSet.contains(npc.getObjectId()))
  81. {
  82. synchronized (myTrackingSet)
  83. {
  84. myTrackingSet.remove(npc.getObjectId());
  85. }
  86. }
  87. final L2MonsterInstance master = ((L2MonsterInstance) npc).getLeader();
  88. if ((master != null) && !master.isDead())
  89. {
  90. L2MonsterInstance minion2 = MinionList.spawnMinion(master, MINION_2);
  91. minion2.teleToLocation(npc.getX(), npc.getY(), npc.getZ());
  92. }
  93. }
  94. else if (npc.getNpcId() == RANKU)
  95. {
  96. for (L2MonsterInstance minion : ((L2MonsterInstance) npc).getMinionList().getSpawnedMinions())
  97. {
  98. if (myTrackingSet.contains(minion.getObjectId()))
  99. {
  100. synchronized (myTrackingSet)
  101. {
  102. myTrackingSet.remove(minion.getObjectId());
  103. }
  104. }
  105. }
  106. }
  107. return super.onKill(npc, killer, isPet);
  108. }
  109. public Ranku(int id, String name, String descr)
  110. {
  111. super(id, name, descr);
  112. addAttackId(RANKU);
  113. addKillId(RANKU);
  114. addKillId(MINION);
  115. }
  116. public static void main(String[] args)
  117. {
  118. new Ranku(-1, "Ranku", "ai");
  119. }
  120. }