From 1288ebfc20c08d3fec45324abde8d1940be0bb82 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Fri, 19 Mar 2021 17:53:59 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E5=AD=90=E5=BC=B9luoj?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/gameserver/bullet.cc | 5 ++++- server/gameserver/bullet.h | 3 ++- server/gameserver/creature.cc | 36 +++++++++++++++++++++++++++++++++ server/gameserver/creature.h | 14 ++++++++++++- server/gameserver/frameevent.cc | 2 +- server/gameserver/frameevent.h | 8 ++++---- server/gameserver/human.cc | 36 --------------------------------- server/gameserver/human.h | 11 ++++------ 8 files changed, 64 insertions(+), 51 deletions(-) diff --git a/server/gameserver/bullet.cc b/server/gameserver/bullet.cc index 0133663..f30b36e 100644 --- a/server/gameserver/bullet.cc +++ b/server/gameserver/bullet.cc @@ -11,6 +11,7 @@ #include "app.h" #include "perfmonitor.h" #include "smoke_mitask.h" +#include "creature.h" Bullet::Bullet():MoveableEntity() { @@ -77,8 +78,10 @@ void Bullet::OnHit(std::set& objects) hum->GetAttrAbs(kHAT_Def); float finaly_dmg = dmg * (1 - def/MetaMgr::Instance()->K); finaly_dmg = std::max(finaly_dmg, 0.0f); + #if 0 sender->stats.damage_amount_out += finaly_dmg; - hum->DecHP(finaly_dmg, sender->GetEntityUniId(), sender->name, gun_meta->i->id()); + #endif + hum->DecHP(finaly_dmg, sender->GetEntityUniId(), sender->GetName(), gun_meta->i->id()); #ifdef DEBUG sender->SendDebugMsg(a8::Format("bullet weapon_id:%d atk:%f", { diff --git a/server/gameserver/bullet.h b/server/gameserver/bullet.h index 64e3039..aa70d76 100644 --- a/server/gameserver/bullet.h +++ b/server/gameserver/bullet.h @@ -11,6 +11,7 @@ namespace MetaData class Human; class Obstacle; +class Creature; class CircleCollider; class MovementComponent; class Bullet : public MoveableEntity @@ -20,7 +21,7 @@ class Bullet : public MoveableEntity MetaData::Equip* gun_meta = nullptr; MetaData::EquipUpgrade* gun_upgrade_meta = nullptr; MetaData::Equip* meta = nullptr; - Human* sender = nullptr; + Creature* sender = nullptr; a8::Vec2 dir; a8::Vec2 born_pos; a8::Vec2 born_dir; diff --git a/server/gameserver/creature.cc b/server/gameserver/creature.cc index ebb4abf..4b9457b 100644 --- a/server/gameserver/creature.cc +++ b/server/gameserver/creature.cc @@ -756,3 +756,39 @@ bool Creature::CanSee(const Creature* c) const { return room->grid_service->InView(GetGridId(), c->GetGridId()); } + +float Creature::GetAttrAbs(int attr_id) +{ + float attr_abs_val = GetBuffAttrAbs(attr_id); + if (attr_id == kHAT_Atk || attr_id == kHAT_Def) { + Buff* buff = GetBuffByEffectId(kBET_Car); + if (buff) { + MetaData::Equip* equip_meta = MetaMgr::Instance()->GetEquip(buff->meta->param4); + if (equip_meta) { + switch (attr_id) { + case kHAT_Atk: + { + attr_abs_val += equip_meta->i->atk(); + } + break; + case kHAT_Def: + { + attr_abs_val += equip_meta->i->def(); + } + break; + default: + { + } + break; + } + } + } + } + return attr_abs_val; +} + +float Creature::GetAttrRate(int attr_id) +{ + float attr_rate_val = GetBuffAttrRate(attr_id); + return attr_rate_val; +} diff --git a/server/gameserver/creature.h b/server/gameserver/creature.h index 9db7277..b73c457 100644 --- a/server/gameserver/creature.h +++ b/server/gameserver/creature.h @@ -13,6 +13,7 @@ namespace MetaData struct xtimer_list; class Skill; +class Obstacle; class Creature : public MoveableEntity { public: @@ -66,12 +67,20 @@ class Creature : public MoveableEntity virtual void CancelAction() {}; virtual void ResetAction() {}; + virtual std::string GetName() { return "";}; + virtual void SendDebugMsg(const std::string& debug_msg); + virtual void DropItems(Obstacle* obstacle) {}; + virtual bool IsPlayer() const { return false;}; + virtual bool IsAndroid() const { return false;}; + + RaceType_e GetRace() { return race_; } + float GetAttrAbs(int attr_id); + float GetAttrRate(int attr_id); private: virtual void AddBuffPostProc(Creature* caster, Buff* buff); virtual void OnBuffRemove(const Buff& buff); - virtual void SendDebugMsg(const std::string& debug_msg); virtual void DoSkillPreProc(int skill_id, int target_id, const a8::Vec2& target_pos); virtual void DoSkillPostProc(bool used, int skill_id, int target_id, const a8::Vec2& target_pos); virtual void _UpdateMove(int speed) {}; @@ -84,6 +93,9 @@ private: Skill* GetPassiveSkill(int skill_id); void RemovePassiveSkill(int skill_id); +protected: + RaceType_e race_ = kHumanRace; + private: std::array buff_attr_abs_ = {}; std::array buff_attr_rate_ = {}; diff --git a/server/gameserver/frameevent.cc b/server/gameserver/frameevent.cc index e52f72a..d566168 100644 --- a/server/gameserver/frameevent.cc +++ b/server/gameserver/frameevent.cc @@ -119,7 +119,7 @@ void FrameEvent::AddExplosion(Bullet* bullet, int item_id, a8::Vec2 bomb_pos) } } -void FrameEvent::AddExplosionEx(Human* sender, int item_id, a8::Vec2 bomb_pos, int effect) +void FrameEvent::AddExplosionEx(Creature* sender, int item_id, a8::Vec2 bomb_pos, int effect) { { auto& tuple = a8::FastAppend(explosions_); diff --git a/server/gameserver/frameevent.h b/server/gameserver/frameevent.h index 437d49b..9dfded9 100644 --- a/server/gameserver/frameevent.h +++ b/server/gameserver/frameevent.h @@ -21,7 +21,7 @@ public: float fly_distance); void AddExplosion(Bullet* bullet, int item_id, a8::Vec2 bomb_pos); void AddSmoke(Bullet* bullet, int item_id, a8::Vec2 pos); - void AddExplosionEx(Human* sender, int item_id, a8::Vec2 bomb_pos, int effect); + void AddExplosionEx(Creature* sender, int item_id, a8::Vec2 bomb_pos, int effect); void AddBulletNumChg(Human* hum); void AddHpChg(Human* hum); void AddWeaponAmmoChg(Human* hum); @@ -39,9 +39,9 @@ private: ::google::protobuf::RepeatedPtrField<::cs::MFAirDrop> airdrops_; std::vector> shots_; std::vector> bullets_; - std::vector> explosions_; - std::vector> smokes_; - std::vector> emotes_; + std::vector> explosions_; + std::vector> smokes_; + std::vector> emotes_; std::vector> chged_buffs_; std::vector> chged_items_; std::vector chged_bullet_nums_; diff --git a/server/gameserver/human.cc b/server/gameserver/human.cc index 1c04557..5f34d92 100644 --- a/server/gameserver/human.cc +++ b/server/gameserver/human.cc @@ -2935,42 +2935,6 @@ void Human::DecItem(int item_id, int item_num) } } -float Human::GetAttrAbs(int attr_id) -{ - float attr_abs_val = GetBuffAttrAbs(attr_id); - if (attr_id == kHAT_Atk || attr_id == kHAT_Def) { - Buff* buff = GetBuffByEffectId(kBET_Car); - if (buff) { - MetaData::Equip* equip_meta = MetaMgr::Instance()->GetEquip(buff->meta->param4); - if (equip_meta) { - switch (attr_id) { - case kHAT_Atk: - { - attr_abs_val += equip_meta->i->atk(); - } - break; - case kHAT_Def: - { - attr_abs_val += equip_meta->i->def(); - } - break; - default: - { - } - break; - } - } - } - } - return attr_abs_val; -} - -float Human::GetAttrRate(int attr_id) -{ - float attr_rate_val = GetBuffAttrRate(attr_id); - return attr_rate_val; -} - bool Human::IsPlayer() const { return IsEntitySubType(EST_Player); diff --git a/server/gameserver/human.h b/server/gameserver/human.h index 288ec92..beb33e8 100644 --- a/server/gameserver/human.h +++ b/server/gameserver/human.h @@ -239,11 +239,9 @@ class Human : public Creature int GetItemNum(int item_id); void AddItem(int item_id, int item_num); void DecItem(int item_id, int item_num); - float GetAttrAbs(int attr_id); - float GetAttrRate(int attr_id); - bool IsPlayer() const; - bool IsAndroid() const; - void DropItems(Obstacle* obstacle); + virtual bool IsPlayer() const override; + virtual bool IsAndroid() const override; + virtual void DropItems(Obstacle* obstacle) override; void ProcNewBieLogic(); void OnEnable(); void OnDisable(); @@ -253,7 +251,6 @@ class Human : public Creature bool HasSpecMove(); void _UpdateSpecMove(); virtual void _UpdateMove(int speed) override; - RaceType_e GetRace() { return race_; } void ChangeToRace(RaceType_e race, int level); void ChangeToRaceAndNotify(RaceType_e race, int level); void WinExp(Human* sender, int exp); @@ -263,6 +260,7 @@ class Human : public Creature void SetSeat(int seat) { seat_ = seat; } void DeadDrop(); bool IsEnemy(Human* hum); + virtual std::string GetName() override { return name;}; protected: void _InternalUpdateMove(float speed); @@ -349,7 +347,6 @@ protected: int seat_ = 0; private: - RaceType_e race_ = kHumanRace; CircleCollider* self_collider_ = nullptr; long long last_sync_gas_frameno = 0; std::map items_;