RequestChangePetName.java 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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 com.l2jserver.gameserver.datatables.PetNameTable;
  17. import com.l2jserver.gameserver.model.L2ItemInstance;
  18. import com.l2jserver.gameserver.model.actor.L2Character;
  19. import com.l2jserver.gameserver.model.actor.L2Summon;
  20. import com.l2jserver.gameserver.model.actor.instance.L2PetInstance;
  21. import com.l2jserver.gameserver.network.SystemMessageId;
  22. import com.l2jserver.gameserver.network.serverpackets.AbstractNpcInfo;
  23. import com.l2jserver.gameserver.network.serverpackets.InventoryUpdate;
  24. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  25. /**
  26. * This class ...
  27. *
  28. * @version $Revision: 1.3.4.4 $ $Date: 2005/04/06 16:13:48 $
  29. */
  30. public final class RequestChangePetName extends L2GameClientPacket
  31. {
  32. private static final String REQUESTCHANGEPETNAME__C__89 = "[C] 89 RequestChangePetName";
  33. //private static Logger _log = Logger.getLogger(RequestChangePetName.class.getName());
  34. private String _name;
  35. @Override
  36. protected void readImpl()
  37. {
  38. _name = readS();
  39. }
  40. @Override
  41. protected void runImpl()
  42. {
  43. L2Character activeChar = getClient().getActiveChar();
  44. if (activeChar == null)
  45. return;
  46. final L2Summon pet = activeChar.getPet();
  47. if (pet == null)
  48. return;
  49. if (pet.getName() != null)
  50. {
  51. activeChar.sendPacket(new SystemMessage(SystemMessageId.NAMING_YOU_CANNOT_SET_NAME_OF_THE_PET));
  52. return;
  53. }
  54. else if (PetNameTable.getInstance().doesPetNameExist(_name, pet.getTemplate().npcId))
  55. {
  56. activeChar.sendPacket(new SystemMessage(SystemMessageId.NAMING_ALREADY_IN_USE_BY_ANOTHER_PET));
  57. return;
  58. }
  59. else if ((_name.length() < 3) || (_name.length() > 16))
  60. {
  61. // SystemMessage sm = new SystemMessage(SystemMessage.NAMING_PETNAME_UP_TO_8CHARS);
  62. activeChar.sendMessage("Your pet's name can be up to 16 characters.");
  63. return;
  64. }
  65. else if (!PetNameTable.getInstance().isValidPetName(_name))
  66. {
  67. activeChar.sendPacket(new SystemMessage(SystemMessageId.NAMING_PETNAME_CONTAINS_INVALID_CHARS));
  68. return;
  69. }
  70. pet.setName(_name);
  71. pet.broadcastPacket(new AbstractNpcInfo.SummonInfo(pet, activeChar,1));
  72. pet.updateAndBroadcastStatus(1);
  73. // set the flag on the control item to say that the pet has a name
  74. if (pet instanceof L2PetInstance)
  75. {
  76. L2ItemInstance controlItem = pet.getOwner().getInventory().getItemByObjectId(pet.getControlItemId());
  77. if (controlItem != null)
  78. {
  79. controlItem.setCustomType2(1);
  80. controlItem.updateDatabase();
  81. InventoryUpdate iu = new InventoryUpdate();
  82. iu.addModifiedItem(controlItem);
  83. activeChar.sendPacket(iu);
  84. }
  85. }
  86. }
  87. @Override
  88. public String getType()
  89. {
  90. return REQUESTCHANGEPETNAME__C__89;
  91. }
  92. }