diff options
| author | joschiwald <joschiwald.trinity@gmail.com> | 2014-09-13 20:41:31 +0200 |
|---|---|---|
| committer | joschiwald <joschiwald.trinity@gmail.com> | 2014-09-13 20:41:31 +0200 |
| commit | 59baaeec48fdd92d8b4067152772e5806be9ff53 (patch) | |
| tree | b4031184f1e16cfb9f87b8c8f5ec5ba5c7ba1f70 /src/server/game/Entities/Unit | |
| parent | 11bb300c6977f32d5240a698a12e258dc121a513 (diff) | |
Core/Chat: cleanup MonsterText methods
Diffstat (limited to 'src/server/game/Entities/Unit')
| -rw-r--r-- | src/server/game/Entities/Unit/Unit.cpp | 84 | ||||
| -rw-r--r-- | src/server/game/Entities/Unit/Unit.h | 11 |
2 files changed, 94 insertions, 1 deletions
diff --git a/src/server/game/Entities/Unit/Unit.cpp b/src/server/game/Entities/Unit/Unit.cpp index adf093f0f17..d29908bc085 100644 --- a/src/server/game/Entities/Unit/Unit.cpp +++ b/src/server/game/Entities/Unit/Unit.cpp @@ -23,6 +23,7 @@ #include "Battleground.h" #include "BattlegroundScore.h" #include "CellImpl.h" +#include "ChatTextBuilder.h" #include "ConditionMgr.h" #include "CreatureAI.h" #include "CreatureAIImpl.h" @@ -8132,7 +8133,7 @@ bool Unit::HandleProcTriggerSpell(Unit* victim, uint32 damage, AuraEffect* trigg if (triggerEntry == NULL) { // Don't cast unknown spell - // TC_LOG_ERROR("entities.unit", "Unit::HandleProcTriggerSpell: Spell %u has 0 in EffectTriggered[%d]. Unhandled custom case?", auraSpellInfo->Id, triggeredByAura->GetEffIndex()); + TC_LOG_ERROR("entities.unit", "Unit::HandleProcTriggerSpell: Spell %u (effIndex: %u) has unknown TriggerSpell %u. Unhandled custom case?", auraSpellInfo->Id, triggeredByAura->GetEffIndex(), trigger_spell_id); return false; } @@ -17840,3 +17841,84 @@ bool Unit::IsHighestExclusiveAura(Aura const* aura, bool removeOtherAuraApplicat return true; } + +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); + VisitNearbyWorldObject(textRange, worker); +} + +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` was not %u found", textId); + return; + } + + Trinity::BroadcastTextBuilder builder(this, msgType, textId, target); + Trinity::LocalizedPacketDo<Trinity::BroadcastTextBuilder> localizer(builder); + Trinity::PlayerDistWorker<Trinity::LocalizedPacketDo<Trinity::BroadcastTextBuilder> > worker(this, textRange, localizer); + VisitNearbyWorldObject(textRange, worker); +} + +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); +} diff --git a/src/server/game/Entities/Unit/Unit.h b/src/server/game/Entities/Unit/Unit.h index 20ca614b42d..7d40b1c24db 100644 --- a/src/server/game/Entities/Unit/Unit.h +++ b/src/server/game/Entities/Unit/Unit.h @@ -2158,6 +2158,17 @@ class Unit : public WorldObject int32 GetHighestExclusiveSameEffectSpellGroupValue(AuraEffect const* aurEff, AuraType auraType, bool checkMiscValue = false, int32 miscValue = 0) const; bool IsHighestExclusiveAura(Aura const* aura, bool removeOtherAuraApplications = false); + 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); + void Talk(uint32 textId, ChatMsg msgType, float textRange, WorldObject const* target); + void Say(uint32 textId, WorldObject const* target = nullptr); + void Yell(uint32 textId, WorldObject const* target = nullptr); + void TextEmote(uint32 textId, WorldObject const* target = nullptr, bool isBossEmote = false); + void Whisper(uint32 textId, Player* target, bool isBossWhisper = false); + protected: explicit Unit (bool isWorldObject); |
