From a45e86ac58c4b4b9f753102d2950dc6a98fd01e4 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Mon, 29 Mar 2021 15:24:33 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90action=E6=94=B9=E9=80=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/gameserver/creature.cc | 46 +++++++++++++++++++++++++++++++++++ server/gameserver/creature.h | 20 ++++++++++++--- server/gameserver/human.cc | 46 ----------------------------------- server/gameserver/human.h | 11 --------- server/gameserver/player.cc | 2 +- server/gameserver/room.cc | 4 +-- 6 files changed, 66 insertions(+), 63 deletions(-) diff --git a/server/gameserver/creature.cc b/server/gameserver/creature.cc index 5f691c8..f5b219d 100644 --- a/server/gameserver/creature.cc +++ b/server/gameserver/creature.cc @@ -847,3 +847,49 @@ bool Creature::IsHuman() const { return IsEntityType(ET_Player); } + +void Creature::StartAction(ActionType_e action_type, + int action_duration, + int item_id, + int target_id) +{ + if (this->action_type == action_type && + this->action_item_id == item_id && + this->action_target_id == target_id) { + return; + } + action_duration = std::max(0, action_duration); + this->action_type = action_type; + this->action_frameno = room->GetFrameNo(); + this->action_duration = action_duration; + this->action_item_id = item_id; + this->action_target_id = target_id; + need_sync_active_player = true; + if (HasBuffEffect(kBET_Camouflage)) { + RemoveBuffByEffectId(kBET_Camouflage); + } +} + +void Creature::CancelAction() +{ + if (action_type == AT_Relive) { + Entity* entity = room->GetEntityByUniId(action_target_id); + if (!entity->IsEntityType(ET_Player)) { + Human* hum = (Human*)entity; + if (hum->action_type == AT_Rescue) { + hum->CancelAction(); + } + } + } + ResetAction(); +} + +void Creature::ResetAction() +{ + action_type = AT_None; + action_duration = 0; + action_frameno = 0; + action_item_id = 0; + action_target_id = 0; + need_sync_active_player = true; +} diff --git a/server/gameserver/creature.h b/server/gameserver/creature.h index 05ace61..69a1e2e 100644 --- a/server/gameserver/creature.h +++ b/server/gameserver/creature.h @@ -21,7 +21,6 @@ class Creature : public MoveableEntity bool dead = false; int team_id = 0; bool aiming = false; - ActionType_e action_type = AT_None; a8::Vec2 attack_dir; HumanAbility ability; a8::Vec2 target_pos; @@ -30,6 +29,8 @@ class Creature : public MoveableEntity Weapon* curr_weapon = nullptr; Weapon car_weapon; + bool need_sync_active_player = false; + virtual ~Creature() override; virtual void Initialize() override; bool HasBuffEffect(int buff_effect_id); @@ -66,8 +67,6 @@ class Creature : public MoveableEntity MetaData::SkillPhase* GetCurrSkillPhase(); bool CanSee(const Creature* c) const; - virtual void CancelAction() {}; - virtual void ResetAction() {}; virtual std::string GetName() { return "";}; virtual void SendDebugMsg(const std::string& debug_msg); virtual void DropItems(Obstacle* obstacle) {}; @@ -80,6 +79,15 @@ class Creature : public MoveableEntity float GetAttrAbs(int attr_id); float GetAttrRate(int attr_id); + void StartAction(ActionType_e action_type, + int action_duration, + int item_id, + int target_id); + void CancelAction(); + void ResetAction(); + int GetActionType() { return action_type; } + int GetActionTargetId() { return action_target_id; } + private: virtual void AddBuffPostProc(Creature* caster, Buff* buff); @@ -99,6 +107,12 @@ private: protected: RaceType_e race_ = kHumanRace; + ActionType_e action_type = AT_None; + int action_duration = 0; + long long action_frameno = 0; + int action_item_id = 0; + int action_target_id = 0; + private: std::array buff_attr_abs_ = {}; std::array buff_attr_rate_ = {}; diff --git a/server/gameserver/human.cc b/server/gameserver/human.cc index 10cf9e3..4872988 100644 --- a/server/gameserver/human.cc +++ b/server/gameserver/human.cc @@ -793,52 +793,6 @@ void Human::AutoLoadingBullet(bool manual) } } -void Human::StartAction(ActionType_e action_type, - int action_duration, - int item_id, - int target_id) -{ - if (this->action_type == action_type && - this->action_item_id == item_id && - this->action_target_id == target_id) { - return; - } - action_duration = std::max(0, action_duration); - this->action_type = action_type; - this->action_frameno = room->GetFrameNo(); - this->action_duration = action_duration; - this->action_item_id = item_id; - this->action_target_id = target_id; - need_sync_active_player = true; - if (HasBuffEffect(kBET_Camouflage)) { - RemoveBuffByEffectId(kBET_Camouflage); - } -} - -void Human::CancelAction() -{ - if (action_type == AT_Relive) { - Entity* entity = room->GetEntityByUniId(action_target_id); - if (!entity->IsEntityType(ET_Player)) { - Human* hum = (Human*)entity; - if (hum->action_type == AT_Rescue) { - hum->CancelAction(); - } - } - } - ResetAction(); -} - -void Human::ResetAction() -{ - action_type = AT_None; - action_duration = 0; - action_frameno = 0; - action_item_id = 0; - action_target_id = 0; - need_sync_active_player = true; -} - void Human::FillSMGameOver(cs::SMGameOver& msg) { if (stats.rank <= 0) { diff --git a/server/gameserver/human.h b/server/gameserver/human.h index 5704526..c39c0c1 100644 --- a/server/gameserver/human.h +++ b/server/gameserver/human.h @@ -69,10 +69,6 @@ class Human : public Creature bool disconnected = false; int anim_type = 0; int anim_seq = 0; - long long action_frameno = 0; - int action_duration = 0; - int action_item_id = 0; - int action_target_id = 0; Skin skin_jlf; int backpack = 0; int helmet = 0; @@ -105,7 +101,6 @@ class Human : public Creature bool need_sync_team_data = false; bool need_sync_teammate_data = false; - bool need_sync_active_player = false; PlayerStats stats; @@ -167,12 +162,6 @@ class Human : public Creature float GetMaxHP(); void UpdatePoisoning(); void AutoLoadingBullet(bool manual = false); - void StartAction(ActionType_e action_type, - int action_duration, - int item_id, - int target_id); - virtual void CancelAction() override; - virtual void ResetAction() override; void BeKill(int killer_id, const std::string& killer_name, int weapon_id); virtual void DecHP(float dec_hp, int killer_id, const std::string& killer_name, int weapon_id) override; void AddToNewObjects(Entity* entity); diff --git a/server/gameserver/player.cc b/server/gameserver/player.cc index e6b6d3d..22e2f6c 100644 --- a/server/gameserver/player.cc +++ b/server/gameserver/player.cc @@ -777,7 +777,7 @@ void Player::HumanInteraction(Human* hum) if (!hum->downed) { return; } - if (hum->action_type == AT_Rescue) { + if (hum->GetActionType() == AT_Rescue) { return; } hum->StartAction( diff --git a/server/gameserver/room.cc b/server/gameserver/room.cc index edbfb70..1743f4f 100644 --- a/server/gameserver/room.cc +++ b/server/gameserver/room.cc @@ -3464,8 +3464,8 @@ void Room::FillObjectPositions(Human* hum, cs::SMUpdate& msg) void Room::RemoveRescue(Human* hum) { for (auto& pair : human_hash_) { - if (pair.second != hum && pair.second->action_type == AT_Relive && - pair.second->action_target_id == hum->GetEntityUniId()) { + if (pair.second != hum && pair.second->GetActionType() == AT_Relive && + pair.second->GetActionTargetId() == hum->GetEntityUniId()) { pair.second->CancelAction(); } }