mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-15 23:20:36 +01:00
Core/Globals: add more AIName and MovementType checks to ObjectMgr
- Ninja fix AI factories (restores prev behaviour of not selecting stuff with PERMIT_BASE_NO) Closes #19831
This commit is contained in:
@@ -29,6 +29,13 @@
|
||||
|
||||
namespace FactorySelector
|
||||
{
|
||||
template <class T, class Value>
|
||||
inline int32 GetPermitFor(T const* obj, Value const& value)
|
||||
{
|
||||
Permissible<T> const* const p = ASSERT_NOTNULL(dynamic_cast<Permissible<T> const*>(value.second.get()));
|
||||
return p->Permit(obj);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
struct PermissibleOrderPred
|
||||
{
|
||||
@@ -38,10 +45,7 @@ namespace FactorySelector
|
||||
template <class Value>
|
||||
bool operator()(Value const& left, Value const& right) const
|
||||
{
|
||||
Permissible<T> const* leftPermit = ASSERT_NOTNULL(dynamic_cast<Permissible<T> const*>(left.second.get()));
|
||||
Permissible<T> const* rightPermit = ASSERT_NOTNULL(dynamic_cast<Permissible<T> const*>(right.second.get()));
|
||||
|
||||
return leftPermit->Permit(_obj) < rightPermit->Permit(_obj);
|
||||
return GetPermitFor(_obj, left) < GetPermitFor(_obj, right);
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -53,9 +57,8 @@ namespace FactorySelector
|
||||
CreatureAICreator const* ai_factory = nullptr;
|
||||
|
||||
// scriptname in db
|
||||
if (!ai_factory)
|
||||
if (CreatureAI* scriptedAI = sScriptMgr->GetCreatureAI(creature))
|
||||
return scriptedAI;
|
||||
if (CreatureAI* scriptedAI = sScriptMgr->GetCreatureAI(creature))
|
||||
return scriptedAI;
|
||||
|
||||
// AIname in db
|
||||
std::string const& aiName = creature->GetAIName();
|
||||
@@ -67,7 +70,7 @@ namespace FactorySelector
|
||||
{
|
||||
CreatureAIRegistry::RegistryMapType const& items = sCreatureAIRegistry->GetRegisteredItems();
|
||||
auto itr = std::max_element(items.begin(), items.end(), PermissibleOrderPred<Creature>(creature));
|
||||
if (itr != items.end())
|
||||
if (itr != items.end() && GetPermitFor(creature, *itr) >= 0)
|
||||
ai_factory = itr->second.get();
|
||||
}
|
||||
|
||||
@@ -105,7 +108,7 @@ namespace FactorySelector
|
||||
{
|
||||
GameObjectAIRegistry::RegistryMapType const& items = sGameObjectAIRegistry->GetRegisteredItems();
|
||||
auto itr = std::max_element(items.begin(), items.end(), PermissibleOrderPred<GameObject>(go));
|
||||
if (itr != items.end())
|
||||
if (itr != items.end() && GetPermitFor(go, *itr) >= 0)
|
||||
ai_factory = itr->second.get();
|
||||
}
|
||||
|
||||
|
||||
@@ -23,8 +23,10 @@
|
||||
#include "BattlegroundMgr.h"
|
||||
#include "Chat.h"
|
||||
#include "Common.h"
|
||||
#include "CreatureAIFactory.h"
|
||||
#include "DatabaseEnv.h"
|
||||
#include "DisableMgr.h"
|
||||
#include "GameObjectAIFactory.h"
|
||||
#include "GossipDef.h"
|
||||
#include "GroupMgr.h"
|
||||
#include "GuildMgr.h"
|
||||
@@ -802,6 +804,12 @@ void ObjectMgr::CheckCreatureTemplate(CreatureTemplate const* cInfo)
|
||||
ok = true;
|
||||
}
|
||||
|
||||
if (!cInfo->AIName.empty() && !sCreatureAIRegistry->HasItem(cInfo->AIName))
|
||||
{
|
||||
TC_LOG_ERROR("sql.sql", "Creature (Entry: %u) has non-registered `AIName` '%s' set, removing", cInfo->Entry, cInfo->AIName.c_str());
|
||||
const_cast<CreatureTemplate*>(cInfo)->AIName.clear();
|
||||
}
|
||||
|
||||
FactionTemplateEntry const* factionTemplate = sFactionTemplateStore.LookupEntry(cInfo->faction);
|
||||
if (!factionTemplate)
|
||||
{
|
||||
@@ -1834,6 +1842,12 @@ void ObjectMgr::LoadCreatures()
|
||||
TC_LOG_ERROR("sql.sql", "Table `creature` has creature (GUID: %u Entry: %u) with `creature_template`.`flags_extra` including CREATURE_FLAG_EXTRA_INSTANCE_BIND but creature is not in instance.", guid, data.id);
|
||||
}
|
||||
|
||||
if (data.movementType >= MAX_DB_MOTION_TYPE)
|
||||
{
|
||||
TC_LOG_ERROR("sql.sql", "Table `creature` has creature (GUID: %u Entry: %u) with wrong movement generator type (%u), ignored and set to IDLE.", guid, data.id, data.movementType);
|
||||
data.movementType = IDLE_MOTION_TYPE;
|
||||
}
|
||||
|
||||
if (data.spawndist < 0.0f)
|
||||
{
|
||||
TC_LOG_ERROR("sql.sql", "Table `creature` has creature (GUID: %u Entry: %u) with `spawndist`< 0, set to 0.", guid, data.id);
|
||||
@@ -6688,6 +6702,11 @@ void ObjectMgr::LoadGameObjectTemplate()
|
||||
got.ScriptId = GetScriptId(fields[33].GetString());
|
||||
|
||||
// Checks
|
||||
if (!got.AIName.empty() && !sGameObjectAIRegistry->HasItem(got.AIName))
|
||||
{
|
||||
TC_LOG_ERROR("sql.sql", "GameObject (Entry: %u) has non-registered `AIName` '%s' set, removing", got.entry, got.AIName.c_str());
|
||||
got.AIName.clear();
|
||||
}
|
||||
|
||||
switch (got.type)
|
||||
{
|
||||
|
||||
@@ -1437,6 +1437,9 @@ void World::SetInitialWorldSettings()
|
||||
TC_LOG_INFO("server.loading", "Initializing PlayerDump tables...");
|
||||
PlayerDump::InitializeTables();
|
||||
|
||||
///- Initialize static helper structures
|
||||
AIRegistry::Initialize();
|
||||
|
||||
TC_LOG_INFO("server.loading", "Loading SpellInfo store...");
|
||||
sSpellMgr->LoadSpellInfoStore();
|
||||
|
||||
@@ -1899,9 +1902,6 @@ void World::SetInitialWorldSettings()
|
||||
mail_timer_expires = ((DAY * IN_MILLISECONDS) / (m_timers[WUPDATE_AUCTIONS].GetInterval()));
|
||||
TC_LOG_INFO("server.loading", "Mail timer set to: " UI64FMTD ", mail return is called every " UI64FMTD " minutes", uint64(mail_timer), uint64(mail_timer_expires));
|
||||
|
||||
///- Initilize static helper structures
|
||||
AIRegistry::Initialize();
|
||||
|
||||
///- Initialize MapManager
|
||||
TC_LOG_INFO("server.loading", "Starting Map System");
|
||||
sMapMgr->Initialize();
|
||||
|
||||
@@ -33,7 +33,6 @@ class FactoryHolder
|
||||
|
||||
explicit FactoryHolder(Key const& k) : _key(k) { }
|
||||
virtual ~FactoryHolder() { }
|
||||
inline Key GetKey() const { return _key; }
|
||||
|
||||
void RegisterSelf() { FactoryHolderRegistry::instance()->InsertItem(this, _key); }
|
||||
|
||||
|
||||
@@ -64,6 +64,12 @@ class ObjectRegistry final
|
||||
return true;
|
||||
}
|
||||
|
||||
/// Returns true if registry contains an item
|
||||
bool HasItem(Key const& key) const
|
||||
{
|
||||
return (_registeredObjects.count(key) > 0);
|
||||
}
|
||||
|
||||
/// Return the map of registered items
|
||||
RegistryMapType const& GetRegisteredItems() const
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user