死亡后自动观战

This commit is contained in:
aozhiwei 2021-09-10 05:58:46 +00:00
parent 9364d4dafd
commit 0e1e48363f
3 changed files with 28 additions and 1 deletions

View File

@ -2181,6 +2181,18 @@ void Human::OnDie()
hum->SendGameOver();
}
}
if (observers_.size() > 1) {
std::vector<Human*> 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
}
}

View File

@ -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);

View File

@ -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<std::tuple<int, int, int>>* GetBox(int box_id);
void CheckShotHoldState(Weapon* weapon);
void AsyncRequestWatchWar(bool send_rsp_msg);
private:
std::map<int, std::vector<std::tuple<int, int, int>>> box_hash_;