From cdb2bfb5fc907688b94d59cf04a1f4d506225508 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Tue, 27 Jul 2021 08:04:37 +0000 Subject: [PATCH] 1 --- server/gameserver/hero.cc | 35 +++++++++++++++++++++++++++++++++++ server/gameserver/hero.h | 1 + 2 files changed, 36 insertions(+) diff --git a/server/gameserver/hero.cc b/server/gameserver/hero.cc index 0a288d1..7ba0f0e 100644 --- a/server/gameserver/hero.cc +++ b/server/gameserver/hero.cc @@ -12,6 +12,7 @@ #include "obstacle.h" #include "collider.h" #include "bullet.h" +#include "explosion.h" Hero::Hero():Creature() { @@ -75,6 +76,40 @@ void Hero::Update(int delta_time) ++updated_times_; } +void Hero::OnExplosionHit(Explosion* e) +{ + if (IsInvincible()) { + return; + } + if (dead) { + return; + } + float dmg = e->GetDmg(); + float def = GetDef() * (1 + GetAbility()->GetAttrRate(kHAT_Def)) + + GetAbility()->GetAttrAbs(kHAT_Def); + float finaly_dmg = dmg * (1 - def/MetaMgr::Instance()->K); + finaly_dmg = std::max(finaly_dmg, 0.0f); +#ifdef DEBUG + { + room->BroadcastDebugMsg(a8::Format("explosion dmg:%d def:%d finaly_dmg:%d", + {dmg, + def, + finaly_dmg})); + } +#endif +#if 1 + DecHP(finaly_dmg, + 1, + "", + 1); +#else + DecHP(finaly_dmg, + sender.Get()->GetUniId(), + sender.Get()->GetName(), + gun_meta->i->id()); +#endif +} + void Hero::OnBulletHit(Bullet* bullet) { if (IsInvincible()) { diff --git a/server/gameserver/hero.h b/server/gameserver/hero.h index 30a9908..3a2e973 100644 --- a/server/gameserver/hero.h +++ b/server/gameserver/hero.h @@ -26,6 +26,7 @@ public: 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 OnExplosionHit(Explosion* e) override; virtual void OnBulletHit(Bullet* 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;