SeedOfAnnihilation.java 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  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 gracia.AI.SeedOfAnnihilation;
  20. import java.util.Calendar;
  21. import java.util.HashMap;
  22. import java.util.Map;
  23. import ai.npc.AbstractNpcAI;
  24. import com.l2jserver.gameserver.datatables.SkillData;
  25. import com.l2jserver.gameserver.instancemanager.ZoneManager;
  26. import com.l2jserver.gameserver.model.Location;
  27. import com.l2jserver.gameserver.model.actor.L2Character;
  28. import com.l2jserver.gameserver.model.actor.L2Npc;
  29. import com.l2jserver.gameserver.model.actor.instance.L2MonsterInstance;
  30. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  31. import com.l2jserver.gameserver.model.zone.L2ZoneType;
  32. import com.l2jserver.gameserver.model.zone.type.L2EffectZone;
  33. import com.l2jserver.gameserver.util.Util;
  34. /**
  35. * Seed Of Annihilation AI.
  36. * @author Gigiikun
  37. */
  38. public class SeedOfAnnihilation extends AbstractNpcAI
  39. {
  40. private static final Map<Integer, Location> TELEPORT_ZONES = new HashMap<>();
  41. private static final int ANNIHILATION_FURNACE = 18928;
  42. // Strength, Agility, Wisdom
  43. private static final int[] ZONE_BUFFS =
  44. {
  45. 0,
  46. 6443,
  47. 6444,
  48. 6442
  49. };
  50. //@formatter:off
  51. private static final int[][] ZONE_BUFFS_LIST =
  52. {
  53. {1, 2, 3},
  54. {1, 3, 2},
  55. {2, 1, 3},
  56. {2, 3, 1},
  57. {3, 2, 1},
  58. {3, 1, 2}
  59. };
  60. //@formatter:on
  61. // 0: Bistakon, 1: Reptilikon, 2: Cokrakon
  62. private final SeedRegion[] _regionsData = new SeedRegion[3];
  63. private Long _seedsNextStatusChange;
  64. static
  65. {
  66. TELEPORT_ZONES.put(60002, new Location(-213175, 182648, -10992));
  67. TELEPORT_ZONES.put(60003, new Location(-181217, 186711, -10528));
  68. TELEPORT_ZONES.put(60004, new Location(-180211, 182984, -15152));
  69. TELEPORT_ZONES.put(60005, new Location(-179275, 186802, -10720));
  70. }
  71. public SeedOfAnnihilation()
  72. {
  73. super(SeedOfAnnihilation.class.getSimpleName(), "gracia/AI");
  74. loadSeedRegionData();
  75. for (int i : TELEPORT_ZONES.keySet())
  76. {
  77. addEnterZoneId(i);
  78. }
  79. for (SeedRegion element : _regionsData)
  80. {
  81. for (int elite_mob_id : element.elite_mob_ids)
  82. {
  83. addSpawnId(elite_mob_id);
  84. }
  85. }
  86. addStartNpc(32739);
  87. addTalkId(32739);
  88. startEffectZonesControl();
  89. }
  90. public void loadSeedRegionData()
  91. {
  92. // Bistakon data
  93. _regionsData[0] = new SeedRegion(new int[]
  94. {
  95. 22750,
  96. 22751,
  97. 22752,
  98. 22753
  99. }, new int[][]
  100. {
  101. {
  102. 22746,
  103. 22746,
  104. 22746
  105. },
  106. {
  107. 22747,
  108. 22747,
  109. 22747
  110. },
  111. {
  112. 22748,
  113. 22748,
  114. 22748
  115. },
  116. {
  117. 22749,
  118. 22749,
  119. 22749
  120. }
  121. }, 60006, new int[][]
  122. {
  123. {
  124. -180450,
  125. 185507,
  126. -10544,
  127. 11632
  128. },
  129. {
  130. -180005,
  131. 185489,
  132. -10544,
  133. 11632
  134. }
  135. });
  136. // Reptilikon data
  137. _regionsData[1] = new SeedRegion(new int[]
  138. {
  139. 22757,
  140. 22758,
  141. 22759
  142. }, new int[][]
  143. {
  144. {
  145. 22754,
  146. 22755,
  147. 22756
  148. }
  149. }, 60007, new int[][]
  150. {
  151. {
  152. -179600,
  153. 186998,
  154. -10704,
  155. 11632
  156. },
  157. {
  158. -179295,
  159. 186444,
  160. -10704,
  161. 11632
  162. }
  163. });
  164. // Cokrakon data
  165. _regionsData[2] = new SeedRegion(new int[]
  166. {
  167. 22763,
  168. 22764,
  169. 22765
  170. }, new int[][]
  171. {
  172. {
  173. 22760,
  174. 22760,
  175. 22761
  176. },
  177. {
  178. 22760,
  179. 22760,
  180. 22762
  181. },
  182. {
  183. 22761,
  184. 22761,
  185. 22760
  186. },
  187. {
  188. 22761,
  189. 22761,
  190. 22762
  191. },
  192. {
  193. 22762,
  194. 22762,
  195. 22760
  196. },
  197. {
  198. 22762,
  199. 22762,
  200. 22761
  201. }
  202. }, 60008, new int[][]
  203. {
  204. {
  205. -180971,
  206. 186361,
  207. -10528,
  208. 11632
  209. },
  210. {
  211. -180758,
  212. 186739,
  213. -10528,
  214. 11632
  215. }
  216. });
  217. int buffsNow = 0;
  218. String var = loadGlobalQuestVar("SeedNextStatusChange");
  219. if (var.equalsIgnoreCase("") || (Long.parseLong(var) < System.currentTimeMillis()))
  220. {
  221. buffsNow = getRandom(ZONE_BUFFS_LIST.length);
  222. saveGlobalQuestVar("SeedBuffsList", String.valueOf(buffsNow));
  223. _seedsNextStatusChange = getNextSeedsStatusChangeTime();
  224. saveGlobalQuestVar("SeedNextStatusChange", String.valueOf(_seedsNextStatusChange));
  225. }
  226. else
  227. {
  228. _seedsNextStatusChange = Long.parseLong(var);
  229. buffsNow = Integer.parseInt(loadGlobalQuestVar("SeedBuffsList"));
  230. }
  231. for (int i = 0; i < _regionsData.length; i++)
  232. {
  233. _regionsData[i].activeBuff = ZONE_BUFFS_LIST[buffsNow][i];
  234. }
  235. }
  236. private Long getNextSeedsStatusChangeTime()
  237. {
  238. Calendar reenter = Calendar.getInstance();
  239. reenter.set(Calendar.SECOND, 0);
  240. reenter.set(Calendar.MINUTE, 0);
  241. reenter.set(Calendar.HOUR_OF_DAY, 13);
  242. reenter.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
  243. if (reenter.getTimeInMillis() <= System.currentTimeMillis())
  244. {
  245. reenter.add(Calendar.DAY_OF_MONTH, 7);
  246. }
  247. return reenter.getTimeInMillis();
  248. }
  249. private void startEffectZonesControl()
  250. {
  251. for (int i = 0; i < _regionsData.length; i++)
  252. {
  253. for (int j = 0; j < _regionsData[i].af_spawns.length; j++)
  254. {
  255. _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);
  256. _regionsData[i].af_npcs[j].setDisplayEffect(_regionsData[i].activeBuff);
  257. }
  258. ZoneManager.getInstance().getZoneById(_regionsData[i].buff_zone, L2EffectZone.class).addSkill(ZONE_BUFFS[_regionsData[i].activeBuff], 1);
  259. }
  260. startQuestTimer("ChangeSeedsStatus", _seedsNextStatusChange - System.currentTimeMillis(), null, null);
  261. }
  262. private void spawnGroupOfMinion(L2MonsterInstance npc, int[] mobIds)
  263. {
  264. for (int mobId : mobIds)
  265. {
  266. addMinion(npc, mobId);
  267. }
  268. }
  269. @Override
  270. public String onSpawn(L2Npc npc)
  271. {
  272. for (SeedRegion element : _regionsData)
  273. {
  274. if (Util.contains(element.elite_mob_ids, npc.getId()))
  275. {
  276. spawnGroupOfMinion((L2MonsterInstance) npc, element.minion_lists[getRandom(element.minion_lists.length)]);
  277. }
  278. }
  279. return super.onSpawn(npc);
  280. }
  281. @Override
  282. public String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
  283. {
  284. if (event.equalsIgnoreCase("ChangeSeedsStatus"))
  285. {
  286. int buffsNow = getRandom(ZONE_BUFFS_LIST.length);
  287. saveGlobalQuestVar("SeedBuffsList", String.valueOf(buffsNow));
  288. _seedsNextStatusChange = getNextSeedsStatusChangeTime();
  289. saveGlobalQuestVar("SeedNextStatusChange", String.valueOf(_seedsNextStatusChange));
  290. for (int i = 0; i < _regionsData.length; i++)
  291. {
  292. _regionsData[i].activeBuff = ZONE_BUFFS_LIST[buffsNow][i];
  293. for (L2Npc af : _regionsData[i].af_npcs)
  294. {
  295. af.setDisplayEffect(_regionsData[i].activeBuff);
  296. }
  297. L2EffectZone zone = ZoneManager.getInstance().getZoneById(_regionsData[i].buff_zone, L2EffectZone.class);
  298. zone.clearSkills();
  299. zone.addSkill(ZONE_BUFFS[_regionsData[i].activeBuff], 1);
  300. }
  301. startQuestTimer("ChangeSeedsStatus", _seedsNextStatusChange - System.currentTimeMillis(), null, null);
  302. }
  303. else if (event.equalsIgnoreCase("transform"))
  304. {
  305. if (player.isAffectedBySkill(6408))
  306. {
  307. npc.showChatWindow(player, 2);
  308. }
  309. else
  310. {
  311. npc.setTarget(player);
  312. npc.doCast(SkillData.getInstance().getSkill(6408, 1));
  313. npc.doCast(SkillData.getInstance().getSkill(6649, 1));
  314. npc.showChatWindow(player, 1);
  315. }
  316. }
  317. return null;
  318. }
  319. @Override
  320. public String onEnterZone(L2Character character, L2ZoneType zone)
  321. {
  322. if (TELEPORT_ZONES.containsKey(zone.getId()))
  323. {
  324. Location teleLoc = TELEPORT_ZONES.get(zone.getId());
  325. character.teleToLocation(teleLoc, false);
  326. }
  327. return super.onEnterZone(character, zone);
  328. }
  329. private static class SeedRegion
  330. {
  331. public int[] elite_mob_ids;
  332. public int[][] minion_lists;
  333. public int buff_zone;
  334. public int[][] af_spawns;
  335. public L2Npc[] af_npcs = new L2Npc[2];
  336. public int activeBuff = 0;
  337. public SeedRegion(int[] emi, int[][] ml, int bz, int[][] as)
  338. {
  339. elite_mob_ids = emi;
  340. minion_lists = ml;
  341. buff_zone = bz;
  342. af_spawns = as;
  343. }
  344. }
  345. }