SilentValley.java 5.9 KB

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