This commit is contained in:
aozhiwei 2023-10-18 14:34:27 +08:00
parent 0dff30fbe6
commit 7cc0c7e840
4 changed files with 34 additions and 9 deletions

View File

@ -690,3 +690,35 @@ behaviac::EBTStatus HeroAgent::DebugOut(std::string msg, int arg0, int arg1, int
#endif #endif
return behaviac::BT_SUCCESS; return behaviac::BT_SUCCESS;
} }
bool HeroAgent::TargetInShotRange()
{
if (!current_target_agent->IsValid()) {
return false;
}
float shot_range = GetShotRange();
bool in_square = Collision::InSquare
(GetPos(),
current_target_agent->GetPos(),
shot_range / 0.7);
if (!in_square) {
return false;
}
return shot_range < owner_->GetPos().DistanceGlmVec3(current_target_agent->GetPos());
}
bool HeroAgent::InTargetShotRange()
{
if (!current_target_agent->IsValid()) {
return false;
}
float shot_range = GetShotRange();
bool in_square = Collision::InSquare
(GetPos(),
current_target_agent->GetPos(),
shot_range / 0.7);
if (!in_square) {
return false;
}
return shot_range < owner_->GetPos().DistanceGlmVec3(current_target_agent->GetPos());
}

View File

@ -82,6 +82,8 @@ public:
bool HasFlag(int tag); bool HasFlag(int tag);
void SetFlag(int tag); void SetFlag(int tag);
void UnSetFlag(int tag); void UnSetFlag(int tag);
bool TargetInShotRange();
bool InTargetShotRange();
behaviac::EBTStatus RegisterEvents(behaviac::vector<BtEvent_e> events); behaviac::EBTStatus RegisterEvents(behaviac::vector<BtEvent_e> events);
behaviac::EBTStatus SearchEnemy(float range); behaviac::EBTStatus SearchEnemy(float range);

View File

@ -86,11 +86,3 @@ Room* TargetAgent::GetRoom()
{ {
return owner_->room; return owner_->room;
} }
float TargetAgent::GetShotRange()
{
if (target_.Get() && target_.Get()->GetCurrWeapon()) {
return target_.Get()->GetCurrWeapon()->meta->range();
}
return 0.0f;
}

View File

@ -21,7 +21,6 @@ public:
float GetMaxHp(); float GetMaxHp();
int GetHeroId(); int GetHeroId();
int GetLevel(); int GetLevel();
float GetShotRange();
void Abandon(); void Abandon();
void SetOwner(Creature* owner); void SetOwner(Creature* owner);