Advertisement
Guest User

Untitled

a guest
Sep 29th, 2011
670
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.05 KB | None | 0 0
  1. package l2.brick.gameserver.model.actor.instance;
  2.  
  3. import java.util.List;
  4.  
  5. import javolution.text.TextBuilder;
  6. import javolution.util.FastList;
  7. import javolution.util.FastSet;
  8.  
  9. import l2.brick.gameserver.ThreadPoolManager;
  10. import l2.brick.gameserver.cache.HtmCache;
  11. import l2.brick.gameserver.datatables.NpcTable;
  12. import l2.brick.gameserver.model.L2Party;
  13. import l2.brick.gameserver.model.L2Spawn;
  14. import l2.brick.gameserver.model.actor.L2Npc;
  15. import l2.brick.gameserver.network.serverpackets.ExShowScreenMessage;
  16. import l2.brick.gameserver.network.serverpackets.NpcHtmlMessage;
  17. import l2.brick.gameserver.templates.chars.L2NpcTemplate;
  18. import l2.brick.gameserver.util.Util;
  19. import l2.brick.util.Rnd;
  20.  
  21. /**
  22. * @author Matim
  23. * @version 1.0
  24. */
  25. public class L2ElvenRuinsTeleporterInstance extends L2Npc
  26. {
  27. private boolean _mayEnter = true;
  28. private long _enterTime;
  29.  
  30. private int[][] spawnList =
  31. {
  32. {47382, 248864, -6361}, {47648, 248820, -6361},
  33. {46485, 247892, -6361}, {46087, 247876, -6361},
  34. {47524, 247185, -6617}, {47476, 246771, -6617},
  35. {47808, 246603, -6617}, {47957, 247063, -6617},
  36. {45407, 249046, -6361}, {45130, 249287, -6361},
  37. {45722, 249420, -6361}, {45142, 249163, -6361},
  38. {45044, 248507, -6411}, {43664, 248686, -6491},
  39. {42855, 247334, -6462}, {43018, 245186, -6462},
  40. {42693, 247676, -6462}, {41634, 246449, -6462},
  41. {43200, 245624, -6462}, {44058, 246578, -6512},
  42. {45603, 245721, -6612}, {45533, 246816, -6612},
  43. {47003, 246591, -6662}, {48000, 246045, -6662},
  44. {47039, 245266, -6662}, {44657, 245547, -6415},
  45. {44737, 247436, -6436}, {42648, 245383, -6462},
  46. {41644, 246296, -6462}, {42780, 247283, -6462},
  47. {44177, 245545, -6462}, {43717, 244419, -6498},
  48. {45244, 243127, -6463}, {45754, 244325, -6517},
  49. {47086, 243145, -6563}, {47999, 244305, -6563},
  50. };
  51.  
  52. private int[] monsterId =
  53. {
  54. 20099, 20022, 20020, 20017, 20015, 20039,
  55. 20001, 20008, 20012, 20031, 20034, 20037,
  56. };
  57.  
  58. private List<L2PcInstance> _raiders = new FastList<L2PcInstance>();
  59. private FastSet<L2Npc> _monsters = new FastSet<L2Npc>();
  60.  
  61. public L2ElvenRuinsTeleporterInstance(int objectId, L2NpcTemplate template)
  62. {
  63. super(objectId, template);
  64. }
  65.  
  66. @Override
  67. public void onBypassFeedback(L2PcInstance player, String command)
  68. {
  69. if (player == null || player.getLastFolkNPC() == null || player.getLastFolkNPC().getObjectId() != this.getObjectId())
  70. {
  71. return;
  72. }
  73.  
  74. if (command.startsWith("enterInside"))
  75. {
  76. teleportInside(player);
  77. }
  78. else if (command.startsWith("giranTele"))
  79. {
  80. player.teleToLocation(83551, 147945, -3400);
  81. }
  82. else if (command.startsWith("mainWindow"))
  83. {
  84. showChatWindow(player);
  85. }
  86. else if (command.startsWith("tutorial"))
  87. {
  88. showHtml(player, "guide.htm");
  89. }
  90. }
  91.  
  92. /**
  93. * Check if party may enter.
  94. * @param player
  95. * @return
  96. */
  97. private boolean checkConditions(L2PcInstance player)
  98. {
  99. L2Party party = player.getParty();
  100.  
  101. if (party == null)
  102. {
  103. player.sendPacket(new ExShowScreenMessage("You need party with at least 5 members to enter!", 5000));
  104. return false;
  105. }
  106. if (party.getLeader() != player)
  107. {
  108. player.sendPacket(new ExShowScreenMessage("You are not party leader!", 5000));
  109. return false;
  110. }
  111. if (party.getMemberCount() < 2) //TODO change to 5
  112. {
  113. player.sendPacket(new ExShowScreenMessage("You need party with at least 5 members to enter!", 5000));
  114. return false;
  115. }
  116. for (L2PcInstance partyMember : party.getPartyMembers())
  117. {
  118. if (partyMember.getLevel() < 82)
  119. {
  120. ExShowScreenMessage msg = new ExShowScreenMessage("Each party member should be level 82 at least!", 5000);
  121. party.broadcastToPartyMembers(msg);
  122. return false;
  123. }
  124. if (!Util.checkIfInRange(500, player, partyMember, true))
  125. {
  126. ExShowScreenMessage msg = new ExShowScreenMessage("Each party member should be close to the leader!", 5000);
  127. party.broadcastToPartyMembers(msg);
  128. return false;
  129. }
  130. }
  131. return true;
  132. }
  133.  
  134. @Override
  135. public void showChatWindow(L2PcInstance player)
  136. {
  137. TextBuilder tb = new TextBuilder();
  138. tb.append("<html><title>Elven Ruins Manager:</title><body><center><br>");
  139. tb.append("Glad to see you <font color=\"LEVEL\">" + player.getName() + "</font>!<br>");
  140.  
  141. if (mayEnter())
  142. {
  143. tb.append("This Location is: <font color=\"LEVEL\">Empty</font>!<br>");
  144. tb.append("Feel free to enter with your party!<br>");
  145. tb.append("<button value=\"Enter with Party\" action=\"bypass -h npc_%objectId%_enterInside\" width=160 height=32 back=\"L2UI_CT1.Button_DF_Down\" fore=\"L2UI_ct1.button_df\">");
  146. }
  147. else
  148. {
  149. tb.append("This Location is: <font color=\"LEVEL\">Not Empty</font>!<br>");
  150. tb.append("You will have to wait!<br>");
  151. tb.append("About: <font color=\"LEVEL\">" + getTimeLeft() + " minutes left!<br>");
  152. }
  153. tb.append("<button value=\"How does it work\" action=\"bypass -h npc_%objectId%_tutorial\" width=160 height=32 back=\"L2UI_CT1.Button_DF_Down\" fore=\"L2UI_ct1.button_df\">");
  154. tb.append("<button value=\"Giran Teleport\" action=\"bypass -h npc_%objectId%_giranTele\" width=160 height=32 back=\"L2UI_CT1.Button_DF_Down\" fore=\"L2UI_ct1.button_df\">");
  155. tb.append("<br><br><br>By Matim");
  156.  
  157. NpcHtmlMessage msg = new NpcHtmlMessage(this.getObjectId());
  158. msg.setHtml(tb.toString());
  159. msg.replace("%objectId%", String.valueOf(this.getObjectId()));
  160.  
  161. player.sendPacket(msg);
  162. }
  163.  
  164. /**
  165. * @param player
  166. * @param htm
  167. */
  168. public void showHtml(L2PcInstance player, String htm)
  169. {
  170. String html = null;
  171. html = HtmCache.getInstance().getHtm(null, "data/html/ephion/RuinsMod/" + htm);
  172.  
  173. NpcHtmlMessage msg = new NpcHtmlMessage(getObjectId());
  174. msg.setHtml(html);
  175. msg.replace("%objectId%", String.valueOf(getObjectId()));
  176. player.sendPacket(msg);
  177. }
  178.  
  179. /**
  180. * Player need party with at least 5 party members.
  181. * If they meets the requirements, they may enter.
  182. * For next 10 min, there won't be any possibility to enter there again
  183. * for example by another parties.
  184. * @param player
  185. */
  186. private void teleportInside(L2PcInstance player)
  187. {
  188. if (checkConditions(player))
  189. {
  190. L2Party party = player.getParty();
  191.  
  192. for (L2PcInstance member: party.getPartyMembers())
  193. {
  194. member.teleToLocation(49315, 248452, -5960);
  195. _raiders.add(member);
  196. setEnterTime(System.currentTimeMillis());
  197. spawnMonsters();
  198. setMayEnter(false);
  199. ThreadPoolManager.getInstance().scheduleGeneral(new ScheduleEnterTask(), 300000); //TODO 600000
  200. }
  201. }
  202. }
  203.  
  204. /**
  205. * Clear Elven ruins, kick each player inside Ruins
  206. * and send them info about that its time to leave :)
  207. */
  208. private void clearRuins()
  209. {
  210. if (!_raiders.isEmpty())
  211. {
  212. for (L2PcInstance raider: _raiders)
  213. {
  214. raider.teleToLocation(-112367, 234703, -3688); //TODO is this correct?
  215. raider.sendMessage("Time is over, you will have to leave now!");
  216. }
  217.  
  218. _raiders.clear();
  219. _monsters.clear();
  220. }
  221. }
  222.  
  223. private void spawnMonsters()
  224. {
  225. L2Npc monster = null;
  226.  
  227. for (int[] spawn: spawnList)
  228. {
  229. monster = addSpawn(monsterId[Rnd.get(monsterId.length)], spawn[0], spawn[1], spawn[2]);
  230. _monsters.add(monster);
  231. }
  232. }
  233.  
  234. private static L2Npc addSpawn(int npcId, int x, int y, int z)
  235. {
  236. L2Npc result = null;
  237. try
  238. {
  239. L2NpcTemplate template = NpcTable.getInstance().getTemplate(npcId);
  240. if (template != null)
  241. {
  242. L2Spawn spawn = new L2Spawn(template);
  243. spawn.setInstanceId(0);
  244. spawn.setHeading(1);
  245. spawn.setLocx(x);
  246. spawn.setLocy(y);
  247. spawn.setLocz(z);
  248. spawn.stopRespawn();
  249. result = spawn.spawnOne(true);
  250.  
  251. return result;
  252. }
  253. }
  254. catch (Exception e1)
  255. {
  256.  
  257. }
  258. return null;
  259. }
  260.  
  261. private class ScheduleEnterTask implements Runnable
  262. {
  263. public ScheduleEnterTask()
  264. {
  265. // Nothing
  266. }
  267.  
  268. @Override
  269. public void run()
  270. {
  271. clearRuins();
  272. setMayEnter(true);
  273. }
  274. }
  275.  
  276. public int getTimeLeft()
  277. {
  278. long ms = System.currentTimeMillis() - _enterTime;
  279. long seconds = ms / 1000;
  280. int minutes = (int) (seconds / 60);
  281.  
  282. return minutes;
  283. }
  284.  
  285. public boolean mayEnter()
  286. {
  287. return _mayEnter;
  288. }
  289.  
  290. public void setMayEnter(boolean b)
  291. {
  292. _mayEnter = b;
  293. }
  294.  
  295. public void setEnterTime(long l)
  296. {
  297. _enterTime = l;
  298. }
  299. }
  300.  
  301.  
  302. <html><body><title>Elven Ruins Manager<title>
  303. <br>
  304. <font color="LEVEL">General Information:</font>
  305. <br>
  306. L2Ephion Elven Ruins, you need good party to enter this location. There may be only one party inside at the same time. You can stay there only for ten minutes, after this time your party will be teleported back. Check party requirements!
  307. <br>
  308. <font color="LEVEL">Party Requirements:</font>
  309. <br>
  310. <center>
  311. <table width=270 border=0 bgcolor="444444">
  312. <tr>
  313. <td>1) Only Party Leader may use teleport button</td>
  314. </tr>
  315. </table>
  316. <br>
  317. <table width=270 border=0 bgcolor="444444">
  318. <tr>
  319. <td>2) You need party with 5 members at least</td>
  320. </tr>
  321. </table>
  322. <br>
  323. <table width=270 border=0 bgcolor="444444">
  324. <tr>
  325. <td>3) Each member should be level 82 or above</td>
  326. </tr>
  327. <br>
  328. </table>
  329. <br><br></center>
  330. <font color="LEVEL">Other Information:</font>
  331. <br>
  332. Inside runins, there will be 50 Strong Monsters, each monster has interesting drop, but only one randomly chosen has treasure, find and kill him, and remember your party have only 10 minutes, until your party will be teleported back! There are no limits to the amount of daily enters of the same party, but each time there will be another randomly selected Monster with Treasure! Have fun, and good luck. You need it, trust me!
  333. <br>
  334. <font color="LEVEL">Important Warning:</font>
  335. <br>
  336. There may appear old grandpa, from time to time he may give you few advices about where exactly you can find Monster with treasure. Unfortunately, in most cases his advice will be wrong and misleading. Forgive him, he is really old, but even now he may be helpful for your party. Its your choice, will you trust him?
  337. <center>
  338. <button value="Main Window" action="bypass -h npc_%objectId%_mainWindow" width=160 height=32 back="L2UI_CT1.Button_DF_Down" fore="L2UI_ct1.button_df">
  339.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement