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.
This commit is contained in:
Justin Clark-Casey (justincc)
2013-09-03 19:33:17 +01:00
parent 1a2627031d
commit 3dbe7313d1
4 changed files with 30 additions and 1 deletions

View File

@@ -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();
}
/// <summary>