mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-01-30 09:03:47 +00:00
feat(Core/Misc): implement ObjectGuid class (port from TC) (#4885)
This commit is contained in:
@@ -20,11 +20,11 @@ inline float GetAge(uint64 t) { return float(time(nullptr) - t) / DAY; }
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// GM ticket
|
||||
GmTicket::GmTicket() : _id(0), _playerGuid(0), _type(TICKET_TYPE_OPEN), _posX(0), _posY(0), _posZ(0), _mapId(0), _createTime(0), _lastModifiedTime(0),
|
||||
_closedBy(0), _resolvedBy(0), _assignedTo(0), _completed(false), _escalatedStatus(TICKET_UNASSIGNED), _viewed(false),
|
||||
_needResponse(false), _needMoreHelp(false) { }
|
||||
GmTicket::GmTicket() : _id(0), _type(TICKET_TYPE_OPEN), _posX(0), _posY(0), _posZ(0), _mapId(0), _createTime(0), _lastModifiedTime(0),
|
||||
_completed(false), _escalatedStatus(TICKET_UNASSIGNED), _viewed(false), _needResponse(false), _needMoreHelp(false) { }
|
||||
|
||||
GmTicket::GmTicket(Player* player) : _type(TICKET_TYPE_OPEN), _createTime(time(nullptr)), _lastModifiedTime(time(nullptr)), _closedBy(0), _resolvedBy(0), _assignedTo(0), _completed(false), _escalatedStatus(TICKET_UNASSIGNED), _viewed(false), _needMoreHelp(false)
|
||||
GmTicket::GmTicket(Player* player) : _type(TICKET_TYPE_OPEN), _createTime(time(nullptr)), _lastModifiedTime(time(nullptr)),
|
||||
_completed(false), _escalatedStatus(TICKET_UNASSIGNED), _viewed(false), _needMoreHelp(false)
|
||||
{
|
||||
_id = sTicketMgr->GenerateTicketId();
|
||||
_playerName = player->GetName();
|
||||
@@ -40,7 +40,7 @@ bool GmTicket::LoadFromDB(Field* fields)
|
||||
uint8 index = 0;
|
||||
_id = fields[ index].GetUInt32();
|
||||
_type = TicketType(fields[++index].GetUInt8());
|
||||
_playerGuid = MAKE_NEW_GUID(fields[++index].GetUInt32(), 0, HIGHGUID_PLAYER);
|
||||
_playerGuid = ObjectGuid::Create<HighGuid::Player>(fields[++index].GetUInt32());
|
||||
_playerName = fields[++index].GetString();
|
||||
_message = fields[++index].GetString();
|
||||
_createTime = fields[++index].GetUInt32();
|
||||
@@ -49,15 +49,15 @@ bool GmTicket::LoadFromDB(Field* fields)
|
||||
_posY = fields[++index].GetFloat();
|
||||
_posZ = fields[++index].GetFloat();
|
||||
_lastModifiedTime = fields[++index].GetUInt32();
|
||||
_closedBy = fields[++index].GetInt32();
|
||||
_assignedTo = MAKE_NEW_GUID(fields[++index].GetUInt32(), 0, HIGHGUID_PLAYER);
|
||||
_closedBy = ObjectGuid::Create<HighGuid::Player>(fields[++index].GetInt32());
|
||||
_assignedTo = ObjectGuid::Create<HighGuid::Player>(fields[++index].GetUInt32());
|
||||
_comment = fields[++index].GetString();
|
||||
_response = fields[++index].GetString();
|
||||
_completed = fields[++index].GetBool();
|
||||
_escalatedStatus = GMTicketEscalationStatus(fields[++index].GetUInt8());
|
||||
_viewed = fields[++index].GetBool();
|
||||
_needMoreHelp = fields[++index].GetBool();
|
||||
_resolvedBy = fields[++index].GetInt32();
|
||||
_resolvedBy = ObjectGuid::Create<HighGuid::Player>(fields[++index].GetInt32());
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -70,7 +70,7 @@ void GmTicket::SaveToDB(SQLTransaction& trans) const
|
||||
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_REP_GM_TICKET);
|
||||
stmt->setUInt32( index, _id);
|
||||
stmt->setUInt8 (++index, uint8(_type));
|
||||
stmt->setUInt32(++index, GUID_LOPART(_playerGuid));
|
||||
stmt->setUInt32(++index, _playerGuid.GetCounter());
|
||||
stmt->setString(++index, _playerName);
|
||||
stmt->setString(++index, _message);
|
||||
stmt->setUInt32(++index, uint32(_createTime));
|
||||
@@ -79,15 +79,15 @@ void GmTicket::SaveToDB(SQLTransaction& trans) const
|
||||
stmt->setFloat (++index, _posY);
|
||||
stmt->setFloat (++index, _posZ);
|
||||
stmt->setUInt32(++index, uint32(_lastModifiedTime));
|
||||
stmt->setInt32 (++index, GUID_LOPART(_closedBy));
|
||||
stmt->setUInt32(++index, GUID_LOPART(_assignedTo));
|
||||
stmt->setInt32 (++index, _closedBy.GetCounter());
|
||||
stmt->setUInt32(++index, _assignedTo.GetCounter());
|
||||
stmt->setString(++index, _comment);
|
||||
stmt->setString(++index, _response);
|
||||
stmt->setBool (++index, _completed);
|
||||
stmt->setUInt8 (++index, uint8(_escalatedStatus));
|
||||
stmt->setBool (++index, _viewed);
|
||||
stmt->setBool (++index, _needMoreHelp);
|
||||
stmt->setInt32 (++index, GUID_LOPART(_resolvedBy));
|
||||
stmt->setInt32 (++index, _resolvedBy.GetCounter());
|
||||
|
||||
CharacterDatabase.ExecuteOrAppend(trans, stmt);
|
||||
}
|
||||
@@ -156,7 +156,7 @@ std::string GmTicket::FormatMessageString(ChatHandler& handler, bool detailed) c
|
||||
ss << handler.PGetParseString(LANG_COMMAND_TICKETLISTAGE, (secsToTimeString(curTime - _lastModifiedTime, true)).c_str());
|
||||
|
||||
std::string name;
|
||||
if (sObjectMgr->GetPlayerNameByGUID(_assignedTo, name))
|
||||
if (sObjectMgr->GetPlayerNameByGUID(_assignedTo.GetCounter(), name))
|
||||
ss << handler.PGetParseString(LANG_COMMAND_TICKETLISTASSIGNEDTO, name.c_str());
|
||||
|
||||
if (detailed)
|
||||
@@ -188,7 +188,8 @@ std::string GmTicket::FormatMessageString(ChatHandler& handler, const char* szCl
|
||||
|
||||
void GmTicket::SetUnassigned()
|
||||
{
|
||||
_assignedTo = 0;
|
||||
_assignedTo.Clear();
|
||||
|
||||
switch (_escalatedStatus)
|
||||
{
|
||||
case TICKET_ASSIGNED:
|
||||
@@ -344,7 +345,7 @@ void TicketMgr::AddTicket(GmTicket* ticket)
|
||||
ticket->SaveToDB(trans);
|
||||
}
|
||||
|
||||
void TicketMgr::CloseTicket(uint32 ticketId, int64 source)
|
||||
void TicketMgr::CloseTicket(uint32 ticketId, ObjectGuid source)
|
||||
{
|
||||
if (GmTicket* ticket = GetTicket(ticketId))
|
||||
{
|
||||
@@ -366,7 +367,7 @@ void TicketMgr::RemoveTicket(uint32 ticketId)
|
||||
}
|
||||
}
|
||||
|
||||
void TicketMgr::ResolveAndCloseTicket(uint32 ticketId, int64 source)
|
||||
void TicketMgr::ResolveAndCloseTicket(uint32 ticketId, ObjectGuid source)
|
||||
{
|
||||
if (GmTicket* ticket = GetTicket(ticketId))
|
||||
{
|
||||
|
||||
@@ -81,23 +81,23 @@ public:
|
||||
|
||||
bool IsClosed() const { return _type != TICKET_TYPE_OPEN; }
|
||||
bool IsCompleted() const { return _completed; }
|
||||
bool IsFromPlayer(uint64 guid) const { return guid == _playerGuid; }
|
||||
bool IsAssigned() const { return _assignedTo != 0; }
|
||||
bool IsAssignedTo(uint64 guid) const { return guid == _assignedTo; }
|
||||
bool IsAssignedNotTo(uint64 guid) const { return IsAssigned() && !IsAssignedTo(guid); }
|
||||
bool IsFromPlayer(ObjectGuid guid) const { return guid == _playerGuid; }
|
||||
bool IsAssigned() const { return _assignedTo; }
|
||||
bool IsAssignedTo(ObjectGuid guid) const { return guid == _assignedTo; }
|
||||
bool IsAssignedNotTo(ObjectGuid guid) const { return IsAssigned() && !IsAssignedTo(guid); }
|
||||
|
||||
uint32 GetId() const { return _id; }
|
||||
Player* GetPlayer() const { return ObjectAccessor::FindPlayerInOrOutOfWorld(_playerGuid); }
|
||||
Player* GetPlayer() const { return ObjectAccessor::FindConnectedPlayer(_playerGuid); }
|
||||
std::string const& GetPlayerName() const { return _playerName; }
|
||||
std::string const& GetMessage() const { return _message; }
|
||||
Player* GetAssignedPlayer() const { return ObjectAccessor::FindPlayerInOrOutOfWorld(_assignedTo); }
|
||||
uint64 GetAssignedToGUID() const { return _assignedTo; }
|
||||
Player* GetAssignedPlayer() const { return ObjectAccessor::FindConnectedPlayer(_assignedTo); }
|
||||
ObjectGuid GetAssignedToGUID() const { return _assignedTo; }
|
||||
std::string GetAssignedToName() const
|
||||
{
|
||||
std::string name;
|
||||
// save queries if ticket is not assigned
|
||||
if (_assignedTo)
|
||||
sObjectMgr->GetPlayerNameByGUID(_assignedTo, name);
|
||||
sObjectMgr->GetPlayerNameByGUID(_assignedTo.GetCounter(), name);
|
||||
|
||||
return name;
|
||||
}
|
||||
@@ -105,7 +105,7 @@ public:
|
||||
GMTicketEscalationStatus GetEscalatedStatus() const { return _escalatedStatus; }
|
||||
|
||||
void SetEscalatedStatus(GMTicketEscalationStatus escalatedStatus) { _escalatedStatus = escalatedStatus; }
|
||||
void SetAssignedTo(uint64 guid, bool isAdmin)
|
||||
void SetAssignedTo(ObjectGuid guid, bool isAdmin)
|
||||
{
|
||||
_assignedTo = guid;
|
||||
if (isAdmin && _escalatedStatus == TICKET_IN_ESCALATION_QUEUE)
|
||||
@@ -113,8 +113,8 @@ public:
|
||||
else if (_escalatedStatus == TICKET_UNASSIGNED)
|
||||
_escalatedStatus = TICKET_ASSIGNED;
|
||||
}
|
||||
void SetClosedBy(int64 value) { _closedBy = value; _type = TICKET_TYPE_CLOSED; }
|
||||
void SetResolvedBy(int64 value) { _resolvedBy = value; }
|
||||
void SetClosedBy(ObjectGuid value) { _closedBy = value; _type = TICKET_TYPE_CLOSED; }
|
||||
void SetResolvedBy(ObjectGuid value) { _resolvedBy = value; }
|
||||
void SetCompleted() { _completed = true; }
|
||||
void SetMessage(std::string const& message)
|
||||
{
|
||||
@@ -145,7 +145,7 @@ public:
|
||||
|
||||
private:
|
||||
uint32 _id;
|
||||
uint64 _playerGuid;
|
||||
ObjectGuid _playerGuid;
|
||||
TicketType _type; // 0 = Open, 1 = Closed, 2 = Character deleted
|
||||
std::string _playerName;
|
||||
float _posX;
|
||||
@@ -155,9 +155,9 @@ private:
|
||||
std::string _message;
|
||||
uint64 _createTime;
|
||||
uint64 _lastModifiedTime;
|
||||
int64 _closedBy; // 0 = Open or Closed by Console (if type = 1), playerGuid = GM who closed it or player abandoned ticket or read the GM response message.
|
||||
int64 _resolvedBy; // 0 = Open, -1 = Resolved by Console, GM who resolved it by closing or completing the ticket.
|
||||
uint64 _assignedTo;
|
||||
ObjectGuid _closedBy; // 0 = Open or Closed by Console (if type = 1), playerGuid = GM who closed it or player abandoned ticket or read the GM response message.
|
||||
ObjectGuid _resolvedBy; // 0 = Open, -1 = Resolved by Console, GM who resolved it by closing or completing the ticket.
|
||||
ObjectGuid _assignedTo;
|
||||
std::string _comment;
|
||||
bool _completed;
|
||||
GMTicketEscalationStatus _escalatedStatus;
|
||||
@@ -191,7 +191,7 @@ public:
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
GmTicket* GetTicketByPlayer(uint64 playerGuid)
|
||||
GmTicket* GetTicketByPlayer(ObjectGuid playerGuid)
|
||||
{
|
||||
for (GmTicketList::const_iterator itr = _ticketList.begin(); itr != _ticketList.end(); ++itr)
|
||||
if (itr->second && itr->second->IsFromPlayer(playerGuid) && !itr->second->IsClosed())
|
||||
@@ -210,8 +210,8 @@ public:
|
||||
}
|
||||
|
||||
void AddTicket(GmTicket* ticket);
|
||||
void CloseTicket(uint32 ticketId, int64 source = -1);
|
||||
void ResolveAndCloseTicket(uint32 ticketId, int64 source); // used when GM resolves a ticket by simply closing it
|
||||
void CloseTicket(uint32 ticketId, ObjectGuid source = ObjectGuid::Empty);
|
||||
void ResolveAndCloseTicket(uint32 ticketId, ObjectGuid source); // used when GM resolves a ticket by simply closing it
|
||||
void RemoveTicket(uint32 ticketId);
|
||||
|
||||
bool GetStatus() const { return _status; }
|
||||
|
||||
Reference in New Issue
Block a user