From ddf18e76f417c2590bf6732094c28cc2828ebd25 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Mon, 31 May 2021 17:13:08 +0800 Subject: [PATCH] =?UTF-8?q?=E6=AD=BB=E4=BA=A1=E5=AF=8C=E6=96=87=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/gameserver/human.cc | 32 ++++++++++++++++++++------------ server/gameserver/human.h | 2 +- server/gameserver/types.h | 8 ++++++++ 3 files changed, 29 insertions(+), 13 deletions(-) diff --git a/server/gameserver/human.cc b/server/gameserver/human.cc index 7353d72..2672837 100644 --- a/server/gameserver/human.cc +++ b/server/gameserver/human.cc @@ -760,7 +760,7 @@ void Human::BeKill(int killer_id, const std::string& killer_name, int weapon_id) equip_meta->i->name(), name }); - SendRollMsg(msg, killer->GetEntityUniId(), killer->team_id); + SendRollMsg(msg, killer->GetEntityUniId(), killer->team_id, weapon_id); } } } @@ -1522,39 +1522,45 @@ void Human::SendDebugMsg(const std::string& debug_msg) SendNotifyMsg(notify_msg); } -void Human::SendRollMsg(const std::string& msg, int killer_id, bool killer_team_id) +void Human::SendRollMsg(const std::string& msg, int killer_id, bool killer_team_id, int weapon_id) { + KillInfo* info = new KillInfo; + info->killer_id = killer_id; + info->killer_team_id = killer_team_id; + info->weapon_id = weapon_id; + info->msg = msg; room->xtimer.AddDeadLineTimerAndAttach ( 0, a8::XParams() .SetSender(this) - .SetParam1(killer_id) - .SetParam2(killer_team_id) - .SetParam3(msg), + .SetParam1(info), [] (const a8::XParams& param) { Human* target = (Human*)param.sender.GetUserData(); - int killer_id = param.param1; - int killer_team_id = param.param2; - std::string text = param.param3.GetString(); + KillInfo* info = (KillInfo*)param.param1.GetUserData(); target->room->TraversePlayerList (a8::XParams(), - [target, killer_id, killer_team_id, text] (Human* hum, a8::XParams& param) -> bool + [target, info] (Human* hum, a8::XParams& param) -> bool { cs::SMRollMsg msg; auto element = msg.add_elements(); element->set_element_type(1); - element->mutable_union_obj_1()->set_text(text); - if (killer_id == hum->GetEntityUniId()){ + element->mutable_union_obj_1()->set_text(info->msg); + if (info->killer_id == hum->GetEntityUniId()){ element->mutable_union_obj_1()->set_color(MetaMgr::Instance()->self_kill_color); - } else if (killer_team_id == hum->team_id) { + } 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); } + if (info->weapon_id != 0) { + auto img_element = msg.add_elements(); + img_element->set_element_type(2); + img_element->mutable_union_obj_2()->set_id(info->weapon_id); + } hum->SendNotifyMsg(msg); return true; }); @@ -1562,6 +1568,8 @@ void Human::SendRollMsg(const std::string& msg, int killer_id, bool killer_team_ &xtimer_attacher.timer_list_, [] (const a8::XParams& param) { + KillInfo* info = (KillInfo*)param.param1.GetUserData(); + delete info; } ); } diff --git a/server/gameserver/human.h b/server/gameserver/human.h index d0f1e50..56dd8eb 100644 --- a/server/gameserver/human.h +++ b/server/gameserver/human.h @@ -211,7 +211,7 @@ class Human : public Creature void SendGameOver(); void FollowTarget(Human* target); virtual void SendDebugMsg(const std::string& debug_msg) override; - void SendRollMsg(const std::string& msg, int killer_id, bool killer_team_id); + void SendRollMsg(const std::string& msg, int killer_id, bool killer_team_id, int weapon_id = 0); void UpdateAction(); void SendUIUpdate(); void SendWxVoip(); diff --git a/server/gameserver/types.h b/server/gameserver/types.h index 6d90db2..4441696 100755 --- a/server/gameserver/types.h +++ b/server/gameserver/types.h @@ -153,6 +153,14 @@ struct ObstacleData DoorState_e door_state = DoorStateClose; }; +struct KillInfo +{ + int killer_id = 0; + int killer_team_id = 0; + int weapon_id = 0; + std::string msg; +}; + #pragma pack(1) struct ObjectSyncFlags {