修复空投问题

This commit is contained in:
aozhiwei 2021-10-26 11:08:38 +08:00
parent b9e29a3dc9
commit 285b0cea65
4 changed files with 2 additions and 38 deletions

View File

@ -866,39 +866,6 @@ namespace MetaData
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()

View File

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

View File

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

View File

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