1
This commit is contained in:
parent
2712902da4
commit
e0265b5ff4
@ -9,6 +9,8 @@
|
||||
|
||||
#include "f8/btmgr.h"
|
||||
|
||||
#include "mt/Equip.h"
|
||||
|
||||
void DumpBt(BaseAgent* agent)
|
||||
{
|
||||
static std::string last_bt_name;
|
||||
@ -182,6 +184,9 @@ bool BaseAgent::HasBuffEffect(int buff_effect)
|
||||
|
||||
float BaseAgent::GetAttackRange()
|
||||
{
|
||||
if (owner_->GetCurrWeapon()) {
|
||||
return owner_->GetCurrWeapon()->meta->range();
|
||||
}
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
|
@ -34,6 +34,7 @@ protected:
|
||||
const char* name);
|
||||
|
||||
protected:
|
||||
bool bullet_trace_mode_ = false;
|
||||
#ifdef DEBUG
|
||||
behaviac::EBTStatus last_status_ = behaviac::BT_INVALID;
|
||||
long long status_frameno_ = 0;
|
||||
@ -45,5 +46,4 @@ protected:
|
||||
|
||||
private:
|
||||
Creature* owner_ = nullptr;
|
||||
bool bullet_trace_mode_ = false;
|
||||
};
|
||||
|
@ -221,7 +221,11 @@ behaviac::EBTStatus HeroAgent::DoAttack()
|
||||
GetOwner()->SetAttackDir(dir);
|
||||
bool shot_ok = false;
|
||||
glm::vec3 shot_dir = dir;
|
||||
GetOwner()->Shot(shot_dir, shot_ok, 0, 0);
|
||||
if (bullet_trace_mode_) {
|
||||
GetOwner()->Shot(shot_dir, shot_ok, 0, enemy->GetUniId());
|
||||
} else {
|
||||
GetOwner()->Shot(shot_dir, shot_ok, 0, 0);
|
||||
}
|
||||
|
||||
CreatureWeakPtr target = enemy->GetWeakPtrRef();
|
||||
long long last_frameno = GetOwner()->room->GetFrameNo();
|
||||
@ -247,7 +251,11 @@ behaviac::EBTStatus HeroAgent::DoAttack()
|
||||
glm::vec3 shot_dir = GetOwner()->GetPos().CalcDir(target.Get()->GetPos());;
|
||||
GlmHelper::Normalize(shot_dir);
|
||||
GetOwner()->SetAttackDir(shot_dir);
|
||||
GetOwner()->Shot(shot_dir, shot_ok, 0, 0);
|
||||
if (bullet_trace_mode_) {
|
||||
GetOwner()->Shot(shot_dir, shot_ok, 0, target.Get()->GetUniId());
|
||||
} else {
|
||||
GetOwner()->Shot(shot_dir, shot_ok, 0, target.Get()->GetUniId());
|
||||
}
|
||||
|
||||
return behaviac::BT_RUNNING;
|
||||
}
|
||||
@ -312,7 +320,11 @@ behaviac::EBTStatus HeroAgent::DoPursuit()
|
||||
bool shot_ok = false;
|
||||
glm::vec3 shot_dir = dir;
|
||||
GetOwner()->SetAttackDir(dir);
|
||||
GetOwner()->Shot(shot_dir, shot_ok, 0, 0);
|
||||
if (bullet_trace_mode_) {
|
||||
GetOwner()->Shot(shot_dir, shot_ok, 0, 0);
|
||||
} else {
|
||||
GetOwner()->Shot(shot_dir, shot_ok, 0, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
return behaviac::BT_RUNNING;
|
||||
@ -328,5 +340,69 @@ behaviac::EBTStatus HeroAgent::DoPursuit()
|
||||
|
||||
behaviac::EBTStatus HeroAgent::DoHelpAttack(int target_uniid)
|
||||
{
|
||||
Creature* enemy = GetOwner()->room->GetCreatureByUniId(target_uniid);
|
||||
if (!enemy) {
|
||||
return behaviac::BT_FAILURE;
|
||||
}
|
||||
if (enemy->dead) {
|
||||
return behaviac::BT_FAILURE;
|
||||
}
|
||||
if (GlmHelper::IsEqual2D(GetOwner()->GetPos().ToGlmVec3(), enemy->GetPos().ToGlmVec3())) {
|
||||
return behaviac::BT_FAILURE;
|
||||
}
|
||||
float distance = enemy->GetPos().Distance2D2(GetOwner()->GetPos());
|
||||
if (distance > GetAttackRange()) {
|
||||
return behaviac::BT_FAILURE;
|
||||
}
|
||||
glm::vec3 dir = GetOwner()->GetPos().CalcDir(enemy->GetPos());
|
||||
GlmHelper::Normalize(dir);
|
||||
GetOwner()->SetMoveDir(dir);
|
||||
GetOwner()->SetAttackDir(dir);
|
||||
bool shot_ok = false;
|
||||
glm::vec3 shot_dir = dir;
|
||||
if (bullet_trace_mode_) {
|
||||
GetOwner()->Shot(shot_dir, shot_ok, 0, enemy->GetUniId());
|
||||
} else {
|
||||
GetOwner()->Shot(shot_dir, shot_ok, 0, 0);
|
||||
}
|
||||
|
||||
CreatureWeakPtr target = enemy->GetWeakPtrRef();
|
||||
long long last_frameno = GetOwner()->room->GetFrameNo();
|
||||
return StartCoroutine
|
||||
(
|
||||
[this, last_frameno, target] () mutable
|
||||
{
|
||||
if (GetOwner()->room->GetFrameNo() - last_frameno > SERVER_FRAME_RATE * 3) {
|
||||
status_ = behaviac::BT_SUCCESS;
|
||||
return behaviac::BT_SUCCESS;
|
||||
} else {
|
||||
if (!target.Get()) {
|
||||
return behaviac::BT_SUCCESS;
|
||||
}
|
||||
if (target.Get()->dead) {
|
||||
return behaviac::BT_SUCCESS;
|
||||
}
|
||||
if (GlmHelper::IsEqual2D(GetOwner()->GetPos().ToGlmVec3(),
|
||||
target.Get()->GetPos().ToGlmVec3())) {
|
||||
return behaviac::BT_FAILURE;
|
||||
}
|
||||
bool shot_ok = false;
|
||||
glm::vec3 shot_dir = GetOwner()->GetPos().CalcDir(target.Get()->GetPos());;
|
||||
GlmHelper::Normalize(shot_dir);
|
||||
GetOwner()->SetAttackDir(shot_dir);
|
||||
if (bullet_trace_mode_) {
|
||||
GetOwner()->Shot(shot_dir, shot_ok, 0, target.Get()->GetUniId());
|
||||
} else {
|
||||
GetOwner()->Shot(shot_dir, shot_ok, 0, target.Get()->GetUniId());
|
||||
}
|
||||
|
||||
return behaviac::BT_RUNNING;
|
||||
}
|
||||
},
|
||||
[this] (bool is_test, bool& has_event)
|
||||
{
|
||||
|
||||
},
|
||||
"CoHelpAttack"
|
||||
);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user