Skip to content

Commit

Permalink
[Core/Text] Replace old Object::MonsterWhisper with Unit:: Whisper (#328
Browse files Browse the repository at this point in the history
)
  • Loading branch information
leelf00 authored Aug 18, 2024
1 parent 8990cae commit b93a292
Show file tree
Hide file tree
Showing 20 changed files with 311 additions and 179 deletions.
6 changes: 6 additions & 0 deletions sql/updates/world/2024_08_18_00_world.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-- Quest 12987 Hodir's Helm
-- Creature text for NPC_ICE_SPIKE_BUNNY 30215
DELETE FROM `creature_text` WHERE `CreatureID`=30215;
INSERT INTO `creature_text`(`CreatureID`, `GroupID`, `ID`, `Text`, `Type`, `Language`, `Probability`, `Emote`, `Duration`, `Sound`, `SoundType`, `BroadcastTextId`, `TextRange`, `comment`) VALUES
(30215, 1, 0, 'Sons of Hodir! I humbly present to you....', 42, 0, 100.0, 0, 0, 0, 0, 30906, 0, 'Player - Read Pronouncement'),
(30215, 2, 0, 'The Helm of Hodir!', 42, 0, 100.0, 0, 0, 0, 0, 30907, 0, 'Player - Read Pronouncement');
24 changes: 0 additions & 24 deletions src/server/game/Entities/Object/Object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2627,30 +2627,6 @@ void WorldObject::MonsterTextEmote(int32 textId, WorldObject const* target, bool
cell.Visit(p, message, *GetMap(), *this, sWorld->getFloatConfig(CONFIG_LISTEN_RANGE_TEXTEMOTE));
}

void WorldObject::MonsterWhisper(const char* text, Player const* target, bool IsBossWhisper)
{
if (!target)
return;

LocaleConstant loc_idx = target->GetSession()->GetSessionDbLocaleIndex();
WorldPacket data;
ChatHandler::BuildChatPacket(data, IsBossWhisper ? CHAT_MSG_RAID_BOSS_WHISPER : CHAT_MSG_MONSTER_WHISPER, LANG_UNIVERSAL, this, target, text, 0, "", loc_idx);
target->GetSession()->SendPacket(&data);
}

void WorldObject::MonsterWhisper(int32 textId, Player const* target, bool IsBossWhisper)
{
if (!target)
return;

LocaleConstant loc_idx = target->GetSession()->GetSessionDbLocaleIndex();
char const* text = sObjectMgr->GetTrinityString(textId, loc_idx);

WorldPacket data;
ChatHandler::BuildChatPacket(data, IsBossWhisper ? CHAT_MSG_RAID_BOSS_WHISPER : CHAT_MSG_MONSTER_WHISPER, LANG_UNIVERSAL, this, target, text, 0, "", loc_idx);
target->GetSession()->SendPacket(&data);
}

void WorldObject::SendMessageToSet(WorldPacket* data, bool self)
{
if (IsInWorld())
Expand Down
2 changes: 0 additions & 2 deletions src/server/game/Entities/Object/Object.h
Original file line number Diff line number Diff line change
Expand Up @@ -602,11 +602,9 @@ class TC_GAME_API WorldObject : public Object, public WorldLocation
void MonsterSay(const char* text, uint32 language, WorldObject const* target);
void MonsterYell(const char* text, uint32 language, WorldObject const* target);
void MonsterTextEmote(const char* text, WorldObject const* target, bool IsBossEmote = false);
void MonsterWhisper(const char* text, Player const* target, bool IsBossWhisper = false);
void MonsterSay(int32 textId, uint32 language, WorldObject const* target);
void MonsterYell(int32 textId, uint32 language, WorldObject const* target);
void MonsterTextEmote(int32 textId, WorldObject const* target, bool IsBossEmote = false);
void MonsterWhisper(int32 textId, Player const* target, bool IsBossWhisper = false);

void PlayDistanceSound(uint32 sound_id, Player* target = NULL);
void PlayDirectSound(uint32 sound_id, Player* target = NULL);
Expand Down
71 changes: 52 additions & 19 deletions src/server/game/Entities/Player/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22459,36 +22459,51 @@ void Player::StopCastingCharm()
}
}

void Player::Say(const std::string& text, const uint32 language)
void Player::Say(const std::string& text, Language language, WorldObject const* /*= nullptr*/)
{
std::string _text(text);
sScriptMgr->OnPlayerChat(this, CHAT_MSG_SAY, language, _text);

WorldPacket data;
ChatHandler::BuildChatPacket(data, CHAT_MSG_SAY, Language(language), this, this, text);
ChatHandler::BuildChatPacket(data, CHAT_MSG_SAY, language, this, this, _text);
SendMessageToSetInRange(&data, sWorld->getFloatConfig(CONFIG_LISTEN_RANGE_SAY), true);
}

void Player::Yell(const std::string& text, const uint32 language)
void Player::Say(uint32 textId, WorldObject const* target /*= nullptr*/)
{
Talk(textId, CHAT_MSG_SAY, sWorld->getFloatConfig(CONFIG_LISTEN_RANGE_SAY), target);
}

void Player::Yell(std::string const& text, Language language, WorldObject const* /*= nullptr*/)
{
std::string _text(text);
sScriptMgr->OnPlayerChat(this, CHAT_MSG_YELL, language, _text);

WorldPacket data;
ChatHandler::BuildChatPacket(data, CHAT_MSG_YELL, Language(language), this, this, text);
ChatHandler::BuildChatPacket(data, CHAT_MSG_YELL, language, this, this, _text);
SendMessageToSetInRange(&data, sWorld->getFloatConfig(CONFIG_LISTEN_RANGE_YELL), true);
}

void Player::TextEmote(const std::string& text)
void Player::Yell(uint32 textId, WorldObject const* target /*= nullptr*/)
{
Talk(textId, CHAT_MSG_YELL, sWorld->getFloatConfig(CONFIG_LISTEN_RANGE_YELL), target);
}

void Player::TextEmote(std::string const& text, WorldObject const* /*= nullptr*/, bool /*= false*/)
{
std::string _text(text);
sScriptMgr->OnPlayerChat(this, CHAT_MSG_EMOTE, LANG_UNIVERSAL, _text);

WorldPacket data;
ChatHandler::BuildChatPacket(data, CHAT_MSG_EMOTE, LANG_UNIVERSAL, this, this, text);
ChatHandler::BuildChatPacket(data, CHAT_MSG_EMOTE, LANG_UNIVERSAL, this, this, _text);
SendMessageToSetInRange(&data, sWorld->getFloatConfig(CONFIG_LISTEN_RANGE_TEXTEMOTE), true, !sWorld->getBoolConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_CHAT));
}

void Player::TextEmote(uint32 textId, WorldObject const* target /*= nullptr*/, bool /*isBossEmote = false*/)
{
Talk(textId, CHAT_MSG_EMOTE, sWorld->getFloatConfig(CONFIG_LISTEN_RANGE_TEXTEMOTE), target);
}

void Player::WhisperAddon(const std::string& text, const std::string& prefix, Player* receiver)
{
std::string _text(text);
Expand All @@ -22502,40 +22517,58 @@ void Player::WhisperAddon(const std::string& text, const std::string& prefix, Pl
receiver->GetSession()->SendPacket(&data);
}

void Player::Whisper(const std::string& text, uint32 language, ObjectGuid receiver)
void Player::Whisper(std::string const& text, Language language, Player* target, bool isBossWhisper)
{
ASSERT(target);

bool isAddonMessage = language == LANG_ADDON;

if (!isAddonMessage) // if not addon data
language = LANG_UNIVERSAL; // whispers should always be readable

Player* rPlayer = ObjectAccessor::FindPlayer(receiver);

std::string _text(text);
sScriptMgr->OnPlayerChat(this, CHAT_MSG_WHISPER, language, _text, rPlayer);
sScriptMgr->OnPlayerChat(this, isBossWhisper ? CHAT_MSG_RAID_BOSS_WHISPER : CHAT_MSG_WHISPER, language, _text, target);

WorldPacket data;
ChatHandler::BuildChatPacket(data, CHAT_MSG_WHISPER, Language(language), this, this, text);
rPlayer->GetSession()->SendPacket(&data);
ChatHandler::BuildChatPacket(data, isBossWhisper ? CHAT_MSG_RAID_BOSS_WHISPER : CHAT_MSG_WHISPER, Language(language), this, this, _text);
target->SendDirectMessage(&data);

// rest stuff shouldn't happen in case of addon message
if (isAddonMessage)
return;

ChatHandler::BuildChatPacket(data, CHAT_MSG_WHISPER_INFORM, Language(language), rPlayer, rPlayer, text);
GetSession()->SendPacket(&data);
ChatHandler::BuildChatPacket(data, CHAT_MSG_WHISPER_INFORM, Language(language), target, target, _text);
SendDirectMessage(&data);

if (!isAcceptWhispers() && !IsGameMaster() && !rPlayer->IsGameMaster())
if (!isAcceptWhispers() && !IsGameMaster() && !target->IsGameMaster())
{
SetAcceptWhispers(true);
ChatHandler(GetSession()).SendSysMessage(LANG_COMMAND_WHISPERON);
}

// announce afk or dnd message
if (rPlayer->isAFK())
ChatHandler(GetSession()).PSendSysMessage(LANG_PLAYER_AFK, rPlayer->GetName().c_str(), rPlayer->autoReplyMsg.c_str());
else if (rPlayer->isDND())
ChatHandler(GetSession()).PSendSysMessage(LANG_PLAYER_DND, rPlayer->GetName().c_str(), rPlayer->autoReplyMsg.c_str());
if (target->isAFK())
ChatHandler(GetSession()).PSendSysMessage(LANG_PLAYER_AFK, target->GetName().c_str(), target->autoReplyMsg.c_str());
else if (target->isDND())
ChatHandler(GetSession()).PSendSysMessage(LANG_PLAYER_DND, target->GetName().c_str(), target->autoReplyMsg.c_str());
}

void Player::Whisper(uint32 textId, Player* target, bool isBossWhisper)
{
if (!target)
return;

BroadcastText const* bct = sObjectMgr->GetBroadcastText(textId);
if (!bct)
{
TC_LOG_ERROR("entities.unit", "WorldObject::MonsterWhisper: `broadcast_text` was not %u found", textId);
return;
}

LocaleConstant locale = target->GetSession()->GetSessionDbLocaleIndex();
WorldPacket data;
ChatHandler::BuildChatPacket(data, isBossWhisper ? CHAT_MSG_RAID_BOSS_WHISPER : CHAT_MSG_WHISPER, LANG_UNIVERSAL, this, target, bct->GetText(locale, GetGender()), 0, "", locale);
target->SendDirectMessage(&data);
}

void Player::SendPersonalMessage(std::string const& text, ChatMsg type, Language lang)
Expand Down
12 changes: 8 additions & 4 deletions src/server/game/Entities/Player/Player.h
Original file line number Diff line number Diff line change
Expand Up @@ -1421,13 +1421,17 @@ class TC_GAME_API Player : public Unit, public GridObject<Player>
}

/// Handles said message in regular chat based on declared language and in config pre-defined Range.
void Say(std::string const& text, const uint32 language);
void Say(std::string const& text, Language language, WorldObject const* = nullptr) override;
void Say(uint32 textId, WorldObject const* target = nullptr) override;
/// Handles yelled message in regular chat based on declared language and in config pre-defined Range.
void Yell(std::string const& text, const uint32 language);
void Yell(std::string const& text, Language language, WorldObject const* = nullptr) override;
void Yell(uint32 textId, WorldObject const* target = nullptr) override;
/// Outputs an universal text which is supposed to be an action.
void TextEmote(std::string const& text);
void TextEmote(std::string const& text, WorldObject const* = nullptr, bool = false) override;
void TextEmote(uint32 textId, WorldObject const* target = nullptr, bool isBossEmote = false) override;
/// Handles whispers from Addons and players based on sender, receiver's guid and language.
void Whisper(std::string const& text, const uint32 language, ObjectGuid receiver);
void Whisper(std::string const& text, Language language, Player* receiver, bool = false) override;
void Whisper(uint32 textId, Player* target, bool isBossWhisper = false) override;
void WhisperAddon(std::string const& text, std::string const& prefix, Player* receiver);

void SendPersonalMessage(std::string const& text, ChatMsg type, Language lang);
Expand Down
83 changes: 83 additions & 0 deletions src/server/game/Entities/Unit/Unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
#include "CreatureGroups.h"
#include "Creature.h"
#include "CreatureTextMgr.h"
#include "Chat.h"
#include "ChatTextBuilder.h"
#include "Formulas.h"
#include "GridNotifiersImpl.h"
#include "Group.h"
Expand Down Expand Up @@ -19765,6 +19767,87 @@ void Unit::BuildValuesUpdate(uint8 updateType, ByteBuffer* data, Player* target)
BuildDynamicValuesUpdate(updateType, data);
}

void Unit::Talk(std::string const& text, ChatMsg msgType, Language language, float textRange, WorldObject const* target)
{
Trinity::CustomChatTextBuilder builder(this, msgType, text, language, target);
Trinity::LocalizedPacketDo<Trinity::CustomChatTextBuilder> localizer(builder);
Trinity::PlayerDistWorker<Trinity::LocalizedPacketDo<Trinity::CustomChatTextBuilder> > worker(this, textRange, localizer);
Cell::VisitWorldObjects(this, worker, textRange);
}

void Unit::Say(std::string const& text, Language language, WorldObject const* target /*= nullptr*/)
{
Talk(text, CHAT_MSG_MONSTER_SAY, language, sWorld->getFloatConfig(CONFIG_LISTEN_RANGE_SAY), target);
}

void Unit::Yell(std::string const& text, Language language, WorldObject const* target /*= nullptr*/)
{
Talk(text, CHAT_MSG_MONSTER_YELL, language, sWorld->getFloatConfig(CONFIG_LISTEN_RANGE_YELL), target);
}

void Unit::TextEmote(std::string const& text, WorldObject const* target /*= nullptr*/, bool isBossEmote /*= false*/)
{
Talk(text, isBossEmote ? CHAT_MSG_RAID_BOSS_EMOTE : CHAT_MSG_MONSTER_EMOTE, LANG_UNIVERSAL, sWorld->getFloatConfig(CONFIG_LISTEN_RANGE_TEXTEMOTE), target);
}

void Unit::Whisper(std::string const& text, Language language, Player* target, bool isBossWhisper /*= false*/)
{
if (!target)
return;

LocaleConstant locale = target->GetSession()->GetSessionDbLocaleIndex();
WorldPacket data;
ChatHandler::BuildChatPacket(data, isBossWhisper ? CHAT_MSG_RAID_BOSS_WHISPER : CHAT_MSG_MONSTER_WHISPER, language, this, target, text, 0, "", locale);
target->SendDirectMessage(&data);
}

void Unit::Talk(uint32 textId, ChatMsg msgType, float textRange, WorldObject const* target)
{
if (!sObjectMgr->GetBroadcastText(textId))
{
TC_LOG_ERROR("entities.unit", "WorldObject::MonsterText: `broadcast_text` (ID: %u) was not found", textId);
return;
}

Trinity::BroadcastTextBuilder builder(this, msgType, textId, GetGender(), target);
Trinity::LocalizedPacketDo<Trinity::BroadcastTextBuilder> localizer(builder);
Trinity::PlayerDistWorker<Trinity::LocalizedPacketDo<Trinity::BroadcastTextBuilder> > worker(this, textRange, localizer);
Cell::VisitWorldObjects(this, worker, textRange);
}

void Unit::Say(uint32 textId, WorldObject const* target /*= nullptr*/)
{
Talk(textId, CHAT_MSG_MONSTER_SAY, sWorld->getFloatConfig(CONFIG_LISTEN_RANGE_SAY), target);
}

void Unit::Yell(uint32 textId, WorldObject const* target /*= nullptr*/)
{
Talk(textId, CHAT_MSG_MONSTER_YELL, sWorld->getFloatConfig(CONFIG_LISTEN_RANGE_YELL), target);
}

void Unit::TextEmote(uint32 textId, WorldObject const* target /*= nullptr*/, bool isBossEmote /*= false*/)
{
Talk(textId, isBossEmote ? CHAT_MSG_RAID_BOSS_EMOTE : CHAT_MSG_MONSTER_EMOTE, sWorld->getFloatConfig(CONFIG_LISTEN_RANGE_TEXTEMOTE), target);
}

void Unit::Whisper(uint32 textId, Player* target, bool isBossWhisper /*= false*/)
{
if (!target)
return;

BroadcastText const* bct = sObjectMgr->GetBroadcastText(textId);
if (!bct)
{
TC_LOG_ERROR("entities.unit", "WorldObject::MonsterWhisper: `broadcast_text` was not %u found", textId);
return;
}

LocaleConstant locale = target->GetSession()->GetSessionDbLocaleIndex();
WorldPacket data;
ChatHandler::BuildChatPacket(data, isBossWhisper ? CHAT_MSG_RAID_BOSS_WHISPER : CHAT_MSG_MONSTER_WHISPER, LANG_UNIVERSAL, this, target, bct->GetText(locale, GetGender()), 0, "", locale);
target->SendDirectMessage(&data);
}

// Returns collisionheight of the unit. If it is 0, it returns DEFAULT_COLLISION_HEIGHT.
float Unit::GetCollisionHeight() const
{
Expand Down
11 changes: 11 additions & 0 deletions src/server/game/Entities/Unit/Unit.h
Original file line number Diff line number Diff line change
Expand Up @@ -2566,6 +2566,17 @@ class TC_GAME_API Unit : public WorldObject
// Movement info
Movement::MoveSpline* movespline;

virtual void Talk(std::string const& text, ChatMsg msgType, Language language, float textRange, WorldObject const* target);
virtual void Say(std::string const& text, Language language, WorldObject const* target = nullptr);
virtual void Yell(std::string const& text, Language language, WorldObject const* target = nullptr);
virtual void TextEmote(std::string const& text, WorldObject const* target = nullptr, bool isBossEmote = false);
virtual void Whisper(std::string const& text, Language language, Player* target, bool isBossWhisper = false);
virtual void Talk(uint32 textId, ChatMsg msgType, float textRange, WorldObject const* target);
virtual void Say(uint32 textId, WorldObject const* target = nullptr);
virtual void Yell(uint32 textId, WorldObject const* target = nullptr);
virtual void TextEmote(uint32 textId, WorldObject const* target = nullptr, bool isBossEmote = false);
virtual void Whisper(uint32 textId, Player* target, bool isBossWhisper = false);

float GetCollisionHeight() const override;

uint32 GetMovementCounter() const
Expand Down
4 changes: 3 additions & 1 deletion src/server/game/Grids/Cells/Cell.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* This file is part of the Pandaria 5.4.8 Project. See THANKS file for Copyright information
* This file is part of the Legends of Azeroth Pandaria Project. See THANKS file for Copyright information
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
Expand Down Expand Up @@ -111,6 +111,8 @@ struct Cell

static CellArea CalculateCellArea(float x, float y, float radius);

template<class T> static void VisitWorldObjects(WorldObject const* obj, T& visitor, float radius, bool dont_load = true);

private:
template<class T, class CONTAINER> void VisitCircle(TypeContainerVisitor<T, CONTAINER> &, Map &, CellCoord const&, CellCoord const&) const;
};
Expand Down
15 changes: 14 additions & 1 deletion src/server/game/Grids/Cells/CellImpl.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* This file is part of the Pandaria 5.4.8 Project. See THANKS file for Copyright information
* This file is part of the Legends of Azeroth Pandaria Project. See THANKS file for Copyright information
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
Expand Down Expand Up @@ -176,4 +176,17 @@ inline void Cell::VisitCircle(TypeContainerVisitor<T, CONTAINER>& visitor, Map&
}
}
}

template<class T>
inline void Cell::VisitWorldObjects(WorldObject const* center_obj, T& visitor, float radius, bool dont_load /*= true*/)
{
CellCoord p(Trinity::ComputeCellCoord(center_obj->GetPositionX(), center_obj->GetPositionY()));
Cell cell(p);
if (dont_load)
cell.SetNoCreate();

TypeContainerVisitor<T, WorldTypeMapContainer> wnotifier(visitor);
cell.Visit(p, wnotifier, *center_obj->GetMap(), *center_obj, radius);
}

#endif
Loading

0 comments on commit b93a292

Please sign in to comment.