From 0e1e48363fd3b7c99b54e6cbc7f82b96c3b4c174 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Fri, 10 Sep 2021 05:58:46 +0000 Subject: [PATCH] =?UTF-8?q?=E6=AD=BB=E4=BA=A1=E5=90=8E=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E8=A7=82=E6=88=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/gameserver/human.cc | 26 ++++++++++++++++++++++++++ server/gameserver/human.h | 1 + server/gameserver/player.h | 2 +- 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/server/gameserver/human.cc b/server/gameserver/human.cc index e20c481..b08fa61 100644 --- a/server/gameserver/human.cc +++ b/server/gameserver/human.cc @@ -2181,6 +2181,18 @@ void Human::OnDie() hum->SendGameOver(); } } + if (observers_.size() > 1) { + std::vector exclude_self_observers; + for (auto& observer : observers_) { + if (observer != this) { + exclude_self_observers.push_back(observer); + } + } + for (auto& observer : exclude_self_observers) { + observers_.erase(observer); + observer->OnWatcherDie(this); + } + } DeadDrop(); } @@ -3740,3 +3752,17 @@ void Human::DoFollow(int target_id) } IncFollowTimes(); } + +void Human::OnWatcherDie(Human* watcher) +{ + if (follow_target_ == watcher) { + follow_target_ = nullptr; + if (socket_handle != 0 && IsPlayer()) { + ((Player*)this)->AsyncRequestWatchWar(true); + } + } else { + #ifdef DEBUG + abort(); + #endif + } +} diff --git a/server/gameserver/human.h b/server/gameserver/human.h index d5f9e28..bb09d3a 100644 --- a/server/gameserver/human.h +++ b/server/gameserver/human.h @@ -269,6 +269,7 @@ class Human : public Creature void ProcUseItem(int item_id); void StartRefreshViewTimer(); void DoFollow(int target_id); + void OnWatcherDie(Human* watcher); protected: void _InternalUpdateMove(float speed); diff --git a/server/gameserver/player.h b/server/gameserver/player.h index 64835a4..47fa30b 100644 --- a/server/gameserver/player.h +++ b/server/gameserver/player.h @@ -122,6 +122,7 @@ class Player : public Human void _CMGetBoxInfo(f8::MsgHdr& hdr, const cs::CMGetBoxInfo& msg); void _CMOpenBox(f8::MsgHdr& hdr, const cs::CMOpenBox& msg); virtual void SetAttackDir(const a8::Vec2& attack_dir) override; + void AsyncRequestWatchWar(bool send_rsp_msg); protected: Player(); @@ -132,7 +133,6 @@ private: void InternalUpdate(int delta_time); std::vector>* GetBox(int box_id); void CheckShotHoldState(Weapon* weapon); - void AsyncRequestWatchWar(bool send_rsp_msg); private: std::map>> box_hash_;