This commit is contained in:
aozhiwei 2020-07-15 14:33:32 +08:00
parent a941fa538c
commit 0445d18b2d
2 changed files with 15 additions and 4 deletions

View File

@ -482,7 +482,7 @@ void AndroidNewAI::UpdateThinking()
void AndroidNewAI::UpdateAttack()
{
Human* myself = (Human*)owner;
if (node_.target->dead) {
if (!node_.target || node_.target->dead) {
ChangeToStateNewAI(ASE_Thinking);
return;
}
@ -490,7 +490,7 @@ void AndroidNewAI::UpdateAttack()
if (distance > GetAttackRange()) {
if (ai_meta->i->pursuit_radius() <= 0) {
//站桩
ChangeToStateNewAI(ASE_Idle);
ChangeToStateNewAI(ASE_Thinking);
} else {
if (distance < ai_meta->i->pursuit_radius()) {
//追击
@ -589,6 +589,7 @@ void AndroidNewAI::ChangeToStateNewAI(AndroidStateEx_e to_state)
switch (to_state) {
case ASE_Idle:
{
node_.target = nullptr;
node_.param1 = 0;
node_.start_shot_frameno = 0;
node_.shot_times = 0;
@ -603,6 +604,7 @@ void AndroidNewAI::ChangeToStateNewAI(AndroidStateEx_e to_state)
break;
case ASE_Thinking:
{
node_.target = nullptr;
node_.param1 = 0;
node_.start_shot_frameno = 0;
node_.shot_times = 0;
@ -621,6 +623,7 @@ void AndroidNewAI::ChangeToStateNewAI(AndroidStateEx_e to_state)
case ASE_RandomWalk:
{
moving_ = true;
node_.target = nullptr;
node_.param1 = SERVER_FRAME_RATE * 2 + rand() % (SERVER_FRAME_RATE * 3);
node_.start_shot_frameno = 0;
node_.shot_times = 0;
@ -679,6 +682,12 @@ Human* AndroidNewAI::GetTarget()
target = hum;
}
});
if (target) {
float distance = myself->GetPos().Distance(target->GetPos());
if (distance > GetAttackRange()) {
target = nullptr;
}
}
return target;
}

View File

@ -2912,9 +2912,11 @@ void Room::InitAndroidAI()
}
}
for (Android* hum : androids) {
#if 1
hum->SetAiLevel(5);
#ifdef DEBUG
#if 0
hum->SetAiLevel(2);
continue;
#endif
#endif
if (IsMiniRoom()) {
int rnd = rand() % MetaMgr::Instance()->mini_room_ai_weights_space;