You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
92 lines
2.6 KiB
92 lines
2.6 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
|
|
using Sog;
|
|
using Sog.Service;
|
|
using ProtoCSStruct;
|
|
using PF;
|
|
|
|
namespace Game
|
|
{
|
|
public class RandomPathGenerator : IMovePathGenerator
|
|
{
|
|
public void Update(MapActor actor, long nowMs)
|
|
{
|
|
if (actor.move.IsMoving())
|
|
{
|
|
return;
|
|
}
|
|
|
|
//75%的概率随机停3-5秒,最多连续停两次
|
|
|
|
long nowSec = nowMs / 1000;
|
|
Random rand = GameServerUtils.GetApp().Rand;
|
|
if(actor.move.m_nextPathGenTimeSec > 0 && nowSec - actor.move.m_nextPathGenTimeSec > 0)
|
|
{
|
|
|
|
if(rand.Next() % 100 < 75)
|
|
{
|
|
actor.move.m_nextPathGenTimeSec = nowSec + 3 + rand.Next() % 3;
|
|
actor.move.m_stopPathGenCount++;
|
|
if(actor.move.m_stopPathGenCount == 3)
|
|
{
|
|
GenPath(actor);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
GenPath(actor);
|
|
}
|
|
}
|
|
else if(actor.move.m_nextPathGenTimeSec == 0)
|
|
{
|
|
if(rand.Next()%100 < 75)
|
|
{
|
|
actor.move.m_nextPathGenTimeSec = nowSec + 3 + rand.Next() % 3;
|
|
actor.move.m_stopPathGenCount++;
|
|
}
|
|
else
|
|
{
|
|
GenPath(actor);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void GenPath(MapActor actor)
|
|
{
|
|
actor.move.m_nextPathGenTimeSec = 0;
|
|
actor.move.m_stopPathGenCount = 0;
|
|
|
|
if(actor.map == null)
|
|
{
|
|
TraceLog.Error("RandomPathGenerator.GenPath actor {0} desc {1} no in map inst, mapDesc {2}"
|
|
, actor.actorId, actor.descId, actor.mapDescId);
|
|
return;
|
|
}
|
|
|
|
//
|
|
Vector3 curPosV = MoveUtils.GetVector3FromPosition(actor.position);
|
|
|
|
ABPathWrap path = new ABPathWrap();
|
|
path.InitRandomPath(curPosV);
|
|
|
|
bool bSucc = actor.map.pathfinding.Search(path);
|
|
path.Close();
|
|
|
|
List<Vector3> result = path.Result;
|
|
|
|
if(bSucc && result.Count > 0)
|
|
{
|
|
TraceLog.Trace("RandomPathGenerator.GenPath actor {0} desc {1} gen path {2} {3}");
|
|
|
|
foreach(var dstPos in result)
|
|
{
|
|
MoveController.AddPathPoint(actor, MoveUtils.GetPositionFromVector3(dstPos));
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
|