本文整理汇总了C++中CreatureTextRepeatIds类的典型用法代码示例。如果您正苦于以下问题:C++ CreatureTextRepeatIds类的具体用法?C++ CreatureTextRepeatIds怎么用?C++ CreatureTextRepeatIds使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CreatureTextRepeatIds类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: TC_LOG_ERROR
uint32 CreatureTextMgr::SendChat(Creature* source, uint8 textGroup, WorldObject const* whisperTarget /*= nullptr*/, ChatMsg msgType /*= CHAT_MSG_ADDON*/, Language language /*= LANG_ADDON*/, CreatureTextRange range /*= TEXT_RANGE_NORMAL*/, uint32 sound /*= 0*/, Team team /*= TEAM_OTHER*/, bool gmOnly /*= false*/, Player* srcPlr /*= nullptr*/)
{
if (!source)
return 0;
CreatureTextMap::const_iterator sList = mTextMap.find(source->GetEntry());
if (sList == mTextMap.end())
{
TC_LOG_ERROR("sql.sql", "CreatureTextMgr: Could not find Text for Creature %s (Entry %u, GUID %u) in 'creature_text' table. Ignoring.", source->GetName().c_str(), source->GetEntry(), source->GetGUIDLow());
return 0;
}
CreatureTextHolder const& textHolder = sList->second;
CreatureTextHolder::const_iterator itr = textHolder.find(textGroup);
if (itr == textHolder.end())
{
TC_LOG_ERROR("sql.sql", "CreatureTextMgr: Could not find TextGroup %u for Creature %s (Entry %u, GUID %u) in 'creature_text' table. Ignoring.", uint32(textGroup), source->GetName().c_str(), source->GetEntry(), source->GetGUIDLow());
return 0;
}
CreatureTextGroup const& textGroupContainer = itr->second; //has all texts in the group
CreatureTextRepeatIds repeatGroup = GetRepeatGroup(source, textGroup);//has all textIDs from the group that were already said
CreatureTextGroup tempGroup;//will use this to talk after sorting repeatGroup
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);
if (tempGroup.empty())
{
CreatureTextRepeatMap::iterator mapItr = mTextRepeatMap.find(source->GetGUID());
if (mapItr != mTextRepeatMap.end())
{
CreatureTextRepeatGroup::iterator groupItr = mapItr->second.find(textGroup);
groupItr->second.clear();
}
tempGroup = textGroupContainer;
}
uint8 count = 0;
float lastChance = -1;
bool isEqualChanced = true;
float totalChance = 0;
for (CreatureTextGroup::const_iterator iter = tempGroup.begin(); iter != tempGroup.end(); ++iter)
{
if (lastChance >= 0 && lastChance != iter->probability)
isEqualChanced = false;
lastChance = iter->probability;
totalChance += iter->probability;
++count;
}
int32 offset = -1;
if (!isEqualChanced)
{
for (CreatureTextGroup::const_iterator iter = tempGroup.begin(); iter != tempGroup.end(); ++iter)
{
uint32 chance = uint32(iter->probability);
uint32 r = urand(0, 100);
++offset;
if (r <= chance)
break;
}
}
uint32 pos = 0;
if (isEqualChanced || offset < 0)
pos = urand(0, count - 1);
else if (offset >= 0)
pos = offset;
CreatureTextGroup::const_iterator iter = tempGroup.begin() + pos;
ChatMsg finalType = (msgType == CHAT_MSG_ADDON) ? iter->type : msgType;
Language finalLang = (language == LANG_ADDON) ? iter->lang : language;
BroadcastText const* broadcastText = sObjectMgr->GetBroadcastText(iter->BroadcastTextId);
uint32 broadcastSound = 0;
if (broadcastText)
broadcastSound = broadcastText->SoundId;
uint32 finalSound = sound ? sound : broadcastSound;
if (range == TEXT_RANGE_NORMAL)
range = iter->TextRange;
if (finalSound)
SendSound(source, finalSound, finalType, whisperTarget, range, team, gmOnly);
Unit* finalSource = source;
if (srcPlr)
finalSource = srcPlr;
uint32 broadcastEmote = 0;
if (broadcastText)
broadcastEmote = broadcastText->EmoteId0;
if (broadcastEmote)
SendEmote(finalSource, broadcastEmote);
//.........这里部分代码省略.........
示例2: Creature
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*/)
{
if(!source)
return 0;
CreatureTextMap::const_iterator sList = mTextMap.find(source->GetEntry());
if(sList == mTextMap.end())
{
sLog->outErrorDb("CreatureTextMgr: Could not find Text for Creature(%s) Entry %u in 'creature_text' table. Ignoring.", source->GetName(), source->GetEntry());
return 0;
}
CreatureTextHolder TextHolder = (*sList).second;
CreatureTextHolder::const_iterator itr = TextHolder.find(textGroup);
if(itr == TextHolder.end())
{
sLog->outErrorDb("CreatureTextMgr: Could not find TextGroup %u for Creature(%s) GuidLow %u Entry %u. Ignoring.", uint32(textGroup), source->GetName(), source->GetGUIDLow(), source->GetEntry());
return 0;
}
CreatureTextGroup TextGroup = (*itr).second;//has all texts in the group
CreatureTextRepeatIds repeatGroup = GetRepeatGroup(source, textGroup);//has all textIDs from the group that were already said
CreatureTextGroup tempGroup;//will use this to talk after sorting repeatGroup
for(CreatureTextGroup::const_iterator giter = TextGroup.begin(); giter != TextGroup.end(); ++giter)
{
if(std::find(repeatGroup.begin(), repeatGroup.end(), (*giter).id) == repeatGroup.end())
tempGroup.push_back((*giter));
}
if(tempGroup.empty())
{
CreatureTextRepeatMap::iterator mapItr = mTextRepeatMap.find(source->GetGUID());
if(mapItr != mTextRepeatMap.end())
{
CreatureTextRepeatGroup::iterator groupItr = (*mapItr).second.find(textGroup);
(*groupItr).second.clear();
}
tempGroup = TextGroup;
}
uint8 count = 0;
float lastChance = -1;
bool isEqualChanced = true;
float totalChance = 0;
for(CreatureTextGroup::const_iterator iter = tempGroup.begin(); iter != tempGroup.end(); ++iter)
{
if(lastChance >= 0 && lastChance != (*iter).probability)
isEqualChanced = false;
lastChance = (*iter).probability;
totalChance += (*iter).probability;
count++;
}
int32 offset = -1;
if(!isEqualChanced)
{
for(CreatureTextGroup::const_iterator iter = tempGroup.begin(); iter != tempGroup.end(); ++iter)
{
uint32 chance = uint32((*iter).probability);
uint32 r = urand(0, 100);
offset++;
if(r <= chance)
break;
}
}
uint32 pos = 0;
if(isEqualChanced || offset < 0)
pos = urand(0, count - 1);
else if(offset >= 0)
pos = offset;
CreatureTextGroup::const_iterator iter = tempGroup.begin() + pos;
ChatMsg finalType = (msgType == CHAT_MSG_ADDON) ? (*iter).type : msgType;
Language finalLang = (language == LANG_ADDON) ? (*iter).lang : language;
uint32 finalSound = sound ? sound : (*iter).sound;
if(finalSound)
SendSound(source, finalSound, finalType, whisperGuid, range, team, gmOnly);
if((*iter).emote)
SendEmote(srcPlr ? srcPlr->ToUnit() : source, (*iter).emote);
SendChatString(srcPlr ? srcPlr->ToUnit() : 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;
}
示例3: TC_LOG_ERROR
uint32 CreatureTextMgr::SendChat(Creature* source, uint8 textGroup, WorldObject const* whisperTarget /*= nullptr*/, ChatMsg msgType /*= CHAT_MSG_ADDON*/, Language language /*= LANG_ADDON*/, CreatureTextRange range /*= TEXT_RANGE_NORMAL*/, uint32 sound /*= 0*/, Team team /*= TEAM_OTHER*/, bool gmOnly /*= false*/, Player* srcPlr /*= nullptr*/)
{
if (!source)
return 0;
CreatureTextMap::const_iterator sList = mTextMap.find(source->GetEntry());
if (sList == mTextMap.end())
{
TC_LOG_ERROR("sql.sql", "CreatureTextMgr: Could not find Text for Creature %s (%s) in 'creature_text' table. Ignoring.", source->GetName().c_str(), source->GetGUID().ToString().c_str());
return 0;
}
CreatureTextHolder const& textHolder = sList->second;
CreatureTextHolder::const_iterator itr = textHolder.find(textGroup);
if (itr == textHolder.end())
{
TC_LOG_ERROR("sql.sql", "CreatureTextMgr: Could not find TextGroup %u for Creature %s (%s) in 'creature_text' table. Ignoring.", uint32(textGroup), source->GetName().c_str(), source->GetGUID().ToString().c_str());
return 0;
}
CreatureTextGroup const& textGroupContainer = itr->second; //has all texts in the group
CreatureTextRepeatIds repeatGroup = GetRepeatGroup(source, textGroup);//has all textIDs from the group that were already said
CreatureTextGroup tempGroup;//will use this to talk after sorting repeatGroup
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);
if (tempGroup.empty())
{
source->ClearTextRepeatGroup(textGroup);
tempGroup = textGroupContainer;
}
auto iter = Trinity::Containers::SelectRandomWeightedContainerElement(tempGroup, [](CreatureTextEntry const& t) -> double
{
return t.probability;
});
ChatMsg finalType = (msgType == CHAT_MSG_ADDON) ? iter->type : msgType;
Language finalLang = (language == LANG_ADDON) ? iter->lang : language;
uint32 finalSound = sound ? sound : iter->sound;
if (range == TEXT_RANGE_NORMAL)
range = iter->TextRange;
if (finalSound)
SendSound(source, finalSound, finalType, whisperTarget, range, team, gmOnly);
Unit* finalSource = source;
if (srcPlr)
finalSource = srcPlr;
if (iter->emote)
SendEmote(finalSource, iter->emote);
if (srcPlr)
{
PlayerTextBuilder builder(source, finalSource, finalSource->getGender(), finalType, iter->group, iter->id, finalLang, whisperTarget);
SendChatPacket(finalSource, builder, finalType, whisperTarget, range, team, gmOnly);
}
else
{
CreatureTextBuilder builder(finalSource, finalSource->getGender(), finalType, iter->group, iter->id, finalLang, whisperTarget);
SendChatPacket(finalSource, builder, finalType, whisperTarget, range, team, gmOnly);
}
SetRepeatId(source, textGroup, iter->id);
return iter->duration;
}