BloodAlliance.java 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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 handlers.bypasshandlers;
  16. import java.util.StringTokenizer;
  17. import java.util.logging.Level;
  18. import com.l2jserver.gameserver.handler.IBypassHandler;
  19. import com.l2jserver.gameserver.model.actor.L2Character;
  20. import com.l2jserver.gameserver.model.actor.L2Npc;
  21. import com.l2jserver.gameserver.model.actor.instance.L2CastleWarehouseInstance;
  22. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  23. import com.l2jserver.gameserver.network.serverpackets.NpcHtmlMessage;
  24. /**
  25. * Castle Warehouse - Blood Alliance
  26. * @author malyelfik
  27. */
  28. public class BloodAlliance implements IBypassHandler
  29. {
  30. private static final String[] COMMANDS =
  31. {
  32. "HonoraryItem",
  33. "Receive",
  34. "Exchange"
  35. };
  36. @Override
  37. public boolean useBypass(String command, L2PcInstance activeChar, L2Character target)
  38. {
  39. if (!(target instanceof L2Npc))
  40. {
  41. return false;
  42. }
  43. L2CastleWarehouseInstance npc = ((L2CastleWarehouseInstance) target);
  44. try
  45. {
  46. NpcHtmlMessage html = new NpcHtmlMessage(npc.getObjectId());
  47. StringTokenizer st = new StringTokenizer(command, " ");
  48. String actualCommand = st.nextToken(); // Get actual command
  49. if (actualCommand.equalsIgnoreCase(COMMANDS[0]))
  50. {
  51. if (activeChar.isClanLeader())
  52. {
  53. html.setFile(activeChar.getHtmlPrefix(), "data/html/castlewarehouse/castlewarehouse-4.htm");
  54. html.replace("%blood%", Integer.toString(npc.getCastle().getBloodAlliance()));
  55. }
  56. else
  57. {
  58. html.setFile(activeChar.getHtmlPrefix(), "data/html/castlewarehouse/castlewarehouse-3.htm");
  59. }
  60. }
  61. else if (actualCommand.equalsIgnoreCase(COMMANDS[1]))
  62. {
  63. int count = npc.getCastle().getBloodAlliance();
  64. if (count == 0)
  65. {
  66. html.setFile(activeChar.getHtmlPrefix(), "data/html/castlewarehouse/castlewarehouse-5.htm");
  67. }
  68. else
  69. {
  70. activeChar.addItem("BloodAlliance", 9911, count, activeChar, true);
  71. npc.getCastle().setBloodAlliance(0);
  72. html.setFile(activeChar.getHtmlPrefix(), "data/html/castlewarehouse/castlewarehouse-6.htm");
  73. }
  74. }
  75. else if (actualCommand.equalsIgnoreCase(COMMANDS[2]))
  76. {
  77. if (activeChar.getInventory().getInventoryItemCount(9911, -1) > 0)
  78. {
  79. activeChar.destroyItemByItemId("BloodAllianceExchange", 9911, 1, activeChar, true);
  80. activeChar.addItem("BloodAllianceExchange", 9910, 30, activeChar, true);
  81. html.setFile(activeChar.getHtmlPrefix(), "data/html/castlewarehouse/castlewarehouse-7.htm");
  82. }
  83. else
  84. {
  85. html.setFile(activeChar.getHtmlPrefix(), "data/html/castlewarehouse/castlewarehouse-8.htm");
  86. }
  87. }
  88. html.replace("%objectId%", String.valueOf(npc.getObjectId()));
  89. activeChar.sendPacket(html);
  90. return true;
  91. }
  92. catch (Exception e)
  93. {
  94. _log.log(Level.WARNING, "Exception in " + getClass().getSimpleName(), e);
  95. }
  96. return false;
  97. }
  98. @Override
  99. public String[] getBypassList()
  100. {
  101. return COMMANDS;
  102. }
  103. }