Core/Scripts: Added support for creating custom GameObjectAI classes, similar to how creature scripts work.

This commit is contained in:
Shauren
2012-04-14 17:49:51 +02:00
parent ab8e69873c
commit a3bdaf7e6d
4 changed files with 16 additions and 1 deletions

View File

@@ -133,6 +133,9 @@ namespace FactorySelector
const GameObjectAICreator* ai_factory = NULL;
GameObjectAIRegistry& ai_registry(*GameObjectAIRepository::instance());
if (GameObjectAI* scriptedAI = sScriptMgr->GetGameObjectAI(go))
return scriptedAI;
ai_factory = ai_registry.GetRegistryItem(go->GetAIName());
//future goAI types go here

View File

@@ -954,6 +954,14 @@ bool ScriptMgr::OnDummyEffect(Unit* caster, uint32 spellId, SpellEffIndex effInd
return tmpscript->OnDummyEffect(caster, spellId, effIndex, target);
}
GameObjectAI* ScriptMgr::GetGameObjectAI(GameObject* go)
{
ASSERT(go);
GET_SCRIPT_RET(GameObjectScript, go->GetScriptId(), tmpscript, NULL);
tmpscript->GetAI(go);
}
bool ScriptMgr::OnAreaTrigger(Player* player, AreaTriggerEntry const* trigger)
{
ASSERT(player);

View File

@@ -39,6 +39,7 @@ class Creature;
class CreatureAI;
class DynamicObject;
class GameObject;
class GameObjectAI;
class Guild;
class GridMap;
class Group;
@@ -471,6 +472,9 @@ class GameObjectScript : public ScriptObject, public UpdatableScript<GameObject>
// Called when the game object is damaged (destructible buildings only).
virtual void OnDamaged(GameObject* /*go*/, Player* /*player*/) { }
// Called when a GameObjectAI object is needed for the gameobject.
virtual GameObjectAI* GetAI(GameObject* /*go*/) const { return NULL; }
};
class AreaTriggerScript : public ScriptObject
@@ -911,6 +915,7 @@ class ScriptMgr
void OnGameObjectDestroyed(GameObject* go, Player* player);
void OnGameObjectDamaged(GameObject* go, Player* player);
void OnGameObjectUpdate(GameObject* go, uint32 diff);
GameObjectAI* GetGameObjectAI(GameObject* go);
public: /* AreaTriggerScript */

View File

@@ -234,7 +234,6 @@ class instance_ulduar : public InstanceMapScript
case NPC_ALGALON:
AlgalonGUID = creature->GetGUID();
break;
// Hodir's Helper NPCs
case NPC_EIVI_NIGHTFEATHER:
if (TeamInInstance == HORDE)