diff --git a/server/gameserver/virtualbullet.cc b/server/gameserver/virtualbullet.cc index 7f362c71..7afd6893 100644 --- a/server/gameserver/virtualbullet.cc +++ b/server/gameserver/virtualbullet.cc @@ -8,6 +8,7 @@ #include "creature.h" #include "collider.h" #include "roomobstacle.h" +#include "human.h" float VirtualBullet::GetStrengthenWall() { @@ -273,7 +274,23 @@ void VirtualBullet::ForceRemove() void VirtualBullet::OnHit(std::set& objects) { + std::shared_ptr old_context_ability = sender.Get()->context_ability; + a8::Vec2 old_context_dir = sender.Get()->context_dir; + a8::Vec2 old_context_pos = sender.Get()->context_pos; + sender.Get()->context_dir = dir; + sender.Get()->context_pos = GetPos(); + for (auto& target : objects) { + bool old_is_dead = target->IsDead(room); + target->OnBulletHit(this); + if (target->IsDead(room) && !old_is_dead) { + OnKillTarget(target); + } + } + + sender.Get()->context_dir = old_context_dir; + sender.Get()->context_pos = old_context_pos; + sender.Get()->context_ability = old_context_ability; } void VirtualBullet::Init() @@ -311,3 +328,13 @@ void VirtualBullet::OnStrengthen(Obstacle* ob) } } } + +void VirtualBullet::OnKillTarget(Entity* target) +{ + if (target->IsCreature(room)) { + Creature* c = (Creature*)target; + if (c->IsHuman() && sender.Get() && sender.Get()->IsHuman()) { + sender.Get()->AsHuman()->stats.IncWeaponKills(gun_meta->i->id(), 1); + } + } +} diff --git a/server/gameserver/virtualbullet.h b/server/gameserver/virtualbullet.h index ee7756b7..a2430f78 100644 --- a/server/gameserver/virtualbullet.h +++ b/server/gameserver/virtualbullet.h @@ -7,6 +7,7 @@ namespace MetaData } struct GridCell; +class Entity; class Room; class Obstacle; class VirtualBullet : public IBullet, public ITask @@ -51,6 +52,7 @@ class VirtualBullet : public IBullet, public ITask std::set& GetGridList() { return grid_list_; }; bool TestCollision(Room* room, ColliderComponent* b); void OnStrengthen(Obstacle* ob); + void OnKillTarget(Entity* target); private: bool later_removed_ = false;