Skip to content

Commit

Permalink
Merge pull request #2 from Foereaper/master
Browse files Browse the repository at this point in the history
Add Eluna multistate support
  • Loading branch information
Niam5 authored Jan 28, 2024
2 parents 3014f7e + 4a69851 commit 813b6e0
Show file tree
Hide file tree
Showing 38 changed files with 482 additions and 220 deletions.
69 changes: 42 additions & 27 deletions src/game/AI/ScriptDevAI/ScriptDevAIMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,9 @@ void Script::RegisterSelf(bool bReportError)
bool ScriptDevAIMgr::OnGossipHello(Player* pPlayer, Creature* pCreature)
{
#ifdef BUILD_ELUNA
if (sEluna->OnGossipHello(pPlayer, pCreature))
return true;
if (Eluna* e = pPlayer->GetEluna())
if (e->OnGossipHello(pPlayer, pCreature))
return true;
#endif

Script* pTempScript = GetScript(pCreature->GetScriptId());
Expand All @@ -185,8 +186,9 @@ bool ScriptDevAIMgr::OnGossipHello(Player* pPlayer, Creature* pCreature)
bool ScriptDevAIMgr::OnGossipHello(Player* pPlayer, GameObject* pGo)
{
#ifdef BUILD_ELUNA
if (sEluna->OnGossipHello(pPlayer, pGo))
return true;
if (Eluna* e = pPlayer->GetEluna())
if (e->OnGossipHello(pPlayer, pGo))
return true;
#endif

Script* pTempScript = GetScript(pGo->GetGOInfo()->ScriptId);
Expand All @@ -204,13 +206,15 @@ bool ScriptDevAIMgr::OnGossipSelect(Player* pPlayer, Creature* pCreature, uint32
#ifdef BUILD_ELUNA
if (code)
{
if (sEluna->OnGossipSelectCode(pPlayer, pCreature, uiSender, uiAction, code))
return true;
if (Eluna* e = pPlayer->GetEluna())
if (e->OnGossipSelectCode(pPlayer, pCreature, uiSender, uiAction, code))
return true;
}
else
{
if (sEluna->OnGossipSelect(pPlayer, pCreature, uiSender, uiAction))
return true;
if (Eluna* e = pPlayer->GetEluna())
if (e->OnGossipSelect(pPlayer, pCreature, uiSender, uiAction))
return true;
}
#endif

Expand Down Expand Up @@ -242,13 +246,15 @@ bool ScriptDevAIMgr::OnGossipSelect(Player* pPlayer, GameObject* pGo, uint32 uiS
#ifdef BUILD_ELUNA
if (code)
{
if (sEluna->OnGossipSelectCode(pPlayer, pGo, uiSender, uiAction, code))
return true;
if (Eluna* e = pPlayer->GetEluna())
if (e->OnGossipSelectCode(pPlayer, pGo, uiSender, uiAction, code))
return true;
}
else
{
if (sEluna->OnGossipSelect(pPlayer, pGo, uiSender, uiAction))
return true;
if (Eluna* e = pPlayer->GetEluna())
if (e->OnGossipSelect(pPlayer, pGo, uiSender, uiAction))
return true;
}
#endif

Expand Down Expand Up @@ -314,8 +320,9 @@ bool ScriptDevAIMgr::OnQuestAccept(Player* pPlayer, Creature* pCreature, const Q
bool ScriptDevAIMgr::OnQuestAccept(Player* pPlayer, GameObject* pGo, const Quest* pQuest)
{
#ifdef BUILD_ELUNA
if (sEluna->OnQuestAccept(pPlayer, pGo, pQuest))
return true;
if (Eluna* e = pPlayer->GetEluna())
if (e->OnQuestAccept(pPlayer, pGo, pQuest))
return true;
#endif

Script* pTempScript = GetScript(pGo->GetGOInfo()->ScriptId);
Expand All @@ -331,8 +338,9 @@ bool ScriptDevAIMgr::OnQuestAccept(Player* pPlayer, GameObject* pGo, const Quest
bool ScriptDevAIMgr::OnQuestAccept(Player* pPlayer, Item* pItem, Quest const* pQuest)
{
#ifdef BUILD_ELUNA
if (sEluna->OnQuestAccept(pPlayer, pItem, pQuest))
return true;
if (Eluna* e = pPlayer->GetEluna())
if (e->OnQuestAccept(pPlayer, pItem, pQuest))
return true;
#endif

Script* pTempScript = GetScript(pItem->GetProto()->ScriptId);
Expand All @@ -348,8 +356,9 @@ bool ScriptDevAIMgr::OnQuestAccept(Player* pPlayer, Item* pItem, Quest const* pQ
bool ScriptDevAIMgr::OnGameObjectUse(Player* pPlayer, GameObject* pGo)
{
#ifdef BUILD_ELUNA
if (sEluna->OnGameObjectUse(pPlayer, pGo))
return true;
if (Eluna* e = pPlayer->GetEluna())
if (e->OnGameObjectUse(pPlayer, pGo))
return true;
#endif

Script* pTempScript = GetScript(pGo->GetGOInfo()->ScriptId);
Expand Down Expand Up @@ -397,8 +406,9 @@ bool ScriptDevAIMgr::OnQuestRewarded(Player* pPlayer, GameObject* pGo, Quest con
bool ScriptDevAIMgr::OnAreaTrigger(Player* pPlayer, AreaTriggerEntry const* atEntry)
{
#ifdef BUILD_ELUNA
if (sEluna->OnAreaTrigger(pPlayer, atEntry))
return true;
if (Eluna* e = pPlayer->GetEluna())
if (e->OnAreaTrigger(pPlayer, atEntry))
return true;
#endif

Script* pTempScript = GetScript(GetAreaTriggerScriptId(atEntry->id));
Expand All @@ -423,8 +433,9 @@ bool ScriptDevAIMgr::OnProcessEvent(uint32 uiEventId, Object* pSource, Object* p
UnitAI* ScriptDevAIMgr::GetCreatureAI(Creature* pCreature) const
{
#ifdef BUILD_ELUNA
if (CreatureAI* luaAI = sEluna->GetAI(pCreature))
return luaAI;
if (Eluna* e = pCreature->GetEluna())
if (CreatureAI* luaAI = e->GetAI(pCreature))
return luaAI;
#endif

Script* pTempScript = GetScript(pCreature->GetScriptId());
Expand All @@ -448,8 +459,9 @@ GameObjectAI* ScriptDevAIMgr::GetGameObjectAI(GameObject* gameobject) const
bool ScriptDevAIMgr::OnItemUse(Player* pPlayer, Item* pItem, SpellCastTargets const& targets)
{
#ifdef BUILD_ELUNA
if (!sEluna->OnUse(pPlayer, pItem, targets))
return true;
if (Eluna* e = pPlayer->GetEluna())
if (!e->OnUse(pPlayer, pItem, targets))
return true;
#endif

Script* pTempScript = GetScript(pItem->GetProto()->ScriptId);
Expand All @@ -474,7 +486,8 @@ bool ScriptDevAIMgr::OnEffectDummy(Unit* pCaster, uint32 spellId, SpellEffectInd
{
Script* pTempScript = GetScript(pTarget->GetScriptId());
#ifdef BUILD_ELUNA
sEluna->OnDummyEffect(pCaster, spellId, effIndex, pTarget);
if (Eluna* e = pCaster->GetEluna())
e->OnDummyEffect(pCaster, spellId, effIndex, pTarget);
#endif
if (!pTempScript || !pTempScript->pEffectDummyNPC)
return false;
Expand All @@ -486,7 +499,8 @@ bool ScriptDevAIMgr::OnEffectDummy(Unit* pCaster, uint32 spellId, SpellEffectInd
{
Script* pTempScript = GetScript(pTarget->GetGOInfo()->ScriptId);
#ifdef BUILD_ELUNA
sEluna->OnDummyEffect(pCaster, spellId, effIndex, pTarget);
if (Eluna* e = pCaster->GetEluna())
e->OnDummyEffect(pCaster, spellId, effIndex, pTarget);
#endif
if (!pTempScript || !pTempScript->pEffectDummyGO)
return false;
Expand All @@ -498,7 +512,8 @@ bool ScriptDevAIMgr::OnEffectDummy(Unit* pCaster, uint32 spellId, SpellEffectInd
{
Script* pTempScript = GetScript(pTarget->GetProto()->ScriptId);
#ifdef BUILD_ELUNA
sEluna->OnDummyEffect(pCaster, spellId, effIndex, pTarget);
if (Eluna* e = pCaster->GetEluna())
e->OnDummyEffect(pCaster, spellId, effIndex, pTarget);
#endif
if (!pTempScript || !pTempScript->pEffectDummyItem)
return false;
Expand Down
6 changes: 4 additions & 2 deletions src/game/AuctionHouse/AuctionHouseHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,8 @@ void WorldSession::HandleAuctionSellItem(WorldPacket& recv_data)
SendAuctionCommandResult(AH, AUCTION_STARTED, AUCTION_OK);

#ifdef BUILD_ELUNA
sEluna->OnAdd(auctionHouse, AH);
if (Eluna* e = sWorld.GetEluna())
e->OnAdd(auctionHouse, AH);
#endif
}

Expand Down Expand Up @@ -471,7 +472,8 @@ void WorldSession::HandleAuctionRemoveItem(WorldPacket& recv_data)
CharacterDatabase.CommitTransaction();
sAuctionMgr.RemoveAItem(auction->itemGuidLow);
#ifdef BUILD_ELUNA
sEluna->OnRemove(auctionHouse, auction);
if (Eluna* e = sWorld.GetEluna())
e->OnRemove(auctionHouse, auction);
#endif
auctionHouse->RemoveAuction(auction->Id);
delete auction;
Expand Down
6 changes: 4 additions & 2 deletions src/game/BattleGround/BattleGround.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,8 @@ void BattleGround::UpdateWorldStateForPlayer(uint32 field, uint32 value, Player*
void BattleGround::EndBattleGround(Team winner)
{
#ifdef BUILD_ELUNA
sEluna->OnBGEnd(this, GetTypeId(), GetInstanceId(), winner);
if (Eluna* e = GetBgMap()->GetEluna())
e->OnBGEnd(this, GetTypeId(), GetInstanceId(), winner);
#endif

this->RemoveFromBgFreeSlotQueue();
Expand Down Expand Up @@ -1185,7 +1186,8 @@ void BattleGround::StartBattleGround()
sBattleGroundMgr.AddBattleGround(GetInstanceId(), GetTypeId(), this);

#ifdef BUILD_ELUNA
sEluna->OnBGStart(this, GetTypeId(), GetInstanceId());
if (Eluna* e = GetBgMap()->GetEluna())
e->OnBGStart(this, GetTypeId(), GetInstanceId());
#endif
}

Expand Down
3 changes: 2 additions & 1 deletion src/game/BattleGround/BattleGroundMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1333,7 +1333,8 @@ uint32 BattleGroundMgr::CreateBattleGround(BattleGroundTypeId bgTypeId, uint32 m
AddBattleGround(bg->GetInstanceId(), bg->GetTypeId(), bg);

#ifdef BUILD_ELUNA
sEluna->OnBGCreate(bg, bgTypeId, bg->GetInstanceId());
if (Eluna* e = bg->GetBgMap()->GetEluna())
e->OnBGCreate(bg, bgTypeId, bg->GetInstanceId());
#endif

// return some not-null value, bgTypeId is good enough for me
Expand Down
10 changes: 6 additions & 4 deletions src/game/Chat/Chat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1426,8 +1426,9 @@ void ChatHandler::ExecuteCommand(const char* text)
case CHAT_COMMAND_UNKNOWN_SUBCOMMAND:
{
#ifdef BUILD_ELUNA
if (!sEluna->OnCommand(m_session ? m_session->GetPlayer() : NULL, fullcmd.c_str()))
return;
if(Eluna* e = sWorld.GetEluna())
if (!e->OnCommand(m_session ? m_session->GetPlayer() : NULL, fullcmd.c_str()))
return;
#endif
SendSysMessage(LANG_NO_SUBCMD);
ShowHelpForCommand(command->ChildCommands, text);
Expand All @@ -1437,8 +1438,9 @@ void ChatHandler::ExecuteCommand(const char* text)
case CHAT_COMMAND_UNKNOWN:
{
#ifdef BUILD_ELUNA
if (!sEluna->OnCommand(m_session ? m_session->GetPlayer() : NULL, fullcmd.c_str()))
return;
if (Eluna* e = sWorld.GetEluna())
if (!e->OnCommand(m_session ? m_session->GetPlayer() : NULL, fullcmd.c_str()))
return;
#endif
SendSysMessage(LANG_NO_CMD);
SetSentErrorMessage(true);
Expand Down
Loading

0 comments on commit 813b6e0

Please sign in to comment.