From 3dbe7313d1c3fc28f0642531fbb6e238a98ac821 Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Tue, 3 Sep 2013 19:33:17 +0100 Subject: [PATCH] Add Close() method to IBehaviour to allow behaviours to cleanup when removed or bot it disconnected. In this case, it is used to turn off jump when physics testing behaviour is removed. --- .../pCampBot/Behaviours/AbstractBehaviour.cs | 2 ++ .../pCampBot/Behaviours/PhysicsBehaviour.cs | 5 +++++ OpenSim/Tools/pCampBot/Bot.cs | 16 +++++++++++++++- OpenSim/Tools/pCampBot/Interfaces/IBehaviour.cs | 8 ++++++++ 4 files changed, 30 insertions(+), 1 deletion(-) diff --git a/OpenSim/Tools/pCampBot/Behaviours/AbstractBehaviour.cs b/OpenSim/Tools/pCampBot/Behaviours/AbstractBehaviour.cs index 66d5542844..9bc85124ac 100644 --- a/OpenSim/Tools/pCampBot/Behaviours/AbstractBehaviour.cs +++ b/OpenSim/Tools/pCampBot/Behaviours/AbstractBehaviour.cs @@ -50,5 +50,7 @@ namespace pCampBot { Bot = bot; } + + public virtual void Close() {} } } diff --git a/OpenSim/Tools/pCampBot/Behaviours/PhysicsBehaviour.cs b/OpenSim/Tools/pCampBot/Behaviours/PhysicsBehaviour.cs index 47b4d46108..65a7c90d49 100644 --- a/OpenSim/Tools/pCampBot/Behaviours/PhysicsBehaviour.cs +++ b/OpenSim/Tools/pCampBot/Behaviours/PhysicsBehaviour.cs @@ -78,6 +78,11 @@ namespace pCampBot Bot.Client.Self.Chat(randomf, 0, ChatType.Normal); } + public override void Close() + { + Bot.Client.Self.Jump(false); + } + private string[] readexcuses() { string allexcuses = ""; diff --git a/OpenSim/Tools/pCampBot/Bot.cs b/OpenSim/Tools/pCampBot/Bot.cs index 0bd8151ecc..f871b7764e 100644 --- a/OpenSim/Tools/pCampBot/Bot.cs +++ b/OpenSim/Tools/pCampBot/Bot.cs @@ -209,7 +209,17 @@ namespace pCampBot public bool RemoveBehaviour(string abbreviatedName) { lock (Behaviours) - return Behaviours.Remove(abbreviatedName); + { + IBehaviour behaviour; + + if (!Behaviours.TryGetValue(abbreviatedName, out behaviour)) + return false; + + behaviour.Close(); + Behaviours.Remove(abbreviatedName); + + return true; + } } private void CreateLibOmvClient() @@ -282,6 +292,10 @@ namespace pCampBot // XXX: This is a really shitty way of yielding so that behaviours can be added/removed Thread.Sleep(100); } + + lock (Behaviours) + foreach (IBehaviour b in Behaviours.Values) + b.Close(); } /// diff --git a/OpenSim/Tools/pCampBot/Interfaces/IBehaviour.cs b/OpenSim/Tools/pCampBot/Interfaces/IBehaviour.cs index f8a661badd..0ed48256c1 100644 --- a/OpenSim/Tools/pCampBot/Interfaces/IBehaviour.cs +++ b/OpenSim/Tools/pCampBot/Interfaces/IBehaviour.cs @@ -50,6 +50,14 @@ namespace pCampBot.Interfaces /// void Initialize(Bot bot); + /// + /// Close down this behaviour. + /// + /// + /// This is triggered if a behaviour is removed via explicit command and when a bot is disconnected + /// + void Close(); + /// /// Action to take when this behaviour is invoked. ///