This commit is contained in:
aozhiwei 2022-12-28 09:59:38 +08:00
parent 54ee60278b
commit e711cf7da6
8 changed files with 10 additions and 230 deletions

View File

@ -94,9 +94,8 @@ void Android::InternalUpdate(int delta_time)
}
if (GetMoveHelper()->GetPathSize() > 0) {
Global::Instance()->verify_set_pos = 1;
int speed = std::max(1, (int)GetSpeed()) * 1;
Position old_pos = GetPos();
_UpdateMove(speed);
UpdateMove();
#ifdef DEBUG1
a8::XPrintf("updatemove old_pos:%f,%f new_pos:%f,%f\n",
{

View File

@ -3183,7 +3183,7 @@ void Creature::_UpdateSpecMove()
GlmHelper::Normalize(move_dir);
SetMoveDir(move_dir);
bool is_collision = false;
_UpdateMove(std::min((int)target_distance, (int)GetSpeed()));
UpdateMove();
move_dir = old_move_dir;
target_distance = target_pos.Distance2D2(GetPos());
if (is_collision || target_distance <= 1.0001f) {

View File

@ -217,7 +217,7 @@ class Creature : public MoveableEntity
void AddInventory(int slot_id, int num);
void DecInventory(int slot_id, int num);
std::array<Inventory, IS_END>& GetInventoryData() { return inventory_; };
virtual void _UpdateMove(int speed) {};
virtual void UpdateMove() {};
virtual void ForwardMove(float distance) {};
bool HasSpecMove();
void _UpdateSpecMove();

View File

@ -140,28 +140,15 @@ float Hero::GetSpeed()
return speed;
}
void Hero::_UpdateMove(int speed)
void Hero::UpdateMove()
{
#if 0
do {
int distance = std::min(5, speed);
InternalUpdateMove(distance);
speed -= distance;
} while (speed > 0);
}
void Hero::InternalUpdateMove(float speed)
{
Position old_pos = GetPos();
GetMutablePos().AddGlmVec3(GetMoveDir() * speed);
if (!CheckCollision()) {
room->grid_service->MoveCreature(this);
} else {
#if 0
if (on_move_collision && !on_move_collision()) {
SetPos(old_pos);
}
#endif
}
#endif
}
void Hero::RecalcSelfCollider()

View File

@ -41,8 +41,7 @@ public:
void BeKill(int killer_id, const std::string& killer_name, int weapon_id);
protected:
virtual void _UpdateMove(int speed) override;
void InternalUpdateMove(float speed);
virtual void UpdateMove() override;
virtual void RecalcSelfCollider() override;
void InitAI();
void DetachFromMaster();

View File

@ -583,97 +583,6 @@ void Human::RecalcSelfCollider()
}
}
void Human::FindPathInMapService()
{
Position old_pos = GetPos();
ColliderComponent* last_collider = Global::last_collider;
if (last_collider) {
switch (last_collider->type) {
case CT_Aabb:
{
}
break;
case CT_Circle:
{
a8::Vec2 extend_dir = last_collider->owner->GetPos().CalcDir2D(GetPos());
if (std::abs(extend_dir.x) > FLT_EPSILON ||
std::abs(extend_dir.y) > FLT_EPSILON) {
extend_dir.Normalize();
{
#if 0
a8::Vec2 extend_dir_inverse(extend_dir.y, extend_dir.x);
float angle = extend_dir_inverse.CalcAngle(move_dir);
if (angle > 0.001f) {
extend_dir.Rotate(-1/180.0f);
} else {
extend_dir.Rotate(1/180.0f);
}
#endif
extend_dir.Rotate(1/180.0f);
}
float distance = ((CircleCollider*)last_collider)->rad + meta->radius();
// 999
#if 1
#else
SetPos(last_collider->owner->GetPos() + extend_dir * (distance + 1));
#endif
if (CheckCollision()) {
SetPos(old_pos);
}
}
return;
}
break;
default:
break;
}
}
// 999
#if 1
#else
{
float up_dot = a8::Vec2::UP.Dot(GetMoveDir());
bool at_left_side = a8::Vec2::LEFT.Dot(GetMoveDir()) > 0.0001f;
if (std::abs(up_dot) <= 0.001f) { //相互垂直
//向上
SetPos(old_pos + a8::Vec2::UP);
if (!CheckCollision()) {
return;
} else {
//向下
SetPos(old_pos + a8::Vec2::DOWN);
if (!CheckCollision()) {
return;
}
}
} else if (up_dot > 0.001f) { //基本相同
SetPos(old_pos + (at_left_side ? a8::Vec2::LEFT : a8::Vec2::RIGHT));
if (!CheckCollision()) {
return;
} else {
//向上
SetPos(old_pos + a8::Vec2::UP);
if (!CheckCollision()) {
return;
}
}
} else if (up_dot < 0.001f) { //基本相反
SetPos(old_pos + (at_left_side ? a8::Vec2::LEFT : a8::Vec2::RIGHT));
if (!CheckCollision()) {
return;
} else {
//向下
SetPos(old_pos + a8::Vec2::DOWN);
if (!CheckCollision()) {
return;
}
}
}
}
#endif
SetPos(old_pos);
}
void Human::BeKill(int killer_id, const std::string& killer_name, int weapon_id,
int real_killer_id, const std::string& real_killer_name)
{
@ -1286,7 +1195,7 @@ void Human::UpdateAction()
}
}
void Human::_UpdateMove(int speed)
void Human::UpdateMove()
{
if (HasBuffEffect(kBET_Vertigo)) {
if (!HasBuffEffect(kBET_Recoil)) {
@ -1318,114 +1227,6 @@ void Human::_UpdateMove(int speed)
}
}
void Human::_InternalUpdateMove(float speed)
{
float nx = GetMoveDir().x * speed;
float ny = GetMoveDir().y * speed;
Position old_pos = GetPos();
if (HasBuffEffect(kBET_ReverseMove)) {
nx = -nx;
ny = -ny;
}
if (HasBuffEffect(kBET_Hide)) {
RemoveBuffByEffectId(kBET_Hide);
}
// 999
#if 1
#else
SetPos(old_pos + a8::Vec2(nx, ny));
#endif
if (!CheckCollision()) {
room->grid_service->MoveCreature(this);
return;
} else {
if (HasBuffEffect(kBET_Sprint)) {
SetPos(old_pos);
RemoveBuffByEffectId(kBET_Sprint);
return;
}
if (Global::last_collider && Global::last_collider->type == CT_Circle) {
// 999
#if 1
#else
SetPos(old_pos + a8::Vec2(nx, ny));
#endif
if (self_collider_->Intersect(Global::last_collider)) {
// 999
#if 1
#else
CircleCollider* circle_collider = (CircleCollider*)Global::last_collider;
a8::Vec2 tmp_dir = GetPos() - (circle_collider->owner->GetPos() + circle_collider->pos);
float len = circle_collider->rad + self_collider_->rad + 1;
float rate = len - tmp_dir.Norm();
tmp_dir.Normalize();
a8::Vec2 new_dir = tmp_dir * rate;
SetPos(GetPos() + new_dir);
#endif
}
if (!CheckCollision()) {
room->grid_service->MoveCreature(this);
return;
}
}
}
#if 0
if (a8::HasBitFlag(status, CS_Collisioning)) {
SetPos(old_pos);
return;
}
#endif
// 999
#if 1
#else
SetPos(old_pos + a8::Vec2(nx, 0));
#endif
#if 0
if (CheckCollision()) {
if (a8::HasBitFlag(status, CS_Collisioning)) {
SetPos(old_pos);
return;
}
#if 0
if (on_move_collision && !on_move_collision()) {
SetPos(old_pos);
return;
}
#endif
nx = 0;
}
#endif
// 999
#if 1
#else
SetPos(old_pos + a8::Vec2(nx, ny));
#endif
#if 0
if (CheckCollision()) {
if (a8::HasBitFlag(status, CS_Collisioning)) {
SetPos(old_pos);
return;
}
#if 0
if (on_move_collision && !on_move_collision()) {
SetPos(old_pos);
return;
}
#endif
ny = 0;
}
#endif
// 999
#if 1
#else
SetPos(old_pos + a8::Vec2(nx, ny));
#endif
room->grid_service->MoveCreature(this);
}
void Human::GenBattleReportData(a8::MutableXObject* params)
{
params->SetVal("room_mode", room->GetRoomMode());

View File

@ -298,7 +298,6 @@ class Human : public Creature
void FillMFTeamData(Human* hum, cs::MFTeamData* team_data, bool is_game_over);
void CarShot(const glm::vec3& target_dir);
virtual void RecalcSelfCollider() override;
void FindPathInMapService();
void BeKill(int killer_id, const std::string& killer_name, int weapon_id,
int real_killer_id, const std::string& real_killer_name);
virtual void DecHP(float dec_hp, int killer_id, const std::string& killer_name, int weapon_id,
@ -369,7 +368,7 @@ class Human : public Creature
virtual void DropItems(Obstacle* obstacle) override;
void OnEnable();
void OnDisable();
virtual void _UpdateMove(int speed) override;
virtual void UpdateMove() override;
Car* GetCar() { return car_; }
void SetCar(Car* car) { car_ = car; }
int GetSeat() { return seat_; }
@ -394,7 +393,6 @@ class Human : public Creature
void CalcAssists(Human* target);
protected:
void _InternalUpdateMove(float speed);
void ProcLootWeapon(AddItemDTO& dto);
void ProcLootSkin(AddItemDTO& dto);
void ProcLootCar(AddItemDTO& dto);

View File

@ -262,11 +262,7 @@ void Player::UpdateMove()
}
Position old_pos = GetPos();
Global::Instance()->verify_set_pos = 1;
if (GetCar() && GetCar()->IsDriver(this)) {
_UpdateMove(std::max(1, (int)GetCar()->GetSpeed()));
} else {
_UpdateMove(std::max(1, (int)GetSpeed()));
}
UpdateMove();
Global::Instance()->verify_set_pos = 0;
if (GetCar() && GetCar()->IsDriver(this)) {
GetCar()->SyncPos();