1
This commit is contained in:
parent
2712902da4
commit
e0265b5ff4
@ -9,6 +9,8 @@
|
|||||||
|
|
||||||
#include "f8/btmgr.h"
|
#include "f8/btmgr.h"
|
||||||
|
|
||||||
|
#include "mt/Equip.h"
|
||||||
|
|
||||||
void DumpBt(BaseAgent* agent)
|
void DumpBt(BaseAgent* agent)
|
||||||
{
|
{
|
||||||
static std::string last_bt_name;
|
static std::string last_bt_name;
|
||||||
@ -182,6 +184,9 @@ bool BaseAgent::HasBuffEffect(int buff_effect)
|
|||||||
|
|
||||||
float BaseAgent::GetAttackRange()
|
float BaseAgent::GetAttackRange()
|
||||||
{
|
{
|
||||||
|
if (owner_->GetCurrWeapon()) {
|
||||||
|
return owner_->GetCurrWeapon()->meta->range();
|
||||||
|
}
|
||||||
return 0.0f;
|
return 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,6 +34,7 @@ protected:
|
|||||||
const char* name);
|
const char* name);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
bool bullet_trace_mode_ = false;
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
behaviac::EBTStatus last_status_ = behaviac::BT_INVALID;
|
behaviac::EBTStatus last_status_ = behaviac::BT_INVALID;
|
||||||
long long status_frameno_ = 0;
|
long long status_frameno_ = 0;
|
||||||
@ -45,5 +46,4 @@ protected:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
Creature* owner_ = nullptr;
|
Creature* owner_ = nullptr;
|
||||||
bool bullet_trace_mode_ = false;
|
|
||||||
};
|
};
|
||||||
|
@ -221,7 +221,11 @@ behaviac::EBTStatus HeroAgent::DoAttack()
|
|||||||
GetOwner()->SetAttackDir(dir);
|
GetOwner()->SetAttackDir(dir);
|
||||||
bool shot_ok = false;
|
bool shot_ok = false;
|
||||||
glm::vec3 shot_dir = dir;
|
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);
|
GetOwner()->Shot(shot_dir, shot_ok, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
CreatureWeakPtr target = enemy->GetWeakPtrRef();
|
CreatureWeakPtr target = enemy->GetWeakPtrRef();
|
||||||
long long last_frameno = GetOwner()->room->GetFrameNo();
|
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());;
|
glm::vec3 shot_dir = GetOwner()->GetPos().CalcDir(target.Get()->GetPos());;
|
||||||
GlmHelper::Normalize(shot_dir);
|
GlmHelper::Normalize(shot_dir);
|
||||||
GetOwner()->SetAttackDir(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;
|
return behaviac::BT_RUNNING;
|
||||||
}
|
}
|
||||||
@ -312,7 +320,11 @@ behaviac::EBTStatus HeroAgent::DoPursuit()
|
|||||||
bool shot_ok = false;
|
bool shot_ok = false;
|
||||||
glm::vec3 shot_dir = dir;
|
glm::vec3 shot_dir = dir;
|
||||||
GetOwner()->SetAttackDir(dir);
|
GetOwner()->SetAttackDir(dir);
|
||||||
|
if (bullet_trace_mode_) {
|
||||||
GetOwner()->Shot(shot_dir, shot_ok, 0, 0);
|
GetOwner()->Shot(shot_dir, shot_ok, 0, 0);
|
||||||
|
} else {
|
||||||
|
GetOwner()->Shot(shot_dir, shot_ok, 0, 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return behaviac::BT_RUNNING;
|
return behaviac::BT_RUNNING;
|
||||||
@ -328,5 +340,69 @@ behaviac::EBTStatus HeroAgent::DoPursuit()
|
|||||||
|
|
||||||
behaviac::EBTStatus HeroAgent::DoHelpAttack(int target_uniid)
|
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