From 3affeba4ea88b0d26e2af53b8c8afd13867b4436 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Tue, 26 Mar 2024 10:44:54 +0800 Subject: [PATCH] 1 --- server/gameserver/custom_member.h | 2 ++ server/gameserver/room.cc | 51 +++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/server/gameserver/custom_member.h b/server/gameserver/custom_member.h index 126a352d..40671608 100644 --- a/server/gameserver/custom_member.h +++ b/server/gameserver/custom_member.h @@ -33,6 +33,7 @@ class CustomMember void _CMBattlePreSetReady(f8::MsgHdr* hdr, const cs::CMBattlePreSetReady& msg); bool IsAndroid(); bool IsReady() { return is_ready_; } + int GetRobotId() { return robot_id_; } private: std::shared_ptr join_msg_; @@ -48,6 +49,7 @@ private: int head_frame_ = 0; int sex_ = 0; int is_ready_ = 0; + int robot_id_ = 0; std::shared_ptr battle_context_; friend class CustomBattle; }; diff --git a/server/gameserver/room.cc b/server/gameserver/room.cc index 76cbe81d..a0fb3bb2 100644 --- a/server/gameserver/room.cc +++ b/server/gameserver/room.cc @@ -536,7 +536,58 @@ void Room::CreateAndroid(int robot_num, std::shared_ptr team) Human* Room::CreateAndroidWithCustomMember(std::shared_ptr custom_member, std::shared_ptr team) { + if (GetHumanNum() >= GetRoomMaxPlayerNum()) { + return nullptr; + } + const mt::Robot* robot_meta = mt::Robot::GetById(custom_member->GetRobotId()); + if (!robot_meta) { + A8_ABORT(); + } + Android* hum = EntityFactory::Instance()->MakeAndroid(AllocUniid()); + hum->name = robot_meta->name(); + hum->meta = mt::Hero::GetById(custom_member->GetNetData()->GetHeroId()); + hum->robot_meta = robot_meta; + hum->SetBornPoint(AllocBornPoint(hum)); + App::Instance()->verify_set_pos = 1; + if (!hum->GetBornPoint()) { + abort(); + } else { + hum->SetPos(hum->GetBornPoint()->RandPoint(this)); + } + App::Instance()->verify_set_pos = 0; + glm::vec3 attack_dir = hum->GetPos().ToGlmVec3(); + GlmHelper::Normalize(attack_dir); + GlmHelper::RotateY(attack_dir, a8::RandAngle()); + hum->SetAttackDir(attack_dir); + hum->SetMoveDir(attack_dir); + hum->room = this; + hum->join_frameno = GetFrameNo(); + hum->Initialize(); + AddToEntityHash(hum); + AddToHumanHash(hum); + if (team) { + team->AddMember(hum); + } else { + MatchTeam(hum); + } + if (!hum->IsOb()) { + IncAliveCount(); + } + refreshed_robot_set_.insert(robot_meta->id()); + if (!CanAddToScene(hum)) { + a8::SetBitFlag(hum->status, CS_Disable); + } else { + AddToAliveHumanHash(hum); + AddToMoveableHash(hum); + grid_service->AddCreature(hum); + hum->FindLocation(); + hum->RefreshView(); + } + OnAddHuman(hum); + frame_event.AddEnterGame(hum->GetWeakPtrRef()); + NotifyUiUpdate(); + return hum; } void Room::FillSMJoinedNotify(Human* self_hum, cs::SMJoinedNotify& msg)