mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-01-23 21:56:22 +00:00
feat(Core/Misc): implement ObjectGuid class (port from TC) (#4885)
This commit is contained in:
@@ -24,7 +24,7 @@
|
||||
#include "WorldPacket.h"
|
||||
#include "WorldSession.h"
|
||||
|
||||
Pet::Pet(Player* owner, PetType type) : Guardian(nullptr, owner ? owner->GetGUID() : 0, true),
|
||||
Pet::Pet(Player* owner, PetType type) : Guardian(nullptr, owner ? owner->GetGUID() : ObjectGuid::Empty, true),
|
||||
m_usedTalentCount(0), m_removed(false), m_owner(owner),
|
||||
m_happinessTimer(PET_LOSE_HAPPINES_INTERVAL), m_petType(type), m_duration(0),
|
||||
m_auraRaidUpdateMask(0), m_loading(false), m_petRegenTimer(PET_FOCUS_REGEN_INTERVAL), m_declinedname(nullptr), m_tempspellTarget(nullptr), m_tempoldTarget(nullptr), m_tempspellIsPositive(false), m_tempspell(0), asynchLoadType(PET_LOAD_DEFAULT)
|
||||
@@ -53,14 +53,14 @@ void Pet::AddToWorld()
|
||||
if (!IsInWorld())
|
||||
{
|
||||
///- Register the pet for guid lookup
|
||||
sObjectAccessor->AddObject(this);
|
||||
GetMap()->GetObjectsStore().Insert<Pet>(GetGUID(), this);
|
||||
Unit::AddToWorld();
|
||||
Motion_Initialize();
|
||||
AIM_Initialize();
|
||||
}
|
||||
|
||||
// pussywizard: apply ICC buff to pets
|
||||
if (IS_PLAYER_GUID(GetOwnerGUID()) && GetMapId() == 631 && FindMap() && FindMap()->ToInstanceMap() && FindMap()->ToInstanceMap()->GetInstanceScript() && FindMap()->ToInstanceMap()->GetInstanceScript()->GetData(251 /*DATA_BUFF_AVAILABLE*/))
|
||||
if (GetOwnerGUID().IsPlayer() && GetMapId() == 631 && FindMap() && FindMap()->ToInstanceMap() && FindMap()->ToInstanceMap()->GetInstanceScript() && FindMap()->ToInstanceMap()->GetInstanceScript()->GetData(251 /*DATA_BUFF_AVAILABLE*/))
|
||||
if (Unit* owner = GetOwner())
|
||||
if (Player* plr = owner->ToPlayer())
|
||||
{
|
||||
@@ -91,14 +91,14 @@ void Pet::RemoveFromWorld()
|
||||
{
|
||||
///- Don't call the function for Creature, normal mobs + totems go in a different storage
|
||||
Unit::RemoveFromWorld();
|
||||
sObjectAccessor->RemoveObject(this);
|
||||
GetMap()->GetObjectsStore().Remove<Pet>(GetGUID());
|
||||
}
|
||||
}
|
||||
|
||||
SpellCastResult Pet::TryLoadFromDB(Player* owner, bool current /*= false*/, PetType mandatoryPetType /*= MAX_PET_TYPE*/)
|
||||
{
|
||||
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_CHAR_PET_BY_ENTRY_AND_SLOT);
|
||||
stmt->setUInt32(0, owner->GetGUIDLow());
|
||||
stmt->setUInt32(0, owner->GetGUID().GetCounter());
|
||||
stmt->setUInt8(1, uint8(current ? PET_SAVE_AS_CURRENT : PET_SAVE_NOT_IN_SLOT));
|
||||
|
||||
PreparedQueryResult result = CharacterDatabase.AsyncQuery(stmt);
|
||||
@@ -157,28 +157,28 @@ bool Pet::LoadPetFromDB(Player* owner, uint8 asynchLoadType, uint32 petentry, ui
|
||||
if (owner->getClass() == CLASS_DEATH_KNIGHT && !owner->CanSeeDKPet()) // DK Pet exception
|
||||
return false;
|
||||
|
||||
uint32 ownerid = owner->GetGUIDLow();
|
||||
ObjectGuid::LowType ownerGuid = owner->GetGUID().GetCounter();
|
||||
PreparedStatement* stmt;
|
||||
|
||||
if (petnumber)
|
||||
{
|
||||
// Known petnumber entry
|
||||
stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_CHAR_PET_BY_ENTRY);
|
||||
stmt->setUInt32(0, ownerid);
|
||||
stmt->setUInt32(0, ownerGuid);
|
||||
stmt->setUInt32(1, petnumber);
|
||||
}
|
||||
else if (current)
|
||||
{
|
||||
// Current pet (slot 0)
|
||||
stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_CHAR_PET_BY_ENTRY_AND_SLOT);
|
||||
stmt->setUInt32(0, ownerid);
|
||||
stmt->setUInt32(0, ownerGuid);
|
||||
stmt->setUInt8(1, uint8(PET_SAVE_AS_CURRENT));
|
||||
}
|
||||
else if (petentry)
|
||||
{
|
||||
// known petentry entry (unique for summoned pet, but non unique for hunter pet (only from current or not stabled pets)
|
||||
stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_CHAR_PET_BY_ENTRY_AND_SLOT_2);
|
||||
stmt->setUInt32(0, ownerid);
|
||||
stmt->setUInt32(0, ownerGuid);
|
||||
stmt->setUInt32(1, petentry);
|
||||
stmt->setUInt8(2, uint8(PET_SAVE_AS_CURRENT));
|
||||
stmt->setUInt8(3, uint8(PET_SAVE_LAST_STABLE_SLOT));
|
||||
@@ -187,13 +187,14 @@ bool Pet::LoadPetFromDB(Player* owner, uint8 asynchLoadType, uint32 petentry, ui
|
||||
{
|
||||
// Any current or other non-stabled pet (for hunter "call pet")
|
||||
stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_CHAR_PET_BY_SLOT);
|
||||
stmt->setUInt32(0, ownerid);
|
||||
stmt->setUInt32(0, ownerGuid);
|
||||
stmt->setUInt8(1, uint8(PET_SAVE_AS_CURRENT));
|
||||
stmt->setUInt8(2, uint8(PET_SAVE_LAST_STABLE_SLOT));
|
||||
}
|
||||
|
||||
if (AsynchPetSummon* info = owner->GetSession()->_loadPetFromDBFirstCallback.GetSecondParam())
|
||||
delete info;
|
||||
|
||||
owner->GetSession()->_loadPetFromDBFirstCallback.Reset();
|
||||
owner->GetSession()->_loadPetFromDBFirstCallback.SetFirstParam(asynchLoadType);
|
||||
owner->GetSession()->_loadPetFromDBFirstCallback.SetSecondParam(info);
|
||||
@@ -204,7 +205,7 @@ bool Pet::LoadPetFromDB(Player* owner, uint8 asynchLoadType, uint32 petentry, ui
|
||||
void Pet::SavePetToDB(PetSaveMode mode, bool logout)
|
||||
{
|
||||
// not save not player pets
|
||||
if (!IS_PLAYER_GUID(GetOwnerGUID()))
|
||||
if (!GetOwnerGUID().IsPlayer())
|
||||
return;
|
||||
|
||||
// dont allow to save pet when it is loaded, possibly bugs action bar!, save only fully controlled creature
|
||||
@@ -242,7 +243,7 @@ void Pet::SavePetToDB(PetSaveMode mode, bool logout)
|
||||
// current/stable/not_in_slot
|
||||
if (mode >= PET_SAVE_AS_CURRENT)
|
||||
{
|
||||
uint32 ownerLowGUID = GUID_LOPART(GetOwnerGUID());
|
||||
ObjectGuid::LowType ownerLowGUID = GetOwnerGUID().GetCounter();
|
||||
trans = CharacterDatabase.BeginTransaction();
|
||||
// remove current data
|
||||
|
||||
@@ -306,7 +307,7 @@ void Pet::SavePetToDB(PetSaveMode mode, bool logout)
|
||||
}
|
||||
}
|
||||
|
||||
void Pet::DeleteFromDB(uint32 guidlow)
|
||||
void Pet::DeleteFromDB(ObjectGuid::LowType guidlow)
|
||||
{
|
||||
SQLTransaction trans = CharacterDatabase.BeginTransaction();
|
||||
|
||||
@@ -644,8 +645,8 @@ bool Pet::CreateBaseAtCreature(Creature* creature)
|
||||
|
||||
if (!IsPositionValid())
|
||||
{
|
||||
LOG_ERROR("server", "Pet (guidlow %d, entry %d) not created base at creature. Suggested coordinates isn't valid (X: %f Y: %f)",
|
||||
GetGUIDLow(), GetEntry(), GetPositionX(), GetPositionY());
|
||||
LOG_ERROR("server", "Pet %s not created base at creature. Suggested coordinates isn't valid (X: %f Y: %f)",
|
||||
GetGUID().ToString().c_str(), GetPositionX(), GetPositionY());
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -684,7 +685,7 @@ bool Pet::CreateBaseAtTamed(CreatureTemplate const* cinfo, Map* map, uint32 phas
|
||||
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
|
||||
LOG_DEBUG("entities.pet", "Pet::CreateBaseForTamed");
|
||||
#endif
|
||||
uint32 guid = sObjectMgr->GenerateLowGuid(HIGHGUID_PET);
|
||||
ObjectGuid::LowType guid = map->GenerateLowGuid<HighGuid::Pet>();
|
||||
uint32 pet_number = sObjectMgr->GeneratePetNumber();
|
||||
if (!Create(guid, map, phaseMask, cinfo->Entry, pet_number))
|
||||
return false;
|
||||
@@ -1260,7 +1261,7 @@ void Pet::_SaveSpells(SQLTransaction& trans)
|
||||
void Pet::_LoadAuras(PreparedQueryResult result, uint32 timediff)
|
||||
{
|
||||
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
|
||||
LOG_DEBUG("entities.pet", "Loading auras for pet %u", GetGUIDLow());
|
||||
LOG_DEBUG("entities.pet", "Loading auras for pet %s", GetGUID().ToString().c_str());
|
||||
#endif
|
||||
|
||||
if (result)
|
||||
@@ -1270,7 +1271,7 @@ void Pet::_LoadAuras(PreparedQueryResult result, uint32 timediff)
|
||||
int32 damage[3];
|
||||
int32 baseDamage[3];
|
||||
Field* fields = result->Fetch();
|
||||
uint64 caster_guid = fields[0].GetUInt64();
|
||||
ObjectGuid caster_guid = ObjectGuid(fields[0].GetUInt64());
|
||||
// nullptr guid stored - pet is the caster of the spell - see Pet::_SaveAuras
|
||||
if (!caster_guid)
|
||||
caster_guid = GetGUID();
|
||||
@@ -1397,13 +1398,13 @@ void Pet::_SaveAuras(SQLTransaction& trans, bool logout)
|
||||
}
|
||||
|
||||
// don't save guid of caster in case we are caster of the spell - guid for pet is generated every pet load, so it won't match saved guid anyways
|
||||
uint64 casterGUID = (itr->second->GetCasterGUID() == GetGUID()) ? 0 : itr->second->GetCasterGUID();
|
||||
ObjectGuid casterGUID = (itr->second->GetCasterGUID() == GetGUID()) ? ObjectGuid::Empty : itr->second->GetCasterGUID();
|
||||
|
||||
uint8 index = 0;
|
||||
|
||||
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_PET_AURA);
|
||||
stmt->setUInt32(index++, m_charmInfo->GetPetNumber());
|
||||
stmt->setUInt64(index++, casterGUID);
|
||||
stmt->setUInt64(index++, casterGUID.GetRawValue());
|
||||
stmt->setUInt32(index++, itr->second->GetId());
|
||||
stmt->setUInt8(index++, effMask);
|
||||
stmt->setUInt8(index++, recalculateMask);
|
||||
@@ -1802,7 +1803,7 @@ void Pet::resetTalentsForAllPetsOf(Player* owner, Pet* online_pet /*= nullptr*/)
|
||||
|
||||
// xinef: zomg! sync query
|
||||
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_CHAR_PET);
|
||||
stmt->setUInt32(0, owner->GetGUIDLow());
|
||||
stmt->setUInt32(0, owner->GetGUID().GetCounter());
|
||||
stmt->setUInt32(1, except_petnumber);
|
||||
PreparedQueryResult resultPets = CharacterDatabase.Query(stmt);
|
||||
|
||||
@@ -1812,7 +1813,7 @@ void Pet::resetTalentsForAllPetsOf(Player* owner, Pet* online_pet /*= nullptr*/)
|
||||
|
||||
// xinef: zomg! sync query
|
||||
stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_PET_SPELL_LIST);
|
||||
stmt->setUInt32(0, owner->GetGUIDLow());
|
||||
stmt->setUInt32(0, owner->GetGUID().GetCounter());
|
||||
stmt->setUInt32(1, except_petnumber);
|
||||
PreparedQueryResult result = CharacterDatabase.Query(stmt);
|
||||
|
||||
@@ -1968,15 +1969,16 @@ bool Pet::IsPermanentPetFor(Player* owner) const
|
||||
}
|
||||
}
|
||||
|
||||
bool Pet::Create(uint32 guidlow, Map* map, uint32 phaseMask, uint32 Entry, uint32 pet_number)
|
||||
bool Pet::Create(ObjectGuid::LowType guidlow, Map* map, uint32 phaseMask, uint32 Entry, uint32 pet_number)
|
||||
{
|
||||
ASSERT(map);
|
||||
SetMap(map);
|
||||
|
||||
SetPhaseMask(phaseMask, false);
|
||||
Object::_Create(guidlow, pet_number, HIGHGUID_PET);
|
||||
|
||||
m_DBTableGuid = guidlow;
|
||||
Object::_Create(guidlow, pet_number, HighGuid::Pet);
|
||||
|
||||
m_spawnId = guidlow;
|
||||
m_originalEntry = Entry;
|
||||
|
||||
if (!InitEntry(Entry))
|
||||
@@ -2184,7 +2186,7 @@ void Pet::HandleAsynchLoadFailed(AsynchPetSummon* info, Player* player, uint8 as
|
||||
|
||||
Map* map = player->GetMap();
|
||||
uint32 pet_number = sObjectMgr->GeneratePetNumber();
|
||||
if (!pet->Create(sObjectMgr->GenerateLowGuid(HIGHGUID_PET), map, player->GetPhaseMask(), info->m_entry, pet_number))
|
||||
if (!pet->Create(map->GenerateLowGuid<HighGuid::Pet>(), map, player->GetPhaseMask(), info->m_entry, pet_number))
|
||||
{
|
||||
LOG_ERROR("server", "no such creature entry %u", info->m_entry);
|
||||
delete pet;
|
||||
@@ -2247,7 +2249,7 @@ void Pet::HandleAsynchLoadFailed(AsynchPetSummon* info, Player* player, uint8 as
|
||||
// we are almost at home...
|
||||
if (asynchLoadType == PET_LOAD_SUMMON_PET)
|
||||
{
|
||||
Unit* caster = ObjectAccessor::GetObjectInMap(info->m_casterGUID, map, (Unit*)nullptr);
|
||||
Unit* caster = ObjectAccessor::GetUnit(*player, info->m_casterGUID);
|
||||
if (!caster)
|
||||
caster = player;
|
||||
|
||||
@@ -2282,7 +2284,7 @@ void Pet::HandleAsynchLoadFailed(AsynchPetSummon* info, Player* player, uint8 as
|
||||
pet->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_SKINNABLE);
|
||||
pet->setDeathState(ALIVE);
|
||||
pet->ClearUnitState(uint32(UNIT_STATE_ALL_STATE & ~(UNIT_STATE_POSSESSED))); // xinef: just in case
|
||||
pet->SetHealth(pet->CountPctFromMaxHealth(uint32(info->m_casterGUID))); // damage for this effect is saved in caster guid, dont create next variable...
|
||||
pet->SetHealth(pet->CountPctFromMaxHealth(uint32(info->m_casterGUID.GetRawValue()))); // damage for this effect is saved in caster guid, dont create next variable...
|
||||
|
||||
//AIM_Initialize();
|
||||
//owner->PetSpellInitialize();
|
||||
@@ -2338,7 +2340,7 @@ void Pet::RemoveSpellCooldown(uint32 spell_id, bool update /* = false */)
|
||||
{
|
||||
WorldPacket data(SMSG_CLEAR_COOLDOWN, 4 + 8);
|
||||
data << uint32(spell_id);
|
||||
data << uint64(GetGUID());
|
||||
data << GetGUID();
|
||||
playerOwner->SendDirectMessage(&data);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user