1
This commit is contained in:
parent
4eb46ec465
commit
bd56f2c193
@ -24,9 +24,10 @@ behaviac::EBTStatus AndroidAgent::DoIdle(int min_time, int max_time)
|
|||||||
if (status_ == behaviac::BT_RUNNING) {
|
if (status_ == behaviac::BT_RUNNING) {
|
||||||
return status_runing_cb_();
|
return status_runing_cb_();
|
||||||
}
|
}
|
||||||
|
int idle_time = a8::RandEx(min_time, max_time);
|
||||||
xtimer_list* timer = GetOwner()->room->xtimer.AddDeadLineTimerAndAttach
|
xtimer_list* timer = GetOwner()->room->xtimer.AddDeadLineTimerAndAttach
|
||||||
(
|
(
|
||||||
min_time / FRAME_RATE_MS,
|
idle_time / FRAME_RATE_MS,
|
||||||
a8::XParams(),
|
a8::XParams(),
|
||||||
[] (const a8::XParams& param)
|
[] (const a8::XParams& param)
|
||||||
{
|
{
|
||||||
@ -47,6 +48,19 @@ behaviac::EBTStatus AndroidAgent::DoIdle(int min_time, int max_time)
|
|||||||
|
|
||||||
behaviac::EBTStatus AndroidAgent::DoRandomWalk()
|
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;
|
return behaviac::BT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,6 +45,7 @@ Creature::Creature():MoveableEntity()
|
|||||||
}
|
}
|
||||||
|
|
||||||
inventory_[IS_1XSCOPE].num = 1;
|
inventory_[IS_1XSCOPE].num = 1;
|
||||||
|
move_helper_ = std::make_shared<MoveHelper>(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
Creature::~Creature()
|
Creature::~Creature()
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
#include "ability.h"
|
#include "ability.h"
|
||||||
#include "weapon.h"
|
#include "weapon.h"
|
||||||
#include "battledatacontext.h"
|
#include "battledatacontext.h"
|
||||||
|
#include "movehelper.h"
|
||||||
|
|
||||||
#include "cs_proto.pb.h"
|
#include "cs_proto.pb.h"
|
||||||
|
|
||||||
@ -130,6 +131,7 @@ class Creature : public MoveableEntity
|
|||||||
virtual MetaData::Player* GetHeroMeta() { return nullptr; };
|
virtual MetaData::Player* GetHeroMeta() { return nullptr; };
|
||||||
virtual void FillMFObjectImage(Room* room, Human* hum, cs::MFCharacterImage* image_data) {};
|
virtual void FillMFObjectImage(Room* room, Human* hum, cs::MFCharacterImage* image_data) {};
|
||||||
virtual void SetPos(a8::Vec2 pos) override;
|
virtual void SetPos(a8::Vec2 pos) override;
|
||||||
|
std::shared_ptr<MoveHelper> GetMoveHelper() { return move_helper_; };
|
||||||
bool HasBuffEffect(int buff_effect_id);
|
bool HasBuffEffect(int buff_effect_id);
|
||||||
Buff* GetBuffByEffectId(int effect_id);
|
Buff* GetBuffByEffectId(int effect_id);
|
||||||
Buff* GetBuffById(int buff_id);
|
Buff* GetBuffById(int buff_id);
|
||||||
@ -346,6 +348,7 @@ protected:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
CreatureWeakPtr weak_ptr_;
|
CreatureWeakPtr weak_ptr_;
|
||||||
|
std::shared_ptr<MoveHelper> move_helper_;
|
||||||
Trigger* trigger_ = nullptr;
|
Trigger* trigger_ = nullptr;
|
||||||
long long collision_times_ = 0;
|
long long collision_times_ = 0;
|
||||||
Team* team_ = nullptr;
|
Team* team_ = nullptr;
|
||||||
|
@ -7,7 +7,6 @@
|
|||||||
|
|
||||||
MoveableEntity::MoveableEntity():RoomEntity()
|
MoveableEntity::MoveableEntity():RoomEntity()
|
||||||
{
|
{
|
||||||
move_helper_ = std::make_shared<MoveHelper>(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MoveableEntity::TraverseAllLayerEntityList(std::function<void (Entity*, bool&)> func)
|
void MoveableEntity::TraverseAllLayerEntityList(std::function<void (Entity*, bool&)> func)
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
#include "gridservice.h"
|
#include "gridservice.h"
|
||||||
#include "roomentity.h"
|
#include "roomentity.h"
|
||||||
#include "movehelper.h"
|
|
||||||
|
|
||||||
class MoveableEntity : public RoomEntity
|
class MoveableEntity : public RoomEntity
|
||||||
{
|
{
|
||||||
@ -12,7 +11,6 @@ class MoveableEntity : public RoomEntity
|
|||||||
virtual void Update(int delta_time) {};
|
virtual void Update(int delta_time) {};
|
||||||
int UpdatedTimes() { return updated_times_;}
|
int UpdatedTimes() { return updated_times_;}
|
||||||
std::set<GridCell*>& GetGridList() { return grid_list_; }
|
std::set<GridCell*>& GetGridList() { return grid_list_; }
|
||||||
std::shared_ptr<MoveHelper> GetMoveHelper() { return move_helper_; };
|
|
||||||
|
|
||||||
void TraverseCreatures(std::function<void (Creature*, bool&)> func);
|
void TraverseCreatures(std::function<void (Creature*, bool&)> func);
|
||||||
void TraverseAllLayerEntityList(std::function<void (Entity*, bool&)> func);
|
void TraverseAllLayerEntityList(std::function<void (Entity*, bool&)> func);
|
||||||
@ -43,5 +41,4 @@ private:
|
|||||||
std::set<GridCell*> grid_list_;
|
std::set<GridCell*> grid_list_;
|
||||||
int chg_move_dir_times_ = 0;
|
int chg_move_dir_times_ = 0;
|
||||||
int chg_attack_dir_times_ = 0;
|
int chg_attack_dir_times_ = 0;
|
||||||
std::shared_ptr<MoveHelper> move_helper_;
|
|
||||||
};
|
};
|
||||||
|
@ -19,14 +19,14 @@ struct MovePathPoint
|
|||||||
float distance = 0.0f;
|
float distance = 0.0f;
|
||||||
};
|
};
|
||||||
|
|
||||||
MoveHelper::MoveHelper(class MoveableEntity* owner)
|
MoveHelper::MoveHelper(Creature* owner)
|
||||||
{
|
{
|
||||||
owner_ = owner;
|
owner_ = owner;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MoveHelper::GetMovePosition(glm::vec3& out_pos)
|
bool MoveHelper::GetMovePosition(glm::vec3& out_pos)
|
||||||
{
|
{
|
||||||
Creature* c = (Creature*)owner_;
|
Creature* c = owner_;
|
||||||
if (path_index_ < paths_.size()) {
|
if (path_index_ < paths_.size()) {
|
||||||
a8::Vec2 src_pos;
|
a8::Vec2 src_pos;
|
||||||
a8::Vec2 tar_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);
|
paths_.push_back(p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t MoveHelper::GetPathSize()
|
||||||
|
{
|
||||||
|
return paths_.size();
|
||||||
|
}
|
||||||
|
@ -1,18 +1,20 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
struct MovePathPoint;
|
struct MovePathPoint;
|
||||||
|
class Creature;
|
||||||
class MoveHelper
|
class MoveHelper
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MoveHelper(class MoveableEntity* owner);
|
MoveHelper(Creature* owner);
|
||||||
|
|
||||||
bool GetMovePosition(glm::vec3& out_pos);
|
bool GetMovePosition(glm::vec3& out_pos);
|
||||||
void CalcTargetPos(float distance);
|
void CalcTargetPos(float distance);
|
||||||
void ClearPath();
|
void ClearPath();
|
||||||
void AddPaths(const a8::Vec3& start, std::vector<a8::Vec3>& paths);
|
void AddPaths(const a8::Vec3& start, std::vector<a8::Vec3>& paths);
|
||||||
|
size_t GetPathSize();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<MovePathPoint*> paths_;
|
std::vector<MovePathPoint*> paths_;
|
||||||
int path_index_ = 0;
|
int path_index_ = 0;
|
||||||
class MoveableEntity* owner_ = nullptr;
|
Creature* owner_ = nullptr;
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user