mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-02-02 10:33:46 +00:00
feat(Core/Time): Implement saparated manager for game time (#8630)
This commit is contained in:
@@ -20,6 +20,7 @@
|
||||
#include "CharacterCache.h"
|
||||
#include "Chat.h"
|
||||
#include "DatabaseEnv.h"
|
||||
#include "GameTime.h"
|
||||
#include "ObjectMgr.h"
|
||||
#include "Player.h"
|
||||
#include "SocialMgr.h"
|
||||
@@ -34,6 +35,7 @@ Channel::Channel(std::string const& name, uint32 channelId, uint32 channelDBId,
|
||||
_channelId(channelId),
|
||||
_channelDBId(channelDBId),
|
||||
_teamId(teamId),
|
||||
_lastSpeakTime(0),
|
||||
_name(name),
|
||||
_password("")
|
||||
{
|
||||
@@ -95,7 +97,7 @@ Channel::Channel(std::string const& name, uint32 channelId, uint32 channelDBId,
|
||||
bool Channel::IsBanned(ObjectGuid guid) const
|
||||
{
|
||||
BannedContainer::const_iterator itr = bannedStore.find(guid);
|
||||
return itr != bannedStore.end() && itr->second > time(nullptr);
|
||||
return itr != bannedStore.end() && itr->second > GameTime::GetGameTime().count();
|
||||
}
|
||||
|
||||
void Channel::UpdateChannelInDB() const
|
||||
@@ -208,7 +210,6 @@ void Channel::JoinChannel(Player* player, std::string const& pass)
|
||||
PlayerInfo pinfo;
|
||||
pinfo.player = guid;
|
||||
pinfo.flags = MEMBER_FLAG_NONE;
|
||||
pinfo.lastSpeakTime = 0;
|
||||
pinfo.plrPtr = player;
|
||||
|
||||
playersStore[guid] = pinfo;
|
||||
@@ -428,8 +429,8 @@ void Channel::KickOrBan(Player const* player, std::string const& badname, bool b
|
||||
{
|
||||
if (!IsBanned(victim))
|
||||
{
|
||||
bannedStore[victim] = time(nullptr) + CHANNEL_BAN_DURATION;
|
||||
AddChannelBanToDB(victim, time(nullptr) + CHANNEL_BAN_DURATION);
|
||||
bannedStore[victim] = GameTime::GetGameTime().count() + CHANNEL_BAN_DURATION;
|
||||
AddChannelBanToDB(victim, GameTime::GetGameTime().count() + CHANNEL_BAN_DURATION);
|
||||
|
||||
if (notify)
|
||||
{
|
||||
@@ -811,9 +812,9 @@ void Channel::Say(ObjectGuid guid, std::string const& what, uint32 lang)
|
||||
else if (playersStore.size() >= 10)
|
||||
speakDelay = 5;
|
||||
|
||||
if (!pinfo.IsAllowedToSpeak(speakDelay))
|
||||
if (!IsAllowedToSpeak(speakDelay))
|
||||
{
|
||||
std::string timeStr = secsToTimeString(pinfo.lastSpeakTime + speakDelay - sWorld->GetGameTime());
|
||||
std::string timeStr = secsToTimeString(_lastSpeakTime + speakDelay - GameTime::GetGameTime().count());
|
||||
if (_channelRights.speakMessage.length() > 0)
|
||||
player->GetSession()->SendNotification("%s", _channelRights.speakMessage.c_str());
|
||||
player->GetSession()->SendNotification("You must wait %s before speaking again.", timeStr.c_str());
|
||||
@@ -830,6 +831,17 @@ void Channel::Say(ObjectGuid guid, std::string const& what, uint32 lang)
|
||||
SendToAll(&data, pinfo.IsModerator() ? ObjectGuid::Empty : guid);
|
||||
}
|
||||
|
||||
bool Channel::IsAllowedToSpeak(uint32 speakDelay)
|
||||
{
|
||||
if (_lastSpeakTime + speakDelay <= GameTime::GetGameTime().count())
|
||||
{
|
||||
_lastSpeakTime = GameTime::GetGameTime().count();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void Channel::Invite(Player const* player, std::string const& newname)
|
||||
{
|
||||
ObjectGuid guid = player->GetGUID();
|
||||
|
||||
@@ -150,7 +150,6 @@ class Channel
|
||||
{
|
||||
ObjectGuid player;
|
||||
uint8 flags;
|
||||
uint64 lastSpeakTime; // pussywizard
|
||||
Player* plrPtr; // pussywizard
|
||||
|
||||
[[nodiscard]] bool HasFlag(uint8 flag) const { return flags & flag; }
|
||||
@@ -175,16 +174,6 @@ class Channel
|
||||
if (state) flags |= MEMBER_FLAG_MUTED;
|
||||
else flags &= ~MEMBER_FLAG_MUTED;
|
||||
}
|
||||
bool IsAllowedToSpeak(uint64 speakDelay) // pussywizard
|
||||
{
|
||||
if (lastSpeakTime + speakDelay <= static_cast<uint64>(sWorld->GetGameTime()))
|
||||
{
|
||||
lastSpeakTime = sWorld->GetGameTime();
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
private:
|
||||
bool _gmStatus = false;
|
||||
};
|
||||
@@ -234,6 +223,7 @@ public:
|
||||
// pussywizard:
|
||||
void AddWatching(Player* p);
|
||||
void RemoveWatching(Player* p);
|
||||
bool IsAllowedToSpeak(uint32 speakDelay); // pussywizard
|
||||
|
||||
private:
|
||||
// initial packet data (notify type and channel name)
|
||||
@@ -339,6 +329,7 @@ private:
|
||||
uint32 _channelDBId;
|
||||
TeamId _teamId;
|
||||
ObjectGuid _ownerGUID;
|
||||
uint32 _lastSpeakTime;
|
||||
std::string _name;
|
||||
std::string _password;
|
||||
ChannelRights _channelRights;
|
||||
|
||||
Reference in New Issue
Block a user