This commit is contained in:
aozhiwei 2022-10-18 13:28:10 +08:00
parent a9d476c33d
commit bef1496890
2 changed files with 32 additions and 6 deletions

View File

@ -86,13 +86,29 @@ void Explosion::ProcDamage()
}
if (type_ == kExplosionEnemyAndObstacle) {
if (sender_.Get() && sender_.Get()->IsProperTarget(c)) {
if (center_.Distance(c->GetPos()) < explosion_range_) {
objects.insert(c);
if (custom_check_cb_) {
bool is_hit = false;
custom_check_cb_({&is_hit, (Entity*)c});
if (is_hit) {
objects.insert(c);
}
} else {
if (center_.Distance(c->GetPos()) < explosion_range_) {
objects.insert(c);
}
}
}
} else {
if (center_.Distance(c->GetPos()) < explosion_range_) {
objects.insert(c);
if (custom_check_cb_) {
bool is_hit = false;
custom_check_cb_({&is_hit, (Entity*)c});
if (is_hit) {
objects.insert(c);
}
} else {
if (center_.Distance(c->GetPos()) < explosion_range_) {
objects.insert(c);
}
}
}
}
@ -112,8 +128,16 @@ void Explosion::ProcDamage()
if (!entity->ReceiveExplosionDmg(this)) {
return;
}
if (center_.Distance(entity->GetPos()) < explosion_range_) {
objects.insert(entity);
if (custom_check_cb_) {
bool is_hit = false;
custom_check_cb_({&is_hit, entity});
if (is_hit) {
objects.insert(entity);
}
} else {
if (center_.Distance(entity->GetPos()) < explosion_range_) {
objects.insert(entity);
}
}
}
);

View File

@ -18,6 +18,7 @@ class Explosion : public std::enable_shared_from_this<Explosion>
int GetExplosionEffect() { return explosion_effect_; };
void SetDamageDelay(int delay) { explosion_damage_delay_ = delay; };
void SetHitCb(CommonCbProc cb) { hit_cb_ = cb; };
void SetCustomCheckCb(CommonCbProc cb) { custom_check_cb_ = cb; };
void SetThrough(bool through) { through_ = through; };
bool IsThrough() { return through_; };
@ -52,6 +53,7 @@ protected:
a8::Vec2 center_;
long long special_damage_type_ = 0;
long long create_frameno_ = 0;
CommonCbProc custom_check_cb_;
CommonCbProc hit_cb_;
bool through_ = false;