RequestChangePetName.java 3.4 KB

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