Get dz safe return from cache not db

This was loading the dz from database to get safe return data every time
a client's dz removal timer triggered

Add the Zone::GetDynamicZone() method so zones that are dz instances can
find the data from the cache of any dz systems
This commit is contained in:
hg 2020-07-16 19:37:51 -04:00
parent fba078bbe9
commit 6e5ca19d18
6 changed files with 27 additions and 7 deletions

View File

@ -9883,13 +9883,14 @@ void Client::SendDzCompassUpdate()
QueuePacket(outapp.get());
}
void Client::GoToDzSafeReturnOrBind(const DynamicZoneLocation& safereturn)
void Client::GoToDzSafeReturnOrBind(const DynamicZone& dynamic_zone)
{
auto safereturn = dynamic_zone.GetSafeReturnLocation();
LogDynamicZonesDetail(
"Sending character [{}] to safereturn zone [{}] or bind", CharacterID(), safereturn.zone_id
);
if (safereturn.zone_id == 0)
if (!dynamic_zone.IsValid() || safereturn.zone_id == 0)
{
GoToBind();
}

View File

@ -1145,7 +1145,7 @@ public:
void DzListTimers();
void SetDzRemovalTimer(bool enable_timer);
void SendDzCompassUpdate();
void GoToDzSafeReturnOrBind(const DynamicZoneLocation& safereturn);
void GoToDzSafeReturnOrBind(const DynamicZone& dynamic_zone);
void MovePCDynamicZone(uint32 zone_id);
void MovePCDynamicZone(const std::string& zone_name);

View File

@ -164,8 +164,7 @@ bool Client::Process() {
if (dynamiczone_removal_timer.Check() && zone && zone->GetInstanceID() != 0)
{
dynamiczone_removal_timer.Disable();
DynamicZone dz = DynamicZone::LoadDzFromDatabase(zone->GetInstanceID());
GoToDzSafeReturnOrBind(dz.GetSafeReturnLocation());
GoToDzSafeReturnOrBind(zone->GetDynamicZone());
}
if (linkdead_timer.Check()) {

View File

@ -5208,7 +5208,7 @@ void EntityList::GateAllClientsToSafeReturn()
DynamicZone dz;
if (zone)
{
dz = DynamicZone::LoadDzFromDatabase(zone->GetInstanceID());
dz = zone->GetDynamicZone();
LogDynamicZones(
"Sending all clients in zone: [{}] instance: [{}] to dz safereturn or bind",
@ -5221,7 +5221,7 @@ void EntityList::GateAllClientsToSafeReturn()
if (client_list_iter.second)
{
// falls back to gating clients to bind if dz invalid
client_list_iter.second->GoToDzSafeReturnOrBind(dz.GetSafeReturnLocation());
client_list_iter.second->GoToDzSafeReturnOrBind(dz);
}
}
}

View File

@ -2714,3 +2714,21 @@ bool Zone::IsZone(uint32 zone_id, uint16 instance_id) const
{
return (zoneid == zone_id && instanceid == instance_id);
}
DynamicZone Zone::GetDynamicZone()
{
if (GetInstanceID() == 0)
{
return {}; // invalid
}
auto expedition = Expedition::FindCachedExpeditionByInstanceID(GetInstanceID());
if (expedition)
{
return expedition->GetDynamicZone();
}
// todo: tasks, missions, and quests with an associated dz for this instance id
return {}; // invalid
}

View File

@ -33,6 +33,7 @@
#include "spawn2.h"
#include "spawngroup.h"
#include "aa_ability.h"
#include "dynamiczone.h"
#include "pathfinder_interface.h"
#include "global_loot_manager.h"
@ -177,6 +178,7 @@ public:
void DumpMerchantList(uint32 npcid);
int SaveTempItem(uint32 merchantid, uint32 npcid, uint32 item, int32 charges, bool sold = false);
int32 MobsAggroCount() { return aggroedmobs; }
DynamicZone GetDynamicZone();
IPathfinder *pathing;
LinkedList<NPC_Emote_Struct *> NPCEmoteList;