1
This commit is contained in:
parent
ddf18e76f4
commit
2d0c9ba3c1
@ -728,6 +728,9 @@ void Human::BeKill(int killer_id, const std::string& killer_name, int weapon_id)
|
||||
#ifdef DEBUG
|
||||
room->CheckPartObjects();
|
||||
#endif
|
||||
KillInfo info;
|
||||
info.killer_id = killer_id;
|
||||
info.weapon_id = weapon_id;
|
||||
if (!dead && !room->IsGameOver() && !real_dead) {
|
||||
lethal_weapon = weapon_id;
|
||||
Entity* hum = room->GetEntityByUniId(killer_id);
|
||||
@ -754,13 +757,17 @@ void Human::BeKill(int killer_id, const std::string& killer_name, int weapon_id)
|
||||
} else {
|
||||
MetaData::Equip* equip_meta = MetaMgr::Instance()->GetEquip(weapon_id);
|
||||
if (equip_meta) {
|
||||
std::string msg = a8::Format(TEXT("battle_server_dead_weapon", "%s 使用 %s 干掉了 %s").c_str(),
|
||||
{
|
||||
killer_name,
|
||||
equip_meta->i->name(),
|
||||
name
|
||||
});
|
||||
SendRollMsg(msg, killer->GetEntityUniId(), killer->team_id, weapon_id);
|
||||
info.killer_id = killer->GetEntityUniId();
|
||||
info.killer_team_id = killer->team_id;
|
||||
SendRollMsgEx
|
||||
(info,
|
||||
TEXT("battle_server_dead_weapon", "%s 使用 %s ${weapon_id} 干掉了 %s").c_str(),
|
||||
{
|
||||
killer_name,
|
||||
equip_meta->i->name(),
|
||||
name
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -3682,3 +3689,122 @@ void Human::OnBulletHit(Bullet* bullet)
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void Human::SendRollMsgEx(KillInfo& info,
|
||||
const char* fmt,
|
||||
std::initializer_list<a8::XValue> args
|
||||
)
|
||||
{
|
||||
cs::SMRollMsg *pb_msg = new cs::SMRollMsg;
|
||||
{
|
||||
std::string result;
|
||||
result.reserve(1024);
|
||||
const char *p = fmt;
|
||||
auto itr = args.begin();
|
||||
while (*p) {
|
||||
if (*p == '%' && *(p+1)) {
|
||||
p++;
|
||||
switch(*p){
|
||||
case 'd':
|
||||
{
|
||||
assert(itr != args.end());
|
||||
result.append(itr->GetString().c_str());
|
||||
itr++;
|
||||
}
|
||||
break;
|
||||
case 'f':
|
||||
{
|
||||
assert(itr != args.end());
|
||||
result.append(itr->GetString().c_str());
|
||||
itr++;
|
||||
}
|
||||
break;
|
||||
case 's':
|
||||
{
|
||||
assert(itr != args.end());
|
||||
result.append(itr->GetString().c_str());
|
||||
itr++;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{
|
||||
result.push_back('%');
|
||||
result.push_back(*p);
|
||||
}
|
||||
break;
|
||||
}
|
||||
} else if (*p == '$' && *(p+1)) {
|
||||
char* p1 = strstr((char*)p, "${weapon_id}");
|
||||
if (p1) {
|
||||
if (!result.empty()) {
|
||||
auto element = pb_msg->add_elements();
|
||||
element->set_element_type(1);
|
||||
element->mutable_union_obj_1()->set_text(result);
|
||||
}
|
||||
{
|
||||
auto element = pb_msg->add_elements();
|
||||
element->set_element_type(2);
|
||||
element->mutable_union_obj_2()->set_id(info.weapon_id);
|
||||
}
|
||||
result = "";
|
||||
} else {
|
||||
result.push_back(*p);
|
||||
}
|
||||
} else {
|
||||
result.push_back(*p);
|
||||
}
|
||||
p++;
|
||||
} //end while p
|
||||
if (!result.empty()) {
|
||||
auto element = pb_msg->add_elements();
|
||||
element->set_element_type(1);
|
||||
element->mutable_union_obj_1()->set_text(result);
|
||||
}
|
||||
}
|
||||
|
||||
KillInfo* info_copy = new KillInfo;
|
||||
*info_copy = info;
|
||||
room->xtimer.AddDeadLineTimerAndAttach
|
||||
(
|
||||
0,
|
||||
a8::XParams()
|
||||
.SetSender(this)
|
||||
.SetParam1(info_copy)
|
||||
.SetParam2(pb_msg),
|
||||
[] (const a8::XParams& param)
|
||||
{
|
||||
Human* target = (Human*)param.sender.GetUserData();
|
||||
KillInfo* info = (KillInfo*)param.param1.GetUserData();
|
||||
cs::SMRollMsg* msg = (cs::SMRollMsg*)param.param1.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->elements(i);
|
||||
if (element.element_type() == 1) {
|
||||
if (info->killer_id == hum->GetEntityUniId()){
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
hum->SendNotifyMsg(*msg);
|
||||
return true;
|
||||
});
|
||||
},
|
||||
&xtimer_attacher.timer_list_,
|
||||
[] (const a8::XParams& param)
|
||||
{
|
||||
KillInfo* info = (KillInfo*)param.param1.GetUserData();
|
||||
cs::SMRollMsg* msg = (cs::SMRollMsg*)param.param1.GetUserData();
|
||||
delete msg;
|
||||
delete info;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
@ -212,6 +212,10 @@ class Human : public Creature
|
||||
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, int weapon_id = 0);
|
||||
void SendRollMsgEx(KillInfo& info,
|
||||
const char* fmt,
|
||||
std::initializer_list<a8::XValue> args
|
||||
);
|
||||
void UpdateAction();
|
||||
void SendUIUpdate();
|
||||
void SendWxVoip();
|
||||
|
Loading…
x
Reference in New Issue
Block a user