Core/Scripting: add the ability to access loot/go state changed events for gameobjects from cpp scripting. (malcrom's idea)

This commit is contained in:
Kandera
2012-05-16 08:47:43 -04:00
parent c05c16a8de
commit c70792df02
3 changed files with 26 additions and 0 deletions
@@ -1910,6 +1910,7 @@ void GameObject::SetLootState(LootState state, Unit* unit)
{ {
m_lootState = state; m_lootState = state;
AI()->OnStateChanged(state, unit); AI()->OnStateChanged(state, unit);
sScriptMgr->OnGameObjectLootStateChanged(this, state, unit);
if (m_model) if (m_model)
{ {
// startOpen determines whether we are going to add or remove the LoS on activation // startOpen determines whether we are going to add or remove the LoS on activation
@@ -1929,6 +1930,7 @@ void GameObject::SetLootState(LootState state, Unit* unit)
void GameObject::SetGoState(GOState state) void GameObject::SetGoState(GOState state)
{ {
SetByteValue(GAMEOBJECT_BYTES_1, 0, state); SetByteValue(GAMEOBJECT_BYTES_1, 0, state);
sScriptMgr->OnGameObjectStateChanged(this, state);
if (m_model) if (m_model)
{ {
if (!IsInWorld()) if (!IsInWorld())
+16
View File
@@ -937,6 +937,22 @@ void ScriptMgr::OnGameObjectDamaged(GameObject* go, Player* player)
tmpscript->OnDamaged(go, player); tmpscript->OnDamaged(go, player);
} }
void ScriptMgr::OnGameObjectLootStateChanged(GameObject* go, uint32 state, Unit* unit)
{
ASSERT(go);
GET_SCRIPT(GameObjectScript, go->GetScriptId(), tmpscript);
tmpscript->OnLootStateChanged(go, state, unit);
}
void ScriptMgr::OnGameObjectStateChanged(GameObject* go, uint32 state)
{
ASSERT(go);
GET_SCRIPT(GameObjectScript, go->GetScriptId(), tmpscript);
tmpscript->OnGameObjectStateChanged(go, state);
}
void ScriptMgr::OnGameObjectUpdate(GameObject* go, uint32 diff) void ScriptMgr::OnGameObjectUpdate(GameObject* go, uint32 diff)
{ {
ASSERT(go); ASSERT(go);
+8
View File
@@ -473,6 +473,12 @@ class GameObjectScript : public ScriptObject, public UpdatableScript<GameObject>
// Called when the game object is damaged (destructible buildings only). // Called when the game object is damaged (destructible buildings only).
virtual void OnDamaged(GameObject* /*go*/, Player* /*player*/) { } virtual void OnDamaged(GameObject* /*go*/, Player* /*player*/) { }
// Called when the game object loot state is changed.
virtual void OnLootStateChanged(GameObject* /*go*/, uint32 /*state*/, Unit* /*unit*/) { }
// Called when the game object state is changed.
virtual void OnGameObjectStateChanged(GameObject* /*go*/, uint32 /*state*/) { }
// Called when a GameObjectAI object is needed for the gameobject. // Called when a GameObjectAI object is needed for the gameobject.
virtual GameObjectAI* GetAI(GameObject* /*go*/) const { return NULL; } virtual GameObjectAI* GetAI(GameObject* /*go*/) const { return NULL; }
}; };
@@ -914,6 +920,8 @@ class ScriptMgr
uint32 GetDialogStatus(Player* player, GameObject* go); uint32 GetDialogStatus(Player* player, GameObject* go);
void OnGameObjectDestroyed(GameObject* go, Player* player); void OnGameObjectDestroyed(GameObject* go, Player* player);
void OnGameObjectDamaged(GameObject* go, Player* player); void OnGameObjectDamaged(GameObject* go, Player* player);
void OnGameObjectLootStateChanged(GameObject* go, uint32 state, Unit* unit);
void OnGameObjectStateChanged(GameObject* go, uint32 state);
void OnGameObjectUpdate(GameObject* go, uint32 diff); void OnGameObjectUpdate(GameObject* go, uint32 diff);
GameObjectAI* GetGameObjectAI(GameObject* go); GameObjectAI* GetGameObjectAI(GameObject* go);