This commit is contained in:
aozhiwei 2020-07-14 17:42:08 +08:00
parent d4cd17eaa8
commit 5e95617be7
2 changed files with 40 additions and 3 deletions

View File

@ -494,12 +494,23 @@ void AndroidNewAI::UpdateAttack()
switch (ai_meta->i->attack_type()) {
case kShotClick:
{
if (ai_meta->i->attack_interval() > 0) {
if (myself->room->GetFrameNo() - node_.start_shot_frameno >
ai_meta->i->attack_interval() / 100) {
//本轮射击结束
node_.shot_times = 0;
}
if (node_.shot_times < ai_meta->i->attack_times()) {
DoShotNewAI();
}
} else {
DoShotNewAI();
}
}
break;
case kShotHold:
{
DoShotNewAI();
}
break;
default:
@ -632,3 +643,27 @@ float AndroidNewAI::GetAttackRange()
attack_range = std::min(500.0f, attack_range);
return attack_range;
}
void AndroidNewAI::DoShotNewAI()
{
Human* myself = (Human*)owner;
if (!node_.target) {
return;
}
bool shot_ok = false;
a8::Vec2 shot_dir = node_.target->GetPos() - myself->GetPos();
if (std::abs(shot_dir.x) > FLT_EPSILON ||
std::abs(shot_dir.y) > FLT_EPSILON) {
shot_dir.Normalize();
myself->attack_dir = shot_dir;
shot_dir.Rotate(ai_meta->i->shot_offset_angle() / 180.0f);
myself->Shot(shot_dir, shot_ok);
if (shot_ok) {
if (node_.shot_times <= 0) {
node_.start_shot_frameno = myself->room->GetFrameNo();
}
++node_.shot_times;
}
}
}

View File

@ -18,11 +18,12 @@ public:
AndroidStateEx_e main_state = ASE_Idle;
long long frameno = 0;
long long exec_frame_num = 0;
long long start_shot_frameno = 0;
int shot_times = 0;
long long param1 = 0;
Human* target = nullptr;
a8::Vec2 shot_dir;
int shot_times = 0;
};
struct OldAiData
@ -64,6 +65,7 @@ private:
void UpdateRandomWalk();
void DoMoveNewAI();
void ChangeToStateNewAI(AndroidStateEx_e to_state);
void DoShotNewAI();
Human* GetTarget();
float GetAttackRange();