Core/SAI: Preliminary implementation of SMART_EVENT_GAME_EVENT_START and SMART_EVENT_GAME_EVENT_END {param1: game_event.entry}
This commit is contained in:
@@ -49,6 +49,7 @@ class GameObjectAI
|
||||
virtual uint32 GetDialogStatus(Player* /*player*/) {return 100;}
|
||||
virtual void Destroyed(Player* /*player*/, uint32 /*eventId*/) {}
|
||||
virtual void SetData(uint32 /*id*/, uint32 /*value*/) {}
|
||||
virtual void OnGameEvent(bool /*start*/, uint16 /*eventId*/) {}
|
||||
};
|
||||
|
||||
class NullGameObjectAI : public GameObjectAI
|
||||
|
||||
@@ -267,6 +267,7 @@ class UnitAI
|
||||
virtual void sQuestComplete(Player* /*player*/, Quest const* /*quest*/) {}
|
||||
virtual void sQuestReward(Player* /*player*/, Quest const* /*quest*/, uint32 /*opt*/) {}
|
||||
virtual bool sOnDummyEffect(Unit* /*caster*/, uint32 /*spellId*/, SpellEffIndex /*effIndex*/) { return false; }
|
||||
virtual void sOnGameEvent(bool /*start*/, uint16 /*eventId*/) {}
|
||||
};
|
||||
|
||||
class PlayerAI : public UnitAI
|
||||
|
||||
@@ -811,6 +811,12 @@ void SmartAI::SetScript9(SmartScriptHolder& e, uint32 entry, Unit* invoker)
|
||||
GetScript()->mLastInvoker = invoker->GetGUID();
|
||||
GetScript()->SetScript9(e, entry);
|
||||
}
|
||||
|
||||
void SmartAI::sOnGameEvent(bool start, uint16 eventId)
|
||||
{
|
||||
GetScript()->ProcessEventsFor(start ? SMART_EVENT_GAME_EVENT_START : SMART_EVENT_GAME_EVENT_END, NULL, eventId);
|
||||
}
|
||||
|
||||
/*
|
||||
SMART_EVENT_UPDATE_OOC
|
||||
SMART_EVENT_SPELLHIT
|
||||
@@ -913,6 +919,11 @@ void SmartGameObjectAI::SetScript9(SmartScriptHolder& e, uint32 entry, Unit* inv
|
||||
GetScript()->SetScript9(e, entry);
|
||||
}
|
||||
|
||||
void SmartGameObjectAI::OnGameEvent(bool start, uint16 eventId)
|
||||
{
|
||||
GetScript()->ProcessEventsFor(start ? SMART_EVENT_GAME_EVENT_START : SMART_EVENT_GAME_EVENT_END, NULL, eventId);
|
||||
}
|
||||
|
||||
class SmartTrigger : public AreaTriggerScript
|
||||
{
|
||||
public:
|
||||
|
||||
@@ -183,6 +183,7 @@ class SmartAI : public CreatureAI
|
||||
//void sQuestComplete(Player* player, Quest const* quest);
|
||||
void sQuestReward(Player* player, Quest const* quest, uint32 opt);
|
||||
bool sOnDummyEffect(Unit* caster, uint32 spellId, SpellEffIndex effIndex);
|
||||
void sOnGameEvent(bool start, uint16 eventId);
|
||||
|
||||
uint32 mEscortQuestID;
|
||||
|
||||
@@ -249,6 +250,7 @@ public:
|
||||
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);
|
||||
|
||||
protected:
|
||||
GameObject* const go;
|
||||
|
||||
@@ -2595,6 +2595,14 @@ void SmartScript::ProcessEvent(SmartScriptHolder& e, Unit* unit, uint32 var0, ui
|
||||
ProcessAction(e, unit, var0, var1);
|
||||
break;
|
||||
}
|
||||
case SMART_EVENT_GAME_EVENT_START:
|
||||
case SMART_EVENT_GAME_EVENT_END:
|
||||
{
|
||||
if (e.event.gameEvent.gameEventId != var0)
|
||||
return;
|
||||
ProcessAction(e, NULL, var0);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
sLog->outErrorDb("SmartScript::ProcessEvent: Unhandled Event type %u", e.GetEventType());
|
||||
break;
|
||||
@@ -2996,7 +3004,9 @@ void SmartScript::SetScript9(SmartScriptHolder& e, uint32 entry)
|
||||
mResumeActionList = e.action.timedActionList.dontResume ? false : true;
|
||||
InitTimer((*i));
|
||||
}
|
||||
}Unit* SmartScript::GetLastInvoker()
|
||||
}
|
||||
|
||||
Unit* SmartScript::GetLastInvoker()
|
||||
{
|
||||
return ObjectAccessor::FindUnit(mLastInvoker);
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
#include "CellImpl.h"
|
||||
#include "InstanceScript.h"
|
||||
#include "ScriptedCreature.h"
|
||||
#include "GameEventMgr.h"
|
||||
|
||||
#include "SmartScriptMgr.h"
|
||||
|
||||
@@ -466,6 +467,14 @@ bool SmartAIMgr::IsEventValid(SmartScriptHolder& e)
|
||||
if (!IsMinMaxValid(e, e.event.behindTarget.cooldownMin, e.event.behindTarget.cooldownMax))
|
||||
return false;
|
||||
break;
|
||||
case SMART_EVENT_GAME_EVENT_START:
|
||||
case SMART_EVENT_GAME_EVENT_END:
|
||||
{
|
||||
GameEventMgr::GameEventDataMap const& events = sGameEventMgr->GetEventMap();
|
||||
if (e.event.gameEvent.gameEventId >= events.size() || !events[e.event.gameEvent.gameEventId].isValid())
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
case SMART_EVENT_TIMED_EVENT_TRIGGERED:
|
||||
case SMART_EVENT_INSTANCE_PLAYER_ENTER:
|
||||
case SMART_EVENT_TRANSPORT_RELOCATE:
|
||||
|
||||
@@ -152,8 +152,10 @@ enum SMART_EVENT
|
||||
SMART_EVENT_FOLLOW_COMPLETED = 65, //1 // none
|
||||
SMART_EVENT_DUMMY_EFFECT = 66, //1 // spellId, effectIndex
|
||||
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_END = 68,
|
||||
SMART_EVENT_END = 70,
|
||||
};
|
||||
|
||||
struct SmartEvent
|
||||
@@ -338,6 +340,11 @@ struct SmartEvent
|
||||
uint32 cooldownMax;
|
||||
} behindTarget;
|
||||
|
||||
struct
|
||||
{
|
||||
uint32 gameEventId;
|
||||
} gameEvent;
|
||||
|
||||
struct
|
||||
{
|
||||
uint32 param1;
|
||||
@@ -1128,7 +1135,9 @@ const uint32 SmartAIEventMask[SMART_EVENT_END][2] =
|
||||
{SMART_EVENT_GOSSIP_HELLO, SMART_SCRIPT_TYPE_MASK_CREATURE + SMART_SCRIPT_TYPE_MASK_GAMEOBJECT },
|
||||
{SMART_EVENT_FOLLOW_COMPLETED, SMART_SCRIPT_TYPE_MASK_CREATURE },
|
||||
{SMART_EVENT_DUMMY_EFFECT, SMART_SCRIPT_TYPE_MASK_SPELL },
|
||||
{SMART_EVENT_IS_BEHIND_TARGET, SMART_SCRIPT_TYPE_MASK_CREATURE }
|
||||
{SMART_EVENT_IS_BEHIND_TARGET, SMART_SCRIPT_TYPE_MASK_CREATURE },
|
||||
{SMART_EVENT_GAME_EVENT_START, SMART_SCRIPT_TYPE_MASK_CREATURE + SMART_SCRIPT_TYPE_MASK_GAMEOBJECT },
|
||||
{SMART_EVENT_GAME_EVENT_END, SMART_SCRIPT_TYPE_MASK_CREATURE + SMART_SCRIPT_TYPE_MASK_GAMEOBJECT },
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -27,6 +27,8 @@
|
||||
#include "GossipDef.h"
|
||||
#include "Player.h"
|
||||
#include "BattlegroundMgr.h"
|
||||
#include "UnitAI.h"
|
||||
#include "GameObjectAI.h"
|
||||
|
||||
bool GameEventMgr::CheckOneGameEvent(uint16 entry) const
|
||||
{
|
||||
@@ -1059,6 +1061,8 @@ uint32 GameEventMgr::Update() // return the next e
|
||||
void GameEventMgr::UnApplyEvent(uint16 event_id)
|
||||
{
|
||||
sLog->outDetail("GameEvent %u \"%s\" removed.", event_id, mGameEvent[event_id].description.c_str());
|
||||
//! Run SAI scripts with SMART_EVENT_GAME_EVENT_END
|
||||
RunSmartAIScripts(event_id, false);
|
||||
// un-spawn positive event tagged objects
|
||||
GameEventUnspawn(event_id);
|
||||
// spawn negative event tagget objects
|
||||
@@ -1090,6 +1094,9 @@ void GameEventMgr::ApplyNewEvent(uint16 event_id)
|
||||
|
||||
sLog->outDetail("GameEvent %u \"%s\" started.", event_id, mGameEvent[event_id].description.c_str());
|
||||
|
||||
//! Run SAI scripts with SMART_EVENT_GAME_EVENT_END
|
||||
RunSmartAIScripts(event_id, true);
|
||||
|
||||
// spawn positive event tagget objects
|
||||
GameEventSpawn(event_id);
|
||||
// un-spawn negative event tagged objects
|
||||
@@ -1601,6 +1608,26 @@ void GameEventMgr::SendWorldStateUpdate(Player* player, uint16 event_id)
|
||||
}
|
||||
}
|
||||
|
||||
void GameEventMgr::RunSmartAIScripts(uint16 event_id, bool activate)
|
||||
{
|
||||
//! Iterate over every supported source type (creature and gameobject)
|
||||
//! Not entirely sure how this will affect units in non-loaded grids.
|
||||
{
|
||||
TRINITY_READ_GUARD(HashMapHolder<Creature>::LockType, *HashMapHolder<Creature>::GetLock());
|
||||
HashMapHolder<Creature>::MapType const& m = ObjectAccessor::GetCreatures();
|
||||
for (HashMapHolder<Creature>::MapType::const_iterator iter = m.begin(); iter != m.end(); ++iter)
|
||||
if (iter->second->IsInWorld())
|
||||
iter->second->AI()->sOnGameEvent(activate, event_id);
|
||||
}
|
||||
{
|
||||
TRINITY_READ_GUARD(HashMapHolder<GameObject>::LockType, *HashMapHolder<Creature>::GetLock());
|
||||
HashMapHolder<GameObject>::MapType const& m = ObjectAccessor::GetGameObjects();
|
||||
for (HashMapHolder<GameObject>::MapType::const_iterator iter = m.begin(); iter != m.end(); ++iter)
|
||||
if (iter->second->IsInWorld())
|
||||
iter->second->AI()->OnGameEvent(activate, event_id);
|
||||
}
|
||||
}
|
||||
|
||||
bool IsHolidayActive(HolidayIds id)
|
||||
{
|
||||
if (id == HOLIDAY_NONE)
|
||||
|
||||
@@ -132,6 +132,7 @@ class GameEventMgr
|
||||
void UpdateEventNPCFlags(uint16 event_id);
|
||||
void UpdateEventNPCVendor(uint16 event_id, bool activate);
|
||||
void UpdateBattlegroundSettings();
|
||||
void RunSmartAIScripts(uint16 event_id, bool activate); //! Runs SMART_EVENT_GAME_EVENT_START/_END SAI
|
||||
bool CheckOneGameEventConditions(uint16 event_id);
|
||||
void SaveWorldEventStateToDB(uint16 event_id);
|
||||
bool hasCreatureQuestActiveEventExcept(uint32 quest_id, uint16 event_id);
|
||||
|
||||
@@ -201,16 +201,16 @@ class ObjectAccessor
|
||||
}
|
||||
|
||||
// when using this, you must use the hashmapholder's lock
|
||||
//HashMapHolder<Creature>::MapType& GetCreatures()
|
||||
//{
|
||||
// return HashMapHolder<Creature>::GetContainer();
|
||||
//}
|
||||
static HashMapHolder<Creature>::MapType const& GetCreatures()
|
||||
{
|
||||
return HashMapHolder<Creature>::GetContainer();
|
||||
}
|
||||
|
||||
//// when using this, you must use the hashmapholder's lock
|
||||
//HashMapHolder<GameObject>::MapType& GetGameObjects()
|
||||
//{
|
||||
// return HashMapHolder<GameObject>::GetContainer();
|
||||
//}
|
||||
// when using this, you must use the hashmapholder's lock
|
||||
static HashMapHolder<GameObject>::MapType const& GetGameObjects()
|
||||
{
|
||||
return HashMapHolder<GameObject>::GetContainer();
|
||||
}
|
||||
|
||||
template<class T> static void AddObject(T* object)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user