Ranku.java 4.2 KB

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