This commit is contained in:
aozhiwei 2021-03-30 11:54:45 +08:00
parent b6cb96c11c
commit d707b56f54

View File

@ -31,8 +31,8 @@ public:
int next_total_shot_times = 0;
long long param1 = 0;
Creature* target = nullptr;
Creature* nearest_human = nullptr;
CreatureWeakPtr target;
CreatureWeakPtr nearest_human;
long long last_check_nearest_human_frameno = 0;
a8::Vec2 shot_dir;
@ -157,7 +157,7 @@ void ZombieModeAI::UpdateThinking()
} else {
Creature* target = GetTarget();
if (target) {
node_->target = target;
node_->target.Attach(target);
ChangeToState(ZSE_Attack);
} else {
if (hum->room->GetFrameNo() >= node_->next_random_move_frameno) {
@ -180,16 +180,16 @@ void ZombieModeAI::UpdateAttack()
if (myself->HasBuffEffect(kBET_Vertigo)) {
return;
}
if (!node_->target || node_->target->dead) {
if (!node_->target.Get() || node_->target.Get()->dead) {
ChangeToState(ZSE_Thinking);
return;
}
if (node_->exec_frame_num > SERVER_FRAME_RATE * 8 ||
myself->GetRace() == node_->target->GetRace()) {
myself->GetRace() == node_->target.Get()->GetRace()) {
ChangeToState(ZSE_Thinking);
return;
}
float distance = myself->GetPos().Distance(node_->target->GetPos());
float distance = myself->GetPos().Distance(node_->target.Get()->GetPos());
if (distance > GetAttackRange()) {
Skill* skill = myself->SelectSkill();
if (myself->CanUseSkill(skill->meta->i->skill_id()) &&
@ -261,7 +261,7 @@ void ZombieModeAI::UpdateRandomWalk()
void ZombieModeAI::UpdatePursuit()
{
Human* myself = (Human*)owner;
float distance = myself->GetPos().Distance(node_->target->GetPos());
float distance = myself->GetPos().Distance(node_->target.Get()->GetPos());
if (distance < GetAttackRange()) {
ChangeToState(ZSE_Attack);
} else {
@ -287,11 +287,11 @@ void ZombieModeAI::DoMove()
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 != ZSE_Pursuit &&
hum->GetPos().ManhattanDistance(node_->nearest_human->GetPos()) < 200) {
hum->GetPos().ManhattanDistance(node_->nearest_human.Get()->GetPos()) < 200) {
ChangeToState(ZSE_Thinking);
} else if (hum->GetPos().ManhattanDistance(node_->nearest_human->GetPos()) > 800) {
} else if (hum->GetPos().ManhattanDistance(node_->nearest_human.Get()->GetPos()) > 800) {
GetTarget();
}
}
@ -304,7 +304,7 @@ void ZombieModeAI::ChangeToState(ZombieState_e to_state)
switch (to_state) {
case ZSE_Idle:
{
node_->target = nullptr;
node_->target.Reset();
node_->param1 = 0;
node_->start_shot_frameno = 0;
node_->shot_times = 0;
@ -319,7 +319,7 @@ void ZombieModeAI::ChangeToState(ZombieState_e to_state)
break;
case ZSE_Thinking:
{
node_->target = nullptr;
node_->target.Reset();
node_->param1 = 0;
node_->start_shot_frameno = 0;
node_->shot_times = 0;
@ -338,7 +338,7 @@ void ZombieModeAI::ChangeToState(ZombieState_e to_state)
case ZSE_RandomWalk:
{
node_->moving = true;
node_->target = nullptr;
node_->target.Reset();
node_->param1 = SERVER_FRAME_RATE * node_->ai_meta->GetMoveTime();
node_->start_shot_frameno = 0;
node_->shot_times = 0;
@ -356,8 +356,8 @@ void ZombieModeAI::ChangeToState(ZombieState_e to_state)
case ZSE_Pursuit:
{
node_->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;
}
@ -394,7 +394,7 @@ Creature* ZombieModeAI::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 0
@ -427,14 +427,14 @@ float ZombieModeAI::GetAttackRange()
void ZombieModeAI::DoShot()
{
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;
}
@ -467,7 +467,7 @@ void ZombieModeAI::DoShot()
void ZombieModeAI::DoSkill(int skill_id)
{
Human* myself = (Human*)owner;
myself->DoSkill(skill_id, node_->target->GetEntityUniId(), a8::Vec2(), node_->target->GetPos());
myself->DoSkill(skill_id, node_->target.Get()->GetEntityUniId(), a8::Vec2(), node_->target.Get()->GetPos());
}
int ZombieModeAI::GetAttackTimes()