BloodAlliance.java 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. * Copyright (C) 2004-2013 L2J DataPack
  3. *
  4. * This file is part of L2J DataPack.
  5. *
  6. * L2J DataPack is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * L2J DataPack is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package handlers.bypasshandlers;
  20. import java.util.StringTokenizer;
  21. import java.util.logging.Level;
  22. import com.l2jserver.gameserver.handler.IBypassHandler;
  23. import com.l2jserver.gameserver.model.actor.L2Character;
  24. import com.l2jserver.gameserver.model.actor.instance.L2CastleWarehouseInstance;
  25. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  26. import com.l2jserver.gameserver.network.serverpackets.NpcHtmlMessage;
  27. /**
  28. * Castle Warehouse - Blood Alliance.
  29. * @author malyelfik
  30. */
  31. public class BloodAlliance implements IBypassHandler
  32. {
  33. private static final String[] COMMANDS =
  34. {
  35. "HonoraryItem",
  36. "Receive",
  37. "Exchange"
  38. };
  39. @Override
  40. public boolean useBypass(String command, L2PcInstance activeChar, L2Character target)
  41. {
  42. if (!(target instanceof L2CastleWarehouseInstance))
  43. {
  44. return false;
  45. }
  46. final L2CastleWarehouseInstance npc = (L2CastleWarehouseInstance) target;
  47. try
  48. {
  49. NpcHtmlMessage html = new NpcHtmlMessage(npc.getObjectId());
  50. StringTokenizer st = new StringTokenizer(command, " ");
  51. String actualCommand = st.nextToken(); // Get actual command
  52. if (actualCommand.equalsIgnoreCase(COMMANDS[0])) // "HonoraryItem"
  53. {
  54. if (npc.isMyLord(activeChar))
  55. {
  56. html.setFile(activeChar.getHtmlPrefix(), "data/html/castlewarehouse/castlewarehouse-4.htm");
  57. html.replace("%blood%", Integer.toString(activeChar.getClan().getBloodAllianceCount()));
  58. }
  59. else
  60. {
  61. html.setFile(activeChar.getHtmlPrefix(), "data/html/castlewarehouse/castlewarehouse-3.htm");
  62. }
  63. }
  64. else if (actualCommand.equalsIgnoreCase(COMMANDS[1])) // "Receive"
  65. {
  66. if (!npc.isMyLord(activeChar))
  67. {
  68. html.setFile(activeChar.getHtmlPrefix(), "data/html/castlewarehouse/castlewarehouse-5.htm");
  69. }
  70. else
  71. {
  72. activeChar.addItem("BloodAlliance", 9911, activeChar.getClan().getBloodAllianceCount(), activeChar, true);
  73. activeChar.getClan().resetBloodAllianceCount();
  74. html.setFile(activeChar.getHtmlPrefix(), "data/html/castlewarehouse/castlewarehouse-6.htm");
  75. }
  76. }
  77. else if (actualCommand.equalsIgnoreCase(COMMANDS[2])) // "Exchange"
  78. {
  79. if (activeChar.getInventory().getInventoryItemCount(9911, -1) > 0)
  80. {
  81. activeChar.destroyItemByItemId("BloodAllianceExchange", 9911, 1, activeChar, true);
  82. activeChar.addItem("BloodAllianceExchange", 9910, 30, activeChar, true);
  83. html.setFile(activeChar.getHtmlPrefix(), "data/html/castlewarehouse/castlewarehouse-7.htm");
  84. }
  85. else
  86. {
  87. html.setFile(activeChar.getHtmlPrefix(), "data/html/castlewarehouse/castlewarehouse-8.htm");
  88. }
  89. }
  90. html.replace("%objectId%", String.valueOf(npc.getObjectId()));
  91. activeChar.sendPacket(html);
  92. return true;
  93. }
  94. catch (Exception e)
  95. {
  96. _log.log(Level.WARNING, "Exception in " + getClass().getSimpleName(), e);
  97. }
  98. return false;
  99. }
  100. @Override
  101. public String[] getBypassList()
  102. {
  103. return COMMANDS;
  104. }
  105. }