add IBullet

This commit is contained in:
aozhiwei 2022-10-26 13:04:43 +08:00
parent 336f20614f
commit afa05474e2
22 changed files with 138 additions and 87 deletions

View File

@ -42,23 +42,27 @@ class Bullet : public MoveableEntity, public IBullet
virtual void Initialize() override;
virtual void Update(int delta_time) override;
void RecalcSelfCollider();
bool IsBomb();
float GetAtk();
float GetExplosionRange();
bool IsCurrWeapon();
bool IsPreBattleBullet();
void ForceRemove();
void OnHit(std::set<Entity*>& objects);
void TriggerHitBuff(Entity* e);
bool IsFlyHook();
protected:
Bullet();
virtual float GetStrengthenWall() override { return strengthen_wall; };
virtual long long GetWeaponUniId() override { return weapon_uniid; };
virtual MetaData::Skill* GetSkillMeta() override {return skill_meta; };
virtual MetaData::Equip* GetGunMeta() override { return gun_meta; };
virtual MetaData::Equip* GetBulletMeta() override { return meta; };
virtual CreatureWeakPtr GetSender() override { return sender; };
virtual CreatureWeakPtr GetPassenger() { return passenger; };
virtual bool IsBomb();
virtual bool IsPreBattleBullet();
virtual Room* GetRoom() { return room; };
protected:
Bullet();
private:

View File

@ -313,22 +313,22 @@ float Car::GetSpeed()
return speed;
}
void Car::OnBulletHit(Bullet* bullet)
void Car::OnBulletHit(IBullet* bullet)
{
if (!IsDead(room)) {
//超能电磁枪已删除
float finaly_dmg = bullet->sender.Get()->GetBattleContext()->CalcDmg(this, bullet);
if (bullet->meta->buff_meta) {
MustBeAddBuff(bullet->sender.Get(), bullet->meta->i->buffid());
float finaly_dmg = bullet->GetSender().Get()->GetBattleContext()->CalcDmg(this, bullet);
if (bullet->GetBulletMeta()->buff_meta) {
MustBeAddBuff(bullet->GetSender().Get(), bullet->GetBulletMeta()->i->buffid());
}
if (!bullet->IsPreBattleBullet()) {
DecHP(finaly_dmg,
bullet->sender.Get()->GetUniId(),
bullet->sender.Get()->GetName(),
bullet->gun_meta->i->id());
bullet->GetSender().Get()->GetUniId(),
bullet->GetSender().Get()->GetName(),
bullet->GetGunMeta()->i->id());
}
if (bullet->meta->buff_meta) {
MustBeAddBuff(this, bullet->meta->i->buffid());
if (bullet->GetBulletMeta()->buff_meta) {
MustBeAddBuff(this, bullet->GetBulletMeta()->i->buffid());
}
}
}

View File

@ -25,7 +25,7 @@ class Car : public Creature
virtual void Initialize() override;
virtual void FillMFObjectPart(Room* room, Human* hum, cs::MFObjectPart* part_data) override;
virtual void FillMFObjectFull(Room* room, Human* hum, cs::MFObjectFull* full_data) override;
virtual void OnBulletHit(Bullet* bullet) override;
virtual void OnBulletHit(IBullet* bullet) override;
virtual void OnExplosionHit(Explosion* e) override;
virtual void GetAabbBox(AabbCollider& aabb_box) override;
virtual void GetHitAabbBox(AabbCollider& aabb_box) override;

View File

@ -53,7 +53,7 @@ void DummyEntity::Initialize()
}
}
void DummyEntity::OnBulletHit(Bullet* bullet)
void DummyEntity::OnBulletHit(IBullet* bullet)
{
}

View File

@ -16,7 +16,7 @@ class DummyEntity : public Entity
std::list<metatable::MapBlockJson>* blocks = nullptr;
virtual void Initialize() override;
virtual void OnBulletHit(Bullet* bullet) override;
virtual void OnBulletHit(IBullet* bullet) override;
virtual void OnExplosionHit(Explosion* explosion) override;
};

View File

@ -21,7 +21,6 @@ class ColliderComponent;
class AabbCollider;
class CircleCollider;
class Human;
class Bullet;
class Explosion;
class Entity
{
@ -44,7 +43,7 @@ class Entity
virtual long long GetDeadFrameNo(Room* room) { return 0;};
virtual void OnPreCollision(Room* room) {};
virtual void RecalcSelfCollider() {};
virtual void OnBulletHit(Bullet* bullet) {};
virtual void OnBulletHit(IBullet* bullet) {};
virtual void OnExplosionHit(Explosion* explosion) {};
virtual void OnAddToTargetPartObject(Entity* target) {};
virtual void OnRemoveFromTargetPartObject(Entity* target) {};

View File

@ -118,7 +118,7 @@ void Hero::OnExplosionHit(Explosion* e)
e->GetExplosionEffect());
}
void Hero::OnBulletHit(Bullet* bullet)
void Hero::OnBulletHit(IBullet* bullet)
{
if (IsInvincible()) {
return;
@ -129,19 +129,19 @@ void Hero::OnBulletHit(Bullet* bullet)
}
RemoveBuffByEffectId(kBET_PeaceMode);
if (!IsDead(room) && (bullet->IsBomb() || bullet->sender.Get()->team_id != team_id)) {
float finaly_dmg = bullet->sender.Get()->GetBattleContext()->CalcDmg(this, bullet);
if (bullet->sender.Get()->IsHuman()) {
bullet->sender.Get()->AsHuman()->stats.damage_amount_out += finaly_dmg;
if (!IsDead(room) && (bullet->IsBomb() || bullet->GetSender().Get()->team_id != team_id)) {
float finaly_dmg = bullet->GetSender().Get()->GetBattleContext()->CalcDmg(this, bullet);
if (bullet->GetSender().Get()->IsHuman()) {
bullet->GetSender().Get()->AsHuman()->stats.damage_amount_out += finaly_dmg;
}
if (bullet->meta->buff_meta) {
MustBeAddBuff(bullet->sender.Get(), bullet->meta->i->buffid());
if (bullet->GetBulletMeta()->buff_meta) {
MustBeAddBuff(bullet->GetSender().Get(), bullet->GetBulletMeta()->i->buffid());
}
if (!bullet->IsPreBattleBullet()) {
DecHP(finaly_dmg,
bullet->sender.Get()->GetUniId(),
bullet->sender.Get()->GetName(),
bullet->gun_meta->i->id());
bullet->GetSender().Get()->GetUniId(),
bullet->GetSender().Get()->GetName(),
bullet->GetGunMeta()->i->id());
}
}
}

View File

@ -28,7 +28,7 @@ public:
virtual void FillMFObjectPart(Room* room, Human* hum, cs::MFObjectPart* part_data) override;
virtual void FillMFObjectFull(Room* room, Human* hum, cs::MFObjectFull* full_data) override;
virtual void OnExplosionHit(Explosion* e) override;
virtual void OnBulletHit(Bullet* bullet) override;
virtual void OnBulletHit(IBullet* bullet) override;
virtual void Update(int delta_time) override;
virtual void DecHP(float dec_hp, int killer_id, const std::string& killer_name, int weapon_id) override;
virtual std::string GetName() override;

View File

@ -3592,7 +3592,7 @@ void Human::GMAddItem(int item_id, int item_num)
SyncAroundPlayers(__FILE__, __LINE__, __func__);
}
void Human::OnBulletHit(Bullet* bullet)
void Human::OnBulletHit(IBullet* bullet)
{
if (IsInvincible()) {
return;
@ -3614,40 +3614,40 @@ void Human::OnBulletHit(Bullet* bullet)
}
#endif
#endif
if (bullet->sender.Get()) {
bullet->sender.Get()->GetTrigger()->BulletHit(bullet, this);
if (bullet->GetSender().Get()) {
bullet->GetSender().Get()->GetTrigger()->BulletHit(bullet, this);
}
RemoveBuffByEffectId(kBET_PeaceMode);
if (!dead && (bullet->IsBomb() || bullet->sender.Get()->team_id != team_id)) {
if (!dead && (bullet->IsBomb() || bullet->GetSender().Get()->team_id != team_id)) {
float finaly_dmg = 0;
if (bullet->skill_meta && SkillHelper::ProcBulletDmg(bullet, this, finaly_dmg)) {
if (bullet->GetSkillMeta() && SkillHelper::ProcBulletDmg(bullet, this, finaly_dmg)) {
} else {
finaly_dmg = bullet->sender.Get()->GetBattleContext()->CalcDmg(this, bullet);
finaly_dmg = bullet->GetSender().Get()->GetBattleContext()->CalcDmg(this, bullet);
}
if (bullet->sender.Get()->IsHuman()) {
bullet->sender.Get()->AsHuman()->stats.damage_amount_out += finaly_dmg;
if (bullet->GetSender().Get()->IsHuman()) {
bullet->GetSender().Get()->AsHuman()->stats.damage_amount_out += finaly_dmg;
}
if (bullet->meta->buff_meta) {
MustBeAddBuff(bullet->sender.Get(), bullet->meta->i->buffid());
if (bullet->GetBulletMeta()->buff_meta) {
MustBeAddBuff(bullet->GetSender().Get(), bullet->GetBulletMeta()->i->buffid());
}
if (bullet->sender.Get() && bullet->sender.Get()->IsCar() && bullet->passenger.Get()) {
if (bullet->GetSender().Get() && bullet->GetSender().Get()->IsCar() && bullet->GetPassenger().Get()) {
if (!bullet->IsPreBattleBullet()) {
DecHP(finaly_dmg,
bullet->passenger.Get()->GetUniId(),
bullet->passenger.Get()->GetName(),
bullet->gun_meta->i->id());
bullet->GetPassenger().Get()->GetUniId(),
bullet->GetPassenger().Get()->GetName(),
bullet->GetGunMeta()->i->id());
}
} else {
if (!bullet->IsPreBattleBullet()) {
if (bullet->sender.Get() && bullet->sender.Get()->IsHuman()) {
bullet->sender.Get()->AsHuman()->stats.IncWeaponDamageOut
(bullet->gun_meta->i->id(), finaly_dmg);
if (bullet->GetSender().Get() && bullet->GetSender().Get()->IsHuman()) {
bullet->GetSender().Get()->AsHuman()->stats.IncWeaponDamageOut
(bullet->GetGunMeta()->i->id(), finaly_dmg);
}
DecHP(finaly_dmg,
bullet->sender.Get()->GetUniId(),
bullet->sender.Get()->GetName(),
bullet->gun_meta->i->id());
bullet->GetSender().Get()->GetUniId(),
bullet->GetSender().Get()->GetName(),
bullet->GetGunMeta()->i->id());
}
}
}

View File

@ -249,7 +249,7 @@ class Human : public Creature
virtual void GetHitAabbBox(AabbCollider& aabb_box) override;
virtual bool IsDead(Room* room) override;
virtual long long GetDeadFrameNo(Room* room) override;
virtual void OnBulletHit(Bullet* bullet) override;
virtual void OnBulletHit(IBullet* bullet) override;
virtual void OnExplosionHit(Explosion* explosion) override;
void FillItemList(::google::protobuf::RepeatedPtrField<::cs::MFPair>* pb_item_list);
long long GetRealDeadFrameNo(Room* room);

View File

@ -106,7 +106,7 @@ void MapBlock::OnPreCollision(Room* room)
}
void MapBlock::OnBulletHit(Bullet* bullet)
void MapBlock::OnBulletHit(IBullet* bullet)
{
}

View File

@ -36,7 +36,7 @@ class MapBlock : public Entity
virtual bool IsDead(Room* room) override;
virtual long long GetDeadFrameNo(Room* room) override;
virtual void OnPreCollision(Room* room) override;
virtual void OnBulletHit(Bullet* bullet) override;
virtual void OnBulletHit(IBullet* bullet) override;
virtual void OnExplosionHit(Explosion* explosion) override;
virtual bool Attackable(Room* room) override;
virtual bool ReceiveExplosionDmg(Explosion* explosion) override;

View File

@ -488,7 +488,7 @@ void Obstacle::SetMasterId(Room* room, int master_id)
}
}
void Obstacle::OnBulletHit(Bullet* bullet)
void Obstacle::OnBulletHit(IBullet* bullet)
{
if (meta->i->bullet_hit() == kBulletHitEatDmg) {
return;
@ -497,13 +497,13 @@ void Obstacle::OnBulletHit(Bullet* bullet)
return;
}
if (!IsDead(bullet->room)) {
if (!IsDead(bullet->GetRoom())) {
if (meta->receive_special_damage_type != 0 &&
((bullet->gun_meta->special_damage_type & meta->receive_special_damage_type) == 0)) {
((bullet->GetGunMeta()->special_damage_type & meta->receive_special_damage_type) == 0)) {
return;
}
if (meta->i->thing_type() == kObstacleOilBucket) {
Entity* real_object = AsRoomObstacle()->GetRealObject(bullet->room);
Entity* real_object = AsRoomObstacle()->GetRealObject(bullet->GetRoom());
if (real_object->IsEntityType(ET_Loot)) {
Loot* loot = (Loot*)real_object;
if (loot->pickuped) {
@ -511,18 +511,18 @@ void Obstacle::OnBulletHit(Bullet* bullet)
}
}
}
float finaly_dmg = bullet->sender.Get()->GetBattleContext()->CalcDmg(this, bullet);
SetHealth(bullet->room, std::max(0.0f, GetHealth(bullet->room) - finaly_dmg));
if (GetHealth(bullet->room) <= 0.01f) {
Die(bullet->room);
float finaly_dmg = bullet->GetSender().Get()->GetBattleContext()->CalcDmg(this, bullet);
SetHealth(bullet->GetRoom(), std::max(0.0f, GetHealth(bullet->GetRoom()) - finaly_dmg));
if (GetHealth(bullet->GetRoom()) <= 0.01f) {
Die(bullet->GetRoom());
if (meta->i->thing_type() == kObstacleOilBucket) {
Entity* real_object = AsRoomObstacle()->GetRealObject(bullet->room);
Entity* real_object = AsRoomObstacle()->GetRealObject(bullet->GetRoom());
if (real_object->IsEntityType(ET_Loot)) {
Loot* loot = (Loot*)real_object;
loot->pickuped = true;
bullet->room->RemoveObjectLater(loot);
bullet->room->RemoveObjectLater(AsRoomObstacle());
RoomObstacle* obstacle = bullet->room->CreateObstacle
bullet->GetRoom()->RemoveObjectLater(loot);
bullet->GetRoom()->RemoveObjectLater(AsRoomObstacle());
RoomObstacle* obstacle = bullet->GetRoom()->CreateObstacle
(
meta->int_param1,
GetPos().x,
@ -531,13 +531,13 @@ void Obstacle::OnBulletHit(Bullet* bullet)
}
}
}
if (IsDead(bullet->room)) {
ProcDieExplosion(bullet->room);
bullet->sender.Get()->DropItems(this);
if (IsDead(bullet->GetRoom())) {
ProcDieExplosion(bullet->GetRoom());
bullet->GetSender().Get()->DropItems(this);
if (meta->i->thing_type() == kObstacleOilBucket) {
MetaData::MapThing* bomb_meta = MetaMgr::Instance()->GetMapThing(meta->int_param1);
if (bomb_meta) {
RoomObstacle* obstacle = bullet->room->CreateObstacle
RoomObstacle* obstacle = bullet->GetRoom()->CreateObstacle
(
bomb_meta->i->thing_id(),
GetPos().x,
@ -546,7 +546,7 @@ void Obstacle::OnBulletHit(Bullet* bullet)
}
}
}
BroadcastFullState(bullet->room);
BroadcastFullState(bullet->GetRoom());
}
}

View File

@ -42,7 +42,7 @@ class Obstacle : public Entity
virtual bool IsDead(Room* room) override;
virtual long long GetDeadFrameNo(Room* room) override;
virtual void OnPreCollision(Room* room) override;
virtual void OnBulletHit(Bullet* bullet) override;
virtual void OnBulletHit(IBullet* bullet) override;
virtual void OnExplosionHit(Explosion* explosion) override;
virtual bool Attackable(Room* room) override;
virtual bool CanThroughable(Creature* c);

View File

@ -305,7 +305,7 @@ void Skill::ProcSJXY()
[this, shot_times, hited_objs] (const std::vector<std::any>& params) mutable
{
++shot_times;
Bullet* bullet = std::any_cast<Bullet*>(params.at(0));
IBullet* bullet = std::any_cast<IBullet*>(params.at(0));
Creature* target = std::any_cast<Creature*>(params.at(1));
int rnd = rand();
bool is_hit = false;

View File

@ -237,13 +237,13 @@ float SkillHelper::GetSwzbBuffTime(const MetaData::Skill* skill_meta)
return skill_meta->number_meta->float_time;
}
void SkillHelper::ProcBulletHitBuff(Bullet* bullet, Creature* c, int buff_uniid)
void SkillHelper::ProcBulletHitBuff(IBullet* bullet, Creature* c, int buff_uniid)
{
Buff* buff = c->GetBuffByUniId(buff_uniid);
if (!buff) {
return;
}
auto skill_meta = bullet->skill_meta;
auto skill_meta = bullet->GetSkillMeta();
if (!skill_meta) {
return;
}
@ -263,7 +263,7 @@ void SkillHelper::ProcBulletHitBuff(Bullet* bullet, Creature* c, int buff_uniid)
skill_meta->i->skill_id(),
skill_meta->number_meta->float_time
});
bullet->sender.Get()->SendDebugMsg(dbg_msg);
bullet->GetSender().Get()->SendDebugMsg(dbg_msg);
a8::XPrintf("%s\n", {dbg_msg});
}
#endif
@ -333,10 +333,10 @@ float SkillHelper::GetYmczDmg(Creature* sender, Creature* target, const MetaData
return finaly_dmg;
}
bool SkillHelper::ProcBulletDmg(Bullet* bullet, Creature* target, float& finaly_dmg)
bool SkillHelper::ProcBulletDmg(IBullet* bullet, Creature* target, float& finaly_dmg)
{
finaly_dmg = 0.0f;
MetaData::Skill* skill_meta = bullet->skill_meta;
MetaData::Skill* skill_meta = bullet->GetSkillMeta();
if (!skill_meta || !skill_meta->number_meta) {
return false;
}
@ -347,7 +347,7 @@ bool SkillHelper::ProcBulletDmg(Bullet* bullet, Creature* target, float& finaly_
finaly_dmg =
(skill_meta->number_meta->float_ratio +
skill_meta->number_meta->float_ratio2 *
bullet->sender.Get()->GetBattleContext()->GetHeroTotalAtk()) *
bullet->GetSender().Get()->GetBattleContext()->GetHeroTotalAtk()) *
(1 - target->GetBattleContext()->GetDef() / (target->GetBattleContext()->GetDef() + 400));
#ifdef DEBUG
{
@ -358,11 +358,11 @@ bool SkillHelper::ProcBulletDmg(Bullet* bullet, Creature* target, float& finaly_
skill_meta->i->skill_id(),
skill_meta->number_meta->float_ratio,
skill_meta->number_meta->float_ratio2,
bullet->sender.Get()->GetBattleContext()->GetHeroTotalAtk(),
bullet->GetSender().Get()->GetBattleContext()->GetHeroTotalAtk(),
target->GetBattleContext()->GetDef(),
finaly_dmg
});
bullet->sender.Get()->SendDebugMsg(dbg_msg);
bullet->GetSender().Get()->SendDebugMsg(dbg_msg);
a8::XPrintf("%s\n", {dbg_msg});
}
#endif

View File

@ -57,8 +57,8 @@ class SkillHelper
static float GetLdfyHp(Creature* c, const MetaData::Skill* skill_meta);
static float GetLdfyBuffTime(Creature* c, const MetaData::Skill* skill_meta);
static void ProcBulletHitBuff(Bullet* bullet, Creature* c, int buff_uniid);
static bool ProcBulletDmg(Bullet* bullet, Creature* target, float& finaly_dmg);
static void ProcBulletHitBuff(IBullet* bullet, Creature* c, int buff_uniid);
static bool ProcBulletDmg(IBullet* bullet, Creature* target, float& finaly_dmg);
static void ProcSummonObstacle(const MetaData::Skill* skill_meta, RoomObstacle* ob);
private:

View File

@ -429,10 +429,10 @@ void Trigger::DispatchEvent(int event_id, const std::vector<std::any>& param)
}
}
void Trigger::BulletHit(Bullet* bullet, Creature* target)
void Trigger::BulletHit(IBullet* bullet, Creature* target)
{
if (bullet->sender.Get()) {
bullet->sender.Get()->GetTrigger()->DispatchEvent(kBulletHitEvent, {bullet, target});
if (bullet->GetSender().Get()) {
bullet->GetSender().Get()->GetTrigger()->DispatchEvent(kBulletHitEvent, {bullet, target});
}
}

View File

@ -64,7 +64,7 @@ public:
void Die();
void ActiveBuff(MetaData::Buff* buff_meta);
void DeactiveBuff(MetaData::Buff* buff_meta);
void BulletHit(Bullet* bullet, Creature* target);
void BulletHit(IBullet* bullet, Creature* target);
void ShieldDestory();
void StartRescue(Human* target);
void EndRescue(Human* target);

View File

@ -1,5 +1,7 @@
#pragma once
#include "weakptr.h"
namespace MetaData
{
struct Equip;
@ -11,6 +13,8 @@ namespace cs
struct CMJoin;
}
class Room;
struct AddItemDTO
{
int uniid = 0;
@ -28,4 +32,10 @@ class IBullet
virtual long long GetWeaponUniId() = 0;
virtual MetaData::Skill* GetSkillMeta() = 0;
virtual MetaData::Equip* GetGunMeta() = 0;
virtual MetaData::Equip* GetBulletMeta() = 0;
virtual CreatureWeakPtr GetSender() = 0;
virtual CreatureWeakPtr GetPassenger() = 0;
virtual bool IsBomb() = 0;
virtual bool IsPreBattleBullet() = 0;
virtual Room* GetRoom() = 0;
};

View File

@ -20,3 +20,33 @@ MetaData::Equip* VirtualBullet::GetGunMeta()
{
return nullptr;
}
MetaData::Equip* VirtualBullet::GetBulletMeta()
{
return nullptr;
}
CreatureWeakPtr VirtualBullet::GetSender()
{
}
CreatureWeakPtr VirtualBullet::GetPassenger()
{
}
bool VirtualBullet::IsBomb()
{
return false;
}
bool VirtualBullet::IsPreBattleBullet()
{
return false;
}
Room* VirtualBullet::GetRoom()
{
return nullptr;
}

View File

@ -6,15 +6,23 @@ namespace MetaData
struct Equip;
}
class Room;
class VirtualBullet : public IBullet
{
public:
long long weapon_uniid = 0;
MetaData::Skill* skill_meta = nullptr;
MetaData::Equip* equip_meta = nullptr;
MetaData::Equip* gun_meta = nullptr;
MetaData::Equip* bullet_meta = nullptr;
virtual float GetStrengthenWall() override;
virtual long long GetWeaponUniId() override;
virtual MetaData::Skill* GetSkillMeta() override;
virtual MetaData::Equip* GetGunMeta() override;
virtual MetaData::Equip* GetBulletMeta() override;
virtual CreatureWeakPtr GetSender() override;
virtual CreatureWeakPtr GetPassenger() override;
virtual bool IsBomb() override;
virtual bool IsPreBattleBullet() override;
virtual Room* GetRoom() override;
};