[Doors] Fix doors triggering invalid zone fetches of dest_zone of "none" (#2985)

* [Doors] Fix doors triggering invalid zone fetches of dest_zone of "none"

* Update doors.cpp

* Tweaks

* PR comments
This commit is contained in:
Chris Miles 2023-02-24 13:22:56 -06:00 committed by GitHub
parent 04fdc54522
commit 7519b0225e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 18 deletions

View File

@ -53,6 +53,14 @@ Doors::Doors(const DoorsRepository::Doors &door) :
strn0cpy(m_door_name, door.name.c_str(), sizeof(m_door_name));
strn0cpy(m_destination_zone_name, door.dest_zone.c_str(), sizeof(m_destination_zone_name));
// destination helpers
if (!door.dest_zone.empty() && Strings::ToLower(door.dest_zone) != "none" && !door.dest_zone.empty()) {
m_has_destination_zone = true;
}
if (!door.dest_zone.empty() && !door.zone.empty() && Strings::EqualFold(door.dest_zone, door.zone)) {
m_same_destination_zone = true;
}
m_database_id = door.id;
m_door_id = door.doorid;
m_incline = door.incline;
@ -450,7 +458,7 @@ void Doors::HandleClick(Client *sender, uint8 trigger)
m_close_timer.Start();
}
if (strncmp(m_destination_zone_name, "NONE", strlen("NONE")) == 0) {
if (!HasDestinationZone()) {
SetOpenState(true);
}
}
@ -497,19 +505,15 @@ void Doors::HandleClick(Client *sender, uint8 trigger)
}
}
/**
* Teleport door
*/
if (((m_open_type == 57) || (m_open_type == 58)) &&
(strncmp(m_destination_zone_name, "NONE", strlen("NONE")) != 0)) {
// teleport door
if (((m_open_type == 57) || (m_open_type == 58)) && HasDestinationZone()) {
bool has_key_required = (required_key_item && ((required_key_item == player_key) || sender->GetGM()));
/**
* If click destination is same zone and doesn't require a key
*/
if ((strncmp(m_destination_zone_name, m_zone_name, strlen(m_zone_name)) == 0) && (!required_key_item)) {
if (IsDestinationZoneSame() && (!required_key_item)) {
if (!disable_add_to_key_ring) {
sender->KeyRingAdd(player_key);
}
sender->MovePC(
zone->GetZoneID(),
zone->GetInstanceID(),
@ -519,14 +523,7 @@ void Doors::HandleClick(Client *sender, uint8 trigger)
m_destination.w
);
}
/**
* If requires a key
*/
else if (
(!IsDoorOpen() || m_open_type == 58) &&
(required_key_item && ((required_key_item == player_key) || sender->GetGM()))
) {
else if ((!IsDoorOpen() || m_open_type == 58) && has_key_required) {
if (!disable_add_to_key_ring) {
sender->KeyRingAdd(player_key);
}
@ -896,3 +893,13 @@ float Doors::GetHeading()
{
return m_position.w;
}
bool Doors::HasDestinationZone() const
{
return m_has_destination_zone;
}
bool Doors::IsDestinationZoneSame() const
{
return m_same_destination_zone;
}

View File

@ -67,8 +67,13 @@ public:
float GetZ();
float GetHeading();
bool HasDestinationZone() const;
bool IsDestinationZoneSame() const;
private:
bool m_has_destination_zone = false;
bool m_same_destination_zone = false;
uint32 m_database_id;
uint8 m_door_id;
char m_zone_name[32];