game2006/server/gameserver/base_agent.h
aozhiwei 95a25be38b 1
2023-06-29 16:14:54 +08:00

105 lines
3.2 KiB
C++

#pragma once
#include "precompile.h"
#include "behaviac/behaviac.h"
#include "behaviac_customized_types.h"
#define MAKE_BTCONTEXT(...) \
[] (CreatureWeakPtr owner, BaseAgent* agent) \
{ \
class Context : public BtContext \
{public: \
__VA_ARGS__; \
std::function<void()> _destory_cb; \
~Context() { if (_destory_cb) { _destory_cb(); };}; \
}; \
auto context = std::make_shared<Context>(); \
context->SetOwner(owner); \
return context; \
}(GetOwner()->GetWeakPtrRef(), this)
namespace a8
{
template<typename T>
static auto SpToWp(std::shared_ptr<T> sp)
{
return std::weak_ptr<T>(sp);
}
}
class BtCoroutine;
class Creature;
class BaseAgent : public behaviac::Agent
{
public:
BaseAgent();
virtual ~BaseAgent();
BEHAVIAC_DECLARE_AGENTTYPE(BaseAgent, behaviac::Agent)
int find_enemy_target_uniid = 0;
int selected_skill_id = 0;
void Exec();
bool IsGameOver();
bool HasTarget(float range);
bool HasBuffEffect(int buff_effect);
float GetAttackRange();
void SetBulletTraceMode(bool mode);
bool CanUseSkill(int skill_id);
int GetUseableSkill(Creature* target);
bool CurrentTargetMoveCanReach();
glm::vec3 GetPos();
bool MoveCanReach(const glm::vec3& pos);
bool ShotCanReach(const glm::vec3& target_pos);
bool CurrentTargetIsValid();
float GetCurrentTargetDistance();
float GetFindEnemyResultTargetDistance();
glm::vec3 GetFindEnemyResultTargetPos();
void SetCurrentTarget(int target_uniid);
int GetFindEnemyResultTargetUniId();
bool IsNearGas(float distance);
float GetSafeAreaRadius();
bool IsDead();
behaviac::EBTStatus CoAttackTarget(int target_id);
behaviac::EBTStatus DoIdle(int min_time, int max_time);
behaviac::EBTStatus DoUseSkill(int skill_id);
behaviac::EBTStatus CoFindPath(float x, float y, float z);
behaviac::EBTStatus SelectUseableSkill(const behaviac::vector<int> skill_ids);
behaviac::EBTStatus CoFindPathToCurrentTarget(float distance);
behaviac::EBTStatus CoMoveToCurrentTarget(float distance);
behaviac::EBTStatus FindEnemy(float range);
behaviac::EBTStatus DoSkill(int skill_id);
behaviac::EBTStatus CoShot();
behaviac::EBTStatus CoRunGas();
public:
void SetOwner(Creature* owner) { owner_ = owner; };
Creature* GetOwner() { return owner_; };
protected:
behaviac::EBTStatus DoRunningCb();
behaviac::EBTStatus StartCoroutine(std::shared_ptr<BtCoroutine> coroutine);
bool InternalUseSkill(int skill_id, CreatureWeakPtr target, int& wait_time);
void Sleep(int time);
protected:
CreatureWeakPtr current_target_;
bool bullet_trace_mode_ = false;
#ifdef DEBUG
behaviac::EBTStatus last_status_ = behaviac::BT_INVALID;
long long status_frameno_ = 0;
const char* status_name_ = nullptr;
#endif
behaviac::EBTStatus status_= behaviac::BT_SUCCESS;
private:
Creature* owner_ = nullptr;
std::shared_ptr<BtCoroutine> coroutine_;
};