diff --git a/server/gameserver/killmgr.cc b/server/gameserver/killmgr.cc index 742b795..3fa7118 100644 --- a/server/gameserver/killmgr.cc +++ b/server/gameserver/killmgr.cc @@ -2,6 +2,11 @@ #include "killmgr.h" #include "human.h" +#include "metamgr.h" +#include "room.h" +#include "player.h" + +#include "cs_proto.pb.h" void KillMgr::Init() { @@ -180,53 +185,76 @@ void KillMgr::OnHumanDead(Human* dead_hum, KillInfo* info) element->mutable_union_obj_1()->set_text(result); } } +#endif +} +void KillMgr::BoradcastRollMsg(Human* dead_hum, + KillInfo* info, + int killer_team_id, + cs::SMRollMsg* pb_msg) +{ KillInfo* info_copy = new KillInfo; - *info_copy = info; - room->xtimer.AddDeadLineTimerAndAttach + *info_copy = *info; + dead_hum->room->xtimer.AddDeadLineTimerAndAttach ( 0, a8::XParams() - .SetSender(this) + .SetSender(dead_hum) .SetParam1(info_copy) - .SetParam2(pb_msg), + .SetParam2(pb_msg) + .SetParam3(killer_team_id), [] (const a8::XParams& param) { - Human* target = (Human*)param.sender.GetUserData(); + Human* dead_hum = (Human*)param.sender.GetUserData(); KillInfo* info = (KillInfo*)param.param1.GetUserData(); - cs::SMRollMsg* msg = (cs::SMRollMsg*)param.param2.GetUserData(); - target->room->TraversePlayerList - (a8::XParams(), - [target, info, &msg] (Human* hum, a8::XParams& param) -> bool - { - for (int i = 0; i < msg->elements_size(); ++i) { - auto element = msg->mutable_elements(i); - if (element->element_type() == 1) { - if (info->killer_id == hum->GetUniId()){ - element->mutable_union_obj_1()->set_color(MetaMgr::Instance()->self_kill_color); - } else if (info->killer_team_id == hum->team_id) { - element->mutable_union_obj_1()->set_color(MetaMgr::Instance()->teammate_kill_color); - } else if (target == hum) { - element->mutable_union_obj_1()->set_color(MetaMgr::Instance()->self_bekill_color); - } else if (target->team_id == hum->team_id) { - element->mutable_union_obj_1()->set_color(MetaMgr::Instance()->teammate_bekill_color); - } else{ - element->mutable_union_obj_1()->clear_color(); - } - } - } - hum->SendNotifyMsg(*msg); - return true; - }); + cs::SMRollMsg* pb_msg = (cs::SMRollMsg*)param.param2.GetUserData(); + int killer_team_id = param.param3; + KillMgr::Instance()->BoradcastRollMsgCb + (dead_hum, + info, + killer_team_id, + pb_msg); }, - &xtimer_attacher.timer_list_, + &dead_hum->xtimer_attacher.timer_list_, [] (const a8::XParams& param) { KillInfo* info = (KillInfo*)param.param1.GetUserData(); - cs::SMRollMsg* msg = (cs::SMRollMsg*)param.param2.GetUserData(); - delete msg; + cs::SMRollMsg* pb_msg = (cs::SMRollMsg*)param.param2.GetUserData(); + delete pb_msg; delete info; } ); -#endif +} + +void KillMgr::BoradcastRollMsgCb(Human* dead_hum, + KillInfo* info, + int killer_team_id, + cs::SMRollMsg* pb_msg) +{ + dead_hum->room->TraversePlayerList + (a8::XParams(), + [dead_hum, info, &pb_msg, killer_team_id] + (Player* hum, a8::XParams& param) -> bool + { + for (int i = 0; i < pb_msg->elements_size(); ++i) { + auto element = pb_msg->mutable_elements(i); + if (element->element_type() == 1) { + int color = element->mutable_union_obj_1()->color(); + if (info->killer_id == hum->GetUniId()){ + color = MetaMgr::Instance()->self_kill_color; + } else if (killer_team_id == hum->team_id) { + color = MetaMgr::Instance()->teammate_kill_color; + } else if (dead_hum == hum) { + color = MetaMgr::Instance()->self_bekill_color; + } else if (dead_hum->team_id == hum->team_id) { + color = MetaMgr::Instance()->teammate_bekill_color; + } + if (element->mutable_union_obj_1()->color() != color) { + element->mutable_union_obj_1()->set_color(color); + } + } + } + hum->SendNotifyMsg(*pb_msg); + return true; + }); } diff --git a/server/gameserver/killmgr.h b/server/gameserver/killmgr.h index eb21cc9..4b9ea75 100644 --- a/server/gameserver/killmgr.h +++ b/server/gameserver/killmgr.h @@ -1,6 +1,9 @@ #pragma once -#include +namespace cs +{ + class SMRollMsg; +} struct KillInfo { @@ -22,4 +25,14 @@ class KillMgr : public a8::Singleton void Init(); void UnInit(); void OnHumanDead(Human* dead_hum, KillInfo* info); + +private: + void BoradcastRollMsg(Human* dead_hum, + KillInfo* info, + int killer_team_id, + cs::SMRollMsg* pb_msg); + void BoradcastRollMsgCb(Human* dead_hum, + KillInfo* info, + int killer_team_id, + cs::SMRollMsg* pb_msg); };