diff --git a/server/gameserver/car.cc b/server/gameserver/car.cc index 1628cbae..bbe08ba2 100644 --- a/server/gameserver/car.cc +++ b/server/gameserver/car.cc @@ -502,6 +502,7 @@ void Car::BeKill(int killer_id, const std::string& killer_name, int weapon_id) ); room->NotifyUiUpdate(); room->frame_event.AddDead(GetWeakPtrRef(), 0); + AllocDeadExp(killer_id); GetTrigger()->Die(killer_id, weapon_id); } diff --git a/server/gameserver/creature.cc b/server/gameserver/creature.cc index 9ce21de0..485d84cb 100644 --- a/server/gameserver/creature.cc +++ b/server/gameserver/creature.cc @@ -4047,3 +4047,31 @@ void Creature::GenLevelAttr() } } } + +void Creature::AllocDeadExp(int real_killer_id) +{ + Creature* killer = room->GetCreatureByUniId(real_killer_id); + if (killer && GetHeroGrowMeta() && + GetHeroGrowMeta()->lootExp() > 0) { + Human* real_killer = nullptr; + if (killer->IsHuman()) { + real_killer = killer->AsHuman(); + } else if (killer->IsHero() && killer->master.Get() && killer->master.Get()->IsHuman()) { + real_killer = killer->master.Get()->AsHuman(); + } + real_killer->WinExp(GetHeroGrowMeta()->lootExp() * mt::Param::s().battle_gain_exp_rate_killer); + real_killer->AsHuman()->GetTeam()->TraverseMembers + ( + [this, real_killer] (Human* hum) -> bool + { + if (real_killer != hum) { + if (GetPos().Distance2D2(hum->GetPos().ToGlmVec3()) < + mt::Param::s().battle_gain_exp_radium) { + hum->WinExp(GetHeroGrowMeta()->lootExp() * + mt::Param::s().battle_gain_exp_rate_teammate); + } + } + return true; + }); + } +} diff --git a/server/gameserver/creature.h b/server/gameserver/creature.h index 1d155cc4..18af2ca0 100644 --- a/server/gameserver/creature.h +++ b/server/gameserver/creature.h @@ -359,6 +359,7 @@ class Creature : public MoveableEntity int GetHeroExp(); int GetHeroMaxExp(); void WinExp(int win_exp); + void AllocDeadExp(int real_killer_id); void RecalcDtoAttr(); void AutoNavigation(const glm::vec3& target_pos, float speed, std::function cb); diff --git a/server/gameserver/hero.cc b/server/gameserver/hero.cc index 71176b3d..72b39610 100644 --- a/server/gameserver/hero.cc +++ b/server/gameserver/hero.cc @@ -369,6 +369,7 @@ void Hero::BeKill(int killer_id, const std::string& killer_name, int weapon_id) room->pve_data.OnBeKill(this); room->NotifyUiUpdate(); } + AllocDeadExp(killer_id); GetTrigger()->Die(killer_id, weapon_id); } diff --git a/server/gameserver/human.cc b/server/gameserver/human.cc index 1386c9df..c2ea43f4 100644 --- a/server/gameserver/human.cc +++ b/server/gameserver/human.cc @@ -1579,32 +1579,7 @@ void Human::OnDie() real_dead_frameno = room->GetFrameNo(); room->OnHumanDie(this); SyncAroundPlayers(__FILE__, __LINE__, __func__); - { - Creature* killer = room->GetCreatureByUniId(stats->killer_id); - if (killer && GetHeroGrowMeta() && - GetHeroGrowMeta()->lootExp() > 0) { - Human* real_killer = nullptr; - if (killer->IsHuman()) { - real_killer = killer->AsHuman(); - } else if (killer->IsHero() && killer->master.Get() && killer->master.Get()->IsHuman()) { - real_killer = killer->master.Get()->AsHuman(); - } - real_killer->WinExp(GetHeroGrowMeta()->lootExp() * mt::Param::s().battle_gain_exp_rate_killer); - real_killer->AsHuman()->GetTeam()->TraverseMembers - ( - [this, real_killer] (Human* hum) -> bool - { - if (real_killer != hum) { - if (GetPos().Distance2D2(hum->GetPos().ToGlmVec3()) < - mt::Param::s().battle_gain_exp_radium) { - hum->WinExp(GetHeroGrowMeta()->lootExp() * - mt::Param::s().battle_gain_exp_rate_teammate); - } - } - return true; - }); - } - } + AllocDeadExp(stats->killer_id); if (GetTeam()) { GetTeam()->TraverseMembers (