PrisonGuards.java 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /*
  2. * Copyright (C) 2004-2014 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.model.L2Object;
  22. import com.l2jserver.gameserver.model.actor.L2Attackable;
  23. import com.l2jserver.gameserver.model.actor.L2Npc;
  24. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  25. import com.l2jserver.gameserver.model.holders.SkillHolder;
  26. import com.l2jserver.gameserver.model.skills.Skill;
  27. import com.l2jserver.gameserver.network.NpcStringId;
  28. import com.l2jserver.gameserver.network.clientpackets.Say2;
  29. /**
  30. * Prison Guards AI.
  31. * @author St3eT
  32. */
  33. public final class PrisonGuards extends AbstractNpcAI
  34. {
  35. // NPCs
  36. private static final int GUARD_HEAD = 18367; // Prison Guard
  37. private static final int GUARD = 18368; // Prison Guard
  38. // Item
  39. private static final int STAMP = 10013; // Race Stamp
  40. // Skills
  41. private static final int TIMER = 5239; // Event Timer
  42. private static final SkillHolder STONE = new SkillHolder(4578, 1); // Petrification
  43. private static final SkillHolder SILENCE = new SkillHolder(4098, 9); // Silence
  44. private PrisonGuards()
  45. {
  46. super(PrisonGuards.class.getSimpleName(), "ai/group_template");
  47. addAttackId(GUARD_HEAD, GUARD);
  48. addSpawnId(GUARD_HEAD, GUARD);
  49. addNpcHateId(GUARD);
  50. addSkillSeeId(GUARD);
  51. addSpellFinishedId(GUARD_HEAD, GUARD);
  52. }
  53. @Override
  54. public String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
  55. {
  56. if (event.equals("CLEAR_STATUS"))
  57. {
  58. npc.setScriptValue(0);
  59. }
  60. else if (event.equals("CHECK_HOME"))
  61. {
  62. if ((npc.calculateDistance(npc.getSpawn().getLocation(), false, false) > 10) && !npc.isInCombat() && !npc.isDead())
  63. {
  64. npc.teleToLocation(npc.getSpawn().getLocation());
  65. }
  66. startQuestTimer("CHECK_HOME", 30000, npc, null);
  67. }
  68. return super.onAdvEvent(event, npc, player);
  69. }
  70. @Override
  71. public String onAttack(L2Npc npc, L2PcInstance player, int damage, boolean isSummon)
  72. {
  73. if (npc.getId() == GUARD_HEAD)
  74. {
  75. if (player.isAffectedBySkill(TIMER))
  76. {
  77. if ((getRandom(100) < 10) && (npc.calculateDistance(player, true, false) < 100))
  78. {
  79. if ((getQuestItemsCount(player, STAMP) <= 3) && npc.isScriptValue(0))
  80. {
  81. giveItems(player, STAMP, 1);
  82. npc.setScriptValue(1);
  83. startQuestTimer("CLEAR_STATUS", 600000, npc, null);
  84. }
  85. }
  86. }
  87. else
  88. {
  89. npc.setTarget(player);
  90. npc.doCast(STONE.getSkill());
  91. broadcastNpcSay(npc, Say2.ALL, NpcStringId.ITS_NOT_EASY_TO_OBTAIN);
  92. }
  93. }
  94. else
  95. {
  96. if (!player.isAffectedBySkill(TIMER) && (npc.calculateDistance(npc.getSpawn().getLocation(), false, false) < 2000))
  97. {
  98. npc.setTarget(player);
  99. npc.doCast(STONE.getSkill());
  100. broadcastNpcSay(npc, Say2.ALL, NpcStringId.YOURE_OUT_OF_YOUR_MIND_COMING_HERE);
  101. }
  102. }
  103. return super.onAttack(npc, player, damage, isSummon);
  104. }
  105. @Override
  106. public String onSkillSee(L2Npc npc, L2PcInstance caster, Skill skill, L2Object[] targets, boolean isSummon)
  107. {
  108. if (!caster.isAffectedBySkill(TIMER))
  109. {
  110. npc.setTarget(caster);
  111. npc.doCast(SILENCE.getSkill());
  112. }
  113. return super.onSkillSee(npc, caster, skill, targets, isSummon);
  114. }
  115. @Override
  116. public String onSpellFinished(L2Npc npc, L2PcInstance player, Skill skill)
  117. {
  118. if ((skill == SILENCE.getSkill()) || (skill == STONE.getSkill()))
  119. {
  120. ((L2Attackable) npc).clearAggroList();
  121. npc.setTarget(npc);
  122. }
  123. return super.onSpellFinished(npc, player, skill);
  124. }
  125. @Override
  126. public boolean onNpcHate(L2Attackable mob, L2PcInstance player, boolean isSummon)
  127. {
  128. return player.isAffectedBySkill(TIMER);
  129. }
  130. @Override
  131. public String onSpawn(L2Npc npc)
  132. {
  133. if (npc.getId() == GUARD_HEAD)
  134. {
  135. npc.setIsImmobilized(true);
  136. npc.setIsInvul(true);
  137. }
  138. else
  139. {
  140. npc.setIsNoRndWalk(true);
  141. cancelQuestTimer("CHECK_HOME", npc, null);
  142. startQuestTimer("CHECK_HOME", 30000, npc, null);
  143. }
  144. return super.onSpawn(npc);
  145. }
  146. public static void main(String[] args)
  147. {
  148. new PrisonGuards();
  149. }
  150. }