[11814] Use the same variable to store the message for AFK and DND

Also make code in this area easier to read

Signed-off-by: Schmoozerd <schmoozerd@scriptdev2.com>
This commit is contained in:
stfx 2011-10-07 16:55:22 +02:00 committed by Schmoozerd
parent e89d5db5e3
commit 5b0c0c9fa4
4 changed files with 42 additions and 40 deletions

View file

@ -454,41 +454,48 @@ void WorldSession::HandleMessagechatOpcode( WorldPacket & recv_data )
if (!_player->isInCombat())
{
if (!msg.empty() || !_player->isAFK())
if (_player->isAFK()) // Already AFK
{
if (msg.empty())
_player->afkMsg = GetMangosString(LANG_PLAYER_AFK_DEFAULT);
_player->ToggleAFK(); // Remove AFK
else
_player->afkMsg = msg;
_player->autoReplyMsg = msg; // Update message
}
if (msg.empty() || !_player->isAFK())
else // New AFK mode
{
_player->ToggleAFK();
if (_player->isAFK() && _player->isDND())
_player->autoReplyMsg = msg.empty() ? GetMangosString(LANG_PLAYER_AFK_DEFAULT) : msg;
if (_player->isDND())
_player->ToggleDND();
_player->ToggleAFK();
}
}
} break;
break;
}
case CHAT_MSG_DND:
{
std::string msg;
recv_data >> msg;
if (!msg.empty() || !_player->isDND())
if (_player->isDND()) // Already DND
{
if (msg.empty())
_player->dndMsg = GetMangosString(LANG_PLAYER_DND_DEFAULT);
_player->ToggleDND(); // Remove DND
else
_player->dndMsg = msg;
_player->autoReplyMsg = msg; // Update message
}
if (msg.empty() || !_player->isDND())
else // New DND mode
{
_player->ToggleDND();
if (_player->isDND() && _player->isAFK())
_player->autoReplyMsg = msg.empty() ? GetMangosString(LANG_PLAYER_DND_DEFAULT) : msg;
if (_player->isAFK())
_player->ToggleAFK();
_player->ToggleDND();
}
} break;
break;
}
default:
sLog.outError("CHAT: unknown message type %u, lang: %u", type, lang);

View file

@ -1649,41 +1649,37 @@ bool Player::BuildEnumData( QueryResult * result, WorldPacket * p_data )
return true;
}
bool Player::ToggleAFK()
void Player::ToggleAFK()
{
ToggleFlag(PLAYER_FLAGS, PLAYER_FLAGS_AFK);
bool state = HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_AFK);
// afk player not allowed in battleground
if (state && InBattleGround() && !InArena())
if (isAFK() && InBattleGround() && !InArena())
LeaveBattleground();
return state;
}
bool Player::ToggleDND()
void Player::ToggleDND()
{
ToggleFlag(PLAYER_FLAGS, PLAYER_FLAGS_DND);
return HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_DND);
}
uint8 Player::chatTag() const
{
// it's bitmask
// 0x8 - ??
// 0x4 - gm
// 0x2 - dnd
// 0x1 - afk
if(isGMChat())
// 0x2 - dnd
// 0x4 - gm
// 0x8 - ??
if (isGMChat()) // Always show GM icons if activated
return 4;
else if(isDND())
return 3;
if(isAFK())
if (isAFK())
return 1;
else
return 0;
if (isDND())
return 3;
return 0;
}
bool Player::TeleportTo(uint32 mapid, float x, float y, float z, float orientation, uint32 options)
@ -18390,9 +18386,9 @@ void Player::Whisper(const std::string& text, uint32 language, ObjectGuid receiv
// announce afk or dnd message
if (rPlayer->isAFK())
ChatHandler(this).PSendSysMessage(LANG_PLAYER_AFK, rPlayer->GetName(), rPlayer->afkMsg.c_str());
ChatHandler(this).PSendSysMessage(LANG_PLAYER_AFK, rPlayer->GetName(), rPlayer->autoReplyMsg.c_str());
else if (rPlayer->isDND())
ChatHandler(this).PSendSysMessage(LANG_PLAYER_DND, rPlayer->GetName(), rPlayer->dndMsg.c_str());
ChatHandler(this).PSendSysMessage(LANG_PLAYER_DND, rPlayer->GetName(), rPlayer->autoReplyMsg.c_str());
}
void Player::PetSpellInitialize()

View file

@ -1060,13 +1060,12 @@ class MANGOS_DLL_SPEC Player : public Unit
Creature* GetNPCIfCanInteractWith(ObjectGuid guid, uint32 npcflagmask);
GameObject* GetGameObjectIfCanInteractWith(ObjectGuid guid, uint32 gameobject_type = MAX_GAMEOBJECT_TYPE) const;
bool ToggleAFK();
bool ToggleDND();
void ToggleAFK();
void ToggleDND();
bool isAFK() const { return HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_AFK); }
bool isDND() const { return HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_DND); }
uint8 chatTag() const;
std::string afkMsg;
std::string dndMsg;
std::string autoReplyMsg;
uint32 GetBarberShopCost(uint8 newhairstyle, uint8 newhaircolor, uint8 newfacialhair);

View file

@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__
#define __REVISION_NR_H__
#define REVISION_NR "11813"
#define REVISION_NR "11814"
#endif // __REVISION_NR_H__