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