SilentValley.java 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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.L2Character;
  24. import com.l2jserver.gameserver.model.actor.L2Npc;
  25. import com.l2jserver.gameserver.model.actor.L2Summon;
  26. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  27. import com.l2jserver.gameserver.model.holders.SkillHolder;
  28. import com.l2jserver.gameserver.network.NpcStringId;
  29. import com.l2jserver.gameserver.network.clientpackets.Say2;
  30. /**
  31. * Silent Valley AI
  32. * @author malyelfik
  33. */
  34. public class SilentValley extends AbstractNpcAI
  35. {
  36. // Skills
  37. private static final SkillHolder BETRAYAL = new SkillHolder(6033, 1); // Treasure Seeker's Betrayal
  38. private static final SkillHolder BLAZE = new SkillHolder(4157, 10); // NPC Blaze - Magic
  39. // Item
  40. private static final int SACK = 13799; // Treasure Sack of the Ancient Giants
  41. // Chance
  42. private static final int SPAWN_CHANCE = 2;
  43. private static final int CHEST_DIE_CHANCE = 5;
  44. // Monsters
  45. private static final int CHEST = 18693; // Treasure Chest of the Ancient Giants
  46. private static final int GUARD1 = 18694; // Treasure Chest Guard
  47. private static final int GUARD2 = 18695; // Treasure Chest Guard
  48. private static final int[] MOBS =
  49. {
  50. 20965, // Chimera Piece
  51. 20966, // Changed Creation
  52. 20967, // Past Creature
  53. 20968, // Nonexistent Man
  54. 20969, // Giant's Shadow
  55. 20970, // Soldier of Ancient Times
  56. 20971, // Warrior of Ancient Times
  57. 20972, // Shaman of Ancient Times
  58. 20973, // Forgotten Ancient People
  59. };
  60. private SilentValley()
  61. {
  62. super(SilentValley.class.getSimpleName(), "ai/group_template");
  63. addAttackId(MOBS);
  64. addAttackId(CHEST, GUARD1, GUARD2);
  65. addEventReceivedId(GUARD1, GUARD2);
  66. addKillId(MOBS);
  67. addSeeCreatureId(MOBS);
  68. addSeeCreatureId(GUARD1, GUARD2);
  69. addSpawnId(CHEST, GUARD2);
  70. }
  71. @Override
  72. public String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
  73. {
  74. if ((npc != null) && !npc.isDead())
  75. {
  76. switch (event)
  77. {
  78. case "CLEAR":
  79. npc.doDie(null);
  80. break;
  81. case "CLEAR_EVENT":
  82. npc.broadcastEvent("CLEAR_ALL_INSTANT", 2000, null);
  83. npc.doDie(null);
  84. break;
  85. case "SPAWN_CHEST":
  86. addSpawn(CHEST, npc.getX() - 100, npc.getY(), npc.getZ() - 100, 0, false, 0);
  87. break;
  88. }
  89. }
  90. return null;
  91. }
  92. @Override
  93. public String onAttack(L2Npc npc, L2PcInstance player, int damage, boolean isSummon)
  94. {
  95. switch (npc.getId())
  96. {
  97. case CHEST:
  98. {
  99. if (!isSummon && npc.isScriptValue(0))
  100. {
  101. npc.setScriptValue(1);
  102. broadcastNpcSay(npc, Say2.NPC_ALL, NpcStringId.YOU_WILL_BE_CURSED_FOR_SEEKING_THE_TREASURE);
  103. npc.setTarget(player);
  104. npc.doCast(BETRAYAL.getSkill());
  105. }
  106. else if (isSummon || (getRandom(100) < CHEST_DIE_CHANCE))
  107. {
  108. npc.dropItem(player, SACK, 1);
  109. npc.broadcastEvent("CLEAR_ALL", 2000, null);
  110. npc.doDie(null);
  111. cancelQuestTimer("CLEAR_EVENT", npc, null);
  112. }
  113. break;
  114. }
  115. case GUARD1:
  116. case GUARD2:
  117. {
  118. npc.setTarget(player);
  119. npc.doCast(BLAZE.getSkill());
  120. attackPlayer((L2Attackable) npc, player);
  121. break;
  122. }
  123. default:
  124. {
  125. if (isSummon)
  126. {
  127. attackPlayer((L2Attackable) npc, player);
  128. }
  129. }
  130. }
  131. return super.onAttack(npc, player, damage, isSummon);
  132. }
  133. @Override
  134. public String onKill(L2Npc npc, L2PcInstance killer, boolean isSummon)
  135. {
  136. if (getRandom(1000) < SPAWN_CHANCE)
  137. {
  138. final int newZ = npc.getZ() + 100;
  139. addSpawn(GUARD2, npc.getX() + 100, npc.getY(), newZ, 0, false, 0);
  140. addSpawn(GUARD1, npc.getX() - 100, npc.getY(), newZ, 0, false, 0);
  141. addSpawn(GUARD1, npc.getX(), npc.getY() + 100, newZ, 0, false, 0);
  142. addSpawn(GUARD1, npc.getX(), npc.getY() - 100, newZ, 0, false, 0);
  143. }
  144. return super.onKill(npc, killer, isSummon);
  145. }
  146. @Override
  147. public String onSeeCreature(L2Npc npc, L2Character creature, boolean isSummon)
  148. {
  149. if (creature.isPlayable())
  150. {
  151. final L2PcInstance player = (isSummon) ? ((L2Summon) creature).getOwner() : creature.getActingPlayer();
  152. if ((npc.getId() == GUARD1) || (npc.getId() == GUARD2))
  153. {
  154. npc.setTarget(player);
  155. npc.doCast(BLAZE.getSkill());
  156. attackPlayer((L2Attackable) npc, player);
  157. }
  158. else if (creature.isAffectedBySkill(BETRAYAL.getSkillId()))
  159. {
  160. attackPlayer((L2Attackable) npc, player);
  161. }
  162. }
  163. return super.onSeeCreature(npc, creature, isSummon);
  164. }
  165. @Override
  166. public String onSpawn(L2Npc npc)
  167. {
  168. if (npc.getId() == CHEST)
  169. {
  170. npc.setIsInvul(true);
  171. startQuestTimer("CLEAR_EVENT", 300000, npc, null);
  172. }
  173. else
  174. {
  175. startQuestTimer("SPAWN_CHEST", 10000, npc, null);
  176. }
  177. return super.onSpawn(npc);
  178. }
  179. @Override
  180. public String onEventReceived(String eventName, L2Npc sender, L2Npc receiver, L2Object reference)
  181. {
  182. if ((receiver != null) && !receiver.isDead())
  183. {
  184. switch (eventName)
  185. {
  186. case "CLEAR_ALL":
  187. startQuestTimer("CLEAR", 60000, receiver, null);
  188. break;
  189. case "CLEAR_ALL_INSTANT":
  190. receiver.doDie(null);
  191. break;
  192. }
  193. }
  194. return super.onEventReceived(eventName, sender, receiver, reference);
  195. }
  196. public static void main(String[] args)
  197. {
  198. new SilentValley();
  199. }
  200. }