mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-15 23:20:36 +01:00
Core/Creatures: Improved creature text selection to be "more random" instead of favoring first entry
This commit is contained in:
@@ -195,7 +195,6 @@ void CreatureTextMgr::LoadCreatureTextLocales()
|
||||
} while (result->NextRow());
|
||||
|
||||
TC_LOG_INFO("server.loading", ">> Loaded %u creature localized texts in %u ms", textCount, GetMSTimeDiffToNow(oldMSTime));
|
||||
|
||||
}
|
||||
|
||||
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*/)
|
||||
@@ -232,42 +231,10 @@ uint32 CreatureTextMgr::SendChat(Creature* source, uint8 textGroup, WorldObject
|
||||
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)
|
||||
auto iter = Trinity::Containers::SelectRandomWeightedContainerElement(tempGroup, [](CreatureTextEntry const& t) -> double
|
||||
{
|
||||
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;
|
||||
return t.probability;
|
||||
});
|
||||
|
||||
ChatMsg finalType = (msgType == CHAT_MSG_ADDON) ? iter->type : msgType;
|
||||
Language finalLang = (language == LANG_ADDON) ? iter->lang : language;
|
||||
@@ -297,9 +264,7 @@ uint32 CreatureTextMgr::SendChat(Creature* source, uint8 textGroup, WorldObject
|
||||
SendChatPacket(finalSource, builder, finalType, whisperTarget, range, team, gmOnly);
|
||||
}
|
||||
|
||||
if (isEqualChanced || (!isEqualChanced && totalChance == 100.0f))
|
||||
SetRepeatId(source, textGroup, iter->id);
|
||||
|
||||
SetRepeatId(source, textGroup, iter->id);
|
||||
return iter->duration;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user