This commit is contained in:
aozhiwei 2022-12-06 10:54:27 +08:00
parent 4eb46ec465
commit bd56f2c193
7 changed files with 30 additions and 9 deletions

View File

@ -24,9 +24,10 @@ behaviac::EBTStatus AndroidAgent::DoIdle(int min_time, int max_time)
if (status_ == behaviac::BT_RUNNING) {
return status_runing_cb_();
}
int idle_time = a8::RandEx(min_time, max_time);
xtimer_list* timer = GetOwner()->room->xtimer.AddDeadLineTimerAndAttach
(
min_time / FRAME_RATE_MS,
idle_time / FRAME_RATE_MS,
a8::XParams(),
[] (const a8::XParams& param)
{
@ -47,6 +48,19 @@ behaviac::EBTStatus AndroidAgent::DoIdle(int min_time, int max_time)
behaviac::EBTStatus AndroidAgent::DoRandomWalk()
{
if (status_ == behaviac::BT_RUNNING) {
return status_runing_cb_();
}
a8::Vec2 dir = GetOwner()->GetMoveDir();
dir.Rotate((10 + rand() % 360)/ 180.0f);
dir.Normalize();
GetOwner()->GetMoveHelper()->CalcTargetPos(500);
status_runing_cb_ =
[] ()
{
return behaviac::BT_SUCCESS;
};
return behaviac::BT_SUCCESS;
}

View File

@ -45,6 +45,7 @@ Creature::Creature():MoveableEntity()
}
inventory_[IS_1XSCOPE].num = 1;
move_helper_ = std::make_shared<MoveHelper>(this);
}
Creature::~Creature()

View File

@ -6,6 +6,7 @@
#include "ability.h"
#include "weapon.h"
#include "battledatacontext.h"
#include "movehelper.h"
#include "cs_proto.pb.h"
@ -130,6 +131,7 @@ class Creature : public MoveableEntity
virtual MetaData::Player* GetHeroMeta() { return nullptr; };
virtual void FillMFObjectImage(Room* room, Human* hum, cs::MFCharacterImage* image_data) {};
virtual void SetPos(a8::Vec2 pos) override;
std::shared_ptr<MoveHelper> GetMoveHelper() { return move_helper_; };
bool HasBuffEffect(int buff_effect_id);
Buff* GetBuffByEffectId(int effect_id);
Buff* GetBuffById(int buff_id);
@ -346,6 +348,7 @@ protected:
private:
CreatureWeakPtr weak_ptr_;
std::shared_ptr<MoveHelper> move_helper_;
Trigger* trigger_ = nullptr;
long long collision_times_ = 0;
Team* team_ = nullptr;

View File

@ -7,7 +7,6 @@
MoveableEntity::MoveableEntity():RoomEntity()
{
move_helper_ = std::make_shared<MoveHelper>(this);
}
void MoveableEntity::TraverseAllLayerEntityList(std::function<void (Entity*, bool&)> func)

View File

@ -2,7 +2,6 @@
#include "gridservice.h"
#include "roomentity.h"
#include "movehelper.h"
class MoveableEntity : public RoomEntity
{
@ -12,7 +11,6 @@ class MoveableEntity : public RoomEntity
virtual void Update(int delta_time) {};
int UpdatedTimes() { return updated_times_;}
std::set<GridCell*>& GetGridList() { return grid_list_; }
std::shared_ptr<MoveHelper> GetMoveHelper() { return move_helper_; };
void TraverseCreatures(std::function<void (Creature*, bool&)> func);
void TraverseAllLayerEntityList(std::function<void (Entity*, bool&)> func);
@ -43,5 +41,4 @@ private:
std::set<GridCell*> grid_list_;
int chg_move_dir_times_ = 0;
int chg_attack_dir_times_ = 0;
std::shared_ptr<MoveHelper> move_helper_;
};

View File

@ -19,14 +19,14 @@ struct MovePathPoint
float distance = 0.0f;
};
MoveHelper::MoveHelper(class MoveableEntity* owner)
MoveHelper::MoveHelper(Creature* owner)
{
owner_ = owner;
}
bool MoveHelper::GetMovePosition(glm::vec3& out_pos)
{
Creature* c = (Creature*)owner_;
Creature* c = owner_;
if (path_index_ < paths_.size()) {
a8::Vec2 src_pos;
a8::Vec2 tar_pos;
@ -258,3 +258,8 @@ void MoveHelper::AddPaths(const a8::Vec3& start, std::vector<a8::Vec3>& paths)
paths_.push_back(p);
}
}
size_t MoveHelper::GetPathSize()
{
return paths_.size();
}

View File

@ -1,18 +1,20 @@
#pragma once
struct MovePathPoint;
class Creature;
class MoveHelper
{
public:
MoveHelper(class MoveableEntity* owner);
MoveHelper(Creature* owner);
bool GetMovePosition(glm::vec3& out_pos);
void CalcTargetPos(float distance);
void ClearPath();
void AddPaths(const a8::Vec3& start, std::vector<a8::Vec3>& paths);
size_t GetPathSize();
private:
std::vector<MovePathPoint*> paths_;
int path_index_ = 0;
class MoveableEntity* owner_ = nullptr;
Creature* owner_ = nullptr;
};