1
This commit is contained in:
parent
57b0c9db44
commit
aca6f74bbc
@ -2019,12 +2019,13 @@ void Human::_UpdateMove(int speed)
|
|||||||
if (HasBuffEffect(kBET_Hide)) {
|
if (HasBuffEffect(kBET_Hide)) {
|
||||||
RemoveBuffByEffectId(kBET_Hide);
|
RemoveBuffByEffectId(kBET_Hide);
|
||||||
}
|
}
|
||||||
|
#if 0
|
||||||
a8::Vec2 curr_pos;
|
a8::Vec2 curr_pos;
|
||||||
curr_pos.x = GetLastPos().x;
|
curr_pos.x = GetLastPos().x;
|
||||||
curr_pos.y = GetLastPos().z;
|
curr_pos.y = GetLastPos().z;
|
||||||
|
|
||||||
SetPos(GetPos() + GetMoveDir() * speed);
|
SetPos(GetPos() + GetMoveDir() * speed);
|
||||||
|
#endif
|
||||||
CheckSpecObject();
|
CheckSpecObject();
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
@ -295,24 +295,6 @@ int MapService::GetGridId(float world_x, float world_y)
|
|||||||
return grid_id;
|
return grid_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
int MapService::FindPathRequest(Human* hum,
|
|
||||||
const a8::Vec2& start_pos,
|
|
||||||
const a8::Vec2& end_pos,
|
|
||||||
int max_step_num)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
FindPathStatus* MapService::QueryFindPathStatus(int query_id)
|
|
||||||
{
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
void MapService::RemoveFindPathRequest(Human* hum, int query_id)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
bool MapService::CollisionDetection(Room* room,
|
bool MapService::CollisionDetection(Room* room,
|
||||||
bool through_wall,
|
bool through_wall,
|
||||||
const a8::Vec2& pos,
|
const a8::Vec2& pos,
|
||||||
|
@ -10,23 +10,6 @@ struct CellNode
|
|||||||
CellNode* next = nullptr;
|
CellNode* next = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct MovePathPoint
|
|
||||||
{
|
|
||||||
a8::Vec2 pos;
|
|
||||||
float distance = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct FindPathStatus
|
|
||||||
{
|
|
||||||
long long frameno = 0;
|
|
||||||
Human* hum = nullptr;
|
|
||||||
a8::Vec2 start_pos;
|
|
||||||
a8::Vec2 end_pos;
|
|
||||||
int curr_step = 0;
|
|
||||||
int max_step_num = 0;
|
|
||||||
std::vector<MovePathPoint> out_ponits;
|
|
||||||
};
|
|
||||||
|
|
||||||
class Room;
|
class Room;
|
||||||
class MapService
|
class MapService
|
||||||
{
|
{
|
||||||
@ -49,12 +32,6 @@ class MapService
|
|||||||
float world_x,
|
float world_x,
|
||||||
float world_y,
|
float world_y,
|
||||||
std::set<ColliderComponent*>& colliders);
|
std::set<ColliderComponent*>& colliders);
|
||||||
int FindPathRequest(Human* hum,
|
|
||||||
const a8::Vec2& start_pos,
|
|
||||||
const a8::Vec2& end_pos,
|
|
||||||
int max_step_num);
|
|
||||||
FindPathStatus* QueryFindPathStatus(int query_id);
|
|
||||||
void RemoveFindPathRequest(Human* hum, int query_id);
|
|
||||||
bool CollisionDetection(Room* room,
|
bool CollisionDetection(Room* room,
|
||||||
bool through_wall,
|
bool through_wall,
|
||||||
const a8::Vec2& pos,
|
const a8::Vec2& pos,
|
||||||
|
@ -5,6 +5,11 @@
|
|||||||
#include "human.h"
|
#include "human.h"
|
||||||
#include "mapinstance.h"
|
#include "mapinstance.h"
|
||||||
|
|
||||||
|
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)
|
||||||
{
|
{
|
||||||
room->grid_service->TraverseAllLayerEntityList(room->GetRoomIdx(), grid_list_, func);
|
room->grid_service->TraverseAllLayerEntityList(room->GetRoomIdx(), grid_list_, func);
|
||||||
@ -92,12 +97,6 @@ void MoveableEntity::SetMoveDir(const a8::Vec2& move_dir)
|
|||||||
++chg_move_dir_times_;
|
++chg_move_dir_times_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MoveableEntity::SetTargetPos(const glm::vec3& target_pos)
|
|
||||||
{
|
|
||||||
target_pos_ = target_pos;
|
|
||||||
++chg_target_pos_times_;
|
|
||||||
}
|
|
||||||
|
|
||||||
void MoveableEntity::SetAttackDir(const a8::Vec2& attack_dir)
|
void MoveableEntity::SetAttackDir(const a8::Vec2& attack_dir)
|
||||||
{
|
{
|
||||||
attack_dir_ = attack_dir;
|
attack_dir_ = attack_dir;
|
||||||
@ -125,27 +124,3 @@ float MoveableEntity::GetAttackDirRotate()
|
|||||||
}
|
}
|
||||||
return angle;
|
return angle;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MoveableEntity::CalcTargetPos(float distance)
|
|
||||||
{
|
|
||||||
glm::vec3 start;
|
|
||||||
glm::vec3 end;
|
|
||||||
glm::vec3 hit_point;
|
|
||||||
|
|
||||||
start.x = GetPos().x / 10.0f;
|
|
||||||
start.z = GetPos().y / 10.0f;
|
|
||||||
|
|
||||||
a8::Vec2 target_pos2d = GetPos() + GetMoveDir() * distance;
|
|
||||||
end.x = target_pos2d.x / 10.0f;
|
|
||||||
end.z = target_pos2d.y / 10.0f;
|
|
||||||
|
|
||||||
last_pos_.x = GetPos().x;
|
|
||||||
last_pos_.z = GetPos().y;
|
|
||||||
|
|
||||||
int ret = room->map_instance->Raycast(0, start, end, hit_point);
|
|
||||||
if (ret > 1) {
|
|
||||||
SetTargetPos(hit_point * 10.0f);
|
|
||||||
} else {
|
|
||||||
SetTargetPos(end * 10.0f);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -2,16 +2,20 @@
|
|||||||
|
|
||||||
#include "gridservice.h"
|
#include "gridservice.h"
|
||||||
#include "roomentity.h"
|
#include "roomentity.h"
|
||||||
|
#include "movehelper.h"
|
||||||
|
|
||||||
class AIComponent;
|
class AIComponent;
|
||||||
class MoveableEntity : public RoomEntity
|
class MoveableEntity : public RoomEntity
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
MoveableEntity();
|
||||||
|
|
||||||
AIComponent* ai = nullptr;
|
AIComponent* ai = nullptr;
|
||||||
|
|
||||||
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);
|
||||||
@ -26,17 +30,12 @@ class MoveableEntity : public RoomEntity
|
|||||||
virtual void UpdateCharImage(const char* file, int line, const char* func);
|
virtual void UpdateCharImage(const char* file, int line, const char* func);
|
||||||
virtual const a8::Vec2& GetMoveDir() { return move_dir_; };
|
virtual const a8::Vec2& GetMoveDir() { return move_dir_; };
|
||||||
virtual void SetMoveDir(const a8::Vec2& move_dir);
|
virtual void SetMoveDir(const a8::Vec2& move_dir);
|
||||||
virtual const glm::vec3& GetLastPos() { return last_pos_; };
|
|
||||||
virtual const glm::vec3& GetTargetPos() { return target_pos_; };
|
|
||||||
virtual void SetTargetPos(const glm::vec3& target_pos);
|
|
||||||
virtual const a8::Vec2& GetAttackDir() { return attack_dir_; };
|
virtual const a8::Vec2& GetAttackDir() { return attack_dir_; };
|
||||||
virtual void SetAttackDir(const a8::Vec2& attack_dir);
|
virtual void SetAttackDir(const a8::Vec2& attack_dir);
|
||||||
virtual const a8::Vec2& GetShotDir() { return attack_dir_; };
|
virtual const a8::Vec2& GetShotDir() { return attack_dir_; };
|
||||||
int GetChgMoveDirTimes() { return chg_move_dir_times_; }
|
int GetChgMoveDirTimes() { return chg_move_dir_times_; }
|
||||||
int GetChgAttackDirTimes() { return chg_attack_dir_times_; }
|
int GetChgAttackDirTimes() { return chg_attack_dir_times_; }
|
||||||
float GetAttackDirRotate();
|
float GetAttackDirRotate();
|
||||||
int GetChgTargetPosTimes() { return chg_target_pos_times_; }
|
|
||||||
void CalcTargetPos(float distance);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
int updated_times_ = 0;
|
int updated_times_ = 0;
|
||||||
@ -44,10 +43,8 @@ protected:
|
|||||||
private:
|
private:
|
||||||
a8::Vec2 move_dir_;
|
a8::Vec2 move_dir_;
|
||||||
a8::Vec2 attack_dir_;
|
a8::Vec2 attack_dir_;
|
||||||
glm::vec3 last_pos_;
|
|
||||||
glm::vec3 target_pos_;
|
|
||||||
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;
|
||||||
int chg_target_pos_times_ = 0;
|
std::shared_ptr<MoveHelper> move_helper_;
|
||||||
};
|
};
|
||||||
|
45
server/gameserver/movehelper.cc
Normal file
45
server/gameserver/movehelper.cc
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
#include "precompile.h"
|
||||||
|
|
||||||
|
#include "movehelper.h"
|
||||||
|
#include "moveableentity.h"
|
||||||
|
|
||||||
|
MoveHelper::MoveHelper(class MoveableEntity* owner)
|
||||||
|
{
|
||||||
|
owner_ = owner;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MoveHelper::GetMovePosition(glm::vec3& out_pos)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MoveHelper::CalcTargetPos(float distance)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
void MoveableEntity::CalcTargetPos(float distance)
|
||||||
|
{
|
||||||
|
glm::vec3 start;
|
||||||
|
glm::vec3 end;
|
||||||
|
glm::vec3 hit_point;
|
||||||
|
|
||||||
|
start.x = GetPos().x / 10.0f;
|
||||||
|
start.z = GetPos().y / 10.0f;
|
||||||
|
|
||||||
|
a8::Vec2 target_pos2d = GetPos() + GetMoveDir() * distance;
|
||||||
|
end.x = target_pos2d.x / 10.0f;
|
||||||
|
end.z = target_pos2d.y / 10.0f;
|
||||||
|
|
||||||
|
last_pos_.x = GetPos().x;
|
||||||
|
last_pos_.z = GetPos().y;
|
||||||
|
|
||||||
|
int ret = room->map_instance->Raycast(0, start, end, hit_point);
|
||||||
|
if (ret > 1) {
|
||||||
|
SetTargetPos(hit_point * 10.0f);
|
||||||
|
} else {
|
||||||
|
SetTargetPos(end * 10.0f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
21
server/gameserver/movehelper.h
Normal file
21
server/gameserver/movehelper.h
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
struct MovePathPoint
|
||||||
|
{
|
||||||
|
glm::vec3 pos;
|
||||||
|
float distance = 0.0f;
|
||||||
|
};
|
||||||
|
|
||||||
|
class MoveHelper
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
MoveHelper(class MoveableEntity* owner);
|
||||||
|
|
||||||
|
bool GetMovePosition(glm::vec3& out_pos);
|
||||||
|
void CalcTargetPos(float distance);
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::vector<MovePathPoint> paths_;
|
||||||
|
int path_index_ = 0;
|
||||||
|
class MoveableEntity* owner_ = nullptr;
|
||||||
|
};
|
@ -786,9 +786,9 @@ void Player::_CMMove(f8::MsgHdr& hdr, const cs::CMMove& msg)
|
|||||||
if (std::fabs(new_move_dir.x - GetMoveDir().x) > 0.00001f ||
|
if (std::fabs(new_move_dir.x - GetMoveDir().x) > 0.00001f ||
|
||||||
std::fabs(new_move_dir.y - GetMoveDir().y) > 0.00001f) {
|
std::fabs(new_move_dir.y - GetMoveDir().y) > 0.00001f) {
|
||||||
SetMoveDir(new_move_dir);
|
SetMoveDir(new_move_dir);
|
||||||
CalcTargetPos(500);
|
GetMoveHelper()->CalcTargetPos(500);
|
||||||
moving = true;
|
|
||||||
}
|
}
|
||||||
|
moving = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user