1
This commit is contained in:
parent
db4f0e676a
commit
4dbd4c8f94
@ -4,10 +4,9 @@
|
|||||||
#include "human.h"
|
#include "human.h"
|
||||||
#include "room.h"
|
#include "room.h"
|
||||||
#include "player.h"
|
#include "player.h"
|
||||||
|
#include "pbutils.h"
|
||||||
#include "mt/Param.h"
|
#include "mt/Param.h"
|
||||||
|
|
||||||
#include "cs_proto.pb.h"
|
|
||||||
|
|
||||||
bool RollMsgHintInfo::Replace(int idx, std::string& text)
|
bool RollMsgHintInfo::Replace(int idx, std::string& text)
|
||||||
{
|
{
|
||||||
switch (idx) {
|
switch (idx) {
|
||||||
@ -63,8 +62,8 @@ void KillMgr::OnHumanDead(Human* dead_hum, KillInfo* info)
|
|||||||
RollMsgHintInfo hint_info;
|
RollMsgHintInfo hint_info;
|
||||||
std::shared_ptr<cs::SMRollMsg> pb_msg = std::make_shared<cs::SMRollMsg>();
|
std::shared_ptr<cs::SMRollMsg> pb_msg = std::make_shared<cs::SMRollMsg>();
|
||||||
FillHintInfo(dead_hum, info, hint_info);
|
FillHintInfo(dead_hum, info, hint_info);
|
||||||
PreprocessRollMsg(pb_msg, hint_info);
|
PBUtils::KillMgr_PreprocessRollMsg(pb_msg, hint_info);
|
||||||
BoradcastRollMsg(dead_hum, info, 0, pb_msg);
|
PBUtils::KillMgr_BoradcastRollMsg(dead_hum, info, 0, pb_msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
void KillMgr::FillHintInfo(Human* dead_hum, KillInfo* info, RollMsgHintInfo& hint_info)
|
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
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void KillMgr::PreprocessRollMsg(std::shared_ptr<cs::SMRollMsg> 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<cs::SMRollMsg> pb_msg)
|
|
||||||
{
|
|
||||||
std::shared_ptr<KillInfo> info_copy = std::make_shared<KillInfo>();
|
|
||||||
*info_copy = *info;
|
|
||||||
std::shared_ptr<cs::SMRollMsg> pb_msg_copy = std::make_shared<cs::SMRollMsg>();
|
|
||||||
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<cs::SMRollMsg> 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;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
@ -44,14 +44,6 @@ class KillMgr : public a8::Singleton<KillMgr>
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void FillHintInfo(Human* dead_hum, KillInfo* info, RollMsgHintInfo& hint_info);
|
void FillHintInfo(Human* dead_hum, KillInfo* info, RollMsgHintInfo& hint_info);
|
||||||
void PreprocessRollMsg(std::shared_ptr<cs::SMRollMsg> pb_msg,
|
|
||||||
RollMsgHintInfo& hint_info);
|
friend class PBUtils;
|
||||||
void BoradcastRollMsg(Human* dead_hum,
|
|
||||||
KillInfo* info,
|
|
||||||
int killer_team_id,
|
|
||||||
std::shared_ptr<cs::SMRollMsg> pb_msg);
|
|
||||||
void BoradcastRollMsgCb(Human* dead_hum,
|
|
||||||
KillInfo* info,
|
|
||||||
int killer_team_id,
|
|
||||||
std::shared_ptr<cs::SMRollMsg> pb_msg);
|
|
||||||
};
|
};
|
||||||
|
@ -4,6 +4,12 @@
|
|||||||
|
|
||||||
#include "pbutils.h"
|
#include "pbutils.h"
|
||||||
#include "ability.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)
|
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<cs::SMRollMsg> 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<cs::SMRollMsg> pb_msg)
|
||||||
|
{
|
||||||
|
std::shared_ptr<KillInfo> info_copy = std::make_shared<KillInfo>();
|
||||||
|
*info_copy = *info;
|
||||||
|
std::shared_ptr<cs::SMRollMsg> pb_msg_copy = std::make_shared<cs::SMRollMsg>();
|
||||||
|
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<cs::SMRollMsg> 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;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
@ -9,6 +9,8 @@ namespace cs
|
|||||||
|
|
||||||
class Ability;
|
class Ability;
|
||||||
class Human;
|
class Human;
|
||||||
|
struct KillInfo;
|
||||||
|
struct RollMsgHintInfo;
|
||||||
class PBUtils
|
class PBUtils
|
||||||
{
|
{
|
||||||
public:
|
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::MFActivePlayerData* player_data);
|
||||||
static void Ability_FillMFAttrAdditionList(Ability* self, Human* hum, cs::MFPlayerFull* full_data);
|
static void Ability_FillMFAttrAdditionList(Ability* self, Human* hum, cs::MFPlayerFull* full_data);
|
||||||
|
|
||||||
|
static void KillMgr_PreprocessRollMsg(std::shared_ptr<cs::SMRollMsg> pb_msg,
|
||||||
|
RollMsgHintInfo& hint_info);
|
||||||
|
static void KillMgr_BoradcastRollMsg(Human* dead_hum,
|
||||||
|
KillInfo* info,
|
||||||
|
int killer_team_id,
|
||||||
|
std::shared_ptr<cs::SMRollMsg> pb_msg);
|
||||||
|
static void KillMgr_BoradcastRollMsgCb(Human* dead_hum,
|
||||||
|
KillInfo* info,
|
||||||
|
int killer_team_id,
|
||||||
|
std::shared_ptr<cs::SMRollMsg> pb_msg);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static void _Ability_FillMFAttrAdditionList
|
static void _Ability_FillMFAttrAdditionList
|
||||||
(Ability* self,
|
(Ability* self,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user