IceFairySirra.java 12 KB

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