SeedOfAnnihilation.java 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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 java.util.Calendar;
  17. import java.util.Map;
  18. import javolution.util.FastMap;
  19. import com.l2jserver.gameserver.datatables.SkillTable;
  20. import com.l2jserver.gameserver.datatables.SpawnTable;
  21. import com.l2jserver.gameserver.instancemanager.ZoneManager;
  22. import com.l2jserver.gameserver.model.L2Spawn;
  23. import com.l2jserver.gameserver.model.actor.L2Character;
  24. import com.l2jserver.gameserver.model.actor.L2Npc;
  25. import com.l2jserver.gameserver.model.actor.instance.L2MonsterInstance;
  26. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  27. import com.l2jserver.gameserver.model.quest.Quest;
  28. import com.l2jserver.gameserver.model.zone.L2ZoneType;
  29. import com.l2jserver.gameserver.model.zone.type.L2EffectZone;
  30. import com.l2jserver.gameserver.util.Util;
  31. import com.l2jserver.util.Rnd;
  32. public class SeedOfAnnihilation extends Quest
  33. {
  34. final private static String qn = "SeedOfAnnihilation";
  35. private static final Map<Integer, int[]> _teleportZones = new FastMap<Integer, int[]>();
  36. private static final int ANNIHILATION_FURNACE = 18928;
  37. // Strength, Agility, Wisdom
  38. private static final int[] ZONE_BUFFS = { 0, 6443, 6444, 6442 };
  39. private static final int[][] ZONE_BUFFS_LIST = { {1,2,3},{1,3,2},{2,1,3},{2,3,1},{3,2,1},{3,1,2} };
  40. // 0: Bistakon, 1: Reptilikon, 2: Cokrakon
  41. private SeedRegion[] _regionsData = new SeedRegion[3];
  42. private Long _seedsNextStatusChange;
  43. private static class SeedRegion
  44. {
  45. public int[] elite_mob_ids;
  46. public int[][] minion_lists;
  47. public int buff_zone;
  48. public int[][] af_spawns;
  49. public L2Npc[] af_npcs = new L2Npc[2];
  50. public int activeBuff = 0;
  51. public SeedRegion(int[] emi, int[][] ml, int bz, int[][] as)
  52. {
  53. elite_mob_ids = emi;
  54. minion_lists = ml;
  55. buff_zone = bz;
  56. af_spawns = as;
  57. }
  58. }
  59. static
  60. {
  61. _teleportZones.put(60002, new int[]{ -213175, 182648, -10992 });
  62. _teleportZones.put(60003, new int[]{ -181217, 186711, -10528 });
  63. _teleportZones.put(60004, new int[]{ -180211, 182984, -15152 });
  64. _teleportZones.put(60005, new int[]{ -179275, 186802, -10720 });
  65. }
  66. public void loadSeedRegionData()
  67. {
  68. // Bistakon data
  69. _regionsData[0] = new SeedRegion(new int[]{ 22750, 22751, 22752, 22753 },
  70. new int[][]{ { 22746, 22746, 22746 }, { 22747, 22747, 22747 },
  71. { 22748, 22748, 22748 }, { 22749, 22749, 22749 } }, 60006,
  72. new int[][]{ {-180450,185507,-10544,11632},{-180005,185489,-10544,11632} });
  73. // Reptilikon data
  74. _regionsData[1] = new SeedRegion(new int[]{ 22757, 22758, 22759 },
  75. new int[][]{ { 22754, 22755, 22756 } }, 60007,
  76. new int[][]{ {-179600,186998,-10704,11632},{-179295,186444,-10704,11632} });
  77. // Cokrakon data
  78. _regionsData[2] = new SeedRegion(new int[]{ 22763, 22764, 22765 },
  79. new int[][]{ { 22760, 22760, 22761 }, { 22760, 22760, 22762 },
  80. { 22761, 22761, 22760 }, { 22761, 22761, 22762 }, { 22762, 22762, 22760 },
  81. { 22762, 22762, 22761 } }, 60008,
  82. new int[][]{ {-180971,186361,-10528,11632},{-180758,186739,-10528,11632} });
  83. int buffsNow = 0;
  84. String var = loadGlobalQuestVar("SeedNextStatusChange");
  85. if (var.equalsIgnoreCase("") || Long.parseLong(var) < System.currentTimeMillis())
  86. {
  87. buffsNow = Rnd.get(ZONE_BUFFS_LIST.length);
  88. saveGlobalQuestVar("SeedBuffsList", String.valueOf(buffsNow));
  89. _seedsNextStatusChange = getNextSeedsStatusChangeTime();
  90. saveGlobalQuestVar("SeedNextStatusChange", String.valueOf(_seedsNextStatusChange));
  91. }
  92. else
  93. {
  94. _seedsNextStatusChange = Long.parseLong(var);
  95. buffsNow = Integer.parseInt(loadGlobalQuestVar("SeedBuffsList"));
  96. }
  97. for(int i = 0; i < _regionsData.length; i++)
  98. _regionsData[i].activeBuff = ZONE_BUFFS_LIST[buffsNow][i];
  99. }
  100. private Long getNextSeedsStatusChangeTime()
  101. {
  102. Calendar reenter = Calendar.getInstance();
  103. reenter.set(Calendar.SECOND, 0);
  104. reenter.set(Calendar.MINUTE, 0);
  105. reenter.set(Calendar.HOUR_OF_DAY, 13);
  106. reenter.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
  107. if (reenter.getTimeInMillis() <= System.currentTimeMillis())
  108. reenter.add(Calendar.DAY_OF_MONTH, 7);
  109. return reenter.getTimeInMillis();
  110. }
  111. public SeedOfAnnihilation(int questId, String name, String descr)
  112. {
  113. super(questId, name, descr);
  114. loadSeedRegionData();
  115. for(int i : _teleportZones.keySet())
  116. addEnterZoneId(i);
  117. for(int i = 0; i < _regionsData.length; i++)
  118. for(int j = 0; j < _regionsData[i].elite_mob_ids.length; j++)
  119. addSpawnId(_regionsData[i].elite_mob_ids[j]);
  120. addStartNpc(32739);
  121. addTalkId(32739);
  122. initialMinionsSpawn();
  123. startEffectZonesControl();
  124. }
  125. private void startEffectZonesControl()
  126. {
  127. for(int i = 0; i < _regionsData.length; i++)
  128. {
  129. for(int j = 0; j < _regionsData[i].af_spawns.length; j++)
  130. {
  131. _regionsData[i].af_npcs[j] = addSpawn(ANNIHILATION_FURNACE, _regionsData[i].af_spawns[j][0], _regionsData[i].af_spawns[j][1], _regionsData[i].af_spawns[j][2], _regionsData[i].af_spawns[j][3], false, 0);
  132. _regionsData[i].af_npcs[j].setDisplayEffect(_regionsData[i].activeBuff);
  133. }
  134. ZoneManager.getInstance().getZoneById(_regionsData[i].buff_zone, L2EffectZone.class).addSkill(ZONE_BUFFS[_regionsData[i].activeBuff], 1);
  135. }
  136. startQuestTimer("ChangeSeedsStatus", _seedsNextStatusChange - System.currentTimeMillis(), null, null);
  137. }
  138. private void initialMinionsSpawn()
  139. {
  140. for (L2Spawn spawn : SpawnTable.getInstance().getSpawnTable())
  141. {
  142. if (spawn == null)
  143. continue;
  144. for(int i = 0; i < _regionsData.length; i++)
  145. {
  146. if (Util.contains(_regionsData[i].elite_mob_ids, spawn.getNpcid()))
  147. {
  148. L2MonsterInstance mob = (L2MonsterInstance) spawn.getLastSpawn();
  149. if (mob != null)
  150. spawnGroupOfMinion(mob, _regionsData[i].minion_lists[Rnd.get(_regionsData[i].minion_lists.length)]);
  151. }
  152. }
  153. }
  154. }
  155. private void spawnGroupOfMinion(L2MonsterInstance npc, int[] mobIds)
  156. {
  157. for (int i = 0; i < mobIds.length; i++)
  158. addMinion(npc, mobIds[i]);
  159. }
  160. @Override
  161. public String onSpawn(L2Npc npc)
  162. {
  163. for(int i = 0; i < _regionsData.length; i++)
  164. {
  165. if (Util.contains(_regionsData[i].elite_mob_ids, npc.getNpcId()))
  166. spawnGroupOfMinion((L2MonsterInstance)npc, _regionsData[i].minion_lists[Rnd.get(_regionsData[i].minion_lists.length)]);
  167. }
  168. return super.onSpawn(npc);
  169. }
  170. @Override
  171. public String onAdvEvent (String event, L2Npc npc, L2PcInstance player)
  172. {
  173. if (event.equalsIgnoreCase("ChangeSeedsStatus"))
  174. {
  175. int buffsNow = Rnd.get(ZONE_BUFFS_LIST.length);
  176. saveGlobalQuestVar("SeedBuffsList", String.valueOf(buffsNow));
  177. _seedsNextStatusChange = getNextSeedsStatusChangeTime();
  178. saveGlobalQuestVar("SeedNextStatusChange", String.valueOf(_seedsNextStatusChange));
  179. for(int i = 0; i < _regionsData.length; i++)
  180. {
  181. _regionsData[i].activeBuff = ZONE_BUFFS_LIST[buffsNow][i];
  182. for(L2Npc af : _regionsData[i].af_npcs)
  183. af.setDisplayEffect(_regionsData[i].activeBuff);
  184. L2EffectZone zone = ZoneManager.getInstance().getZoneById(_regionsData[i].buff_zone, L2EffectZone.class);
  185. zone.clearSkills();
  186. zone.addSkill(ZONE_BUFFS[_regionsData[i].activeBuff], 1);
  187. }
  188. startQuestTimer("ChangeSeedsStatus", _seedsNextStatusChange - System.currentTimeMillis(), null, null);
  189. }
  190. else if (event.equalsIgnoreCase("transform"))
  191. {
  192. if (player.getFirstEffect(6408) != null)
  193. npc.showChatWindow(player, 2);
  194. else
  195. {
  196. npc.setTarget(player);
  197. npc.doCast(SkillTable.getInstance().getInfo(6408, 1));
  198. npc.doCast(SkillTable.getInstance().getInfo(6649, 1));
  199. npc.showChatWindow(player, 1);
  200. }
  201. }
  202. return null;
  203. }
  204. @Override
  205. public String onKill (L2Npc npc, L2PcInstance killer, boolean isPet)
  206. {
  207. return super.onKill(npc,killer,isPet);
  208. }
  209. @Override
  210. public String onEnterZone(L2Character character, L2ZoneType zone)
  211. {
  212. if (_teleportZones.containsKey(zone.getId()))
  213. {
  214. int[] teleLoc = _teleportZones.get(zone.getId());
  215. character.teleToLocation(teleLoc[0],teleLoc[1],teleLoc[2]);
  216. }
  217. return super.onEnterZone(character, zone);
  218. }
  219. public static void main(String[] args)
  220. {
  221. new SeedOfAnnihilation(-1,qn,"ai");
  222. }
  223. }