aozhiwei 8eafed4b34 1
2023-11-27 15:27:38 +08:00

141 lines
5.2 KiB
C++

#pragma once
#include <a8/singleton.h>
#include <a8/timer_attacher.h>
#include <f8/protoutils.h>
#include <f8/timer.h>
#include "netdata.h"
namespace cs
{
class CMJoin;
class CMReconnect;
class CMPing;
}
namespace MetaData
{
struct Map;
struct MapTplThing;
}
class GridService;
class MapService;
class MapInstance;
class Building;
class CustomBattle;
struct RoomInitInfo
{
int room_idx = 0;
RoomMode_e room_mode = kPvpMode;
std::string room_uuid;
RoomType_e room_type = RoomType_NewBrid;
int creator_game_times = 0;
int creator_register_time = 0;
int creator_proto_version = 0;
int creator_channel = 0;
bool force_entry_newbie_room = false;
int init_map_id = 0;
int pve_instance_id = 0;
int pve_human_num = 0;
bool is_newbie_room = false;
const mt::Map* map_meta = nullptr;
std::string map_tpl_name;
std::shared_ptr<GridService> grid_service;
std::shared_ptr<MapService> map_service;
std::shared_ptr<MapInstance> map_instance;
std::vector<const mt::MapTplThing*>* mini_room_spawn_points = nullptr;
std::vector<const mt::MapTplThing*>* normal_room_spawn_points = nullptr;
std::vector<const mt::MapTplThing*>* room_monster_spawn_points = nullptr;
mt::MapTplThing* level0room_born_point_meta = nullptr;
const mt::MapTplThing* level1room_born_point_meta = nullptr;
std::vector<const mt::MapTplThing*>* loots = nullptr;
std::vector<const mt::MapTplThing*>* level0room_spec_things = nullptr;
std::shared_ptr<CustomBattle> custom_battle;
};
class Room;
class MatchTeam;
class RoomMgr : public a8::Singleton<RoomMgr>
{
public:
enum { HID = HID_RoomMgr };
private:
RoomMgr() {};
friend class a8::Singleton<RoomMgr>;
public:
void Init();
void UnInit();
void Update(int delta_time);
void _CMJoin(f8::MsgHdr* hdr, const cs::CMJoin& msg);
void _CMReconnect(f8::MsgHdr* hdr, const cs::CMReconnect& msg);
void _CMPing(f8::MsgHdr* hdr, const cs::CMPing& msg);
void ActiveRoom(const std::string& room_uuid);
int RoomNum();
int OverRoomNum();
std::shared_ptr<Room> GetRoomByUuid(const std::string& uuid);
void AddOverRoom(const std::string& room_uuid);
bool IsGM(const std::string& account_id);
void JoinTeam(MatchTeam* team);
void SendGetBattleData(int mode,
std::vector<std::shared_ptr<cs::CMJoin>>& join_msgs,
std::function<
void(std::vector<std::shared_ptr<BattleDataContext>>&)> cb);
int GetMatchMode() { return match_mode_; };
void SetMatchMode(int mode);
bool HasTask();
private:
void InstallReportStateTimer();
std::shared_ptr<Room> GetRoomByIdx(int room_idx);
std::shared_ptr<Room> GetJoinableRoom(const cs::CMJoin& msg,
const RoomType_e self_room_type,
int game_times,
int creator_register_time,
int proto_version,
int channel);
std::shared_ptr<Room> GetJoinableRoom(MatchTeam* team);
void ReportServerState(int instance_id, const std::string& host, int port);
void FreeOverRoom(const std::string& room_uuid);
bool IsLimitJoin();
int AllocRoomIdx();
std::shared_ptr<Room> CreateRoom(const cs::CMJoin& msg,
RoomType_e room_type,
int game_times,
int creator_register_time,
int creator_proto_version,
int creator_channel,
int map_id,
std::shared_ptr<CustomBattle> custom_battle);
void JoinErrorHandle(const cs::CMJoin& msg, int error_code, int socket_handle);
std::string GenTeamHashData(const std::string& team_uuid, std::map<std::string, std::string>* team_hash);
void OnJoinRoomOk(const cs::CMJoin& msg, Player* hum);
void TeamRoomTimeOut(const std::string& team_uuid);
void AdjustCMJoin(cs::CMJoin* msg);
std::shared_ptr<CustomBattle> GetCustomRoom(const std::string& room_uuid);
std::shared_ptr<CustomBattle> GetHisCustomRoom(const std::string& room_uuid);
void _CMJoinCustomBattle(f8::MsgHdr* hdr, const cs::CMJoin& msg);
void SendGetCustomBattleData(std::shared_ptr<cs::CMJoin> join_msg,
std::function<void(int, const std::string, std::shared_ptr<CustomBattle>)> cb);
private:
int current_room_idx_ = 0;
int match_mode_ = 0;
std::map<std::string, std::shared_ptr<Room>> inactive_room_hash_;
std::map<std::string, std::shared_ptr<Room>> room_hash_;
std::map<int, std::shared_ptr<Room>> room_idx_hash_;
std::map<std::string, std::shared_ptr<Room>> over_room_hash_;
f8::Attacher reportstate_timer_attacher_;
std::map<std::string, int> gm_hash_;
std::map<std::string, std::map<std::string, std::string>> team_room_hash_;
std::map<std::string, std::shared_ptr<CustomBattle>> custom_room_hash_;
std::map<std::string, std::shared_ptr<CustomBattle>> his_custom_room_hash_;
};