This commit is contained in:
aozhiwei 2022-12-28 10:37:12 +08:00
parent 4e20487fa9
commit f0e8cf7d0e
8 changed files with 29 additions and 29 deletions

View File

@ -92,7 +92,7 @@ void Android::InternalUpdate(int delta_time)
room->grid_service->MoveCreature(this);
return;
}
if (GetMoveHelper()->GetPathSize() > 0) {
if (GetMovement()->GetPathSize() > 0) {
Global::Instance()->verify_set_pos = 1;
Position old_pos = GetPos();
UpdateMove();

View File

@ -94,8 +94,8 @@ behaviac::EBTStatus AndroidAgent::DoRandomWalk()
GlmHelper::Normalize(dir);
GetOwner()->SetMoveDir(dir);
GetOwner()->SetAttackDir(dir);
GetOwner()->GetMoveHelper()->CalcTargetPos(200);
if (GetOwner()->GetMoveHelper()->GetPathSize() <= 0) {
GetOwner()->GetMovement()->CalcTargetPos(200);
if (GetOwner()->GetMovement()->GetPathSize() <= 0) {
return behaviac::BT_FAILURE;
}
@ -115,7 +115,7 @@ behaviac::EBTStatus AndroidAgent::DoRandomWalk()
(
[this, handler] ()
{
if (GetOwner()->GetMoveHelper()->GetPathSize() <= 0) {
if (GetOwner()->GetMovement()->GetPathSize() <= 0) {
if (!handler.expired()) {
GetOwner()->GetTrigger()->RemoveEventHandler(handler);
}
@ -265,23 +265,23 @@ behaviac::EBTStatus AndroidAgent::DoPursuit()
} else {
glm::vec3 dir = GetOwner()->GetPos().CalcDir(target.Get()->GetPos());
if (GlmHelper::Norm(dir) <= 1.0f) {
GetOwner()->GetMoveHelper()->CalcTargetPos(60);
GetOwner()->GetMovement()->CalcTargetPos(60);
last_pursuit_frameno = GetOwner()->room->GetFrameNo();
} else {
bool is_shot = false;
if (GlmHelper::Norm(dir) > 300) {
if (GetOwner()->GetMoveHelper()->GetPathSize() < 1) {
if (GetOwner()->GetMovement()->GetPathSize() < 1) {
GlmHelper::Normalize(dir);
GetOwner()->SetMoveDir(dir);
GetOwner()->SetAttackDir(dir);
GetOwner()->GetMoveHelper()->CalcTargetPos(200);
GetOwner()->GetMovement()->CalcTargetPos(200);
last_pursuit_frameno = GetOwner()->room->GetFrameNo();
} else {
if (GetOwner()->room->GetFrameNo() - last_pursuit_frameno > SERVER_FRAME_RATE * 1) {
GlmHelper::Normalize(dir);
GetOwner()->SetMoveDir(dir);
GetOwner()->SetAttackDir(dir);
GetOwner()->GetMoveHelper()->CalcTargetPos(200);
GetOwner()->GetMovement()->CalcTargetPos(200);
last_pursuit_frameno = GetOwner()->room->GetFrameNo();
}
}

View File

@ -132,23 +132,23 @@ behaviac::EBTStatus BaseAgent::CoAttackTarget(int target_id)
} else {
glm::vec3 dir = GetOwner()->GetPos().CalcDir(target.Get()->GetPos());
if (GlmHelper::Norm(dir) <= 1.0f) {
GetOwner()->GetMoveHelper()->CalcTargetPos(60);
GetOwner()->GetMovement()->CalcTargetPos(60);
last_pursuit_frameno = GetOwner()->room->GetFrameNo();
} else {
bool is_shot = false;
if (GlmHelper::Norm(dir) > 300) {
if (GetOwner()->GetMoveHelper()->GetPathSize() < 1) {
if (GetOwner()->GetMovement()->GetPathSize() < 1) {
GlmHelper::Normalize(dir);
GetOwner()->SetMoveDir(dir);
GetOwner()->SetAttackDir(dir);
GetOwner()->GetMoveHelper()->CalcTargetPos(200);
GetOwner()->GetMovement()->CalcTargetPos(200);
last_pursuit_frameno = GetOwner()->room->GetFrameNo();
} else {
if (GetOwner()->room->GetFrameNo() - last_pursuit_frameno > SERVER_FRAME_RATE * 1) {
GlmHelper::Normalize(dir);
GetOwner()->SetMoveDir(dir);
GetOwner()->SetAttackDir(dir);
GetOwner()->GetMoveHelper()->CalcTargetPos(200);
GetOwner()->GetMovement()->CalcTargetPos(200);
last_pursuit_frameno = GetOwner()->room->GetFrameNo();
}
}

View File

@ -60,7 +60,7 @@ Creature::Creature():MoveableEntity()
}
inventory_[IS_1XSCOPE].num = 1;
move_helper_ = std::make_shared<MoveHelper>(this);
movement_ = std::make_shared<Movement>(this);
}
Creature::~Creature()
@ -3176,11 +3176,11 @@ void Creature::UpdateMove()
}
{
if (GetMoveHelper()->UpdatePosition()) {
if (GetMovement()->UpdatePosition()) {
} else {
#if 0
GetMoveHelper()->CalcTargetPos(500);
if (GetMoveHelper()->GetMovePosition(out_pos)) {
GetMovement()->CalcTargetPos(500);
if (GetMovement()->GetMovePosition(out_pos)) {
a8::Vec2 new_pos;
new_pos.x = out_pos.x;
new_pos.y = out_pos.z;

View File

@ -60,7 +60,7 @@ class Team;
class Car;
class Trigger;
class DelayAddBuffHandle;
class MoveHelper;
class Movement;
class Player;
class Creature : public MoveableEntity
{
@ -125,7 +125,7 @@ class Creature : public MoveableEntity
virtual const mt::Hero* GetHeroMeta() { return nullptr; };
virtual void FillMFObjectImage(Room* room, Human* hum, cs::MFCharacterImage* image_data) {};
virtual void SetPos(Position pos) override;
std::shared_ptr<MoveHelper> GetMoveHelper() { return move_helper_; };
std::shared_ptr<Movement> GetMovement() { return movement_; };
bool HasBuffEffect(int buff_effect_id);
Buff* GetBuffByEffectId(int effect_id);
Buff* GetBuffById(int buff_id);
@ -338,7 +338,7 @@ protected:
private:
CreatureWeakPtr weak_ptr_;
std::shared_ptr<MoveHelper> move_helper_;
std::shared_ptr<Movement> movement_;
std::shared_ptr<Trigger> trigger_;
long long collision_times_ = 0;
Team* team_ = nullptr;

View File

@ -11,12 +11,12 @@
#include "mt/Map.h"
MoveHelper::MoveHelper(Creature* owner)
Movement::Movement(Creature* owner)
{
owner_ = owner;
}
bool MoveHelper::UpdatePosition()
bool Movement::UpdatePosition()
{
if (path_index_ >= paths_.size()) {
ClearPath();
@ -93,7 +93,7 @@ bool MoveHelper::UpdatePosition()
return true;
}
void MoveHelper::CalcTargetPos(float distance)
void Movement::CalcTargetPos(float distance)
{
ClearPath();
#ifdef DEBUG1
@ -180,13 +180,13 @@ void MoveHelper::CalcTargetPos(float distance)
paths_.push_back(point);
}
void MoveHelper::ClearPath()
void Movement::ClearPath()
{
path_index_ = 0;
paths_.clear();
}
void MoveHelper::AddPaths(const a8::Vec3& start, std::vector<a8::Vec3>& paths)
void Movement::AddPaths(const a8::Vec3& start, std::vector<a8::Vec3>& paths)
{
#if 0
if (paths.empty()) {
@ -271,7 +271,7 @@ void MoveHelper::AddPaths(const a8::Vec3& start, std::vector<a8::Vec3>& paths)
#endif
}
size_t MoveHelper::GetPathSize()
size_t Movement::GetPathSize()
{
return paths_.size();
}

View File

@ -9,14 +9,14 @@ private:
glm::vec3 dir;
float distance = 0.0f;
friend class MoveHelper;
friend class Movement;
};
class Creature;
class MoveHelper
class Movement
{
public:
MoveHelper(Creature* owner);
Movement(Creature* owner);
bool UpdatePosition();
void CalcTargetPos(float distance);

View File

@ -776,7 +776,7 @@ void Player::_CMMove(f8::MsgHdr& hdr, const cs::CMMove& msg)
std::fabs(new_move_dir.y - GetMoveDir().y) > 0.00001f ||
std::fabs(new_move_dir.z - GetMoveDir().z) > 0.00001f) {
SetMoveDir(new_move_dir);
GetMoveHelper()->CalcTargetPos(500);
GetMovement()->CalcTargetPos(500);
}
moving = true;
}