Skip to content

Commit

Permalink
Merge pull request #21 from ElunaLuaEngine/multistate
Browse files Browse the repository at this point in the history
Multistate implementation
  • Loading branch information
Foereaper authored Jan 26, 2024
2 parents efafa32 + 46fe442 commit fb48e0c
Show file tree
Hide file tree
Showing 34 changed files with 466 additions and 220 deletions.
2 changes: 2 additions & 0 deletions src/common/Utilities/AsyncCallbackProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ class AsyncCallbackProcessor
_callbacks.insert(_callbacks.end(), std::make_move_iterator(updateCallbacks.begin()), std::make_move_iterator(updateCallbacks.end()));
}

bool HasPendingCallbacks() { return !_callbacks.empty(); }

private:
AsyncCallbackProcessor(AsyncCallbackProcessor const&) = delete;
AsyncCallbackProcessor& operator=(AsyncCallbackProcessor const&) = delete;
Expand Down
3 changes: 2 additions & 1 deletion src/server/game/Achievements/AchievementMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1534,7 +1534,8 @@ void AchievementMgr::CompletedAchievement(AchievementEntry const* achievement)
UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_EARN_ACHIEVEMENT_POINTS, achievement->Points);

#ifdef ELUNA
sEluna->OnAchievementComplete(GetPlayer(), achievement->ID);
if (Eluna* e = GetPlayer()->GetEluna())
e->OnAchievementComplete(GetPlayer(), achievement->ID);
#endif

// reward items and titles if any
Expand Down
13 changes: 9 additions & 4 deletions src/server/game/Battlegrounds/Battleground.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,9 @@ Battleground::~Battleground()
DelObject(i);

#ifdef ELUNA
sEluna->OnBGDestroy(this, GetTypeID(), GetInstanceID());
if (BattlegroundMap* bg = FindBgMap())
if (Eluna* e = bg->GetEluna())
e->OnBGDestroy(this, GetTypeID(), GetInstanceID());
#endif

sBattlegroundMgr->RemoveBattleground(GetTypeID(), GetInstanceID());
Expand Down Expand Up @@ -457,7 +459,8 @@ inline void Battleground::_ProcessJoin(uint32 diff)
StartingEventOpenDoors();

#ifdef ELUNA
sEluna->OnBGStart(this, GetTypeID(), GetInstanceID());
if (Eluna* e = GetBgMap()->GetEluna())
e->OnBGStart(this, GetTypeID(), GetInstanceID());
#endif

if (StartMessageIds[BG_STARTING_EVENT_FOURTH])
Expand Down Expand Up @@ -815,7 +818,8 @@ void Battleground::EndBattleground(uint32 winner)
}
#ifdef ELUNA
//the type of the winner,change Team to BattlegroundTeamId,it could be better.
sEluna->OnBGEnd(this, GetTypeID(), GetInstanceID(), Team(winner));
if (Eluna* e = GetBgMap()->GetEluna())
e->OnBGEnd(this, GetTypeID(), GetInstanceID(), Team(winner));
#endif
}

Expand Down Expand Up @@ -990,7 +994,8 @@ void Battleground::StartBattleground()
sBattlegroundMgr->AddBattleground(this);

#ifdef ELUNA
sEluna->OnBGCreate(this, GetTypeID(), GetInstanceID());
if (Eluna* e = GetBgMap()->GetEluna())
e->OnBGCreate(this, GetTypeID(), GetInstanceID());
#endif

if (m_IsRated)
Expand Down
4 changes: 2 additions & 2 deletions src/server/game/Chat/ChatCommands/ChatCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ namespace Trinity::Impl::ChatCommands
else if (!handler.HasSentErrorMessage())
{ /* invocation failed, we should show usage */
#ifdef ELUNA
if (!sEluna->OnCommand(handler.IsConsole() ? NULL : handler.GetSession()->GetPlayer(), std::string(cmdStr).c_str()))
if (!sWorld->GetEluna()->OnCommand(handler.IsConsole() ? nullptr : handler.GetSession()->GetPlayer(), std::string(cmdStr).c_str()))
return true;
#endif
cmd->SendCommandHelp(handler);
Expand All @@ -312,7 +312,7 @@ namespace Trinity::Impl::ChatCommands
}

#ifdef ELUNA
if (!sEluna->OnCommand(handler.IsConsole() ? NULL : handler.GetSession()->GetPlayer(), std::string(cmdStr).c_str()))
if (!sWorld->GetEluna()->OnCommand(handler.IsConsole() ? nullptr : handler.GetSession()->GetPlayer(), std::string(cmdStr).c_str()))
return true;
#endif

Expand Down
15 changes: 10 additions & 5 deletions src/server/game/Combat/CombatManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,14 @@ void CombatReference::EndCombat()
if (needFirstAI)
{
if (Player* player = first->ToPlayer())
sEluna->OnPlayerLeaveCombat(player);
if (Eluna* e = first->GetEluna())
e->OnPlayerLeaveCombat(player);
}
if (needSecondAI)
{
if (Player* player = second->ToPlayer())
sEluna->OnPlayerLeaveCombat(player);
if (Eluna* e = second->GetEluna())
e->OnPlayerLeaveCombat(player);
}
#endif
if (needFirstAI)
Expand Down Expand Up @@ -128,7 +130,8 @@ void CombatReference::SuppressFor(Unit* who)
{
#ifdef ELUNA
if (Player* player = who->ToPlayer())
sEluna->OnPlayerLeaveCombat(player);
if (Eluna* e = player->GetEluna())
e->OnPlayerLeaveCombat(player);
#endif
if (UnitAI* ai = who->GetAI())
ai->JustExitedCombat();
Expand Down Expand Up @@ -325,7 +328,8 @@ void CombatManager::SuppressPvPCombat()
{
#ifdef ELUNA
if (Player* player = _owner->ToPlayer())
sEluna->OnPlayerLeaveCombat(player);
if (Eluna* e = player->GetEluna())
e->OnPlayerLeaveCombat(player);
#endif
if (UnitAI* ownerAI = _owner->GetAI())
ownerAI->JustExitedCombat();
Expand Down Expand Up @@ -380,7 +384,8 @@ void CombatManager::EndAllPvPCombat()
{
#ifdef ELUNA
if (Player* player = me->ToPlayer())
sEluna->OnPlayerEnterCombat(player, other);
if (Eluna* e = player->GetEluna())
e->OnPlayerEnterCombat(player, other);
#endif
if (UnitAI* ai = me->GetAI())
ai->JustEnteredCombat(other);
Expand Down
6 changes: 4 additions & 2 deletions src/server/game/Entities/Creature/Creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,8 @@ void Creature::AddToWorld()
GetZoneScript()->OnCreatureCreate(this);

#ifdef ELUNA
sEluna->OnAddToWorld(this);
if (Eluna* e = GetEluna())
e->OnAddToWorld(this);
#endif
}
}
Expand All @@ -306,7 +307,8 @@ void Creature::RemoveFromWorld()
if (IsInWorld())
{
#ifdef ELUNA
sEluna->OnRemoveFromWorld(this);
if (Eluna* e = GetEluna())
e->OnRemoveFromWorld(this);
#endif
if (GetZoneScript())
GetZoneScript()->OnCreatureRemove(this);
Expand Down
26 changes: 17 additions & 9 deletions src/server/game/Entities/GameObject/GameObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,8 @@ void GameObject::AddToWorld()
WorldObject::AddToWorld();

#ifdef ELUNA
sEluna->OnAddToWorld(this);
if (Eluna* e = GetEluna())
e->OnAddToWorld(this);
#endif
}
}
Expand All @@ -242,7 +243,8 @@ void GameObject::RemoveFromWorld()
if (IsInWorld())
{
#ifdef ELUNA
sEluna->OnRemoveFromWorld(this);
if (Eluna* e = GetEluna())
e->OnRemoveFromWorld(this);
#endif
if (m_zoneScript)
m_zoneScript->OnGameObjectRemove(this);
Expand Down Expand Up @@ -462,7 +464,8 @@ bool GameObject::Create(ObjectGuid::LowType guidlow, uint32 name_id, Map* map, u
void GameObject::Update(uint32 diff)
{
#ifdef ELUNA
sEluna->UpdateAI(this, diff);
if (Eluna* e = GetEluna())
e->UpdateAI(this, diff);
#endif
m_Events.Update(diff);

Expand Down Expand Up @@ -1634,8 +1637,9 @@ void GameObject::Use(Unit* user)
playerUser->PlayerTalkClass->ClearMenus();

#ifdef ELUNA
if (sEluna->OnGossipHello(playerUser, this))
return;
if (Eluna* e = GetEluna())
if (e->OnGossipHello(playerUser, this))
return;
#endif
if (AI()->OnGossipHello(playerUser))
return;
Expand Down Expand Up @@ -2426,7 +2430,8 @@ void GameObject::SetDestructibleState(GameObjectDestructibleState state, WorldOb
case GO_DESTRUCTIBLE_DAMAGED:
{
#ifdef ELUNA
sEluna->OnDamaged(this, attackerOrHealer);
if (Eluna* e = GetEluna())
e->OnDamaged(this, attackerOrHealer);
#endif
EventInform(m_goInfo->building.damagedEvent, attackerOrHealer);
AI()->Damaged(attackerOrHealer, m_goInfo->building.damagedEvent);
Expand Down Expand Up @@ -2454,7 +2459,8 @@ void GameObject::SetDestructibleState(GameObjectDestructibleState state, WorldOb
case GO_DESTRUCTIBLE_DESTROYED:
{
#ifdef ELUNA
sEluna->OnDestroyed(this, attackerOrHealer);
if (Eluna* e = GetEluna())
e->OnDestroyed(this, attackerOrHealer);
#endif
EventInform(m_goInfo->building.destroyedEvent, attackerOrHealer);
AI()->Destroyed(attackerOrHealer, m_goInfo->building.destroyedEvent);
Expand Down Expand Up @@ -2512,7 +2518,8 @@ void GameObject::SetLootState(LootState state, Unit* unit)
m_lootStateUnitGUID.Clear();

#ifdef ELUNA
sEluna->OnLootStateChanged(this, state);
if (Eluna* e = GetEluna())
e->OnLootStateChanged(this, state);
#endif
AI()->OnLootStateChanged(state, unit);

Expand Down Expand Up @@ -2543,7 +2550,8 @@ void GameObject::SetGoState(GOState state)
{
SetByteValue(GAMEOBJECT_BYTES_1, 0, state);
#ifdef ELUNA
sEluna->OnGameObjectStateChanged(this, state);
if (Eluna* e = GetEluna())
e->OnGameObjectStateChanged(this, state);
#endif
if (AI())
AI()->OnStateChanged(state);
Expand Down
30 changes: 27 additions & 3 deletions src/server/game/Entities/Object/Object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "CellImpl.h"
#include "CinematicMgr.h"
#include "Common.h"
#include "Config.h"
#include "Creature.h"
#include "GameTime.h"
#include "GridNotifiersImpl.h"
Expand Down Expand Up @@ -1057,7 +1058,8 @@ void WorldObject::CleanupsBeforeDelete(bool /*finalCleanup*/)
void WorldObject::Update (uint32 time_diff)
{
#ifdef ELUNA
elunaEvents->Update(time_diff);
if(elunaEvents) // can be null on maps without eluna
elunaEvents->Update(time_diff);
#endif
}

Expand Down Expand Up @@ -1840,8 +1842,20 @@ void WorldObject::SetMap(Map* map)
m_InstanceId = map->GetInstanceId();

#ifdef ELUNA
if (!elunaEvents)
elunaEvents = new ElunaEventProcessor(&Eluna::GEluna, this);
//@todo: possibly look into cleanly clearing all pending events from previous map's event mgr.

// if multistate, delete elunaEvents and set to nullptr. events shouldn't move across states.
// in single state, the timed events should move across maps
bool compatMode = sConfigMgr->GetBoolDefault("Eluna.CompatibilityMode", true);
if (!compatMode)
{
delete elunaEvents;
elunaEvents = nullptr; // set to null in case map doesn't use eluna
}

if(Eluna * e = map->GetEluna())
if(!elunaEvents)
elunaEvents = new ElunaEventProcessor(e, this);
#endif

if (IsWorldObject())
Expand Down Expand Up @@ -3587,6 +3601,16 @@ std::string WorldObject::GetDebugInfo() const
return sstr.str();
}

#ifdef ELUNA
Eluna* WorldObject::GetEluna() const
{
if (IsInWorld())
return GetMap()->GetEluna();

return nullptr;
}
#endif

template TC_GAME_API void WorldObject::GetGameObjectListWithEntryInGrid(std::list<GameObject*>&, uint32, float) const;
template TC_GAME_API void WorldObject::GetGameObjectListWithEntryInGrid(std::deque<GameObject*>&, uint32, float) const;
template TC_GAME_API void WorldObject::GetGameObjectListWithEntryInGrid(std::vector<GameObject*>&, uint32, float) const;
Expand Down
8 changes: 8 additions & 0 deletions src/server/game/Entities/Object/Object.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
#include <list>
#include <set>
#include <unordered_map>
#ifdef ELUNA
#include "LuaValue.h"
#endif

class Corpse;
class Creature;
Expand All @@ -56,6 +59,7 @@ class WorldPacket;
class ZoneScript;
#ifdef ELUNA
class ElunaEventProcessor;
class Eluna;
#endif
struct FactionTemplateEntry;
struct PositionFullTerrainStatus;
Expand Down Expand Up @@ -501,6 +505,10 @@ class TC_GAME_API WorldObject : public Object, public WorldLocation

#ifdef ELUNA
ElunaEventProcessor* elunaEvents;

Eluna* GetEluna() const;

LuaVal lua_data = LuaVal({});
#endif

// Transports
Expand Down
Loading

0 comments on commit fb48e0c

Please sign in to comment.