game2006/server/gameserver/base_agent.h
aozhiwei 18a6cb7db8 1
2023-04-05 14:12:44 +08:00

64 lines
1.4 KiB
C++

#pragma once
#include "precompile.h"
#include "behaviac/behaviac.h"
#include "behaviac_customized_types.h"
struct BtCoroutine
{
std::any context;
const char* name = nullptr;
std::function<behaviac::EBTStatus()> runing_cb;
std::function<void(bool, bool&)> event_cb;
BtCoroutine(std::any context, const char* name)
{
this->context = context;
this->name = name;
}
};
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);
behaviac::EBTStatus CoAttackTarget(int target_id);
behaviac::EBTStatus DoIdle(int min_time, int max_time);
public:
void SetOwner(Creature* owner) { owner_ = owner; };
Creature* GetOwner() { return owner_; };
protected:
behaviac::EBTStatus DoRunningCb();
behaviac::EBTStatus StartCoroutine(std::shared_ptr<BtCoroutine> coroutine);
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_;
};