diff --git a/server/gameserver/android_new.ai.cc b/server/gameserver/android_new.ai.cc index 9998e20..535eb38 100644 --- a/server/gameserver/android_new.ai.cc +++ b/server/gameserver/android_new.ai.cc @@ -561,24 +561,14 @@ void AndroidNewAI::DoMoveNewAI() if (hum->UpdatedTimes() % 2 == 0) { if (std::abs(hum->move_dir.x) > FLT_EPSILON || std::abs(hum->move_dir.y) > FLT_EPSILON) { - #if 1 + hum->on_move_collision = + [this] () { + ChangeToStateNewAI(ASE_RandomWalk); + return false; + }; int speed = std::max(1, (int)hum->GetSpeed()); hum->_UpdateMove(speed); - #else - int speed = std::max(1, (int)hum->GetSpeed()); - for (int i = 0; i < speed; ++i) { - a8::Vec2 old_pos = hum->GetPos(); - hum->SetPos(hum->GetPos() + hum->move_dir); - if (hum->IsCollisionInMapService()) { - hum->SetPos(old_pos); - if (i == 0) { - hum->FindPathInMapService(); - } - break; - } - hum->room->grid_service->MoveHuman(hum); - } - #endif + hum->on_move_collision = nullptr; } } } @@ -624,7 +614,7 @@ void AndroidNewAI::ChangeToStateNewAI(AndroidStateEx_e to_state) { moving_ = true; node_.target = nullptr; - node_.param1 = SERVER_FRAME_RATE * 2 + rand() % (SERVER_FRAME_RATE * 3); + node_.param1 = SERVER_FRAME_RATE * 5 + rand() % (SERVER_FRAME_RATE * 3); node_.start_shot_frameno = 0; node_.shot_times = 0; hum->move_dir = a8::Vec2(1.0f, 0); @@ -714,6 +704,7 @@ void AndroidNewAI::DoShotNewAI() if (node_.total_shot_times >= node_.next_total_shot_times) { shot_dir = node_.target->GetPos() - myself->GetPos(); node_.next_total_shot_times += 7 + (rand() % 6); + myself->attack_dir = shot_dir; } if (std::abs(shot_dir.x) > FLT_EPSILON || std::abs(shot_dir.y) > FLT_EPSILON) { diff --git a/server/gameserver/human.cc b/server/gameserver/human.cc index 7046936..6aba8b3 100644 --- a/server/gameserver/human.cc +++ b/server/gameserver/human.cc @@ -1832,11 +1832,19 @@ void Human::_InternalUpdateMove(float speed) SetPos(old_pos + a8::Vec2(nx, 0)); if (IsCollisionInMapService()) { + if (on_move_collision && !on_move_collision()) { + SetPos(old_pos); + return; + } nx = 0; } SetPos(old_pos + a8::Vec2(nx, ny)); if (IsCollisionInMapService()) { + if (on_move_collision && !on_move_collision()) { + SetPos(old_pos); + return; + } ny = 0; } diff --git a/server/gameserver/human.h b/server/gameserver/human.h index 35992ee..b4f7b7a 100644 --- a/server/gameserver/human.h +++ b/server/gameserver/human.h @@ -54,6 +54,7 @@ class Human : public MoveableEntity a8::Vec2 move_dir; a8::Vec2 attack_dir; std::function on_loading_bullet; + std::function on_move_collision; std::string name; std::string avatar_url;