This commit is contained in:
aozhiwei 2021-10-25 19:38:35 +08:00
parent 9d68d679f8
commit 28e428c227
6 changed files with 82 additions and 26 deletions

View File

@ -255,8 +255,8 @@ void Hero::DecHP(float dec_hp, int killer_id, const std::string& killer_name, in
void Hero::BeKill(int killer_id, const std::string& killer_name, int weapon_id) void Hero::BeKill(int killer_id, const std::string& killer_name, int weapon_id)
{ {
dead = true; dead = true;
if (meta->i->dead_drop() != 0) { if (meta->HasDrop()) {
room->ScatterDrop(GetPos(), meta->i->dead_drop()); room->ScatterDrop(GetPos(), meta->RandDrop());
} }
room->frame_event.AddDead(GetWeakPtrRef(), 0); room->frame_event.AddDead(GetWeakPtrRef(), 0);
room->xtimer.AddDeadLineTimerAndAttach room->xtimer.AddDeadLineTimerAndAttach

View File

@ -578,6 +578,25 @@ namespace MetaData
void Player::Init() void Player::Init()
{ {
{
int total_weight = 0;
std::vector<std::string> strings;
a8::Split(i->dead_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;
dead_drop.push_back
(std::make_tuple(
drop_id,
total_weight
)
);
}
}
{ {
std::vector<std::string> strings; std::vector<std::string> strings;
a8::Split(i->volume(), strings, '|'); a8::Split(i->volume(), strings, '|');
@ -603,6 +622,20 @@ namespace MetaData
} }
} }
int Player::RandDrop()
{
if (HasDrop()) {
int total_weight = std::get<1>(dead_drop[dead_drop.size() - 1]);
int rnd = rand() % total_weight;
for (auto& tuple : dead_drop) {
if (rnd < std::get<1>(tuple)) {
return std::get<0>(tuple);
}
}
}
return 0;
}
void PlayerSkin::Init() void PlayerSkin::Init()
{ {

View File

@ -131,8 +131,11 @@ namespace MetaData
std::array<int, IS_END> volume = {}; std::array<int, IS_END> volume = {};
std::vector<int> init_buffs; std::vector<int> init_buffs;
std::vector<std::tuple<int, int>> dead_drop;
bool HasDrop() { return !dead_drop.empty();};
void Init(); void Init();
int RandDrop();
}; };
struct PlayerSkin struct PlayerSkin

View File

@ -199,8 +199,12 @@ void RoomObstacle::SpecExplosion()
room->grid_service->GetAllCellsByXy(room, GetPos().x, GetPos().y, *grid_list_); room->grid_service->GetAllCellsByXy(room, GetPos().x, GetPos().y, *grid_list_);
} }
a8::Vec2 bomb_born_offset = a8::Vec2::UP; a8::Vec2 bomb_born_offset = a8::Vec2::UP;
bomb_born_offset.Rotate(a8::RandAngle()); if (pos_list && explosion_times_ <= pos_list->size()) {
bomb_born_offset = bomb_born_offset * a8::RandEx(1, std::max(2, meta->i->explosion_float())); bomb_born_offset = pos_list->at(explosion_times_ - 1);
} else {
bomb_born_offset.Rotate(a8::RandAngle());
bomb_born_offset = bomb_born_offset * a8::RandEx(1, std::max(2, meta->i->explosion_float()));
}
a8::Vec2 bomb_pos = GetPos() + bomb_born_offset; a8::Vec2 bomb_pos = GetPos() + bomb_born_offset;
if (room->grid_service->CanAdd(bomb_pos.x, bomb_pos.y)) { if (room->grid_service->CanAdd(bomb_pos.x, bomb_pos.y)) {
std::shared_ptr<Explosion> explosion = EntityFactory::Instance()->MakeExplosion(); std::shared_ptr<Explosion> explosion = EntityFactory::Instance()->MakeExplosion();
@ -241,12 +245,7 @@ void RoomObstacle::SpecExplosion()
} }
} }
} }
int total_explosion_times = meta->i->explosion_times(); if (explosion_times_ >= total_explosion_times_) {
if (context_ability && context_ability->GetAttrAbs(kHAT_WeaponExplosionContinueTime) > 0.001f) {
total_explosion_times += context_ability->GetAttrAbs(kHAT_WeaponExplosionContinueTime) * 1000 /
meta->i->explosion_interval();
}
if (explosion_times_ >= total_explosion_times) {
if (room->xtimer.GetRunningTimer()) { if (room->xtimer.GetRunningTimer()) {
room->xtimer.DeleteTimer(room->xtimer.GetRunningTimer()); room->xtimer.DeleteTimer(room->xtimer.GetRunningTimer());
} }
@ -330,6 +329,11 @@ void RoomObstacle::Active()
void RoomObstacle::ActiveSelfExplosion() void RoomObstacle::ActiveSelfExplosion()
{ {
total_explosion_times_ = meta->i->explosion_times();
if (context_ability && context_ability->GetAttrAbs(kHAT_WeaponExplosionContinueTime) > 0.001f) {
total_explosion_times_ += context_ability->GetAttrAbs(kHAT_WeaponExplosionContinueTime) * 1000 /
meta->i->explosion_interval();
}
room->xtimer.AddDeadLineTimerAndAttach room->xtimer.AddDeadLineTimerAndAttach
( (
meta->i->time() / FRAME_RATE_MS, meta->i->time() / FRAME_RATE_MS,
@ -684,21 +688,35 @@ void RoomObstacle::InstallPreExplostionSummonTimer()
{ {
if (!meta->preexplosion_summon.empty()) { if (!meta->preexplosion_summon.empty()) {
int base_time = 0; int base_time = 0;
for (auto& tuple : meta->preexplosion_summon) { pos_list = std::make_shared<std::vector<a8::Vec2>>();
int time = std::get<0>(tuple); for (int i = 0; i < total_explosion_times_; ++i) {
int obstacle_id = std::get<1>(tuple); for (auto& tuple : meta->preexplosion_summon) {
room->xtimer.AddDeadLineTimerAndAttach int time = std::get<0>(tuple);
( int obstacle_id = std::get<1>(tuple);
(base_time + time) / FRAME_RATE_MS, room->xtimer.AddDeadLineTimerAndAttach
a8::XParams() (
.SetSender(this) (base_time + time) / FRAME_RATE_MS,
.SetParam1(obstacle_id), a8::XParams()
[] (const a8::XParams& param) .SetSender(this)
{ .SetParam1(obstacle_id),
RoomObstacle* obstacle = (RoomObstacle*)param.sender.GetUserData(); [] (const a8::XParams& param)
}, {
&xtimer_attacher.timer_list_ RoomObstacle* obstacle = (RoomObstacle*)param.sender.GetUserData();
); },
&xtimer_attacher.timer_list_
);
}//end for tuple
{
a8::Vec2 bomb_born_offset = a8::Vec2::UP;
bomb_born_offset.Rotate(a8::RandAngle());
bomb_born_offset = bomb_born_offset * a8::RandEx(1, std::max(2, meta->i->explosion_float()));
a8::Vec2 bomb_pos = GetPos() + bomb_born_offset;
if (room->grid_service->CanAdd(bomb_pos.x, bomb_pos.y)) {
pos_list->push_back(bomb_born_offset);
} else {
pos_list->push_back(a8::Vec2());
}
}
} }
base_time += meta->i->explosion_interval(); base_time += meta->i->explosion_interval();
} }

View File

@ -66,6 +66,8 @@ protected:
int explosion_times_ = 0; int explosion_times_ = 0;
bool detached_ = false; bool detached_ = false;
std::map<int, CreatureWeakPtr>* hit_objects_ = nullptr; std::map<int, CreatureWeakPtr>* hit_objects_ = nullptr;
std::shared_ptr<std::vector<a8::Vec2>> pos_list;
int total_explosion_times_ = 0;
RoomObstacle(); RoomObstacle();

View File

@ -222,7 +222,7 @@ message Player
optional string ai_script = 26; optional string ai_script = 26;
optional string init_buffs = 27; optional string init_buffs = 27;
optional int32 default_weapon = 28; optional int32 default_weapon = 28;
optional int32 dead_drop = 29; optional string dead_drop = 29;
optional int32 delay_delete = 39; optional int32 delay_delete = 39;
optional int32 ai = 46; optional int32 ai = 46;
optional int32 delay_remove = 47; optional int32 delay_remove = 47;