Core/AI: Added EventInform hook for GameObjectAI and implemented it in SAI

This commit is contained in:
Shauren
2012-06-11 11:10:46 +02:00
parent 20b97b0119
commit 28f8e42a69
7 changed files with 53 additions and 26 deletions
+2 -1
View File
@@ -53,7 +53,8 @@ class GameObjectAI
virtual uint64 GetData64(uint32 /*id*/) { return 0; }
virtual void SetData(uint32 /*id*/, uint32 /*value*/) {}
virtual void OnGameEvent(bool /*start*/, uint16 /*eventId*/) {}
virtual void OnStateChanged(uint32 /*state*/, Unit* /*unit*/) { }
virtual void OnStateChanged(uint32 /*state*/, Unit* /*unit*/) {}
virtual void EventInform(uint32 eventId) {}
};
class NullGameObjectAI : public GameObjectAI
@@ -937,6 +937,11 @@ void SmartGameObjectAI::OnStateChanged(uint32 state, Unit* unit)
GetScript()->ProcessEventsFor(SMART_EVENT_GO_STATE_CHANGED, unit, state);
}
void SmartGameObjectAI::EventInform(uint32 eventId)
{
GetScript()->ProcessEventsFor(SMART_EVENT_GO_EVENT_INFORM, NULL, eventId);
}
class SmartTrigger : public AreaTriggerScript
{
public:
+23 -22
View File
@@ -235,30 +235,31 @@ class SmartAI : public CreatureAI
class SmartGameObjectAI : public GameObjectAI
{
public:
SmartGameObjectAI(GameObject* g) : GameObjectAI(g), go(g) {}
~SmartGameObjectAI() {}
public:
SmartGameObjectAI(GameObject* g) : GameObjectAI(g), go(g) {}
~SmartGameObjectAI() {}
void UpdateAI(uint32 diff);
void InitializeAI();
void Reset();
SmartScript* GetScript() { return &mScript; }
static int Permissible(const GameObject* g);
void UpdateAI(uint32 diff);
void InitializeAI();
void Reset();
SmartScript* GetScript() { return &mScript; }
static int Permissible(const GameObject* g);
bool GossipHello(Player* player);
bool GossipSelect(Player* player, uint32 sender, uint32 action);
bool GossipSelectCode(Player* /*player*/, uint32 /*sender*/, uint32 /*action*/, const char* /*code*/);
bool QuestAccept(Player* player, Quest const* quest);
bool QuestReward(Player* player, Quest const* quest, uint32 opt);
uint32 GetDialogStatus(Player* /*player*/);
void Destroyed(Player* player, uint32 eventId);
void SetData(uint32 id, uint32 value);
void SetScript9(SmartScriptHolder& e, uint32 entry, Unit* invoker);
void OnGameEvent(bool start, uint16 eventId);
void OnStateChanged(uint32 state, Unit* unit);
bool GossipHello(Player* player);
bool GossipSelect(Player* player, uint32 sender, uint32 action);
bool GossipSelectCode(Player* /*player*/, uint32 /*sender*/, uint32 /*action*/, const char* /*code*/);
bool QuestAccept(Player* player, Quest const* quest);
bool QuestReward(Player* player, Quest const* quest, uint32 opt);
uint32 GetDialogStatus(Player* /*player*/);
void Destroyed(Player* player, uint32 eventId);
void SetData(uint32 id, uint32 value);
void SetScript9(SmartScriptHolder& e, uint32 entry, Unit* invoker);
void OnGameEvent(bool start, uint16 eventId);
void OnStateChanged(uint32 state, Unit* unit);
void EventInform(uint32 eventId);
protected:
GameObject* const go;
SmartScript mScript;
protected:
GameObject* const go;
SmartScript mScript;
};
#endif
@@ -2771,6 +2771,13 @@ void SmartScript::ProcessEvent(SmartScriptHolder& e, Unit* unit, uint32 var0, ui
ProcessAction(e, unit, var0, var1);
break;
}
case SMART_EVENT_GO_EVENT_INFORM:
{
if (e.event.eventInform.eventId != var0)
return;
ProcessAction(e, NULL, var0);
break;
}
default:
sLog->outErrorDb("SmartScript::ProcessEvent: Unhandled Event type %u", e.GetEventType());
break;
@@ -533,6 +533,7 @@ bool SmartAIMgr::IsEventValid(SmartScriptHolder& e)
break;
}
case SMART_EVENT_GO_STATE_CHANGED:
case SMART_EVENT_GO_EVENT_INFORM:
case SMART_EVENT_TIMED_EVENT_TRIGGERED:
case SMART_EVENT_INSTANCE_PLAYER_ENTER:
case SMART_EVENT_TRANSPORT_RELOCATE:
@@ -153,9 +153,10 @@ enum SMART_EVENT
SMART_EVENT_IS_BEHIND_TARGET = 67, //1 // cooldownMin, CooldownMax
SMART_EVENT_GAME_EVENT_START = 68, //1 // game_event.Entry
SMART_EVENT_GAME_EVENT_END = 69, //1 // game_event.Entry
SMART_EVENT_GO_STATE_CHANGED = 70, // go state
SMART_EVENT_GO_STATE_CHANGED = 70, //1 // go state
SMART_EVENT_GO_EVENT_INFORM = 71, //1 // eventId
SMART_EVENT_END = 71,
SMART_EVENT_END = 72,
};
struct SmartEvent
@@ -350,6 +351,11 @@ struct SmartEvent
uint32 state;
} goStateChanged;
struct
{
uint32 eventId;
} eventInform;
struct
{
uint32 param1;
@@ -1711,7 +1711,13 @@ bool GameObject::IsInRange(float x, float y, float z, float radius) const
void GameObject::EventInform(uint32 eventId)
{
if (eventId && m_zoneScript)
if (!eventId)
return;
if (AI())
AI()->EventInform(eventId);
if (m_zoneScript)
m_zoneScript->ProcessEvent(this, eventId);
}