重构空投代码
This commit is contained in:
parent
d7e1777e1e
commit
7d20375571
@ -2027,57 +2027,14 @@ void Creature::FindLocationWithTarget(Entity* target, ColliderComponent* target_
|
|||||||
|
|
||||||
void Creature::FindLocation()
|
void Creature::FindLocation()
|
||||||
{
|
{
|
||||||
Entity* target = nullptr;
|
|
||||||
ColliderComponent* target_collider = nullptr;
|
ColliderComponent* target_collider = nullptr;
|
||||||
TraverseAllLayerEntityList
|
if (CollisonDetectionAndGetCollider(&target_collider)) {
|
||||||
(
|
if (!target_collider) {
|
||||||
[this, &target, &target_collider] (Entity* entity, bool& stop)
|
abort();
|
||||||
{
|
}
|
||||||
ColliderComponent* collider = nullptr;
|
}
|
||||||
switch (entity->GetEntityType()) {
|
if (target_collider) {
|
||||||
case ET_Obstacle:
|
FindLocationWithTarget(target_collider->owner, target_collider);
|
||||||
{
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1011,56 +1011,15 @@ void Room::OnPlayerOffline(Player* hum)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Entity* Room::FindFirstCollisonEntity(const a8::Vec2& aabb_pos, AabbCollider& aabb_box)
|
void Room::FindLocationWithAabb(ColliderComponent* target_collider,
|
||||||
{
|
const a8::Vec2& aabb_pos,
|
||||||
Entity* target = nullptr;
|
AabbCollider* aabb_box,
|
||||||
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,
|
|
||||||
float& new_x, float& new_y)
|
float& new_x, float& new_y)
|
||||||
{
|
{
|
||||||
a8::Vec2 old_pos = aabb_pos;
|
a8::Vec2 old_pos = aabb_pos;
|
||||||
a8::Vec2 new_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) {
|
if (!ret) {
|
||||||
abort();
|
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.x = 0 + thing_meta->i->width()/2.0f;
|
||||||
air_drop_aabb_box._max.y = 0 + thing_meta->i->height()/2.0f;
|
air_drop_aabb_box._max.y = 0 + thing_meta->i->height()/2.0f;
|
||||||
}
|
}
|
||||||
Entity* target = FindFirstCollisonEntity(box_pos, air_drop_aabb_box);
|
ColliderComponent* pickup_collider = nullptr;
|
||||||
if (target) {
|
{
|
||||||
|
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_x = box_pos.x;
|
||||||
float new_y = box_pos.y;
|
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.x = new_x;
|
||||||
box_pos.y = new_y;
|
box_pos.y = new_y;
|
||||||
}
|
}
|
||||||
|
@ -147,8 +147,9 @@ public:
|
|||||||
int self_channel,
|
int self_channel,
|
||||||
int init_map_id);
|
int init_map_id);
|
||||||
void OnPlayerOffline(Player* hum);
|
void OnPlayerOffline(Player* hum);
|
||||||
Entity* FindFirstCollisonEntity(const a8::Vec2& aabb_pos, AabbCollider& aabb_box);
|
void FindLocationWithAabb(ColliderComponent* target_collider,
|
||||||
void FindLocationWithAabb(Entity* target, const a8::Vec2& aabb_pos, AabbCollider* aabb_box,
|
const a8::Vec2& aabb_pos,
|
||||||
|
AabbCollider* aabb_box,
|
||||||
float& new_x, float& new_y);
|
float& new_x, float& new_y);
|
||||||
void FillSMUiUpdate(cs::SMUiUpdate& msg);
|
void FillSMUiUpdate(cs::SMUiUpdate& msg);
|
||||||
void NotifyUiUpdate();
|
void NotifyUiUpdate();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user