DenOfEvil.java 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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.ThreadPoolManager;
  22. import com.l2jserver.gameserver.datatables.SkillData;
  23. import com.l2jserver.gameserver.instancemanager.ZoneManager;
  24. import com.l2jserver.gameserver.model.Location;
  25. import com.l2jserver.gameserver.model.actor.L2Character;
  26. import com.l2jserver.gameserver.model.actor.L2Npc;
  27. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  28. import com.l2jserver.gameserver.model.skills.Skill;
  29. import com.l2jserver.gameserver.model.zone.type.L2EffectZone;
  30. import com.l2jserver.gameserver.network.SystemMessageId;
  31. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  32. import com.l2jserver.gameserver.util.Util;
  33. /**
  34. * Dummy AI for spawns/respawns only for testing.
  35. * @author Gnacik
  36. */
  37. public final class DenOfEvil extends AbstractNpcAI
  38. {
  39. // private static final int _buffer_id = 32656;
  40. protected static final int[] EYE_IDS =
  41. {
  42. 18812,
  43. 18813,
  44. 18814
  45. };
  46. private static final int SKILL_ID = 6150; // others +2
  47. private static final Location[] EYE_SPAWNS =
  48. {
  49. new Location(71544, -129400, -3360, 16472),
  50. new Location(70954, -128854, -3360, 16),
  51. new Location(72145, -128847, -3368, 32832),
  52. new Location(76147, -128372, -3144, 16152),
  53. new Location(71573, -128309, -3360, 49152),
  54. new Location(75211, -127441, -3152, 0),
  55. new Location(77005, -127406, -3144, 32784),
  56. new Location(75965, -126486, -3144, 49120),
  57. new Location(70972, -126429, -3016, 19208),
  58. new Location(69916, -125838, -3024, 2840),
  59. new Location(71658, -125459, -3016, 35136),
  60. new Location(70605, -124646, -3040, 52104),
  61. new Location(67283, -123237, -2912, 12376),
  62. new Location(68383, -122754, -2912, 27904),
  63. new Location(74137, -122733, -3024, 13272),
  64. new Location(66736, -122007, -2896, 60576),
  65. new Location(73289, -121769, -3024, 1024),
  66. new Location(67894, -121491, -2912, 43872),
  67. new Location(75530, -121477, -3008, 34424),
  68. new Location(74117, -120459, -3024, 52344),
  69. new Location(69608, -119855, -2534, 17251),
  70. new Location(71014, -119027, -2520, 31904),
  71. new Location(68944, -118964, -2527, 59874),
  72. new Location(62261, -118263, -3072, 12888),
  73. new Location(70300, -117942, -2528, 46208),
  74. new Location(74312, -117583, -2272, 15280),
  75. new Location(63276, -117409, -3064, 24760),
  76. new Location(68104, -117192, -2168, 15888),
  77. new Location(73758, -116945, -2216, 0),
  78. new Location(74944, -116858, -2220, 30892),
  79. new Location(61715, -116623, -3064, 59888),
  80. new Location(69140, -116464, -2168, 28952),
  81. new Location(67311, -116374, -2152, 1280),
  82. new Location(62459, -116370, -3064, 48624),
  83. new Location(74475, -116260, -2216, 47456),
  84. new Location(68333, -115015, -2168, 45136),
  85. new Location(68280, -108129, -1160, 17992),
  86. new Location(62983, -107259, -2384, 12552),
  87. new Location(67062, -107125, -1144, 64008),
  88. new Location(68893, -106954, -1160, 36704),
  89. new Location(63848, -106771, -2384, 32784),
  90. new Location(62372, -106514, -2384, 0),
  91. new Location(67838, -106143, -1160, 51232),
  92. new Location(62905, -106109, -2384, 51288)
  93. };
  94. private DenOfEvil()
  95. {
  96. super(DenOfEvil.class.getSimpleName(), "ai/group_template");
  97. addKillId(EYE_IDS);
  98. addSpawnId(EYE_IDS);
  99. for (Location loc : EYE_SPAWNS)
  100. {
  101. addSpawn(EYE_IDS[getRandom(EYE_IDS.length)], loc, false, 0);
  102. }
  103. }
  104. private int getSkillIdByNpcId(int npcId)
  105. {
  106. int diff = npcId - EYE_IDS[0];
  107. diff *= 2;
  108. return SKILL_ID + diff;
  109. }
  110. @Override
  111. public String onSpawn(L2Npc npc)
  112. {
  113. npc.disableCoreAI(true);
  114. npc.setIsImmobilized(true);
  115. L2EffectZone zone = ZoneManager.getInstance().getZone(npc, L2EffectZone.class);
  116. if (zone == null)
  117. {
  118. _log.warning("NPC " + npc + " spawned outside of L2EffectZone, check your zone coords! X:" + npc.getX() + " Y:" + npc.getY() + " Z:" + npc.getZ());
  119. return null;
  120. }
  121. int skillId = getSkillIdByNpcId(npc.getId());
  122. int skillLevel = zone.getSkillLevel(skillId);
  123. zone.addSkill(skillId, skillLevel + 1);
  124. if (skillLevel == 3) // 3+1=4
  125. {
  126. ThreadPoolManager.getInstance().scheduleAi(new KashaDestruction(zone), 2 * 60 * 1000l);
  127. zone.broadcastPacket(SystemMessage.getSystemMessage(SystemMessageId.KASHA_EYE_PITCHES_TOSSES_EXPLODE));
  128. }
  129. else if (skillLevel == 2)
  130. {
  131. zone.broadcastPacket(SystemMessage.getSystemMessage(SystemMessageId.I_CAN_FEEL_ENERGY_KASHA_EYE_GETTING_STRONGER_RAPIDLY));
  132. }
  133. return super.onSpawn(npc);
  134. }
  135. @Override
  136. public String onKill(L2Npc npc, L2PcInstance killer, boolean isSummon)
  137. {
  138. ThreadPoolManager.getInstance().scheduleAi(new RespawnNewEye(npc.getLocation()), 15000);
  139. L2EffectZone zone = ZoneManager.getInstance().getZone(npc, L2EffectZone.class);
  140. if (zone == null)
  141. {
  142. _log.warning("NPC " + npc + " killed outside of L2EffectZone, check your zone coords! X:" + npc.getX() + " Y:" + npc.getY() + " Z:" + npc.getZ());
  143. return null;
  144. }
  145. int skillId = getSkillIdByNpcId(npc.getId());
  146. int skillLevel = zone.getSkillLevel(skillId);
  147. zone.addSkill(skillId, skillLevel - 1);
  148. return super.onKill(npc, killer, isSummon);
  149. }
  150. private class RespawnNewEye implements Runnable
  151. {
  152. private final Location _loc;
  153. public RespawnNewEye(Location loc)
  154. {
  155. _loc = loc;
  156. }
  157. @Override
  158. public void run()
  159. {
  160. addSpawn(EYE_IDS[getRandom(EYE_IDS.length)], _loc, false, 0);
  161. }
  162. }
  163. private class KashaDestruction implements Runnable
  164. {
  165. L2EffectZone _zone;
  166. public KashaDestruction(L2EffectZone zone)
  167. {
  168. _zone = zone;
  169. }
  170. @Override
  171. public void run()
  172. {
  173. for (int i = SKILL_ID; i <= (SKILL_ID + 4); i = i + 2)
  174. {
  175. // test 3 skills if some is lvl 4
  176. if (_zone.getSkillLevel(i) > 3)
  177. {
  178. destroyZone();
  179. break;
  180. }
  181. }
  182. }
  183. private void destroyZone()
  184. {
  185. for (L2Character character : _zone.getCharactersInside())
  186. {
  187. if (character == null)
  188. {
  189. continue;
  190. }
  191. if (character.isPlayable())
  192. {
  193. Skill skill = SkillData.getInstance().getSkill(6149, 1);
  194. skill.applyEffects(character, character);
  195. }
  196. else
  197. {
  198. if (character.doDie(null)) // mobs die
  199. {
  200. if (character.isNpc())
  201. {
  202. // respawn eye
  203. L2Npc npc = (L2Npc) character;
  204. if (Util.contains(EYE_IDS, npc.getId()))
  205. {
  206. ThreadPoolManager.getInstance().scheduleAi(new RespawnNewEye(npc.getLocation()), 15000);
  207. }
  208. }
  209. }
  210. }
  211. }
  212. for (int i = SKILL_ID; i <= (SKILL_ID + 4); i = i + 2)
  213. {
  214. _zone.removeSkill(i);
  215. }
  216. }
  217. }
  218. public static void main(String[] args)
  219. {
  220. new DenOfEvil();
  221. }
  222. }