Fix initialization issues with loading 'disable_timer' from the database for doors

This commit is contained in:
Akkadius 2017-04-10 19:55:17 -05:00
parent 080f6c5c3e
commit b5b6145786
4 changed files with 102 additions and 82 deletions

View File

@ -70,6 +70,8 @@ m_Destination(door->dest_x, door->dest_y, door->dest_z, door->dest_heading)
is_ldon_door = door->is_ldon_door;
client_version_mask = door->client_version_mask;
disable_timer = (door->disable_timer == 1 ? true : false);
}
Doors::Doors(const char *dmodel, const glm::vec4& position, uint8 dopentype, uint16 dsize) :
@ -102,6 +104,8 @@ m_Destination(glm::vec4())
is_ldon_door = 0;
client_version_mask = 4294967295u;
disable_timer = 0;
}
@ -458,21 +462,21 @@ void Doors::NPCOpen(NPC* sender, bool alt_mode)
safe_delete(outapp);
if (!alt_mode) { // original function
if(!isopen) {
if (!is_open) {
if (!disable_timer)
close_timer.Start();
isopen=true;
is_open = true;
}
else {
close_timer.Disable();
if (!disable_timer)
isopen=false;
is_open = false;
}
}
else { // alternative function
if (!disable_timer)
close_timer.Start();
isopen=true;
is_open = true;
}
}
}
@ -487,21 +491,21 @@ void Doors::ForceOpen(Mob *sender, bool alt_mode)
safe_delete(outapp);
if (!alt_mode) { // original function
if(!isopen) {
if (!is_open) {
if (!disable_timer)
close_timer.Start();
isopen=true;
is_open = true;
}
else {
close_timer.Disable();
if (!disable_timer)
isopen=false;
is_open = false;
}
}
else { // alternative function
if (!disable_timer)
close_timer.Start();
isopen=true;
is_open = true;
}
}
@ -515,18 +519,18 @@ void Doors::ForceClose(Mob *sender, bool alt_mode)
safe_delete(outapp);
if (!alt_mode) { // original function
if(!isopen) {
if (!is_open) {
if (!disable_timer)
close_timer.Start();
isopen=true;
is_open = true;
}
else {
close_timer.Disable();
isopen=false;
is_open = false;
}
}
else { // alternative function
if(isopen)
if (is_open)
close_timer.Trigger();
}
}
@ -541,14 +545,14 @@ void Doors::ToggleState(Mob *sender)
MoveDoor_Struct* md=(MoveDoor_Struct*)outapp->pBuffer;
md->doorid = door_id;
if(!isopen) {
if(!is_open) {
md->action = invert_state == 0 ? OPEN_DOOR : OPEN_INVDOOR;
isopen=true;
is_open=true;
}
else
{
md->action = invert_state == 0 ? CLOSE_DOOR : CLOSE_INVDOOR;
isopen=false;
is_open=false;
}
entity_list.QueueClients(sender,outapp,false);
@ -561,7 +565,7 @@ void Doors::DumpDoor(){
db_id, door_id, zone_name, door_name, to_string(m_Position).c_str());
Log(Logs::General, Logs::None,
"opentype:%i guild_id:%i lockpick:%i keyitem:%i nokeyring:%i trigger_door:%i trigger_type:%i door_param:%i open:%s",
opentype, guild_id, lockpick, keyitem, nokeyring, trigger_door, trigger_type, door_param, (isopen) ? "open":"closed");
opentype, guild_id, lockpick, keyitem, nokeyring, trigger_door, trigger_type, door_param, (is_open) ? "open":"closed");
Log(Logs::General, Logs::None,
"dest_zone:%s destination:%s ",
dest_zone, to_string(m_Destination).c_str());
@ -665,8 +669,6 @@ bool ZoneDatabase::LoadDoors(int32 iDoorCount, Door *into, const char *zone_name
into[rowIndex].db_id = atoi(row[0]);
into[rowIndex].door_id = atoi(row[1]);
Log(Logs::Detail, Logs::Doors, "Door Load: db id: %u, door_id %u", into[rowIndex].db_id, into[rowIndex].door_id);
strn0cpy(into[rowIndex].zone_name, row[2], 32);
strn0cpy(into[rowIndex].door_name, row[3], 32);
@ -695,7 +697,13 @@ bool ZoneDatabase::LoadDoors(int32 iDoorCount, Door *into, const char *zone_name
into[rowIndex].size = atoi(row[24]);
into[rowIndex].is_ldon_door = atoi(row[25]);
into[rowIndex].client_version_mask = (uint32)strtoul(row[26], nullptr, 10);
into[rowIndex].disable_timer = (atoi(row[27]) ? true : false);
into[rowIndex].disable_timer = atoi(row[27]);
Log(Logs::Detail, Logs::Doors, "Door Load: db id: %u, door_id %u disable_timer: %i",
into[rowIndex].db_id,
into[rowIndex].door_id,
into[rowIndex].disable_timer
);
}
return true;

View File

@ -32,8 +32,8 @@ public:
const glm::vec4& GetPosition() const{ return m_Position; }
int GetIncline() { return incline; }
bool triggered;
void SetOpenState(bool st) { isopen = st; }
bool IsDoorOpen() { return isopen; }
void SetOpenState(bool st) { is_open = st; }
bool IsDoorOpen() { return is_open; }
uint8 GetTriggerDoorID() { return trigger_door; }
uint8 GetTriggerType() { return trigger_type; }
@ -93,7 +93,7 @@ private:
int invert_state;
uint32 entity_id;
bool disable_timer;
bool isopen;
bool is_open;
Timer close_timer;
//Timer trigger_timer;

View File

@ -890,29 +890,41 @@ bool EntityList::MakeDoorSpawnPacket(EQApplicationPacket *app, Client *client)
memset(packet_buffer, 0, length);
uchar *ptr = packet_buffer;
Doors *door;
Door_Struct nd;
Door_Struct new_door;
it = door_list.begin();
while (it != door_list.end()) {
door = it->second;
if (door && (door->GetClientVersionMask() & mask_test) &&
strlen(door->GetDoorName()) > 3) {
memset(&nd, 0, sizeof(nd));
memcpy(nd.name, door->GetDoorName(), 32);
memset(&new_door, 0, sizeof(new_door));
memcpy(new_door.name, door->GetDoorName(), 32);
auto position = door->GetPosition();
nd.xPos = position.x;
nd.yPos = position.y;
nd.zPos = position.z;
nd.heading = position.w;
nd.incline = door->GetIncline();
nd.size = door->GetSize();
nd.doorId = door->GetDoorID();
nd.opentype = door->GetOpenType();
nd.state_at_spawn = door->GetInvertState() ? !door->IsDoorOpen() : door->IsDoorOpen();
nd.invert_state = door->GetInvertState();
nd.door_param = door->GetDoorParam();
memcpy(ptr, &nd, sizeof(nd));
ptr+=sizeof(nd);
new_door.xPos = position.x;
new_door.yPos = position.y;
new_door.zPos = position.z;
new_door.heading = position.w;
new_door.incline = door->GetIncline();
new_door.size = door->GetSize();
new_door.doorId = door->GetDoorID();
new_door.opentype = door->GetOpenType();
Log(Logs::General, Logs::Doors, "Door timer_disable: %s door_id: %u is_open: %s invert_state: %i",
(door->GetDisableTimer() ? "true" : "false"),
door->GetDoorID(),
(door->IsDoorOpen() ? "true" : "false"),
door->GetInvertState()
);
new_door.state_at_spawn = (door->GetInvertState() ? !door->IsDoorOpen() : door->IsDoorOpen());
new_door.invert_state = door->GetInvertState();
new_door.door_param = door->GetDoorParam();
memcpy(ptr, &new_door, sizeof(new_door));
ptr += sizeof(new_door);
*(ptr - 1) = 0x01;
*(ptr - 3) = 0x01;
}

View File

@ -202,7 +202,7 @@ struct Door {
uint8 nokeyring;
uint8 trigger_door;
uint8 trigger_type;
bool disable_timer;
uint8 disable_timer;
uint32 door_param;
int invert_state;
uint16 size;