This commit is contained in:
aozhiwei 2019-05-07 14:19:54 +08:00
parent 6a30ba3375
commit 568e7449b4
9 changed files with 44 additions and 3 deletions

View File

@ -50,6 +50,7 @@ void HandlerMgr::RegisterNetMsgHandlers()
RegisterNetMsgHandler(&ggmsghandler, &Player::_CMVoice); RegisterNetMsgHandler(&ggmsghandler, &Player::_CMVoice);
RegisterNetMsgHandler(&ggmsghandler, &Player::_CMGameOver); RegisterNetMsgHandler(&ggmsghandler, &Player::_CMGameOver);
RegisterNetMsgHandler(&ggmsghandler, &Player::_CMWatchWar); RegisterNetMsgHandler(&ggmsghandler, &Player::_CMWatchWar);
RegisterNetMsgHandler(&ggmsghandler, &Player::_CMLeave);
} }
void HandlerMgr::ProcGMMsg(unsigned long saddr, int sockhandle, void HandlerMgr::ProcGMMsg(unsigned long saddr, int sockhandle,

View File

@ -434,7 +434,9 @@ void Human::FillSMGameOver(cs::SMGameOver& msg)
room->TouchHumanList(a8::XParams(), room->TouchHumanList(a8::XParams(),
[&human_list] (Human* hum, a8::XParams& param) -> bool [&human_list] (Human* hum, a8::XParams& param) -> bool
{ {
human_list.push_back(hum); if (hum->leave_frameno_ == 0 || hum->leave_frameno_ > hum->room->battle_start_frameno_) {
human_list.push_back(hum);
}
return true; return true;
}); });
std::sort(human_list.begin(), human_list.end(), std::sort(human_list.begin(), human_list.end(),
@ -529,13 +531,13 @@ void Human::BeKill(int killer_id, const std::string& killer_name, int weapon_id)
} }
} }
} }
if (!HasLiveTeammate()) { if (!HasLiveTeammate() && !leave_) {
if (team_members) { if (team_members) {
for (auto& member : *team_members) { for (auto& member : *team_members) {
member->SendGameOver(); member->SendGameOver();
} }
} else { } else {
SendGameOver(); SendGameOver();
} }
} }
} }

View File

@ -186,6 +186,8 @@ protected:
long long reflect_damage_frameno_ = 0; long long reflect_damage_frameno_ = 0;
long long summon_hero_frameno_ = 0; long long summon_hero_frameno_ = 0;
a8::XTimerAttacher skill_xtimer_attacher_; a8::XTimerAttacher skill_xtimer_attacher_;
bool leave_ = false;
long long leave_frameno_ = 0;
std::array<int, IS_END - 1> inventory_ = {}; std::array<int, IS_END - 1> inventory_ = {};
std::array<int, IS_END> volume_ = {}; std::array<int, IS_END> volume_ = {};

View File

@ -993,3 +993,17 @@ void Player::_CMWatchWar(f8::MsgHdr& hdr, const cs::CMWatchWar& msg)
SendNotifyMsg(respmsg); SendNotifyMsg(respmsg);
} }
} }
void Player::_CMLeave(f8::MsgHdr& hdr, const cs::CMLeave& msg)
{
if (!leave_) {
if (room->BattleStarted()) {
//如果战斗已经开始算自杀
BeKill(entity_uniid, name, VW_Spectate);
}
leave_ = true;
leave_frameno_ = room->frame_no;
}
cs::SMLeave respmsg;
SendNotifyMsg(respmsg);
}

View File

@ -90,5 +90,6 @@ class Player : public Human
void _CMVoice(f8::MsgHdr& hdr, const cs::CMVoice& msg); void _CMVoice(f8::MsgHdr& hdr, const cs::CMVoice& msg);
void _CMGameOver(f8::MsgHdr& hdr, const cs::CMGameOver& msg); void _CMGameOver(f8::MsgHdr& hdr, const cs::CMGameOver& msg);
void _CMWatchWar(f8::MsgHdr& hdr, const cs::CMWatchWar& msg); void _CMWatchWar(f8::MsgHdr& hdr, const cs::CMWatchWar& msg);
void _CMLeave(f8::MsgHdr& hdr, const cs::CMLeave& msg);
}; };

View File

@ -614,6 +614,11 @@ Human* Room::GetWatchWarTarget(Human* hum)
return nullptr; return nullptr;
} }
bool Room::BattleStarted()
{
return battle_start_frameno_ != 0;
}
int Room::NewTeam() int Room::NewTeam()
{ {
++current_teamid; ++current_teamid;
@ -757,6 +762,7 @@ void Room::UpdateGas()
} }
gas_data.rad_old = gas_data.old_area_meta->i->rad(); gas_data.rad_old = gas_data.old_area_meta->i->rad();
gas_data.rad_new = gas_data.new_area_meta->i->rad(); gas_data.rad_new = gas_data.new_area_meta->i->rad();
battle_start_frameno_ = frame_no;
} }
} }
break; break;

View File

@ -43,6 +43,7 @@ public:
a8::XTimer xtimer; a8::XTimer xtimer;
Plane plane; Plane plane;
GridService grid_service; GridService grid_service;
long long battle_start_frameno_ = 0;
~Room(); ~Room();
void Init(); void Init();
@ -83,6 +84,7 @@ public:
void OnHumanDie(Human* hum); void OnHumanDie(Human* hum);
bool OverBorder(const Vector2D pos, float radius); bool OverBorder(const Vector2D pos, float radius);
Human* GetWatchWarTarget(Human* hum); Human* GetWatchWarTarget(Human* hum);
bool BattleStarted();
private: private:
unsigned short AllocUniid(); unsigned short AllocUniid();

View File

@ -11,6 +11,7 @@ enum CMMessageId_e
_CMVoice = 206; _CMVoice = 206;
_CMGameOver = 207; _CMGameOver = 207;
_CMWatchWar = 208; _CMWatchWar = 208;
_CMLeave = 209;
} }
enum SMMessageId_e enum SMMessageId_e
@ -19,6 +20,7 @@ enum SMMessageId_e
_SMRpcError = 102; _SMRpcError = 102;
_SMWatchWar = 208; _SMWatchWar = 208;
_SMLeave = 209;
_SMJoinedNotify = 103; _SMJoinedNotify = 103;
_SMMapInfo = 1002; _SMMapInfo = 1002;

View File

@ -657,6 +657,12 @@ message CMWatchWar
} }
//
message CMLeave
{
}
//endcmmsg //endcmmsg
//error_code == 0 , //error_code == 0 ,
@ -741,6 +747,11 @@ message SMGameOver
repeated MFPlayerStats player_stats = 6; // repeated MFPlayerStats player_stats = 6; //
} }
//
message SMLeave
{
}
//线 //线
message SMDisconnectNotify message SMDisconnectNotify
{ {