aboutsummaryrefslogtreecommitdiff
path: root/src/server/game/BattlePets/BattlePetMgr.cpp
diff options
context:
space:
mode:
authorMeji <alvaromegias_46@hotmail.com>2021-11-25 20:55:12 +0100
committerGitHub <noreply@github.com>2021-11-25 20:55:12 +0100
commit93c668ac50a529876054212dfef6544f70259035 (patch)
treea7bbe39e67a1f9b22ffdc44263b80e73bb364471 /src/server/game/BattlePets/BattlePetMgr.cpp
parent52824eedd374c92f53c772fe6431518a5f30626d (diff)
Core/BattlePets: Implemented BattlePetSpeciesFlags::NotAccountWide (#27303)
Co-authored-by: Shauren <shauren.trinity@gmail.com>
Diffstat (limited to 'src/server/game/BattlePets/BattlePetMgr.cpp')
-rw-r--r--src/server/game/BattlePets/BattlePetMgr.cpp89
1 files changed, 75 insertions, 14 deletions
diff --git a/src/server/game/BattlePets/BattlePetMgr.cpp b/src/server/game/BattlePets/BattlePetMgr.cpp
index 811361d223a..79754f190aa 100644
--- a/src/server/game/BattlePets/BattlePetMgr.cpp
+++ b/src/server/game/BattlePets/BattlePetMgr.cpp
@@ -26,6 +26,7 @@
#include "ObjectAccessor.h"
#include "ObjectMgr.h"
#include "Player.h"
+#include "Realm.h"
#include "World.h"
#include "WorldSession.h"
@@ -216,12 +217,34 @@ void BattlePetMgr::LoadFromDB(PreparedQueryResult pets, PreparedQueryResult slot
{
Field* fields = pets->Fetch();
uint32 species = fields[1].GetUInt32();
+ ObjectGuid ownerGuid = !fields[11].IsNull() ? ObjectGuid::Create<HighGuid::Player>(fields[11].GetInt64()) : ObjectGuid::Empty;
if (BattlePetSpeciesEntry const* speciesEntry = sBattlePetSpeciesStore.LookupEntry(species))
{
- if (HasMaxPetCount(speciesEntry))
+ if (speciesEntry->GetFlags().HasFlag(BattlePetSpeciesFlags::NotAccountWide))
{
- TC_LOG_ERROR("misc", "Battlenet account with id %u has more than maximum battle pets of species %u", _owner->GetBattlenetAccountId(), species);
+ if (ownerGuid.IsEmpty())
+ {
+ TC_LOG_ERROR("misc", "Battlenet account with id %u has battle pet of species %u with BattlePetSpeciesFlags::NotAccountWide but no owner", _owner->GetBattlenetAccountId(), species);
+ continue;
+ }
+ }
+ else
+ {
+ if (!ownerGuid.IsEmpty())
+ {
+ TC_LOG_ERROR("misc", "Battlenet account with id %u has battle pet of species %u without BattlePetSpeciesFlags::NotAccountWide but with owner", _owner->GetBattlenetAccountId(), species);
+ continue;
+ }
+ }
+
+ if (HasMaxPetCount(speciesEntry, ownerGuid))
+ {
+ if (ownerGuid.IsEmpty())
+ TC_LOG_ERROR("misc", "Battlenet account with id %u has more than maximum battle pets of species %u", _owner->GetBattlenetAccountId(), species);
+ else
+ TC_LOG_ERROR("misc", "Battlenet account with id %u has more than maximum battle pets of species %u for player %s", _owner->GetBattlenetAccountId(), species, ownerGuid.ToString().c_str());
+
continue;
}
@@ -239,11 +262,18 @@ void BattlePetMgr::LoadFromDB(PreparedQueryResult pets, PreparedQueryResult slot
pet.NameTimestamp = fields[10].GetInt64();
pet.PacketInfo.CreatureID = speciesEntry->CreatureID;
- if (!fields[11].IsNull())
+ if (!fields[12].IsNull())
{
pet.DeclinedName = std::make_unique<DeclinedName>();
for (uint8 i = 0; i < MAX_DECLINED_NAME_CASES; ++i)
- pet.DeclinedName->name[i] = fields[11 + i].GetString();
+ pet.DeclinedName->name[i] = fields[12 + i].GetString();
+ }
+
+ if (!ownerGuid.IsEmpty())
+ {
+ pet.PacketInfo.OwnerInfo.emplace();
+ pet.PacketInfo.OwnerInfo->Guid = ownerGuid;
+ pet.PacketInfo.OwnerInfo->PlayerVirtualRealm = pet.PacketInfo.OwnerInfo->PlayerNativeRealm = GetVirtualRealmAddress();
}
pet.SaveInfo = BATTLE_PET_UNCHANGED;
@@ -292,6 +322,17 @@ void BattlePetMgr::SaveToDB(LoginDatabaseTransaction& trans)
stmt->setUInt16(9, itr->second.PacketInfo.Flags);
stmt->setString(10, itr->second.PacketInfo.Name);
stmt->setInt64(11, itr->second.NameTimestamp);
+ if (itr->second.PacketInfo.OwnerInfo)
+ {
+ stmt->setInt64(12, itr->second.PacketInfo.OwnerInfo->Guid.GetCounter());
+ stmt->setInt32(13, realm.Id.Realm);
+ }
+ else
+ {
+ stmt->setNull(12);
+ stmt->setNull(13);
+ }
+
trans->Append(stmt);
if (itr->second.DeclinedName)
@@ -399,7 +440,15 @@ void BattlePetMgr::AddPet(uint32 species, uint32 display, uint16 breed, BattlePe
pet.PacketInfo.Name = "";
pet.CalculateStats();
pet.PacketInfo.Health = pet.PacketInfo.MaxHealth;
- pet.NameTimestamp = 0;
+
+ Player* player = _owner->GetPlayer();
+ if (battlePetSpecies->GetFlags().HasFlag(BattlePetSpeciesFlags::NotAccountWide))
+ {
+ pet.PacketInfo.OwnerInfo.emplace();
+ pet.PacketInfo.OwnerInfo->Guid = player->GetGUID();
+ pet.PacketInfo.OwnerInfo->PlayerVirtualRealm = pet.PacketInfo.OwnerInfo->PlayerNativeRealm = GetVirtualRealmAddress();
+ }
+
pet.SaveInfo = BATTLE_PET_NEW;
_pets[pet.PacketInfo.Guid.GetCounter()] = std::move(pet);
@@ -408,8 +457,8 @@ void BattlePetMgr::AddPet(uint32 species, uint32 display, uint16 breed, BattlePe
updates.push_back(std::ref(pet));
SendUpdates(std::move(updates), true);
- _owner->GetPlayer()->UpdateCriteria(CriteriaType::UniquePetsOwned);
- _owner->GetPlayer()->UpdateCriteria(CriteriaType::LearnedNewPet, species);
+ player->UpdateCriteria(CriteriaType::UniquePetsOwned);
+ player->UpdateCriteria(CriteriaType::LearnedNewPet, species);
}
void BattlePetMgr::RemovePet(ObjectGuid guid)
@@ -473,19 +522,30 @@ bool BattlePetMgr::IsPetInSlot(ObjectGuid guid)
return false;
}
-uint8 BattlePetMgr::GetPetCount(uint32 species) const
+uint8 BattlePetMgr::GetPetCount(BattlePetSpeciesEntry const* battlePetSpecies, ObjectGuid ownerGuid) const
{
- return uint8(std::count_if(_pets.begin(), _pets.end(), [species](std::pair<uint64 const, BattlePet> const& pet)
+ return uint8(std::count_if(_pets.begin(), _pets.end(), [battlePetSpecies, ownerGuid](std::pair<uint64 const, BattlePet> const& pet)
{
- return pet.second.PacketInfo.Species == species && pet.second.SaveInfo != BATTLE_PET_REMOVED;
+ if (pet.second.PacketInfo.Species != battlePetSpecies->ID)
+ return false;
+
+ if (pet.second.SaveInfo == BATTLE_PET_REMOVED)
+ return false;
+
+ if (battlePetSpecies->GetFlags().HasFlag(BattlePetSpeciesFlags::NotAccountWide))
+ if (!ownerGuid.IsEmpty() && pet.second.PacketInfo.OwnerInfo)
+ if (pet.second.PacketInfo.OwnerInfo->Guid != ownerGuid)
+ return false;
+
+ return true;
}));
}
-bool BattlePetMgr::HasMaxPetCount(BattlePetSpeciesEntry const* speciesEntry) const
+bool BattlePetMgr::HasMaxPetCount(BattlePetSpeciesEntry const* battlePetSpecies, ObjectGuid ownerGuid) const
{
- uint8 maxPetsPerSpecies = speciesEntry->GetFlags().HasFlag(BattlePetSpeciesFlags::LegacyAccountUnique) ? 1 : DEFAULT_MAX_BATTLE_PETS_PER_SPECIES;
+ uint8 maxPetsPerSpecies = battlePetSpecies->GetFlags().HasFlag(BattlePetSpeciesFlags::LegacyAccountUnique) ? 1 : DEFAULT_MAX_BATTLE_PETS_PER_SPECIES;
- return GetPetCount(speciesEntry->ID) >= maxPetsPerSpecies;
+ return GetPetCount(battlePetSpecies, ownerGuid) >= maxPetsPerSpecies;
}
uint32 BattlePetMgr::GetPetUniqueSpeciesCount() const
@@ -624,7 +684,8 @@ void BattlePetMgr::SendJournal()
for (auto& pet : _pets)
if (pet.second.SaveInfo != BATTLE_PET_REMOVED)
- battlePetJournal.Pets.push_back(std::ref(pet.second.PacketInfo));
+ if (!pet.second.PacketInfo.OwnerInfo || pet.second.PacketInfo.OwnerInfo->Guid == _owner->GetPlayer()->GetGUID())
+ battlePetJournal.Pets.push_back(std::ref(pet.second.PacketInfo));
battlePetJournal.Slots.reserve(_slots.size());
std::transform(_slots.begin(), _slots.end(), std::back_inserter(battlePetJournal.Slots), [](WorldPackets::BattlePet::BattlePetSlot& slot) { return std::ref(slot); });