Monastery.java 5.8 KB

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