feat(Core/Misc): implement ObjectGuid class (port from TC) (#4885)

This commit is contained in:
UltraNix
2021-04-25 22:18:03 +02:00
committed by GitHub
parent 91081f4ad8
commit f4c226423d
568 changed files with 10655 additions and 11019 deletions

View File

@@ -213,7 +213,7 @@ public:
if (Transport* tt = chr->GetTransport())
if (MotionTransport* trans = tt->ToMotionTransport())
{
uint32 guid = sObjectMgr->GenerateRecycledLowGuid(HIGHGUID_UNIT);
ObjectGuid::LowType guid = sObjectMgr->GenerateCreatureSpawnId();
CreatureData& data = sObjectMgr->NewOrExistCreatureData(guid);
data.id = id;
data.phaseMask = chr->GetPhaseMaskForSpawn();
@@ -231,7 +231,7 @@ public:
}
Creature* creature = new Creature();
if (!creature->Create(sObjectMgr->GenerateRecycledLowGuid(HIGHGUID_UNIT), map, chr->GetPhaseMaskForSpawn(), id, 0, x, y, z, o))
if (!creature->Create(map->GenerateLowGuid<HighGuid::Unit>(), map, chr->GetPhaseMaskForSpawn(), id, 0, x, y, z, o))
{
delete creature;
return false;
@@ -239,20 +239,20 @@ public:
creature->SaveToDB(map->GetId(), (1 << map->GetSpawnMode()), chr->GetPhaseMaskForSpawn());
uint32 db_guid = creature->GetDBTableGUIDLow();
ObjectGuid::LowType spawnId = creature->GetSpawnId();
// To call _LoadGoods(); _LoadQuests(); CreateTrainerSpells()
// current "creature" variable is deleted and created fresh new, otherwise old values might trigger asserts or cause undefined behavior
creature->CleanupsBeforeDelete();
delete creature;
creature = new Creature();
if (!creature->LoadCreatureFromDB(db_guid, map))
if (!creature->LoadCreatureFromDB(spawnId, map, true, false, true))
{
delete creature;
return false;
}
sObjectMgr->AddCreatureToGrid(db_guid, sObjectMgr->GetCreatureData(db_guid));
sObjectMgr->AddCreatureToGrid(spawnId, sObjectMgr->GetCreatureData(spawnId));
return true;
}
@@ -322,22 +322,22 @@ public:
char* guidStr = strtok((char*)args, " ");
char* waitStr = strtok((char*)nullptr, " ");
uint32 lowGuid = atoi((char*)guidStr);
ObjectGuid::LowType spawnId = atoi((char*)guidStr);
Creature* creature = nullptr;
/* FIXME: impossible without entry
if (lowguid)
creature = ObjectAccessor::GetCreature(*handler->GetSession()->GetPlayer(), MAKE_GUID(lowguid, HIGHGUID_UNIT));
creature = ObjectAccessor::GetCreature(*handler->GetSession()->GetPlayer(), MAKE_GUID(lowguid, HighGuid::Unit));
*/
// attempt check creature existence by DB data
if (!creature)
{
CreatureData const* data = sObjectMgr->GetCreatureData(lowGuid);
CreatureData const* data = sObjectMgr->GetCreatureData(spawnId);
if (!data)
{
handler->PSendSysMessage(LANG_COMMAND_CREATGUIDNOTFOUND, lowGuid);
handler->PSendSysMessage(LANG_COMMAND_CREATGUIDNOTFOUND, spawnId);
handler->SetSentErrorMessage(true);
return false;
}
@@ -345,7 +345,7 @@ public:
else
{
// obtain real GUID for DB operations
lowGuid = creature->GetDBTableGUIDLow();
spawnId = creature->GetSpawnId();
}
int wait = waitStr ? atoi(waitStr) : 0;
@@ -357,7 +357,7 @@ public:
PreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_UPD_CREATURE_MOVEMENT_TYPE);
stmt->setUInt8(0, uint8(WAYPOINT_MOTION_TYPE));
stmt->setUInt32(1, lowGuid);
stmt->setUInt32(1, spawnId);
WorldDatabase.Execute(stmt);
@@ -470,12 +470,12 @@ public:
if (!cId)
return false;
uint32 lowguid = atoi(cId);
ObjectGuid::LowType lowguid = atoi(cId);
if (!lowguid)
return false;
if (CreatureData const* cr_data = sObjectMgr->GetCreatureData(lowguid))
unit = handler->GetSession()->GetPlayer()->GetMap()->GetCreature(MAKE_NEW_GUID(lowguid, cr_data->id, HIGHGUID_UNIT));
unit = handler->GetSession()->GetPlayer()->GetMap()->GetCreature(ObjectGuid::Create<HighGuid::Unit>(cr_data->id, lowguid));
}
else
unit = handler->getSelectedCreature();
@@ -729,7 +729,7 @@ public:
std::string curRespawnDelayStr = secsToTimeString(uint64(curRespawnDelay), true);
std::string defRespawnDelayStr = secsToTimeString(target->GetRespawnDelay(), true);
handler->PSendSysMessage(LANG_NPCINFO_CHAR, target->GetDBTableGUIDLow(), target->GetGUIDLow(), faction, npcflags, Entry, displayid, nativeid);
handler->PSendSysMessage(LANG_NPCINFO_CHAR, target->GetSpawnId(), target->GetGUID().GetCounter(), faction, npcflags, Entry, displayid, nativeid);
handler->PSendSysMessage(LANG_NPCINFO_LEVEL, target->getLevel());
handler->PSendSysMessage(LANG_NPCINFO_EQUIPMENT, target->GetCurrentEquipmentId(), target->GetOriginalEquipmentId());
handler->PSendSysMessage(LANG_NPCINFO_HEALTH, target->GetCreateHealth(), target->GetMaxHealth(), target->GetHealth());
@@ -778,7 +778,7 @@ public:
do
{
Field* fields = result->Fetch();
uint32 guid = fields[0].GetUInt32();
ObjectGuid::LowType guid = fields[0].GetUInt32();
uint32 entry = fields[1].GetUInt32();
float x = fields[2].GetFloat();
float y = fields[3].GetFloat();
@@ -803,7 +803,7 @@ public:
//move selected creature
static bool HandleNpcMoveCommand(ChatHandler* handler, const char* args)
{
uint32 lowguid = 0;
ObjectGuid::LowType lowguid = 0;
Creature* creature = handler->getSelectedCreature();
@@ -818,7 +818,7 @@ public:
/* FIXME: impossible without entry
if (lowguid)
creature = ObjectAccessor::GetCreature(*handler->GetSession()->GetPlayer(), MAKE_GUID(lowguid, HIGHGUID_UNIT));
creature = ObjectAccessor::GetCreature(*handler->GetSession()->GetPlayer(), MAKE_GUID(lowguid, HighGuid::Unit));
*/
// Attempting creature load from DB data
@@ -843,12 +843,12 @@ public:
}
else
{
lowguid = creature->GetDBTableGUIDLow();
lowguid = creature->GetSpawnId();
}
}
else
{
lowguid = creature->GetDBTableGUIDLow();
lowguid = creature->GetSpawnId();
}
float x = handler->GetSession()->GetPlayer()->GetPositionX();
@@ -858,7 +858,7 @@ public:
if (creature)
{
if (CreatureData const* data = sObjectMgr->GetCreatureData(creature->GetDBTableGUIDLow()))
if (CreatureData const* data = sObjectMgr->GetCreatureData(creature->GetSpawnId()))
{
const_cast<CreatureData*>(data)->posX = x;
const_cast<CreatureData*>(data)->posY = y;
@@ -971,7 +971,7 @@ public:
if (!guid_str)
return false;
uint32 lowguid = 0;
ObjectGuid::LowType lowguid = 0;
Creature* creature = nullptr;
if (dontdel_str)
@@ -1009,16 +1009,15 @@ public:
creature = handler->getSelectedCreature();
if (!creature || creature->IsPet())
return false;
lowguid = creature->GetDBTableGUIDLow();
lowguid = creature->GetSpawnId();
}
else // case .setmovetype #creature_guid $move_type (with selected creature)
{
lowguid = atoi((char*)guid_str);
/* impossible without entry
if (lowguid)
creature = ObjectAccessor::GetCreature(*handler->GetSession()->GetPlayer(), MAKE_GUID(lowguid, HIGHGUID_UNIT));
*/
creature = handler->GetCreatureFromPlayerMapByDbGuid(lowguid);
// attempt check creature existence by DB data
if (!creature)
@@ -1033,7 +1032,7 @@ public:
}
else
{
lowguid = creature->GetDBTableGUIDLow();
lowguid = creature->GetSpawnId();
}
}
@@ -1133,10 +1132,10 @@ public:
mtype = RANDOM_MOTION_TYPE;
Creature* creature = handler->getSelectedCreature();
uint32 guidLow = 0;
ObjectGuid::LowType guidLow = 0;
if (creature)
guidLow = creature->GetDBTableGUIDLow();
guidLow = creature->GetSpawnId();
else
return false;
@@ -1182,10 +1181,10 @@ public:
}
Creature* creature = handler->getSelectedCreature();
uint32 guidLow = 0;
ObjectGuid::LowType guidLow = 0;
if (creature)
guidLow = creature->GetDBTableGUIDLow();
guidLow = creature->GetSpawnId();
else
return false;
@@ -1305,11 +1304,11 @@ public:
if (!creature || !receiver_str || !text)
return false;
uint64 receiver_guid = atol(receiver_str);
ObjectGuid receiver_guid = ObjectGuid::Create<HighGuid::Player>(atol(receiver_str));
// check online security
Player* receiver = ObjectAccessor::FindPlayer(receiver_guid);
if (handler->HasLowerSecurity(receiver, 0))
if (handler->HasLowerSecurity(receiver, ObjectGuid::Empty))
return false;
creature->MonsterWhisper(text, receiver);
@@ -1430,17 +1429,17 @@ public:
if (!*args)
return false;
uint32 leaderGUID = (uint32) atoi((char*)args);
ObjectGuid::LowType leaderGUID = (uint32) atoi((char*)args);
Creature* creature = handler->getSelectedCreature();
if (!creature || !creature->GetDBTableGUIDLow())
if (!creature || !creature->GetSpawnId())
{
handler->SendSysMessage(LANG_SELECT_CREATURE);
handler->SetSentErrorMessage(true);
return false;
}
uint32 lowguid = creature->GetDBTableGUIDLow();
ObjectGuid::LowType lowguid = creature->GetSpawnId();
if (creature->GetFormation())
{
handler->PSendSysMessage("Selected creature is already member of group %u", creature->GetFormation()->GetId());
@@ -1482,7 +1481,7 @@ public:
if (!*args)
return false;
uint32 linkguid = (uint32) atoi((char*)args);
ObjectGuid::LowType linkguid = (uint32) atoi((char*)args);
Creature* creature = handler->getSelectedCreature();
@@ -1493,21 +1492,21 @@ public:
return false;
}
if (!creature->GetDBTableGUIDLow())
if (!creature->GetSpawnId())
{
handler->PSendSysMessage("Selected creature %u isn't in creature table", creature->GetGUIDLow());
handler->PSendSysMessage("Selected creature %s isn't in creature table", creature->GetGUID().ToString().c_str());
handler->SetSentErrorMessage(true);
return false;
}
if (!sObjectMgr->SetCreatureLinkedRespawn(creature->GetDBTableGUIDLow(), linkguid))
if (!sObjectMgr->SetCreatureLinkedRespawn(creature->GetSpawnId(), linkguid))
{
handler->PSendSysMessage("Selected creature can't link with guid '%u'", linkguid);
handler->SetSentErrorMessage(true);
return false;
}
handler->PSendSysMessage("LinkGUID '%u' added to creature with DBTableGUID: '%u'", linkguid, creature->GetDBTableGUIDLow());
handler->PSendSysMessage("LinkGUID '%u' added to creature with SpawnId: '%u'", linkguid, creature->GetSpawnId());
return true;
}
@@ -1517,7 +1516,7 @@ public:
/*if (!*args)
return false;
uint64 guid = handler->GetSession()->GetPlayer()->GetSelection();
ObjectGuid guid = handler->GetSession()->GetPlayer()->GetSelection();
if (guid == 0)
{
handler->SendSysMessage(LANG_NO_SELECTION);
@@ -1601,7 +1600,7 @@ public:
}
}
uint64 guid;
ObjectGuid guid;
guid = handler->GetSession()->GetPlayer()->GetSelection();
if (guid == 0)
{
@@ -1648,7 +1647,7 @@ public:
return false;
}
}
uint64 guid;
ObjectGuid guid;
guid = handler->GetSession()->GetPlayer()->GetSelection();
if (guid == 0)
{