PrisonGuards.java 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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.Map;
  17. import javolution.util.FastMap;
  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.instance.L2PcInstance;
  26. import com.l2jserver.gameserver.network.serverpackets.NpcSay;
  27. import com.l2jserver.util.Rnd;
  28. public class PrisonGuards extends L2AttackableAIScript
  29. {
  30. final private static int GUARD1 = 18367;
  31. final private static int GUARD2 = 18368;
  32. final private static int STAMP = 10013;
  33. final private static String[] GUARDVARS = {"1st","2nd","3rd","4th"};
  34. final private static String qn = "IOPRace";
  35. private final static int silence = 4098;
  36. private final static int pertification = 4578;
  37. private final static int eventTimer = 5239;
  38. private boolean _firstAttacked = false;
  39. private Map<L2Npc,Integer> _guards = new FastMap<L2Npc, Integer>();
  40. public PrisonGuards(int questId, String name, String descr)
  41. {
  42. super(questId, name, descr);
  43. int[] mob = {GUARD1, GUARD2};
  44. registerMobs(mob);
  45. // place 1
  46. _guards.put(addSpawn(GUARD2,160704,184704,-3704,49152,false,0),0);
  47. _guards.put(addSpawn(GUARD2,160384,184704,-3704,49152,false,0),0);
  48. _guards.put(addSpawn(GUARD1,160528,185216,-3704,49152,false,0),0);
  49. // place 2
  50. _guards.put(addSpawn(GUARD2,135120,171856,-3704,49152,false,0),1);
  51. _guards.put(addSpawn(GUARD2,134768,171856,-3704,49152,false,0),1);
  52. _guards.put(addSpawn(GUARD1,134928,172432,-3704,49152,false,0),1);
  53. // place 3
  54. _guards.put(addSpawn(GUARD2,146880,151504,-2872,49152,false,0),2);
  55. _guards.put(addSpawn(GUARD2,146366,151506,-2872,49152,false,0),2);
  56. _guards.put(addSpawn(GUARD1,146592,151888,-2872,49152,false,0),2);
  57. // place 4
  58. _guards.put(addSpawn(GUARD2,155840,160448,-3352,0,false,0),3);
  59. _guards.put(addSpawn(GUARD2,155840,159936,-3352,0,false,0),3);
  60. _guards.put(addSpawn(GUARD1,155578,160177,-3352,0,false,0),3);
  61. for (L2Npc npc : _guards.keySet())
  62. {
  63. npc.setIsNoRndWalk(true);
  64. npc.setIsImmobilized(true);
  65. if (npc.getNpcId() == GUARD1)
  66. {
  67. npc.setIsInvul(true);
  68. npc.disableCoreAI(true);
  69. }
  70. }
  71. }
  72. @Override
  73. public String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
  74. {
  75. if (event.equalsIgnoreCase("Respawn"))
  76. {
  77. L2Npc newGuard = addSpawn(npc.getNpcId(), npc.getSpawn().getLocx(), npc.getSpawn().getLocy(), npc.getSpawn().getLocz(), npc.getSpawn().getHeading(), false, 0);
  78. newGuard.setIsNoRndWalk(true);
  79. newGuard.setIsImmobilized(true);
  80. if (npc.getNpcId() == GUARD1)
  81. {
  82. newGuard.setIsInvul(true);
  83. newGuard.disableCoreAI(true);
  84. }
  85. int place = _guards.get(npc);
  86. _guards.remove(npc);
  87. _guards.put(newGuard, place);
  88. }
  89. else if (event.equalsIgnoreCase("attackEnd"))
  90. {
  91. if (npc.getNpcId() == GUARD2)
  92. {
  93. if (npc.getX() != npc.getSpawn().getLocx() || npc.getY() != npc.getSpawn().getLocy())
  94. {
  95. npc.teleToLocation(npc.getSpawn().getLocx(), npc.getSpawn().getLocy(), npc.getSpawn().getLocz(), npc.getSpawn().getHeading(), false);
  96. npc.setIsImmobilized(true);
  97. }
  98. ((L2Attackable) npc).getAggroList().clear();
  99. npc.getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
  100. }
  101. }
  102. return null;
  103. }
  104. @Override
  105. public String onSkillSee(L2Npc npc, L2PcInstance player, L2Skill skill, L2Object[] targets, boolean isPet)
  106. {
  107. L2Character caster = isPet ? player.getPet() : player;
  108. if (npc.getNpcId() == GUARD2)
  109. {
  110. if (_firstAttacked && caster.getFirstEffect(eventTimer) == null)
  111. {
  112. if (caster.getFirstEffect(silence) == null)
  113. castDebuff(npc, caster, silence, isPet, false, true);
  114. }
  115. }
  116. return super.onSkillSee(npc, player, skill, targets, isPet);
  117. }
  118. @Override
  119. public String onAggroRangeEnter(L2Npc npc, L2PcInstance player, boolean isPet)
  120. {
  121. L2Character target = isPet ? player.getPet() : player;
  122. if (npc.getNpcId() == GUARD2)
  123. {
  124. if (target.getFirstEffect(eventTimer) != null)
  125. {
  126. cancelQuestTimer("attackEnd", null, null);
  127. startQuestTimer("attackEnd", 180000, npc, null);
  128. npc.setIsImmobilized(false);
  129. npc.setTarget(target);
  130. npc.setRunning();
  131. ((L2Attackable) npc).addDamageHate(target, 0, 999);
  132. npc.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, target);
  133. }
  134. else
  135. {
  136. if (npc.getX() != npc.getSpawn().getLocx() || npc.getY() != npc.getSpawn().getLocy())
  137. {
  138. npc.teleToLocation(npc.getSpawn().getLocx(), npc.getSpawn().getLocy(), npc.getSpawn().getLocz(), npc.getSpawn().getHeading(), false);
  139. npc.setIsImmobilized(true);
  140. }
  141. ((L2Attackable) npc).getAggroList().remove(target);
  142. npc.getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
  143. return null;
  144. }
  145. }
  146. return super.onAggroRangeEnter(npc, player, isPet);
  147. }
  148. @Override
  149. public String onAttack(L2Npc npc, L2PcInstance player, int damage, boolean isPet)
  150. {
  151. L2Character attacker = isPet ? player.getPet() : player;
  152. _firstAttacked = true;
  153. if (attacker.getFirstEffect(eventTimer) == null)
  154. {
  155. if (attacker.getFirstEffect(pertification) == null)
  156. castDebuff(npc, attacker, pertification, isPet, true, false);
  157. npc.setTarget(null);
  158. ((L2Attackable) npc).getAggroList().remove(attacker);
  159. ((L2Attackable) npc).stopHating(attacker);
  160. ((L2Attackable) npc).abortAttack();
  161. npc.getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
  162. return null;
  163. }
  164. if (npc.getNpcId() == GUARD2)
  165. {
  166. cancelQuestTimer("attackEnd", null, null);
  167. startQuestTimer("attackEnd", 180000, npc, null);
  168. npc.setIsImmobilized(false);
  169. npc.setTarget(attacker);
  170. npc.setRunning();
  171. ((L2Attackable) npc).addDamageHate(attacker, 0, 999);
  172. npc.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, attacker);
  173. }
  174. else if (npc.getNpcId() == GUARD1 && Rnd.get(100) < 5)
  175. {
  176. if (player.getQuestState(qn) != null && player.getQuestState(qn).getInt(GUARDVARS[_guards.get(npc)]) != 1)
  177. {
  178. player.getQuestState(qn).set(GUARDVARS[_guards.get(npc)], "1");
  179. player.getQuestState(qn).giveItems(STAMP, 1);
  180. }
  181. }
  182. return super.onAttack(npc, player, damage, isPet);
  183. }
  184. @Override
  185. public String onKill(L2Npc npc, L2PcInstance player, boolean isPet)
  186. {
  187. if (_guards.containsKey(npc))
  188. startQuestTimer("Respawn", 20000, npc, null);
  189. return super.onKill(npc, player, isPet);
  190. }
  191. private void castDebuff(L2Npc npc, L2Character player, int effectId, boolean isSummon, boolean fromAttack, boolean isSpell)
  192. {
  193. if (fromAttack)
  194. {
  195. /*
  196. * 1800107 It's not easy to obtain.
  197. * 1800108 You're out of your mind coming here...
  198. */
  199. int msg = (npc.getNpcId() == GUARD1 ? 1800107 : 1800108);
  200. npc.broadcastPacket(new NpcSay(npc.getObjectId(), 0, npc.getNpcId(), msg));
  201. }
  202. L2Skill skill = SkillTable.getInstance().getInfo(effectId, isSpell ? 9 : 1);
  203. if (skill != null)
  204. {
  205. npc.setTarget(isSummon ? player.getPet() : player);
  206. npc.doCast(skill);
  207. }
  208. }
  209. public static void main(String[] args)
  210. {
  211. new PrisonGuards(-1, "PrisonGuards", "ai");
  212. }
  213. }