RequestChangePetName.java 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 com.l2jserver.gameserver.data.sql.impl.PetNameTable;
  21. import com.l2jserver.gameserver.model.actor.L2Summon;
  22. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  23. import com.l2jserver.gameserver.network.SystemMessageId;
  24. /**
  25. * This class ...
  26. * @version $Revision: 1.3.4.4 $ $Date: 2005/04/06 16:13:48 $
  27. */
  28. public final class RequestChangePetName extends L2GameClientPacket
  29. {
  30. private static final String _C__93_REQUESTCHANGEPETNAME = "[C] 93 RequestChangePetName";
  31. private String _name;
  32. @Override
  33. protected void readImpl()
  34. {
  35. _name = readS();
  36. }
  37. @Override
  38. protected void runImpl()
  39. {
  40. L2PcInstance activeChar = getClient().getActiveChar();
  41. if (activeChar == null)
  42. {
  43. return;
  44. }
  45. final L2Summon pet = activeChar.getSummon();
  46. if (pet == null)
  47. {
  48. return;
  49. }
  50. if (!pet.isPet())
  51. {
  52. activeChar.sendPacket(SystemMessageId.DONT_HAVE_PET);
  53. return;
  54. }
  55. if (pet.getName() != null)
  56. {
  57. activeChar.sendPacket(SystemMessageId.NAMING_YOU_CANNOT_SET_NAME_OF_THE_PET);
  58. return;
  59. }
  60. if (PetNameTable.getInstance().doesPetNameExist(_name, pet.getTemplate().getId()))
  61. {
  62. activeChar.sendPacket(SystemMessageId.NAMING_ALREADY_IN_USE_BY_ANOTHER_PET);
  63. return;
  64. }
  65. if ((_name.length() < 3) || (_name.length() > 16))
  66. {
  67. // activeChar.sendPacket(SystemMessageId.NAMING_PETNAME_UP_TO_8CHARS);
  68. activeChar.sendMessage("Your pet's name can be up to 16 characters in length.");
  69. return;
  70. }
  71. if (!PetNameTable.getInstance().isValidPetName(_name))
  72. {
  73. activeChar.sendPacket(SystemMessageId.NAMING_PETNAME_CONTAINS_INVALID_CHARS);
  74. return;
  75. }
  76. pet.setName(_name);
  77. pet.updateAndBroadcastStatus(1);
  78. }
  79. @Override
  80. public String getType()
  81. {
  82. return _C__93_REQUESTCHANGEPETNAME;
  83. }
  84. }