mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-01-29 00:23:48 +00:00
fix(Scripts/TheBotanica): Rework Laj (#15279)
This commit is contained in:
@@ -139,6 +139,21 @@ namespace Acore::Containers
|
||||
return *it;
|
||||
}
|
||||
|
||||
/*
|
||||
* Select a random element from a container.
|
||||
*
|
||||
* Note: container cannot be empty
|
||||
*/
|
||||
template<class C, class Predicate>
|
||||
inline auto SelectRandomContainerElementIf(C const& container, Predicate&& predicate) -> typename std::add_const<decltype(*std::begin(container))>::type&
|
||||
{
|
||||
C containerCopy;
|
||||
std::copy_if(std::begin(container), std::end(container), std::inserter(containerCopy, std::end(containerCopy)), predicate);
|
||||
auto it = std::begin(containerCopy);
|
||||
std::advance(it, urand(0, uint32(std::size(containerCopy)) - 1));
|
||||
return *it;
|
||||
}
|
||||
|
||||
/*
|
||||
* Select a random element from a container where each element has a different chance to be selected.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user