重构空投代码
This commit is contained in:
parent
d7e1777e1e
commit
7d20375571
@ -2027,57 +2027,14 @@ void Creature::FindLocationWithTarget(Entity* target, ColliderComponent* target_
|
||||
|
||||
void Creature::FindLocation()
|
||||
{
|
||||
Entity* target = nullptr;
|
||||
ColliderComponent* target_collider = nullptr;
|
||||
TraverseAllLayerEntityList
|
||||
(
|
||||
[this, &target, &target_collider] (Entity* entity, bool& stop)
|
||||
{
|
||||
ColliderComponent* collider = nullptr;
|
||||
switch (entity->GetEntityType()) {
|
||||
case ET_Obstacle:
|
||||
{
|
||||
if (!target) {
|
||||
collider = TestCollisionAndGetCollider(room, entity);
|
||||
if (collider) {
|
||||
target = entity;
|
||||
target_collider = collider;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ET_Building:
|
||||
{
|
||||
if (!target || !target->IsEntityType(ET_Building)) {
|
||||
AabbCollider aabb_box;
|
||||
entity->GetAabbBox(aabb_box);
|
||||
collider = TestCollisionAndGetCollider(room, &aabb_box);
|
||||
if (collider) {
|
||||
target = entity;
|
||||
target_collider = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ET_Dummy:
|
||||
{
|
||||
if (!target) {
|
||||
collider = TestCollisionAndGetCollider(room, entity);
|
||||
if (collider) {
|
||||
target = entity;
|
||||
target_collider = collider;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{
|
||||
}
|
||||
break;
|
||||
}
|
||||
});
|
||||
if (target) {
|
||||
FindLocationWithTarget(target, target_collider);
|
||||
if (CollisonDetectionAndGetCollider(&target_collider)) {
|
||||
if (!target_collider) {
|
||||
abort();
|
||||
}
|
||||
}
|
||||
if (target_collider) {
|
||||
FindLocationWithTarget(target_collider->owner, target_collider);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1011,56 +1011,15 @@ void Room::OnPlayerOffline(Player* hum)
|
||||
}
|
||||
}
|
||||
|
||||
Entity* Room::FindFirstCollisonEntity(const a8::Vec2& aabb_pos, AabbCollider& aabb_box)
|
||||
{
|
||||
Entity* target = nullptr;
|
||||
std::set<GridCell*> tmp_grids;
|
||||
grid_service->GetAllCellsByXy(this, aabb_pos.x, aabb_pos.y, tmp_grids);
|
||||
grid_service->TraverseAllLayerEntityList
|
||||
(
|
||||
room_idx_,
|
||||
tmp_grids,
|
||||
[this, &target, &aabb_pos, &aabb_box] (Entity* entity, bool& stop)
|
||||
{
|
||||
switch (entity->GetEntityType()) {
|
||||
case ET_Obstacle:
|
||||
{
|
||||
if (!target) {
|
||||
if (entity->TestCollisionEx(this, aabb_pos, aabb_box)) {
|
||||
target = entity;
|
||||
stop = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ET_Building:
|
||||
{
|
||||
if (!target || !target->IsEntityType(ET_Building)) {
|
||||
AabbCollider building_aabb_box;
|
||||
entity->GetAabbBox(building_aabb_box);
|
||||
if (building_aabb_box.IntersectEx(aabb_pos, &aabb_box)) {
|
||||
target = entity;
|
||||
stop = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
});
|
||||
return target;
|
||||
}
|
||||
|
||||
void Room::FindLocationWithAabb(Entity* target, const a8::Vec2& aabb_pos, AabbCollider* aabb_box,
|
||||
void Room::FindLocationWithAabb(ColliderComponent* target_collider,
|
||||
const a8::Vec2& aabb_pos,
|
||||
AabbCollider* aabb_box,
|
||||
float& new_x, float& new_y)
|
||||
{
|
||||
a8::Vec2 old_pos = aabb_pos;
|
||||
a8::Vec2 new_pos = aabb_pos;
|
||||
AabbCollider target_collider;
|
||||
target->GetAabbBox(target_collider);
|
||||
{
|
||||
bool ret = aabb_box->CalcSafePointEx(aabb_pos, &target_collider, new_pos);
|
||||
bool ret = aabb_box->CalcSafePointEx(aabb_pos, target_collider, new_pos);
|
||||
if (!ret) {
|
||||
abort();
|
||||
}
|
||||
@ -1733,11 +1692,27 @@ void Room::AirDrop(int appear_time, int box_id, int airdrop_id)
|
||||
air_drop_aabb_box._max.x = 0 + thing_meta->i->width()/2.0f;
|
||||
air_drop_aabb_box._max.y = 0 + thing_meta->i->height()/2.0f;
|
||||
}
|
||||
Entity* target = FindFirstCollisonEntity(box_pos, air_drop_aabb_box);
|
||||
if (target) {
|
||||
ColliderComponent* pickup_collider = nullptr;
|
||||
{
|
||||
bool through_wall = false;
|
||||
bool is_collision = map_service->CollisionDetectionAndGetCollider
|
||||
(
|
||||
this,
|
||||
through_wall,
|
||||
box_pos,
|
||||
&air_drop_aabb_box,
|
||||
&pickup_collider
|
||||
);
|
||||
if (is_collision) {
|
||||
if (!pickup_collider) {
|
||||
abort();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (pickup_collider) {
|
||||
float new_x = box_pos.x;
|
||||
float new_y = box_pos.y;
|
||||
FindLocationWithAabb(target, box_pos, &air_drop_aabb_box, new_x, new_y);
|
||||
FindLocationWithAabb(pickup_collider, box_pos, &air_drop_aabb_box, new_x, new_y);
|
||||
box_pos.x = new_x;
|
||||
box_pos.y = new_y;
|
||||
}
|
||||
|
@ -147,8 +147,9 @@ public:
|
||||
int self_channel,
|
||||
int init_map_id);
|
||||
void OnPlayerOffline(Player* hum);
|
||||
Entity* FindFirstCollisonEntity(const a8::Vec2& aabb_pos, AabbCollider& aabb_box);
|
||||
void FindLocationWithAabb(Entity* target, const a8::Vec2& aabb_pos, AabbCollider* aabb_box,
|
||||
void FindLocationWithAabb(ColliderComponent* target_collider,
|
||||
const a8::Vec2& aabb_pos,
|
||||
AabbCollider* aabb_box,
|
||||
float& new_x, float& new_y);
|
||||
void FillSMUiUpdate(cs::SMUiUpdate& msg);
|
||||
void NotifyUiUpdate();
|
||||
|
Loading…
x
Reference in New Issue
Block a user