Implemented ObjectGuid support for AzerothCore.

This commit is contained in:
UltraNix
2021-04-21 19:55:37 +02:00
parent ca5f1bb59d
commit c4383324fb
19 changed files with 206 additions and 181 deletions

View File

@@ -124,13 +124,13 @@ namespace LuaGlobalFunctions
/**
* Finds and Returns [Player] by guid if found
*
* @param uint64 guid : guid of the [Player], you can get it with [Object:GetGUID]
* @param ObjectGuid guid : guid of the [Player], you can get it with [Object:GetGUID]
* @return [Player] player
*/
int GetPlayerByGUID(lua_State* L)
{
uint64 guid = Eluna::CHECKVAL<uint64>(L, 1);
Eluna::Push(L, eObjectAccessor()FindPlayer(ObjectGuid(guid)));
ObjectGuid guid = Eluna::CHECKVAL<ObjectGuid>(L, 1);
Eluna::Push(L, eObjectAccessor()FindPlayer(guid));
return 1;
}
@@ -261,14 +261,14 @@ namespace LuaGlobalFunctions
/**
* Returns [Guild] by the leader's GUID
*
* @param uint64 guid : the guid of a [Guild] leader
* @param ObjectGuid guid : the guid of a [Guild] leader
* @return [Guild] guild, or `nil` if it doesn't exist
*/
int GetGuildByLeaderGUID(lua_State* L)
{
uint64 guid = Eluna::CHECKVAL<uint64>(L, 1);
ObjectGuid guid = Eluna::CHECKVAL<ObjectGuid>(L, 1);
Eluna::Push(L, eGuildMgr->GetGuildByLeader(ObjectGuid(guid)));
Eluna::Push(L, eGuildMgr->GetGuildByLeader(guid));
return 1;
}
@@ -291,7 +291,7 @@ namespace LuaGlobalFunctions
* [Player] and [Creature] for example can have the same low GUID but not GUID.
*
* @param uint32 lowguid : low GUID of the [Player]
* @return uint64 guid
* @return ObjectGuid guid
*/
int GetPlayerGUID(lua_State* L)
{
@@ -307,7 +307,7 @@ namespace LuaGlobalFunctions
* [Player] and [Item] for example can have the same low GUID but not GUID.
*
* @param uint32 lowguid : low GUID of the [Item]
* @return uint64 guid
* @return ObjectGuid guid
*/
int GetItemGUID(lua_State* L)
{
@@ -325,7 +325,7 @@ namespace LuaGlobalFunctions
*
* @param uint32 lowguid : low GUID of the [GameObject]
* @param uint32 entry : entry ID of the [GameObject]
* @return uint64 guid
* @return ObjectGuid guid
*/
int GetObjectGUID(lua_State* L)
{
@@ -344,7 +344,7 @@ namespace LuaGlobalFunctions
*
* @param uint32 lowguid : low GUID of the [Creature]
* @param uint32 entry : entry ID of the [Creature]
* @return uint64 guid
* @return ObjectGuid guid
*/
int GetUnitGUID(lua_State* L)
{
@@ -370,14 +370,14 @@ namespace LuaGlobalFunctions
* For example creatures in instances use the same low GUID assigned for that spawn in the database.
* This is why to identify a creature you have to know the instanceId and low GUID. See [Map:GetIntstanceId]
*
* @param uint64 guid : GUID of an [Object]
* @param ObjectGuid guid : GUID of an [Object]
* @return uint32 lowguid : low GUID of the [Object]
*/
int GetGUIDLow(lua_State* L)
{
uint64 guid = Eluna::CHECKVAL<uint64>(L, 1);
ObjectGuid guid = Eluna::CHECKVAL<ObjectGuid>(L, 1);
Eluna::Push(L, GUID_LOPART(guid));
Eluna::Push(L, guid.GetCounter());
return 1;
}
@@ -435,13 +435,13 @@ namespace LuaGlobalFunctions
*
* GUID consist of entry ID, low GUID, and type ID.
*
* @param uint64 guid : GUID of an [Object]
* @param ObjectGuid guid : GUID of an [Object]
* @return int32 typeId : type ID of the [Object]
*/
int GetGUIDType(lua_State* L)
{
uint64 guid = Eluna::CHECKVAL<uint64>(L, 1);
Eluna::Push(L, static_cast<int>(GUID_HIPART(guid)));
ObjectGuid guid = Eluna::CHECKVAL<ObjectGuid>(L, 1);
Eluna::Push(L, static_cast<int>(guid.GetHigh()));
return 1;
}
@@ -450,13 +450,13 @@ namespace LuaGlobalFunctions
*
* GUID consist of entry ID, low GUID, and type ID.
*
* @param uint64 guid : GUID of an [Creature] or [GameObject]
* @param ObjectGuid guid : GUID of an [Creature] or [GameObject]
* @return uint32 entry : entry ID, or `0` if `guid` is not a [Creature] or [GameObject]
*/
int GetGUIDEntry(lua_State* L)
{
uint64 guid = Eluna::CHECKVAL<uint64>(L, 1);
Eluna::Push(L, GUID_ENPART(guid));
ObjectGuid guid = Eluna::CHECKVAL<ObjectGuid>(L, 1);
Eluna::Push(L, guid.GetEntry());
return 1;
}
@@ -537,7 +537,7 @@ namespace LuaGlobalFunctions
lua_pushvalue(L, 3);
int functionRef = luaL_ref(L, LUA_REGISTRYINDEX);
if (functionRef >= 0)
return Eluna::GetEluna(L)->Register(L, regtype, id, 0, 0, ev, functionRef, shots);
return Eluna::GetEluna(L)->Register(L, regtype, id, ObjectGuid(), 0, ev, functionRef, shots);
else
luaL_argerror(L, 3, "unable to make a ref to function");
return 0;
@@ -552,7 +552,7 @@ namespace LuaGlobalFunctions
lua_pushvalue(L, 2);
int functionRef = luaL_ref(L, LUA_REGISTRYINDEX);
if (functionRef >= 0)
return Eluna::GetEluna(L)->Register(L, regtype, 0, 0, 0, ev, functionRef, shots);
return Eluna::GetEluna(L)->Register(L, regtype, 0, ObjectGuid(), 0, ev, functionRef, shots);
else
luaL_argerror(L, 2, "unable to make a ref to function");
return 0;
@@ -560,7 +560,7 @@ namespace LuaGlobalFunctions
static int RegisterUniqueHelper(lua_State* L, int regtype)
{
uint64 guid = Eluna::CHECKVAL<uint64>(L, 1);
ObjectGuid guid = Eluna::CHECKVAL<ObjectGuid>(L, 1);
uint32 instanceId = Eluna::CHECKVAL<uint32>(L, 2);
uint32 ev = Eluna::CHECKVAL<uint32>(L, 3);
luaL_checktype(L, 4, LUA_TFUNCTION);
@@ -1149,7 +1149,7 @@ namespace LuaGlobalFunctions
* @proto cancel = (guid, instance_id, event, function)
* @proto cancel = (guid, instance_id, event, function, shots)
*
* @param uint64 guid : the GUID of a single [Creature]
* @param ObjectGuid guid : the GUID of a single [Creature]
* @param uint32 instance_id : the instance ID of a single [Creature]
* @param uint32 event : refer to CreatureEvents above
* @param function function : function that will be called when the event occurs
@@ -1708,7 +1708,7 @@ namespace LuaGlobalFunctions
#ifndef AZEROTHCORE
if (!creature->Create(map->GenerateLowGuid<HighGuid::Unit>(), map, phase, entry, pos))
#else
if (!creature->Create(sObjectMgr->GenerateLowGuid(HIGHGUID_UNIT), map, phase, entry, 0, x, y, z, o))
if (!creature->Create(map->GenerateLowGuid<HighGuid::Unit>(), map, phase, entry, 0, x, y, z, o))
#endif
{
delete creature;
@@ -1718,11 +1718,8 @@ namespace LuaGlobalFunctions
creature->SaveToDB(map->GetId(), (1 << map->GetSpawnMode()), phase);
#ifndef AZEROTHCORE
uint32 db_guid = creature->GetSpawnId();
#else
uint32 db_guid = creature->GetDBTableGUIDLow();
#endif
// 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();
@@ -1731,7 +1728,7 @@ namespace LuaGlobalFunctions
#ifndef AZEROTHCORE
if (!creature->LoadFromDB(db_guid, map, true, true))
#else
if (!creature->LoadFromDB(db_guid, map))
if (!creature->LoadFromDB(db_guid, map, true))
#endif
{
delete creature;
@@ -1783,7 +1780,7 @@ namespace LuaGlobalFunctions
QuaternionData rot = QuaternionData::fromEulerAnglesZYX(o, 0.f, 0.f);
if (!object->Create(guidLow, objectInfo->entry, map, phase, Position(x, y, z, o), rot, 0, GO_STATE_READY))
#else
uint32 guidLow = sObjectMgr->GenerateLowGuid(HIGHGUID_GAMEOBJECT);
uint32 guidLow = map->GenerateLowGuid<HighGuid::GameObject>();
if (!object->Create(guidLow, entry, map, phase, x, y, z, o, G3D::Quat(0.0f, 0.0f, 0.0f, 0.0f), 100, GO_STATE_READY))
#endif
{
@@ -1799,11 +1796,7 @@ namespace LuaGlobalFunctions
{
// fill the gameobject data and save to the db
object->SaveToDB(map->GetId(), (1 << map->GetSpawnMode()), phase);
#ifndef AZEROTHCORE
guidLow = object->GetSpawnId();
#else
guidLow = object->GetDBTableGUIDLow();
#endif
// delete the old object and do a clean load from DB with a fresh new GameObject instance.
// this is required to avoid weird behavior and memory leaks
@@ -2157,7 +2150,7 @@ namespace LuaGlobalFunctions
item->SaveToDB();
#endif
draft.AddItem(item);
#if defined TRINITY
#if defined TRINITY || AZEROTHCORE
Eluna::Push(L, item->GetGUID().GetCounter());
#else
Eluna::Push(L, item->GetGUIDLow());
@@ -2768,7 +2761,7 @@ namespace LuaGlobalFunctions
*
* @proto (entry)
* @proto (entry, event_type)
* @param uint64 guid : the GUID of a single [Creature] whose handlers will be cleared
* @param ObjectGuid guid : the GUID of a single [Creature] whose handlers will be cleared
* @param uint32 instance_id : the instance ID of a single [Creature] whose handlers will be cleared
* @param uint32 event_type : the event whose handlers will be cleared, see [Global:RegisterCreatureEvent]
*/
@@ -2778,7 +2771,7 @@ namespace LuaGlobalFunctions
if (lua_isnoneornil(L, 3))
{
uint64 guid = Eluna::CHECKVAL<uint64>(L, 1);
ObjectGuid guid = Eluna::CHECKVAL<ObjectGuid>(L, 1);
uint32 instanceId = Eluna::CHECKVAL<uint32>(L, 2);
Eluna* E = Eluna::GetEluna(L);
@@ -2787,7 +2780,7 @@ namespace LuaGlobalFunctions
}
else
{
uint64 guid = Eluna::CHECKVAL<uint64>(L, 1);
ObjectGuid guid = Eluna::CHECKVAL<ObjectGuid>(L, 1);
uint32 instanceId = Eluna::CHECKVAL<uint32>(L, 2);
uint32 event_type = Eluna::CHECKVAL<uint32>(L, 3);
Eluna::GetEluna(L)->CreatureUniqueBindings->Clear(Key((Hooks::CreatureEvents)event_type, guid, instanceId));