mirror of
https://github.com/EQEmu/Server.git
synced 2026-05-16 22:58:34 +00:00
[Expeditions] Create common dz abstract class (#1312)
This creates an abstract class in common so zone and world can share most of the implementation. World now has access to the same dz data and api as zone. Rename CharacterChange to AddRemoveCharacter for clarity Rename GetRemainingDuration to GetDurationRemaining for consistency Move dynamic zone queries to custom repository methods
This commit is contained in:
+58
-10
@@ -12,16 +12,21 @@ extern ZSList zoneserver_list;
|
||||
DynamicZone::DynamicZone(
|
||||
uint32_t id, uint32_t zone_id, uint32_t instance_id, uint32_t zone_version,
|
||||
uint32_t start_time, uint32_t duration, DynamicZoneType type
|
||||
) :
|
||||
m_id(id),
|
||||
m_instance_id(instance_id),
|
||||
m_zone_id(zone_id),
|
||||
m_zone_version(zone_version),
|
||||
m_start_time(std::chrono::system_clock::from_time_t(start_time)),
|
||||
m_duration(duration),
|
||||
m_type(type),
|
||||
m_expire_time(m_start_time + m_duration)
|
||||
)
|
||||
{
|
||||
m_id = id;
|
||||
m_instance_id = instance_id;
|
||||
m_zone_id = zone_id;
|
||||
m_zone_version = zone_version;
|
||||
m_start_time = std::chrono::system_clock::from_time_t(start_time);
|
||||
m_duration = std::chrono::seconds(duration);
|
||||
m_type = type;
|
||||
m_expire_time = m_start_time + m_duration;
|
||||
}
|
||||
|
||||
Database& DynamicZone::GetDatabase()
|
||||
{
|
||||
return database;
|
||||
}
|
||||
|
||||
DynamicZone* DynamicZone::FindDynamicZoneByID(uint32_t dz_id)
|
||||
@@ -99,10 +104,27 @@ void DynamicZone::HandleZoneMessage(ServerPacket* pack)
|
||||
case ServerOP_DzSetSafeReturn:
|
||||
case ServerOP_DzSetZoneIn:
|
||||
{
|
||||
auto buf = reinterpret_cast<ServerDzLocation_Struct*>(pack->pBuffer);
|
||||
auto dz = DynamicZone::FindDynamicZoneByID(buf->dz_id);
|
||||
if (dz)
|
||||
{
|
||||
if (pack->opcode == ServerOP_DzSetCompass)
|
||||
{
|
||||
dz->SetCompass(buf->zone_id, buf->x, buf->y, buf->z, false);
|
||||
}
|
||||
else if (pack->opcode == ServerOP_DzSetSafeReturn)
|
||||
{
|
||||
dz->SetSafeReturn(buf->zone_id, buf->x, buf->y, buf->z, buf->heading, false);
|
||||
}
|
||||
else if (pack->opcode == ServerOP_DzSetZoneIn)
|
||||
{
|
||||
dz->SetZoneInLocation(buf->x, buf->y, buf->z, buf->heading, false);
|
||||
}
|
||||
}
|
||||
zoneserver_list.SendPacket(pack);
|
||||
break;
|
||||
}
|
||||
case ServerOP_DzCharacterChange:
|
||||
case ServerOP_DzAddRemoveCharacter:
|
||||
case ServerOP_DzRemoveAllCharacters:
|
||||
{
|
||||
auto buf = reinterpret_cast<ServerDzCharacter_Struct*>(pack->pBuffer);
|
||||
@@ -125,3 +147,29 @@ void DynamicZone::HandleZoneMessage(ServerPacket* pack)
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
void DynamicZone::SendInstanceAddRemoveCharacter(uint32_t character_id, bool remove)
|
||||
{
|
||||
ZoneServer* instance_zs = zoneserver_list.FindByInstanceID(GetInstanceID());
|
||||
if (instance_zs)
|
||||
{
|
||||
auto pack = CreateServerAddRemoveCharacterPacket(character_id, remove);
|
||||
instance_zs->SendPacket(pack.get());
|
||||
}
|
||||
}
|
||||
|
||||
void DynamicZone::SendInstanceRemoveAllCharacters()
|
||||
{
|
||||
ZoneServer* instance_zs = zoneserver_list.FindByInstanceID(GetInstanceID());
|
||||
if (instance_zs)
|
||||
{
|
||||
auto pack = CreateServerRemoveAllCharactersPacket();
|
||||
instance_zs->SendPacket(pack.get());
|
||||
}
|
||||
}
|
||||
|
||||
void DynamicZone::SendGlobalLocationChange(uint16_t server_opcode, const DynamicZoneLocation& location)
|
||||
{
|
||||
auto pack = CreateServerDzLocationPacket(server_opcode, location);
|
||||
zoneserver_list.SendPacket(pack.get());
|
||||
}
|
||||
|
||||
+12
-19
@@ -1,9 +1,9 @@
|
||||
#ifndef WORLD_DYNAMIC_ZONE_H
|
||||
#define WORLD_DYNAMIC_ZONE_H
|
||||
|
||||
#include "../common/eq_constants.h"
|
||||
#include <chrono>
|
||||
#include "../common/dynamic_zone_base.h"
|
||||
|
||||
class Database;
|
||||
class ServerPacket;
|
||||
|
||||
enum class DynamicZoneStatus
|
||||
@@ -14,9 +14,11 @@ enum class DynamicZoneStatus
|
||||
ExpiredEmpty,
|
||||
};
|
||||
|
||||
class DynamicZone
|
||||
class DynamicZone : public DynamicZoneBase
|
||||
{
|
||||
public:
|
||||
using DynamicZoneBase::DynamicZoneBase; // inherit base constructors
|
||||
|
||||
DynamicZone() = default;
|
||||
DynamicZone(uint32_t id, uint32_t zone_id, uint32_t instance_id, uint32_t zone_version,
|
||||
uint32_t start_time, uint32_t duration, DynamicZoneType type);
|
||||
@@ -24,29 +26,20 @@ public:
|
||||
static DynamicZone* FindDynamicZoneByID(uint32_t dz_id);
|
||||
static void HandleZoneMessage(ServerPacket* pack);
|
||||
|
||||
uint32_t GetID() const { return m_id; }
|
||||
uint16_t GetInstanceID() const { return static_cast<uint16_t>(m_instance_id); }
|
||||
uint16_t GetZoneID() const { return static_cast<uint16_t>(m_zone_id); }
|
||||
uint32_t GetZoneVersion() const { return m_zone_version; }
|
||||
std::chrono::system_clock::duration GetRemainingDuration() const {
|
||||
return m_expire_time - std::chrono::system_clock::now(); }
|
||||
void SetSecondsRemaining(uint32_t seconds_remaining) override;
|
||||
|
||||
DynamicZoneStatus Process(bool force_expire);
|
||||
bool IsExpired() const { return m_expire_time < std::chrono::system_clock::now(); }
|
||||
void SetSecondsRemaining(uint32_t seconds_remaining);
|
||||
|
||||
protected:
|
||||
Database& GetDatabase() override;
|
||||
void SendInstanceAddRemoveCharacter(uint32_t character_id, bool remove) override;
|
||||
void SendInstanceRemoveAllCharacters() override;
|
||||
void SendGlobalLocationChange(uint16_t server_opcode, const DynamicZoneLocation& location) override;
|
||||
|
||||
private:
|
||||
void SendZonesDurationUpdate();
|
||||
|
||||
uint32_t m_id = 0;
|
||||
uint32_t m_instance_id = 0;
|
||||
uint32_t m_zone_id = 0;
|
||||
uint32_t m_zone_version = 0;
|
||||
bool m_is_pending_early_shutdown = false;
|
||||
DynamicZoneType m_type{ DynamicZoneType::None };
|
||||
std::chrono::seconds m_duration;
|
||||
std::chrono::time_point<std::chrono::system_clock> m_start_time;
|
||||
std::chrono::time_point<std::chrono::system_clock> m_expire_time;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -142,7 +142,7 @@ void Expedition::CheckExpireWarning()
|
||||
if (m_warning_cooldown_timer.Check(false))
|
||||
{
|
||||
using namespace std::chrono_literals;
|
||||
auto remaining = GetDynamicZone().GetRemainingDuration();
|
||||
auto remaining = GetDynamicZone().GetDurationRemaining();
|
||||
if ((remaining > 14min && remaining < 15min) ||
|
||||
(remaining > 4min && remaining < 5min) ||
|
||||
(remaining > 0min && remaining < 1min))
|
||||
|
||||
@@ -1388,7 +1388,7 @@ void ZoneServer::HandleMessage(uint16 opcode, const EQ::Net::Packet &p) {
|
||||
ExpeditionMessage::HandleZoneMessage(pack);
|
||||
break;
|
||||
}
|
||||
case ServerOP_DzCharacterChange:
|
||||
case ServerOP_DzAddRemoveCharacter:
|
||||
case ServerOP_DzRemoveAllCharacters:
|
||||
case ServerOP_DzSetSecondsRemaining:
|
||||
case ServerOP_DzSetCompass:
|
||||
|
||||
Reference in New Issue
Block a user