PrisonGuards.java 8.1 KB

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