This commit is contained in:
aozhiwei 2023-04-02 15:10:53 +08:00
parent bf281fee0f
commit 162216cc27
6 changed files with 72 additions and 48 deletions

View File

@ -1072,3 +1072,55 @@ void Bullet::Raycast()
}); });
#endif #endif
} }
void Bullet::ProcRequestBulletDmg(int shield_hit, int strength_wall_uniid, int target_uniid, const glm::vec3& pos)
{
#if 1
#else
Entity* entity = room->GetEntityByUniId(target_uniid);
if (entity && entity->IsCreature(room) && entity != this && !entity->IsDead(room)) {
Creature* c = (Creature*)entity;
float dmg = c->GetBattleContext()->CalcDmg(c, bullet);
if (msg.strengthen_wall_uniid()) {
dmg *= 2;
}
bool shield = false;
if (dmg > 0.00001f) {
if (msg.shield_hit()) {
Buff* hold_shield_buff = c->GetBuffByEffectId(kBET_HoldShield);
if (hold_shield_buff) {
c->shield_hp_ = std::max(0.0f, c->shield_hp_ - dmg);
room->frame_event.AddPropChg(c->GetWeakPtrRef(),
kPropShieldHp,
c->shield_max_hp_,
c->shield_hp_);
if (c->shield_hp_ <= 0) {
c->GetTrigger()->ShieldDestory();
if (hold_shield_buff->meta->_buff_param1_int_list.size() > 0) {
TryAddBuff(this, hold_shield_buff->meta->_buff_param1_int_list[0]);
}
c->RemoveBuffByUniId(hold_shield_buff->buff_uniid);
}
shield = true;
}
}
if (!shield) {
bullet->strengthen_wall = msg.strengthen_wall_uniid() ? 1 : 0;
std::set<Entity*> objects;
objects.insert(c);
bullet->OnHit(objects);
#if 0
c->OnBulletHit(bullet);
#endif
}
}
#ifdef DEBUG
a8::XPrintf("dmg:%f shield:%d\n",
{
dmg,
shield ? 1 : 0
});
#endif
}
#endif
}

View File

@ -57,6 +57,7 @@ class Bullet : public MoveableEntity, public IBullet
virtual Room* GetRoom() { return room; }; virtual Room* GetRoom() { return room; };
virtual float GetHitRadius() override; virtual float GetHitRadius() override;
virtual const Position& GetPos() override; virtual const Position& GetPos() override;
virtual void ProcRequestBulletDmg(int shield_hit, int strength_wall_uniid, int target_uniid, const glm::vec3& pos) override;
protected: protected:
Bullet(); Bullet();

View File

@ -1198,13 +1198,16 @@ void Player::_CMRequestBulletDmg(f8::MsgHdr& hdr, const cs::CMRequestBulletDmg&
{ {
auto itr = room->report_bullet_hash.find(msg.bullet_uniid()); auto itr = room->report_bullet_hash.find(msg.bullet_uniid());
#ifdef DEBUG #ifdef DEBUG
a8::XPrintf("CMRequestBulletDmg bullet_uniid:%d shield_hit:%d strengthen_wall_uniid:%d target_uniid:%d found:%d\n", a8::XPrintf("CMRequestBulletDmg bullet_uniid:%d shield_hit:%d strengthen_wall_uniid:%d target_uniid:%d found:%d pos:%f,%f,%f\n",
{ {
msg.bullet_uniid(), msg.bullet_uniid(),
msg.shield_hit(), msg.shield_hit(),
msg.strengthen_wall_uniid(), msg.strengthen_wall_uniid(),
msg.target_uniid(), msg.target_uniid(),
itr == room->report_bullet_hash.end() ? 0 :1 itr == room->report_bullet_hash.end() ? 0 :1,
msg.pos().x(),
msg.pos().y(),
msg.pos().z()
}); });
#endif #endif
if (itr == room->report_bullet_hash.end()) { if (itr == room->report_bullet_hash.end()) {
@ -1213,52 +1216,13 @@ void Player::_CMRequestBulletDmg(f8::MsgHdr& hdr, const cs::CMRequestBulletDmg&
Entity* bullet_entity = room->GetEntityByUniId(msg.bullet_uniid()); Entity* bullet_entity = room->GetEntityByUniId(msg.bullet_uniid());
if (bullet_entity && bullet_entity->GetEntityType() == ET_Bullet) { if (bullet_entity && bullet_entity->GetEntityType() == ET_Bullet) {
Bullet* bullet = (Bullet*)bullet_entity; ((Bullet*)bullet_entity)->ProcRequestBulletDmg
Entity* entity = room->GetEntityByUniId(msg.target_uniid()); (
if (entity && entity->IsCreature(room) && entity != this && !entity->IsDead(room)) { msg.shield_hit(),
Creature* c = (Creature*)entity; msg.strengthen_wall_uniid(),
float dmg = c->GetBattleContext()->CalcDmg(c, bullet); msg.target_uniid(),
if (msg.strengthen_wall_uniid()) { glm::vec3(msg.pos().x(), msg.pos().y(), msg.pos().z())
dmg *= 2; );
}
bool shield = false;
if (dmg > 0.00001f) {
if (msg.shield_hit()) {
Buff* hold_shield_buff = c->GetBuffByEffectId(kBET_HoldShield);
if (hold_shield_buff) {
c->shield_hp_ = std::max(0.0f, c->shield_hp_ - dmg);
room->frame_event.AddPropChg(c->GetWeakPtrRef(),
kPropShieldHp,
c->shield_max_hp_,
c->shield_hp_);
if (c->shield_hp_ <= 0) {
c->GetTrigger()->ShieldDestory();
if (hold_shield_buff->meta->_buff_param1_int_list.size() > 0) {
TryAddBuff(this, hold_shield_buff->meta->_buff_param1_int_list[0]);
}
c->RemoveBuffByUniId(hold_shield_buff->buff_uniid);
}
shield = true;
}
}
if (!shield) {
bullet->strengthen_wall = msg.strengthen_wall_uniid() ? 1 : 0;
std::set<Entity*> objects;
objects.insert(c);
bullet->OnHit(objects);
#if 0
c->OnBulletHit(bullet);
#endif
}
}
#ifdef DEBUG
a8::XPrintf("dmg:%f shield:%d\n",
{
dmg,
shield ? 1 : 0
});
#endif
}
} }
room->report_bullet_hash.erase(msg.bullet_uniid()); room->report_bullet_hash.erase(msg.bullet_uniid());
} }

View File

@ -90,4 +90,5 @@ class IBullet
virtual bool IsPreBattleBullet() = 0; virtual bool IsPreBattleBullet() = 0;
virtual Room* GetRoom() = 0; virtual Room* GetRoom() = 0;
virtual float GetHitRadius() = 0; virtual float GetHitRadius() = 0;
virtual void ProcRequestBulletDmg(int shield_hit, int strength_wall_uniid, int target_uniid, const glm::vec3& pos) = 0;
}; };

View File

@ -289,3 +289,8 @@ float VirtualBullet::GetHitRadius()
{ {
return gun_meta->bullet_rad(); return gun_meta->bullet_rad();
} }
void VirtualBullet::ProcRequestBulletDmg(int shield_hit, int strength_wall_uniid, int target_uniid, const glm::vec3& pos)
{
}

View File

@ -32,6 +32,7 @@ class VirtualBullet : public IBullet, public ITask
virtual bool IsPreBattleBullet() override; virtual bool IsPreBattleBullet() override;
virtual Room* GetRoom() override; virtual Room* GetRoom() override;
virtual float GetHitRadius() override; virtual float GetHitRadius() override;
virtual void ProcRequestBulletDmg(int shield_hit, int strength_wall_uniid, int target_uniid, const glm::vec3& pos) override;
virtual void Update(int delta_time) override; virtual void Update(int delta_time) override;
virtual bool IsDone() override; virtual bool IsDone() override;