This commit is contained in:
aozhiwei 2021-08-31 15:55:05 +08:00
parent c3a3500b9b
commit cd55ba4e28
4 changed files with 231 additions and 247 deletions

View File

@ -254,7 +254,7 @@ void Human::FillMFObjectFull(Room* room, Human* hum, cs::MFObjectFull* full_data
"room.frameno:%d",
{
dead_frameno,
dead_times,
stats.dead_times,
room->AliveCount(),
room->GetFrameNo()
});
@ -670,141 +670,35 @@ void Human::FillSMGameOver(cs::SMGameOver& msg)
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);
if (hum && hum->IsEntityType(ET_Player)) {
Creature* killer = (Creature*)hum;
if (killer_id == GetUniId()) {
info.killer_id = killer->GetUniId();
info.killer_team_id = killer->team_id;
SendRollMsgEx(info,
TEXT("battle_server_dead_specate", "%s 自杀").c_str(),
{
killer_name
});
} else {
((Human*)hum)->stats.kills++;
((Human*)hum)->stats.last_kill_frameno = room->GetFrameNo();
((Human*)hum)->kill_humans.insert(this);
((Human*)hum)->SyncAroundPlayers(__FILE__, __LINE__, __func__);
((Human*)hum)->GetTrigger()->Kill(this);
if (weapon_id == VW_Tank) {
info.killer_id = killer->GetUniId();
info.killer_team_id = killer->team_id;
SendRollMsgEx
(info,
TEXT("battle_server_dead_car", "%s 使用 载具 干掉了 %s").c_str(),
{
killer_name,
name
});
} else {
info.killer_id = killer->GetUniId();
info.killer_team_id = killer->team_id;
SendRollMsgEx
(info,
TEXT("battle_server_dead_weapon", "%s 使用 ${weapon_text_icon} 干掉了 %s").c_str(),
{
killer_name,
name
}
);
}
}
} else {
switch (weapon_id) {
case VW_SafeArea:
{
SendRollMsgEx
(info,
TEXT("battle_server_dead_gas", "%s 被${weapon_text_icon}干掉").c_str(),
{
name
});
}
break;
case VW_Spectate:
{
SendRollMsgEx
(info,
TEXT("battle_server_dead_specate", "%s ${weapon_text_icon}").c_str(),
{
name
});
}
break;
case VW_SelfDetonate:
{
SendRollMsgEx
(info,
TEXT("battle_server_dead_self_detonate", "%s ${weapon_text_icon}").c_str(),
{
name
});
}
break;
case VW_Mine:
{
SendRollMsgEx
(info,
TEXT("battle_server_dead_mine", "%s ${weapon_text_icon}").c_str(),
{
name
});
}
break;
default:
{
}
break;
}
KillInfo info;
{
info.killer_id = killer_id;
info.killer_name = killer_name;
info.weapon_id = weapon_id;
}
{
++stats.dead_times;
stats.killer_id = killer_id;
stats.killer_name = killer_name;
stats.weapon_id = weapon_id;
}
++stats.dead_times;
stats.killer_id = killer_id;
stats.killer_name = killer_name;
stats.weapon_id = weapon_id;
GetTrigger()->Die();
{
dead = true;
real_dead = true;
downed = false;
SetHP(0.0f);
dead_frameno = room->GetFrameNo();
++dead_times;
if (HasBuffEffect(kBET_Camouflage)) {
RemoveBuffByEffectId(kBET_Camouflage);
}
ClearLordMode();
room->frame_event.AddDead(GetWeakPtrRef(),
0);
#ifdef DEBUG
room->CheckPartObjects();
#endif
#if 1
real_dead = true;
OnDie();
#else
int max_revive_times = MetaMgr::Instance()->GetSysParamAsInt("max_revive_times", 1);
if (weapon_id != VW_Spectate &&
dead_times <= max_revive_times &&
room->AliveCount() >= 5 &&
IsEntitySubType(EST_Player)) {
Revive();
} else {
real_dead = true;
OnDie();
}
#endif
DoGetDown();
#if 0
KillMgr::Instance()->OnHumanDead();
#endif
KillMgr::Instance()->OnHumanDead(this, &info);
room->frame_event.AddDead(GetWeakPtrRef(), 0);
}
}
}
@ -1845,7 +1739,7 @@ void Human::GenBattleReportData(a8::MutableXObject* params)
int pistol_kill = 0;
int submachine_kill = 0;
for (Human* hum : kill_humans) {
MetaData::Equip* equip_meta = MetaMgr::Instance()->GetEquip(hum->lethal_weapon);
MetaData::Equip* equip_meta = MetaMgr::Instance()->GetEquip(stats.weapon_id);
if (equip_meta) {
switch (equip_meta->i->equip_subtype()) {
case 7:
@ -3379,126 +3273,6 @@ void Human::SendRollMsgEx(KillInfo& info,
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_text_icon}");
if (p1) {
if (!result.empty()) {
auto element = pb_msg->add_elements();
element->set_element_type(1);
element->mutable_union_obj_1()->set_text(result);
}
MetaData::Equip* equip_meta = MetaMgr::Instance()->GetEquip(info.weapon_id);
if (equip_meta) {
auto element = pb_msg->add_elements();
element->set_element_type(2);
element->mutable_union_obj_2()->set_id(equip_meta->i->text_icon());
} else {
auto element = pb_msg->add_elements();
element->set_element_type(2);
element->mutable_union_obj_2()->set_id(info.weapon_id);
}
result = "";
p = p1 + strlen("${weapon_text_icon}") - 1;
} 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.param2.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->mutable_elements(i);
if (element->element_type() == 1) {
if (info->killer_id == hum->GetUniId()){
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);
} else{
element->mutable_union_obj_1()->clear_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.param2.GetUserData();
delete msg;
delete info;
}
);
}
void Human::ProcUseItem(int item_id)

View File

@ -109,7 +109,6 @@ class Human : public Creature
int max_energy_shield = 0;
int vip = 0;
int sdmg = 0;
int lethal_weapon = 0;
long long join_frameno = 0;
long long enable_frameno = 0;
int emoji1 = 0;
@ -117,7 +116,6 @@ class Human : public Creature
int parachute = 0;
bool has_pass = 0;
xtimer_list* revive_timer = nullptr;
int dead_times = 0;
long long dead_frameno = 0;
long long real_dead_frameno = 0;

View File

@ -15,5 +15,218 @@ void KillMgr::UnInit()
void KillMgr::OnHumanDead(Human* dead_hum, KillInfo* info)
{
#if 0
{
Entity* hum = room->GetEntityByUniId(killer_id);
if (hum && hum->IsEntityType(ET_Player)) {
Creature* killer = (Creature*)hum;
if (killer_id == GetUniId()) {
info.killer_id = killer->GetUniId();
info.killer_team_id = killer->team_id;
SendRollMsgEx(info,
TEXT("battle_server_dead_specate", "%s 自杀").c_str(),
{
killer_name
});
} else {
((Human*)hum)->stats.kills++;
((Human*)hum)->stats.last_kill_frameno = room->GetFrameNo();
((Human*)hum)->kill_humans.insert(this);
((Human*)hum)->SyncAroundPlayers(__FILE__, __LINE__, __func__);
((Human*)hum)->GetTrigger()->Kill(this);
if (weapon_id == VW_Tank) {
info.killer_id = killer->GetUniId();
info.killer_team_id = killer->team_id;
SendRollMsgEx
(info,
TEXT("battle_server_dead_car", "%s 使用 载具 干掉了 %s").c_str(),
{
killer_name,
name
});
} else {
info.killer_id = killer->GetUniId();
info.killer_team_id = killer->team_id;
SendRollMsgEx
(info,
TEXT("battle_server_dead_weapon", "%s 使用 ${weapon_text_icon} 干掉了 %s").c_str(),
{
killer_name,
name
}
);
}
}
} else {
switch (weapon_id) {
case VW_SafeArea:
{
SendRollMsgEx
(info,
TEXT("battle_server_dead_gas", "%s 被${weapon_text_icon}干掉").c_str(),
{
name
});
}
break;
case VW_Spectate:
{
SendRollMsgEx
(info,
TEXT("battle_server_dead_specate", "%s ${weapon_text_icon}").c_str(),
{
name
});
}
break;
case VW_SelfDetonate:
{
SendRollMsgEx
(info,
TEXT("battle_server_dead_self_detonate", "%s ${weapon_text_icon}").c_str(),
{
name
});
}
break;
case VW_Mine:
{
SendRollMsgEx
(info,
TEXT("battle_server_dead_mine", "%s ${weapon_text_icon}").c_str(),
{
name
});
}
break;
default:
{
}
break;
}
}
}
#endif
#if 0
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_text_icon}");
if (p1) {
if (!result.empty()) {
auto element = pb_msg->add_elements();
element->set_element_type(1);
element->mutable_union_obj_1()->set_text(result);
}
MetaData::Equip* equip_meta = MetaMgr::Instance()->GetEquip(info.weapon_id);
if (equip_meta) {
auto element = pb_msg->add_elements();
element->set_element_type(2);
element->mutable_union_obj_2()->set_id(equip_meta->i->text_icon());
} else {
auto element = pb_msg->add_elements();
element->set_element_type(2);
element->mutable_union_obj_2()->set_id(info.weapon_id);
}
result = "";
p = p1 + strlen("${weapon_text_icon}") - 1;
} 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.param2.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->mutable_elements(i);
if (element->element_type() == 1) {
if (info->killer_id == hum->GetUniId()){
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);
} else{
element->mutable_union_obj_1()->clear_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.param2.GetUserData();
delete msg;
delete info;
}
);
#endif
}

View File

@ -5,9 +5,8 @@
struct KillInfo
{
int killer_id = 0;
int killer_team_id = 0;
std::string killer_name;
int weapon_id = 0;
std::string msg;
};
class Human;