添加救援处理

This commit is contained in:
aozhiwei 2020-07-27 15:30:49 +08:00
parent 9578fe6f06
commit 0a1ce78fd6
3 changed files with 53 additions and 30 deletions

View File

@ -381,6 +381,9 @@ void Human::Shot(a8::Vec2& target_dir, bool& shot_ok)
if (!curr_weapon->meta) { if (!curr_weapon->meta) {
return; return;
} }
if (downed) {
return;
}
if (curr_weapon->weapon_idx != 0 && if (curr_weapon->weapon_idx != 0 &&
curr_weapon->ammo <= 0) { curr_weapon->ammo <= 0) {
@ -1066,25 +1069,26 @@ void Human::DecHP(float dec_hp, int killer_id, const std::string& killer_name, i
} }
#endif #endif
#endif #endif
auto downed_func = [] (const a8::XParams& param) auto downed_func =
{ [] (const a8::XParams& param)
Human* hum = (Human*)param.sender.GetUserData(); {
if (!hum->downed) { Human* hum = (Human*)param.sender.GetUserData();
hum->FreeDownedTimer(); if (!hum->downed) {
return; hum->FreeDownedTimer();
} return;
if (hum->dead) { }
hum->FreeDownedTimer(); if (hum->dead) {
return; hum->FreeDownedTimer();
} return;
if (!hum->HasLiveTeammate()) { }
hum->FreeDownedTimer(); if (!hum->HasLiveTeammate()) {
hum->BeKill(param.param1, param.param2, param.param3); hum->FreeDownedTimer();
return; hum->BeKill(param.param1, param.param2, param.param3);
} return;
int dec_hp = MetaMgr::Instance()->GetSysParamAsInt("downed_dec_hp"); }
hum->DecHP(dec_hp, param.param1, param.param2, param.param3); int dec_hp = MetaMgr::Instance()->GetSysParamAsInt("downed_dec_hp");
}; hum->DecHP(dec_hp, param.param1, param.param2, param.param3);
};
if (energy_shield > 0.001f) { if (energy_shield > 0.001f) {
energy_shield = std::max(0.0f, energy_shield - dec_hp); energy_shield = std::max(0.0f, energy_shield - dec_hp);
SyncAroundPlayers(__FILE__, __LINE__, __func__); SyncAroundPlayers(__FILE__, __LINE__, __func__);
@ -1114,16 +1118,17 @@ void Human::DecHP(float dec_hp, int killer_id, const std::string& killer_name, i
} }
CancelAction(); CancelAction();
DoGetDown(); DoGetDown();
downed_timer = room->xtimer.AddRepeatTimerAndAttach( downed_timer = room->xtimer.AddRepeatTimerAndAttach
SERVER_FRAME_RATE, (
a8::XParams() SERVER_FRAME_RATE,
.SetSender(this) a8::XParams()
.SetParam1(killer_id) .SetSender(this)
.SetParam2(killer_name) .SetParam1(killer_id)
.SetParam3(weapon_id), .SetParam2(killer_name)
downed_func, .SetParam3(weapon_id),
&xtimer_attacher.timer_list_ downed_func,
); &xtimer_attacher.timer_list_
);
SyncAroundPlayers(__FILE__, __LINE__, __func__); SyncAroundPlayers(__FILE__, __LINE__, __func__);
} else { } else {
BeKill(killer_id, killer_name, weapon_id); BeKill(killer_id, killer_name, weapon_id);
@ -1181,6 +1186,9 @@ void Human::RemoveOutObjects(Entity* entity)
bool Human::HasLiveTeammate() bool Human::HasLiveTeammate()
{ {
if (room->GetRoomMode() == kZombieMode) {
return true;
}
if (team_members) { if (team_members) {
for (auto& hum : *team_members) { for (auto& hum : *team_members) {
if (hum != this && !hum->dead) { if (hum != this && !hum->dead) {
@ -1193,6 +1201,10 @@ bool Human::HasLiveTeammate()
bool Human::HasNoDownedTeammate() bool Human::HasNoDownedTeammate()
{ {
if (room->GetRoomMode() == kZombieMode &&
GetRace() == kHumanRace) {
return true;
}
if (team_members) { if (team_members) {
for (auto& hum : *team_members) { for (auto& hum : *team_members) {
if (hum != this && !hum->dead && !hum->downed) { if (hum != this && !hum->dead && !hum->downed) {

View File

@ -568,7 +568,7 @@ void Room::OnHumanDie(Human* hum)
{ {
if (GetRoomMode() == kZombieMode) { if (GetRoomMode() == kZombieMode) {
if (hum->GetRace() == kHumanRace) { if (hum->GetRace() == kHumanRace) {
RemoveRescue(hum);
} else if (hum->GetRace() == kZombieRace) { } else if (hum->GetRace() == kZombieRace) {
} else { } else {
abort(); abort();
@ -3110,6 +3110,16 @@ void Room::FillObjectPositions(Human* hum, cs::SMUpdate& msg)
} }
} }
void Room::RemoveRescue(Human* hum)
{
for (auto& pair : human_hash_) {
if (pair.second != hum && pair.second->action_type == AT_Relive &&
pair.second->action_target_id == hum->GetEntityUniId()) {
pair.second->CancelAction();
}
}
}
size_t Room::GetRoomMaxPlayerNum() size_t Room::GetRoomMaxPlayerNum()
{ {
if (room_mode_ == kZombieMode) { if (room_mode_ == kZombieMode) {

View File

@ -134,6 +134,7 @@ public:
void AdjustPosInnerMap(a8::Vec2& pos, float radius); void AdjustPosInnerMap(a8::Vec2& pos, float radius);
bool IsMiniRoom(); bool IsMiniRoom();
void FillObjectPositions(Human* hum, cs::SMUpdate& msg); void FillObjectPositions(Human* hum, cs::SMUpdate& msg);
void RemoveRescue(Human* hum);
private: private:
int AllocUniid(); int AllocUniid();