This commit is contained in:
aozhiwei 2021-07-16 15:52:22 +08:00
parent 22ef2e0301
commit 39e7f5f6f6
2 changed files with 29 additions and 3 deletions

View File

@ -343,21 +343,30 @@ float Bullet::GetExplosionRange()
void Bullet::Check(float distance)
{
int c_hit_num = 0;
int t_hit_num = 0;
std::set<Entity*> objects;
room->grid_service->TraverseCreatures
(room->GetRoomIdx(),
GetGridList(),
[this, &objects] (Creature* c, bool& stop)
[this, &objects, &c_hit_num] (Creature* c, bool& stop)
{
if (sender.Get()->IsProperTarget(c)) {
if (gun_meta->i->ispenetrate() &&
hit_objects_.find(c->GetUniId()) != hit_objects_.end()) {
//穿人
return;
}
AabbCollider aabb_box;
c->GetHitAabbBox(aabb_box);
if (c != sender.Get() && !c->dead && TestCollision(room, &aabb_box)) {
if (meta->i->_inventory_slot() == IS_C4) {
if (!c->IsHuman()) {
++c_hit_num;
objects.insert(c);
}
} else {
++c_hit_num;
objects.insert(c);
}
}
@ -369,8 +378,14 @@ void Bullet::Check(float distance)
for (ColliderComponent* collider : colliders) {
if (collider->owner->IsEntityType(ET_Obstacle)) {
Obstacle* obstacle = (Obstacle*)collider->owner;
if (gun_meta->i->is_penetrate_thing() &&
hit_objects_.find(obstacle->GetUniId()) != hit_objects_.end()) {
//穿物件
continue;
}
if (!obstacle->CanThroughable(this)) {
if (TestCollision(room, collider)) {
++t_hit_num;
objects.insert(collider->owner);
}
}
@ -390,8 +405,18 @@ void Bullet::Check(float distance)
if (!objects.empty()) {
OnHit(objects);
}
room->RemoveObjectLater(this);
later_removed_ = true;
bool need_remove = true;
if (distance < bullet_range) {
if (!gun_meta->i->is_penetrate_thing() && t_hit_num > 0 ||
!gun_meta->i->ispenetrate() && c_hit_num > 0) {
} else {
need_remove = false;
}
}
if (need_remove) {
room->RemoveObjectLater(this);
later_removed_ = true;
}
}
}
}

View File

@ -66,6 +66,7 @@ private:
bool later_removed_ = false;
std::shared_ptr<Ability> ability_;
bool is_curr_weapon = false;
std::set<int> hit_objects_;
friend class EntityFactory;
};