mirror of
https://github.com/EQEmu/Server.git
synced 2026-09-03 01:06:36 +00:00
[Expeditions] Decouple dz updates from expeditions (#1303)
Use internal dz messages to process duration and location changes Add world DynamicZone class (later this will inherit from a base) Add FindDynamicZoneByID to get dz from zone and world system caches
This commit is contained in:
+4
-52
@@ -30,28 +30,19 @@
|
||||
extern ClientList client_list;
|
||||
extern ZSList zoneserver_list;
|
||||
|
||||
Expedition::Expedition(uint32_t expedition_id, uint32_t dz_id, uint32_t dz_instance_id,
|
||||
uint32_t dz_zone_id, uint32_t start_time, uint32_t duration, uint32_t leader_id
|
||||
Expedition::Expedition(uint32_t expedition_id, const DynamicZone& dz, uint32_t leader_id
|
||||
) :
|
||||
m_expedition_id(expedition_id),
|
||||
m_dz_id(dz_id),
|
||||
m_dz_instance_id(dz_instance_id),
|
||||
m_dz_zone_id(dz_zone_id),
|
||||
m_start_time(std::chrono::system_clock::from_time_t(start_time)),
|
||||
m_duration(duration),
|
||||
m_dynamic_zone(dz),
|
||||
m_leader_id(leader_id),
|
||||
m_choose_leader_cooldown_timer{ static_cast<uint32_t>(RuleI(Expedition, ChooseLeaderCooldownTime)) }
|
||||
{
|
||||
m_expire_time = m_start_time + m_duration;
|
||||
m_warning_cooldown_timer.Enable();
|
||||
}
|
||||
|
||||
void Expedition::AddMember(uint32_t character_id)
|
||||
{
|
||||
auto it = std::find_if(m_member_ids.begin(), m_member_ids.end(),
|
||||
[&](uint32_t member_id) { return member_id == character_id; });
|
||||
|
||||
if (it == m_member_ids.end())
|
||||
if (!HasMember(character_id))
|
||||
{
|
||||
m_member_ids.emplace_back(character_id);
|
||||
}
|
||||
@@ -126,16 +117,6 @@ void Expedition::SendZonesExpeditionDeleted()
|
||||
zoneserver_list.SendPacket(pack.get());
|
||||
}
|
||||
|
||||
void Expedition::SendZonesDurationUpdate()
|
||||
{
|
||||
uint32_t packsize = sizeof(ServerExpeditionUpdateDuration_Struct);
|
||||
auto pack = std::make_unique<ServerPacket>(ServerOP_ExpeditionDzDuration, packsize);
|
||||
auto packbuf = reinterpret_cast<ServerExpeditionUpdateDuration_Struct*>(pack->pBuffer);
|
||||
packbuf->expedition_id = GetID();
|
||||
packbuf->new_duration_seconds = static_cast<uint32_t>(m_duration.count());
|
||||
zoneserver_list.SendPacket(pack.get());
|
||||
}
|
||||
|
||||
void Expedition::SendZonesExpireWarning(uint32_t minutes_remaining)
|
||||
{
|
||||
uint32_t pack_size = sizeof(ServerExpeditionExpireWarning_Struct);
|
||||
@@ -156,41 +137,12 @@ void Expedition::SendZonesLeaderChanged()
|
||||
zoneserver_list.SendPacket(pack.get());
|
||||
}
|
||||
|
||||
void Expedition::UpdateDzSecondsRemaining(uint32_t seconds_remaining)
|
||||
{
|
||||
auto now = std::chrono::system_clock::now();
|
||||
auto update_time = std::chrono::seconds(seconds_remaining);
|
||||
|
||||
auto current_remaining = m_expire_time - now;
|
||||
if (current_remaining > update_time) // reduce only
|
||||
{
|
||||
LogExpeditionsDetail(
|
||||
"Updating expedition [{}] dz instance [{}] seconds remaining to [{}]s",
|
||||
GetID(), GetInstanceID(), seconds_remaining
|
||||
);
|
||||
|
||||
// preserve original start time and adjust duration instead
|
||||
m_expire_time = now + update_time;
|
||||
m_duration = std::chrono::duration_cast<std::chrono::seconds>(m_expire_time - m_start_time);
|
||||
|
||||
ExpeditionDatabase::UpdateDzDuration(GetInstanceID(), static_cast<uint32_t>(m_duration.count()));
|
||||
|
||||
// update zone level caches and update the actual dz instance's timer
|
||||
SendZonesDurationUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
std::chrono::system_clock::duration Expedition::GetRemainingDuration() const
|
||||
{
|
||||
return m_expire_time - std::chrono::system_clock::now();
|
||||
}
|
||||
|
||||
void Expedition::CheckExpireWarning()
|
||||
{
|
||||
if (m_warning_cooldown_timer.Check(false))
|
||||
{
|
||||
using namespace std::chrono_literals;
|
||||
auto remaining = GetRemainingDuration();
|
||||
auto remaining = GetDynamicZone().GetRemainingDuration();
|
||||
if ((remaining > 14min && remaining < 15min) ||
|
||||
(remaining > 4min && remaining < 5min) ||
|
||||
(remaining > 0min && remaining < 1min))
|
||||
|
||||
Reference in New Issue
Block a user