[XmlElement("ExploreDungeonFunk")]
public class ExploreDungeonFunkTag : ProfileBehavior
{
private bool m_IsDone = false;
public override bool IsDone
{
get { return m_IsDone; }
}
private Zeta.CommonBot.Dungeons.DungeonExplorer DE;
private MoveResult lastMoveResult = MoveResult.PathGenerating;
private bool InitDone = false;
private void Init()
{
Zeta.CommonBot.Dungeons.GridSegmentation.BoxSize = 18;
Zeta.CommonBot.Dungeons.GridSegmentation.BoxTolerance = 0.18f;
Zeta.CommonBot.Dungeons.GridSegmentation.Update();
Zeta.CommonBot.Logic.BrainBehavior.DungeonExplorer.Reset();
Zeta.CommonBot.Logic.BrainBehavior.DungeonExplorer.Update();
DE= Zeta.CommonBot.Logic.BrainBehavior.DungeonExplorer;
Logging.Write("DE CR: " + DE.CurrentRoute.Count());
Logging.Write("DE BR: " + DE.GetBestRoute().Count());
InitDone = true;
}
private Zeta.Pathfinding.PathFindResult PR = new Zeta.Pathfinding.PathFindResult();
private void UpdateRoute()
{
DE.Update();
lastMoveResult = MoveResult.PathGenerated;
}
private void MoveToNextNode()
{
DungeonNode NextNode = DE.CurrentRoute.Peek();
float Distance = ZetaDia.Me.Position.Distance(NextNode.NavigableCenter);
Vector3 NextTargetV3 = MathEx.CalculatePointFrom(ZetaDia.Me.Position, NextNode.NavigableCenter, Distance);
Logging.Write("Moving to " + NextNode.NavigableCenter.ToString());
lastMoveResult = Zeta.Navigation.Navigator.MoveTo(NextNode.NavigableCenter);
switch (lastMoveResult)
{
case MoveResult.ReachedDestination:
break;
case MoveResult.Moved:
Logging.Write("Movement return is successful.");
break;
case MoveResult.PathGenerated:
case MoveResult.PathGenerating:
break;
case MoveResult.Failed:
case MoveResult.PathGenerationFailed:
Logging.Write("Movement return is failure!");
break;
}
}
private static Vector3 PlayerPOS = Vector3.Zero;
private static DateTime lastUpdatedPOS = DateTime.MinValue;
private static void PlayerPOSUpdate()
{
lastUpdatedPOS = DateTime.Now;
try
{
PlayerPOS = ZetaDia.Me.Position;
}
catch { PlayerPOS = Vector3.Zero; }
}
protected override Composite CreateBehavior()
{
return
new Zeta.TreeSharp.Sequence(
new Zeta.TreeSharp.Action(ret => PlayerPOSUpdate()
),
new Zeta.TreeSharp.PrioritySelector(
new Zeta.TreeSharp.Decorator(ret => !InitDone,
new Zeta.TreeSharp.Action(ret => Init())
),
new Zeta.TreeSharp.Decorator(ret => DE.CurrentRoute.Count == 0,
new Zeta.TreeSharp.Action(ret => DE.Update())
),
new Zeta.TreeSharp.Decorator(ret => DateTime.Now.Subtract(lastUpdatedPOS).TotalSeconds >= 2,
new Zeta.TreeSharp.Action(ret => PlayerPOSUpdate())
),
new Zeta.TreeSharp.Decorator(ret => lastMoveResult != MoveResult.Moved && (lastMoveResult == MoveResult.Failed || lastMoveResult == MoveResult.PathGenerationFailed),
new Zeta.TreeSharp.Action(ret => UpdateRoute())
),
new Zeta.TreeSharp.Decorator(ret => DE.CurrentNode.NavigableCenter.Distance(PlayerPOS) <= 10f || lastMoveResult == MoveResult.ReachedDestination,
new Zeta.TreeSharp.Action(ret => DE.CurrentRoute.Dequeue())
),
new Zeta.TreeSharp.Decorator(ret => !ZetaDia.Me.Movement.IsMoving,
new Zeta.TreeSharp.Action(ret => MoveToNextNode())
)));
}
}