fixes for arena I've been working on with Dave (most credit belongs to him I feel)

This commit is contained in:
Fuzz
2024-07-04 14:08:21 +10:00
parent 6dddab7c1a
commit 08cbe2f4ec
3 changed files with 40 additions and 9 deletions

View File

@@ -1808,6 +1808,16 @@ Player* PlayerbotAI::GetPlayer(ObjectGuid guid)
return unit ? unit->ToPlayer() : nullptr;
}
uint32 GetCreatureIdForCreatureTemplateId(uint32 creatureTemplateId)
{
QueryResult results = WorldDatabase.Query("SELECT guid FROM `acore_world`.`creature` WHERE id1 = {} LIMIT 1;", creatureTemplateId);
if (results) {
Field* fields = results->Fetch();
return fields[0].Get<uint32>();
}
return 0;
}
Unit* PlayerbotAI::GetUnit(CreatureData const* creatureData)
{
if (!creatureData)
@@ -1817,7 +1827,10 @@ Unit* PlayerbotAI::GetUnit(CreatureData const* creatureData)
if (!map)
return nullptr;
auto creatureBounds = map->GetCreatureBySpawnIdStore().equal_range(creatureData->spawnId);
uint32 spawnId = creatureData->spawnId;
if (!spawnId) // workaround for CreatureData with missing spawnId (this just uses first matching creatureId in DB, but thats ok this method is only used for battlemasters and theres only 1 of each type)
spawnId = GetCreatureIdForCreatureTemplateId(creatureData->id1);
auto creatureBounds = map->GetCreatureBySpawnIdStore().equal_range(spawnId);
if (creatureBounds.first == creatureBounds.second)
return nullptr;