follow_target ok

This commit is contained in:
aozhiwei 2021-09-07 02:57:15 +00:00
parent 77bbf02524
commit d807207da0
7 changed files with 69 additions and 4 deletions

View File

@ -2762,3 +2762,32 @@ void Creature::OnBattleStart(Room* room)
RemoveBuffByUniId(*itr);
}
}
bool Creature::CanFollow(Creature* follower)
{
if (follower->GetUniId() == GetUniId()) {
return false;
}
if (!follower->IsPlayer()) {
return false;
}
if (follower->team_id != team_id) {
return false;
}
#if 0
if (follower->follow_target.Get()) {
return false;
}
#endif
if (!follower->HasBuffEffect(kBET_Jump)) {
return false;
}
if (!IsPlayer()) {
return false;
}
if (!HasBuffEffect(kBET_Jump)) {
return false;
}
return true;
}

View File

@ -238,6 +238,7 @@ class Creature : public MoveableEntity
void TraverseBuff(std::function<void (Buff*, bool&)> func);
long long GetCollisionTimes() { return collision_times_; };
std::string DebugOutBuffList();
bool CanFollow(Creature* follower);
protected:
virtual void OnBuffRemove(Buff& buff);

View File

@ -398,7 +398,7 @@ long long Human::GetRealDeadFrameNo(Room* room)
return real_dead_frameno;
}
void Human::FillMFTeamData(cs::MFTeamData* team_data, bool is_game_over)
void Human::FillMFTeamData(Human* hum, cs::MFTeamData* team_data, bool is_game_over)
{
{
last_sync_teamdata_frameno_ = room->GetFrameNo();
@ -447,6 +447,12 @@ void Human::FillMFTeamData(cs::MFTeamData* team_data, bool is_game_over)
room->GetFrameNo() - room->GetBattleStartFrameNo() < 4) {
team_data->set_user_data(user_data);
}
if (HasBuffEffect(kBET_Jump) && GetTeam()) {
bool can_follow = hum->CanFollow(this);
if (can_follow) {
team_data->set_can_follow(can_follow);
}
}
}
}
@ -652,7 +658,7 @@ void Human::FillSMGameOver(cs::SMGameOver& msg)
[this, &msg] (Human* member) -> bool
{
if (this != member) {
member->FillMFTeamData(msg.add_team_data(), true);
member->FillMFTeamData(this, msg.add_team_data(), true);
cs::MFPlayerStats* p = msg.add_player_stats();
member->FillMFPlayerStats(p);
}
@ -2429,7 +2435,7 @@ void Human::NotifyObservers(cs::SMUpdate* msg, cs::MFActivePlayerData* active_pl
[observer, msg] (Human* member) -> bool
{
if (member != observer) {
member->FillMFTeamData(msg->add_team_data(), false);
member->FillMFTeamData(observer, msg->add_team_data(), false);
}
return true;
});

View File

@ -180,7 +180,7 @@ class Human : public Creature
virtual void OnExplosionHit(Explosion* explosion) override;
void FillItemList(::google::protobuf::RepeatedPtrField<::cs::MFPair>* pb_item_list);
long long GetRealDeadFrameNo(Room* room);
void FillMFTeamData(cs::MFTeamData* team_data, bool is_game_over);
void FillMFTeamData(Human* hum, cs::MFTeamData* team_data, bool is_game_over);
void CarShot(const a8::Vec2& target_dir);
virtual void RecalcSelfCollider() override;
void FindPathInMapService();

View File

@ -20,6 +20,7 @@
#include "perfmonitor.h"
#include "jsondatamgr.h"
#include "skill.h"
#include "team.h"
const int kREVIVE_BUFF_ID = 1005;
@ -1230,6 +1231,23 @@ void Player::UpdateAiming()
void Player::UpdateFollow()
{
if (follow == 0){
if (follow_target.Get()) {
follow_target.Detach();
room->frame_event.AddPropChg(GetWeakPtrRef(), kPropFollowTarget, 0, 0, true);
}
} else {
if (GetTeam()) {
Human* member = GetTeam()->GetMemberByUniId(follow);
if (member && member->CanFollow(this)) {
if (follow_target.Get()) {
follow_target.Detach();
}
follow_target.Attach(member);
room->frame_event.AddPropChg(GetWeakPtrRef(), kPropFollowTarget, 0, follow, true);
}
}
}
follow = -1;
}

View File

@ -108,3 +108,13 @@ void Team::CombineTeam(Team* b_team)
return true;
});
}
Human* Team::GetMemberByUniId(int member_id)
{
for (Human* member : members_) {
if (member->GetUniId() == member_id) {
return member;
}
}
return nullptr;
}

View File

@ -19,6 +19,7 @@ class Team
bool IsFull();
void CombineBornPoint();
void CombineTeam(Team* b_team);
Human* GetMemberByUniId(int member_id);
private:
int team_id_ = 0;