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,16 +86,32 @@ void Explosion::ProcDamage()
} }
if (type_ == kExplosionEnemyAndObstacle) { if (type_ == kExplosionEnemyAndObstacle) {
if (sender_.Get() && sender_.Get()->IsProperTarget(c)) { if (sender_.Get() && sender_.Get()->IsProperTarget(c)) {
if (center_.Distance(c->GetPos()) < explosion_range_) { if (custom_check_cb_) {
bool is_hit = false;
custom_check_cb_({&is_hit, (Entity*)c});
if (is_hit) {
objects.insert(c); objects.insert(c);
} }
}
} else { } else {
if (center_.Distance(c->GetPos()) < explosion_range_) { if (center_.Distance(c->GetPos()) < explosion_range_) {
objects.insert(c); objects.insert(c);
} }
} }
} }
} else {
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);
}
}
}
}
); );
room_->grid_service->TraverseAllLayerEntityList room_->grid_service->TraverseAllLayerEntityList
( (
@ -112,10 +128,18 @@ void Explosion::ProcDamage()
if (!entity->ReceiveExplosionDmg(this)) { if (!entity->ReceiveExplosionDmg(this)) {
return; return;
} }
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_) { if (center_.Distance(entity->GetPos()) < explosion_range_) {
objects.insert(entity); objects.insert(entity);
} }
} }
}
); );
if (force_target_.Get() && objects.find(force_target_.Get()) == objects.end()) { if (force_target_.Get() && objects.find(force_target_.Get()) == objects.end()) {
objects.insert(force_target_.Get()); objects.insert(force_target_.Get());

View File

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