78 lines
2.1 KiB
C++
78 lines
2.1 KiB
C++
#pragma once
|
|
|
|
#include "precompile.h"
|
|
#include "behaviac/behaviac.h"
|
|
#include "behaviac_customized_types.h"
|
|
|
|
#define MAKE_BTCONTEXT(...) \
|
|
[] (CreatureWeakPtr owner, BaseAgent* agent) \
|
|
{ \
|
|
struct Context : public BtContext \
|
|
{ \
|
|
__VA_ARGS__; \
|
|
std::function<void()> _destory_cb; \
|
|
~Context() { if (_destory_cb) { _destory_cb(); };}; \
|
|
}; \
|
|
auto context = std::make_shared<Context>(); \
|
|
context->owner = 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);
|
|
}
|
|
}
|
|
|
|
struct BtCoroutine;
|
|
class Creature;
|
|
class BaseAgent : public behaviac::Agent
|
|
{
|
|
public:
|
|
BaseAgent();
|
|
|
|
virtual ~BaseAgent();
|
|
|
|
BEHAVIAC_DECLARE_AGENTTYPE(BaseAgent, behaviac::Agent)
|
|
|
|
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);
|
|
|
|
behaviac::EBTStatus CoAttackTarget(int target_id);
|
|
behaviac::EBTStatus DoIdle(int min_time, int max_time);
|
|
behaviac::EBTStatus DoUseSkill(int skill_id);
|
|
|
|
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:
|
|
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_;
|
|
};
|