From cfef2b19bbce1bc6d9d5891b685ce5d399602fff Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Tue, 3 Sep 2013 19:33:17 +0100 Subject: 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. --- OpenSim/Tools/pCampBot/Behaviours/AbstractBehaviour.cs | 2 ++ OpenSim/Tools/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(-) (limited to 'OpenSim/Tools') diff --git a/OpenSim/Tools/pCampBot/Behaviours/AbstractBehaviour.cs b/OpenSim/Tools/pCampBot/Behaviours/AbstractBehaviour.cs index 66d5542..9bc8512 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 47b4d46..65a7c90 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 0bd8151..f871b77 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 f8a661b..0ed4825 100644 --- a/OpenSim/Tools/pCampBot/Interfaces/IBehaviour.cs +++ b/OpenSim/Tools/pCampBot/Interfaces/IBehaviour.cs @@ -51,6 +51,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. /// /// -- cgit v1.1