Core/TextMgr: updated with new funtions for future useage

--HG--
branch : trunk
This commit is contained in:
Rat
2010-10-25 18:25:21 +02:00
parent a792e3d67c
commit e4c27a2ffa
2 changed files with 63 additions and 20 deletions
+58 -15
View File
@@ -108,7 +108,7 @@ void CreatureTextMgr::LoadCreatureTexts()
sLog.outString(">> Loaded %u Creature Texts for %u Creatures.", TextCount, CreatureCount); sLog.outString(">> Loaded %u Creature Texts for %u Creatures.", TextCount, CreatureCount);
} }
uint32 CreatureTextMgr::SendChat(Creature* source, uint8 textGroup, uint64 whisperGuid, ChatType msgtype, Language language, TextRange range, uint32 sound) uint32 CreatureTextMgr::SendChat(Creature* source, uint8 textGroup, uint64 whisperGuid, ChatType msgtype, Language language, TextRange range, uint32 sound, Team team, bool gmOnly)
{ {
if (!source) if (!source)
return 0; return 0;
@@ -183,25 +183,25 @@ uint32 CreatureTextMgr::SendChat(Creature* source, uint8 textGroup, uint64 whisp
uint32 finalSound = sound ? sound : (*iter).sound; uint32 finalSound = sound ? sound : (*iter).sound;
if (finalSound) if (finalSound)
SendSound(source, finalSound, finalType, whisperGuid, range); SendSound(source, finalSound, finalType, whisperGuid, range, team, gmOnly);
SendChatString(source, (*iter).text.c_str(), finalType, finalLang, whisperGuid, range);
if (isEqualChanced || (!isEqualChanced && totalChance == 100.0f))
SetRepeatId(source, textGroup, (*iter).id);
if ((*iter).emote) if ((*iter).emote)
SendEmote(source, (*iter).emote); SendEmote(source, (*iter).emote);
SendChatString(source, (*iter).text.c_str(), finalType, finalLang, whisperGuid, range, team, gmOnly);
if (isEqualChanced || (!isEqualChanced && totalChance == 100.0f))
SetRepeatId(source, textGroup, (*iter).id);
return (*iter).duration; return (*iter).duration;
} }
void CreatureTextMgr::SendSound(Creature* source,uint32 sound, ChatType msgtype, uint64 whisperGuid, TextRange range) void CreatureTextMgr::SendSound(Creature* source,uint32 sound, ChatType msgtype, uint64 whisperGuid, TextRange range, Team team, bool gmOnly)
{ {
if (!sound || !source) if (!sound || !source)
return; return;
WorldPacket data(SMSG_PLAY_SOUND, 4); WorldPacket data(SMSG_PLAY_SOUND, 4);
data << uint32(sound); data << uint32(sound);
SendChatPacket(&data, source, msgtype, whisperGuid, range); SendChatPacket(&data, source, msgtype, whisperGuid, range, team, gmOnly);
} }
void CreatureTextMgr::SendEmote(Creature* source, uint32 emote) void CreatureTextMgr::SendEmote(Creature* source, uint32 emote)
{ {
@@ -248,14 +248,14 @@ CreatureTextRepeatIds CreatureTextMgr::GetRepeatGroup(Creature* source, uint8 te
return ids; return ids;
} }
void CreatureTextMgr::SendChatString(WorldObject* source, char const* text, ChatType msgtype, Language language, uint64 whisperGuid, TextRange range) const void CreatureTextMgr::SendChatString(WorldObject* source, char const* text, ChatType msgtype, Language language, uint64 whisperGuid, TextRange range, Team team, bool gmOnly) const
{ {
if (!source) if (!source)
return; return;
WorldPacket data(SMSG_MESSAGECHAT, 200); WorldPacket data(SMSG_MESSAGECHAT, 200);
BuildMonsterChat(&data, source, msgtype, text, language, whisperGuid);//build our packet BuildMonsterChat(&data, source, msgtype, text, language, whisperGuid);//build our packet
SendChatPacket(&data, source, msgtype, whisperGuid, range);//send our packet SendChatPacket(&data, source, msgtype, whisperGuid, range, team, gmOnly);//send our packet
} }
void CreatureTextMgr::BuildMonsterChat(WorldPacket *data, WorldObject* source, ChatType msgtype, char const* text, Language language, uint64 whisperGuid) const void CreatureTextMgr::BuildMonsterChat(WorldPacket *data, WorldObject* source, ChatType msgtype, char const* text, Language language, uint64 whisperGuid) const
@@ -316,7 +316,7 @@ void CreatureTextMgr::BuildMonsterChat(WorldPacket *data, WorldObject* source, C
*data << (uint8)0; // ChatTag *data << (uint8)0; // ChatTag
} }
void CreatureTextMgr::SendChatPacket(WorldPacket *data, WorldObject* source, ChatType msgtype, uint64 whisperGuid, TextRange range) const void CreatureTextMgr::SendChatPacket(WorldPacket *data, WorldObject* source, ChatType msgtype, uint64 whisperGuid, TextRange range, Team team, bool gmOnly) const
{ {
if (!source) if (!source)
return; return;
@@ -335,7 +335,7 @@ void CreatureTextMgr::SendChatPacket(WorldPacket *data, WorldObject* source, Cha
case CHAT_TYPE_WHISPER: case CHAT_TYPE_WHISPER:
case CHAT_TYPE_BOSS_WHISPER: case CHAT_TYPE_BOSS_WHISPER:
{ {
if (range == TEXT_RANGE_NORMAL) if (range == TEXT_RANGE_NORMAL)//ignores team and gmOnly
{ {
Player *player = sObjectMgr.GetPlayer(whisperGuid); Player *player = sObjectMgr.GetPlayer(whisperGuid);
if (!player || !player->GetSession()) if (!player || !player->GetSession())
@@ -357,29 +357,52 @@ void CreatureTextMgr::SendChatPacket(WorldPacket *data, WorldObject* source, Cha
uint32 areaId = source->GetAreaId(); uint32 areaId = source->GetAreaId();
Map::PlayerList const& pList = source->GetMap()->GetPlayers(); Map::PlayerList const& pList = source->GetMap()->GetPlayers();
for (Map::PlayerList::const_iterator itr = pList.begin(); itr != pList.end(); ++itr) for (Map::PlayerList::const_iterator itr = pList.begin(); itr != pList.end(); ++itr)
if (itr->getSource()->GetAreaId() == areaId) if (itr->getSource()->GetAreaId() == areaId && (!team || (team && itr->getSource()->GetTeam() == team)) && (!gmOnly || itr->getSource()->isGameMaster()))
{
if (data->GetOpcode() == SMSG_MESSAGECHAT)//override whisperguid with actual player's guid
data->put<uint64>(1+4+8+4+4+(int32)(strlen(source->GetName())+1), uint64(itr->getSource()->GetGUID()));
(itr->getSource())->GetSession()->SendPacket(data); (itr->getSource())->GetSession()->SendPacket(data);
} }
}
return; return;
case TEXT_RANGE_ZONE: case TEXT_RANGE_ZONE:
{ {
uint32 zoneId = source->GetZoneId(); uint32 zoneId = source->GetZoneId();
Map::PlayerList const& pList = source->GetMap()->GetPlayers(); Map::PlayerList const& pList = source->GetMap()->GetPlayers();
for (Map::PlayerList::const_iterator itr = pList.begin(); itr != pList.end(); ++itr) for (Map::PlayerList::const_iterator itr = pList.begin(); itr != pList.end(); ++itr)
if (itr->getSource()->GetZoneId() == zoneId) if (itr->getSource()->GetZoneId() == zoneId && (!team || (team && itr->getSource()->GetTeam() == team)) && (!gmOnly || itr->getSource()->isGameMaster()))
{
if (data->GetOpcode() == SMSG_MESSAGECHAT)//override whisperguid with actual player's guid
data->put<uint64>(1+4+8+4+4+(int32)(strlen(source->GetName())+1), uint64(itr->getSource()->GetGUID()));
(itr->getSource())->GetSession()->SendPacket(data); (itr->getSource())->GetSession()->SendPacket(data);
} }
}
return; return;
case TEXT_RANGE_MAP: case TEXT_RANGE_MAP:
{ {
Map::PlayerList const& pList = source->GetMap()->GetPlayers(); Map::PlayerList const& pList = source->GetMap()->GetPlayers();
for (Map::PlayerList::const_iterator itr = pList.begin(); itr != pList.end(); ++itr) for (Map::PlayerList::const_iterator itr = pList.begin(); itr != pList.end(); ++itr)
{
if (data->GetOpcode() == SMSG_MESSAGECHAT)//override whisperguid with actual player's guid
data->put<uint64>(1+4+8+4+4+(int32)(strlen(source->GetName())+1), uint64(itr->getSource()->GetGUID()));
if (!team || (team && itr->getSource()->GetTeam() == team) && (!gmOnly || itr->getSource()->isGameMaster()))
(itr->getSource())->GetSession()->SendPacket(data); (itr->getSource())->GetSession()->SendPacket(data);
} }
}
return; return;
case TEXT_RANGE_WORLD: case TEXT_RANGE_WORLD:
{ {
sWorld.SendGlobalMessage(data); const SessionMap smap = sWorld.GetAllSessions();
for (SessionMap::const_iterator iter = smap.begin(); iter != smap.end(); ++iter)
{
if (Player* plr = (*iter).second->GetPlayer())
{
if (data->GetOpcode() == SMSG_MESSAGECHAT)//override whisperguid with actual player's guid
data->put<uint64>(1+4+8+4+4+(int32)(strlen(source->GetName())+1), uint64(plr->GetGUID()));
if (plr->GetSession() && (!team || (team && plr->GetTeam() == team)) && (!gmOnly || plr->isGameMaster()))
plr->GetSession()->SendPacket(data);
}
}
} }
return; return;
case TEXT_RANGE_NORMAL: case TEXT_RANGE_NORMAL:
@@ -388,3 +411,23 @@ void CreatureTextMgr::SendChatPacket(WorldPacket *data, WorldObject* source, Cha
} }
source->SendMessageToSetInRange(data, dist, true); source->SendMessageToSetInRange(data, dist, true);
} }
bool CreatureTextMgr::TextExist(uint32 sourceEntry, uint8 textGroup)
{
if (!sourceEntry)
return false;
CreatureTextMap::const_iterator sList = mTextMap.find(sourceEntry);
if (sList == mTextMap.end())
{
sLog.outErrorDb("CreatureTextMgr::TextExist: Could not find Text for Creature (entry %u) in 'creature_text' table.", sourceEntry);
return false;
}
CreatureTextHolder TextHolder = (*sList).second;
CreatureTextHolder::const_iterator itr = TextHolder.find(textGroup);
if (itr == TextHolder.end())
{
sLog.outErrorDb("CreatureTextMgr::TextExist: Could not find TextGroup %u for Creature (entry %u).",uint32(textGroup), sourceEntry);
return false;
}
return true;
}
+5 -5
View File
@@ -62,18 +62,18 @@ class CreatureTextMgr
void LoadCreatureTexts(); void LoadCreatureTexts();
CreatureTextMap const& GetTextMap() const { return mTextMap; } CreatureTextMap const& GetTextMap() const { return mTextMap; }
void SendSound(Creature* source,uint32 sound, ChatType msgtype, uint64 whisperGuid, TextRange range); void SendSound(Creature* source,uint32 sound, ChatType msgtype, uint64 whisperGuid, TextRange range, Team team, bool gmOnly);
void SendEmote(Creature* source, uint32 emote); void SendEmote(Creature* source, uint32 emote);
//if sent, returns the 'duration' of the text else 0 if error //if sent, returns the 'duration' of the text else 0 if error
uint32 SendChat(Creature* source, uint8 textGroup, uint64 whisperGuid = 0, ChatType msgtype = CHAT_TYPE_END, Language language = LANG_ADDON, TextRange range = TEXT_RANGE_NORMAL, uint32 sound = 0); uint32 SendChat(Creature* source, uint8 textGroup, uint64 whisperGuid = 0, ChatType msgtype = CHAT_TYPE_END, Language language = LANG_ADDON, TextRange range = TEXT_RANGE_NORMAL, uint32 sound = 0, Team team = TEAM_OTHER, bool gmOnly = false);
void SendChatString(WorldObject* source, char const* text, ChatType msgtype = CHAT_TYPE_SAY, Language language = LANG_UNIVERSAL, uint64 whisperGuid = 0, TextRange range = TEXT_RANGE_NORMAL) const; void SendChatString(WorldObject* source, char const* text, ChatType msgtype = CHAT_TYPE_SAY, Language language = LANG_UNIVERSAL, uint64 whisperGuid = 0, TextRange range = TEXT_RANGE_NORMAL, Team team = TEAM_OTHER, bool gmOnly = false) const;
bool TextExist(uint32 sourceEntry, uint8 textGroup);
private: private:
CreatureTextRepeatIds GetRepeatGroup(Creature* source, uint8 textGroup); CreatureTextRepeatIds GetRepeatGroup(Creature* source, uint8 textGroup);
void SetRepeatId(Creature* source, uint8 textGroup, uint8 id); void SetRepeatId(Creature* source, uint8 textGroup, uint8 id);
void BuildMonsterChat(WorldPacket *data, WorldObject* source, ChatType msgtype, char const* text, Language language, uint64 whisperGuid) const; void BuildMonsterChat(WorldPacket *data, WorldObject* source, ChatType msgtype, char const* text, Language language, uint64 whisperGuid) const;
void SendChatPacket(WorldPacket *data, WorldObject* source, ChatType msgtype, uint64 whisperGuid, TextRange range) const; void SendChatPacket(WorldPacket *data, WorldObject* source, ChatType msgtype, uint64 whisperGuid, TextRange range, Team team, bool gmOnly) const;
CreatureTextMap mTextMap; CreatureTextMap mTextMap;
CreatureTextRepeatMap mTextRepeatMap; CreatureTextRepeatMap mTextRepeatMap;