From 5c9028712df537bd88aa54de58fdb9d0472a5fde Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Fri, 29 May 2020 23:34:52 +0800 Subject: [PATCH] youhua shua android --- server/gameserver/android.ai.cc | 6 +- server/gameserver/human.cc | 31 ++++- server/gameserver/human.h | 2 +- server/gameserver/room.cc | 206 +++++++++++++++++--------------- server/gameserver/room.h | 8 +- 5 files changed, 152 insertions(+), 101 deletions(-) diff --git a/server/gameserver/android.ai.cc b/server/gameserver/android.ai.cc index 1c2a901..cfd0d38 100644 --- a/server/gameserver/android.ai.cc +++ b/server/gameserver/android.ai.cc @@ -33,7 +33,7 @@ void AndroidAI::Update(int delta_time) if (hum->dead) { return; } - if (a8::HasBitFlag(hum->status, HS_NewBieNpc)) { + if (a8::HasBitFlag(hum->status, HS_NewBieGuideAndroid)) { UpdateNewBieNpc(); return; } @@ -109,7 +109,7 @@ void AndroidAI::DoMove() if (owner->UpdatedTimes() % 2 == 0) { Human* hum = (Human*)owner; int speed = std::max(1, (int)hum->GetSpeed()); - if (a8::HasBitFlag(hum->status, HS_NewBieNpc) && + if (a8::HasBitFlag(hum->status, HS_NewBieGuideAndroid) && hum->room->GetFrameNo() - hum->enable_frameno < SERVER_FRAME_RATE * 8) { hum->move_dir = hum->room->GetFirstNewBie()->GetPos() - hum->GetPos(); hum->move_dir.Normalize(); @@ -190,6 +190,6 @@ void AndroidAI::UpdateNewBieNpc() sender->Shot(shot_dir); } } else { - a8::UnSetBitFlag(hum->status, HS_NewBieNpc); + a8::UnSetBitFlag(hum->status, HS_NewBieGuideAndroid); } } diff --git a/server/gameserver/human.cc b/server/gameserver/human.cc index a888144..e34ba56 100644 --- a/server/gameserver/human.cc +++ b/server/gameserver/human.cc @@ -3313,7 +3313,7 @@ void Human::ProcNewBieLogic() [] (const a8::XParams& param) { Human* hum = (Human*)param.sender.GetUserData(); - hum->room->ShuaNewBieAndroid(hum); + hum->room->ShuaGuideAndroid(hum); }, &xtimer_attacher.timer_list_ ); @@ -3367,10 +3367,39 @@ void Human::AdjustDecHp(float old_health, float& new_health) void Human::OnEnable() { + a8::UnSetBitFlag(status, HS_Disable); + enable_frameno = room->GetFrameNo(); + room->grid_service->AddHuman(this); + FindLocation(); + RefreshView(); } void Human::OnDisable() { + a8::SetBitFlag(status, HS_Disable); + for (auto& cell : grid_list) { + bool has_target = false; + for (Human* hum : cell->human_list[room->GetRoomIdx()]) { + if (hum == this) { + has_target = true; + } else { + hum->AddOutObjects(this); + } + } + if (has_target) { + cell->human_list[room->GetRoomIdx()].erase(this); + } + } + room->TouchHumanList + ( + a8::XParams() + .SetSender(this), + [] (Human* hum, a8::XParams& param) + { + Human* target = (Human*)param.sender.GetUserData(); + hum->RemovePartObjects(target); + return true; + }); grid_id = 0; grid_list.clear(); last_collision_door = nullptr; diff --git a/server/gameserver/human.h b/server/gameserver/human.h index b5ffa05..e5defb2 100644 --- a/server/gameserver/human.h +++ b/server/gameserver/human.h @@ -18,7 +18,7 @@ enum HumanStatus { HS_AlreadyLordMode = 1, HS_Disable = 2, - HS_NewBieNpc = 3, + HS_NewBieGuideAndroid = 3, HS_AlreadyEquip = 5, HS_AlreadyProcNewBieLogic = 6, HS_End diff --git a/server/gameserver/room.cc b/server/gameserver/room.cc index 17eeb24..6570122 100644 --- a/server/gameserver/room.cc +++ b/server/gameserver/room.cc @@ -289,7 +289,7 @@ void Room::CreateAndroid(int robot_num) Human* Room::FindEnemy(Human* hum) { - if (a8::HasBitFlag(hum->status, HS_NewBieNpc) && + if (a8::HasBitFlag(hum->status, HS_NewBieGuideAndroid) && GetFrameNo() - hum->enable_frameno < SERVER_FRAME_RATE * 8) { return first_newbie_; } @@ -1605,7 +1605,7 @@ void Room::NotifyGameStart() }, &xtimer_attacher_.timer_list_); - if (room_type == RT_NewBrid || room_type == RT_MidBrid) { + if (room_type_ == RT_NewBrid || room_type_ == RT_MidBrid) { NewBieRoomStart(); } } @@ -1648,13 +1648,8 @@ void Room::EnableHuman(Human* target) }); #endif if (a8::HasBitFlag(target->status, HS_Disable)) { - a8::UnSetBitFlag(target->status, HS_Disable); target->OnEnable(); - target->enable_frameno = GetFrameNo(); AddToMoveableHash(target); - grid_service->AddHuman(target); - target->FindLocation(); - target->RefreshView(); if (!target->real_dead) { AddToAliveHumanHash(target); } @@ -1678,33 +1673,16 @@ void Room::DisableHuman(Human* target) }); #endif if (!a8::HasBitFlag(target->status, HS_Disable)) { - a8::SetBitFlag(target->status, HS_Disable); + target->OnDisable(); RemoveFromMoveableHash(target); RemoveFromAliveHumanHash(target); - for (auto& cell : target->grid_list) { - bool has_target = false; - for (Human* hum : cell->human_list[room_idx_]) { - if (hum == target) { - has_target = true; - } else { - hum->AddOutObjects(target); - } - } - if (has_target) { - cell->human_list[room_idx_].erase(target); - } - } - for (auto& pair : human_hash_) { - pair.second->RemovePartObjects(target); - } - target->OnDisable(); } #ifdef DEBUG CheckPartObjects(); #endif } -void Room::ShuaNewBieAndroid(Human* target) +void Room::ShuaGuideAndroid(Human* target) { #ifdef DEBUG a8::UdpLog::Instance()->Debug("room_idx:%d ShuaNewBieAndroid %s %s", @@ -1714,11 +1692,9 @@ void Room::ShuaNewBieAndroid(Human* target) target->name }); #endif - for (auto& pair : human_hash_) { - if (pair.second->entity_subtype == EST_Android && - a8::HasBitFlag(pair.second->status, HS_Disable) - ) { - Android* hum = (Android*)pair.second; + { + Human* hum = GetOneCanEnableAndroid(); + if (hum) { a8::Vec2 pos = target->GetPos(); pos.x -= MetaMgr::Instance()->newbie_first_robot_distance; if (OverBorder(pos, hum->GetRadius())) { @@ -1729,9 +1705,8 @@ void Room::ShuaNewBieAndroid(Human* target) } } hum->SetPos(pos); - a8::SetBitFlag(hum->status, HS_NewBieNpc); EnableHuman(hum); - break; + a8::SetBitFlag(hum->status, HS_NewBieGuideAndroid); } } { @@ -1852,32 +1827,11 @@ void Room::DieAndroidTimerFunc() void Room::ProcShuaAndroid(int shua_time, int shua_num) { - Human* target = nullptr; - for (auto& pair : accountid_hash_) { - if (!pair.second->real_dead) { - target = pair.second; - break; - } - } + Human* target = GetOneAlivePlayer(); if (!target) { return; } - int real_shua_num = shua_num; - int autodie_time = 10; - int autodie_distance = 500; - if (room_type_ == RT_NewBrid) { - real_shua_num = std::max(0, - MetaMgr::Instance()->level0room_robot_water - RealAliveCount() + - (int)accountid_hash_.size()); - autodie_time = MetaMgr::Instance()->level0room_robot_autodie_time; - autodie_distance = MetaMgr::Instance()->level0room_robot_autodie_distance; - } else if (room_type_ == RT_MidBrid) { - real_shua_num = std::max(0, - MetaMgr::Instance()->level1room_robot_water - RealAliveCount() + - (int)accountid_hash_.size()); - autodie_time = MetaMgr::Instance()->level1room_robot_autodie_time; - autodie_distance = MetaMgr::Instance()->level1room_robot_autodie_distance; - } + int real_shua_num = GetCanShuaNum(shua_num); if (real_shua_num <= 0) { return; } @@ -1891,49 +1845,22 @@ void Room::ProcShuaAndroid(int shua_time, int shua_num) }); #endif - int refreshed_num = 0; - for (auto& pair : human_hash_) { - if (pair.second->entity_subtype == EST_Android && - !pair.second->real_dead && - a8::HasBitFlag(pair.second->status, HS_Disable) - ) { - Android* hum = (Android*)pair.second; - a8::Vec2 pos = target->GetPos(); - a8::Vec2 dir = a8::Vec2::UP; - dir.Rotate(a8::RandAngle()); - pos = pos + dir * 400; + std::vector humans; + GetCanEnableAndroids(humans, real_shua_num); + for (auto& hum : humans) { + a8::Vec2 pos = target->GetPos(); + a8::Vec2 dir = a8::Vec2::UP; + dir.Rotate(a8::RandAngle()); + pos = pos + dir * 400; + if (OverBorder(pos, hum->GetRadius())) { + pos.x = target->GetPos().x; if (OverBorder(pos, hum->GetRadius())) { - pos.x = target->GetPos().x; - if (OverBorder(pos, hum->GetRadius())) { - break; - } - } - hum->SetPos(pos); - EnableHuman(hum); - xtimer.AddDeadLineTimerAndAttach - ( - SERVER_FRAME_RATE * autodie_time, - a8::XParams() - .SetSender(hum) - .SetParam1(autodie_time) - .SetParam2(autodie_distance) - .SetParam3(0), - [] (const a8::XParams& param) - { - Human* hum = (Human*)param.sender.GetUserData(); - hum->room->CheckAutoDie( - hum, - param.param1, - param.param2, - param.param3 - ); - }, - &hum->xtimer_attacher.timer_list_); - ++refreshed_num; - if (refreshed_num >= real_shua_num) { break; } } + hum->SetPos(pos); + EnableHuman(hum); + InstallCheckAutoDieTimer(hum); } } @@ -2463,3 +2390,92 @@ void Room::NewBieRoomStart() &xtimer_attacher_.timer_list_); } } + +Human* Room::GetOneCanEnableAndroid() +{ + std::vector humans; + GetCanEnableAndroids(humans, 1); + return !humans.empty() ? humans[0] : nullptr; +} + +void Room::GetCanEnableAndroids(std::vector& humans, int num) +{ + for (auto& pair : human_hash_) { + if (pair.second->IsAndroid() && + !pair.second->real_dead && + a8::HasBitFlag(pair.second->status, HS_Disable) + ) { + if (humans.size() >= num) { + break; + } + humans.push_back(pair.second); + } + } +} + +void Room::InstallCheckAutoDieTimer(Human* hum) +{ + int autodie_time = 10; + int autodie_distance = 500; + if (room_type_ == RT_NewBrid) { + autodie_time = MetaMgr::Instance()->level0room_robot_autodie_time; + autodie_distance = MetaMgr::Instance()->level0room_robot_autodie_distance; + } else if (room_type_ == RT_MidBrid) { + autodie_time = MetaMgr::Instance()->level1room_robot_autodie_time; + autodie_distance = MetaMgr::Instance()->level1room_robot_autodie_distance; + } + + xtimer.AddDeadLineTimerAndAttach + ( + SERVER_FRAME_RATE * autodie_time, + a8::XParams() + .SetSender(hum) + .SetParam1(autodie_time) + .SetParam2(autodie_distance) + .SetParam3(0), + [] (const a8::XParams& param) + { + Human* hum = (Human*)param.sender.GetUserData(); + hum->room->CheckAutoDie( + hum, + param.param1, + param.param2, + param.param3 + ); + }, + &hum->xtimer_attacher.timer_list_); +} + +Player* Room::GetOneAlivePlayer() +{ + std::vector humans; + GetAlivePlayers(humans, 1); + return !humans.empty() ? humans[0] : nullptr; +} + +void Room::GetAlivePlayers(std::vector& humans, int num) +{ + for (auto& pair : accountid_hash_) { + if (!pair.second->real_dead) { + if (humans.size() >= num) { + break; + } + humans.push_back(pair.second); + } + } +} + +int Room::GetCanShuaNum(int shua_num) +{ + int real_shua_num = shua_num; + if (room_type_ == RT_NewBrid) { + real_shua_num = std::max(0, + MetaMgr::Instance()->level0room_robot_water - RealAliveCount() + + (int)accountid_hash_.size()); + } else if (room_type_ == RT_MidBrid) { + real_shua_num = std::max(0, + MetaMgr::Instance()->level1room_robot_water - RealAliveCount() + + (int)accountid_hash_.size()); + } + return real_shua_num; +} diff --git a/server/gameserver/room.h b/server/gameserver/room.h index 1bfe718..4ec7bed 100644 --- a/server/gameserver/room.h +++ b/server/gameserver/room.h @@ -109,10 +109,16 @@ public: bool HaveMyTeam(const std::string& team_uuid); ObstacleData* GetPermanentObstacleData(int entity_uniid); long long GetGasInactiveTime(); - void ShuaNewBieAndroid(Human* target); + void ShuaGuideAndroid(Human* target); void InitAirDrop(); void CheckPartObjects(Human* testa = nullptr, Human* testb = nullptr); bool RuningInTimer(); + Human* GetOneCanEnableAndroid(); + void GetCanEnableAndroids(std::vector& humans, int num); + void InstallCheckAutoDieTimer(Human* hum); + Player* GetOneAlivePlayer(); + void GetAlivePlayers(std::vector& humans, int num); + int GetCanShuaNum(int shua_num); private: int AllocUniid();