RequestMakeMacro.java 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. * Copyright (C) 2004-2015 L2J Server
  3. *
  4. * This file is part of L2J Server.
  5. *
  6. * L2J Server 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 Server 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 com.l2jserver.gameserver.network.clientpackets;
  20. import java.util.ArrayList;
  21. import java.util.List;
  22. import com.l2jserver.Config;
  23. import com.l2jserver.gameserver.enums.MacroType;
  24. import com.l2jserver.gameserver.model.Macro;
  25. import com.l2jserver.gameserver.model.MacroCmd;
  26. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  27. import com.l2jserver.gameserver.network.SystemMessageId;
  28. public final class RequestMakeMacro extends L2GameClientPacket
  29. {
  30. private static final String _C__CD_REQUESTMAKEMACRO = "[C] CD RequestMakeMacro";
  31. private Macro _macro;
  32. private int _commandsLenght = 0;
  33. private static final int MAX_MACRO_LENGTH = 12;
  34. @Override
  35. protected void readImpl()
  36. {
  37. int _id = readD();
  38. String _name = readS();
  39. String _desc = readS();
  40. String _acronym = readS();
  41. int _icon = readC();
  42. int _count = readC();
  43. if (_count > MAX_MACRO_LENGTH)
  44. {
  45. _count = MAX_MACRO_LENGTH;
  46. }
  47. if (Config.DEBUG)
  48. {
  49. _log.info("Make macro id:" + _id + "\tname:" + _name + "\tdesc:" + _desc + "\tacronym:" + _acronym + "\ticon:" + _icon + "\tcount:" + _count);
  50. }
  51. final List<MacroCmd> commands = new ArrayList<>(_count);
  52. for (int i = 0; i < _count; i++)
  53. {
  54. int entry = readC();
  55. int type = readC(); // 1 = skill, 3 = action, 4 = shortcut
  56. int d1 = readD(); // skill or page number for shortcuts
  57. int d2 = readC();
  58. String command = readS();
  59. _commandsLenght += command.length();
  60. commands.add(new MacroCmd(entry, MacroType.values()[(type < 1) || (type > 6) ? 0 : type], d1, d2, command));
  61. }
  62. _macro = new Macro(_id, _icon, _name, _desc, _acronym, commands);
  63. }
  64. @Override
  65. protected void runImpl()
  66. {
  67. L2PcInstance player = getClient().getActiveChar();
  68. if (player == null)
  69. {
  70. return;
  71. }
  72. if (_commandsLenght > 255)
  73. {
  74. // Invalid macro. Refer to the Help file for instructions.
  75. player.sendPacket(SystemMessageId.INVALID_MACRO);
  76. return;
  77. }
  78. if (player.getMacros().getAllMacroses().size() > 48)
  79. {
  80. // You may create up to 48 macros.
  81. player.sendPacket(SystemMessageId.YOU_MAY_CREATE_UP_TO_48_MACROS);
  82. return;
  83. }
  84. if (_macro.getName().isEmpty())
  85. {
  86. // Enter the name of the macro.
  87. player.sendPacket(SystemMessageId.ENTER_THE_MACRO_NAME);
  88. return;
  89. }
  90. if (_macro.getDescr().length() > 32)
  91. {
  92. // Macro descriptions may contain up to 32 characters.
  93. player.sendPacket(SystemMessageId.MACRO_DESCRIPTION_MAX_32_CHARS);
  94. return;
  95. }
  96. player.registerMacro(_macro);
  97. }
  98. @Override
  99. public String getType()
  100. {
  101. return _C__CD_REQUESTMAKEMACRO;
  102. }
  103. }