2010-10-07 15:35:36 +02:00
/*
2012-01-01 00:32:13 +01:00
* Copyright (C) 2008-2012 TrinityCore <http://www.trinitycore.org/>
2010-10-07 15:35:36 +02:00
*
* 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
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
2010-09-25 18:47:03 +02:00
*/
#include "Common.h"
#include "DatabaseEnv.h"
#include "ObjectMgr.h"
2012-03-01 22:26:05 +01:00
#include "Cell.h"
#include "CellImpl.h"
#include "GridNotifiers.h"
#include "GridNotifiersImpl.h"
#include "CreatureTextMgr.h"
class CreatureTextBuilder
{
public :
CreatureTextBuilder ( WorldObject * obj , ChatMsg msgtype , uint8 textGroup , uint32 id , uint32 language , uint64 targetGUID )
: _source ( obj ), _msgType ( msgtype ), _textGroup ( textGroup ), _textId ( id ), _language ( language ), _targetGUID ( targetGUID )
{
}
size_t operator ()( WorldPacket * data , LocaleConstant locale ) const
{
std :: string text = sCreatureTextMgr -> GetLocalizedChatString ( _source -> GetEntry (), _textGroup , _textId , locale );
char const * localizedName = _source -> GetNameForLocaleIdx ( locale );
* data << uint8 ( _msgType );
* data << uint32 ( _language );
* data << uint64 ( _source -> GetGUID ());
* data << uint32 ( 1 ); // 2.1.0
* data << uint32 ( strlen ( localizedName ) + 1 );
* data << localizedName ;
size_t whisperGUIDpos = data -> wpos ();
* data << uint64 ( _targetGUID ); // Unit Target
if ( _targetGUID && ! IS_PLAYER_GUID ( _targetGUID ))
{
* data << uint32 ( 1 ); // target name length
* data << uint8 ( 0 ); // target name
}
* data << uint32 ( text . length () + 1 );
* data << text ;
* data << uint8 ( 0 ); // ChatTag
return whisperGUIDpos ;
}
WorldObject * _source ;
ChatMsg _msgType ;
uint8 _textGroup ;
uint32 _textId ;
uint32 _language ;
uint64 _targetGUID ;
};
2010-09-25 18:47:03 +02:00
void CreatureTextMgr :: LoadCreatureTexts ()
{
2010-12-19 17:06:33 +01:00
uint32 oldMSTime = getMSTime ();
2010-09-25 18:47:03 +02:00
mTextMap . clear (); // for reload case
2010-09-26 20:48:25 +02:00
mTextRepeatMap . clear (); //reset all currently used temp texts
2010-09-25 18:47:03 +02:00
2011-12-31 20:14:38 +01:00
PreparedStatement * stmt = WorldDatabase . GetPreparedStatement ( WORLD_SEL_CREATURE_TEXT );
2010-09-25 18:47:03 +02:00
PreparedQueryResult result = WorldDatabase . Query ( stmt );
2010-09-25 22:03:57 +02:00
2010-09-25 18:47:03 +02:00
if ( ! result )
{
2010-12-23 23:25:44 +01:00
sLog -> outString ( ">> Loaded 0 ceature texts. DB table `creature_texts` is empty." );
sLog -> outString ();
2010-09-25 18:47:03 +02:00
return ;
}
2010-09-25 22:03:57 +02:00
2010-12-19 17:06:33 +01:00
uint32 textCount = 0 ;
uint32 creatureCount = 0 ;
2010-09-25 18:47:03 +02:00
do
{
Field * fields = result -> Fetch ();
CreatureTextEntry temp ;
2010-09-29 23:26:28 +02:00
temp . entry = fields [ 0 ]. GetUInt32 ();
2010-09-25 18:47:03 +02:00
temp . group = fields [ 1 ]. GetUInt8 ();
temp . id = fields [ 2 ]. GetUInt8 ();
temp . text = fields [ 3 ]. GetString ();
2011-05-13 22:44:01 +02:00
temp . type = ChatMsg ( fields [ 4 ]. GetUInt8 ());
2010-09-25 18:47:03 +02:00
temp . lang = Language ( fields [ 5 ]. GetUInt8 ());
temp . probability = fields [ 6 ]. GetFloat ();
temp . emote = Emote ( fields [ 7 ]. GetUInt32 ());
temp . duration = fields [ 8 ]. GetUInt32 ();
temp . sound = fields [ 9 ]. GetUInt32 ();
if ( temp . sound )
{
if ( ! sSoundEntriesStore . LookupEntry ( temp . sound )){
2010-12-23 23:25:44 +01:00
sLog -> outErrorDb ( "CreatureTextMgr: Entry %u, Group %u in table `creature_texts` has Sound %u but sound does not exist." , temp . entry , temp . group , temp . sound );
2010-09-25 18:47:03 +02:00
temp . sound = 0 ;
}
}
if ( ! GetLanguageDescByID ( temp . lang ))
{
2010-12-23 23:25:44 +01:00
sLog -> outErrorDb ( "CreatureTextMgr: Entry %u, Group %u in table `creature_texts` using Language %u but Language does not exist." , temp . entry , temp . group , uint32 ( temp . lang ));
2010-09-25 18:47:03 +02:00
temp . lang = LANG_UNIVERSAL ;
}
2011-05-13 22:44:01 +02:00
if ( temp . type >= MAX_CHAT_MSG_TYPE )
2010-09-25 18:47:03 +02:00
{
2010-12-23 23:25:44 +01:00
sLog -> outErrorDb ( "CreatureTextMgr: Entry %u, Group %u in table `creature_texts` has Type %u but this Chat Type does not exist." , temp . entry , temp . group , uint32 ( temp . type ));
2011-05-13 22:44:01 +02:00
temp . type = CHAT_MSG_SAY ;
2010-09-25 18:47:03 +02:00
}
if ( temp . emote )
{
if ( ! sEmotesStore . LookupEntry ( temp . emote ))
{
2010-12-23 23:25:44 +01:00
sLog -> outErrorDb ( "CreatureTextMgr: Entry %u, Group %u in table `creature_texts` has Emote %u but emote does not exist." , temp . entry , temp . group , uint32 ( temp . emote ));
2010-09-25 18:47:03 +02:00
temp . emote = EMOTE_ONESHOT_NONE ;
}
}
//entry not yet added, add empty TextHolder (list of groups)
if ( mTextMap . find ( temp . entry ) == mTextMap . end ())
2010-12-19 17:06:33 +01:00
++ creatureCount ;
2012-03-01 22:26:05 +01:00
2010-09-25 18:47:03 +02:00
//add the text into our entry's group
mTextMap [ temp . entry ][ temp . group ]. push_back ( temp );
2010-09-25 22:03:57 +02:00
2010-12-19 17:06:33 +01:00
++ textCount ;
2010-09-25 18:47:03 +02:00
} while ( result -> NextRow ());
2010-12-23 23:25:44 +01:00
sLog -> outString ( ">> Loaded %u creature texts for %u creatures in %u ms" , textCount , creatureCount , GetMSTimeDiffToNow ( oldMSTime ));
sLog -> outString ();
2010-09-25 18:47:03 +02:00
}
2010-09-25 23:52:17 +02:00
2012-03-01 22:26:05 +01:00
void CreatureTextMgr :: LoadCreatureTextLocales ()
{
uint32 oldMSTime = getMSTime ();
mLocaleTextMap . clear (); // for reload case
QueryResult result = WorldDatabase . Query ( "SELECT entry, textGroup, id, text_loc1, text_loc2, text_loc3, text_loc4, text_loc5, text_loc6, text_loc7, text_loc8 FROM locales_creature_text" );
if ( ! result )
return ;
uint32 textCount = 0 ;
do
{
Field * fields = result -> Fetch ();
CreatureTextLocale & loc = mLocaleTextMap [ CreatureTextId ( fields [ 0 ]. GetUInt32 (), uint32 ( fields [ 1 ]. GetUInt8 ()), fields [ 2 ]. GetUInt32 ())];
for ( uint8 i = 1 ; i < TOTAL_LOCALES ; ++ i )
{
LocaleConstant locale = LocaleConstant ( i );
2012-03-05 23:23:23 +01:00
ObjectMgr :: AddLocaleString ( fields [ 3 + i - 1 ]. GetString (), locale , loc . Text );
2012-03-01 22:26:05 +01:00
}
++ textCount ;
} while ( result -> NextRow ());
sLog -> outString ( ">> Loaded %u creature localized texts in %u ms" , textCount , GetMSTimeDiffToNow ( oldMSTime ));
sLog -> outString ();
}
2011-05-13 22:44:01 +02:00
uint32 CreatureTextMgr :: SendChat ( Creature * source , uint8 textGroup , uint64 whisperGuid /*= 0*/ , ChatMsg msgType /*= CHAT_MSG_ADDON*/ , Language language /*= LANG_ADDON*/ , TextRange range /*= TEXT_RANGE_NORMAL*/ , uint32 sound /*= 0*/ , Team team /*= TEAM_OTHER*/ , bool gmOnly /*= false*/ , Player * srcPlr /*= NULL*/ )
2010-09-25 23:52:17 +02:00
{
2010-09-26 20:48:25 +02:00
if ( ! source )
2010-09-29 23:26:28 +02:00
return 0 ;
2012-03-01 22:26:05 +01:00
2010-09-26 20:48:25 +02:00
CreatureTextMap :: const_iterator sList = mTextMap . find ( source -> GetEntry ());
if ( sList == mTextMap . end ())
{
2011-04-29 20:47:02 +02:00
sLog -> outErrorDb ( "CreatureTextMgr: Could not find Text for Creature(%s) Entry %u in 'creature_text' table. Ignoring." , source -> GetName (), source -> GetEntry ());
2010-09-29 23:26:28 +02:00
return 0 ;
2010-09-26 20:48:25 +02:00
}
2012-03-01 22:26:05 +01:00
CreatureTextHolder const & textHolder = sList -> second ;
CreatureTextHolder :: const_iterator itr = textHolder . find ( textGroup );
if ( itr == textHolder . end ())
2010-09-26 20:48:25 +02:00
{
2011-04-29 20:47:02 +02:00
sLog -> outErrorDb ( "CreatureTextMgr: Could not find TextGroup %u for Creature(%s) GuidLow %u Entry %u. Ignoring." , uint32 ( textGroup ), source -> GetName (), source -> GetGUIDLow (), source -> GetEntry ());
2010-09-29 23:26:28 +02:00
return 0 ;
2010-09-26 20:48:25 +02:00
}
2012-03-01 22:26:05 +01:00
CreatureTextGroup const & textGroupContainer = itr -> second ; //has all texts in the group
2011-04-29 20:47:02 +02:00
CreatureTextRepeatIds repeatGroup = GetRepeatGroup ( source , textGroup ); //has all textIDs from the group that were already said
2010-09-26 20:48:25 +02:00
CreatureTextGroup tempGroup ; //will use this to talk after sorting repeatGroup
2012-03-01 22:26:05 +01:00
for ( CreatureTextGroup :: const_iterator giter = textGroupContainer . begin (); giter != textGroupContainer . end (); ++ giter )
if ( std :: find ( repeatGroup . begin (), repeatGroup . end (), giter -> id ) == repeatGroup . end ())
tempGroup . push_back ( * giter );
2010-09-26 20:48:25 +02:00
if ( tempGroup . empty ())
{
CreatureTextRepeatMap :: iterator mapItr = mTextRepeatMap . find ( source -> GetGUID ());
if ( mapItr != mTextRepeatMap . end ())
{
2012-03-01 22:26:05 +01:00
CreatureTextRepeatGroup :: iterator groupItr = mapItr -> second . find ( textGroup );
groupItr -> second . clear ();
2010-09-26 20:48:25 +02:00
}
2012-03-01 22:26:05 +01:00
tempGroup = textGroupContainer ;
2010-09-26 20:48:25 +02:00
}
2012-03-01 22:26:05 +01:00
2010-09-26 20:48:25 +02:00
uint8 count = 0 ;
float lastChance = - 1 ;
bool isEqualChanced = true ;
float totalChance = 0 ;
for ( CreatureTextGroup :: const_iterator iter = tempGroup . begin (); iter != tempGroup . end (); ++ iter )
{
2012-03-01 22:26:05 +01:00
if ( lastChance >= 0 && lastChance != iter -> probability )
2010-09-26 20:48:25 +02:00
isEqualChanced = false ;
2012-03-01 22:26:05 +01:00
lastChance = iter -> probability ;
totalChance += iter -> probability ;
++ count ;
2010-09-26 20:48:25 +02:00
}
2012-03-01 22:26:05 +01:00
2010-09-29 23:26:28 +02:00
int32 offset = - 1 ;
if ( ! isEqualChanced )
2010-09-26 20:48:25 +02:00
{
for ( CreatureTextGroup :: const_iterator iter = tempGroup . begin (); iter != tempGroup . end (); ++ iter )
{
2012-03-01 22:26:05 +01:00
uint32 chance = uint32 ( iter -> probability );
2010-09-26 20:48:25 +02:00
uint32 r = urand ( 0 , 100 );
2012-03-01 22:26:05 +01:00
++ offset ;
2010-09-26 20:48:25 +02:00
if ( r <= chance )
2010-10-07 14:00:52 +02:00
break ;
2010-09-26 20:48:25 +02:00
}
}
2012-03-01 22:26:05 +01:00
2010-09-29 23:26:28 +02:00
uint32 pos = 0 ;
if ( isEqualChanced || offset < 0 )
2011-04-29 20:47:02 +02:00
pos = urand ( 0 , count - 1 );
2010-09-29 23:26:28 +02:00
else if ( offset >= 0 )
pos = offset ;
2012-03-01 22:26:05 +01:00
2010-09-29 23:26:28 +02:00
CreatureTextGroup :: const_iterator iter = tempGroup . begin () + pos ;
2012-03-01 22:26:05 +01:00
ChatMsg finalType = ( msgType == CHAT_MSG_ADDON ) ? iter -> type : msgType ;
Language finalLang = ( language == LANG_ADDON ) ? iter -> lang : language ;
uint32 finalSound = sound ? sound : iter -> sound ;
2010-09-29 23:26:28 +02:00
if ( finalSound )
2010-10-25 18:25:21 +02:00
SendSound ( source , finalSound , finalType , whisperGuid , range , team , gmOnly );
2010-09-29 23:26:28 +02:00
2012-03-01 22:26:05 +01:00
Unit * finalSource = source ;
if ( srcPlr )
finalSource = srcPlr ;
2010-09-26 20:48:25 +02:00
2012-03-01 22:26:05 +01:00
if ( iter -> emote )
SendEmote ( finalSource , iter -> emote );
2010-09-26 20:48:25 +02:00
2012-03-01 22:26:05 +01:00
CreatureTextBuilder builder ( finalSource , finalType , iter -> group , iter -> id , finalLang , whisperGuid );
SendChatPacket ( finalSource , builder , finalType , whisperGuid , range , team , gmOnly );
if ( isEqualChanced || ( ! isEqualChanced && totalChance == 100.0f ))
SetRepeatId ( source , textGroup , iter -> id );
2010-09-26 20:48:25 +02:00
2012-03-01 22:26:05 +01:00
return iter -> duration ;
2010-09-25 23:52:17 +02:00
}
2012-03-01 22:26:05 +01:00
float CreatureTextMgr :: GetRangeForChatType ( ChatMsg msgType ) const
2010-09-25 23:52:17 +02:00
{
2012-03-01 22:26:05 +01:00
float dist = sWorld -> getFloatConfig ( CONFIG_LISTEN_RANGE_SAY );
2011-05-13 22:44:01 +02:00
switch ( msgType )
2010-09-25 23:52:17 +02:00
{
2012-03-01 22:26:05 +01:00
case CHAT_MSG_MONSTER_YELL :
dist = sWorld -> getFloatConfig ( CONFIG_LISTEN_RANGE_YELL );
2010-09-25 23:52:17 +02:00
break ;
2012-03-01 22:26:05 +01:00
case CHAT_MSG_MONSTER_EMOTE :
case CHAT_MSG_RAID_BOSS_EMOTE :
dist = sWorld -> getFloatConfig ( CONFIG_LISTEN_RANGE_TEXTEMOTE );
2010-09-25 23:52:17 +02:00
break ;
default :
break ;
}
2012-03-01 22:26:05 +01:00
return dist ;
2010-09-25 23:52:17 +02:00
}
2012-03-01 22:26:05 +01:00
void CreatureTextMgr :: SendSound ( Creature * source , uint32 sound , ChatMsg msgType , uint64 whisperGuid , TextRange range , Team team , bool gmOnly )
2010-09-25 23:52:17 +02:00
{
2012-03-01 22:26:05 +01:00
if ( ! sound || ! source )
2010-09-26 20:48:25 +02:00
return ;
2012-03-01 22:26:05 +01:00
WorldPacket data ( SMSG_PLAY_SOUND , 4 );
data << uint32 ( sound );
SendNonChatPacket ( source , & data , msgType , whisperGuid , range , team , gmOnly );
}
void CreatureTextMgr :: SendNonChatPacket ( WorldObject * source , WorldPacket * data , ChatMsg msgType , uint64 whisperGuid , TextRange range , Team team , bool gmOnly ) const
{
float dist = GetRangeForChatType ( msgType );
2010-10-07 14:00:52 +02:00
2011-05-13 22:44:01 +02:00
switch ( msgType )
2010-09-25 23:52:17 +02:00
{
2011-05-13 22:44:01 +02:00
case CHAT_MSG_MONSTER_WHISPER :
case CHAT_MSG_RAID_BOSS_WHISPER :
{
if ( range == TEXT_RANGE_NORMAL ) //ignores team and gmOnly
2010-09-25 23:52:17 +02:00
{
2011-07-27 12:14:27 +02:00
Player * player = ObjectAccessor :: FindPlayer ( whisperGuid );
2011-05-13 22:44:01 +02:00
if ( ! player || ! player -> GetSession ())
2010-09-25 23:52:17 +02:00
return ;
2011-05-13 22:44:01 +02:00
player -> GetSession () -> SendPacket ( data );
return ;
2010-09-25 23:52:17 +02:00
}
2010-09-29 23:26:28 +02:00
break ;
2011-05-13 22:44:01 +02:00
}
2010-09-25 23:52:17 +02:00
default :
break ;
}
switch ( range )
{
case TEXT_RANGE_AREA :
2011-05-16 21:19:32 +02:00
{
uint32 areaId = source -> GetAreaId ();
2012-03-01 22:26:05 +01:00
Map :: PlayerList const & players = source -> GetMap () -> GetPlayers ();
for ( Map :: PlayerList :: const_iterator itr = players . begin (); itr != players . end (); ++ itr )
2011-05-16 21:19:32 +02:00
if ( itr -> getSource () -> GetAreaId () == areaId && ( ! team || Team ( itr -> getSource () -> GetTeam ()) == team ) && ( ! gmOnly || itr -> getSource () -> isGameMaster ()))
2012-03-01 22:26:05 +01:00
itr -> getSource () -> GetSession () -> SendPacket ( data );
2010-09-25 23:52:17 +02:00
return ;
2011-05-16 21:19:32 +02:00
}
2010-09-25 23:52:17 +02:00
case TEXT_RANGE_ZONE :
2011-05-16 21:19:32 +02:00
{
uint32 zoneId = source -> GetZoneId ();
2012-03-01 22:26:05 +01:00
Map :: PlayerList const & players = source -> GetMap () -> GetPlayers ();
for ( Map :: PlayerList :: const_iterator itr = players . begin (); itr != players . end (); ++ itr )
2011-05-16 21:19:32 +02:00
if ( itr -> getSource () -> GetZoneId () == zoneId && ( ! team || Team ( itr -> getSource () -> GetTeam ()) == team ) && ( ! gmOnly || itr -> getSource () -> isGameMaster ()))
2012-03-01 22:26:05 +01:00
itr -> getSource () -> GetSession () -> SendPacket ( data );
2010-09-25 23:52:17 +02:00
return ;
2011-05-16 21:19:32 +02:00
}
case TEXT_RANGE_MAP :
{
2012-03-01 22:26:05 +01:00
Map :: PlayerList const & players = source -> GetMap () -> GetPlayers ();
for ( Map :: PlayerList :: const_iterator itr = players . begin (); itr != players . end (); ++ itr )
2011-05-16 21:19:32 +02:00
if (( ! team || Team ( itr -> getSource () -> GetTeam ()) == team ) && ( ! gmOnly || itr -> getSource () -> isGameMaster ()))
2012-03-01 22:26:05 +01:00
itr -> getSource () -> GetSession () -> SendPacket ( data );
2011-05-16 21:19:32 +02:00
return ;
}
2010-09-25 23:52:17 +02:00
case TEXT_RANGE_WORLD :
2011-05-16 21:19:32 +02:00
{
2012-03-01 22:26:05 +01:00
SessionMap const & smap = sWorld -> GetAllSessions ();
2011-05-16 21:19:32 +02:00
for ( SessionMap :: const_iterator iter = smap . begin (); iter != smap . end (); ++ iter )
2012-03-01 22:26:05 +01:00
if ( Player * player = iter -> second -> GetPlayer ())
2011-11-07 11:06:39 -06:00
if ( player -> GetSession () && ( ! team || Team ( player -> GetTeam ()) == team ) && ( ! gmOnly || player -> isGameMaster ()))
player -> GetSession () -> SendPacket ( data );
2010-09-25 23:52:17 +02:00
return ;
2011-05-16 21:19:32 +02:00
}
2010-09-25 23:52:17 +02:00
case TEXT_RANGE_NORMAL :
default :
break ;
}
2012-03-01 22:26:05 +01:00
2010-09-25 23:52:17 +02:00
source -> SendMessageToSetInRange ( data , dist , true );
}
2010-10-25 18:25:21 +02:00
2012-03-01 22:26:05 +01:00
void CreatureTextMgr :: SendEmote ( Unit * source , uint32 emote )
{
if ( ! source )
return ;
source -> HandleEmoteCommand ( emote );
}
void CreatureTextMgr :: SetRepeatId ( Creature * source , uint8 textGroup , uint8 id )
{
if ( ! source )
return ;
CreatureTextRepeatIds & repeats = mTextRepeatMap [ source -> GetGUID ()][ textGroup ];
if ( std :: find ( repeats . begin (), repeats . end (), id ) == repeats . end ())
repeats . push_back ( id );
else
sLog -> outErrorDb ( "CreatureTextMgr: TextGroup %u for Creature(%s) GuidLow %u Entry %u, id %u already added" , uint32 ( textGroup ), source -> GetName (), source -> GetGUIDLow (), source -> GetEntry (), uint32 ( id ));
}
CreatureTextRepeatIds CreatureTextMgr :: GetRepeatGroup ( Creature * source , uint8 textGroup )
{
ASSERT ( source ); //should never happen
CreatureTextRepeatIds ids ;
CreatureTextRepeatMap :: const_iterator mapItr = mTextRepeatMap . find ( source -> GetGUID ());
if ( mapItr != mTextRepeatMap . end ())
{
CreatureTextRepeatGroup :: const_iterator groupItr = ( * mapItr ). second . find ( textGroup );
if ( groupItr != mapItr -> second . end ())
ids = groupItr -> second ;
}
return ids ;
}
2010-10-25 18:25:21 +02:00
bool CreatureTextMgr :: TextExist ( uint32 sourceEntry , uint8 textGroup )
{
if ( ! sourceEntry )
return false ;
2012-03-01 22:26:05 +01:00
2010-10-25 18:25:21 +02:00
CreatureTextMap :: const_iterator sList = mTextMap . find ( sourceEntry );
if ( sList == mTextMap . end ())
{
2011-02-20 20:16:34 +01:00
sLog -> outDebug ( LOG_FILTER_UNITS , "CreatureTextMgr::TextExist: Could not find Text for Creature (entry %u) in 'creature_text' table." , sourceEntry );
2010-10-25 18:25:21 +02:00
return false ;
}
2012-03-01 22:26:05 +01:00
CreatureTextHolder const & textHolder = sList -> second ;
CreatureTextHolder :: const_iterator itr = textHolder . find ( textGroup );
if ( itr == textHolder . end ())
2010-10-25 18:25:21 +02:00
{
2011-04-29 20:47:02 +02:00
sLog -> outDebug ( LOG_FILTER_UNITS , "CreatureTextMgr::TextExist: Could not find TextGroup %u for Creature (entry %u)." , uint32 ( textGroup ), sourceEntry );
2010-10-25 18:25:21 +02:00
return false ;
}
2012-03-01 22:26:05 +01:00
2010-10-25 18:25:21 +02:00
return true ;
2010-10-26 11:40:13 +02:00
}
2012-03-01 22:26:05 +01:00
std :: string CreatureTextMgr :: GetLocalizedChatString ( uint32 entry , uint8 textGroup , uint32 id , LocaleConstant locale ) const
{
CreatureTextMap :: const_iterator mapitr = mTextMap . find ( entry );
if ( mapitr == mTextMap . end ())
return "" ;
CreatureTextHolder :: const_iterator holderItr = mapitr -> second . find ( textGroup );
if ( holderItr == mapitr -> second . end ())
return "" ;
CreatureTextGroup :: const_iterator groupItr = holderItr -> second . begin ();
for (; groupItr != holderItr -> second . end (); ++ groupItr )
if ( groupItr -> id == id )
break ;
if ( groupItr == holderItr -> second . end ())
return "" ;
std :: string baseText = groupItr -> text ;
if ( locale == DEFAULT_LOCALE )
return baseText ;
if ( locale > MAX_LOCALES )
return baseText ;
LocaleCreatureTextMap :: const_iterator locItr = mLocaleTextMap . find ( CreatureTextId ( entry , uint32 ( textGroup ), id ));
if ( locItr == mLocaleTextMap . end ())
return baseText ;
2012-03-10 20:21:27 +01:00
ObjectMgr :: GetLocaleString ( locItr -> second . Text , locale , baseText );
2012-03-01 22:26:05 +01:00
return baseText ;
}