This commit is contained in:
aozhiwei 2022-11-30 10:34:24 +08:00
parent 0fe9e2c114
commit 0d6d0cfac4
7 changed files with 50 additions and 21 deletions

View File

@ -2014,6 +2014,15 @@ void Human::_UpdateMove(int speed)
if (GetDisableMoveTimes() > 0) {
return;
}
#ifdef MAP3D
{
if (HasBuffEffect(kBET_Hide)) {
RemoveBuffByEffectId(kBET_Hide);
}
CheckSpecObject();
}
#else
{
a8::UnSetBitFlag(status, CS_Collisioning);
do {
@ -2023,19 +2032,11 @@ void Human::_UpdateMove(int speed)
} while (speed > 0 && !a8::HasBitFlag(status, CS_Collisioning));
CheckSpecObject();
}
#endif
}
void Human::_InternalUpdateMove(float speed)
{
#ifdef MAP3D
a8::Vec2 old_pos = GetPos();
if (HasBuffEffect(kBET_Hide)) {
RemoveBuffByEffectId(kBET_Hide);
}
room->grid_service->MoveCreature(this);
#else
float nx = GetMoveDir().x * speed;
float ny = GetMoveDir().y * speed;
a8::Vec2 old_pos = GetPos();
@ -2107,7 +2108,6 @@ void Human::_InternalUpdateMove(float speed)
SetPos(old_pos + a8::Vec2(nx, ny));
room->grid_service->MoveCreature(this);
#endif
}
void Human::GenBattleReportData(a8::MutableXObject* params)

View File

@ -158,9 +158,9 @@ void MapInstance::Init()
dtTileRef tile_ref = navmesh_->getTileRefAt(0, 0, 0);
int i = 0;
a8::Vec3 start;
a8::Vec3 end;
a8::Vec3 hit_point;
glm::vec3 start;
glm::vec3 end;
glm::vec3 hit_point;
start.x = 10;
//start.y = 0.166666701;
start.y = 0.0;
@ -664,7 +664,7 @@ int MapInstance::FindRandomPointAroundCircle(int layer,
return 0;
}
int MapInstance::Raycast(int layer, const a8::Vec3& start, const a8::Vec3& end, a8::Vec3& hit_point)
int MapInstance::Raycast(int layer, const glm::vec3& start, const glm::vec3& end, glm::vec3& hit_point)
{
float hitPoint[3];

View File

@ -49,7 +49,7 @@ class MapInstance
std::vector<a8::Vec3>& points,
unsigned int max_points,
float max_radius);
int Raycast(int layer, const a8::Vec3& start, const a8::Vec3& end, a8::Vec3& hit_point);
int Raycast(int layer, const glm::vec3& start, const glm::vec3& end, glm::vec3& hit_point);
bool FindNearestPoint(const a8::Vec3& center, float radius, a8::Vec3& nearestPt);
private:

View File

@ -1,7 +1,9 @@
#include "precompile.h"
#include "moveableentity.h"
#include "room.h"
#include "human.h"
#include "mapinstance.h"
void MoveableEntity::TraverseAllLayerEntityList(std::function<void (Entity*, bool&)> func)
{
@ -90,7 +92,7 @@ void MoveableEntity::SetMoveDir(const a8::Vec2& move_dir)
++chg_move_dir_times_;
}
void MoveableEntity::SetTargetPos(const a8::Vec3& target_pos)
void MoveableEntity::SetTargetPos(const glm::vec3& target_pos)
{
target_pos_ = target_pos;
++chg_target_pos_times_;
@ -123,3 +125,22 @@ float MoveableEntity::GetAttackDirRotate()
}
return angle;
}
void MoveableEntity::CalcTargetPos(float distance)
{
glm::vec3 start;
glm::vec3 end;
glm::vec3 hit_point;
start.x = GetPos().x / 10;
start.z = GetPos().y / 10;
a8::Vec2 target_pos2d = GetPos() + GetMoveDir() * distance;
end.x = target_pos2d.x / 10;
end.z = target_pos2d.y / 10;
int ret = room->map_instance->Raycast(0, start, end, hit_point);
if (ret > 1) {
} else {
}
}

View File

@ -26,8 +26,8 @@ class MoveableEntity : public RoomEntity
virtual void UpdateCharImage(const char* file, int line, const char* func);
virtual const a8::Vec2& GetMoveDir() { return move_dir_; };
virtual void SetMoveDir(const a8::Vec2& move_dir);
virtual const a8::Vec3& GetTargetPos() { return target_pos_; };
virtual void SetTargetPos(const a8::Vec3& target_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 void SetAttackDir(const a8::Vec2& attack_dir);
virtual const a8::Vec2& GetShotDir() { return attack_dir_; };
@ -35,6 +35,7 @@ class MoveableEntity : public RoomEntity
int GetChgAttackDirTimes() { return chg_attack_dir_times_; }
float GetAttackDirRotate();
int GetChgTargetPosTimes() { return chg_target_pos_times_; }
void CalcTargetPos(float distance);
protected:
int updated_times_ = 0;
@ -42,7 +43,7 @@ protected:
private:
a8::Vec2 move_dir_;
a8::Vec2 attack_dir_;
a8::Vec3 target_pos_;
glm::vec3 target_pos_;
std::set<GridCell*> grid_list_;
int chg_move_dir_times_ = 0;
int chg_attack_dir_times_ = 0;

View File

@ -783,13 +783,17 @@ void Player::_CMMove(f8::MsgHdr& hdr, const cs::CMMove& msg)
if (!(HasBuffEffect(kBET_Jump) && follow_target.Get())) {
if (GetDisableMoveDirTimes() <= 0) {
new_move_dir.Normalize();
if (std::fabs(new_move_dir.x - GetMoveDir().x) > 0.00001f ||
std::fabs(new_move_dir.y - GetMoveDir().y) > 0.00001f) {
SetMoveDir(new_move_dir);
CalcTargetPos(500);
moving = true;
}
}
}
}
}
}
assert(!isnan(GetMoveDir().x) && !isnan(GetMoveDir().y));
if (msg.has_attack_dir()) {
if (std::isfinite(msg.attack_dir().x()) &&

View File

@ -10,6 +10,9 @@
#include <a8/vec2.h>
#include <a8/vec3.h>
#include <glm/vec2.hpp>
#include <glm/vec3.hpp>
typedef std::function<void(const std::vector<std::any>&)> CommonCbProc;
#include "constant.h"