Core/AI: Added a way to specify if certain AI types mustn't be allowed on DB

Ref 072c884ed8
Ref 2c7e921cdc
This commit is contained in:
ariel-
2017-12-28 12:12:58 -03:00
parent 465b43fabe
commit a998bba5c2
5 changed files with 67 additions and 35 deletions

View File

@@ -20,22 +20,15 @@
#define TRINITY_CREATUREAIFACTORY_H
#include "ObjectRegistry.h"
#include "FactoryHolder.h"
#include "SelectableAI.h"
class Creature;
class CreatureAI;
typedef FactoryHolder<CreatureAI, Creature> CreatureAICreator;
struct SelectableAI : public CreatureAICreator, public Permissible<Creature>
template <class REAL_AI, bool is_db_allowed = true>
struct CreatureAIFactory : public SelectableAI<Creature, CreatureAI, is_db_allowed>
{
SelectableAI(std::string const& name) : CreatureAICreator(name), Permissible<Creature>() { }
};
template<class REAL_AI>
struct CreatureAIFactory : public SelectableAI
{
CreatureAIFactory(std::string const& name) : SelectableAI(name) { }
CreatureAIFactory(std::string const& name) : SelectableAI<Creature, CreatureAI, is_db_allowed>(name) { }
inline CreatureAI* Create(Creature* c) const override
{
@@ -48,7 +41,7 @@ struct CreatureAIFactory : public SelectableAI
}
};
typedef CreatureAICreator::FactoryHolderRegistry CreatureAIRegistry;
typedef SelectableAI<Creature, CreatureAI>::FactoryHolderRegistry CreatureAIRegistry;
#define sCreatureAIRegistry CreatureAIRegistry::instance()

View File

@@ -42,8 +42,8 @@ namespace AIRegistry
(new CreatureAIFactory<PassiveAI>("PassiveAI"))->RegisterSelf();
(new CreatureAIFactory<CritterAI>("CritterAI"))->RegisterSelf();
(new CreatureAIFactory<GuardAI>("GuardAI"))->RegisterSelf();
(new CreatureAIFactory<PetAI>("PetAI"))->RegisterSelf();
(new CreatureAIFactory<TotemAI>("TotemAI"))->RegisterSelf();
(new CreatureAIFactory<PetAI, false>("PetAI"))->RegisterSelf();
(new CreatureAIFactory<TotemAI, false>("TotemAI"))->RegisterSelf();
(new CreatureAIFactory<CombatAI>("CombatAI"))->RegisterSelf();
(new CreatureAIFactory<ArcherAI>("ArcherAI"))->RegisterSelf();
(new CreatureAIFactory<TurretAI>("TurretAI"))->RegisterSelf();

View File

@@ -19,22 +19,15 @@
#define TRINITY_GAMEOBJECTAIFACTORY_H
#include "ObjectRegistry.h"
#include "FactoryHolder.h"
#include "SelectableAI.h"
class GameObject;
class GameObjectAI;
typedef FactoryHolder<GameObjectAI, GameObject> GameObjectAICreator;
struct SelectableGameObjectAI : public GameObjectAICreator, public Permissible<GameObject>
template <class REAL_GO_AI, bool is_db_allowed = true>
struct GameObjectAIFactory : public SelectableAI<GameObject, GameObjectAI, is_db_allowed>
{
SelectableGameObjectAI(std::string const& name) : GameObjectAICreator(name), Permissible<GameObject>() { }
};
template<class REAL_GO_AI>
struct GameObjectAIFactory : public SelectableGameObjectAI
{
GameObjectAIFactory(std::string const& name) : SelectableGameObjectAI(name) { }
GameObjectAIFactory(std::string const& name) : SelectableAI<GameObject, GameObjectAI, is_db_allowed>(name) { }
GameObjectAI* Create(GameObject* go) const override
{
@@ -47,7 +40,7 @@ struct GameObjectAIFactory : public SelectableGameObjectAI
}
};
typedef GameObjectAICreator::FactoryHolderRegistry GameObjectAIRegistry;
typedef SelectableAI<GameObject, GameObjectAI>::FactoryHolderRegistry GameObjectAIRegistry;
#define sGameObjectAIRegistry GameObjectAIRegistry::instance()

View File

@@ -0,0 +1,39 @@
/*
* Copyright (C) 2008-2017 TrinityCore <http://www.trinitycore.org/>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#ifndef SelectableAI_h__
#define SelectableAI_h__
#include "FactoryHolder.h"
class DBPermit
{
public:
virtual ~DBPermit() { }
virtual bool IsScriptNameAllowedInDB() const = 0;
};
template <class O, class AI, bool is_db_allowed = true>
struct SelectableAI : public FactoryHolder<AI, O>, public Permissible<O>, public DBPermit
{
SelectableAI(std::string const& name) : FactoryHolder<AI, O>(name), Permissible<O>(), DBPermit() { }
bool IsScriptNameAllowedInDB() const final override { return is_db_allowed; }
};
#endif // SelectableAI_h__

View File

@@ -817,16 +817,23 @@ void ObjectMgr::CheckCreatureTemplate(CreatureTemplate const* cInfo)
const_cast<CreatureTemplate*>(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<CreatureTemplate*>(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<CreatureTemplate*>(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<CreatureTemplate*>(cInfo)->AIName.clear();
}
else
{
DBPermit const* permit = dynamic_cast<DBPermit const*>(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<CreatureTemplate*>(cInfo)->AIName.clear();
}
}
}
FactionTemplateEntry const* factionTemplate = sFactionTemplateStore.LookupEntry(cInfo->faction);