This commit is contained in:
aozhiwei 2020-06-04 22:11:21 +08:00
parent 7a8a3fe687
commit 2112624943
5 changed files with 136 additions and 2 deletions

View File

@ -6,6 +6,9 @@
#include "android.h"
#include "room.h"
#include "metamgr.h"
#include "player.h"
const int SHUA_RANGE = 580;
/*
@ -41,6 +44,14 @@ void AndroidAI::Update(int delta_time)
UpdateLastNpc();
return;
}
if ((hum->room->GetRoomType() == RT_NewBrid ||
hum->room->GetRoomType() == RT_MidBrid) &&
hum->room->GetGasData().gas_mode != GasInactive &&
hum->team_uuid.empty()
) {
UpdateNewBieRoomLogic();
return;
}
switch (state) {
case AS_thinking:
{
@ -177,6 +188,7 @@ void AndroidAI::UpdateNewBieNpc()
for (int i = 0; i < speed; ++i) {
a8::Vec2 old_pos = hum->GetPos();
hum->SetPos(hum->GetPos() + hum->move_dir);
#if 0
if (hum->IsCollisionInMapService()) {
hum->SetPos(old_pos);
if (i == 0) {
@ -184,6 +196,7 @@ void AndroidAI::UpdateNewBieNpc()
}
break;
}
#endif
hum->room->grid_service->MoveHuman(hum);
}
} else if (hum->room->GetFrameNo() - hum->enable_frameno < SERVER_FRAME_RATE * 3) {
@ -219,6 +232,7 @@ void AndroidAI::UpdateLastNpc()
for (int i = 0; i < speed; ++i) {
a8::Vec2 old_pos = hum->GetPos();
hum->SetPos(hum->GetPos() + hum->move_dir);
#if 0
if (hum->IsCollisionInMapService()) {
hum->SetPos(old_pos);
if (i == 0) {
@ -226,6 +240,7 @@ void AndroidAI::UpdateLastNpc()
}
break;
}
#endif
hum->room->grid_service->MoveHuman(hum);
}
} else if (hum->room->GetFrameNo() - hum->enable_frameno < SERVER_FRAME_RATE * 3) {
@ -243,3 +258,110 @@ void AndroidAI::UpdateLastNpc()
a8::UnSetBitFlag(hum->status, HS_LastAndroid);
}
}
void AndroidAI::UpdateNewBieRoomLogic()
{
Human* hum = (Human*)owner;
Human* target = last_target_;
if (!last_target_ || last_target_->real_dead) {
if (rand() % 100 < 70) {
hum->room->TouchPlayerList
(
a8::XParams(),
[hum, &target] (Player* player, a8::XParams& param)
{
if (!player->dead && hum->team_id != player->team_id) {
if (!target) {
target = player;
} else {
if (hum->GetPos().ManhattanDistance(player->GetPos()) <
hum->GetPos().ManhattanDistance(target->GetPos())) {
target = player;
}
}
}
});
} else {
std::vector<Human*> alive_humans;
hum->room->TouchHumanList
(
a8::XParams(),
[hum, &alive_humans] (Human* huma, a8::XParams& param)
{
if (!huma->dead &&
huma->IsAndroid() &&
hum->team_id != huma->team_id &&
!a8::HasBitFlag(huma->status, HS_Disable)) {
alive_humans.push_back(huma);
}
return true;
});
if (!alive_humans.empty()) {
target = alive_humans[rand() % alive_humans.size()];
}
}
last_target_ = target;
}
if (!target) {
return;
}
if (target->IsPlayer()) {
if (hum->room->AliveCount() < 15) {
if (hum->GetPos().ManhattanDistance(target->GetPos()) > 1000) {
a8::Vec2 pos = target->GetPos();
a8::Vec2 dir = target->move_dir;
dir = a8::Vec2::UP;
if (rand() % 100 < 1) {
dir.Rotate(a8::RandAngle() / 2.0f);
} else {
dir.Rotate(a8::RandAngle());
}
pos = pos + dir * SHUA_RANGE;
if (hum->room->OverBorder(pos, hum->GetRadius())) {
pos.x = target->GetPos().x;
if (hum->room->OverBorder(pos, hum->GetRadius())) {
pos = target->GetPos();
}
}
hum->SetPos(pos);
hum->room->grid_service->MoveHuman(hum);
hum->FindLocation();
hum->RefreshView();
}
}
}
if (hum->GetPos().ManhattanDistance(target->GetPos()) > 180) {
int speed = std::max(1, (int)hum->GetSpeed());
hum->move_dir = target->GetPos() - hum->GetPos();
hum->move_dir.Normalize();
hum->attack_dir = hum->move_dir;
speed *= 0.7;
for (int i = 0; i < speed; ++i) {
a8::Vec2 old_pos = hum->GetPos();
hum->SetPos(hum->GetPos() + hum->move_dir);
#if 0
if (hum->IsCollisionInMapService()) {
hum->SetPos(old_pos);
if (i == 0) {
hum->FindPathInMapService();
}
break;
}
#endif
hum->room->grid_service->MoveHuman(hum);
}
} else {
if (hum->room->GetFrameNo() - last_attack_frameno_ > SERVER_FRAME_RATE + (rand() % 15)) {
last_attack_frameno_ = hum->room->GetFrameNo();
Human* sender = (Human*)owner;
a8::Vec2 shot_dir = target->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);
}
}
}
}

View File

@ -23,6 +23,7 @@ class AndroidAI : public AIComponent
private:
void UpdateNewBieNpc();
void UpdateLastNpc();
void UpdateNewBieRoomLogic();
void ChangeToState(AndroidState_e to_state);
@ -31,4 +32,5 @@ private:
private:
Human* last_target_ = nullptr;
long long last_attack_frameno_ = 0;
};

View File

@ -299,6 +299,11 @@ void Human::Shot(a8::Vec2& target_dir)
AutoLoadingBullet();
return;
}
if ((room->GetFrameNo() - last_shot_frameno_) * (1000 / SERVER_FRAME_RATE) <
curr_weapon->GetAttrValue(kHAT_FireRate)
) {
return;
}
#if 1
float fly_distance = 5;

View File

@ -452,6 +452,9 @@ void Player::Shot()
void Player::ProcInteraction()
{
if (room->GetGasData().gas_mode == GasInactive) {
return;
}
for (auto obj_id : interaction_objids) {
Entity* entity = room->GetEntityByUniId(obj_id);
if (entity) {

View File

@ -27,7 +27,7 @@
#include "perfmonitor.h"
const int ROOM_MAX_PLAYER_NUM = 40;
const int SHUA_RANGE = 512;
const int SHUA_RANGE = 580;
static long long RoomXGetTickCount(void* context)
{
@ -1880,7 +1880,8 @@ void Room::ProcShuaAndroid(int shua_time, int shua_num)
for (auto& hum : humans) {
a8::Vec2 pos = target->GetPos();
a8::Vec2 dir = target->move_dir;
if (rand() % 100 < 80) {
dir = a8::Vec2::UP;
if (rand() % 100 < 1) {
dir.Rotate(a8::RandAngle() / 2.0f);
} else {
dir.Rotate(a8::RandAngle());
@ -1898,6 +1899,7 @@ void Room::ProcShuaAndroid(int shua_time, int shua_num)
a8::SetBitFlag(hum->status, HS_NewBieGuideAndroid);
#endif
InstallCheckAutoDieTimer(hum);
break;
}
}