game2006/server/gameserver/new_hero_agent.h
aozhiwei 27564fa261 1
2023-10-19 17:01:48 +08:00

162 lines
5.0 KiB
C++

#pragma once
#include "new_base_agent.h"
#define MAKE_BTCONTEXT(...) \
[] (CreatureWeakPtr owner, BaseAgent* agent) \
{ \
class Context : public BtContext \
{public: \
__VA_ARGS__; \
std::function<void()> _destory_cb; \
long long frameno = 0; \
~Context() { if (_destory_cb) { _destory_cb(); };}; \
}; \
auto context = std::make_shared<Context>(); \
context->SetOwner(owner); \
context->frameno = owner.Get()->room->GetFrameNo(); \
return context; \
}(owner_->GetWeakPtrRef(), this)
namespace a8
{
template<typename T>
static auto SpToWp(std::shared_ptr<T> sp)
{
return std::weak_ptr<T>(sp);
}
}
class Hero;
class RoomAgent;
class TeamAgent;
class TargetAgent;
class MasterAgent;
class BtCoroutine;
class HeroAgent : public BaseAgent
{
public:
HeroAgent();
virtual ~HeroAgent();
BEHAVIAC_DECLARE_AGENTTYPE(HeroAgent, BaseAgent)
void Exec();
void SetOwner(Creature* owner);
int GetUniId();
int GetAgentType();
bool IsMoving();
glm::vec3 GetPos();
bool IsDead();
glm::vec3 GetSafeAreaCenter();
float GetSafeAreaRadius();
float GetHp();
float GetMaxHp();
void OpenBulletTraceMode();
void CloseBulletTraceMode();
float CalcDistance(const glm::vec3& target_pos);
int GetHeroId();
int GetLevel();
bool CanShot();
bool CanUseSkill(int skill_id);
void SendEmote(int emote);
int GetBattleTimes();
void SetMoveDir(const glm::vec3& dir);
void SetAttackDir(const glm::vec3& dir);
void ShotNormal(const glm::vec3& dir);
void ShotTrace();
glm::vec3 GetRandomDir();
glm::vec3 GetTargetDir();
glm::vec3 RandomPoint(const glm::vec3& center, float range);
float GetShotRange();
void SetV(int id, int val);
int GetV(int id);
int IncV(int id, int val);
int DecV(int id, int val);
bool HasBuffEffect(int effect_id);
bool IsNearGas(float anti_range);
bool MasterInRange(float anti_range);
bool HasFlag(int tag);
void SetFlag(int tag);
void UnSetFlag(int tag);
bool TargetInShotRange();
bool InTargetShotRange();
void ResetShotTimes();
void ResetUseSkillTimes();
int GetShotTimes();
int GetUseSkillTimes();
float GetTargetManhattanDistance();
std::string GetSkillBtFile();
void Abort(behaviac::string msg, behaviac::vector<int> args);
bool HasUseableSkill();
behaviac::EBTStatus RegisterEvents(behaviac::vector<BtEvent_e> events);
behaviac::EBTStatus SearchEnemy(float range);
behaviac::EBTStatus DebugOut(std::string msg, int arg0, int arg1, int arg2);
behaviac::EBTStatus RandomSafeZonePoint(int try_count, int step_len);
behaviac::EBTStatus CoIdle(int min_val, int max_val);
behaviac::EBTStatus CoMoveCurrentTargetRaycast();
behaviac::EBTStatus CoShotCurrentTargetRaycast();
behaviac::EBTStatus CoMoveMasterRaycast();
behaviac::EBTStatus CoFindPath(const glm::vec3& pos);
behaviac::EBTStatus CoFindPathEx(const glm::vec3& pos, float distance);
behaviac::EBTStatus CoStartMove(int min_val, int max_val);
behaviac::EBTStatus CoMoveForward(int min_val, int max_val);
behaviac::EBTStatus CoSleep(int time);
behaviac::EBTStatus CoUseSkill(int skill_id);
virtual Room* GetRoom() override;
public:
RoomAgent* room_agent = nullptr;
TeamAgent* team_agent = nullptr;
MasterAgent* master_agent = nullptr;
TargetAgent* current_target_agent = nullptr;
float task_param0 = 0.0f;
float task_param1 = 0.0f;
float task_param2 = 0.0f;
float task_param3 = 0.0f;
float task_param4 = 0.0f;
float tmp_val0 = 0.0f;
float tmp_val1 = 0.0f;
float tmp_val2 = 0.0f;
float tmp_val3 = 0.0f;
float tmp_val4 = 0.0f;
glm::vec3 tmp_point0 = glm::vec3(0.0f, 0.0f, 0.0f);
glm::vec3 tmp_point1 = glm::vec3(0.0f, 0.0f, 0.0f);
glm::vec3 tmp_point2 = glm::vec3(0.0f, 0.0f, 0.0f);
int out_errno = 0;
float out_val0 = 0.0;
float out_val1 = 0.0;
float out_val2 = 0.0;
float out_val3 = 0.0;
float out_val4 = 0.0;
glm::vec3 out_point0 = glm::vec3(0.0f, 0.0f, 0.0f);
glm::vec3 out_point1 = glm::vec3(0.0f, 0.0f, 0.0f);
glm::vec3 out_point2 = glm::vec3(0.0f, 0.0f, 0.0f);
protected:
behaviac::EBTStatus DoRunningCb();
behaviac::EBTStatus StartCoroutine(std::shared_ptr<BtCoroutine> coroutine);
bool InternalUseSkill(int skill_id, int& wait_time);
private:
Creature* owner_ = nullptr;
bool bullet_trace_mode_ = false;
long long flags_ = 0;
std::map<int, int> dyn_hash_;
#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;
std::shared_ptr<BtCoroutine> coroutine_;
};