This commit is contained in:
aozhiwei 2022-12-31 19:33:44 +08:00
parent 9e697629a2
commit d4b03e49ba
5 changed files with 5 additions and 131 deletions

View File

@ -1777,28 +1777,6 @@ void Creature::SummonObstacle(Buff* buff, int id, const Position& target_pos)
} }
} }
bool Creature::CollisonDetection()
{
ColliderComponent* pickup_collider = nullptr;
return CollisonDetectionAndGetCollider(&pickup_collider);
}
bool Creature::CollisonDetectionAndGetCollider(ColliderComponent** pickup_collider)
{
bool through_wall = HasBuffEffect(kBET_ThroughWall) ||
HasBuffEffect(kBET_Fly);
AabbCollider aabb_box;
GetAabbBox(aabb_box);
return room->map_service->CollisionDetectionAndGetCollider
(
room,
through_wall,
GetPos(),
&aabb_box,
pickup_collider
);
}
void Creature::FillSkillCasterState(SkillCasterState* caster_state) void Creature::FillSkillCasterState(SkillCasterState* caster_state)
{ {
caster_state->caster.Attach(this); caster_state->caster.Attach(this);
@ -2163,21 +2141,6 @@ void Creature::SetMaxHP(float max_hp)
#endif #endif
} }
bool Creature::TryMove(const Position& target_pos, Position& out_pos)
{
bool move_ok = false;
Position old_pos = GetPos();
out_pos = GetPos();
SetPos(target_pos);
if (CollisonDetection()) {
out_pos = target_pos;
move_ok = true;
} else {
}
return move_ok;
}
void Creature::SetInfiniteBulletMode() void Creature::SetInfiniteBulletMode()
{ {
inventory_[IS_9MM].num = FIGHTING_MODE_BULLET_NUM; inventory_[IS_9MM].num = FIGHTING_MODE_BULLET_NUM;
@ -2190,12 +2153,6 @@ void Creature::SetInfiniteBulletMode()
void Creature::FindLocation() void Creature::FindLocation()
{ {
ColliderComponent* target_collider = nullptr;
if (CollisonDetectionAndGetCollider(&target_collider)) {
if (!target_collider) {
A8_ABORT();
}
}
} }
bool Creature::Attackable(Room* room) bool Creature::Attackable(Room* room)
@ -2340,13 +2297,7 @@ bool Creature::TrySummonHero(const mt::Hero* hero_meta, glm::vec3 dir, Position
collider._max.x = hero_meta->radius(); collider._max.x = hero_meta->radius();
collider._max.y = hero_meta->radius(); collider._max.y = hero_meta->radius();
collider.MoveCenter(hero_meta->move_offset_x(), hero_meta->move_offset_y()); collider.MoveCenter(hero_meta->move_offset_x(), hero_meta->move_offset_y());
return !room->map_service->CollisionDetection abort();
(
room,
through_wall,
born_pos,
&collider
);
} }
Hero* Creature::InternalSummonHero(Buff* buff, const mt::Hero* hero_meta, glm::vec3 dir, Position born_pos, Hero* Creature::InternalSummonHero(Buff* buff, const mt::Hero* hero_meta, glm::vec3 dir, Position born_pos,

View File

@ -225,8 +225,6 @@ class Creature : public MoveableEntity
void _UpdateSpecMove(); void _UpdateSpecMove();
void CheckSpecObject(); void CheckSpecObject();
bool CollisonDetection();
bool CollisonDetectionAndGetCollider(ColliderComponent** pickup_collider);
void SummonObstacle(Buff* buff, int id, const Position& target_pos); void SummonObstacle(Buff* buff, int id, const Position& target_pos);
void SummonHero(Buff* buff, const Position& pos, const glm::vec3& dir); void SummonHero(Buff* buff, const Position& pos, const glm::vec3& dir);
void FillSkillCasterState(SkillCasterState* caster_state); void FillSkillCasterState(SkillCasterState* caster_state);
@ -249,7 +247,6 @@ class Creature : public MoveableEntity
float GetHPRate(); float GetHPRate();
void GetHitEnemys(std::set<Creature*>& enemys, float radius); void GetHitEnemys(std::set<Creature*>& enemys, float radius);
void GetHitEnemys(std::set<Creature*>& enemys, const glm::vec3 center, float radius); void GetHitEnemys(std::set<Creature*>& enemys, const glm::vec3 center, float radius);
bool TryMove(const Position& target_pos, Position& out_pos);
void SetInfiniteBulletMode(); void SetInfiniteBulletMode();
void FindLocation(); void FindLocation();
bool CheckCollision(); bool CheckCollision();

View File

@ -77,8 +77,12 @@ void Incubator::AllocAndroid(Human* target, int num)
#else #else
hum->SetPos(target->GetPos() + dir * (MetaMgr::Instance()->incubator_base_length + rand_len)); hum->SetPos(target->GetPos() + dir * (MetaMgr::Instance()->incubator_base_length + rand_len));
#endif #endif
#if 1
if (true) {
#else
if (hum->CollisonDetection() || !CanSee(hum, target)) { if (hum->CollisonDetection() || !CanSee(hum, target)) {
hum->SetPos(old_pos); hum->SetPos(old_pos);
#endif
} else { } else {
room->EnableHuman(hum); room->EnableHuman(hum);
#ifdef DEBUG #ifdef DEBUG

View File

@ -297,72 +297,3 @@ int MapService::GetGridId(float world_x, float world_y)
int grid_id = (int)(world_x/cell_width_) + (int)(world_y/cell_width_) * map_width_; int grid_id = (int)(world_x/cell_width_) + (int)(world_y/cell_width_) * map_width_;
return grid_id; return grid_id;
} }
bool MapService::CollisionDetection(Room* room,
bool through_wall,
const Position& pos,
ColliderComponent* a_collider)
{
ColliderComponent* pickup_collider = nullptr;
return CollisionDetectionAndGetCollider
(
room,
through_wall,
pos,
a_collider,
&pickup_collider
);
}
bool MapService::CollisionDetectionAndGetCollider(Room* room,
bool through_wall,
const Position& pos,
ColliderComponent* a_collider,
ColliderComponent** pickup_collider)
{
// 999
#if 1
#else
*pickup_collider = nullptr;
if (room->OverBorder(pos, a_collider)){
return true;
}
if (through_wall) {
return false;
}
std::set<ColliderComponent*> colliders;
GetColliders(room, pos.x, pos.y, colliders);
for (ColliderComponent* collider : colliders) {
switch (collider->owner->GetEntityType()) {
case ET_Obstacle:
{
Obstacle* obstacle = (Obstacle*)collider->owner;
if (obstacle->meta->prebattle_hide() && room->GetGasData().GetGasMode() == GasInactive) {
break;
}
if (obstacle->meta->collision_hit() != kCollisionHitPass) {
if (!obstacle->IsDead(room) && collider->IntersectEx(pos, a_collider)) {
*pickup_collider = collider;
return true;
}
}
}
break;
case ET_Building:
case ET_Dummy:
{
if (collider->IntersectEx(pos, a_collider)) {
*pickup_collider = collider;
return true;
}
}
break;
default:
break;
}
}
#endif
return false;
}

View File

@ -32,15 +32,6 @@ class MapService
float world_x, float world_x,
float world_y, float world_y,
std::set<ColliderComponent*>& colliders); std::set<ColliderComponent*>& colliders);
bool CollisionDetection(Room* room,
bool through_wall,
const Position& pos,
ColliderComponent* collider);
bool CollisionDetectionAndGetCollider(Room* room,
bool through_wall,
const Position& pos,
ColliderComponent* collider,
ColliderComponent** pickup_collider);
private: private:
int GetGridId(float world_x, float world_y); int GetGridId(float world_x, float world_y);