Core/BattlePets: Store declined names
Port From (https://github.com/TrinityCore/TrinityCore/commit/82b3a409db4dfe689c84234f3ae427369325bf0b)
This commit is contained in:
@@ -179,6 +179,14 @@ namespace Game.BattlePets
|
||||
pet.PacketInfo.Flags = petsResult.Read<ushort>(7);
|
||||
pet.PacketInfo.Name = petsResult.Read<string>(8);
|
||||
pet.PacketInfo.CreatureID = speciesEntry.CreatureID;
|
||||
|
||||
if (!petsResult.IsNull(9))
|
||||
{
|
||||
pet.DeclinedName = new();
|
||||
for (byte i = 0; i < SharedConst.MaxDeclinedNameCases; ++i)
|
||||
pet.DeclinedName.name[i] = petsResult.Read<string>(9 + i);
|
||||
}
|
||||
|
||||
pet.SaveInfo = BattlePetSaveInfo.Unchanged;
|
||||
pet.CalculateStats();
|
||||
_pets[pet.PacketInfo.Guid.GetCounter()] = pet;
|
||||
@@ -223,6 +231,19 @@ namespace Game.BattlePets
|
||||
stmt.AddValue(8, pair.Value.PacketInfo.Flags);
|
||||
stmt.AddValue(9, pair.Value.PacketInfo.Name);
|
||||
trans.Append(stmt);
|
||||
|
||||
if (pair.Value.DeclinedName != null)
|
||||
{
|
||||
stmt = DB.Login.GetPreparedStatement(LoginStatements.INS_BATTLE_PET_DECLINED_NAME);
|
||||
stmt.AddValue(0, pair.Key);
|
||||
|
||||
for (byte i = 0; i < SharedConst.MaxDeclinedNameCases; i++)
|
||||
stmt.AddValue(i + 1, pair.Value.DeclinedName.name[i]);
|
||||
|
||||
trans.Append(stmt);
|
||||
}
|
||||
|
||||
|
||||
pair.Value.SaveInfo = BattlePetSaveInfo.Unchanged;
|
||||
break;
|
||||
case BattlePetSaveInfo.Changed:
|
||||
@@ -236,9 +257,29 @@ namespace Game.BattlePets
|
||||
stmt.AddValue(6, _owner.GetBattlenetAccountId());
|
||||
stmt.AddValue(7, pair.Key);
|
||||
trans.Append(stmt);
|
||||
|
||||
stmt = DB.Login.GetPreparedStatement(LoginStatements.DEL_BATTLE_PET_DECLINED_NAME);
|
||||
stmt.AddValue(0, pair.Key);
|
||||
trans.Append(stmt);
|
||||
|
||||
if (pair.Value.DeclinedName != null)
|
||||
{
|
||||
stmt = DB.Login.GetPreparedStatement(LoginStatements.INS_BATTLE_PET_DECLINED_NAME);
|
||||
stmt.AddValue(0, pair.Key);
|
||||
|
||||
for (byte i = 0; i < SharedConst.MaxDeclinedNameCases; i++)
|
||||
stmt.AddValue(i + 1, pair.Value.DeclinedName.name[i]);
|
||||
|
||||
trans.Append(stmt);
|
||||
}
|
||||
|
||||
pair.Value.SaveInfo = BattlePetSaveInfo.Unchanged;
|
||||
break;
|
||||
case BattlePetSaveInfo.Removed:
|
||||
stmt = DB.Login.GetPreparedStatement(LoginStatements.DEL_BATTLE_PET_DECLINED_NAME);
|
||||
stmt.AddValue(0, pair.Key);
|
||||
trans.Append(stmt);
|
||||
|
||||
stmt = DB.Login.GetPreparedStatement(LoginStatements.DEL_BATTLE_PETS);
|
||||
stmt.AddValue(0, _owner.GetBattlenetAccountId());
|
||||
stmt.AddValue(1, pair.Key);
|
||||
@@ -340,6 +381,22 @@ namespace Game.BattlePets
|
||||
pet.SaveInfo = BattlePetSaveInfo.Changed;
|
||||
}
|
||||
|
||||
public void ModifyName(ObjectGuid guid, string name, DeclinedName declinedName)
|
||||
{
|
||||
BattlePet pet = GetPet(guid);
|
||||
if (pet == null)
|
||||
return;
|
||||
|
||||
pet.PacketInfo.Name = name;
|
||||
|
||||
pet.DeclinedName = new DeclinedName();
|
||||
if (declinedName != null)
|
||||
pet.DeclinedName = declinedName;
|
||||
|
||||
if (pet.SaveInfo != BattlePetSaveInfo.New)
|
||||
pet.SaveInfo = BattlePetSaveInfo.Changed;
|
||||
}
|
||||
|
||||
bool IsPetInSlot(ObjectGuid guid)
|
||||
{
|
||||
foreach (BattlePetSlot slot in _slots)
|
||||
@@ -582,6 +639,7 @@ namespace Game.BattlePets
|
||||
}
|
||||
|
||||
public BattlePetStruct PacketInfo;
|
||||
public DeclinedName DeclinedName;
|
||||
public BattlePetSaveInfo SaveInfo;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,14 +45,7 @@ namespace Game
|
||||
[WorldPacketHandler(ClientOpcodes.BattlePetModifyName)]
|
||||
void HandleBattlePetModifyName(BattlePetModifyName battlePetModifyName)
|
||||
{
|
||||
BattlePetMgr.BattlePet pet = GetBattlePetMgr().GetPet(battlePetModifyName.PetGuid);
|
||||
if (pet != null)
|
||||
{
|
||||
pet.PacketInfo.Name = battlePetModifyName.Name;
|
||||
|
||||
if (pet.SaveInfo != BattlePetSaveInfo.New)
|
||||
pet.SaveInfo = BattlePetSaveInfo.Changed;
|
||||
}
|
||||
GetBattlePetMgr().ModifyName(battlePetModifyName.PetGuid, battlePetModifyName.Name, battlePetModifyName.DeclinedName.Value);
|
||||
}
|
||||
|
||||
[WorldPacketHandler(ClientOpcodes.BattlePetDeletePet)]
|
||||
|
||||
@@ -125,7 +125,7 @@ namespace Game.Networking.Packets
|
||||
|
||||
if (_worldPacket.HasBit())
|
||||
{
|
||||
Declined = new DeclinedName();
|
||||
DeclinedName.Set(new DeclinedName());
|
||||
|
||||
byte[] declinedNameLengths = new byte[SharedConst.MaxDeclinedNameCases];
|
||||
|
||||
@@ -133,7 +133,7 @@ namespace Game.Networking.Packets
|
||||
declinedNameLengths[i] = _worldPacket.ReadBits<byte>(7);
|
||||
|
||||
for (byte i = 0; i < SharedConst.MaxDeclinedNameCases; ++i)
|
||||
Declined.name[i] = _worldPacket.ReadString(declinedNameLengths[i]);
|
||||
DeclinedName.Value.name[i] = _worldPacket.ReadString(declinedNameLengths[i]);
|
||||
}
|
||||
|
||||
Name = _worldPacket.ReadString(nameLength);
|
||||
@@ -141,7 +141,7 @@ namespace Game.Networking.Packets
|
||||
|
||||
public ObjectGuid PetGuid;
|
||||
public string Name;
|
||||
public DeclinedName Declined;
|
||||
public Optional<DeclinedName> DeclinedName;
|
||||
}
|
||||
|
||||
class BattlePetDeletePet : ClientPacket
|
||||
|
||||
Reference in New Issue
Block a user