Skip to content

Commit bf39a05

Browse files
authored
[Cleanup] Cleanup #door Command. (#2783)
* [Cleanup] Cleanup #door Command. # Notes - Resolves an issue with `.1` versus `0.1`. - Resolves an issue with updating a pre-existing door. - Adds `heading` to the update/insert. * Update doors.cpp
1 parent 08c8393 commit bf39a05

File tree

5 files changed

+75
-76
lines changed

5 files changed

+75
-76
lines changed

zone/doors.cpp

Lines changed: 73 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -802,20 +802,75 @@ void Doors::CreateDatabaseEntry()
802802
return;
803803
}
804804

805-
content_db.InsertDoor(
806-
GetDoorDBID(),
807-
GetDoorID(),
808-
GetDoorName(),
809-
m_position,
810-
GetOpenType(),
811-
static_cast<uint16>(GetGuildID()),
812-
GetLockpick(),
813-
GetKeyItem(),
814-
static_cast<uint8>(GetDoorParam()),
815-
static_cast<uint8>(GetInvertState()),
816-
GetIncline(),
817-
GetSize()
805+
const auto& l = DoorsRepository::GetWhere(
806+
content_db,
807+
fmt::format(
808+
"zone = '{}' AND doorid = {}",
809+
zone->GetShortName(),
810+
GetDoorID()
811+
)
818812
);
813+
if (!l.empty()) {
814+
auto e = l[0];
815+
816+
e.name = GetDoorName();
817+
e.pos_x = GetX();
818+
e.pos_y = GetY();
819+
e.pos_z = GetZ();
820+
e.heading = GetHeading();
821+
e.opentype = GetOpenType();
822+
e.guild = static_cast<uint16>(GetGuildID());
823+
e.lockpick = GetLockpick();
824+
e.keyitem = GetKeyItem();
825+
e.door_param = static_cast<uint8>(GetDoorParam());
826+
e.invert_state = static_cast<uint8>(GetInvertState());
827+
e.incline = GetIncline();
828+
e.size = GetSize();
829+
830+
auto updated = DoorsRepository::UpdateOne(content_db, e);
831+
if (!updated) {
832+
LogError(
833+
"Failed to update door in Zone [{}] Version [{}] Database ID [{}] ID [{}]",
834+
zone->GetShortName(),
835+
zone->GetInstanceVersion(),
836+
GetDoorDBID(),
837+
GetDoorID()
838+
);
839+
}
840+
841+
return;
842+
}
843+
844+
auto e = DoorsRepository::NewEntity();
845+
846+
e.id = GetDoorDBID();
847+
e.doorid = GetDoorID();
848+
e.zone = zone->GetShortName();
849+
e.version = zone->GetInstanceVersion();
850+
e.name = GetDoorName();
851+
e.pos_x = GetX();
852+
e.pos_y = GetY();
853+
e.pos_z = GetZ();
854+
e.heading = GetHeading();
855+
e.opentype = GetOpenType();
856+
e.guild = static_cast<uint16>(GetGuildID());
857+
e.lockpick = GetLockpick();
858+
e.keyitem = GetKeyItem();
859+
e.door_param = static_cast<uint8>(GetDoorParam());
860+
e.invert_state = static_cast<uint8>(GetInvertState());
861+
e.incline = GetIncline();
862+
e.size = GetSize();
863+
864+
const auto& n = DoorsRepository::InsertOne(content_db, e);
865+
if (!n.id) {
866+
LogError(
867+
"Failed to create door in Zone [{}] Version [{}] Database ID [{}] ID [{}]",
868+
zone->GetShortName(),
869+
zone->GetInstanceVersion(),
870+
GetDoorDBID(),
871+
GetDoorID()
872+
);
873+
}
819874
}
820875

821876
float Doors::GetX()
@@ -832,3 +887,8 @@ float Doors::GetZ()
832887
{
833888
return m_position.z;
834889
}
890+
891+
float Doors::GetHeading()
892+
{
893+
return m_position.w;
894+
}

zone/doors.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ class Doors : public Entity
6565
float GetX();
6666
float GetY();
6767
float GetZ();
68+
float GetHeading();
6869

6970
private:
7071

zone/gm_commands/door_manipulation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ void DoorManipulation::CommandHandler(Client *c, const Seperator *sep)
187187
std::vector<std::string> set_size_options_negative;
188188

189189
std::vector<std::string> xyz_values = {
190-
".1", "1", "5", "10", "25", "50", "100"
190+
"0.1", "1", "5", "10", "25", "50", "100"
191191
};
192192

193193
// build positive options x/y/z

zone/zonedb.cpp

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -3075,53 +3075,6 @@ void ZoneDatabase::QGlobalPurge()
30753075
database.QueryDatabase(query);
30763076
}
30773077

3078-
void ZoneDatabase::InsertDoor(
3079-
uint32 database_id,
3080-
uint8 id,
3081-
std::string name,
3082-
const glm::vec4 &position,
3083-
uint8 open_type,
3084-
uint16 guild_id,
3085-
uint32 lockpick,
3086-
uint32 key_item_id,
3087-
uint8 door_param,
3088-
uint8 invert,
3089-
int incline,
3090-
uint16 size,
3091-
bool disable_timer
3092-
) {
3093-
auto e = DoorsRepository::NewEntity();
3094-
3095-
e.id = database_id;
3096-
e.doorid = id;
3097-
e.zone = zone->GetShortName();
3098-
e.version = zone->GetInstanceVersion();
3099-
e.name = name;
3100-
e.pos_x = position.x;
3101-
e.pos_y = position.y;
3102-
e.pos_z = position.z;
3103-
e.opentype = open_type;
3104-
e.guild = guild_id;
3105-
e.lockpick = lockpick;
3106-
e.keyitem = key_item_id;
3107-
e.disable_timer = static_cast<int8_t>(disable_timer);
3108-
e.door_param = door_param;
3109-
e.invert_state = invert;
3110-
e.incline = incline;
3111-
e.size = size;
3112-
3113-
const auto& n = DoorsRepository::InsertOne(*this, e);
3114-
if (!n.id) {
3115-
LogError(
3116-
"Failed to create door in Zone [{}] Version [{}] Database ID [{}] ID [{}]",
3117-
zone->GetShortName(),
3118-
zone->GetInstanceVersion(),
3119-
database_id,
3120-
id
3121-
);
3122-
}
3123-
}
3124-
31253078
void ZoneDatabase::LoadAltCurrencyValues(uint32 char_id, std::map<uint32, uint32> &currency) {
31263079

31273080
std::string query = StringFormat("SELECT currency_id, amount "

zone/zonedb.h

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -570,21 +570,6 @@ class ZoneDatabase : public SharedDatabase {
570570
std::vector<DoorsRepository::Doors> LoadDoors(const std::string& zone_name, int16 version);
571571
uint32 GetDoorsCountPlusOne();
572572
int GetDoorsDBCountPlusOne(std::string zone_short_name, int16 version);
573-
void InsertDoor(
574-
uint32 database_id,
575-
uint8 id,
576-
std::string name,
577-
const glm::vec4 &position,
578-
uint8 open_type,
579-
uint16 guild_id,
580-
uint32 ockpick,
581-
uint32 key_item_id,
582-
uint8 door_param,
583-
uint8 invert,
584-
int incline,
585-
uint16 size,
586-
bool disable_timer = false
587-
);
588573

589574
/* Blocked Spells */
590575
int32 GetBlockedSpellsCount(uint32 zoneid);

0 commit comments

Comments
 (0)