Advertisement
Guest User

PlayerBuffer

a guest
Sep 13th, 2020
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 24.67 KB | None | 0 0
  1. package net.sf.l2j.gameserver.model.actor.instance;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.List;
  5. import java.util.Map;
  6. import java.util.StringTokenizer;
  7.  
  8. import net.sf.l2j.commons.lang.StringUtil;
  9. import net.sf.l2j.commons.random.Rnd;
  10.  
  11. import net.sf.l2j.Config;
  12. import net.sf.l2j.gameserver.data.BufferTable;
  13. import net.sf.l2j.gameserver.data.SkillTable;
  14. import net.sf.l2j.gameserver.model.L2Skill;
  15. import net.sf.l2j.gameserver.model.actor.Creature;
  16. import net.sf.l2j.gameserver.model.actor.Npc;
  17. import net.sf.l2j.gameserver.model.actor.Summon;
  18. import net.sf.l2j.gameserver.model.actor.ai.CtrlIntention;
  19. import net.sf.l2j.gameserver.model.actor.template.NpcTemplate;
  20. import net.sf.l2j.gameserver.network.serverpackets.ItemList;
  21. import net.sf.l2j.gameserver.network.serverpackets.MagicSkillUse;
  22. import net.sf.l2j.gameserver.network.serverpackets.MoveToPawn;
  23. import net.sf.l2j.gameserver.network.serverpackets.MyTargetSelected;
  24. import net.sf.l2j.gameserver.network.serverpackets.NpcHtmlMessage;
  25. import net.sf.l2j.gameserver.network.serverpackets.ValidateLocation;
  26.  
  27. /**
  28. * @author Baggos
  29. */
  30. public final class PlayerBuffer extends Npc
  31. {
  32. public PlayerBuffer(int objectId, NpcTemplate template)
  33. {
  34. super(objectId, template);
  35. }
  36.  
  37. @Override
  38. public void onAction(Player player)
  39. {
  40. if (this != player.getTarget())
  41. {
  42. player.setTarget(this);
  43. player.sendPacket(new MyTargetSelected(getObjectId(), 0));
  44. player.sendPacket(new ValidateLocation(this));
  45. }
  46. else
  47. {
  48. if (!canInteract(player))
  49. player.getAI().setIntention(CtrlIntention.INTERACT, this);
  50. else
  51. {
  52. // Rotate the player to face the instance
  53. player.sendPacket(new MoveToPawn(player, this, Npc.INTERACTION_DISTANCE));
  54.  
  55. if (hasRandomAnimation())
  56. onRandomAnimation(Rnd.get(8));
  57.  
  58. showMainBuffWindow(player);
  59.  
  60. // Send ActionFailed to the player in order to avoid he stucks player.sendPacket(ActionFailed.STATIC_PACKET);
  61. }
  62. }
  63. }
  64.  
  65.  
  66.  
  67. @Override
  68. public void onBypassFeedback(Player player, String command)
  69. {
  70. if (player.getPvpFlag() > 0 && Config.PRESTRICT_USE_BUFFER_ON_PVPFLAG)
  71. {
  72. player.sendMessage("You can't use buffer when you are pvp flagged.");
  73. return;
  74. }
  75.  
  76. if (player.isInCombat() && Config.PRESTRICT_USE_BUFFER_IN_COMBAT)
  77. {
  78. player.sendMessage("You can't use buffer when you are in combat.");
  79. return;
  80. }
  81.  
  82. if (player.isDead())
  83. return;
  84.  
  85. StringTokenizer st = new StringTokenizer(command, " ");
  86. String actualCommand = st.nextToken();
  87.  
  88. if (actualCommand.equalsIgnoreCase("bufflist"))
  89. {
  90. autoBuffFunction(player, st.nextToken());
  91. }
  92. else if (actualCommand.equalsIgnoreCase("restore"))
  93. {
  94. String noble = st.nextToken();
  95. player.setCurrentHpMp(player.getMaxHp(), player.getMaxMp());
  96. player.setCurrentCp(player.getMaxCp());
  97.  
  98. if (noble.equals("true"))
  99. {
  100. SkillTable.getInstance().getInfo(1323, 1).getEffects(player, player);
  101. player.broadcastPacket(new MagicSkillUse(this, player, 1323, 1, 850, 0));
  102. }
  103.  
  104. final Summon summon = player.getPet();
  105. if (summon != null)
  106. summon.setCurrentHpMp(summon.getMaxHp(), summon.getMaxMp());
  107.  
  108. showMainBuffWindow(player);
  109. }
  110. else if (actualCommand.equalsIgnoreCase("cancellation"))
  111. {
  112. L2Skill buff;
  113. buff = SkillTable.getInstance().getInfo(1056, 1);
  114. buff.getEffects(this, player);
  115. player.stopAllEffectsExceptThoseThatLastThroughDeath();
  116. player.broadcastPacket(new MagicSkillUse(this, player, 1056, 1, 850, 0));
  117. player.stopAllEffects();
  118.  
  119. final Summon summon = player.getPet();
  120. if (summon != null)
  121. summon.stopAllEffects();
  122.  
  123. showMainBuffWindow(player);
  124. }else if(actualCommand.startsWith("playerbuffp")) {
  125. showBuffPlayerWindow(player);
  126. }
  127. else if(actualCommand.startsWith("petbuffp")) {
  128. showBuffPetWindow(player);
  129. }else if(actualCommand.startsWith("bmainp")) {
  130. showMainBuffWindow(player);
  131. }
  132. else if (actualCommand.equalsIgnoreCase("openlist"))
  133. {
  134. String category = st.nextToken();
  135. String htmfile = st.nextToken();
  136.  
  137. NpcHtmlMessage html = new NpcHtmlMessage(getObjectId());
  138.  
  139. if (category.equalsIgnoreCase("null"))
  140. {
  141. html.setFile("data/html/mods/buffer/" + htmfile + ".htm");
  142.  
  143. // First Page
  144. if (htmfile.equals("index"))
  145. {
  146. html.replace("%name%", player.getName());
  147. html.replace("%buffcount%", "You have " + player.getBuffCount() + "/" + player.getMaxBuffCount() + " buffs.");
  148. }
  149. }
  150. else
  151. html.setFile("data/html/mods/buffer/" + category + "/" + htmfile + ".htm");
  152.  
  153. html.replace("%objectId%", String.valueOf(getObjectId()));
  154. player.sendPacket(html);
  155. }
  156.  
  157. else if (actualCommand.equalsIgnoreCase("dobuff"))
  158. {
  159. int buffid = Integer.valueOf(st.nextToken());
  160. int bufflevel = Integer.valueOf(st.nextToken());
  161. String category = st.nextToken();
  162. String windowhtml = st.nextToken();
  163. String votebuff = null;
  164.  
  165. if (st.hasMoreTokens())
  166. votebuff = st.nextToken();
  167.  
  168. if (windowhtml.equals("malaria"))
  169. {
  170. if (player.getInventory().getInventoryItemCount(Config.PVOTE_BUFF_ITEM_ID, 0) >= 1)
  171. {
  172. player.getInventory().destroyItemByItemId("Consume", Config.PVOTE_BUFF_ITEM_ID, 1, player, null);
  173. player.getInventory().updateDatabase();
  174. player.sendPacket(new ItemList(player, true));
  175. player.sendMessage(1 + " Vote buff item destroyed.");
  176. }
  177. else
  178. {
  179. player.sendMessage("You dont have enough (" + 1 + ") vote item for buff.");
  180. return;
  181. }
  182. }
  183.  
  184. if (votebuff != null)
  185. {
  186. if (player.getInventory().getInventoryItemCount(Config.PVOTE_BUFF_ITEM_ID, 0) >= Config.PVOTE_BUFF_ITEM_COUNT)
  187. {
  188. player.getInventory().destroyItemByItemId("Consume", Config.PVOTE_BUFF_ITEM_ID, Config.PVOTE_BUFF_ITEM_COUNT, player, null);
  189. player.getInventory().updateDatabase();
  190. player.sendPacket(new ItemList(player, true));
  191. player.sendMessage(Config.PVOTE_BUFF_ITEM_COUNT + " vote stone destroyed.");
  192. }
  193. else
  194. {
  195. player.sendMessage("You dont have enough (" + Config.PVOTE_BUFF_ITEM_COUNT + ") vote item for buff.");
  196. return;
  197. }
  198. }
  199.  
  200. Creature target = player;
  201. if (category.equalsIgnoreCase("pet"))
  202. {
  203. if (player.getPet() == null)
  204. {
  205. player.sendMessage("Incorrect Pet");
  206. showMainBuffWindow(player);
  207. return;
  208. }
  209. target = player.getPet();
  210. }
  211.  
  212. MagicSkillUse mgc = new MagicSkillUse(this, target, buffid, bufflevel, 1150, 0);
  213. player.sendPacket(mgc);
  214. player.broadcastPacket(mgc);
  215. SkillTable.getInstance().getInfo(buffid, bufflevel).getEffects(this, target);
  216.  
  217. NpcHtmlMessage html = new NpcHtmlMessage(getObjectId());
  218. html.setFile("data/html/mods/buffer/" + category + "/" + windowhtml + ".htm");
  219. html.replace("%objectId%", String.valueOf(getObjectId()));
  220. html.replace("%name%", player.getName());
  221. player.sendPacket(html);
  222. }
  223. else if (actualCommand.equalsIgnoreCase("getbuff"))
  224. {
  225. int buffid = Integer.valueOf(st.nextToken());
  226. int bufflevel = Integer.valueOf(st.nextToken());
  227. if (buffid != 0)
  228. {
  229. SkillTable.getInstance().getInfo(buffid, bufflevel).getEffects(this, player);
  230. broadcastPacket(new MagicSkillUse(this, player, buffid, bufflevel, 450, 0));
  231. showMainBuffWindow(player);
  232. }
  233. }
  234. else if (actualCommand.startsWith("support"))
  235. {
  236. showGiveBuffsWindow(player, st.nextToken());
  237. }
  238. else if (actualCommand.startsWith("givebuffs"))
  239. {
  240. final String schemeName = st.nextToken();
  241. final int cost = Integer.parseInt(st.nextToken());
  242.  
  243. Creature target = null;
  244. if (st.hasMoreTokens())
  245. {
  246. final String targetType = st.nextToken();
  247. if (targetType != null && targetType.equalsIgnoreCase("pet"))
  248. target = player.getPet();
  249. }
  250. else
  251. target = player;
  252.  
  253. if (target == null)
  254. player.sendMessage("You don't have a pet.");
  255. else if (cost == 0 || player.reduceAdena("NPC Buffer", cost, this, true))
  256. {
  257. for (int skillId : BufferTable.getInstance().getScheme(player.getObjectId(), schemeName))
  258. SkillTable.getInstance().getInfo(skillId, SkillTable.getInstance().getMaxLevel(skillId)).getEffects(this, target);
  259. }
  260. }
  261. else if (actualCommand.startsWith("editschemes"))
  262. {
  263. if (st.countTokens() == 2)
  264. showEditSchemeWindow(player, st.nextToken(), st.nextToken());
  265. else
  266. player.sendMessage("Something wrong with your scheme. Please contact with Admin");
  267. }
  268. else if (actualCommand.startsWith("skill"))
  269. {
  270. final String groupType = st.nextToken();
  271. final String schemeName = st.nextToken();
  272.  
  273. final int skillId = Integer.parseInt(st.nextToken());
  274.  
  275. final List<Integer> skills = BufferTable.getInstance().getScheme(player.getObjectId(), schemeName);
  276.  
  277. if (actualCommand.startsWith("skillselect") && !schemeName.equalsIgnoreCase("none"))
  278. {
  279. if (skills.size() < Config.PBUFFER_MAX_SKILLS)
  280. skills.add(skillId);
  281. else
  282. player.sendMessage("This scheme has reached the maximum amount of buffs.");
  283. }
  284. else if (actualCommand.startsWith("skillunselect"))
  285. skills.remove(Integer.valueOf(skillId));
  286.  
  287. showEditSchemeWindow(player, groupType, schemeName);
  288. }
  289. else if (actualCommand.startsWith("manageschemes"))
  290. {
  291. showManageSchemeWindow(player);
  292. }
  293. else if (actualCommand.startsWith("createscheme"))
  294. {
  295. try
  296. {
  297. final String schemeName = st.nextToken();
  298. if (schemeName.length() > 14)
  299. {
  300. player.sendMessage("Scheme's name must contain up to 14 chars. Spaces are trimmed.");
  301. showMainBuffWindow(player);
  302. return;
  303. }
  304.  
  305. final Map<String, ArrayList<Integer>> schemes = BufferTable.getInstance().getPlayerSchemes(player.getObjectId());
  306. if (schemes != null)
  307. {
  308. if (schemes.size() == Config.PBUFFER_MAX_SCHEMES)
  309. {
  310. player.sendMessage("Maximum schemes amount is already reached.");
  311. showMainBuffWindow(player);
  312. return;
  313. }
  314.  
  315. if (schemes.containsKey(schemeName))
  316. {
  317. player.sendMessage("The scheme name already exists.");
  318. showMainBuffWindow(player);
  319. return;
  320. }
  321. }
  322.  
  323. BufferTable.getInstance().setScheme(player.getObjectId(), schemeName.trim(), new ArrayList<Integer>());
  324. showMainBuffWindow(player);
  325. }
  326. catch (Exception e)
  327. {
  328. player.sendMessage("Scheme's name must contain up to 14 chars. Spaces are trimmed.");
  329. showMainBuffWindow(player);
  330. }
  331. }
  332. else if (actualCommand.startsWith("deletescheme"))
  333. {
  334. try
  335. {
  336. final String schemeName = st.nextToken();
  337. final Map<String, ArrayList<Integer>> schemes = BufferTable.getInstance().getPlayerSchemes(player.getObjectId());
  338.  
  339. if (schemes != null && schemes.containsKey(schemeName))
  340. schemes.remove(schemeName);
  341. }
  342. catch (Exception e)
  343. {
  344. player.sendMessage("This scheme name is invalid.");
  345. }
  346. showMainBuffWindow(player);
  347. }
  348. else if (actualCommand.startsWith("clearscheme"))
  349. {
  350. try
  351. {
  352. final String schemeName = st.nextToken();
  353. final Map<String, ArrayList<Integer>> schemes = BufferTable.getInstance().getPlayerSchemes(player.getObjectId());
  354.  
  355. if (schemes != null && schemes.containsKey(schemeName))
  356. schemes.get(schemeName).clear();
  357. }
  358. catch (Exception e)
  359. {
  360. player.sendMessage("This scheme name is invalid.");
  361. }
  362. showMainBuffWindow(player);
  363. }
  364. else
  365. super.onBypassFeedback(player, command);
  366. }
  367.  
  368. /**
  369. * Sends an html packet to player with Give Buffs menu info for player and pet, depending on targetType parameter {player, pet}
  370. * @param player : The player to make checks on.
  371. * @param targetType : a String used to define if the player or his pet must be used as target.
  372. */
  373. private void showGiveBuffsWindow(Player player, String targetType)
  374. {
  375. final StringBuilder sb = new StringBuilder(200);
  376.  
  377. final Map<String, ArrayList<Integer>> schemes = BufferTable.getInstance().getPlayerSchemes(player.getObjectId());
  378. if (schemes == null || schemes.isEmpty())
  379. sb.append("<font color=\"LEVEL\">You haven't defined any scheme, please go to 'Manage my schemes' and create at least one valid scheme.</font>");
  380. else
  381. {
  382. for (Map.Entry<String, ArrayList<Integer>> scheme : schemes.entrySet())
  383. {
  384. final int cost = getFee(scheme.getValue());
  385. StringUtil.append(sb, "<font color=\"LEVEL\"><a action=\"bypass -h npc_%objectId%_givebuffs ", targetType, " ", scheme.getKey(), " ", cost, "\">", scheme.getKey(), " (", scheme.getValue().size(), " skill(s))</a>", ((cost > 0) ? " - Adena cost: " + cost : ""), "</font><br1>");
  386. }
  387. }
  388.  
  389. final NpcHtmlMessage html = new NpcHtmlMessage(0);
  390. html.setFile("data/html/mods/buffer/schememanager/index-1.htm");
  391. html.replace("%schemes%", sb.toString());
  392. html.replace("%targettype%", (targetType.equalsIgnoreCase("pet") ? "&nbsp;<a action=\"bypass -h npc_%objectId%_support player\">yourself</a>&nbsp;|&nbsp;your pet" : "yourself&nbsp;|&nbsp;<a action=\"bypass -h npc_%objectId%_support pet\">your pet</a>"));
  393. html.replace("%objectId%", getObjectId());
  394. player.sendPacket(html);
  395. }
  396.  
  397. /**
  398. * Sends an html packet to player with Manage scheme menu info. This allows player to create/delete/clear schemes
  399. * @param player : The player to make checks on.
  400. */
  401. private void showManageSchemeWindow(Player player)
  402. {
  403. final StringBuilder sb = new StringBuilder(200);
  404.  
  405. final Map<String, ArrayList<Integer>> schemes = BufferTable.getInstance().getPlayerSchemes(player.getObjectId());
  406. if (schemes == null || schemes.isEmpty())
  407. sb.append("<font color=\"LEVEL\">You haven't created any scheme.</font>");
  408. else
  409. {
  410. sb.append("<table>");
  411. for (Map.Entry<String, ArrayList<Integer>> scheme : schemes.entrySet())
  412. StringUtil.append(sb, "<tr><td width=140>", scheme.getKey(), " (", scheme.getValue().size(), " skill(s))</td><td width=60><button value=\"Clear\" action=\"bypass -h npc_%objectId%_clearscheme ", scheme.getKey(), "\" width=55 height=15 back=\"sek.cbui94\" fore=\"sek.cbui92\"></td><td width=60><button value=\"Drop\" action=\"bypass -h npc_%objectId%_deletescheme ", scheme.getKey(), "\" width=55 height=15 back=\"sek.cbui94\" fore=\"sek.cbui92\"></td></tr>");
  413.  
  414. sb.append("</table>");
  415. }
  416.  
  417. final NpcHtmlMessage html = new NpcHtmlMessage(0);
  418. html.setFile("data/html/mods/buffer/schememanager/index-2.htm");
  419. html.replace("%schemes%", sb.toString());
  420. html.replace("%max_schemes%", Config.PBUFFER_MAX_SCHEMES);
  421. html.replace("%objectId%", getObjectId());
  422. player.sendPacket(html);
  423. }
  424.  
  425. /**
  426. * This sends an html packet to player with Edit Scheme Menu info. This allows player to edit each created scheme (add/delete skills)
  427. * @param player : The player to make checks on.
  428. * @param groupType : The group of skills to select.
  429. * @param schemeName : The scheme to make check.
  430. */
  431. private void showEditSchemeWindow(Player player, String groupType, String schemeName)
  432. {
  433. final NpcHtmlMessage html = new NpcHtmlMessage(0);
  434.  
  435. if (schemeName.equalsIgnoreCase("none"))
  436. html.setFile("data/html/mods/buffer/schememanager/index-3.htm");
  437. else
  438. {
  439. if (groupType.equalsIgnoreCase("none"))
  440. html.setFile("data/html/mods/buffer/schememanager/index-4.htm");
  441. else
  442. {
  443. html.setFile("data/html/mods/buffer/schememanager/index-5.htm");
  444. html.replace("%skilllistframe%", getGroupSkillList(player, groupType, schemeName));
  445. }
  446. html.replace("%schemename%", schemeName);
  447. html.replace("%myschemeframe%", getPlayerSchemeSkillList(player, groupType, schemeName));
  448. html.replace("%typesframe%", getTypesFrame(groupType, schemeName));
  449. }
  450. html.replace("%schemes%", getPlayerSchemes(player, schemeName));
  451. html.replace("%objectId%", getObjectId());
  452. player.sendPacket(html);
  453. }
  454.  
  455. /**
  456. * @param player : The player to make checks on.
  457. * @param schemeName : The name to don't link (previously clicked).
  458. * @return a String listing player's schemes. The scheme currently on selection isn't linkable.
  459. */
  460. private static String getPlayerSchemes(Player player, String schemeName)
  461. {
  462. final Map<String, ArrayList<Integer>> schemes = BufferTable.getInstance().getPlayerSchemes(player.getObjectId());
  463. if (schemes == null || schemes.isEmpty())
  464. return "Please create at least one scheme.";
  465.  
  466. final StringBuilder sb = new StringBuilder(200);
  467. sb.append("<table>");
  468.  
  469. for (Map.Entry<String, ArrayList<Integer>> scheme : schemes.entrySet())
  470. {
  471. if (schemeName.equalsIgnoreCase(scheme.getKey()))
  472. StringUtil.append(sb, "<tr><td width=200>", scheme.getKey(), " (<font color=\"LEVEL\">", scheme.getValue().size(), "</font> / ", Config.PBUFFER_MAX_SKILLS, " skill(s))</td></tr>");
  473. else
  474. StringUtil.append(sb, "<tr><td width=200><a action=\"bypass -h npc_%objectId%_editschemes none ", scheme.getKey(), "\">", scheme.getKey(), " (", scheme.getValue().size(), " / ", Config.PBUFFER_MAX_SKILLS, " skill(s))</a></td></tr>");
  475. }
  476.  
  477. sb.append("</table>");
  478.  
  479. return sb.toString();
  480. }
  481.  
  482. /**
  483. * @param player : The player to make checks on.
  484. * @param groupType : The group of skills to select.
  485. * @param schemeName : The scheme to make check.
  486. * @return a String representing skills available to selection for a given groupType.
  487. */
  488. private static String getGroupSkillList(Player player, String groupType, String schemeName)
  489. {
  490. final List<Integer> skills = new ArrayList<>();
  491. for (int skillId : BufferTable.getSkillsIdsByType(groupType))
  492. {
  493. if (BufferTable.getInstance().getSchemeContainsSkill(player.getObjectId(), schemeName, skillId))
  494. continue;
  495.  
  496. skills.add(skillId);
  497. }
  498.  
  499. if (skills.isEmpty())
  500. return "That group doesn't contain any skills.";
  501.  
  502. final StringBuilder sb = new StringBuilder(500);
  503.  
  504. sb.append("<table>");
  505. int count = 0;
  506. for (int skillId : skills)
  507. {
  508. if (BufferTable.getInstance().getSchemeContainsSkill(player.getObjectId(), schemeName, skillId))
  509. continue;
  510.  
  511. if (count == 0)
  512. sb.append("<tr>");
  513.  
  514. if (skillId < 100)
  515. sb.append("<td width=180><font color=\"949490\"><a action=\"bypass -h npc_%objectId%_skillselect " + groupType + " " + schemeName + " " + skillId + "\">" + SkillTable.getInstance().getInfo(skillId, 1).getName() + "</a></font></td>");
  516. else if (skillId < 1000)
  517. sb.append("<td width=180><font color=\"949490\"><a action=\"bypass -h npc_%objectId%_skillselect " + groupType + " " + schemeName + " " + skillId + "\">" + SkillTable.getInstance().getInfo(skillId, 1).getName() + "</a></font></td>");
  518. else
  519. sb.append("<td width=180><font color=\"949490\"><a action=\"bypass -h npc_%objectId%_skillselect " + groupType + " " + schemeName + " " + skillId + "\">" + SkillTable.getInstance().getInfo(skillId, 1).getName() + "</a></font></td>");
  520.  
  521. count++;
  522. if (count == 2)
  523. {
  524. sb.append("</tr><tr><td></td></tr>");
  525. count = 0;
  526. }
  527. }
  528.  
  529. if (!sb.toString().endsWith("</tr>"))
  530. sb.append("</tr>");
  531.  
  532. sb.append("</table>");
  533.  
  534. return sb.toString();
  535. }
  536.  
  537. /**
  538. * @param player : The player to make checks on.
  539. * @param groupType : The group of skills to select.
  540. * @param schemeName : The scheme to make check.
  541. * @return a String representing a given scheme's content.
  542. */
  543. private static String getPlayerSchemeSkillList(Player player, String groupType, String schemeName)
  544. {
  545. final List<Integer> skills = BufferTable.getInstance().getScheme(player.getObjectId(), schemeName);
  546. if (skills.isEmpty())
  547. return "That scheme is empty.";
  548.  
  549. final StringBuilder sb = new StringBuilder(500);
  550. sb.append("<table>");
  551. int count = 0;
  552.  
  553. for (int sk : skills)
  554. {
  555. if (count == 0)
  556. sb.append("<tr>");
  557.  
  558. if (sk < 100)
  559. sb.append("<td width=180><font color=\"6e6e6a\"><a action=\"bypass -h npc_%objectId%_skillunselect " + groupType + " " + schemeName + " " + sk + "\">" + SkillTable.getInstance().getInfo(sk, 1).getName() + "</a></font></td>");
  560. else if (sk < 1000)
  561. sb.append("<td width=180><font color=\"6e6e6a\"><a action=\"bypass -h npc_%objectId%_skillunselect " + groupType + " " + schemeName + " " + sk + "\">" + SkillTable.getInstance().getInfo(sk, 1).getName() + "</a></font></td>");
  562. else
  563. sb.append("<td width=180><font color=\"6e6e6a\"><a action=\"bypass -h npc_%objectId%_skillunselect " + groupType + " " + schemeName + " " + sk + "\">" + SkillTable.getInstance().getInfo(sk, 1).getName() + "</a></font></td>");
  564.  
  565. count++;
  566. if (count == 2)
  567. {
  568. sb.append("</tr><tr><td></td></tr>");
  569. count = 0;
  570. }
  571. }
  572.  
  573. if (!sb.toString().endsWith("<tr>"))
  574. sb.append("<tr>");
  575.  
  576. sb.append("</table>");
  577.  
  578. return sb.toString();
  579. }
  580.  
  581. /**
  582. * @param groupType : The group of skills to select.
  583. * @param schemeName : The scheme to make check.
  584. * @return a string representing all groupTypes availables. The group currently on selection isn't linkable.
  585. */
  586. private static String getTypesFrame(String groupType, String schemeName)
  587. {
  588. final StringBuilder sb = new StringBuilder(500);
  589. sb.append("<table>");
  590.  
  591. int count = 0;
  592. for (String s : BufferTable.getSkillTypes())
  593. {
  594. if (count == 0)
  595. sb.append("<tr>");
  596.  
  597. if (groupType.equalsIgnoreCase(s))
  598. StringUtil.append(sb, "<td width=65>", s, "</td>");
  599. else
  600. StringUtil.append(sb, "<td width=65><a action=\"bypass -h npc_%objectId%_editschemes ", s, " ", schemeName, "\">", s, "</a></td>");
  601.  
  602. count++;
  603. if (count == 4)
  604. {
  605. sb.append("</tr>");
  606. count = 0;
  607. }
  608. }
  609.  
  610. if (!sb.toString().endsWith("</tr>"))
  611. sb.append("</tr>");
  612.  
  613. sb.append("</table>");
  614.  
  615. return sb.toString();
  616. }
  617.  
  618. /**
  619. * @param list : A list of skill ids.
  620. * @return a global fee for all skills contained in list.
  621. */
  622. private static int getFee(ArrayList<Integer> list)
  623. {
  624. if (Config.PBUFFER_STATIC_BUFF_COST >= 0)
  625. return (list.size() * Config.PBUFFER_STATIC_BUFF_COST);
  626.  
  627. int fee = 0;
  628. for (int sk : list)
  629. {
  630. if (Config.PBUFFER_BUFFLIST.get(sk) == null)
  631. continue;
  632.  
  633. fee += Config.PBUFFER_BUFFLIST.get(sk).getValue();
  634. }
  635.  
  636. return fee;
  637. }
  638.  
  639. private void autoBuffFunction(Player player, String bufflist)
  640. {
  641. ArrayList<L2Skill> skills_to_buff = new ArrayList<>();
  642. List<Integer> list = null;
  643.  
  644. if (bufflist.equalsIgnoreCase("fighter"))
  645. list = Config.PFIGHTER_SKILL_LIST;
  646. else if (bufflist.equalsIgnoreCase("mage"))
  647. list = Config.PMAGE_SKILL_LIST;
  648.  
  649. if (list != null)
  650. {
  651. for (int skillId : list)
  652. {
  653. L2Skill skill = SkillTable.getInstance().getInfo(skillId, SkillTable.getInstance().getMaxLevel(skillId));
  654. if (skill != null)
  655. skills_to_buff.add(skill);
  656. }
  657.  
  658. for (L2Skill sk : skills_to_buff)
  659. sk.getEffects(player, player);
  660.  
  661. player.updateEffectIcons();
  662.  
  663. list = null;
  664. }
  665.  
  666. skills_to_buff.clear();
  667.  
  668. showMainBuffWindow(player);
  669. }
  670. private void showBuffPlayerWindow(Player activeChar) {
  671. NpcHtmlMessage html = new NpcHtmlMessage(1);
  672. html.setFile("data/html/mods/buffer/player/Player.htm");
  673. html.replace("%objectId%", getObjectId());
  674. activeChar.sendPacket(html);
  675. }
  676.  
  677. private void showBuffPetWindow(Player activeChar) {
  678. NpcHtmlMessage html = new NpcHtmlMessage(1);
  679. html.setFile("data/html/mods/buffer/pet/Pet.htm");
  680. html.replace("%objectId%", getObjectId());
  681. activeChar.sendPacket(html);
  682. }
  683.  
  684. private void showMainBuffWindow(Player activeChar) {
  685. final StringBuilder sb = new StringBuilder(200);
  686.  
  687. final Map<String, ArrayList<Integer>> schemes = BufferTable.getInstance().getPlayerSchemes(activeChar.getObjectId());
  688. if (schemes == null || schemes.isEmpty())
  689. sb.append("<font color=\"LEVEL\">You haven't defined any scheme.</font>");
  690. else
  691. {
  692. for (Map.Entry<String, ArrayList<Integer>> scheme : schemes.entrySet())
  693. {
  694. final int cost = getFee(scheme.getValue());
  695. StringUtil.append(sb, "<font color=\"LEVEL\">", scheme.getKey(), " [", scheme.getValue().size(), " / ", activeChar.getMaxBuffCount(), "]", ((cost > 0) ? " - cost: " + StringUtil.formatNumber(cost) : ""), "</font><br1>");
  696. StringUtil.append(sb, "<a action=\"bypass npc_%objectId%_givebuffs ", scheme.getKey(), " ", cost, "\">Use on Me</a>&nbsp;|&nbsp;");
  697. StringUtil.append(sb, "<a action=\"bypass npc_%objectId%_givebuffs ", scheme.getKey(), " ", cost, " pet\">Use on Pet</a>&nbsp;|&nbsp;");
  698. StringUtil.append(sb, "<a action=\"bypass npc_%objectId%_editschemes ", scheme.getKey(), " 1\">Edit</a>&nbsp;|&nbsp;");
  699. StringUtil.append(sb, "<a action=\"bypass npc_%objectId%_deletescheme ", scheme.getKey(), "\">Delete</a><br>");
  700. }
  701. }
  702.  
  703. final NpcHtmlMessage html = new NpcHtmlMessage(0);
  704. html.setFile("data/html/mods/buffer/index.htm");
  705. html.replace("%schemes%", sb.toString());
  706. html.replace("%max_schemes%", Config.BUFFER_MAX_SCHEMES);
  707. html.replace("%objectId%", getObjectId());
  708. activeChar.sendPacket(html);
  709. }
  710.  
  711. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement