2
0

AdminEventEngine.java 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779
  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 net.sf.l2j.gameserver.handler.admincommandhandlers;
  16. import java.io.BufferedInputStream;
  17. import java.io.BufferedReader;
  18. import java.io.DataInputStream;
  19. import java.io.File;
  20. import java.io.FileInputStream;
  21. import java.io.FileOutputStream;
  22. import java.io.InputStreamReader;
  23. import java.io.PrintStream;
  24. import java.util.Collection;
  25. import java.util.Iterator;
  26. import java.util.LinkedList;
  27. import java.util.StringTokenizer;
  28. import javolution.text.TextBuilder;
  29. import net.sf.l2j.gameserver.datatables.SpawnTable;
  30. import net.sf.l2j.gameserver.handler.IAdminCommandHandler;
  31. import net.sf.l2j.gameserver.model.L2Spawn;
  32. import net.sf.l2j.gameserver.model.L2World;
  33. import net.sf.l2j.gameserver.model.actor.instance.L2NpcInstance;
  34. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  35. import net.sf.l2j.gameserver.model.entity.L2Event;
  36. import net.sf.l2j.gameserver.network.serverpackets.CharInfo;
  37. import net.sf.l2j.gameserver.network.serverpackets.ItemList;
  38. import net.sf.l2j.gameserver.network.serverpackets.NpcHtmlMessage;
  39. import net.sf.l2j.gameserver.network.serverpackets.PlaySound;
  40. import net.sf.l2j.gameserver.network.serverpackets.UserInfo;
  41. /**
  42. * This class handles following admin commands:
  43. * - admin = shows menu
  44. *
  45. * @version $Revision: 1.3.2.1.2.4 $ $Date: 2005/04/11 10:06:06 $
  46. */
  47. public class AdminEventEngine implements IAdminCommandHandler
  48. {
  49. private static final String[] ADMIN_COMMANDS =
  50. {
  51. "admin_event",
  52. "admin_event_new",
  53. "admin_event_choose",
  54. "admin_event_store",
  55. "admin_event_set",
  56. "admin_event_change_teams_number",
  57. "admin_event_announce",
  58. "admin_event_panel",
  59. "admin_event_control_begin",
  60. "admin_event_control_teleport",
  61. "admin_add", "admin_event_see",
  62. "admin_event_del",
  63. "admin_delete_buffer",
  64. "admin_event_control_sit",
  65. "admin_event_name",
  66. "admin_event_control_kill",
  67. "admin_event_control_res",
  68. "admin_event_control_poly",
  69. "admin_event_control_unpoly",
  70. "admin_event_control_prize",
  71. "admin_event_control_chatban",
  72. "admin_event_control_finish"
  73. };
  74. private static String tempBuffer = "";
  75. private static String tempName = "";
  76. private static String tempName2 = "";
  77. private static boolean npcsDeleted = false;
  78. public boolean useAdminCommand(String command, L2PcInstance activeChar)
  79. {
  80. if (command.equals("admin_event"))
  81. showMainPage(activeChar);
  82. else if (command.equals("admin_event_new"))
  83. {
  84. showNewEventPage(activeChar);
  85. }
  86. else if (command.startsWith("admin_add"))
  87. {
  88. tempBuffer += command.substring(10);
  89. showNewEventPage(activeChar);
  90. }
  91. else if (command.startsWith("admin_event_see"))
  92. {
  93. String eventName = command.substring(16);
  94. try
  95. {
  96. NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  97. DataInputStream in = new DataInputStream(new BufferedInputStream(new FileInputStream("data/events/" + eventName)));
  98. BufferedReader inbr = new BufferedReader(new InputStreamReader(in));
  99. TextBuilder replyMSG = new TextBuilder("<html><body>");
  100. replyMSG.append("<center><font color=\"LEVEL\">" + eventName + "</font><font color=\"FF0000\"> bY " + inbr.readLine() + "</font></center><br>");
  101. replyMSG.append("<br>" + inbr.readLine());
  102. replyMSG.append("</body></html>");
  103. adminReply.setHtml(replyMSG.toString());
  104. activeChar.sendPacket(adminReply);
  105. }
  106. catch (Exception e)
  107. {
  108. e.printStackTrace();
  109. }
  110. }
  111. else if (command.startsWith("admin_event_del"))
  112. {
  113. String eventName = command.substring(16);
  114. File file = new File("data/events/" + eventName);
  115. file.delete();
  116. showMainPage(activeChar);
  117. }
  118. else if (command.startsWith("admin_event_name"))
  119. {
  120. tempName += command.substring(17);
  121. showNewEventPage(activeChar);
  122. }
  123. else if (command.equalsIgnoreCase("admin_delete_buffer"))
  124. {
  125. try
  126. {
  127. tempBuffer += tempBuffer.substring(0, tempBuffer.length() - 10);
  128. showNewEventPage(activeChar);
  129. }
  130. catch (Exception e)
  131. {
  132. tempBuffer = "";
  133. }
  134. }
  135. else if (command.startsWith("admin_event_store"))
  136. {
  137. try
  138. {
  139. FileOutputStream file = new FileOutputStream("data/events/" + tempName);
  140. PrintStream p = new PrintStream(file);
  141. p.println(activeChar.getName());
  142. p.println(tempBuffer);
  143. file.close();
  144. }
  145. catch (Exception e)
  146. {
  147. e.printStackTrace();
  148. }
  149. tempBuffer = "";
  150. tempName = "";
  151. showMainPage(activeChar);
  152. }
  153. else if (command.startsWith("admin_event_set"))
  154. {
  155. L2Event.eventName = command.substring(16);
  156. showEventParameters(activeChar, 2);
  157. }
  158. else if (command.startsWith("admin_event_change_teams_number"))
  159. {
  160. showEventParameters(activeChar, Integer.parseInt(command.substring(32)));
  161. }
  162. else if (command.startsWith("admin_event_panel"))
  163. {
  164. showEventControl(activeChar);
  165. }
  166. else if (command.startsWith("admin_event_control_begin"))
  167. {
  168. try
  169. {
  170. L2Event.active = true;
  171. L2Event.players.clear();
  172. L2Event.connectionLossData.clear();
  173. for (int j = 0; j < L2Event.teamsNumber; j++)
  174. {
  175. LinkedList<String> link = new LinkedList<String>();
  176. L2Event.players.put(j + 1, link);
  177. }
  178. int i = 0;
  179. while (L2Event.participatingPlayers.size() > 0)
  180. {
  181. String target = getMaxLeveledPlayer();
  182. if (!target.equals(""))
  183. {
  184. L2Event.players.get(i + 1).add(target);
  185. i = (i + 1) % L2Event.teamsNumber;
  186. }
  187. }
  188. destroyEventNpcs();
  189. npcsDeleted = true;
  190. }
  191. catch (Exception e)
  192. {
  193. e.printStackTrace();
  194. }
  195. showEventControl(activeChar);
  196. }
  197. else if (command.startsWith("admin_event_control_teleport"))
  198. {
  199. StringTokenizer st = new StringTokenizer(command.substring(29), "-");
  200. while (st.hasMoreElements())
  201. {
  202. teleportTeam(activeChar, Integer.parseInt(st.nextToken()));
  203. }
  204. showEventControl(activeChar);
  205. }
  206. else if (command.startsWith("admin_event_control_sit"))
  207. {
  208. StringTokenizer st = new StringTokenizer(command.substring(24), "-");
  209. while (st.hasMoreElements())
  210. {
  211. sitTeam(Integer.parseInt(st.nextToken()));
  212. }
  213. showEventControl(activeChar);
  214. }
  215. else if (command.startsWith("admin_event_control_kill"))
  216. {
  217. StringTokenizer st = new StringTokenizer(command.substring(25), "-");
  218. while (st.hasMoreElements())
  219. {
  220. killTeam(activeChar, Integer.parseInt(st.nextToken()));
  221. }
  222. showEventControl(activeChar);
  223. }
  224. else if (command.startsWith("admin_event_control_res"))
  225. {
  226. StringTokenizer st = new StringTokenizer(command.substring(24), "-");
  227. while (st.hasMoreElements())
  228. {
  229. resTeam(Integer.parseInt(st.nextToken()));
  230. }
  231. showEventControl(activeChar);
  232. }
  233. else if (command.startsWith("admin_event_control_poly"))
  234. {
  235. StringTokenizer st0 = new StringTokenizer(command.substring(25));
  236. StringTokenizer st = new StringTokenizer(st0.nextToken(), "-");
  237. String id = st0.nextToken();
  238. while (st.hasMoreElements())
  239. {
  240. polyTeam(Integer.parseInt(st.nextToken()), id);
  241. }
  242. showEventControl(activeChar);
  243. }
  244. else if (command.startsWith("admin_event_control_unpoly"))
  245. {
  246. StringTokenizer st = new StringTokenizer(command.substring(27), "-");
  247. while (st.hasMoreElements())
  248. {
  249. unpolyTeam(Integer.parseInt(st.nextToken()));
  250. }
  251. showEventControl(activeChar);
  252. }
  253. else if (command.startsWith("admin_event_control_prize"))
  254. {
  255. StringTokenizer st0 = new StringTokenizer(command.substring(26));
  256. StringTokenizer st = new StringTokenizer(st0.nextToken(), "-");
  257. String n = st0.nextToken();
  258. StringTokenizer st1 = new StringTokenizer(n, "*");
  259. n = st1.nextToken();
  260. String type = "";
  261. if (st1.hasMoreElements())
  262. type = st1.nextToken();
  263. String id = st0.nextToken();
  264. while (st.hasMoreElements())
  265. {
  266. regardTeam(activeChar, Integer.parseInt(st.nextToken()), Integer.parseInt(n), Integer.parseInt(id), type);
  267. }
  268. showEventControl(activeChar);
  269. }
  270. else if (command.startsWith("admin_event_control_finish"))
  271. {
  272. for (int i = 0; i < L2Event.teamsNumber; i++)
  273. {
  274. telePlayersBack(i + 1);
  275. }
  276. L2Event.eventName = "";
  277. L2Event.teamsNumber = 0;
  278. L2Event.names.clear();
  279. L2Event.participatingPlayers.clear();
  280. L2Event.players.clear();
  281. L2Event.id = 12760;
  282. L2Event.npcs.clear();
  283. L2Event.active = false;
  284. npcsDeleted = false;
  285. }
  286. else if (command.startsWith("admin_event_announce"))
  287. {
  288. StringTokenizer st = new StringTokenizer(command.substring(21));
  289. L2Event.id = Integer.parseInt(st.nextToken());
  290. L2Event.teamsNumber = Integer.parseInt(st.nextToken());
  291. String temp = " ";
  292. String temp2 = "";
  293. while (st.hasMoreElements())
  294. {
  295. temp += st.nextToken() + " ";
  296. }
  297. st = new StringTokenizer(temp, "-");
  298. Integer i = 1;
  299. while (st.hasMoreElements())
  300. {
  301. temp2 = st.nextToken();
  302. if (!temp2.equals(" "))
  303. {
  304. L2Event.names.put(i, temp2.substring(1, temp2.length() - 1));
  305. i++;
  306. }
  307. }
  308. L2Event.participatingPlayers.clear();
  309. muestraNpcConInfoAPlayers(activeChar, L2Event.id);
  310. PlaySound _snd = new PlaySound(1, "B03_F", 0, 0, 0, 0, 0);
  311. activeChar.sendPacket(_snd);
  312. activeChar.broadcastPacket(_snd);
  313. NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  314. TextBuilder replyMSG = new TextBuilder("<html><body>");
  315. replyMSG.append("<center><font color=\"LEVEL\">[ L2J EVENT ENGINE</font></center><br>");
  316. replyMSG.append("<center>The event <font color=\"LEVEL\">" + L2Event.eventName + "</font> has been announced, now you can type //event_panel to see the event panel control</center><br>");
  317. replyMSG.append("</body></html>");
  318. adminReply.setHtml(replyMSG.toString());
  319. activeChar.sendPacket(adminReply);
  320. }
  321. return true;
  322. }
  323. public String[] getAdminCommandList()
  324. {
  325. return ADMIN_COMMANDS;
  326. }
  327. String showStoredEvents()
  328. {
  329. File dir = new File("data/events");
  330. String[] files = dir.list();
  331. String result = "";
  332. if (files == null)
  333. {
  334. result = "No 'data/events' directory!";
  335. return result;
  336. }
  337. for (int i = 0; i < files.length; i++)
  338. {
  339. File file = new File("data/events/" + files[i]);
  340. result += "<font color=\"LEVEL\">" + file.getName() + " </font><br><button value=\"select\" action=\"bypass -h admin_event_set " + file.getName()
  341. + "\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"><button value=\"ver\" action=\"bypass -h admin_event_see " + file.getName()
  342. + "\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"><button value=\"delete\" action=\"bypass -h admin_event_del " + file.getName()
  343. + "\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"><br><br>";
  344. }
  345. return result;
  346. }
  347. public void showMainPage(L2PcInstance activeChar)
  348. {
  349. NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  350. TextBuilder replyMSG = new TextBuilder("<html><body>");
  351. replyMSG.append("<center><font color=\"LEVEL\">[ L2J EVENT ENGINE ]</font></center><br>");
  352. replyMSG.append("<br><center><button value=\"Create NEW event \" action=\"bypass -h admin_event_new\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">");
  353. replyMSG.append("<center><br>Stored Events<br></center>");
  354. replyMSG.append(showStoredEvents());
  355. replyMSG.append("</body></html>");
  356. adminReply.setHtml(replyMSG.toString());
  357. activeChar.sendPacket(adminReply);
  358. }
  359. public void showNewEventPage(L2PcInstance activeChar)
  360. {
  361. NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  362. TextBuilder replyMSG = new TextBuilder("<html><body>");
  363. replyMSG.append("<center><font color=\"LEVEL\">[ L2J EVENT ENGINE ]</font></center><br>");
  364. replyMSG.append("<br><center>Event's Title <br><font color=\"LEVEL\">");
  365. if (tempName.equals(""))
  366. replyMSG.append("Use //event_name text to insert a new title");
  367. else
  368. replyMSG.append(tempName);
  369. replyMSG.append("</font></center><br><br>Event's description<br>");
  370. if (tempBuffer.equals(""))
  371. replyMSG.append("Use //add text o //delete_buffer to modify this text field");
  372. else
  373. replyMSG.append(tempBuffer);
  374. if (!(tempName.equals("") && tempBuffer.equals("")))
  375. replyMSG.append("<br><button value=\"Crear\" action=\"bypass -h admin_event_store\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">");
  376. replyMSG.append("</body></html>");
  377. adminReply.setHtml(replyMSG.toString());
  378. activeChar.sendPacket(adminReply);
  379. }
  380. public void showEventParameters(L2PcInstance activeChar, int teamnumbers)
  381. {
  382. NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  383. TextBuilder replyMSG = new TextBuilder("<html><body>");
  384. replyMSG.append("<center><font color=\"LEVEL\">[ L2J EVENT ENGINE ]</font></center><br>");
  385. replyMSG.append("<center><font color=\"LEVEL\">" + L2Event.eventName + "</font></center><br>");
  386. replyMSG.append("<br><center><button value=\"Change number of teams to\" action=\"bypass -h admin_event_change_teams_number $event_teams_number\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"> <edit var=\"event_teams_number\" width=100 height=20><br><br>");
  387. replyMSG.append("<font color=\"LEVEL\">Team's Names</font><br>");
  388. for (int i = 0; i < teamnumbers; i++)
  389. {
  390. replyMSG.append((i + 1) + ".- <edit var=\"event_teams_name" + (i + 1) + "\" width=100 height=20><br>");
  391. }
  392. replyMSG.append("<br><br>Announcer NPC id<edit var=\"event_npcid\" width=100 height=20><br><br><button value=\"Announce Event!!\" action=\"bypass -h admin_event_announce $event_npcid " + teamnumbers + " ");
  393. for (int i = 0; i < teamnumbers; i++)
  394. {
  395. replyMSG.append("$event_teams_name" + (i + 1) + " - ");
  396. }
  397. replyMSG.append("\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">");
  398. replyMSG.append("</body></html>");
  399. adminReply.setHtml(replyMSG.toString());
  400. activeChar.sendPacket(adminReply);
  401. }
  402. void muestraNpcConInfoAPlayers(L2PcInstance activeChar, int id)
  403. {
  404. L2Event.npcs.clear();
  405. LinkedList<L2PcInstance> temp = new LinkedList<L2PcInstance>();
  406. temp.clear();
  407. Collection<L2PcInstance> pls = L2World.getInstance().getAllPlayers().values();
  408. //synchronized (L2World.getInstance().getAllPlayers())
  409. {
  410. for (L2PcInstance player : pls)
  411. {
  412. if (!temp.contains(player))
  413. {
  414. L2Event.spawn(player, id);
  415. temp.add(player);
  416. }
  417. Collection<L2PcInstance> plrs = player.getKnownList().getKnownPlayers().values();
  418. //synchronized (player.getKnownList().getKnownPlayers())
  419. {
  420. for (L2PcInstance playertemp : plrs)
  421. {
  422. if ((Math.abs(playertemp.getX() - player.getX()) < 500) && (Math.abs(playertemp.getY() - player.getY()) < 500) && (Math.abs(playertemp.getZ() - player.getZ()) < 500))
  423. temp.add(playertemp);
  424. }
  425. }
  426. }
  427. }
  428. L2Event.announceAllPlayers(activeChar.getName() + " wants to make an event !!! (you'll find a npc with the details around)");
  429. }
  430. void showEventControl(L2PcInstance activeChar)
  431. {
  432. NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  433. TextBuilder replyMSG = new TextBuilder("<html><body>");
  434. replyMSG.append("<center><font color=\"LEVEL\">[ L2J EVENT ENGINE ]</font></center><br><font color=\"LEVEL\">" + L2Event.eventName + "</font><br><br><table width=200>");
  435. replyMSG.append("<tr><td>Apply this command to teams number </td><td><edit var=\"team_number\" width=100 height=15></td></tr>");
  436. replyMSG.append("<tr><td>&nbsp;</td></tr>");
  437. if (!npcsDeleted)
  438. replyMSG.append("<tr><td><button value=\"Start\" action=\"bypass -h admin_event_control_begin\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td><td><font color=\"LEVEL\">Destroys all event npcs so no more people can't participate now on</font></td></tr>");
  439. replyMSG.append("<tr><td>&nbsp;</td></tr>");
  440. replyMSG.append("<tr><td><button value=\"Teleport\" action=\"bypass -h admin_event_control_teleport $team_number\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td><td><font color=\"LEVEL\">Teleports the specified team to your position</font></td></tr>");
  441. replyMSG.append("<tr><td>&nbsp;</td></tr>");
  442. replyMSG.append("<tr><td><button value=\"Sit\" action=\"bypass -h admin_event_control_sit $team_number\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td><td><font color=\"LEVEL\">Sits/Stands up the team</font></td></tr>");
  443. replyMSG.append("<tr><td>&nbsp;</td></tr>");
  444. replyMSG.append("<tr><td><button value=\"Kill\" action=\"bypass -h admin_event_control_kill $team_number\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td><td><font color=\"LEVEL\">Finish with the life of all the players in the selected team</font></td></tr>");
  445. replyMSG.append("<tr><td>&nbsp;</td></tr>");
  446. replyMSG.append("<tr><td><button value=\"Resurrect\" action=\"bypass -h admin_event_control_res $team_number\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td><td><font color=\"LEVEL\">Resurrect Team's members</font></td></tr>");
  447. replyMSG.append("<tr><td>&nbsp;</td></tr>");
  448. replyMSG.append("<tr><td><button value=\"Polymorph\" action=\"bypass -h admin_event_control_poly $team_number $poly_id\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td><td><edit var=\"poly_id\" width=100 height=15><font color=\"LEVEL\">Polymorphs the team into the NPC with the id specified</font></td></tr>");
  449. replyMSG.append("<tr><td>&nbsp;</td></tr>");
  450. replyMSG.append("<tr><td><button value=\"UnPolymorph\" action=\"bypass -h admin_event_control_unpoly $team_number\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td><td><font color=\"LEVEL\">Unpolymorph the team</font></td></tr>");
  451. replyMSG.append("<tr><td>&nbsp;</td></tr>");
  452. replyMSG.append("<tr><td>&nbsp;</td></tr>");
  453. replyMSG.append("<tr><td><button value=\"Give Item\" action=\"bypass -h admin_event_control_prize $team_number $n $id\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"> number <edit var=\"n\" width=100 height=15> item id <edit var=\"id\" width=100 height=15></td><td><font color=\"LEVEL\">Give the specified item id to every single member of the team, you can put 5*level, 5*kills or 5 in the number field for example</font></td></tr>");
  454. replyMSG.append("<tr><td>&nbsp;</td></tr>");
  455. replyMSG.append("<tr><td><button value=\"End\" action=\"bypass -h admin_event_control_finish\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td><td><font color=\"LEVEL\">Will finish the event teleporting back all the players</font></td></tr>");
  456. replyMSG.append("</table></body></html>");
  457. adminReply.setHtml(replyMSG.toString());
  458. activeChar.sendPacket(adminReply);
  459. }
  460. String getMaxLeveledPlayer()
  461. {
  462. Iterator<String> it = L2Event.participatingPlayers.iterator();
  463. L2PcInstance pc = null;
  464. int max = 0;
  465. String name = "";
  466. while (it.hasNext())
  467. {
  468. try
  469. {
  470. tempName2 = it.next();
  471. pc = L2World.getInstance().getPlayer(tempName2);
  472. if (max < pc.getLevel())
  473. {
  474. max = pc.getLevel();
  475. name = pc.getName();
  476. }
  477. }
  478. catch (Exception e)
  479. {
  480. try
  481. {
  482. L2Event.participatingPlayers.remove(tempName2);
  483. }
  484. catch (Exception e2)
  485. {
  486. }
  487. }
  488. }
  489. L2Event.participatingPlayers.remove(name);
  490. return name;
  491. }
  492. void destroyEventNpcs()
  493. {
  494. L2NpcInstance npc;
  495. while (L2Event.npcs.size() > 0)
  496. {
  497. try
  498. {
  499. npc = (L2NpcInstance) L2World.getInstance().findObject(Integer.parseInt(L2Event.npcs.getFirst()));
  500. L2Spawn spawn = npc.getSpawn();
  501. if (spawn != null)
  502. {
  503. spawn.stopRespawn();
  504. SpawnTable.getInstance().deleteSpawn(spawn, true);
  505. }
  506. npc.deleteMe();
  507. L2Event.npcs.removeFirst();
  508. }
  509. catch (Exception e)
  510. {
  511. L2Event.npcs.removeFirst();
  512. }
  513. }
  514. }
  515. void teleportTeam(L2PcInstance activeChar, int team)
  516. {
  517. LinkedList<String> linked = L2Event.players.get(team);
  518. Iterator<String> it = linked.iterator();
  519. while (it.hasNext())
  520. {
  521. try
  522. {
  523. L2PcInstance pc = L2World.getInstance().getPlayer(it.next());
  524. pc.setTitle(L2Event.names.get(team));
  525. pc.teleToLocation(activeChar.getX(), activeChar.getY(), activeChar.getZ(), true);
  526. }
  527. catch (Exception e)
  528. {
  529. }
  530. }
  531. }
  532. void sitTeam(int team)
  533. {
  534. LinkedList<String> linked = L2Event.players.get(team);
  535. Iterator<String> it = linked.iterator();
  536. while (it.hasNext())
  537. {
  538. try
  539. {
  540. L2PcInstance pc = L2World.getInstance().getPlayer(it.next());
  541. pc.eventSitForced = !pc.eventSitForced;
  542. if (pc.eventSitForced)
  543. pc.sitDown();
  544. else
  545. pc.standUp();
  546. }
  547. catch (Exception e)
  548. {
  549. }
  550. }
  551. }
  552. void killTeam(L2PcInstance activeChar, int team)
  553. {
  554. LinkedList<String> linked = L2Event.players.get(team);
  555. Iterator<String> it = linked.iterator();
  556. while (it.hasNext())
  557. {
  558. try
  559. {
  560. L2PcInstance target = L2World.getInstance().getPlayer(it.next());
  561. target.reduceCurrentHp(target.getMaxHp() + target.getMaxCp() + 1, activeChar);
  562. }
  563. catch (Exception e)
  564. {
  565. }
  566. }
  567. }
  568. void resTeam(int team)
  569. {
  570. LinkedList<String> linked = L2Event.players.get(team);
  571. Iterator<String> it = linked.iterator();
  572. while (it.hasNext())
  573. {
  574. L2PcInstance character = L2World.getInstance().getPlayer(it.next());
  575. if (character == null || !character.isDead())
  576. continue;
  577. character.restoreExp(100.0);
  578. character.doRevive();
  579. character.setCurrentHpMp(character.getMaxHp(), character.getMaxMp());
  580. character.setCurrentCp(character.getMaxCp());
  581. }
  582. }
  583. void polyTeam(int team, String id)
  584. {
  585. LinkedList<String> linked = L2Event.players.get(team);
  586. Iterator<String> it = linked.iterator();
  587. while (it.hasNext())
  588. {
  589. try
  590. {
  591. L2PcInstance target = L2World.getInstance().getPlayer(it.next());
  592. target.getPoly().setPolyInfo("npc", id);
  593. target.teleToLocation(target.getX(), target.getY(), target.getZ(), true);
  594. CharInfo info1 = new CharInfo(target);
  595. target.broadcastPacket(info1);
  596. UserInfo info2 = new UserInfo(target);
  597. target.sendPacket(info2);
  598. }
  599. catch (Exception e)
  600. {
  601. }
  602. }
  603. }
  604. void unpolyTeam(int team)
  605. {
  606. LinkedList<String> linked = L2Event.players.get(team);
  607. Iterator<String> it = linked.iterator();
  608. while (it.hasNext())
  609. {
  610. try
  611. {
  612. L2PcInstance target = L2World.getInstance().getPlayer(it.next());
  613. target.getPoly().setPolyInfo(null, "1");
  614. target.decayMe();
  615. target.spawnMe(target.getX(), target.getY(), target.getZ());
  616. CharInfo info1 = new CharInfo(target);
  617. target.broadcastPacket(info1);
  618. UserInfo info2 = new UserInfo(target);
  619. target.sendPacket(info2);
  620. }
  621. catch (Exception e)
  622. {
  623. }
  624. }
  625. }
  626. private void createItem(L2PcInstance activeChar, L2PcInstance player, int id, int num)
  627. {
  628. player.getInventory().addItem("Event", id, num, player, activeChar);
  629. ItemList il = new ItemList(player, true);
  630. player.sendPacket(il);
  631. NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  632. TextBuilder replyMSG = new TextBuilder("<html><body>");
  633. replyMSG.append("CONGRATULATIONS, you should have a present in your inventory");
  634. replyMSG.append("</body></html>");
  635. adminReply.setHtml(replyMSG.toString());
  636. player.sendPacket(adminReply);
  637. }
  638. void regardTeam(L2PcInstance activeChar, int team, int n, int id, String type)
  639. {
  640. LinkedList<String> linked = L2Event.players.get(team);
  641. int temp = n;
  642. Iterator<String> it = linked.iterator();
  643. while (it.hasNext())
  644. {
  645. try
  646. {
  647. L2PcInstance target = L2World.getInstance().getPlayer(it.next());
  648. if (type.equalsIgnoreCase("level"))
  649. temp = n * target.getLevel();
  650. else if (type.equalsIgnoreCase("kills"))
  651. temp = n * target.kills.size();
  652. else
  653. temp = n;
  654. createItem(activeChar, target, id, temp);
  655. }
  656. catch (Exception e)
  657. {
  658. }
  659. }
  660. }
  661. void telePlayersBack(int team)
  662. {
  663. resTeam(team);
  664. unpolyTeam(team);
  665. LinkedList<String> linked = L2Event.players.get(team);
  666. Iterator<String> it = linked.iterator();
  667. while (it.hasNext())
  668. {
  669. try
  670. {
  671. L2PcInstance target = L2World.getInstance().getPlayer(it.next());
  672. target.setTitle(target.eventTitle);
  673. target.setKarma(target.eventkarma);
  674. target.setPvpKills(target.eventpvpkills);
  675. target.setPkKills(target.eventpkkills);
  676. target.teleToLocation(target.eventX, target.eventY, target.eventZ, true);
  677. target.kills.clear();
  678. target.eventSitForced = false;
  679. target.atEvent = false;
  680. }
  681. catch (Exception e)
  682. {
  683. }
  684. }
  685. }
  686. }