aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Tools/pCampBot/Behaviours
diff options
context:
space:
mode:
authorJustin Clark-Casey (justincc)2011-11-24 22:36:45 +0000
committerJustin Clark-Casey (justincc)2011-11-24 22:36:45 +0000
commit2ae5b40ca6bb3d33310f0f66569bf150548a2de6 (patch)
tree9c485fa9e2e9d1b2d976d3b6d9777457b836df36 /OpenSim/Tools/pCampBot/Behaviours
parentminor: remove mono compiler warning (diff)
downloadopensim-SC_OLD-2ae5b40ca6bb3d33310f0f66569bf150548a2de6.zip
opensim-SC_OLD-2ae5b40ca6bb3d33310f0f66569bf150548a2de6.tar.gz
opensim-SC_OLD-2ae5b40ca6bb3d33310f0f66569bf150548a2de6.tar.bz2
opensim-SC_OLD-2ae5b40ca6bb3d33310f0f66569bf150548a2de6.tar.xz
On pCampBot, add bot as a property on behaviours instead of passing it in every time
Diffstat (limited to 'OpenSim/Tools/pCampBot/Behaviours')
-rw-r--r--OpenSim/Tools/pCampBot/Behaviours/AbstractBehaviour.cs49
-rw-r--r--OpenSim/Tools/pCampBot/Behaviours/GrabbingBehaviour.cs16
-rw-r--r--OpenSim/Tools/pCampBot/Behaviours/PhysicsBehaviour.cs31
-rw-r--r--OpenSim/Tools/pCampBot/Behaviours/TeleportBehaviour.cs22
4 files changed, 83 insertions, 35 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
28using OpenMetaverse;
29using System;
30using System.Collections.Generic;
31using System.Linq;
32using pCampBot.Interfaces;
33
34namespace 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/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 25529d0..daa7485 100644
--- a/OpenSim/Tools/pCampBot/Behaviours/PhysicsBehaviour.cs
+++ b/OpenSim/Tools/pCampBot/Behaviours/PhysicsBehaviour.cs
@@ -40,42 +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 70
72 bot.Client.Self.Movement.AtPos = true; 71 Bot.Client.Self.Movement.AtPos = true;
73 Thread.Sleep(bot.Random.Next(3000, 13000)); 72 Thread.Sleep(Bot.Random.Next(3000, 13000));
74 bot.Client.Self.Movement.AtPos = false; 73 Bot.Client.Self.Movement.AtPos = false;
75 bot.Client.Self.Jump(true); 74 Bot.Client.Self.Jump(true);
76 string randomf = talkarray[bot.Random.Next(talkarray.Length)]; 75 string randomf = talkarray[Bot.Random.Next(talkarray.Length)];
77 if (talkarray.Length > 1 && randomf.Length > 1) 76 if (talkarray.Length > 1 && randomf.Length > 1)
78 bot.Client.Self.Chat(randomf, 0, ChatType.Normal); 77 Bot.Client.Self.Chat(randomf, 0, ChatType.Normal);
79 } 78 }
80 79
81 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