TurekOrcs.java 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*
  2. * Copyright (C) 2004-2015 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.group_template;
  20. import ai.npc.AbstractNpcAI;
  21. import com.l2jserver.gameserver.ai.CtrlIntention;
  22. import com.l2jserver.gameserver.model.L2Object;
  23. import com.l2jserver.gameserver.model.L2World;
  24. import com.l2jserver.gameserver.model.Location;
  25. import com.l2jserver.gameserver.model.actor.L2Attackable;
  26. import com.l2jserver.gameserver.model.actor.L2Npc;
  27. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  28. import com.l2jserver.gameserver.network.NpcStringId;
  29. /**
  30. * Turek Orcs AI - flee and return with assistance
  31. * @author GKR
  32. */
  33. public final class TurekOrcs extends AbstractNpcAI
  34. {
  35. // NPC's
  36. private static final int[] MOBS =
  37. {
  38. 20494, // Turek War Hound
  39. 20495, // Turek Orc Warlord
  40. 20497, // Turek Orc Skirmisher
  41. 20498, // Turek Orc Supplier
  42. 20499, // Turek Orc Footman
  43. 20500, // Turek Orc Sentinel
  44. };
  45. private TurekOrcs()
  46. {
  47. super(TurekOrcs.class.getSimpleName(), "ai/group_template");
  48. addAttackId(MOBS);
  49. addEventReceivedId(MOBS);
  50. addMoveFinishedId(MOBS);
  51. }
  52. @Override
  53. public String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
  54. {
  55. if (event.equalsIgnoreCase("checkState") && !npc.isDead() && (npc.getAI().getIntention() != CtrlIntention.AI_INTENTION_ATTACK))
  56. {
  57. if ((npc.getCurrentHp() > (npc.getMaxHp() * 0.7)) && (npc.getVariables().getInt("state") == 2))
  58. {
  59. npc.getVariables().set("state", 3);
  60. ((L2Attackable) npc).returnHome();
  61. }
  62. else
  63. {
  64. npc.getVariables().remove("state");
  65. }
  66. }
  67. return super.onAdvEvent(event, npc, player);
  68. }
  69. @Override
  70. public String onAttack(L2Npc npc, L2PcInstance attacker, int damage, boolean isSummon)
  71. {
  72. if (!npc.getVariables().hasVariable("isHit"))
  73. {
  74. npc.getVariables().set("isHit", 1);
  75. }
  76. else if ((npc.getCurrentHp() < (npc.getMaxHp() * 0.5)) && (npc.getCurrentHp() > (npc.getMaxHp() * 0.3)) && (attacker.getCurrentHp() > (attacker.getMaxHp() * 0.25)) && npc.hasAIValue("fleeX") && npc.hasAIValue("fleeY") && npc.hasAIValue("fleeZ") && (npc.getVariables().getInt("state") == 0) && (getRandom(100) < 10))
  77. {
  78. // Say and flee
  79. broadcastNpcSay(npc, 0, NpcStringId.getNpcStringId(getRandom(1000007, 1000027)));
  80. npc.disableCoreAI(true); // to avoid attacking behaviour, while flee
  81. npc.setIsRunning(true);
  82. npc.getAI().setIntention(CtrlIntention.AI_INTENTION_MOVE_TO, new Location(npc.getAIValue("fleeX"), npc.getAIValue("fleeY"), npc.getAIValue("fleeZ")));
  83. npc.getVariables().set("state", 1);
  84. npc.getVariables().set("attacker", attacker.getObjectId());
  85. }
  86. return super.onAttack(npc, attacker, damage, isSummon);
  87. }
  88. @Override
  89. public String onEventReceived(String eventName, L2Npc sender, L2Npc receiver, L2Object reference)
  90. {
  91. if (eventName.equals("WARNING") && !receiver.isDead() && (receiver.getAI().getIntention() != CtrlIntention.AI_INTENTION_ATTACK) && (reference != null) && (reference.getActingPlayer() != null) && !reference.getActingPlayer().isDead())
  92. {
  93. receiver.getVariables().set("state", 3);
  94. receiver.setIsRunning(true);
  95. ((L2Attackable) receiver).addDamageHate(reference.getActingPlayer(), 0, 99999);
  96. receiver.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, reference.getActingPlayer());
  97. }
  98. return super.onEventReceived(eventName, sender, receiver, reference);
  99. }
  100. @Override
  101. public void onMoveFinished(L2Npc npc)
  102. {
  103. // NPC reaches flee point
  104. if (npc.getVariables().getInt("state") == 1)
  105. {
  106. if ((npc.getX() == npc.getAIValue("fleeX")) && (npc.getY() == npc.getAIValue("fleeY")))
  107. {
  108. npc.disableCoreAI(false);
  109. startQuestTimer("checkState", 15000, npc, null);
  110. npc.getVariables().set("state", 2);
  111. npc.broadcastEvent("WARNING", 400, L2World.getInstance().getPlayer(npc.getVariables().getInt("attacker")));
  112. }
  113. else
  114. {
  115. npc.getAI().setIntention(CtrlIntention.AI_INTENTION_MOVE_TO, new Location(npc.getAIValue("fleeX"), npc.getAIValue("fleeY"), npc.getAIValue("fleeZ")));
  116. }
  117. }
  118. else if ((npc.getVariables().getInt("state") == 3) && npc.staysInSpawnLoc())
  119. {
  120. npc.disableCoreAI(false);
  121. npc.getVariables().remove("state");
  122. }
  123. }
  124. public static void main(String[] args)
  125. {
  126. new TurekOrcs();
  127. }
  128. }