Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zone Sleep time changed to 15min #7110

Open
wants to merge 3 commits into
base: base
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 43 additions & 3 deletions src/map/zone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,41 @@ void CZone::UpdateWeather()
// clang-format on
}

void CZone::CheckMobsPathedBack()
{
// clang-format off
CTaskMgr::getInstance()->AddTask("zone_empty_timer", server_clock::now(), this, CTaskMgr::TASK_INTERVAL, 5s,
[](time_point tick, CTaskMgr::CTask* PTask)
{
bool allMobsHome = true;
// if the timer runs out, check if all the mobs have pathed home
CZone* PZone = std::any_cast<CZone*>(PTask->m_data);
if (PZone && PZone->GetZoneEntities())
{
EntityList_t mobListMap = PZone->GetZoneEntities()->GetMobList();
for (const auto& pair : mobListMap)
{
CMobEntity* mob = dynamic_cast<CMobEntity*>(pair.second);
if (mob && mob->IsFarFromHome())
{
// at least one mob is away from home
allMobsHome = false;
break;
}
}
}

// if all mobs home, sleep the zone, @todo and stop timer?
if (allMobsHome)
{
PZone->SleepZone();
}

return 0;
});
// clang-format on
}

/************************************************************************
* *
* Remove a character from the zone. If ZoneServer and character are *
Expand All @@ -706,7 +741,7 @@ void CZone::DecreaseZoneCounter(CCharEntity* PChar)

if (m_zoneEntities->CharListEmpty())
{
m_timeZoneEmpty = server_clock::now();
CheckMobsPathedBack();
}
else
{
Expand Down Expand Up @@ -747,6 +782,9 @@ void CZone::IncreaseZoneCounter(CCharEntity* PChar)
if (!ZoneTimer && !m_zoneEntities->CharListEmpty())
{
createZoneTimers();

// the zone is active again, remove the timer, if its still going
CTaskMgr::getInstance()->RemoveTask("zone_empty_timer");
}

PChar->StatusEffectContainer->DelStatusEffectsByFlag(EFFECTFLAG_ON_ZONE_PATHOS, true);
Expand Down Expand Up @@ -901,8 +939,10 @@ void CZone::ZoneServer(time_point tick)
{
m_BattlefieldHandler->HandleBattlefields(tick);
}

if (ZoneTimer && m_zoneEntities->CharListEmpty() && m_timeZoneEmpty + 5s < server_clock::now())
}
void CZone::SleepZone()
{
if (ZoneTimer && m_zoneEntities->CharListEmpty())
{
ZoneTimer->m_type = CTaskMgr::TASK_REMOVE;
ZoneTimer = nullptr;
Expand Down
4 changes: 2 additions & 2 deletions src/map/zone.h
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,8 @@ class CZone
bool CanUseMisc(uint16 misc) const;
void SetWeather(WEATHER weatherCondition);
void UpdateWeather();
void CheckMobsPathedBack();
void SleepZone();

virtual void SpawnPCs(CCharEntity* PChar);
virtual void SpawnMOBs(CCharEntity* PChar);
Expand Down Expand Up @@ -680,8 +682,6 @@ class CZone

CTreasurePool* m_TreasurePool;

time_point m_timeZoneEmpty; // The time point when the last player left the zone

std::unordered_map<std::string, QueryByNameResult_t> m_queryByNameResults;

protected:
Expand Down