diff --git a/server/gameserver/killmgr.cc b/server/gameserver/killmgr.cc index cbc195c4..c10fc5a7 100644 --- a/server/gameserver/killmgr.cc +++ b/server/gameserver/killmgr.cc @@ -4,10 +4,9 @@ #include "human.h" #include "room.h" #include "player.h" +#include "pbutils.h" #include "mt/Param.h" -#include "cs_proto.pb.h" - bool RollMsgHintInfo::Replace(int idx, std::string& text) { switch (idx) { @@ -63,8 +62,8 @@ void KillMgr::OnHumanDead(Human* dead_hum, KillInfo* info) RollMsgHintInfo hint_info; std::shared_ptr pb_msg = std::make_shared(); FillHintInfo(dead_hum, info, hint_info); - PreprocessRollMsg(pb_msg, hint_info); - BoradcastRollMsg(dead_hum, info, 0, pb_msg); + PBUtils::KillMgr_PreprocessRollMsg(pb_msg, hint_info); + PBUtils::KillMgr_BoradcastRollMsg(dead_hum, info, 0, pb_msg); } void KillMgr::FillHintInfo(Human* dead_hum, KillInfo* info, RollMsgHintInfo& hint_info) @@ -135,105 +134,3 @@ void KillMgr::FillHintInfo(Human* dead_hum, KillInfo* info, RollMsgHintInfo& hin } #endif } - -void KillMgr::PreprocessRollMsg(std::shared_ptr pb_msg, - RollMsgHintInfo& hint_info) -{ - if (hint_info.hint_template) { - for (auto& tuple : *hint_info.hint_template) { - int el_type = std::get<0>(tuple); - std::string el_val = std::get<1>(tuple); - switch (el_type) { - case kTextElement: - { - auto e = pb_msg->add_elements(); - e->set_element_type(el_type); - e->mutable_union_obj_1()->set_text(el_val); - } - break; - case kImageElement: - { - auto e = pb_msg->add_elements(); - e->set_element_type(el_type); - e->mutable_union_obj_2()->set_id(a8::XValue(el_val)); - } - break; - default: - { - std::string text; - if (hint_info.Replace(el_type, text)) { - if (el_type == kFieldIdxWeaponTextIcon) { - auto e = pb_msg->add_elements(); - e->set_element_type(kImageElement); - e->mutable_union_obj_2()->set_id(a8::XValue(text)); - } else { - auto e = pb_msg->add_elements(); - e->set_element_type(kTextElement); - e->mutable_union_obj_1()->set_text(text); - } - } - } - break; - } - } - } -} - -void KillMgr::BoradcastRollMsg(Human* dead_hum, - KillInfo* info, - int killer_team_id, - std::shared_ptr pb_msg) -{ - std::shared_ptr info_copy = std::make_shared(); - *info_copy = *info; - std::shared_ptr pb_msg_copy = std::make_shared(); - pb_msg_copy = pb_msg; - dead_hum->room->xtimer.SetTimeoutEx - ( - 0, - [dead_hum, info_copy, pb_msg_copy, killer_team_id] - (int event, const a8::Args* args) mutable - { - if (a8::TIMER_EXEC_EVENT == event) { - KillMgr::Instance()->BoradcastRollMsgCb - (dead_hum, - info_copy.get(), - killer_team_id, - pb_msg_copy); - } - }, - &dead_hum->xtimer_attacher); -} - -void KillMgr::BoradcastRollMsgCb(Human* dead_hum, - KillInfo* info, - int killer_team_id, - std::shared_ptr pb_msg) -{ - dead_hum->room->TraversePlayerList - ( - [dead_hum, info, &pb_msg, killer_team_id] - (Player* hum) -> bool - { - for (int i = 0; i < pb_msg->elements_size(); ++i) { - auto element = pb_msg->mutable_elements(i); - if (element->element_type() == kTextElement) { - int color = element->mutable_union_obj_1()->color(); - if (info->killer_id == hum->GetUniId()){ - color = mt::Param::s().self_kill_color; - } else if (killer_team_id == hum->team_id) { - color = mt::Param::s().teammate_kill_color; - } else if (dead_hum == hum) { - color = mt::Param::s().self_bekill_color; - } else if (dead_hum->team_id == hum->team_id) { - color = mt::Param::s().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 727f07a7..c6e9386a 100644 --- a/server/gameserver/killmgr.h +++ b/server/gameserver/killmgr.h @@ -44,14 +44,6 @@ class KillMgr : public a8::Singleton private: void FillHintInfo(Human* dead_hum, KillInfo* info, RollMsgHintInfo& hint_info); - void PreprocessRollMsg(std::shared_ptr pb_msg, - RollMsgHintInfo& hint_info); - void BoradcastRollMsg(Human* dead_hum, - KillInfo* info, - int killer_team_id, - std::shared_ptr pb_msg); - void BoradcastRollMsgCb(Human* dead_hum, - KillInfo* info, - int killer_team_id, - std::shared_ptr pb_msg); + + friend class PBUtils; }; diff --git a/server/gameserver/pbutils.cc b/server/gameserver/pbutils.cc index 240a0ae1..806c4ebe 100644 --- a/server/gameserver/pbutils.cc +++ b/server/gameserver/pbutils.cc @@ -4,6 +4,12 @@ #include "pbutils.h" #include "ability.h" +#include "killmgr.h" +#include "room.h" +#include "player.h" +#include "human.h" + +#include "mt/Param.h" void PBUtils::Ability_FillMFAttrAdditionList(Ability* self, Human* hum, cs::MFActivePlayerData* player_data) { @@ -48,3 +54,105 @@ void PBUtils::_Ability_FillMFAttrAdditionList(Ability* self, } } } + +void PBUtils::KillMgr_PreprocessRollMsg(std::shared_ptr pb_msg, + RollMsgHintInfo& hint_info) +{ + if (hint_info.hint_template) { + for (auto& tuple : *hint_info.hint_template) { + int el_type = std::get<0>(tuple); + std::string el_val = std::get<1>(tuple); + switch (el_type) { + case kTextElement: + { + auto e = pb_msg->add_elements(); + e->set_element_type(el_type); + e->mutable_union_obj_1()->set_text(el_val); + } + break; + case kImageElement: + { + auto e = pb_msg->add_elements(); + e->set_element_type(el_type); + e->mutable_union_obj_2()->set_id(a8::XValue(el_val)); + } + break; + default: + { + std::string text; + if (hint_info.Replace(el_type, text)) { + if (el_type == kFieldIdxWeaponTextIcon) { + auto e = pb_msg->add_elements(); + e->set_element_type(kImageElement); + e->mutable_union_obj_2()->set_id(a8::XValue(text)); + } else { + auto e = pb_msg->add_elements(); + e->set_element_type(kTextElement); + e->mutable_union_obj_1()->set_text(text); + } + } + } + break; + } + } + } +} + +void PBUtils::KillMgr_BoradcastRollMsg(Human* dead_hum, + KillInfo* info, + int killer_team_id, + std::shared_ptr pb_msg) +{ + std::shared_ptr info_copy = std::make_shared(); + *info_copy = *info; + std::shared_ptr pb_msg_copy = std::make_shared(); + pb_msg_copy = pb_msg; + dead_hum->room->xtimer.SetTimeoutEx + ( + 0, + [dead_hum, info_copy, pb_msg_copy, killer_team_id] + (int event, const a8::Args* args) mutable + { + if (a8::TIMER_EXEC_EVENT == event) { + PBUtils::KillMgr_BoradcastRollMsgCb + (dead_hum, + info_copy.get(), + killer_team_id, + pb_msg_copy); + } + }, + &dead_hum->xtimer_attacher); +} + +void PBUtils::KillMgr_BoradcastRollMsgCb(Human* dead_hum, + KillInfo* info, + int killer_team_id, + std::shared_ptr pb_msg) +{ + dead_hum->room->TraversePlayerList + ( + [dead_hum, info, &pb_msg, killer_team_id] + (Player* hum) -> bool + { + for (int i = 0; i < pb_msg->elements_size(); ++i) { + auto element = pb_msg->mutable_elements(i); + if (element->element_type() == kTextElement) { + int color = element->mutable_union_obj_1()->color(); + if (info->killer_id == hum->GetUniId()){ + color = mt::Param::s().self_kill_color; + } else if (killer_team_id == hum->team_id) { + color = mt::Param::s().teammate_kill_color; + } else if (dead_hum == hum) { + color = mt::Param::s().self_bekill_color; + } else if (dead_hum->team_id == hum->team_id) { + color = mt::Param::s().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/pbutils.h b/server/gameserver/pbutils.h index 11bccbcf..e64652c2 100644 --- a/server/gameserver/pbutils.h +++ b/server/gameserver/pbutils.h @@ -9,6 +9,8 @@ namespace cs class Ability; class Human; +struct KillInfo; +struct RollMsgHintInfo; class PBUtils { public: @@ -16,6 +18,17 @@ class PBUtils static void Ability_FillMFAttrAdditionList(Ability* self, Human* hum, cs::MFActivePlayerData* player_data); static void Ability_FillMFAttrAdditionList(Ability* self, Human* hum, cs::MFPlayerFull* full_data); + static void KillMgr_PreprocessRollMsg(std::shared_ptr pb_msg, + RollMsgHintInfo& hint_info); + static void KillMgr_BoradcastRollMsg(Human* dead_hum, + KillInfo* info, + int killer_team_id, + std::shared_ptr pb_msg); + static void KillMgr_BoradcastRollMsgCb(Human* dead_hum, + KillInfo* info, + int killer_team_id, + std::shared_ptr pb_msg); + private: static void _Ability_FillMFAttrAdditionList (Ability* self,