29 using System.Collections.Generic;
30 using System.Reflection;
31 using System.Threading;
34 using OpenSim.Framework;
35 using pCampBot.Interfaces;
44 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
65 Simulator currentSim = client.Network.CurrentSim;
66 ulong currentHandle = currentSim.Handle;
67 uint currentX, currentY;
68 Utils.LongToUInts(currentHandle, out currentX, out currentY);
70 List<GridRegion> candidateRegions =
new List<GridRegion>();
76 if (candidateRegions.Count != 0)
78 GridRegion destRegion = candidateRegions[Bot.Manager.Rng.Next(candidateRegions.Count)];
80 uint targetX, targetY;
81 Utils.LongToUInts(destRegion.RegionHandle, out targetX, out targetY);
83 Vector3 pos = client.Self.SimPosition;
84 if (targetX < currentX)
86 else if (targetX > currentX)
87 pos.X = Constants.RegionSize + 1;
89 if (targetY < currentY)
91 else if (targetY > currentY)
92 pos.Y = Constants.RegionSize + 1;
95 "[CROSS BEHAVIOUR]: {0} moving to cross from {1} into {2}, target {3}",
96 Bot.Name, currentSim.Name, destRegion.Name, pos);
99 client.Self.Movement.TurnToward(pos);
102 Bot.Client.Self.RegionCrossed += Self_RegionCrossed;
105 Bot.Client.Self.Movement.AtPos =
true;
111 "[CROSS BEHAVIOUR]: {0} failed to cross from {1} into {2} with {3}ms",
117 "[CROSS BEHAVIOUR]: {0} crossed from {1} into {2}",
118 Bot.Name, currentSim.Name, destRegion.Name);
121 Bot.Client.Self.RegionCrossed -= Self_RegionCrossed;
127 "[CROSS BEHAVIOUR]: {0} stopped moving after cross from {1} into {2}",
128 Bot.Name, currentSim.Name, destRegion.Name);
130 Bot.Client.Self.Movement.AtPos =
false;
135 "[CROSS BEHAVIOUR]: No candidate region for {0} to cross into from {1}. Ignoring.",
140 private bool TryAddRegion(ulong handle, List<GridRegion> regions)
142 Dictionary<ulong, GridRegion> knownRegions = Bot.Manager.RegionsKnown;
146 if (knownRegions.Count == 0)
149 m_log.DebugFormat(
"[CROSS BEHAVIOUR]: Looking for region with handle {0} in known regions", handle);
151 if (knownRegions.ContainsKey(handle))
155 "[CROSS BEHAVIOUR]: Adding region {0} to crossing candidates for {1}", region.Name,
Bot.Name);
168 internal void Self_RegionCrossed(
object o, RegionCrossedEventArgs args)
170 m_regionCrossedMutex.Set();
OpenSim.Server.Handlers.Simulation.Utils Utils
AutoResetEvent m_regionCrossedMutex
const int m_regionCrossingTimeout
string AbbreviatedName
Abbreviated name of this behaviour.
Get the bot to make a region crossing.
override void Action()
Action to take when this behaviour is invoked.
OpenSim.Services.Interfaces.GridRegion GridRegion
GridClient Client
New instance of a SecondLife client