DenOfEvil.java 7.2 KB

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