添加匹配规则

This commit is contained in:
aozhiwei 2020-04-07 20:52:34 +08:00
parent 95150f6cfe
commit 2da781943b
6 changed files with 97 additions and 10 deletions

View File

@ -141,6 +141,10 @@ public:
MetaMgr::Instance()->horse_shoot_x = MetaMgr::Instance()->GetSysParamAsInt("horse_shoot_x");
MetaMgr::Instance()->horse_shoot_y = MetaMgr::Instance()->GetSysParamAsInt("horse_shoot_y");
MetaMgr::Instance()->max_mount_horse_distance = MetaMgr::Instance()->GetSysParamAsFloat("max_mount_horse_distance", 100);
MetaMgr::Instance()->newbie_game_times = MetaMgr::Instance()->GetSysParamAsInt("newbie_game_times", 5);
MetaMgr::Instance()->niube_win_times = MetaMgr::Instance()->GetSysParamAsInt("niube_win_times", 1);
MetaMgr::Instance()->newbie_fill_interval = MetaMgr::Instance()->GetSysParamAsInt("newbie_fill_interval", 5000);
MetaMgr::Instance()->other_fill_interval = MetaMgr::Instance()->GetSysParamAsInt("other_fill_interval", 2000);
if (MetaMgr::Instance()->K < 0.01f) {
abort();
}

View File

@ -60,6 +60,10 @@ class MetaMgr : public a8::Singleton<MetaMgr>
float horse_shoot_x = 0.0f;
float horse_shoot_y = 0.0f;
float max_mount_horse_distance = 100.0f;
int newbie_game_times = 0;
int niube_win_times = 0;
int newbie_fill_interval = 0;
int other_fill_interval = 0;
private:
MetaDataLoader* loader_ = nullptr;

View File

@ -186,6 +186,7 @@ void Room::AddPlayer(Player* hum)
moveable_hash_[hum->entity_uniid] = hum;
accountid_hash_[hum->account_id] = hum;
human_hash_[hum->entity_uniid] = hum;
last_add_player_tick = a8::XGetTickCount();
++alive_count_;
++App::Instance()->perf.alive_count;
grid_service.AddHuman(hum);
@ -749,11 +750,7 @@ bool Room::CanJoin(const std::string& accountid)
if (accountid_hash_.find(accountid) != accountid_hash_.end()) {
return false;
}
if (App::Instance()->HasFlag(5)) {
return accountid_hash_.size() < 1;
} else {
return accountid_hash_.size() < ROOM_MAX_PLAYER_NUM;
}
return accountid_hash_.size() < ROOM_MAX_PLAYER_NUM;
}
void Room::OnPlayerOffline(Player* hum)
@ -1583,6 +1580,19 @@ int Room::CreateAndTakeonCar(int car_id, a8::Vec2 pos)
return car_uniid;
}
bool Room::HaveMyTeam(const std::string& team_uuid)
{
if (team_uuid.empty()) {
return false;
}
for (auto& pair : accountid_hash_) {
if (pair.second->team_uuid == team_uuid) {
return true;
}
}
return false;
}
void Room::NotifyWxVoip()
{
xtimer.AddDeadLineTimerAndAttach(0,

View File

@ -17,6 +17,15 @@ namespace MetaData
struct MapTplThing;
}
enum RoomType_e
{
RT_FirstBrid = 0,
RT_NewBrid = 2,
RT_MidBrid = 3,
RT_OldBrid = 4,
RT_Max
};
struct timer_list;
struct xtimer_list;
class Entity;
@ -50,6 +59,8 @@ public:
long long last_debugout_tick = 0;
a8::Vec2 last_player_jump_pos;
bool waiting_start = false;
RoomType_e room_type = RT_NewBrid;
long long last_add_player_tick = 0;
~Room();
void Init();
@ -101,6 +112,7 @@ public:
void TakeOnCarObject(int car_uniid);
void TakeOffCarObject(int car_uniid, a8::Vec2 pos);
int CreateAndTakeonCar(int car_id, a8::Vec2 pos);
bool HaveMyTeam(const std::string& team_uuid);
private:
int AllocUniid();

View File

@ -21,6 +21,30 @@ const int ROOM_NUM_DOWN_LIMIT = 20;
const int ROOM_NUM_UP_LIMIT = 40;
const int HUM_NUM_DOWN_LIMIT = 500;
static RoomType_e GetHumanRoomType(const cs::CMJoin& msg)
{
std::vector<std::string> tmp_strings;
a8::Split(msg.pre_settlement_info(), tmp_strings, ',');
if (tmp_strings.size() < 3) {
return RT_FirstBrid;
}
//游戏次数,吃鸡数,击杀数
int game_times = a8::XValue(tmp_strings[0]);
int win_times = a8::XValue(tmp_strings[1]);
int kill_times = a8::XValue(tmp_strings[2]);
if (game_times <= 0) {
return RT_FirstBrid;
}
if (game_times <= MetaMgr::Instance()->newbie_game_times) {
return RT_NewBrid;
}
if (win_times <= MetaMgr::Instance()->niube_win_times) {
return RT_MidBrid;
} else {
return RT_OldBrid;
}
}
void RoomMgr::Init()
{
if (!App::Instance()->HasFlag(8)) {
@ -79,7 +103,7 @@ void RoomMgr::_CMJoin(f8::MsgHdr& hdr, const cs::CMJoin& msg)
});
return;
}
Room* room = GetJoinableRoom(msg.account_id());
Room* room = GetJoinableRoom(msg);
if (!room) {
room = new Room();
room->room_uuid = App::Instance()->NewUuid();
@ -121,11 +145,44 @@ int RoomMgr::OverRoomNum()
return over_room_hash_.size();
}
Room* RoomMgr::GetJoinableRoom(const std::string& account_id)
Room* RoomMgr::GetJoinableRoom(const cs::CMJoin& msg)
{
RoomType_e self_room_type = GetHumanRoomType(msg);
std::vector<std::vector<Room*>> group_rooms;
for (int i = 0; i < RT_Max; ++i) {
group_rooms.push_back(std::vector<Room*>());
}
for (auto& pair : inactive_room_hash_) {
if (pair.second->CanJoin(account_id)) {
return pair.second;
Room* room = pair.second;
if (room->CanJoin(msg.account_id())) {
if (!msg.team_uuid().empty() && room->HaveMyTeam(msg.team_uuid())) {
return room;
}
group_rooms[room->room_type].push_back(room);
}
}
if (!group_rooms[self_room_type].empty()) {
return group_rooms[self_room_type][rand() % group_rooms[self_room_type].size()];
}
if (self_room_type == RT_FirstBrid) {
return nullptr;
}
for (int i = 0; i < RT_Max; ++i) {
if (i != self_room_type) {
for (Room* room : group_rooms[i]) {
if (i <= RT_NewBrid) {
if (a8::XGetTickCount() - room->last_add_player_tick >
MetaMgr::Instance()->newbie_fill_interval) {
return room;
}
} else {
if (a8::XGetTickCount() - room->last_add_player_tick >
MetaMgr::Instance()->other_fill_interval) {
return room;
}
}
}
}
}
return nullptr;

View File

@ -31,7 +31,7 @@ class RoomMgr : public a8::Singleton<RoomMgr>
void InstallReportStateTimer();
private:
Room* GetJoinableRoom(const std::string& account_id);
Room* GetJoinableRoom(const cs::CMJoin& msg);
void ReportServerState(int instance_id, const std::string& host, int port);
void FreeOverRoom(long long room_uuid);
bool IsLimitJoin();