BloodAlliance.java 3.6 KB

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