RequestMakeMacro.java 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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 com.l2jserver.gameserver.network.clientpackets;
  16. import java.util.logging.Logger;
  17. import com.l2jserver.Config;
  18. import com.l2jserver.gameserver.model.L2Macro;
  19. import com.l2jserver.gameserver.model.L2Macro.L2MacroCmd;
  20. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  21. import com.l2jserver.gameserver.network.SystemMessageId;
  22. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  23. public final class RequestMakeMacro extends L2GameClientPacket
  24. {
  25. protected static final Logger _log = Logger.getLogger(RequestMakeMacro.class.getName());
  26. private L2Macro _macro;
  27. private int _commandsLenght = 0;
  28. private static final String _C__C1_REQUESTMAKEMACRO = "[C] C1 RequestMakeMacro";
  29. private static final int MAX_MACRO_LENGTH = 12;
  30. /**
  31. * packet type id 0xc1
  32. *
  33. * sample
  34. *
  35. * c1
  36. * d // id
  37. * S // macro name
  38. * S // unknown desc
  39. * S // unknown acronym
  40. * c // icon
  41. * c // count
  42. *
  43. * c // entry
  44. * c // type
  45. * d // skill id
  46. * c // shortcut id
  47. * S // command name
  48. *
  49. * format: cdSSScc (ccdcS)
  50. */
  51. @Override
  52. protected void readImpl()
  53. {
  54. int _id = readD();
  55. String _name = readS();
  56. String _desc = readS();
  57. String _acronym = readS();
  58. int _icon = readC();
  59. int _count = readC();
  60. if (_count > MAX_MACRO_LENGTH) _count = MAX_MACRO_LENGTH;
  61. L2MacroCmd[] commands = new L2MacroCmd[_count];
  62. if (Config.DEBUG)
  63. _log.info("Make macro id:"+_id+"\tname:"+_name+"\tdesc:"+_desc+"\tacronym:"+_acronym+"\ticon:"+_icon+"\tcount:"+_count);
  64. for (int i = 0; i < _count; i++)
  65. {
  66. int entry = readC();
  67. int type = readC(); // 1 = skill, 3 = action, 4 = shortcut
  68. int d1 = readD(); // skill or page number for shortcuts
  69. int d2 = readC();
  70. String command = readS();
  71. _commandsLenght += command.length();
  72. commands[i] = new L2MacroCmd(entry, type, d1, d2, command);
  73. if (Config.DEBUG)
  74. _log.info("entry:"+entry+"\ttype:"+type+"\td1:"+d1+"\td2:"+d2+"\tcommand:"+command);
  75. }
  76. _macro = new L2Macro(_id, _icon, _name, _desc, _acronym, commands);
  77. }
  78. @Override
  79. protected void runImpl()
  80. {
  81. L2PcInstance player = getClient().getActiveChar();
  82. if (player == null)
  83. return;
  84. if (_commandsLenght > 255)
  85. {
  86. //Invalid macro. Refer to the Help file for instructions.
  87. player.sendPacket(new SystemMessage(SystemMessageId.INVALID_MACRO));
  88. return;
  89. }
  90. if (player.getMacroses().getAllMacroses().length > 48)
  91. {
  92. //You may create up to 48 macros.
  93. player.sendPacket(new SystemMessage(SystemMessageId.YOU_MAY_CREATE_UP_TO_48_MACROS));
  94. return;
  95. }
  96. if (_macro.name.length() == 0)
  97. {
  98. //Enter the name of the macro.
  99. player.sendPacket(new SystemMessage(SystemMessageId.ENTER_THE_MACRO_NAME));
  100. return;
  101. }
  102. if (_macro.descr.length() > 32)
  103. {
  104. //Macro descriptions may contain up to 32 characters.
  105. player.sendPacket(new SystemMessage(SystemMessageId.MACRO_DESCRIPTION_MAX_32_CHARS));
  106. return;
  107. }
  108. player.registerMacro(_macro);
  109. }
  110. /* (non-Javadoc)
  111. * @see com.l2jserver.gameserver.clientpackets.ClientBasePacket#getType()
  112. */
  113. @Override
  114. public String getType()
  115. {
  116. return _C__C1_REQUESTMAKEMACRO;
  117. }
  118. }