This commit is contained in:
aozhiwei 2022-08-31 12:28:32 +08:00
parent ce7c06d841
commit 435fef7a89
2 changed files with 23 additions and 2 deletions

View File

@ -282,10 +282,21 @@ void HeroAI::DoMoveAI()
}
return false;
};
if (owner->room->IsPveRoom()) {
}
int speed = std::max(1, (int)hero->GetSpeed()) * 1;
a8::Vec2 old_pos = hero->GetPos();
hero->_UpdateMove(speed);
if (owner->room->IsPveRoom() && IsNearGas()) {
#if 1
hero->SetPos(old_pos);
hero->on_move_collision();
#else
//if (hero->room->GetFrameNo() - node_->last_adjust_dir_frameno > SERVER_FRAME_RATE * 3) {
a8::Vec2 dir = hero->GetPos() - hero->room->GetGasData().pos_new;
hero->SetMoveDir(dir);
node_->last_adjust_dir_frameno = hero->room->GetFrameNo();
//}
#endif
}
hero->on_move_collision = old_on_move_collision_func;
}
}
@ -613,3 +624,10 @@ void HeroAI::ForceRandomWalk(int time, int idle_time)
node_->next_random_move_frameno = myself->room->GetFrameNo() +
idle_time / FRAME_RATE_MS;
}
bool HeroAI::IsNearGas()
{
Hero* hero = (Hero*)owner;
float distance = hero->GetPos().Distance(hero->room->GetGasData().pos_new);
return distance + hero->GetRadius() * 2 + 20 > hero->room->GetGasData().rad_new;
}

View File

@ -36,6 +36,8 @@ public:
a8::Vec2 target_pos;
RoomObstacleWeakPtr target_obstacle;
long long last_collision_times = 0;
long long last_adjust_dir_frameno = 0;
};
class HeroAI : public AIComponent
@ -66,6 +68,7 @@ protected:
float GetAttackRange();
float GetShotRange();
int GetAttackTimes();
bool IsNearGas();
protected:
HeroAINode* node_ = nullptr;