#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 _destory_cb; \ ~Context() { if (_destory_cb) { _destory_cb(); };}; \ }; \ auto context = std::make_shared(); \ context->SetOwner(owner); \ return context; \ }(GetOwner()->GetWeakPtrRef(), this) namespace a8 { template static auto SpToWp(std::shared_ptr sp) { return std::weak_ptr(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 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 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 coroutine_; };