diff options
Diffstat (limited to 'OpenSim/Tools/pCampBot/Behaviours')
5 files changed, 252 insertions, 36 deletions
diff --git a/OpenSim/Tools/pCampBot/Behaviours/AbstractBehaviour.cs b/OpenSim/Tools/pCampBot/Behaviours/AbstractBehaviour.cs new file mode 100644 index 0000000..9a9371d --- /dev/null +++ b/OpenSim/Tools/pCampBot/Behaviours/AbstractBehaviour.cs | |||
@@ -0,0 +1,49 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using OpenMetaverse; | ||
29 | using System; | ||
30 | using System.Collections.Generic; | ||
31 | using System.Linq; | ||
32 | using pCampBot.Interfaces; | ||
33 | |||
34 | namespace pCampBot | ||
35 | { | ||
36 | public class AbstractBehaviour : IBehaviour | ||
37 | { | ||
38 | public string Name { get; protected set; } | ||
39 | |||
40 | public Bot Bot { get; protected set; } | ||
41 | |||
42 | public virtual void Action() {} | ||
43 | |||
44 | public virtual void Initialize(Bot bot) | ||
45 | { | ||
46 | Bot = bot; | ||
47 | } | ||
48 | } | ||
49 | } | ||
diff --git a/OpenSim/Tools/pCampBot/Behaviours/CrossBehaviour.cs b/OpenSim/Tools/pCampBot/Behaviours/CrossBehaviour.cs new file mode 100644 index 0000000..1e01c64 --- /dev/null +++ b/OpenSim/Tools/pCampBot/Behaviours/CrossBehaviour.cs | |||
@@ -0,0 +1,169 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Reflection; | ||
31 | using System.Threading; | ||
32 | using log4net; | ||
33 | using OpenMetaverse; | ||
34 | using OpenSim.Framework; | ||
35 | using pCampBot.Interfaces; | ||
36 | |||
37 | namespace pCampBot | ||
38 | { | ||
39 | /// <summary> | ||
40 | /// Get the bot to make a region crossing. | ||
41 | /// </summary> | ||
42 | public class CrossBehaviour : AbstractBehaviour | ||
43 | { | ||
44 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
45 | |||
46 | public AutoResetEvent m_regionCrossedMutex = new AutoResetEvent(false); | ||
47 | |||
48 | public const int m_regionCrossingTimeout = 1000 * 60; | ||
49 | |||
50 | public CrossBehaviour() { Name = "Cross"; } | ||
51 | |||
52 | public override void Action() | ||
53 | { | ||
54 | GridClient client = Bot.Client; | ||
55 | |||
56 | // // Fly to make the border cross easier. | ||
57 | // client.Self.Movement.Fly = true; | ||
58 | // client.Self.Movement.Fly = false; | ||
59 | |||
60 | // Seek out neighbouring region | ||
61 | Simulator currentSim = client.Network.CurrentSim; | ||
62 | ulong currentHandle = currentSim.Handle; | ||
63 | uint currentX, currentY; | ||
64 | Utils.LongToUInts(currentHandle, out currentX, out currentY); | ||
65 | |||
66 | List<GridRegion> candidateRegions = new List<GridRegion>(); | ||
67 | TryAddRegion(Utils.UIntsToLong(Math.Max(0, currentX - Constants.RegionSize), currentY), candidateRegions); // West | ||
68 | TryAddRegion(Utils.UIntsToLong(currentX + Constants.RegionSize, currentY), candidateRegions); // East | ||
69 | TryAddRegion(Utils.UIntsToLong(currentX, Math.Max(0, currentY - Constants.RegionSize)), candidateRegions); // South | ||
70 | TryAddRegion(Utils.UIntsToLong(currentX, currentY + Constants.RegionSize), candidateRegions); // North | ||
71 | |||
72 | if (candidateRegions.Count != 0) | ||
73 | { | ||
74 | GridRegion destRegion = candidateRegions[Bot.Manager.Rng.Next(candidateRegions.Count)]; | ||
75 | |||
76 | uint targetX, targetY; | ||
77 | Utils.LongToUInts(destRegion.RegionHandle, out targetX, out targetY); | ||
78 | |||
79 | Vector3 pos = client.Self.SimPosition; | ||
80 | if (targetX < currentX) | ||
81 | pos.X = -1; | ||
82 | else if (targetX > currentX) | ||
83 | pos.X = Constants.RegionSize + 1; | ||
84 | |||
85 | if (targetY < currentY) | ||
86 | pos.Y = -1; | ||
87 | else if (targetY > currentY) | ||
88 | pos.Y = Constants.RegionSize + 1; | ||
89 | |||
90 | m_log.DebugFormat( | ||
91 | "[CROSS BEHAVIOUR]: {0} moving to cross from {1} into {2}, target {3}", | ||
92 | Bot.Name, currentSim.Name, destRegion.Name, pos); | ||
93 | |||
94 | // Face in the direction of the candidate region | ||
95 | client.Self.Movement.TurnToward(pos); | ||
96 | |||
97 | // Listen for event so that we know when we've crossed the region boundary | ||
98 | Bot.Client.Self.RegionCrossed += Self_RegionCrossed; | ||
99 | |||
100 | // Start moving | ||
101 | Bot.Client.Self.Movement.AtPos = true; | ||
102 | |||
103 | // Stop when reach region target or border cross detected | ||
104 | if (!m_regionCrossedMutex.WaitOne(m_regionCrossingTimeout)) | ||
105 | { | ||
106 | m_log.ErrorFormat( | ||
107 | "[CROSS BEHAVIOUR]: {0} failed to cross from {1} into {2} with {3}ms", | ||
108 | Bot.Name, currentSim.Name, destRegion.Name, m_regionCrossingTimeout); | ||
109 | } | ||
110 | else | ||
111 | { | ||
112 | m_log.DebugFormat( | ||
113 | "[CROSS BEHAVIOUR]: {0} crossed from {1} into {2}", | ||
114 | Bot.Name, currentSim.Name, destRegion.Name); | ||
115 | } | ||
116 | |||
117 | Bot.Client.Self.RegionCrossed -= Self_RegionCrossed; | ||
118 | |||
119 | // We will hackishly carry on travelling into the region for a little bit. | ||
120 | Thread.Sleep(6000); | ||
121 | |||
122 | m_log.DebugFormat( | ||
123 | "[CROSS BEHAVIOUR]: {0} stopped moving after cross from {1} into {2}", | ||
124 | Bot.Name, currentSim.Name, destRegion.Name); | ||
125 | |||
126 | Bot.Client.Self.Movement.AtPos = false; | ||
127 | } | ||
128 | else | ||
129 | { | ||
130 | m_log.DebugFormat( | ||
131 | "[CROSS BEHAVIOUR]: No candidate region for {0} to cross into from {1}. Ignoring.", | ||
132 | Bot.Name, currentSim.Name); | ||
133 | } | ||
134 | } | ||
135 | |||
136 | private bool TryAddRegion(ulong handle, List<GridRegion> regions) | ||
137 | { | ||
138 | Dictionary<ulong, GridRegion> knownRegions = Bot.Manager.RegionsKnown; | ||
139 | |||
140 | lock (knownRegions) | ||
141 | { | ||
142 | if (knownRegions.Count == 0) | ||
143 | return false; | ||
144 | |||
145 | m_log.DebugFormat("[CROSS BEHAVIOUR]: Looking for region with handle {0} in known regions", handle); | ||
146 | |||
147 | if (knownRegions.ContainsKey(handle)) | ||
148 | { | ||
149 | GridRegion region = knownRegions[handle]; | ||
150 | m_log.DebugFormat( | ||
151 | "[CROSS BEHAVIOUR]: Adding region {0} to crossing candidates for {1}", region.Name, Bot.Name); | ||
152 | |||
153 | regions.Add(region); | ||
154 | |||
155 | return true; | ||
156 | } | ||
157 | else | ||
158 | { | ||
159 | return false; | ||
160 | } | ||
161 | } | ||
162 | } | ||
163 | |||
164 | internal void Self_RegionCrossed(object o, RegionCrossedEventArgs args) | ||
165 | { | ||
166 | m_regionCrossedMutex.Set(); | ||
167 | } | ||
168 | } | ||
169 | } \ No newline at end of file | ||
diff --git a/OpenSim/Tools/pCampBot/Behaviours/GrabbingBehaviour.cs b/OpenSim/Tools/pCampBot/Behaviours/GrabbingBehaviour.cs index 0a6d5d2..6ad02b2 100644 --- a/OpenSim/Tools/pCampBot/Behaviours/GrabbingBehaviour.cs +++ b/OpenSim/Tools/pCampBot/Behaviours/GrabbingBehaviour.cs | |||
@@ -39,20 +39,20 @@ namespace pCampBot | |||
39 | /// <remarks> | 39 | /// <remarks> |
40 | /// The viewer itself does not give the option of grabbing objects that haven't been signalled as grabbable. | 40 | /// The viewer itself does not give the option of grabbing objects that haven't been signalled as grabbable. |
41 | /// </remarks> | 41 | /// </remarks> |
42 | public class GrabbingBehaviour : IBehaviour | 42 | public class GrabbingBehaviour : AbstractBehaviour |
43 | { | 43 | { |
44 | public string Name { get { return "Grabbing"; } } | 44 | public GrabbingBehaviour() { Name = "Grabbing"; } |
45 | 45 | ||
46 | public void Action(Bot bot) | 46 | public override void Action() |
47 | { | 47 | { |
48 | Dictionary<UUID, Primitive> objects = bot.Objects; | 48 | Dictionary<UUID, Primitive> objects = Bot.Objects; |
49 | 49 | ||
50 | Primitive prim = objects.ElementAt(bot.Random.Next(0, objects.Count)).Value; | 50 | Primitive prim = objects.ElementAt(Bot.Random.Next(0, objects.Count)).Value; |
51 | 51 | ||
52 | // This appears to be a typical message sent when a viewer user clicks a clickable object | 52 | // This appears to be a typical message sent when a viewer user clicks a clickable object |
53 | bot.Client.Self.Grab(prim.LocalID); | 53 | Bot.Client.Self.Grab(prim.LocalID); |
54 | bot.Client.Self.GrabUpdate(prim.ID, Vector3.Zero); | 54 | Bot.Client.Self.GrabUpdate(prim.ID, Vector3.Zero); |
55 | bot.Client.Self.DeGrab(prim.LocalID); | 55 | Bot.Client.Self.DeGrab(prim.LocalID); |
56 | } | 56 | } |
57 | } | 57 | } |
58 | } \ No newline at end of file | 58 | } \ No newline at end of file |
diff --git a/OpenSim/Tools/pCampBot/Behaviours/PhysicsBehaviour.cs b/OpenSim/Tools/pCampBot/Behaviours/PhysicsBehaviour.cs index f782bb5..daa7485 100644 --- a/OpenSim/Tools/pCampBot/Behaviours/PhysicsBehaviour.cs +++ b/OpenSim/Tools/pCampBot/Behaviours/PhysicsBehaviour.cs | |||
@@ -40,43 +40,41 @@ namespace pCampBot | |||
40 | /// <remarks> | 40 | /// <remarks> |
41 | /// TODO: talkarray should be in a separate behaviour. | 41 | /// TODO: talkarray should be in a separate behaviour. |
42 | /// </remarks> | 42 | /// </remarks> |
43 | public class PhysicsBehaviour : IBehaviour | 43 | public class PhysicsBehaviour : AbstractBehaviour |
44 | { | 44 | { |
45 | public string Name { get { return "Physics"; } } | ||
46 | |||
47 | private string[] talkarray; | 45 | private string[] talkarray; |
48 | 46 | ||
49 | public PhysicsBehaviour() | 47 | public PhysicsBehaviour() |
50 | { | 48 | { |
49 | Name = "Physics"; | ||
51 | talkarray = readexcuses(); | 50 | talkarray = readexcuses(); |
52 | } | 51 | } |
53 | 52 | ||
54 | public void Action(Bot bot) | 53 | public override void Action() |
55 | { | 54 | { |
56 | int walkorrun = bot.Random.Next(4); // Randomize between walking and running. The greater this number, | 55 | int walkorrun = Bot.Random.Next(4); // Randomize between walking and running. The greater this number, |
57 | // the greater the bot's chances to walk instead of run. | 56 | // the greater the bot's chances to walk instead of run. |
58 | bot.Client.Self.Jump(false); | 57 | Bot.Client.Self.Jump(false); |
59 | if (walkorrun == 0) | 58 | if (walkorrun == 0) |
60 | { | 59 | { |
61 | bot.Client.Self.Movement.AlwaysRun = true; | 60 | Bot.Client.Self.Movement.AlwaysRun = true; |
62 | } | 61 | } |
63 | else | 62 | else |
64 | { | 63 | { |
65 | bot.Client.Self.Movement.AlwaysRun = false; | 64 | Bot.Client.Self.Movement.AlwaysRun = false; |
66 | } | 65 | } |
67 | 66 | ||
68 | // TODO: unused: Vector3 pos = client.Self.SimPosition; | 67 | // TODO: unused: Vector3 pos = client.Self.SimPosition; |
69 | Vector3 newpos = new Vector3(bot.Random.Next(1, 254), bot.Random.Next(1, 254), bot.Random.Next(1, 254)); | 68 | Vector3 newpos = new Vector3(Bot.Random.Next(1, 254), Bot.Random.Next(1, 254), Bot.Random.Next(1, 254)); |
70 | bot.Client.Self.Movement.TurnToward(newpos); | 69 | Bot.Client.Self.Movement.TurnToward(newpos); |
71 | |||
72 | bot.Client.Self.Movement.AtPos = true; | ||
73 | Thread.Sleep(bot.Random.Next(3000, 13000)); | ||
74 | bot.Client.Self.Movement.AtPos = false; | ||
75 | bot.Client.Self.Jump(true); | ||
76 | 70 | ||
77 | string randomf = talkarray[bot.Random.Next(talkarray.Length)]; | 71 | Bot.Client.Self.Movement.AtPos = true; |
72 | Thread.Sleep(Bot.Random.Next(3000, 13000)); | ||
73 | Bot.Client.Self.Movement.AtPos = false; | ||
74 | Bot.Client.Self.Jump(true); | ||
75 | string randomf = talkarray[Bot.Random.Next(talkarray.Length)]; | ||
78 | if (talkarray.Length > 1 && randomf.Length > 1) | 76 | if (talkarray.Length > 1 && randomf.Length > 1) |
79 | bot.Client.Self.Chat(randomf, 0, ChatType.Normal); | 77 | Bot.Client.Self.Chat(randomf, 0, ChatType.Normal); |
80 | } | 78 | } |
81 | 79 | ||
82 | private string[] readexcuses() | 80 | private string[] readexcuses() |
diff --git a/OpenSim/Tools/pCampBot/Behaviours/TeleportBehaviour.cs b/OpenSim/Tools/pCampBot/Behaviours/TeleportBehaviour.cs index fc2ed2c..fbb4e96 100644 --- a/OpenSim/Tools/pCampBot/Behaviours/TeleportBehaviour.cs +++ b/OpenSim/Tools/pCampBot/Behaviours/TeleportBehaviour.cs | |||
@@ -38,38 +38,38 @@ namespace pCampBot | |||
38 | /// <summary> | 38 | /// <summary> |
39 | /// Teleport to a random region on the grid. | 39 | /// Teleport to a random region on the grid. |
40 | /// </summary> | 40 | /// </summary> |
41 | public class TeleportBehaviour : IBehaviour | 41 | public class TeleportBehaviour : AbstractBehaviour |
42 | { | 42 | { |
43 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 43 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
44 | 44 | ||
45 | public string Name { get { return "Teleport"; } } | 45 | public TeleportBehaviour() { Name = "Teleport"; } |
46 | 46 | ||
47 | public void Action(Bot bot) | 47 | public override void Action() |
48 | { | 48 | { |
49 | Random rng = bot.Manager.Rng; | 49 | Random rng = Bot.Manager.Rng; |
50 | GridRegion[] knownRegions; | 50 | GridRegion[] knownRegions; |
51 | 51 | ||
52 | lock (bot.Manager.RegionsKnown) | 52 | lock (Bot.Manager.RegionsKnown) |
53 | { | 53 | { |
54 | if (bot.Manager.RegionsKnown.Count == 0) | 54 | if (Bot.Manager.RegionsKnown.Count == 0) |
55 | { | 55 | { |
56 | m_log.DebugFormat( | 56 | m_log.DebugFormat( |
57 | "[TELEPORT BEHAVIOUR]: Ignoring teleport action for {0} since no regions are known yet", bot.Name); | 57 | "[TELEPORT BEHAVIOUR]: Ignoring teleport action for {0} since no regions are known yet", Bot.Name); |
58 | return; | 58 | return; |
59 | } | 59 | } |
60 | 60 | ||
61 | knownRegions = bot.Manager.RegionsKnown.Values.ToArray(); | 61 | knownRegions = Bot.Manager.RegionsKnown.Values.ToArray(); |
62 | } | 62 | } |
63 | 63 | ||
64 | Simulator sourceRegion = bot.Client.Network.CurrentSim; | 64 | Simulator sourceRegion = Bot.Client.Network.CurrentSim; |
65 | GridRegion destRegion = knownRegions[rng.Next(knownRegions.Length)]; | 65 | GridRegion destRegion = knownRegions[rng.Next(knownRegions.Length)]; |
66 | Vector3 destPosition = new Vector3(rng.Next(255), rng.Next(255), 50); | 66 | Vector3 destPosition = new Vector3(rng.Next(255), rng.Next(255), 50); |
67 | 67 | ||
68 | m_log.DebugFormat( | 68 | m_log.DebugFormat( |
69 | "[TELEPORT BEHAVIOUR]: Teleporting {0} from {1} {2} to {3} {4}", | 69 | "[TELEPORT BEHAVIOUR]: Teleporting {0} from {1} {2} to {3} {4}", |
70 | bot.Name, sourceRegion.Name, bot.Client.Self.SimPosition, destRegion.Name, destPosition); | 70 | Bot.Name, sourceRegion.Name, Bot.Client.Self.SimPosition, destRegion.Name, destPosition); |
71 | 71 | ||
72 | bot.Client.Self.Teleport(destRegion.RegionHandle, destPosition); | 72 | Bot.Client.Self.Teleport(destRegion.RegionHandle, destPosition); |
73 | } | 73 | } |
74 | } | 74 | } |
75 | } \ No newline at end of file | 75 | } \ No newline at end of file |