Implement safe AdventureBot group travel and formations
This commit is contained in:
1 parent
a758239da9
commit
cac4142ec1
26 files changed
+1482
-79
No files matched your search
@@ -167,7 +167,69 @@ Surface ClientlessFlightMgr::Sample(Player * player, Record & record, float x, f
|
||||
};
|
||||
}
|
||||
|
||||
bool ClientlessFlightMgr::Start(Player * player, Position const & target, std::string & error)
|
||||
bool ClientlessFlightMgr::Start(Player* player,Position const& target,std::string& error)
|
||||
{return Begin(player,target,error,false);}
|
||||
bool ClientlessFlightMgr::Follow(Player* player,Position const& target,std::string& error)
|
||||
{
|
||||
auto found=_records.find(player->GetGUID().GetCounter());
|
||||
if(found!=_records.end() && (found->second.Status.State==ClientlessFlightState::Mounting || found->second.Status.State==ClientlessFlightState::Flying))
|
||||
{
|
||||
auto& record=found->second;
|
||||
if(!record.Status.FollowingPlayer || record.Returning){error="existing flight must finish safely";return false;}
|
||||
if(!Trinity::IsValidMapCoord(target.GetPositionX(),target.GetPositionY(),target.GetPositionZ()))return false;
|
||||
auto surface=Sample(player,record,target.GetPositionX(),target.GetPositionY());
|
||||
if(!surface.Valid || target.GetPositionZ()<surface.Ground || target.GetPositionZ()+5>surface.Ceiling)return false;
|
||||
record.Status.Target=target;record.Status.Landing=target;record.TargetUpdated=record.Elapsed;return true;
|
||||
}
|
||||
return Begin(player,target,error,true);
|
||||
}
|
||||
bool ClientlessFlightMgr::LandFollowing(Player* player)
|
||||
{
|
||||
auto found=_records.find(player->GetGUID().GetCounter());if(found==_records.end())return false;
|
||||
auto& record=found->second;if(!record.Status.FollowingPlayer)return false;
|
||||
record.Status.FollowingPlayer=false;
|
||||
if(record.Status.State==ClientlessFlightState::Mounting)
|
||||
{Fail(player,record,"group flight cancelled before takeoff");return true;}
|
||||
auto surface=Sample(player,record,player->GetPositionX(),player->GetPositionY());
|
||||
float solid=player->GetMap()->GetHeight(player->GetPhaseShift(),player->GetPositionX(),player->GetPositionY(),MAX_HEIGHT,true,MAX_HEIGHT);
|
||||
if(surface.Valid && std::fabs(surface.Ground-solid)<0.7f)
|
||||
{
|
||||
record.Status.Landing.Relocate(player->GetPositionX(),player->GetPositionY(),solid,player->GetOrientation());
|
||||
record.Status.Target=record.Status.Landing;record.Memory={};record.Following.reset();record.Status.Travelled=0;
|
||||
record.Status.Detail="landing after group flight";return true;
|
||||
}
|
||||
Fail(player,record,"no safe local landing; returning along validated flight trail");return true;
|
||||
}
|
||||
bool ClientlessFlightMgr::AdvanceFollowing(Player* player,Record& record)
|
||||
{
|
||||
Point current=PointOf(*player),goal=PointOf(record.Status.Target);
|
||||
if(Distance(current,goal)<2){if(record.Moving)player->StopMoving();record.Moving=false;record.Status.Detail="holding flight formation";return true;}
|
||||
auto sample=[&](float x,float y){return Sample(player,record,x,y);};
|
||||
auto ray=[&](Point const& a,Point const& b){return ClearRay(player,a,b);};
|
||||
auto settings=record.Settings;settings.Safety=1;
|
||||
Point best;float score=std::numeric_limits<float>::infinity();
|
||||
float heading=std::atan2(goal.Y-current.Y,goal.X-current.X);
|
||||
float length=std::min(25.0f,Distance(current,goal));
|
||||
for(float turn:{0.0f,0.4f,-0.4f,0.8f,-0.8f})for(float climb:{0.0f,4.0f})
|
||||
{
|
||||
auto point=Mix(current,goal,std::min(1.0f,length/std::max(0.1f,Distance(current,goal))));
|
||||
if(turn!=0){float horizontal=Horizontal(current,point);point.X=current.X+std::cos(heading+turn)*horizontal;point.Y=current.Y+std::sin(heading+turn)*horizontal;}
|
||||
point.Z+=climb;
|
||||
if(!Corridor(current,point,goal,settings,sample,ray,true))continue;
|
||||
float candidate=Distance(point,goal)+std::fabs(turn)*4+climb;
|
||||
if(candidate<score){score=candidate;best=point;}
|
||||
}
|
||||
if(!std::isfinite(score)){player->StopMoving();record.Moving=false;record.Status.Detail="group flight corridor blocked; holding mounted";return false;}
|
||||
if(record.Moving && player->IsSplineEnabled() && Distance(best,PointOf(record.Segment))<3)return true;
|
||||
if(record.Breadcrumbs.size()<4096)record.Breadcrumbs.push_back(*player);
|
||||
record.Segment.Relocate(best.X,best.Y,best.Z,player->GetOrientation());
|
||||
Movement::MoveSplineInit move(player);move.MoveTo(best.X,best.Y,best.Z,false);move.SetFly();move.SetWalk(false);move.SetVelocity(player->GetSpeed(MOVE_FLIGHT));
|
||||
player->AddUnitMovementFlag(MOVEMENTFLAG_FLYING);
|
||||
if(move.Launch()<=0){record.Moving=false;return false;}
|
||||
record.Moving=true;record.SegmentElapsed=0;++record.Status.Segments;record.Status.Detail="following moving group flight target";return true;
|
||||
}
|
||||
|
||||
bool ClientlessFlightMgr::Begin(Player * player, Position const & target, std::string & error, bool following)
|
||||
{
|
||||
if (! Trinity::IsValidMapCoord(target.GetPositionX(), target.GetPositionY(), target.GetPositionZ()))
|
||||
{
|
||||
@@ -228,7 +290,14 @@ bool ClientlessFlightMgr::Start(Player * player, Position const & target, std::s
|
||||
return false;
|
||||
}
|
||||
bool foundLanding = false;
|
||||
for (float radius :
|
||||
if(following)
|
||||
{
|
||||
auto surface=Sample(player,record,target.GetPositionX(),target.GetPositionY());
|
||||
if(!surface.Valid || target.GetPositionZ()<surface.Ground || target.GetPositionZ()+5>surface.Ceiling)
|
||||
{error="group flight target outside verified flight bounds";return false;}
|
||||
record.Status.Landing=target;record.Status.FollowingPlayer=true;foundLanding=true;
|
||||
}
|
||||
if(!following) for (float radius :
|
||||
{
|
||||
0.0f, 6.0f, 12.0f, 20.0f
|
||||
})
|
||||
@@ -273,13 +342,16 @@ bool ClientlessFlightMgr::Start(Player * player, Position const & target, std::s
|
||||
record.Status.State = ClientlessFlightState::Mounting;
|
||||
record.Status.MountSpell = spell;
|
||||
record.Status.Detail = "waiting for native flying mount";
|
||||
if(auto group=player->GetGroup())if(group->GetLeaderGUID()!=player->GetGUID())
|
||||
if(!following)if(auto group=player->GetGroup())if(group->GetLeaderGUID()!=player->GetGUID())
|
||||
{
|
||||
auto source=_records.find(group->GetLeaderGUID().GetCounter());
|
||||
if(source!=_records.end() && source->second.Status.MapId==player->GetMapId() &&
|
||||
source->second.Status.Target.GetExactDist(target)<1 && !source->second.Published->Aborted)
|
||||
{
|
||||
record.Following=source->second.Published;record.Status.Landing=source->second.Status.Landing;
|
||||
std::vector<ObjectGuid> members;for(auto const& member:group->GetMemberSlots())if(member.guid!=group->GetLeaderGUID())members.push_back(member.guid);
|
||||
std::sort(members.begin(),members.end());auto slot=std::find(members.begin(),members.end(),player->GetGUID())-members.begin();
|
||||
record.FormationDelay=3500+uint32(slot)*600; // native shared corridor, staggered single-file departure
|
||||
TC_LOG_INFO("server.adventurebot.navigation","FLIGHT_SHARED_TRAIL guid=%u leader=%u",player->GetGUID().GetCounter(),group->GetLeaderGUID().GetCounter());
|
||||
}
|
||||
}
|
||||
@@ -297,6 +369,7 @@ bool ClientlessFlightMgr::Start(Player * player, Position const & target, std::s
|
||||
void ClientlessFlightMgr::Fail(Player * player, Record & record, std::string const & reason)
|
||||
{
|
||||
record.Published->Aborted=true;
|
||||
record.Status.FollowingPlayer=false;
|
||||
player->StopMoving();
|
||||
record.Moving = false;
|
||||
if (record.Status.State == ClientlessFlightState::Mounting) player->InterruptNonMeleeSpells(false);
|
||||
@@ -427,6 +500,7 @@ void ClientlessFlightMgr::Update(uint32 diff)
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if(record.Following && record.Elapsed<record.FormationDelay)continue;
|
||||
if (! player->CanFly() || record.Elapsed >(record.Returning ? 2100000u : 1800000u))
|
||||
{
|
||||
Fail(player, record, "flight permission lost or total timeout");
|
||||
@@ -438,6 +512,11 @@ void ClientlessFlightMgr::Update(uint32 diff)
|
||||
continue;
|
||||
}
|
||||
record.CheckTimer = 200;
|
||||
if(record.Status.FollowingPlayer)
|
||||
{
|
||||
if(record.Elapsed-record.TargetUpdated>5000 || player->IsInCombat())LandFollowing(player);
|
||||
else {AdvanceFollowing(player,record);continue;}
|
||||
}
|
||||
if (record.Moving && player->IsSplineEnabled())
|
||||
{
|
||||
if (record.SegmentElapsed > 10000)
|
||||
|
||||
Reference in new issue
Block a user