diff --git a/server/gameserver/creature.h b/server/gameserver/creature.h index 8ccff61b..e0792776 100644 --- a/server/gameserver/creature.h +++ b/server/gameserver/creature.h @@ -383,6 +383,7 @@ private: std::map passive_skill_hash_; std::map buff_interval_hash_; std::array inventory_ = {}; + friend class Skill; friend class Trigger; }; diff --git a/server/gameserver/human.cc b/server/gameserver/human.cc index ad1847c0..65628edc 100644 --- a/server/gameserver/human.cc +++ b/server/gameserver/human.cc @@ -1234,6 +1234,12 @@ void Human::DecHP(float dec_hp, int killer_id, const std::string& killer_name, i if (HasBuffEffect(kBET_Invincible)) { return; } + { + Human* hum = room->GetHumanByUniId(real_killer_id); + if (hum) { + attacker_hash_[real_killer_id] = room->GetFrameNo(); + } + } struct DownedInfo { int killer_id = 0; @@ -4852,3 +4858,25 @@ void Human::NotifyTeamMarkTargetPos() }); } } + +void Human::CalcAssists(Human* target) +{ + if (GetTeam() && GetTeam()->GetMemberNum() > 1) { + GetTeam()->TraverseMembers + ( + [target, this] (Human* hum) + { + if (hum == this) { + return true; + } + auto itr = hum->attacker_hash_.find(target->GetUniId()); + if (itr != hum->attacker_hash_.end()) { + if (hum->room->GetFrameNo() - itr->second < + SERVER_FRAME_RATE * MetaMgr::Instance()->GetSysParamAsInt("assist_time", 5)) { + ++hum->stats.assist; + } + } + return true; + }); + } +} diff --git a/server/gameserver/human.h b/server/gameserver/human.h index ccbe2231..b5bba27c 100644 --- a/server/gameserver/human.h +++ b/server/gameserver/human.h @@ -364,6 +364,7 @@ class Human : public Creature void WinPveScore(int score); int GetTeamMode(); void NotifyTeamMarkTargetPos(); + void CalcAssists(Human* target); protected: void _InternalUpdateMove(float speed); @@ -453,4 +454,5 @@ private: long long jump_frameno_ = 0; float old_sync_speed = 0; + std::map attacker_hash_; }; diff --git a/server/gameserver/trigger.cc b/server/gameserver/trigger.cc index e75be0e7..341474cc 100644 --- a/server/gameserver/trigger.cc +++ b/server/gameserver/trigger.cc @@ -132,13 +132,12 @@ void Trigger::Shot(MetaData::Equip* weapon_meta) void Trigger::Kill(Creature* target, int weapon_id) { if (owner_->IsHuman() && target->IsHuman()) { -#if 1 + Human* owner_hum = owner_->AsHuman(); + Human* target_hum = target->AsHuman(); + owner_hum->CalcAssists(target_hum); if (target->GetUniId() != owner_->GetUniId()) { owner_->AsHuman()->stats.kills++; } -#else - owner_->AsHuman()->stats.kills++; -#endif owner_->AsHuman()->stats.last_kill_frameno = owner_->room->GetFrameNo(); owner_->AsHuman()->kill_humans.insert(target->AsHuman()); owner_->AsHuman()->SyncAroundPlayers(__FILE__, __LINE__, __func__);