This commit is contained in:
aozhiwei 2023-05-23 19:56:49 +08:00
parent 644c1a5c45
commit d3812d7ed7
3 changed files with 25 additions and 9 deletions

View File

@ -4,11 +4,13 @@
#include "human.h" #include "human.h"
#include "room.h" #include "room.h"
#include "player.h" #include "player.h"
#include "mt/Param.h" #include "mt/Param.h"
#include "mt/Text.h" #include "mt/Text.h"
#include "mt/Equip.h" #include "mt/Equip.h"
#include "mt/Hero.h"
bool RollMsgHintInfo::Replace(int idx, std::string& text) bool RollMsgHintInfo::Replace(Room* room, int idx, std::string& text)
{ {
switch (idx) { switch (idx) {
case kFieldIdxMasterName: case kFieldIdxMasterName:
@ -23,7 +25,10 @@ bool RollMsgHintInfo::Replace(int idx, std::string& text)
break; break;
case kFieldIdxKillerHeroId: case kFieldIdxKillerHeroId:
{ {
text = killer_name; Human* hum = room->GetHumanByUniId(killer_id);
if (hum) {
text = a8::XValue(hum->meta->id()).GetString();
}
} }
break; break;
case kFieldIdxDeadName: case kFieldIdxDeadName:
@ -33,7 +38,10 @@ bool RollMsgHintInfo::Replace(int idx, std::string& text)
break; break;
case kFieldIdxDeadHeroId: case kFieldIdxDeadHeroId:
{ {
text = dead_name; Human* hum = room->GetHumanByUniId(dead_id);
if (hum) {
text = a8::XValue(hum->meta->id()).GetString();
}
} }
break; break;
case kFieldIdxWeaponTextIcon: case kFieldIdxWeaponTextIcon:
@ -109,6 +117,8 @@ void KillMgr::FillHintInfo(Human* dead_hum, KillInfo* info, RollMsgHintInfo& hin
if (equip_meta) { if (equip_meta) {
hint_info.weapon_text_icon = equip_meta->text_icon(); hint_info.weapon_text_icon = equip_meta->text_icon();
} }
hint_info.dead_id = dead_hum->GetUniId();
hint_info.killer_id = info->killer_id;
hint_info.killer_name = killer->GetName(); hint_info.killer_name = killer->GetName();
if (info->killer_id == dead_hum->GetUniId()) { if (info->killer_id == dead_hum->GetUniId()) {
//${dead.name} 自杀 //${dead.name} 自杀

View File

@ -7,6 +7,8 @@ namespace cs
class SMRollMsg; class SMRollMsg;
} }
class Room;
struct KillInfo struct KillInfo
{ {
int root_master_id = 0; int root_master_id = 0;
@ -19,13 +21,15 @@ struct KillInfo
struct RollMsgHintInfo struct RollMsgHintInfo
{ {
int killer_id = 0;
int dead_id = 0;
std::string master_name; std::string master_name;
std::string killer_name; std::string killer_name;
std::string dead_name; std::string dead_name;
std::string weapon_text_icon; std::string weapon_text_icon;
std::vector<std::tuple<int, std::string>>* hint_template = nullptr; std::vector<std::tuple<int, std::string>>* hint_template = nullptr;
bool Replace(int idx, std::string& text); bool Replace(Room* room, int idx, std::string& text);
}; };
class Human; class Human;
@ -44,7 +48,8 @@ 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, void PreprocessRollMsg(Human* dead_hum,
std::shared_ptr<cs::SMRollMsg> pb_msg,
RollMsgHintInfo& hint_info); RollMsgHintInfo& hint_info);
void BoradcastRollMsg(Human* dead_hum, void BoradcastRollMsg(Human* dead_hum,
KillInfo* info, KillInfo* info,

View File

@ -178,12 +178,13 @@ 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); PreprocessRollMsg(dead_hum, pb_msg, hint_info);
BoradcastRollMsg(dead_hum, info, 0, pb_msg); BoradcastRollMsg(dead_hum, info, 0, pb_msg);
} }
void KillMgr::PreprocessRollMsg(std::shared_ptr<cs::SMRollMsg> pb_msg, void KillMgr::PreprocessRollMsg(Human* dead_hum,
RollMsgHintInfo& hint_info) std::shared_ptr<cs::SMRollMsg> pb_msg,
RollMsgHintInfo& hint_info)
{ {
if (hint_info.hint_template) { if (hint_info.hint_template) {
for (auto& tuple : *hint_info.hint_template) { for (auto& tuple : *hint_info.hint_template) {
@ -214,7 +215,7 @@ void KillMgr::PreprocessRollMsg(std::shared_ptr<cs::SMRollMsg> pb_msg,
default: default:
{ {
std::string text; std::string text;
if (hint_info.Replace(el_type, text)) { if (hint_info.Replace(dead_hum->room, el_type, text)) {
if (el_type == kFieldIdxWeaponTextIcon) { if (el_type == kFieldIdxWeaponTextIcon) {
auto e = pb_msg->add_elements(); auto e = pb_msg->add_elements();
e->set_element_type(kImageElement); e->set_element_type(kImageElement);