48 lines
1.2 KiB
C++
48 lines
1.2 KiB
C++
#include "precompile.h"
|
|
|
|
#include "mt/AirDrop.h"
|
|
|
|
IMPL_TABLE(mt::AirDrop)
|
|
|
|
namespace mt
|
|
{
|
|
|
|
void AirDrop::Init1()
|
|
{
|
|
{
|
|
int total_weight = 0;
|
|
std::vector<std::string> strings;
|
|
a8::Split(drop_id(), strings, '|');
|
|
for (const std::string& str : strings) {
|
|
std::vector<std::string> strings2;
|
|
a8::Split(str, strings2, ':');
|
|
assert(strings2.size() == 2);
|
|
int drop_id = a8::XValue(strings2[0]);
|
|
int weight = a8::XValue(strings2[1]);
|
|
total_weight += weight;
|
|
_drop.push_back
|
|
(std::make_tuple(
|
|
drop_id,
|
|
total_weight
|
|
)
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
int AirDrop::RandDrop() const
|
|
{
|
|
if (HasDrop()) {
|
|
int total_weight = std::get<1>(_drop[_drop.size() - 1]);
|
|
int rnd = rand() % total_weight;
|
|
for (auto& tuple : _drop) {
|
|
if (rnd < std::get<1>(tuple)) {
|
|
return std::get<0>(tuple);
|
|
}
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
}
|