merge nb3
This commit is contained in:
commit
856e4213f2
@ -186,17 +186,7 @@ void AndroidAI::UpdateNewBieNpc()
|
||||
} else if (hum->room->GetFrameNo() - 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 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() - hum->enable_frameno < SERVER_FRAME_RATE * 3) {
|
||||
@ -230,17 +220,7 @@ void AndroidAI::UpdateLastNpc()
|
||||
} else if (hum->room->GetFrameNo() - 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 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() - hum->enable_frameno < SERVER_FRAME_RATE * 3) {
|
||||
@ -262,8 +242,12 @@ void AndroidAI::UpdateLastNpc()
|
||||
void AndroidAI::UpdateNewBieRoomLogic()
|
||||
{
|
||||
Human* hum = (Human*)owner;
|
||||
Human* old_last_target = last_target_;
|
||||
Human* target = last_target_;
|
||||
if (!last_target_ || last_target_->real_dead) {
|
||||
if ((last_target_ && last_target_->real_dead) || !last_target_) {
|
||||
if (hum->last_human_target && !hum->last_human_target->dead) {
|
||||
target = hum->last_human_target;
|
||||
} else {
|
||||
if (rand() % 100 < 70) {
|
||||
hum->room->TouchPlayerList
|
||||
(
|
||||
@ -282,22 +266,26 @@ void AndroidAI::UpdateNewBieRoomLogic()
|
||||
}
|
||||
});
|
||||
} else {
|
||||
std::vector<Human*> alive_humans;
|
||||
hum->room->TouchHumanList
|
||||
(
|
||||
a8::XParams(),
|
||||
[hum, &alive_humans] (Human* huma, a8::XParams& param)
|
||||
[hum, &target] (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);
|
||||
if (!target) {
|
||||
target = huma;
|
||||
} else {
|
||||
if (hum->GetPos().ManhattanDistance(huma->GetPos()) <
|
||||
hum->GetPos().ManhattanDistance(target->GetPos())) {
|
||||
target = huma;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
});
|
||||
if (!alive_humans.empty()) {
|
||||
target = alive_humans[rand() % alive_humans.size()];
|
||||
}
|
||||
}
|
||||
last_target_ = target;
|
||||
@ -331,25 +319,21 @@ void AndroidAI::UpdateNewBieRoomLogic()
|
||||
}
|
||||
}
|
||||
if (hum->GetPos().ManhattanDistance(target->GetPos()) > 180) {
|
||||
if (hum->GetPos().ManhattanDistance(target->GetPos()) > 650 &&
|
||||
hum->room->GetFrameNo() - last_findenemy_frameno_ > SERVER_FRAME_RATE * 3) {
|
||||
last_findenemy_frameno_ = hum->room->GetFrameNo();
|
||||
last_target_ = nullptr;
|
||||
} else {
|
||||
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();
|
||||
@ -363,5 +347,14 @@ void AndroidAI::UpdateNewBieRoomLogic()
|
||||
sender->Shot(shot_dir);
|
||||
}
|
||||
}
|
||||
if (old_last_target && last_target_ && old_last_target == last_target_) {
|
||||
++series_attack_frames_;
|
||||
} else {
|
||||
series_attack_frames_ = 0;
|
||||
}
|
||||
if (series_attack_frames_ > SERVER_FRAME_RATE * 10 &&
|
||||
last_target_ && last_target_->IsAndroid()) {
|
||||
last_target_ = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -33,4 +33,6 @@ private:
|
||||
private:
|
||||
Human* last_target_ = nullptr;
|
||||
long long last_attack_frameno_ = 0;
|
||||
long long last_findenemy_frameno_ = 0;
|
||||
long long series_attack_frames_ = 0;
|
||||
};
|
||||
|
@ -1471,7 +1471,7 @@ void Human::RemoveObserver(Human* observer)
|
||||
|
||||
void Human::SendUpdateMsg()
|
||||
{
|
||||
if (!follow_target_ && !a8::HasBitFlag(status, HS_Disable)) {
|
||||
if (!follow_target_ && !a8::HasBitFlag(status, HS_Disable) && IsPlayer()) {
|
||||
cs::MFActivePlayerData* active_player_data_pb = nullptr;
|
||||
if (send_msg_times == 0 || need_sync_active_player) {
|
||||
active_player_data_pb = new cs::MFActivePlayerData();
|
||||
@ -1491,6 +1491,8 @@ void Human::SendUpdateMsg()
|
||||
delete active_player_data_pb;
|
||||
}
|
||||
++send_msg_times;
|
||||
} else {
|
||||
need_sync_active_player = false;
|
||||
}
|
||||
ClearFrameData();
|
||||
}
|
||||
|
@ -59,7 +59,8 @@ void MapMgr::AttachRoom(Room* room, RoomInitInfo& init_info)
|
||||
init_info.grid_service = grid_service_;
|
||||
init_info.map_service = map_service_;
|
||||
init_info.spawn_points = &spawn_points_;
|
||||
init_info.newbie_born_point_meta = newbie_born_point_;
|
||||
init_info.level0room_born_point_meta = level0room_born_point_;
|
||||
init_info.level1room_born_point_meta = level1room_born_point_;
|
||||
init_info.loots = &loots_;
|
||||
init_info.buildings = &buildings_;
|
||||
init_info.level0room_spec_things = &level0room_spec_things_;
|
||||
@ -106,7 +107,11 @@ void MapMgr::CreateThings()
|
||||
}
|
||||
if (spawn_points_hash.find(MetaMgr::Instance()->newbie_born_point) !=
|
||||
spawn_points_hash.end()) {
|
||||
newbie_born_point_ = spawn_points_hash[MetaMgr::Instance()->newbie_born_point];
|
||||
level0room_born_point_ = spawn_points_hash[MetaMgr::Instance()->newbie_born_point];
|
||||
}
|
||||
if (spawn_points_hash.find(MetaMgr::Instance()->level1room_born_point) !=
|
||||
spawn_points_hash.end()) {
|
||||
level1room_born_point_ = spawn_points_hash[MetaMgr::Instance()->level1room_born_point];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -42,7 +42,8 @@ class MapMgr : public a8::Singleton<MapMgr>
|
||||
MapService* map_service_ = nullptr;
|
||||
GridService* grid_service_ = nullptr;
|
||||
std::vector<MetaData::MapTplThing*> spawn_points_;
|
||||
MetaData::MapTplThing* newbie_born_point_ = nullptr;
|
||||
MetaData::MapTplThing* level0room_born_point_ = nullptr;
|
||||
MetaData::MapTplThing* level1room_born_point_ = nullptr;
|
||||
std::vector<MetaData::MapTplThing*> loots_;
|
||||
std::vector<Building*> buildings_;
|
||||
std::vector<MetaData::MapTplThing*> level0room_spec_things_;
|
||||
|
@ -240,6 +240,7 @@ public:
|
||||
METAMGR_READ(level1room_robot_water, 8);
|
||||
METAMGR_READ(level1room_robot_autodie_time, 10);
|
||||
METAMGR_READ(level1room_robot_autodie_distance, 500);
|
||||
METAMGR_READ_STR(level1room_born_point, "");
|
||||
|
||||
METAMGR_READ(refresh_robot_min_num, 5);
|
||||
METAMGR_READ(refresh_robot_max_num, 10);
|
||||
|
@ -100,6 +100,7 @@ class MetaMgr : public a8::Singleton<MetaMgr>
|
||||
int level1room_robot_water = 0;
|
||||
int level1room_robot_autodie_time = 0;
|
||||
int level1room_robot_autodie_distance = 0;
|
||||
std::string level1room_born_point;
|
||||
|
||||
int refresh_robot_min_num = 0;
|
||||
int refresh_robot_max_num = 0;
|
||||
|
@ -51,7 +51,8 @@ void Room::InitData(RoomInitInfo& init_info)
|
||||
map_service = init_info.map_service;
|
||||
map_meta_ = init_info.map_meta;
|
||||
spawn_points_ = init_info.spawn_points;
|
||||
newbie_born_point_meta_ = init_info.newbie_born_point_meta;
|
||||
level0room_born_point_meta_ = init_info.level0room_born_point_meta;
|
||||
level1room_born_point_meta_ = init_info.level1room_born_point_meta;
|
||||
loots_ = init_info.loots;
|
||||
buildings_ = init_info.buildings;
|
||||
level0room_spec_things_ = init_info.level0room_spec_things;
|
||||
@ -314,6 +315,36 @@ Human* Room::FindEnemy(Human* hum)
|
||||
if ((rand() % 10) < 2) {
|
||||
sub_type = EST_Android;
|
||||
}
|
||||
if (room_type_ == RT_MidBrid) {
|
||||
sub_type = EST_Android;
|
||||
Human* target = nullptr;
|
||||
hum->room->TouchHumanList
|
||||
(
|
||||
a8::XParams(),
|
||||
[hum, &target] (Human* huma, a8::XParams& param)
|
||||
{
|
||||
if (!huma->dead &&
|
||||
huma->IsAndroid() &&
|
||||
hum->team_id != huma->team_id &&
|
||||
!a8::HasBitFlag(huma->status, HS_Disable)) {
|
||||
if (!target) {
|
||||
target = huma;
|
||||
} else {
|
||||
if (hum->GetPos().ManhattanDistance(huma->GetPos()) <
|
||||
hum->GetPos().ManhattanDistance(target->GetPos())) {
|
||||
target = huma;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
});
|
||||
if (target) {
|
||||
if (hum->GetPos().ManhattanDistance(target->GetPos()) > 190) {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
return target;
|
||||
}
|
||||
hum->TouchAllLayerHumanList
|
||||
(
|
||||
[&enemys, hum, sub_type] (Human* target, bool& stop)
|
||||
@ -1464,8 +1495,11 @@ void Room::CreateSpawnPoints()
|
||||
BornPoint born_point;
|
||||
born_point.thing_tpl = thing_tpl;
|
||||
born_point_hash_[uniid] = born_point;
|
||||
if (thing_tpl == newbie_born_point_meta_) {
|
||||
newbie_born_point_uniid_ = uniid;
|
||||
if (thing_tpl == level0room_born_point_meta_) {
|
||||
level0room_born_point_uniid_ = uniid;
|
||||
}
|
||||
if (thing_tpl == level1room_born_point_meta_) {
|
||||
level1room_born_point_uniid_ = uniid;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1571,7 +1605,7 @@ void Room::SecondRandPoint()
|
||||
}
|
||||
CombineTeamBornPoint();
|
||||
if (room_type_ == RT_NewBrid) {
|
||||
BornPoint* newbie_point = GetBornPoint(newbie_born_point_uniid_);
|
||||
BornPoint* newbie_point = GetBornPoint(level0room_born_point_uniid_);
|
||||
if (newbie_point && first_newbie_) {
|
||||
ForceSetBornPoint(first_newbie_, newbie_point);
|
||||
} else {
|
||||
@ -1579,10 +1613,16 @@ void Room::SecondRandPoint()
|
||||
}
|
||||
}
|
||||
if (room_type_ == RT_MidBrid) {
|
||||
BornPoint* newbie_point = GetBornPoint(level1room_born_point_uniid_);
|
||||
for (auto& pair : accountid_hash_) {
|
||||
pair.second->on_grid_chg = std::bind(&Room::OnHumanGridChg,
|
||||
this,
|
||||
std::placeholders::_1);
|
||||
for (Human* member : *pair.second->team_members) {
|
||||
if (newbie_point) {
|
||||
ForceSetBornPoint(member, newbie_point);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#ifdef DEBUG
|
||||
|
@ -206,7 +206,8 @@ private:
|
||||
std::string map_tpl_name_;
|
||||
RoomType_e room_type_ = RT_NewBrid;
|
||||
const std::vector<MetaData::MapTplThing*>* spawn_points_ = nullptr;
|
||||
const MetaData::MapTplThing* newbie_born_point_meta_ = nullptr;
|
||||
const MetaData::MapTplThing* level0room_born_point_meta_ = nullptr;
|
||||
const MetaData::MapTplThing* level1room_born_point_meta_ = nullptr;
|
||||
const std::vector<MetaData::MapTplThing*>* loots_ = nullptr;
|
||||
const std::vector<Building*>* buildings_ = nullptr;
|
||||
const std::vector<MetaData::MapTplThing*>* level0room_spec_things_ = nullptr;
|
||||
@ -223,7 +224,8 @@ private:
|
||||
MetaData::AirLine* airline_ = nullptr;
|
||||
a8::XTimerAttacher xtimer_attacher_;
|
||||
size_t airdrop_times_ = 0;
|
||||
int newbie_born_point_uniid_ = 0;
|
||||
int level0room_born_point_uniid_ = 0;
|
||||
int level1room_born_point_uniid_ = 0;
|
||||
bool show_handed_ = false;
|
||||
|
||||
int current_teamid_ = 0;
|
||||
|
@ -151,7 +151,8 @@ struct RoomInitInfo
|
||||
GridService* grid_service = nullptr;
|
||||
MapService* map_service = nullptr;
|
||||
const std::vector<MetaData::MapTplThing*>* spawn_points = nullptr;
|
||||
const MetaData::MapTplThing* newbie_born_point_meta = nullptr;
|
||||
const MetaData::MapTplThing* level0room_born_point_meta = nullptr;
|
||||
const MetaData::MapTplThing* level1room_born_point_meta = nullptr;
|
||||
const std::vector<MetaData::MapTplThing*>* loots = nullptr;
|
||||
const std::vector<Building*>* buildings = nullptr;
|
||||
const std::vector<MetaData::MapTplThing*>* level0room_spec_things = nullptr;
|
||||
|
Loading…
x
Reference in New Issue
Block a user