Monastery.java 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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.group_template;
  16. import java.util.Collection;
  17. import javolution.util.FastList;
  18. import com.l2jserver.gameserver.ai.CtrlIntention;
  19. import com.l2jserver.gameserver.datatables.SkillTable;
  20. import com.l2jserver.gameserver.model.L2Object;
  21. import com.l2jserver.gameserver.model.L2Skill;
  22. import com.l2jserver.gameserver.model.actor.L2Attackable;
  23. import com.l2jserver.gameserver.model.actor.L2Character;
  24. import com.l2jserver.gameserver.model.actor.L2Npc;
  25. import com.l2jserver.gameserver.model.actor.L2Playable;
  26. import com.l2jserver.gameserver.model.actor.L2Summon;
  27. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  28. import com.l2jserver.gameserver.model.actor.instance.L2PetInstance;
  29. import com.l2jserver.gameserver.network.NpcStringId;
  30. import com.l2jserver.gameserver.network.serverpackets.NpcSay;
  31. import com.l2jserver.gameserver.templates.skills.L2SkillType;
  32. import com.l2jserver.gameserver.util.Util;
  33. import com.l2jserver.util.Rnd;
  34. public class Monastery extends L2AttackableAIScript
  35. {
  36. static final int[] mobs1 = {22124, 22125, 22126, 22127, 22129};
  37. static final int[] mobs2 = {22134, 22135};
  38. static final NpcStringId[] messages = {
  39. NpcStringId.YOU_CANNOT_CARRY_A_WEAPON_WITHOUT_AUTHORIZATION,
  40. NpcStringId.S1_WHY_WOULD_YOU_CHOOSE_THE_PATH_OF_DARKNESS,
  41. NpcStringId.S1_HOW_DARE_YOU_DEFY_THE_WILL_OF_EINHASAD
  42. };
  43. public Monastery(int questId, String name, String descr)
  44. {
  45. super(questId, name, descr);
  46. registerMobs(mobs1, QuestEventType.ON_AGGRO_RANGE_ENTER, QuestEventType.ON_SPAWN, QuestEventType.ON_SPELL_FINISHED);
  47. registerMobs(mobs2, QuestEventType.ON_SKILL_SEE);
  48. }
  49. @Override
  50. public String onAggroRangeEnter(L2Npc npc, L2PcInstance player, boolean isPet)
  51. {
  52. if (Util.contains(mobs1,npc.getNpcId()) && !npc.isInCombat() && npc.getTarget() == null)
  53. {
  54. if (player.getActiveWeaponInstance() != null)
  55. {
  56. npc.setTarget(player);
  57. npc.broadcastPacket(new NpcSay(npc.getObjectId(), 0, npc.getNpcId(), messages[0]));
  58. switch (npc.getNpcId())
  59. {
  60. case 22124:
  61. case 22126:
  62. {
  63. L2Skill skill = SkillTable.getInstance().getInfo(4589,8);
  64. npc.doCast(skill);
  65. break;
  66. }
  67. default:
  68. {
  69. npc.setIsRunning(true);
  70. ((L2Attackable) npc).addDamageHate(player, 0, 999);
  71. npc.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, player);
  72. break;
  73. }
  74. }
  75. }
  76. else if (((L2Attackable)npc).getMostHated() == null)
  77. return null;
  78. }
  79. return super.onAggroRangeEnter(npc, player, isPet);
  80. }
  81. @Override
  82. public String onSkillSee(L2Npc npc, L2PcInstance caster, L2Skill skill, L2Object[] targets, boolean isPet)
  83. {
  84. if (Util.contains(mobs2,npc.getNpcId()))
  85. {
  86. if (skill.getSkillType() == L2SkillType.AGGDAMAGE && targets.length != 0)
  87. {
  88. for (L2Object obj : targets)
  89. {
  90. if (obj.equals(npc))
  91. {
  92. NpcSay packet = new NpcSay(npc.getObjectId(), 0, npc.getNpcId(), messages[Rnd.get(2)+1]);
  93. packet.addStringParameter(caster.getName());
  94. npc.broadcastPacket(packet);
  95. ((L2Attackable) npc).addDamageHate(caster, 0, 999);
  96. npc.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, caster);
  97. break;
  98. }
  99. }
  100. }
  101. }
  102. return super.onSkillSee(npc, caster, skill, targets, isPet);
  103. }
  104. @Override
  105. public String onSpawn(L2Npc npc)
  106. {
  107. if (Util.contains(mobs1,npc.getNpcId()))
  108. {
  109. FastList<L2Playable> result = new FastList<L2Playable>();
  110. Collection<L2Object> objs = npc.getKnownList().getKnownObjects().values();
  111. for (L2Object obj : objs)
  112. {
  113. if (obj instanceof L2PcInstance || obj instanceof L2PetInstance)
  114. {
  115. if (Util.checkIfInRange(npc.getAggroRange(), npc, obj, true) && !((L2Character) obj).isDead())
  116. result.add((L2Playable) obj);
  117. }
  118. }
  119. if (!result.isEmpty() && result.size() != 0)
  120. {
  121. Object[] characters = result.toArray();
  122. for (Object obj : characters)
  123. {
  124. L2Playable target = (L2Playable) (obj instanceof L2PcInstance ? obj : ((L2Summon) obj).getOwner());
  125. if (target.getActiveWeaponInstance() != null && !npc.isInCombat() && npc.getTarget() == null)
  126. {
  127. npc.setTarget(target);
  128. npc.broadcastPacket(new NpcSay(npc.getObjectId(), 0, npc.getNpcId(), messages[0]));
  129. switch (npc.getNpcId())
  130. {
  131. case 22124:
  132. case 22126:
  133. case 22127:
  134. {
  135. L2Skill skill = SkillTable.getInstance().getInfo(4589,8);
  136. npc.doCast(skill);
  137. break;
  138. }
  139. default:
  140. {
  141. npc.setIsRunning(true);
  142. ((L2Attackable) npc).addDamageHate(target, 0, 999);
  143. npc.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, target);
  144. break;
  145. }
  146. }
  147. }
  148. }
  149. }
  150. }
  151. return super.onSpawn(npc);
  152. }
  153. @Override
  154. public String onSpellFinished(L2Npc npc, L2PcInstance player, L2Skill skill)
  155. {
  156. if (Util.contains(mobs1,npc.getNpcId()) && skill.getId() == 4589)
  157. {
  158. npc.setIsRunning(true);
  159. ((L2Attackable) npc).addDamageHate(player, 0, 999);
  160. npc.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, player);
  161. }
  162. return super.onSpellFinished(npc, player, skill);
  163. }
  164. public static void main(String[] args)
  165. {
  166. new Monastery(-1, "Monastery", "ai");
  167. }
  168. }