This commit is contained in:
aozhiwei 2022-12-31 16:06:08 +08:00
parent 14143166b4
commit db1bb9b4a8

View File

@ -105,107 +105,11 @@ bool VirtualBullet::IsDone()
void VirtualBullet::Check(float distance)
{
int c_hit_num = 0;
int t_hit_num = 0;
int o_hit_num = 0;
std::set<Entity*> objects;
{
std::set<ColliderComponent*> colliders;
room->map_service->GetColliders(room, GetPos().x, GetPos().y, colliders);
for (ColliderComponent* collider : colliders) {
if (collider->owner->IsEntityType(ET_Dummy)) {
if (a8::HasBitFlag(collider->tag, kHalfWallTag)) {
continue;
}
if (TestCollision(room, collider)) {
++o_hit_num;
objects.insert(collider->owner);
}
} else if (collider->owner->IsEntityType(ET_Obstacle)) {
Obstacle* obstacle = (Obstacle*)collider->owner;
if (gun_meta->is_penetrate_thing() &&
hit_objects_.find(obstacle->GetUniId()) != hit_objects_.end()) {
//穿物件
continue;
}
if (!obstacle->CanThroughable(this)) {
if (TestCollision(room, collider)) {
objects.insert(collider->owner);
if (gun_meta->is_penetrate_thing()) {
++t_hit_num;
++o_hit_num;
hit_objects_.insert(collider->owner->GetUniId());
}
}
} else if (obstacle->meta->thing_type() == kObstacleStrengthenWall) {
if (!strengthened_ && sender.Get() &&
sender.Get()->team_id == obstacle->GetTeamId(room)) {
bool ret = Check2dRotationRectangle
(GetPos().x,
GetPos().y,
gun_meta->bullet_rad(),
obstacle->GetPos().x,
obstacle->GetPos().y,
obstacle->meta->width(),
obstacle->meta->height(),
obstacle->GetRotate() * 180.0f
);
if (ret) {
strengthened_ = true;
OnStrengthen(obstacle);
#ifdef DEBUG
a8::XPrintf("命中能量墙\n", {});
#endif
}
}
}
}
}
}
bool eat = false;
if (o_hit_num <= 0) {
room->grid_service->TraverseCreatures
(room->GetRoomIdx(),
GetGridList(),
[this, &objects, &c_hit_num, &eat] (Creature* c, bool& stop)
{
if (sender.Get()->IsProperTarget(c)) {
if (gun_meta->ispenetrate() &&
hit_objects_.find(c->GetUniId()) != hit_objects_.end()) {
//穿人
return;
}
if (c->HasBuffEffect(kBET_BulletThrough)) {
return;
}
if (c->HasBuffEffect(kBET_HoldShield)) {
c->CheckBulletHitHoldShield(this, result.eat);
if (result.eat) {
stop = true;
return;
}
}
AabbCollider aabb_box;
c->GetHitAabbBox(aabb_box);
if (c != sender.Get() && !c->dead && TestCollision(room, &aabb_box)) {
if (bullet_meta->_inventory_slot() == IS_C4) {
if (!c->IsHuman()) {
objects.insert(c);
if (gun_meta->ispenetrate()) {
++c_hit_num;
hit_objects_.insert(c->GetUniId());
}
}
} else {
objects.insert(c);
if (gun_meta->ispenetrate()) {
++c_hit_num;
hit_objects_.insert(c->GetUniId());
}
}
}
}
});
BulletCheckResult result;
result.flyed_distance = distance;
GetHitThings(result);
if (result.o_hit_num <= 0) {
GetHitCreatures(result);
}
#if 0
float bullet_range = gun_meta->range();
@ -368,5 +272,47 @@ void VirtualBullet::GetHitThings(BulletCheckResult& result)
void VirtualBullet::GetHitCreatures(BulletCheckResult& result)
{
room->grid_service->TraverseCreatures
(room->GetRoomIdx(),
GetGridList(),
[this, &result] (Creature* c, bool& stop)
{
bool no_teammate = false;
if (sender.Get()->IsProperTarget(c, no_teammate)) {
if (gun_meta->ispenetrate() &&
hit_objects_.find(c->GetUniId()) != hit_objects_.end()) {
//穿人
return;
}
if (c->HasBuffEffect(kBET_BulletThrough)) {
return;
}
if (c->HasBuffEffect(kBET_HoldShield)) {
c->CheckBulletHitHoldShield(this, result.eat);
if (result.eat) {
stop = true;
return;
}
}
AabbCollider aabb_box;
c->GetHitAabbBox(aabb_box);
if (c != sender.Get() && !c->dead && TestCollision(room, &aabb_box)) {
if (bullet_meta->_inventory_slot() == IS_C4) {
if (!c->IsHuman()) {
result.objects.insert(c);
if (gun_meta->ispenetrate()) {
++result.c_hit_num;
hit_objects_.insert(c->GetUniId());
}
}
} else {
result.objects.insert(c);
if (gun_meta->ispenetrate()) {
++result.c_hit_num;
hit_objects_.insert(c->GetUniId());
}
}
}
}
});
}