This commit is contained in:
aozhiwei 2021-10-25 20:16:14 +08:00
commit 557395c20d
4 changed files with 44 additions and 2 deletions

View File

@ -864,6 +864,43 @@ namespace MetaData
return 0; return 0;
} }
void AirDrop::Init()
{
{
int total_weight = 0;
std::vector<std::string> strings;
a8::Split(i->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()
{
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;
}
void AirRaid::Init() void AirRaid::Init()
{ {
{ {

View File

@ -200,6 +200,11 @@ namespace MetaData
struct AirDrop struct AirDrop
{ {
const metatable::AirDrop* i = nullptr; const metatable::AirDrop* i = nullptr;
std::vector<std::tuple<int, int>> drop;
bool HasDrop() { return !drop.empty();};
void Init();
int RandDrop();
}; };
struct AirRaid struct AirRaid

View File

@ -1637,7 +1637,7 @@ void Room::InitAirDrop()
a8::XParams() a8::XParams()
.SetSender(this) .SetSender(this)
.SetParam1(air_drop.i->appear_time()) .SetParam1(air_drop.i->appear_time())
.SetParam2(air_drop.i->drop_id()) .SetParam2(air_drop.RandDrop())
.SetParam3(air_drop.i->id()), .SetParam3(air_drop.i->id()),
[] (const a8::XParams& param) [] (const a8::XParams& param)
{ {

View File

@ -326,7 +326,7 @@ message AirDrop
optional int32 id = 1; optional int32 id = 1;
optional int32 time = 2; optional int32 time = 2;
optional int32 appear_time = 3; optional int32 appear_time = 3;
optional int32 drop_id = 4; optional string drop_id = 4;
} }
message AirRaid message AirRaid