Add click/grab behaviour to pCampbot, which gets bots to randomly click things.
This can be specified on pCampbot.exe by using g in the list of behaviours for the new -behaviours,-b switch e.g. -b p,g to get both existing physics and grabbing behaviours. grabbing is primitive, it attempts grabs on random prims whether they're actually signalled as clickable or not. behaviour is currently primitive overall, behaviours are just executed in a listremove-scene-viewer
parent
3ea379e4cd
commit
5a67940acc
|
@ -0,0 +1,56 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) Contributors, http://opensimulator.org/
|
||||||
|
* See CONTRIBUTORS.TXT for a full list of copyright holders.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
* * Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* * Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* * Neither the name of the OpenSimulator Project nor the
|
||||||
|
* names of its contributors may be used to endorse or promote products
|
||||||
|
* derived from this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
|
||||||
|
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
|
||||||
|
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||||
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
using OpenMetaverse;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using pCampBot.Interfaces;
|
||||||
|
|
||||||
|
namespace pCampBot
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Click (grab) on random objects in the scene.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// The viewer itself does not give the option of grabbing objects that haven't been signalled as grabbable.
|
||||||
|
/// </remarks>
|
||||||
|
public class GrabbingBehaviour : IBehaviour
|
||||||
|
{
|
||||||
|
public void Action(PhysicsBot bot)
|
||||||
|
{
|
||||||
|
Dictionary<UUID, Primitive> objects = bot.Objects;
|
||||||
|
|
||||||
|
Primitive prim = objects.ElementAt(bot.Random.Next(0, objects.Count)).Value;
|
||||||
|
|
||||||
|
// This appears to be a typical message sent when a viewer user clicks a clickable object
|
||||||
|
bot.Client.Self.Grab(prim.LocalID);
|
||||||
|
bot.Client.Self.GrabUpdate(prim.ID, Vector3.Zero);
|
||||||
|
bot.Client.Self.DeGrab(prim.LocalID);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -35,7 +35,7 @@ using pCampBot.Interfaces;
|
||||||
namespace pCampBot
|
namespace pCampBot
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This is a behaviour designed to stress physics by moving and bouncing around bots a whole lot.
|
/// Stress physics by moving and bouncing around bots a whole lot.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <remarks>
|
/// <remarks>
|
||||||
/// TODO: talkarray should be in a separate behaviour.
|
/// TODO: talkarray should be in a separate behaviour.
|
||||||
|
|
|
@ -120,13 +120,23 @@ namespace pCampBot
|
||||||
string password = cs.GetString("password");
|
string password = cs.GetString("password");
|
||||||
string loginUri = cs.GetString("loginuri");
|
string loginUri = cs.GetString("loginuri");
|
||||||
|
|
||||||
// Hardcoded for new
|
HashSet<string> behaviourSwitches = new HashSet<string>();
|
||||||
List<IBehaviour> behaviours = new List<IBehaviour>();
|
Array.ForEach<string>(
|
||||||
behaviours.Add(new PhysicsBehaviour());
|
cs.GetString("behaviours", "p").Split(new char[] { ',' }), b => behaviourSwitches.Add(b));
|
||||||
|
|
||||||
for (int i = 0; i < botcount; i++)
|
for (int i = 0; i < botcount; i++)
|
||||||
{
|
{
|
||||||
string lastName = string.Format("{0}_{1}", lastNameStem, i);
|
string lastName = string.Format("{0}_{1}", lastNameStem, i);
|
||||||
|
|
||||||
|
List<IBehaviour> behaviours = new List<IBehaviour>();
|
||||||
|
|
||||||
|
// Hard-coded for now
|
||||||
|
if (behaviourSwitches.Contains("p"))
|
||||||
|
behaviours.Add(new PhysicsBehaviour());
|
||||||
|
|
||||||
|
if (behaviourSwitches.Contains("g"))
|
||||||
|
behaviours.Add(new GrabbingBehaviour());
|
||||||
|
|
||||||
startupBot(i, this, behaviours, firstName, lastName, password, loginUri);
|
startupBot(i, this, behaviours, firstName, lastName, password, loginUri);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,8 +55,27 @@ namespace pCampBot
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Behaviours implemented by this bot.
|
/// Behaviours implemented by this bot.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// Lock this list before manipulating it.
|
||||||
|
/// </remarks>
|
||||||
public List<IBehaviour> Behaviours { get; private set; }
|
public List<IBehaviour> Behaviours { get; private set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Objects that the bot has discovered.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// Returns a list copy. Inserting new objects manually will have no effect.
|
||||||
|
/// </remarks>
|
||||||
|
public Dictionary<UUID, Primitive> Objects
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
lock (m_objects)
|
||||||
|
return new Dictionary<UUID, Primitive>(m_objects);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private Dictionary<UUID, Primitive> m_objects = new Dictionary<UUID, Primitive>();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Is this bot connected to the grid?
|
/// Is this bot connected to the grid?
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -125,7 +144,14 @@ namespace pCampBot
|
||||||
private void Action()
|
private void Action()
|
||||||
{
|
{
|
||||||
while (true)
|
while (true)
|
||||||
Behaviours.ForEach(b => b.Action(this));
|
lock (Behaviours)
|
||||||
|
Behaviours.ForEach(
|
||||||
|
b =>
|
||||||
|
{
|
||||||
|
// m_log.DebugFormat("[pCAMPBOT]: For {0} performing action {1}", Name, b.GetType());
|
||||||
|
b.Action(this);
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -407,6 +433,9 @@ namespace pCampBot
|
||||||
|
|
||||||
if (prim != null)
|
if (prim != null)
|
||||||
{
|
{
|
||||||
|
lock (m_objects)
|
||||||
|
m_objects[prim.ID] = prim;
|
||||||
|
|
||||||
if (prim.Textures != null)
|
if (prim.Textures != null)
|
||||||
{
|
{
|
||||||
if (prim.Textures.DefaultTexture.TextureID != UUID.Zero)
|
if (prim.Textures.DefaultTexture.TextureID != UUID.Zero)
|
||||||
|
|
|
@ -84,12 +84,13 @@ namespace pCampBot
|
||||||
//Set up our nifty config.. thanks to nini
|
//Set up our nifty config.. thanks to nini
|
||||||
ArgvConfigSource cs = new ArgvConfigSource(args);
|
ArgvConfigSource cs = new ArgvConfigSource(args);
|
||||||
|
|
||||||
cs.AddSwitch("Startup", "botcount","n");
|
cs.AddSwitch("Startup", "botcount", "n");
|
||||||
cs.AddSwitch("Startup", "loginuri","l");
|
cs.AddSwitch("Startup", "loginuri", "l");
|
||||||
cs.AddSwitch("Startup", "firstname");
|
cs.AddSwitch("Startup", "firstname");
|
||||||
cs.AddSwitch("Startup", "lastname");
|
cs.AddSwitch("Startup", "lastname");
|
||||||
cs.AddSwitch("Startup", "password");
|
cs.AddSwitch("Startup", "password");
|
||||||
cs.AddSwitch("Startup", "help","h");
|
cs.AddSwitch("Startup", "behaviours", "b");
|
||||||
|
cs.AddSwitch("Startup", "help", "h");
|
||||||
cs.AddSwitch("Startup", "wear");
|
cs.AddSwitch("Startup", "wear");
|
||||||
|
|
||||||
IConfig ol = cs.Configs["Startup"];
|
IConfig ol = cs.Configs["Startup"];
|
||||||
|
@ -110,6 +111,7 @@ namespace pCampBot
|
||||||
" -firstname first name for the bots\n" +
|
" -firstname first name for the bots\n" +
|
||||||
" -lastname lastname for the bots. Each lastname will have _<bot-number> appended, e.g. Ima Bot_0\n" +
|
" -lastname lastname for the bots. Each lastname will have _<bot-number> appended, e.g. Ima Bot_0\n" +
|
||||||
" -password password for the bots\n" +
|
" -password password for the bots\n" +
|
||||||
|
" -b, behaviours behaviours for bots. Current options p (physics), g (grab). Comma separated, e.g. p,g. Default is p",
|
||||||
" -wear set appearance folder to load from (default: no)\n" +
|
" -wear set appearance folder to load from (default: no)\n" +
|
||||||
" -h, -help show this message"
|
" -h, -help show this message"
|
||||||
);
|
);
|
||||||
|
|
|
@ -2487,6 +2487,7 @@
|
||||||
|
|
||||||
<ReferencePath>../../../bin/</ReferencePath>
|
<ReferencePath>../../../bin/</ReferencePath>
|
||||||
<Reference name="System"/>
|
<Reference name="System"/>
|
||||||
|
<Reference name="System.Core"/>
|
||||||
<Reference name="OpenMetaverseTypes" path="../../../bin/"/>
|
<Reference name="OpenMetaverseTypes" path="../../../bin/"/>
|
||||||
<Reference name="OpenMetaverse" path="../../../bin/"/>
|
<Reference name="OpenMetaverse" path="../../../bin/"/>
|
||||||
<Reference name="OpenSim.Framework"/>
|
<Reference name="OpenSim.Framework"/>
|
||||||
|
|
Loading…
Reference in New Issue