This commit is contained in:
aozhiwei 2022-10-26 17:58:32 +08:00
parent 56a073aea8
commit 43997995f4
2 changed files with 29 additions and 0 deletions

View File

@ -8,6 +8,7 @@
#include "creature.h" #include "creature.h"
#include "collider.h" #include "collider.h"
#include "roomobstacle.h" #include "roomobstacle.h"
#include "human.h"
float VirtualBullet::GetStrengthenWall() float VirtualBullet::GetStrengthenWall()
{ {
@ -273,7 +274,23 @@ void VirtualBullet::ForceRemove()
void VirtualBullet::OnHit(std::set<Entity*>& objects) void VirtualBullet::OnHit(std::set<Entity*>& objects)
{ {
std::shared_ptr<Ability> 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() 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);
}
}
}

View File

@ -7,6 +7,7 @@ namespace MetaData
} }
struct GridCell; struct GridCell;
class Entity;
class Room; class Room;
class Obstacle; class Obstacle;
class VirtualBullet : public IBullet, public ITask class VirtualBullet : public IBullet, public ITask
@ -51,6 +52,7 @@ class VirtualBullet : public IBullet, public ITask
std::set<GridCell*>& GetGridList() { return grid_list_; }; std::set<GridCell*>& GetGridList() { return grid_list_; };
bool TestCollision(Room* room, ColliderComponent* b); bool TestCollision(Room* room, ColliderComponent* b);
void OnStrengthen(Obstacle* ob); void OnStrengthen(Obstacle* ob);
void OnKillTarget(Entity* target);
private: private:
bool later_removed_ = false; bool later_removed_ = false;