This commit is contained in:
aozhiwei 2021-10-25 17:42:32 +08:00
parent 55fca6a011
commit 060f878346
9 changed files with 84 additions and 12 deletions

View File

@ -487,8 +487,8 @@ float Car::GetMaxOil()
void Car::DropItems(Obstacle* obstacle) void Car::DropItems(Obstacle* obstacle)
{ {
if (obstacle->meta->i->drop() != 0) { if (obstacle->meta->HasDrop()) {
room->ScatterDrop(obstacle->GetPos(), obstacle->meta->i->drop()); room->ScatterDrop(obstacle->GetPos(), obstacle->meta->RandDrop());
} }
} }

View File

@ -389,7 +389,7 @@ void Hero::DropItems(Obstacle* obstacle)
if (obstacle->IsEntitySubType(EST_RoomObstacle)) { if (obstacle->IsEntitySubType(EST_RoomObstacle)) {
is_treasure_box = ((RoomObstacle*)obstacle)->is_treasure_box; is_treasure_box = ((RoomObstacle*)obstacle)->is_treasure_box;
} }
int drop_id = obstacle->meta->i->drop(); int drop_id = obstacle->meta->RandDrop();
if (drop_id == 0) { if (drop_id == 0) {
return; return;
} }

View File

@ -2271,7 +2271,7 @@ void Human::DropItems(Obstacle* obstacle)
if (obstacle->IsEntitySubType(EST_RoomObstacle)) { if (obstacle->IsEntitySubType(EST_RoomObstacle)) {
is_treasure_box = ((RoomObstacle*)obstacle)->is_treasure_box; is_treasure_box = ((RoomObstacle*)obstacle)->is_treasure_box;
} }
int drop_id = obstacle->meta->i->drop(); int drop_id = obstacle->meta->RandDrop();
if (drop_id == 0) { if (drop_id == 0) {
return; return;
} }
@ -2290,7 +2290,7 @@ void Human::DropItems(Obstacle* obstacle)
} }
if (drop_id == 0) { if (drop_id == 0) {
drop_id = obstacle->meta->i->drop(); drop_id = obstacle->meta->RandDrop();
} }
room->ScatterDrop(obstacle->GetPos(), drop_id); room->ScatterDrop(obstacle->GetPos(), drop_id);
if (is_treasure_box) { if (is_treasure_box) {

View File

@ -207,9 +207,36 @@ namespace MetaData
{ {
{ {
std::vector<std::string> strings; std::vector<std::string> strings;
a8::Split(i->buff_list(), strings, '|'); a8::Split(i->preexplosion_summon(), strings, '|');
for (const std::string& tmp_str : strings) { for (const std::string& str : strings) {
buff_list.push_back(a8::XValue(tmp_str)); std::vector<std::string> strings2;
a8::Split(str, strings2, ':');
assert(strings2.size() == 2);
preexplosion_summon.push_back
(std::make_tuple(
a8::XValue(strings2[0]),
a8::XValue(strings2[1])
)
);
}
}
{
int total_weight = 0;
std::vector<std::string> strings;
a8::Split(i->drop(), 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
)
);
} }
} }
{ {
@ -269,6 +296,20 @@ namespace MetaData
} }
} }
int MapThing::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 Equip::Init() void Equip::Init()
{ {
{ {

View File

@ -59,8 +59,12 @@ namespace MetaData
float float_param2 = 0; float float_param2 = 0;
long long sweep_tags = 0; long long sweep_tags = 0;
std::vector<int> param2_list; std::vector<int> param2_list;
std::vector<std::tuple<int, int>> preexplosion_summon;
std::vector<std::tuple<int, int>> drop;
bool HasDrop() { return !drop.empty();};
void Init(); void Init();
int RandDrop();
}; };
struct SafeArea struct SafeArea

View File

@ -577,8 +577,8 @@ void Obstacle::OnExplosionHit(Explosion* e)
} }
if (IsDead(e->GetRoom())) { if (IsDead(e->GetRoom())) {
ProcDieExplosion(e->GetRoom()); ProcDieExplosion(e->GetRoom());
if (meta->i->drop() != 0) { if (meta->HasDrop()) {
e->GetRoom()->ScatterDrop(GetPos(), meta->i->drop()); e->GetRoom()->ScatterDrop(GetPos(), meta->RandDrop());
} }
if (meta->i->thing_type() == kObstacleOilBucket) { if (meta->i->thing_type() == kObstacleOilBucket) {
MetaData::MapThing* bomb_meta = MetaMgr::Instance()->GetMapThing(meta->int_param1); MetaData::MapThing* bomb_meta = MetaMgr::Instance()->GetMapThing(meta->int_param1);
@ -707,7 +707,7 @@ int Obstacle::OnCollisionTrigger(Creature* c, ColliderComponent* collider)
case kCollisionHitDeadAndDrop: case kCollisionHitDeadAndDrop:
{ {
if (c->room->GetGasData().gas_mode != GasInactive && if (c->room->GetGasData().gas_mode != GasInactive &&
meta->i->drop() != 0 && meta->HasDrop() &&
c->IsHuman()) { c->IsHuman()) {
Die(c->room); Die(c->room);
c->DropItems(this); c->DropItems(this);

View File

@ -338,6 +338,7 @@ void RoomObstacle::ActiveSelfExplosion()
[] (const a8::XParams& param) [] (const a8::XParams& param)
{ {
RoomObstacle* obstacle = (RoomObstacle*)param.sender.GetUserData(); RoomObstacle* obstacle = (RoomObstacle*)param.sender.GetUserData();
obstacle->InstallPreExplostionSummonTimer();
obstacle->room->xtimer.AddRepeatTimerAndAttach obstacle->room->xtimer.AddRepeatTimerAndAttach
( (
obstacle->meta->i->explosion_interval() / FRAME_RATE_MS, obstacle->meta->i->explosion_interval() / FRAME_RATE_MS,
@ -678,3 +679,27 @@ void RoomObstacle::PushCollisionObjects()
} }
}); });
} }
void RoomObstacle::InstallPreExplostionSummonTimer()
{
if (!meta->preexplosion_summon.empty()) {
int base_time = 0;
for (auto& tuple : meta->preexplosion_summon) {
int time = std::get<0>(tuple);
int obstacle_id = std::get<1>(tuple);
room->xtimer.AddDeadLineTimerAndAttach
(
(base_time + time) / FRAME_RATE_MS,
a8::XParams()
.SetSender(this)
.SetParam1(obstacle_id),
[] (const a8::XParams& param)
{
RoomObstacle* obstacle = (RoomObstacle*)param.sender.GetUserData();
},
&xtimer_attacher.timer_list_
);
}
base_time += meta->i->explosion_interval();
}
}

View File

@ -56,6 +56,7 @@ private:
void SummonAirDropBox(int box_id); void SummonAirDropBox(int box_id);
void ProcKeepRangeBuff(); void ProcKeepRangeBuff();
void DetachFromMaster(); void DetachFromMaster();
void InstallPreExplostionSummonTimer();
protected: protected:
RoomObstacleWeakPtr weak_ptr_; RoomObstacleWeakPtr weak_ptr_;

View File

@ -51,7 +51,7 @@ message MapThing
optional int32 hp = 5; // optional int32 hp = 5; //
optional float damage = 6; // optional float damage = 6; //
optional float damage_dia = 7; // optional float damage_dia = 7; //
optional int32 drop = 8; // optional string drop = 8; //
optional int32 is_door = 10; // optional int32 is_door = 10; //
optional int32 is_house = 11; // optional int32 is_house = 11; //
optional int32 is_tree = 12; // optional int32 is_tree = 12; //
@ -61,6 +61,7 @@ message MapThing
optional int32 explosion_interval = 18; optional int32 explosion_interval = 18;
optional int32 explosion_times = 19; optional int32 explosion_times = 19;
optional int32 explosion_float = 20; optional int32 explosion_float = 20;
optional string preexplosion_summon = 35;
optional string monster_list = 21; optional string monster_list = 21;
optional string special_damage_type = 22; optional string special_damage_type = 22;
optional string receive_special_damage_type = 23; optional string receive_special_damage_type = 23;