diff options
author | Meji <alvaromegias_46@hotmail.com> | 2021-11-20 19:06:14 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-20 19:06:14 +0100 |
commit | 8614690e27df8197586cc702760409293f3f6c3d (patch) | |
tree | eb95f093b283d9bb728e3e26800240dda462b137 /src/server/game/BattlePets/BattlePetMgr.cpp | |
parent | b1eb4c2b3e0745e0d801bfa4111c692cc3bb00a1 (diff) |
Core/BattlePets: Implemented battle pet name query packet (#27294)
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.cpp | 41 |
1 files changed, 28 insertions, 13 deletions
diff --git a/src/server/game/BattlePets/BattlePetMgr.cpp b/src/server/game/BattlePets/BattlePetMgr.cpp index 9ff67a33d1e..54b4282e40e 100644 --- a/src/server/game/BattlePets/BattlePetMgr.cpp +++ b/src/server/game/BattlePets/BattlePetMgr.cpp @@ -20,6 +20,7 @@ #include "Containers.h" #include "Creature.h" #include "DatabaseEnv.h" +#include "GameTime.h" #include "Item.h" #include "Log.h" #include "ObjectAccessor.h" @@ -235,13 +236,14 @@ void BattlePetMgr::LoadFromDB(PreparedQueryResult pets, PreparedQueryResult slot pet.PacketInfo.Quality = fields[7].GetUInt8(); pet.PacketInfo.Flags = fields[8].GetUInt16(); pet.PacketInfo.Name = fields[9].GetString(); + pet.NameTimestamp = fields[10].GetInt64(); pet.PacketInfo.CreatureID = speciesEntry->CreatureID; - if (!fields[10].IsNull()) + if (!fields[11].IsNull()) { - pet.DeclinedName.reset(new DeclinedName); + pet.DeclinedName = std::make_unique<DeclinedName>(); for (uint8 i = 0; i < MAX_DECLINED_NAME_CASES; ++i) - pet.DeclinedName->name[i] = fields[10 + i].GetString(); + pet.DeclinedName->name[i] = fields[11 + i].GetString(); } pet.SaveInfo = BATTLE_PET_UNCHANGED; @@ -289,6 +291,7 @@ void BattlePetMgr::SaveToDB(LoginDatabaseTransaction& trans) stmt->setUInt8(8, itr->second.PacketInfo.Quality); stmt->setUInt16(9, itr->second.PacketInfo.Flags); stmt->setString(10, itr->second.PacketInfo.Name); + stmt->setInt64(11, itr->second.NameTimestamp); trans->Append(stmt); if (itr->second.DeclinedName) @@ -313,8 +316,9 @@ void BattlePetMgr::SaveToDB(LoginDatabaseTransaction& trans) stmt->setUInt8(3, itr->second.PacketInfo.Quality); stmt->setUInt16(4, itr->second.PacketInfo.Flags); stmt->setString(5, itr->second.PacketInfo.Name); - stmt->setUInt32(6, _owner->GetBattlenetAccountId()); - stmt->setUInt64(7, itr->first); + stmt->setInt64(6, itr->second.NameTimestamp); + stmt->setUInt32(7, _owner->GetBattlenetAccountId()); + stmt->setUInt64(8, itr->first); trans->Append(stmt); stmt = LoginDatabase.GetPreparedStatement(LOGIN_DEL_BATTLE_PET_DECLINED_NAME); @@ -395,6 +399,7 @@ void BattlePetMgr::AddPet(uint32 species, uint32 display, uint16 breed, BattlePe pet.PacketInfo.Name = ""; pet.CalculateStats(); pet.PacketInfo.Health = pet.PacketInfo.MaxHealth; + pet.NameTimestamp = 0; pet.SaveInfo = BATTLE_PET_NEW; _pets[pet.PacketInfo.Guid.GetCounter()] = std::move(pet); @@ -441,6 +446,7 @@ void BattlePetMgr::ModifyName(ObjectGuid guid, std::string const& name, Declined return; pet->PacketInfo.Name = name; + pet->NameTimestamp = !pet->PacketInfo.Name.empty() ? GameTime::GetGameTime() : time_t(0); pet->DeclinedName.reset(); if (declinedName) @@ -448,6 +454,14 @@ void BattlePetMgr::ModifyName(ObjectGuid guid, std::string const& name, Declined if (pet->SaveInfo != BATTLE_PET_NEW) pet->SaveInfo = BATTLE_PET_CHANGED; + + // Update the timestamp if the battle pet is summoned + Player* player = _owner->GetPlayer(); + Creature* summonedBattlePet = ObjectAccessor::GetCreatureOrPetOrVehicle(*player, player->GetCritterGUID()); + if (summonedBattlePet) + if (player->GetSummonedBattlePetGUID() == summonedBattlePet->GetBattlePetCompanionGUID()) + if (summonedBattlePet->GetBattlePetCompanionGUID() == guid) + summonedBattlePet->SetBattlePetCompanionNameTimestamp(pet->NameTimestamp); } bool BattlePetMgr::IsPetInSlot(ObjectGuid guid) @@ -581,20 +595,21 @@ void BattlePetMgr::SummonPet(ObjectGuid guid) return; // TODO: set proper CreatureID for spell DEFAULT_SUMMON_BATTLE_PET_SPELL (default EffectMiscValueA is 40721 - Murkimus the Gladiator) - _owner->GetPlayer()->SetSummonedBattlePetGUID(guid); - _owner->GetPlayer()->SetCurrentBattlePetBreedQuality(pet->PacketInfo.Quality); - _owner->GetPlayer()->CastSpell(_owner->GetPlayer(), speciesEntry->SummonSpellID ? speciesEntry->SummonSpellID : uint32(DEFAULT_SUMMON_BATTLE_PET_SPELL)); + Player* player = _owner->GetPlayer(); + player->SetSummonedBattlePetGUID(guid); + player->SetCurrentBattlePetBreedQuality(pet->PacketInfo.Quality); + player->CastSpell(player, speciesEntry->SummonSpellID ? speciesEntry->SummonSpellID : uint32(DEFAULT_SUMMON_BATTLE_PET_SPELL)); } void BattlePetMgr::DismissPet() { - Player* ownerPlayer = _owner->GetPlayer(); - Creature* pet = ObjectAccessor::GetCreatureOrPetOrVehicle(*ownerPlayer, ownerPlayer->GetCritterGUID()); - if (pet && *ownerPlayer->m_activePlayerData->SummonedBattlePetGUID == pet->GetBattlePetCompanionGUID()) + Player* player = _owner->GetPlayer(); + Creature* pet = ObjectAccessor::GetCreatureOrPetOrVehicle(*player, player->GetCritterGUID()); + if (pet && player->GetSummonedBattlePetGUID() == pet->GetBattlePetCompanionGUID()) { pet->DespawnOrUnsummon(); - ownerPlayer->SetSummonedBattlePetGUID(ObjectGuid::Empty); - ownerPlayer->SetCurrentBattlePetBreedQuality(AsUnderlyingType(BattlePetBreedQuality::Poor)); + player->SetSummonedBattlePetGUID(ObjectGuid::Empty); + player->SetCurrentBattlePetBreedQuality(AsUnderlyingType(BattlePetBreedQuality::Poor)); } } |