From 523dab764b0b3ebe76f957115e976b36fb79987e Mon Sep 17 00:00:00 2001 From: ariel- Date: Thu, 28 Dec 2017 12:12:58 -0300 Subject: Core/AI: Added a way to specify if certain AI types mustn't be allowed on DB Ref 072c884ed86a9bf895cd5f53b0f6480ae14c3059 Ref 2c7e921cdc14527bd99d6976793e69999f262f9d (cherry picked from commit a998bba5c239d6bae8426b989ec96475efb969ae) --- src/server/game/AI/CreatureAIFactory.h | 17 ++++---------- src/server/game/AI/CreatureAIRegistry.cpp | 4 ++-- src/server/game/AI/GameObjectAIFactory.h | 17 ++++---------- src/server/game/AI/SelectableAI.h | 39 +++++++++++++++++++++++++++++++ src/server/game/Globals/ObjectMgr.cpp | 25 +++++++++++++------- 5 files changed, 67 insertions(+), 35 deletions(-) create mode 100644 src/server/game/AI/SelectableAI.h (limited to 'src') diff --git a/src/server/game/AI/CreatureAIFactory.h b/src/server/game/AI/CreatureAIFactory.h index 70de867e8e8..d8d9c5ea828 100644 --- a/src/server/game/AI/CreatureAIFactory.h +++ b/src/server/game/AI/CreatureAIFactory.h @@ -19,22 +19,15 @@ #define TRINITY_CREATUREAIFACTORY_H #include "ObjectRegistry.h" -#include "FactoryHolder.h" +#include "SelectableAI.h" class Creature; class CreatureAI; -typedef FactoryHolder CreatureAICreator; - -struct SelectableAI : public CreatureAICreator, public Permissible -{ - SelectableAI(std::string const& name) : CreatureAICreator(name), Permissible() { } -}; - -template -struct CreatureAIFactory : public SelectableAI +template +struct CreatureAIFactory : public SelectableAI { - CreatureAIFactory(std::string const& name) : SelectableAI(name) { } + CreatureAIFactory(std::string const& name) : SelectableAI(name) { } inline CreatureAI* Create(Creature* c) const override { @@ -47,7 +40,7 @@ struct CreatureAIFactory : public SelectableAI } }; -typedef CreatureAICreator::FactoryHolderRegistry CreatureAIRegistry; +typedef SelectableAI::FactoryHolderRegistry CreatureAIRegistry; #define sCreatureAIRegistry CreatureAIRegistry::instance() diff --git a/src/server/game/AI/CreatureAIRegistry.cpp b/src/server/game/AI/CreatureAIRegistry.cpp index 35ba2a56be6..10a06384f49 100644 --- a/src/server/game/AI/CreatureAIRegistry.cpp +++ b/src/server/game/AI/CreatureAIRegistry.cpp @@ -41,8 +41,8 @@ namespace AIRegistry (new CreatureAIFactory("PassiveAI"))->RegisterSelf(); (new CreatureAIFactory("CritterAI"))->RegisterSelf(); (new CreatureAIFactory("GuardAI"))->RegisterSelf(); - (new CreatureAIFactory("PetAI"))->RegisterSelf(); - (new CreatureAIFactory("TotemAI"))->RegisterSelf(); + (new CreatureAIFactory("PetAI"))->RegisterSelf(); + (new CreatureAIFactory("TotemAI"))->RegisterSelf(); (new CreatureAIFactory("CombatAI"))->RegisterSelf(); (new CreatureAIFactory("ArcherAI"))->RegisterSelf(); (new CreatureAIFactory("TurretAI"))->RegisterSelf(); diff --git a/src/server/game/AI/GameObjectAIFactory.h b/src/server/game/AI/GameObjectAIFactory.h index 88dcb5cbb81..99d3214b5de 100644 --- a/src/server/game/AI/GameObjectAIFactory.h +++ b/src/server/game/AI/GameObjectAIFactory.h @@ -19,22 +19,15 @@ #define TRINITY_GAMEOBJECTAIFACTORY_H #include "ObjectRegistry.h" -#include "FactoryHolder.h" +#include "SelectableAI.h" class GameObject; class GameObjectAI; -typedef FactoryHolder GameObjectAICreator; - -struct SelectableGameObjectAI : public GameObjectAICreator, public Permissible -{ - SelectableGameObjectAI(std::string const& name) : GameObjectAICreator(name), Permissible() { } -}; - -template -struct GameObjectAIFactory : public SelectableGameObjectAI +template +struct GameObjectAIFactory : public SelectableAI { - GameObjectAIFactory(std::string const& name) : SelectableGameObjectAI(name) { } + GameObjectAIFactory(std::string const& name) : SelectableAI(name) { } GameObjectAI* Create(GameObject* go) const override { @@ -47,7 +40,7 @@ struct GameObjectAIFactory : public SelectableGameObjectAI } }; -typedef GameObjectAICreator::FactoryHolderRegistry GameObjectAIRegistry; +typedef SelectableAI::FactoryHolderRegistry GameObjectAIRegistry; #define sGameObjectAIRegistry GameObjectAIRegistry::instance() diff --git a/src/server/game/AI/SelectableAI.h b/src/server/game/AI/SelectableAI.h new file mode 100644 index 00000000000..7b28049ffd5 --- /dev/null +++ b/src/server/game/AI/SelectableAI.h @@ -0,0 +1,39 @@ +/* + * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +#ifndef SelectableAI_h__ +#define SelectableAI_h__ + +#include "FactoryHolder.h" + +class DBPermit +{ + public: + virtual ~DBPermit() { } + virtual bool IsScriptNameAllowedInDB() const = 0; +}; + +template +struct SelectableAI : public FactoryHolder, public Permissible, public DBPermit +{ + SelectableAI(std::string const& name) : FactoryHolder(name), Permissible(), DBPermit() { } + + bool IsScriptNameAllowedInDB() const final override { return is_db_allowed; } +}; + + +#endif // SelectableAI_h__ diff --git a/src/server/game/Globals/ObjectMgr.cpp b/src/server/game/Globals/ObjectMgr.cpp index 387910ee1e0..12f14c6bbcb 100644 --- a/src/server/game/Globals/ObjectMgr.cpp +++ b/src/server/game/Globals/ObjectMgr.cpp @@ -946,16 +946,23 @@ void ObjectMgr::CheckCreatureTemplate(CreatureTemplate const* cInfo) const_cast(cInfo)->maxgold = cInfo->mingold; } - if (cInfo->AIName == "TotemAI" || cInfo->AIName == "PetAI") + if (!cInfo->AIName.empty()) { - TC_LOG_ERROR("sql.sql", "Creature (Entry: %u) has not-allowed `AIName` '%s' set, removing", cInfo->Entry, cInfo->AIName.c_str()); - const_cast(cInfo)->AIName.clear(); - } - - 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(cInfo)->AIName.clear(); + auto registryItem = sCreatureAIRegistry->GetRegistryItem(cInfo->AIName); + if (!registryItem) + { + TC_LOG_ERROR("sql.sql", "Creature (Entry: %u) has non-registered `AIName` '%s' set, removing", cInfo->Entry, cInfo->AIName.c_str()); + const_cast(cInfo)->AIName.clear(); + } + else + { + DBPermit const* permit = dynamic_cast(registryItem); + if (!ASSERT_NOTNULL(permit)->IsScriptNameAllowedInDB()) + { + TC_LOG_ERROR("sql.sql", "Creature (Entry: %u) has not-allowed `AIName` '%s' set, removing", cInfo->Entry, cInfo->AIName.c_str()); + const_cast(cInfo)->AIName.clear(); + } + } } FactionTemplateEntry const* factionTemplate = sFactionTemplateStore.LookupEntry(cInfo->faction); -- cgit v1.2.3