IceFairySirra.java 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  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.individual;
  16. import java.util.concurrent.Future;
  17. import java.util.logging.Level;
  18. import javolution.util.FastList;
  19. import ai.group_template.L2AttackableAIScript;
  20. import com.l2jserver.Config;
  21. import com.l2jserver.gameserver.cache.HtmCache;
  22. import com.l2jserver.gameserver.datatables.DoorTable;
  23. import com.l2jserver.gameserver.datatables.NpcTable;
  24. import com.l2jserver.gameserver.datatables.SpawnTable;
  25. import com.l2jserver.gameserver.instancemanager.GrandBossManager;
  26. import com.l2jserver.gameserver.model.L2Spawn;
  27. import com.l2jserver.gameserver.model.actor.L2Npc;
  28. import com.l2jserver.gameserver.model.actor.instance.L2DoorInstance;
  29. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  30. import com.l2jserver.gameserver.model.item.instance.L2ItemInstance;
  31. import com.l2jserver.gameserver.model.zone.type.L2BossZone;
  32. import com.l2jserver.gameserver.network.NpcStringId;
  33. import com.l2jserver.gameserver.network.serverpackets.ActionFailed;
  34. import com.l2jserver.gameserver.network.serverpackets.ExShowScreenMessage;
  35. import com.l2jserver.gameserver.network.serverpackets.NpcHtmlMessage;
  36. import com.l2jserver.gameserver.templates.chars.L2NpcTemplate;
  37. import com.l2jserver.util.Rnd;
  38. /**
  39. * Ice Fairy Sirra AI
  40. * @author Kerberos
  41. */
  42. public class IceFairySirra extends L2AttackableAIScript
  43. {
  44. private static final int STEWARD = 32029;
  45. private static final int SILVER_HEMOCYTE = 8057;
  46. private static L2BossZone _sirrasZone;
  47. private static L2PcInstance _player = null;
  48. protected FastList<L2Npc> _allMobs = new FastList<L2Npc>();
  49. protected Future<?> _onDeadEventTask = null;
  50. public IceFairySirra(int id,String name,String descr)
  51. {
  52. super(id,name,descr);
  53. int[] mob = {22100, 22102, 22104, 29056};
  54. registerMobs(mob);
  55. registerMobs(new int[] { STEWARD } , QuestEventType.QUEST_START, QuestEventType.ON_TALK, QuestEventType.ON_FIRST_TALK);
  56. String test = loadGlobalQuestVar("Sirra_Respawn");
  57. if (!test.equalsIgnoreCase(""))
  58. {
  59. long remain = Long.parseLong(test) - System.currentTimeMillis();
  60. if (remain <= 0)
  61. init(false);
  62. else
  63. {
  64. init(true);
  65. startQuestTimer("respawn", remain, null, null);
  66. }
  67. }
  68. else
  69. init(false);
  70. }
  71. public void init(boolean isBusy)
  72. {
  73. _sirrasZone = GrandBossManager.getInstance().getZone(105546 , -127892 , -2768);
  74. if (_sirrasZone == null)
  75. {
  76. _log.warning("IceFairySirraManager: Failed to load zone");
  77. return;
  78. }
  79. _sirrasZone.setZoneEnabled(false);
  80. L2Npc steward = findTemplate(STEWARD);
  81. if (steward != null)
  82. steward.setBusy(isBusy);
  83. openGates();
  84. }
  85. public void cleanUp()
  86. {
  87. init(false);
  88. cancelQuestTimer("30MinutesRemaining",null, _player);
  89. cancelQuestTimer("20MinutesRemaining",null, _player);
  90. cancelQuestTimer("10MinutesRemaining",null, _player);
  91. cancelQuestTimer("End",null, _player);
  92. for (L2Npc mob : _allMobs)
  93. {
  94. try
  95. {
  96. mob.getSpawn().stopRespawn();
  97. mob.deleteMe();
  98. }
  99. catch (Exception e)
  100. {
  101. _log.log(Level.SEVERE, "IceFairySirraManager: Failed deleting mob.", e);
  102. }
  103. }
  104. _allMobs.clear();
  105. }
  106. public L2Npc findTemplate(int npcId)
  107. {
  108. L2Npc npc = null;
  109. for (L2Spawn spawn : SpawnTable.getInstance().getSpawnTable())
  110. {
  111. if (spawn != null && spawn.getNpcid() == npcId)
  112. {
  113. npc = spawn.getLastSpawn();
  114. break;
  115. }
  116. }
  117. return npc;
  118. }
  119. protected void openGates()
  120. {
  121. for (int i = 23140001; i < 23140003; i++ )
  122. {
  123. try
  124. {
  125. L2DoorInstance door = DoorTable.getInstance().getDoor(i);
  126. if (door != null)
  127. {
  128. door.openMe();
  129. }
  130. else
  131. {
  132. _log.warning("IceFairySirraManager: Attempted to open undefined door. doorId: "+i);
  133. }
  134. }
  135. catch (Exception e)
  136. {
  137. _log.log(Level.SEVERE, "IceFairySirraManager: Failed closing door", e);
  138. }
  139. }
  140. }
  141. protected void closeGates()
  142. {
  143. for (int i = 23140001; i < 23140003; i++ )
  144. {
  145. try
  146. {
  147. L2DoorInstance door = DoorTable.getInstance().getDoor(i);
  148. if (door != null)
  149. {
  150. door.closeMe();
  151. }
  152. else
  153. {
  154. _log.warning("IceFairySirraManager: Attempted to close undefined door. doorId: "+i);
  155. }
  156. }
  157. catch (Exception e)
  158. {
  159. _log.log(Level.SEVERE, "IceFairySirraManager: Failed closing door", e);
  160. }
  161. }
  162. }
  163. public boolean checkItems (L2PcInstance player)
  164. {
  165. if (player.getParty() != null)
  166. {
  167. for (L2PcInstance pc : player.getParty().getPartyMembers())
  168. {
  169. L2ItemInstance i = pc.getInventory().getItemByItemId(SILVER_HEMOCYTE);
  170. if (i == null || i.getCount() < 10)
  171. return false;
  172. }
  173. }
  174. else
  175. return false;
  176. return true;
  177. }
  178. public void destroyItems (L2PcInstance player)
  179. {
  180. if (player.getParty() != null)
  181. {
  182. for (L2PcInstance pc : player.getParty().getPartyMembers())
  183. {
  184. L2ItemInstance i = pc.getInventory().getItemByItemId(SILVER_HEMOCYTE);
  185. pc.destroyItem("Hemocytes", i.getObjectId(), 10, null, false);
  186. }
  187. }
  188. else
  189. cleanUp();
  190. }
  191. public void teleportInside (L2PcInstance player)
  192. {
  193. if (player.getParty() != null)
  194. {
  195. for (L2PcInstance pc : player.getParty().getPartyMembers())
  196. {
  197. pc.teleToLocation(113533,-126159,-3488,false);
  198. if (_sirrasZone == null)
  199. {
  200. _log.warning("IceFairySirraManager: Failed to load zone");
  201. cleanUp();
  202. return;
  203. }
  204. _sirrasZone.allowPlayerEntry(pc,2103);
  205. }
  206. }
  207. else
  208. cleanUp();
  209. }
  210. public void screenMessage(L2PcInstance player, NpcStringId npcString, int time)
  211. {
  212. if (player.getParty() != null)
  213. {
  214. for (L2PcInstance pc : player.getParty().getPartyMembers())
  215. {
  216. pc.sendPacket(new ExShowScreenMessage(npcString, 2, time));
  217. }
  218. }
  219. else
  220. cleanUp();
  221. }
  222. public void doSpawns()
  223. {
  224. int[][] mobs = { {29060 , 105546 , -127892 , -2768} ,
  225. {29056 , 102779 , -125920 , -2840},
  226. {22100 , 111719 , -126646 , -2992},
  227. {22102 , 109509 , -128946 , -3216},
  228. {22104 , 109680 , -125756 , -3136}};
  229. L2Spawn spawnDat;
  230. L2NpcTemplate template;
  231. try
  232. {
  233. for (int i = 0; i <5; i++)
  234. {
  235. template = NpcTable.getInstance().getTemplate(mobs[i][0]);
  236. if (template != null)
  237. {
  238. spawnDat = new L2Spawn(template);
  239. spawnDat.setAmount(1);
  240. spawnDat.setLocx(mobs[i][1]);
  241. spawnDat.setLocy(mobs[i][2]);
  242. spawnDat.setLocz(mobs[i][3]);
  243. spawnDat.setHeading(0);
  244. spawnDat.setRespawnDelay(60);
  245. SpawnTable.getInstance().addNewSpawn(spawnDat, false);
  246. _allMobs.add(spawnDat.doSpawn());
  247. spawnDat.stopRespawn();
  248. }
  249. else
  250. {
  251. _log.warning("IceFairySirraManager: Data missing in NPC table for ID: "+mobs[i][0]);
  252. }
  253. }
  254. }
  255. catch (Exception e)
  256. {
  257. _log.warning("IceFairySirraManager: Spawns could not be initialized: "+ e);
  258. }
  259. }
  260. public String getHtmlPath(int val)
  261. {
  262. String pom = "";
  263. pom = "32029-" + val;
  264. if (val == 0)
  265. pom = "32029";
  266. String temp = "data/html/default/" + pom + ".htm";
  267. if (!Config.LAZY_CACHE)
  268. {
  269. // If not running lazy cache the file must be in the cache or it doesnt exist
  270. if (HtmCache.getInstance().contains(temp))
  271. return temp;
  272. }
  273. else if (HtmCache.getInstance().isLoadable(temp))
  274. return temp;
  275. // If the file is not found, the standard message "I have nothing to say to you" is returned
  276. return "data/html/npcdefault.htm";
  277. }
  278. public void sendHtml(L2Npc npc, L2PcInstance player, String filename)
  279. {
  280. NpcHtmlMessage html = new NpcHtmlMessage(npc.getObjectId());
  281. html.setFile(player.getHtmlPrefix(), filename);
  282. html.replace("%objectId%", String.valueOf(npc.getObjectId()));
  283. player.sendPacket(html);
  284. player.sendPacket( ActionFailed.STATIC_PACKET );
  285. }
  286. @Override
  287. public String onFirstTalk (L2Npc npc, L2PcInstance player)
  288. {
  289. if (player.getQuestState("IceFairySirra") == null)
  290. newQuestState(player);
  291. player.setLastQuestNpcObject(npc.getObjectId());
  292. String filename = "";
  293. if (npc.isBusy())
  294. filename = getHtmlPath(10);
  295. else
  296. filename = getHtmlPath(0);
  297. sendHtml(npc, player, filename);
  298. return null;
  299. }
  300. @Override
  301. public String onAdvEvent (String event, L2Npc npc, L2PcInstance player)
  302. {
  303. if (event.equalsIgnoreCase("check_condition"))
  304. {
  305. if (npc.isBusy())//should never happen
  306. return super.onAdvEvent(event, npc, player);
  307. else
  308. {
  309. String filename = "";
  310. if (player.isInParty() && player.getParty().getPartyLeaderOID() == player.getObjectId())
  311. {
  312. if (checkItems(player) == true)
  313. {
  314. startQuestTimer("start",100000,null,player);
  315. _player = player;
  316. destroyItems(player);
  317. player.getInventory().addItem("Scroll",8379,3,player,null);
  318. npc.setBusy(true);
  319. screenMessage(player,NpcStringId.STEWARD_PLEASE_WAIT_A_MOMENT,100000);
  320. filename = getHtmlPath(3);
  321. }
  322. else
  323. {
  324. filename = getHtmlPath(2);
  325. }
  326. }
  327. else
  328. {
  329. filename = getHtmlPath(1);
  330. }
  331. sendHtml(npc, player, filename);
  332. }
  333. }
  334. else if (event.equalsIgnoreCase("start"))
  335. {
  336. if (_sirrasZone == null)
  337. {
  338. _log.warning("IceFairySirraManager: Failed to load zone");
  339. cleanUp();
  340. return super.onAdvEvent(event, npc, player);
  341. }
  342. _sirrasZone.setZoneEnabled(true);
  343. closeGates();
  344. doSpawns();
  345. startQuestTimer("Party_Port",2000,null,player);
  346. startQuestTimer("End",1802000,null,player);
  347. }
  348. else if (event.equalsIgnoreCase("Party_Port"))
  349. {
  350. teleportInside(player);
  351. screenMessage(player,NpcStringId.STEWARD_PLEASE_RESTORE_THE_QUEENS_FORMER_APPEARANCE,10000);
  352. startQuestTimer("30MinutesRemaining",300000,null,player);
  353. }
  354. else if (event.equalsIgnoreCase("30MinutesRemaining"))
  355. {
  356. screenMessage(player,NpcStringId.N30_MINUTES_REMAIN,10000);
  357. startQuestTimer("20minutesremaining",600000,null,player);
  358. }
  359. else if (event.equalsIgnoreCase("20MinutesRemaining"))
  360. {
  361. screenMessage(player,NpcStringId.N20_MINUTES_REMAIN,10000);
  362. startQuestTimer("10minutesremaining",600000,null,player);
  363. }
  364. else if (event.equalsIgnoreCase("10MinutesRemaining"))
  365. {
  366. screenMessage(player,NpcStringId.STEWARD_WASTE_NO_TIME_PLEASE_HURRY,10000);
  367. }
  368. else if (event.equalsIgnoreCase("End"))
  369. {
  370. screenMessage(player,NpcStringId.STEWARD_WAS_IT_INDEED_TOO_MUCH_TO_ASK,10000);
  371. cleanUp();
  372. }
  373. else if (event.equalsIgnoreCase("respawn"))
  374. {
  375. cleanUp();
  376. }
  377. return super.onAdvEvent(event, npc, player);
  378. }
  379. @Override
  380. public String onKill (L2Npc npc, L2PcInstance killer, boolean isPet)
  381. {
  382. if (npc.getNpcId() == 29056)
  383. {
  384. cancelQuestTimer("30MinutesRemaining",null, _player);
  385. cancelQuestTimer("20MinutesRemaining",null, _player);
  386. cancelQuestTimer("10MinutesRemaining",null, _player);
  387. cancelQuestTimer("End",null, _player);
  388. for (L2Npc mob : _allMobs)
  389. {
  390. try
  391. {
  392. mob.getSpawn().stopRespawn();
  393. mob.deleteMe();
  394. }
  395. catch (Exception e)
  396. {
  397. _log.log(Level.SEVERE, "IceFairySirraManager: Failed deleting mob.", e);
  398. }
  399. }
  400. _allMobs.clear();
  401. init(true);
  402. int respawnMinDelay = 43200000 * (int)(Config.RAID_MIN_RESPAWN_MULTIPLIER);
  403. int respawnMaxDelay = 129600000 * (int)(Config.RAID_MAX_RESPAWN_MULTIPLIER);
  404. int respawn_delay = Rnd.get(respawnMinDelay,respawnMaxDelay);
  405. saveGlobalQuestVar("Sirra_Respawn", String.valueOf(System.currentTimeMillis()+respawn_delay));
  406. startQuestTimer("respawn", respawn_delay, null, null);
  407. screenMessage(killer,NpcStringId.STEWARD_PLEASE_RESTORE_THE_QUEENS_FORMER_APPEARANCE,10000);
  408. }
  409. return super.onKill(npc,killer,isPet);
  410. }
  411. public static void main(String[] args)
  412. {
  413. new IceFairySirra(-1,"IceFairySirra","ai");
  414. }
  415. }