This commit is contained in:
aozhiwei 2020-07-15 14:57:16 +08:00
parent 0445d18b2d
commit af72a55260
3 changed files with 17 additions and 17 deletions

View File

@ -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) {

View File

@ -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;
}

View File

@ -54,6 +54,7 @@ class Human : public MoveableEntity
a8::Vec2 move_dir;
a8::Vec2 attack_dir;
std::function<void ()> on_loading_bullet;
std::function<bool ()> on_move_collision;
std::string name;
std::string avatar_url;