This commit is contained in:
aozhiwei 2021-03-30 13:50:48 +08:00
parent d707b56f54
commit 97ad733576
4 changed files with 31 additions and 29 deletions

View File

@ -115,7 +115,7 @@ void AndroidNewAI::DefaultAi()
break;
case AS_attack:
{
if ((old_ai_data_.state_elapsed_time < 3000 && old_ai_data_.last_target) ||
if ((old_ai_data_.state_elapsed_time < 3000 && old_ai_data_.last_target.Get()) ||
(old_ai_data_.state_elapsed_time < 1100)) {
DoAttackOldAI();
} else {
@ -208,7 +208,7 @@ void AndroidNewAI::DoAttackOldAI()
sender->Shot(shot_dir, shot_ok);
}
}
old_ai_data_.last_target = enemy;
old_ai_data_.last_target.Attach(enemy);
}
}
@ -291,9 +291,10 @@ void AndroidNewAI::UpdateLastNpc()
void AndroidNewAI::UpdateNewBieRoomLogic()
{
Human* hum = (Human*)owner;
Human* old_last_target = old_ai_data_.last_target;
Human* target = old_ai_data_.last_target;
if ((old_ai_data_.last_target && old_ai_data_.last_target->real_dead) || !old_ai_data_.last_target) {
Creature* old_last_target = old_ai_data_.last_target.Get();
Creature* target = old_ai_data_.last_target.Get();
if ((old_ai_data_.last_target.Get() && old_ai_data_.last_target.Get()->real_dead) ||
!old_ai_data_.last_target.Get()) {
if (hum->last_human_target && !hum->last_human_target->dead) {
target = hum->last_human_target;
} else {
@ -337,7 +338,7 @@ void AndroidNewAI::UpdateNewBieRoomLogic()
});
}
}
old_ai_data_.last_target = target;
old_ai_data_.last_target.Attach(target);
}
if (!target) {
return;
@ -371,7 +372,7 @@ void AndroidNewAI::UpdateNewBieRoomLogic()
if (hum->GetPos().ManhattanDistance(target->GetPos()) > 650 &&
hum->room->GetFrameNo() - old_ai_data_.last_findenemy_frameno > SERVER_FRAME_RATE * 3) {
old_ai_data_.last_findenemy_frameno = hum->room->GetFrameNo();
old_ai_data_.last_target = nullptr;
old_ai_data_.last_target.Reset();
} else {
int speed = std::max(1, (int)hum->GetSpeed());
hum->move_dir = target->GetPos() - hum->GetPos();
@ -397,14 +398,14 @@ void AndroidNewAI::UpdateNewBieRoomLogic()
sender->Shot(shot_dir, shot_ok);
}
}
if (old_last_target && old_ai_data_.last_target && old_last_target == old_ai_data_.last_target) {
if (old_last_target && old_ai_data_.last_target.Get() && old_last_target == old_ai_data_.last_target.Get()) {
++old_ai_data_.series_attack_frames;
} else {
old_ai_data_.series_attack_frames = 0;
}
if (old_ai_data_.series_attack_frames > SERVER_FRAME_RATE * 10 &&
old_ai_data_.last_target && old_ai_data_.last_target->IsAndroid()) {
old_ai_data_.last_target = nullptr;
old_ai_data_.last_target.Get() && old_ai_data_.last_target.Get()->IsAndroid()) {
old_ai_data_.last_target.Reset();
}
}
}
@ -483,7 +484,7 @@ void AndroidNewAI::UpdateThinking()
} else {
Human* target = GetTarget();
if (target) {
node_.target = target;
node_.target.Attach(target);
ChangeToStateNewAI(ASE_Attack);
} else {
if (hum->room->GetFrameNo() >= node_.next_random_move_frameno) {
@ -503,7 +504,7 @@ void AndroidNewAI::UpdateThinking()
void AndroidNewAI::UpdateAttack()
{
Human* myself = (Human*)owner;
if (!node_.target || node_.target->dead) {
if (!node_.target.Get() || node_.target.Get()->dead) {
ChangeToStateNewAI(ASE_Thinking);
return;
}
@ -511,7 +512,7 @@ void AndroidNewAI::UpdateAttack()
ChangeToStateNewAI(ASE_Thinking);
return;
}
float distance = myself->GetPos().Distance(node_.target->GetPos());
float distance = myself->GetPos().Distance(node_.target.Get()->GetPos());
if (distance > GetAttackRange()) {
if (ai_meta->i->pursuit_radius() <= 0) {
//站桩
@ -569,7 +570,7 @@ void AndroidNewAI::UpdateRandomWalk()
void AndroidNewAI::UpdatePursuit()
{
Human* myself = (Human*)owner;
float distance = myself->GetPos().Distance(node_.target->GetPos());
float distance = myself->GetPos().Distance(node_.target.Get()->GetPos());
if (!myself->HasBuffEffect(kBET_Jump) &&
!a8::HasBitFlag(myself->status, HS_DisableAttack) &&
distance < GetAttackRange()) {
@ -594,11 +595,11 @@ void AndroidNewAI::DoMoveNewAI()
int speed = std::max(1, (int)hum->GetSpeed()) * 1;
hum->_UpdateMove(speed);
hum->on_move_collision = nullptr;
if (node_.nearest_human) {
if (node_.nearest_human.Get()) {
if (node_.main_state != ASE_Pursuit &&
hum->GetPos().ManhattanDistance(node_.nearest_human->GetPos()) < 200) {
hum->GetPos().ManhattanDistance(node_.nearest_human.Get()->GetPos()) < 200) {
ChangeToStateNewAI(ASE_Thinking);
} else if (hum->GetPos().ManhattanDistance(node_.nearest_human->GetPos()) > 800) {
} else if (hum->GetPos().ManhattanDistance(node_.nearest_human.Get()->GetPos()) > 800) {
GetTarget();
}
}
@ -611,7 +612,7 @@ void AndroidNewAI::ChangeToStateNewAI(AndroidStateEx_e to_state)
switch (to_state) {
case ASE_Idle:
{
node_.target = nullptr;
node_.target.Reset();
node_.param1 = 0;
node_.start_shot_frameno = 0;
node_.shot_times = 0;
@ -627,7 +628,7 @@ void AndroidNewAI::ChangeToStateNewAI(AndroidStateEx_e to_state)
break;
case ASE_Thinking:
{
node_.target = nullptr;
node_.target.Reset();
node_.param1 = 0;
node_.start_shot_frameno = 0;
node_.shot_times = 0;
@ -646,7 +647,7 @@ void AndroidNewAI::ChangeToStateNewAI(AndroidStateEx_e to_state)
case ASE_RandomWalk:
{
moving_ = true;
node_.target = nullptr;
node_.target.Reset();
#if 1
node_.param1 = SERVER_FRAME_RATE * ai_meta->GetMoveTime();
#else
@ -668,8 +669,8 @@ void AndroidNewAI::ChangeToStateNewAI(AndroidStateEx_e to_state)
case ASE_Pursuit:
{
moving_ = true;
if (node_.target) {
hum->move_dir = node_.target->GetPos() - hum->GetPos();
if (node_.target.Get()) {
hum->move_dir = node_.target.Get()->GetPos() - hum->GetPos();
hum->move_dir.Normalize();
hum->attack_dir = hum->move_dir;
}
@ -715,7 +716,7 @@ Human* AndroidNewAI::GetTarget()
}
});
if (target) {
node_.nearest_human = target;
node_.nearest_human.Attach(target);
node_.last_check_nearest_human_frameno = myself->room->GetFrameNo();
float distance = myself->GetPos().Distance(target->GetPos());
if (distance > GetAttackRange()) {
@ -739,14 +740,14 @@ float AndroidNewAI::GetAttackRange()
void AndroidNewAI::DoShotNewAI()
{
Human* myself = (Human*)owner;
if (!node_.target) {
if (!node_.target.Get()) {
return;
}
bool shot_ok = false;
a8::Vec2 shot_dir = myself->attack_dir;
if (node_.total_shot_times >= node_.next_total_shot_times) {
shot_dir = node_.target->GetPos() - myself->GetPos();
shot_dir = node_.target.Get()->GetPos() - myself->GetPos();
node_.next_total_shot_times += 7 + (rand() % 6);
myself->attack_dir = shot_dir;
}

View File

@ -1,6 +1,7 @@
#pragma once
#include "aicomponent.h"
#include "weakptr.h"
enum AndroidState_e
{
@ -32,8 +33,8 @@ public:
int next_total_shot_times = 0;
long long param1 = 0;
Human* target = nullptr;
Human* nearest_human = nullptr;
CreatureWeakPtr target;
CreatureWeakPtr nearest_human;
long long last_check_nearest_human_frameno = 0;
a8::Vec2 shot_dir;
};
@ -42,7 +43,7 @@ struct OldAiData
{
AndroidState_e state = AS_thinking;
int state_elapsed_time = 0;
Human* last_target = nullptr;
CreatureWeakPtr last_target;
long long last_attack_frameno = 0;
long long last_findenemy_frameno = 0;
long long series_attack_frames = 0;

View File

@ -21,6 +21,7 @@ class Creature : public MoveableEntity
int status = 0;
bool dead = false;
bool real_dead = false;
int team_id = 0;
bool aiming = false;
a8::Vec2 attack_dir;

View File

@ -87,7 +87,6 @@ class Human : public Creature
int emoji2 = 0;
int parachute = 0;
bool has_pass = 0;
bool real_dead = false;
xtimer_list* revive_timer = nullptr;
int dead_times = 0;
long long dead_frameno = 0;