This commit is contained in:
aozhiwei 2020-07-15 16:24:07 +08:00
parent bc74c6704f
commit ad44ba7cea
6 changed files with 82 additions and 4 deletions

View File

@ -470,10 +470,15 @@ void AndroidNewAI::UpdateThinking()
node_.target = target;
ChangeToStateNewAI(ASE_Attack);
} else {
if ((rand() % 7) < 4) {
ChangeToStateNewAI(ASE_Idle);
if (hum->room->GetFrameNo() >= node_.next_random_move_frameno) {
if ((rand() % 7) < 4) {
ChangeToStateNewAI(ASE_Idle);
} else {
ChangeToStateNewAI(ASE_RandomWalk);
}
} else {
ChangeToStateNewAI(ASE_RandomWalk);
ChangeToStateNewAI(ASE_Idle);
node_.param1 = node_.next_random_move_frameno - hum->room->GetFrameNo();
}
}
}
@ -620,9 +625,15 @@ void AndroidNewAI::ChangeToStateNewAI(AndroidStateEx_e to_state)
{
moving_ = true;
node_.target = nullptr;
#if 1
node_.param1 = SERVER_FRAME_RATE * ai_meta->GetMoveTime();
#else
node_.param1 = SERVER_FRAME_RATE * 5 + rand() % (SERVER_FRAME_RATE * 3);
#endif
node_.start_shot_frameno = 0;
node_.shot_times = 0;
node_.next_random_move_frameno = hum->room->GetFrameNo() +
SERVER_FRAME_RATE * ai_meta->GetMoveIdleTime();
hum->move_dir = a8::Vec2(1.0f, 0);
hum->move_dir.Rotate(a8::RandAngle());
hum->move_dir.Normalize();
@ -694,7 +705,7 @@ float AndroidNewAI::GetAttackRange()
if (myself->curr_weapon && myself->curr_weapon->meta) {
attack_range = myself->curr_weapon->meta->i->range();
}
attack_range = std::min(300.0f, attack_range);
attack_range = std::min(ai_meta->i->attack_range(), (int)attack_range);
return attack_range;
}

View File

@ -19,6 +19,7 @@ public:
long long frameno = 0;
long long exec_frame_num = 0;
long long start_shot_frameno = 0;
long long next_random_move_frameno = 0;
int shot_times = 0;
int total_shot_times = 0;
int next_total_shot_times = 0;

View File

@ -497,4 +497,58 @@ namespace MetaData
{
}
void AI::Init()
{
{
std::vector<std::string> strings;
a8::Split(i->random_move_idle_time(), strings, ';');
if (!i->random_move_idle_time().empty()) {
random_move_idle_time_ = std::make_tuple
(
a8::XValue(strings[0]).GetInt(),
a8::XValue(strings[1]).GetInt()
);
} else {
random_move_idle_time_ = std::make_tuple
(
2,
3
);
}
}
{
std::vector<std::string> strings;
a8::Split(i->random_move_time(), strings, ';');
if (!i->random_move_time().empty()) {
random_move_time_ = std::make_tuple
(
a8::XValue(strings[0]).GetInt(),
a8::XValue(strings[1]).GetInt()
);
} else {
random_move_time_ = std::make_tuple
(
3,
7
);
}
}
}
int AI::GetMoveIdleTime()
{
return a8::RandEx(
std::get<0>(random_move_idle_time_),
std::get<1>(random_move_idle_time_)
);
}
int AI::GetMoveTime()
{
return a8::RandEx(
std::get<0>(random_move_time_),
std::get<1>(random_move_time_)
);
}
}

View File

@ -218,6 +218,14 @@ namespace MetaData
struct AI
{
const metatable::AI* i = nullptr;
void Init();
int GetMoveIdleTime();
int GetMoveTime();
private:
std::tuple<int, int> random_move_idle_time_;
std::tuple<int, int> random_move_time_;
};
}

View File

@ -570,6 +570,7 @@ private:
for (auto& meta : ai_meta_list) {
MetaData::AI& item = a8::FastAppend(ai_list);
item.i = &meta;
item.Init();
ai_hash[meta.ai_level()] = &item;
}

View File

@ -243,6 +243,9 @@ message AI
optional int32 attack_times = 4;
optional int32 attack_type = 5;
optional float shot_offset_angle = 6;
optional string random_move_idle_time = 8;
optional string random_move_time = 9;
optional int32 attack_range = 10;
}
//end