1
This commit is contained in:
parent
06652837e0
commit
79eb19a10d
@ -33,6 +33,10 @@ void AndroidAI::Update(int delta_time)
|
||||
if (hum->dead) {
|
||||
return;
|
||||
}
|
||||
if (a8::HasBitFlag(hum->status, HS_NewBieNpc)) {
|
||||
UpdateNewBieNpc();
|
||||
return;
|
||||
}
|
||||
switch (state) {
|
||||
case AS_thinking:
|
||||
{
|
||||
@ -149,3 +153,43 @@ void AndroidAI::DoAttack()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AndroidAI::UpdateNewBieNpc()
|
||||
{
|
||||
Human* hum = (Human*)owner;
|
||||
if (hum->room->frame_no - hum->enable_frameno < 2) {
|
||||
hum->move_dir = hum->room->first_newbie->GetPos() - hum->GetPos();
|
||||
hum->move_dir.Normalize();
|
||||
hum->attack_dir = hum->move_dir;
|
||||
if (hum->curr_weapon->weapon_idx != 0) {
|
||||
hum->curr_weapon->ammo = 10;
|
||||
}
|
||||
} else if (hum->room->frame_no - hum->enable_frameno < SERVER_FRAME_RATE * 1.5) {
|
||||
int speed = std::max(1, (int)hum->GetSpeed());
|
||||
for (int i = 0; i < speed; ++i) {
|
||||
a8::Vec2 old_pos = hum->GetPos();
|
||||
hum->SetPos(hum->GetPos() + hum->move_dir);
|
||||
if (hum->IsCollisionInMapService()) {
|
||||
hum->SetPos(old_pos);
|
||||
if (i == 0) {
|
||||
hum->FindPathInMapService();
|
||||
}
|
||||
break;
|
||||
}
|
||||
hum->room->grid_service->MoveHuman(hum);
|
||||
}
|
||||
} else if (hum->room->frame_no - hum->enable_frameno < SERVER_FRAME_RATE * 3) {
|
||||
Human* enemy = hum->room->first_newbie;
|
||||
Human* sender = hum;
|
||||
a8::Vec2 shot_dir = enemy->GetPos() - sender->GetPos();
|
||||
if (std::abs(shot_dir.x) > FLT_EPSILON ||
|
||||
std::abs(shot_dir.y) > FLT_EPSILON) {
|
||||
shot_dir.Normalize();
|
||||
shot_dir.Rotate((rand() % 10) / 180.0f);
|
||||
sender->attack_dir = shot_dir;
|
||||
sender->Shot(shot_dir);
|
||||
}
|
||||
} else {
|
||||
a8::UnSetBitFlag(hum->status, HS_NewBieNpc);
|
||||
}
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ class AndroidAI : public AIComponent
|
||||
virtual void Update(int delta_time) override;
|
||||
|
||||
private:
|
||||
void UpdateNewBieNpc();
|
||||
|
||||
void ChangeToState(AndroidState_e to_state);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user