1
This commit is contained in:
parent
d707b56f54
commit
97ad733576
@ -115,7 +115,7 @@ void AndroidNewAI::DefaultAi()
|
|||||||
break;
|
break;
|
||||||
case AS_attack:
|
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)) {
|
(old_ai_data_.state_elapsed_time < 1100)) {
|
||||||
DoAttackOldAI();
|
DoAttackOldAI();
|
||||||
} else {
|
} else {
|
||||||
@ -208,7 +208,7 @@ void AndroidNewAI::DoAttackOldAI()
|
|||||||
sender->Shot(shot_dir, shot_ok);
|
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()
|
void AndroidNewAI::UpdateNewBieRoomLogic()
|
||||||
{
|
{
|
||||||
Human* hum = (Human*)owner;
|
Human* hum = (Human*)owner;
|
||||||
Human* old_last_target = old_ai_data_.last_target;
|
Creature* old_last_target = old_ai_data_.last_target.Get();
|
||||||
Human* target = old_ai_data_.last_target;
|
Creature* target = old_ai_data_.last_target.Get();
|
||||||
if ((old_ai_data_.last_target && old_ai_data_.last_target->real_dead) || !old_ai_data_.last_target) {
|
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) {
|
if (hum->last_human_target && !hum->last_human_target->dead) {
|
||||||
target = hum->last_human_target;
|
target = hum->last_human_target;
|
||||||
} else {
|
} else {
|
||||||
@ -337,7 +338,7 @@ void AndroidNewAI::UpdateNewBieRoomLogic()
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
old_ai_data_.last_target = target;
|
old_ai_data_.last_target.Attach(target);
|
||||||
}
|
}
|
||||||
if (!target) {
|
if (!target) {
|
||||||
return;
|
return;
|
||||||
@ -371,7 +372,7 @@ void AndroidNewAI::UpdateNewBieRoomLogic()
|
|||||||
if (hum->GetPos().ManhattanDistance(target->GetPos()) > 650 &&
|
if (hum->GetPos().ManhattanDistance(target->GetPos()) > 650 &&
|
||||||
hum->room->GetFrameNo() - old_ai_data_.last_findenemy_frameno > SERVER_FRAME_RATE * 3) {
|
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_findenemy_frameno = hum->room->GetFrameNo();
|
||||||
old_ai_data_.last_target = nullptr;
|
old_ai_data_.last_target.Reset();
|
||||||
} else {
|
} else {
|
||||||
int speed = std::max(1, (int)hum->GetSpeed());
|
int speed = std::max(1, (int)hum->GetSpeed());
|
||||||
hum->move_dir = target->GetPos() - hum->GetPos();
|
hum->move_dir = target->GetPos() - hum->GetPos();
|
||||||
@ -397,14 +398,14 @@ void AndroidNewAI::UpdateNewBieRoomLogic()
|
|||||||
sender->Shot(shot_dir, shot_ok);
|
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;
|
++old_ai_data_.series_attack_frames;
|
||||||
} else {
|
} else {
|
||||||
old_ai_data_.series_attack_frames = 0;
|
old_ai_data_.series_attack_frames = 0;
|
||||||
}
|
}
|
||||||
if (old_ai_data_.series_attack_frames > SERVER_FRAME_RATE * 10 &&
|
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.Get() && old_ai_data_.last_target.Get()->IsAndroid()) {
|
||||||
old_ai_data_.last_target = nullptr;
|
old_ai_data_.last_target.Reset();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -483,7 +484,7 @@ void AndroidNewAI::UpdateThinking()
|
|||||||
} else {
|
} else {
|
||||||
Human* target = GetTarget();
|
Human* target = GetTarget();
|
||||||
if (target) {
|
if (target) {
|
||||||
node_.target = target;
|
node_.target.Attach(target);
|
||||||
ChangeToStateNewAI(ASE_Attack);
|
ChangeToStateNewAI(ASE_Attack);
|
||||||
} else {
|
} else {
|
||||||
if (hum->room->GetFrameNo() >= node_.next_random_move_frameno) {
|
if (hum->room->GetFrameNo() >= node_.next_random_move_frameno) {
|
||||||
@ -503,7 +504,7 @@ void AndroidNewAI::UpdateThinking()
|
|||||||
void AndroidNewAI::UpdateAttack()
|
void AndroidNewAI::UpdateAttack()
|
||||||
{
|
{
|
||||||
Human* myself = (Human*)owner;
|
Human* myself = (Human*)owner;
|
||||||
if (!node_.target || node_.target->dead) {
|
if (!node_.target.Get() || node_.target.Get()->dead) {
|
||||||
ChangeToStateNewAI(ASE_Thinking);
|
ChangeToStateNewAI(ASE_Thinking);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -511,7 +512,7 @@ void AndroidNewAI::UpdateAttack()
|
|||||||
ChangeToStateNewAI(ASE_Thinking);
|
ChangeToStateNewAI(ASE_Thinking);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
float distance = myself->GetPos().Distance(node_.target->GetPos());
|
float distance = myself->GetPos().Distance(node_.target.Get()->GetPos());
|
||||||
if (distance > GetAttackRange()) {
|
if (distance > GetAttackRange()) {
|
||||||
if (ai_meta->i->pursuit_radius() <= 0) {
|
if (ai_meta->i->pursuit_radius() <= 0) {
|
||||||
//站桩
|
//站桩
|
||||||
@ -569,7 +570,7 @@ void AndroidNewAI::UpdateRandomWalk()
|
|||||||
void AndroidNewAI::UpdatePursuit()
|
void AndroidNewAI::UpdatePursuit()
|
||||||
{
|
{
|
||||||
Human* myself = (Human*)owner;
|
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) &&
|
if (!myself->HasBuffEffect(kBET_Jump) &&
|
||||||
!a8::HasBitFlag(myself->status, HS_DisableAttack) &&
|
!a8::HasBitFlag(myself->status, HS_DisableAttack) &&
|
||||||
distance < GetAttackRange()) {
|
distance < GetAttackRange()) {
|
||||||
@ -594,11 +595,11 @@ void AndroidNewAI::DoMoveNewAI()
|
|||||||
int speed = std::max(1, (int)hum->GetSpeed()) * 1;
|
int speed = std::max(1, (int)hum->GetSpeed()) * 1;
|
||||||
hum->_UpdateMove(speed);
|
hum->_UpdateMove(speed);
|
||||||
hum->on_move_collision = nullptr;
|
hum->on_move_collision = nullptr;
|
||||||
if (node_.nearest_human) {
|
if (node_.nearest_human.Get()) {
|
||||||
if (node_.main_state != ASE_Pursuit &&
|
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);
|
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();
|
GetTarget();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -611,7 +612,7 @@ void AndroidNewAI::ChangeToStateNewAI(AndroidStateEx_e to_state)
|
|||||||
switch (to_state) {
|
switch (to_state) {
|
||||||
case ASE_Idle:
|
case ASE_Idle:
|
||||||
{
|
{
|
||||||
node_.target = nullptr;
|
node_.target.Reset();
|
||||||
node_.param1 = 0;
|
node_.param1 = 0;
|
||||||
node_.start_shot_frameno = 0;
|
node_.start_shot_frameno = 0;
|
||||||
node_.shot_times = 0;
|
node_.shot_times = 0;
|
||||||
@ -627,7 +628,7 @@ void AndroidNewAI::ChangeToStateNewAI(AndroidStateEx_e to_state)
|
|||||||
break;
|
break;
|
||||||
case ASE_Thinking:
|
case ASE_Thinking:
|
||||||
{
|
{
|
||||||
node_.target = nullptr;
|
node_.target.Reset();
|
||||||
node_.param1 = 0;
|
node_.param1 = 0;
|
||||||
node_.start_shot_frameno = 0;
|
node_.start_shot_frameno = 0;
|
||||||
node_.shot_times = 0;
|
node_.shot_times = 0;
|
||||||
@ -646,7 +647,7 @@ void AndroidNewAI::ChangeToStateNewAI(AndroidStateEx_e to_state)
|
|||||||
case ASE_RandomWalk:
|
case ASE_RandomWalk:
|
||||||
{
|
{
|
||||||
moving_ = true;
|
moving_ = true;
|
||||||
node_.target = nullptr;
|
node_.target.Reset();
|
||||||
#if 1
|
#if 1
|
||||||
node_.param1 = SERVER_FRAME_RATE * ai_meta->GetMoveTime();
|
node_.param1 = SERVER_FRAME_RATE * ai_meta->GetMoveTime();
|
||||||
#else
|
#else
|
||||||
@ -668,8 +669,8 @@ void AndroidNewAI::ChangeToStateNewAI(AndroidStateEx_e to_state)
|
|||||||
case ASE_Pursuit:
|
case ASE_Pursuit:
|
||||||
{
|
{
|
||||||
moving_ = true;
|
moving_ = true;
|
||||||
if (node_.target) {
|
if (node_.target.Get()) {
|
||||||
hum->move_dir = node_.target->GetPos() - hum->GetPos();
|
hum->move_dir = node_.target.Get()->GetPos() - hum->GetPos();
|
||||||
hum->move_dir.Normalize();
|
hum->move_dir.Normalize();
|
||||||
hum->attack_dir = hum->move_dir;
|
hum->attack_dir = hum->move_dir;
|
||||||
}
|
}
|
||||||
@ -715,7 +716,7 @@ Human* AndroidNewAI::GetTarget()
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (target) {
|
if (target) {
|
||||||
node_.nearest_human = target;
|
node_.nearest_human.Attach(target);
|
||||||
node_.last_check_nearest_human_frameno = myself->room->GetFrameNo();
|
node_.last_check_nearest_human_frameno = myself->room->GetFrameNo();
|
||||||
float distance = myself->GetPos().Distance(target->GetPos());
|
float distance = myself->GetPos().Distance(target->GetPos());
|
||||||
if (distance > GetAttackRange()) {
|
if (distance > GetAttackRange()) {
|
||||||
@ -739,14 +740,14 @@ float AndroidNewAI::GetAttackRange()
|
|||||||
void AndroidNewAI::DoShotNewAI()
|
void AndroidNewAI::DoShotNewAI()
|
||||||
{
|
{
|
||||||
Human* myself = (Human*)owner;
|
Human* myself = (Human*)owner;
|
||||||
if (!node_.target) {
|
if (!node_.target.Get()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool shot_ok = false;
|
bool shot_ok = false;
|
||||||
a8::Vec2 shot_dir = myself->attack_dir;
|
a8::Vec2 shot_dir = myself->attack_dir;
|
||||||
if (node_.total_shot_times >= node_.next_total_shot_times) {
|
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);
|
node_.next_total_shot_times += 7 + (rand() % 6);
|
||||||
myself->attack_dir = shot_dir;
|
myself->attack_dir = shot_dir;
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "aicomponent.h"
|
#include "aicomponent.h"
|
||||||
|
#include "weakptr.h"
|
||||||
|
|
||||||
enum AndroidState_e
|
enum AndroidState_e
|
||||||
{
|
{
|
||||||
@ -32,8 +33,8 @@ public:
|
|||||||
int next_total_shot_times = 0;
|
int next_total_shot_times = 0;
|
||||||
|
|
||||||
long long param1 = 0;
|
long long param1 = 0;
|
||||||
Human* target = nullptr;
|
CreatureWeakPtr target;
|
||||||
Human* nearest_human = nullptr;
|
CreatureWeakPtr nearest_human;
|
||||||
long long last_check_nearest_human_frameno = 0;
|
long long last_check_nearest_human_frameno = 0;
|
||||||
a8::Vec2 shot_dir;
|
a8::Vec2 shot_dir;
|
||||||
};
|
};
|
||||||
@ -42,7 +43,7 @@ struct OldAiData
|
|||||||
{
|
{
|
||||||
AndroidState_e state = AS_thinking;
|
AndroidState_e state = AS_thinking;
|
||||||
int state_elapsed_time = 0;
|
int state_elapsed_time = 0;
|
||||||
Human* last_target = nullptr;
|
CreatureWeakPtr last_target;
|
||||||
long long last_attack_frameno = 0;
|
long long last_attack_frameno = 0;
|
||||||
long long last_findenemy_frameno = 0;
|
long long last_findenemy_frameno = 0;
|
||||||
long long series_attack_frames = 0;
|
long long series_attack_frames = 0;
|
||||||
|
@ -21,6 +21,7 @@ class Creature : public MoveableEntity
|
|||||||
|
|
||||||
int status = 0;
|
int status = 0;
|
||||||
bool dead = false;
|
bool dead = false;
|
||||||
|
bool real_dead = false;
|
||||||
int team_id = 0;
|
int team_id = 0;
|
||||||
bool aiming = false;
|
bool aiming = false;
|
||||||
a8::Vec2 attack_dir;
|
a8::Vec2 attack_dir;
|
||||||
|
@ -87,7 +87,6 @@ class Human : public Creature
|
|||||||
int emoji2 = 0;
|
int emoji2 = 0;
|
||||||
int parachute = 0;
|
int parachute = 0;
|
||||||
bool has_pass = 0;
|
bool has_pass = 0;
|
||||||
bool real_dead = false;
|
|
||||||
xtimer_list* revive_timer = nullptr;
|
xtimer_list* revive_timer = nullptr;
|
||||||
int dead_times = 0;
|
int dead_times = 0;
|
||||||
long long dead_frameno = 0;
|
long long dead_frameno = 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user