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.0.7.6-extended
parent
2a7b4c9db9
commit
cfef2b19bb
|
@ -50,5 +50,7 @@ namespace pCampBot
|
||||||
{
|
{
|
||||||
Bot = bot;
|
Bot = bot;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public virtual void Close() {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,6 +78,11 @@ namespace pCampBot
|
||||||
Bot.Client.Self.Chat(randomf, 0, ChatType.Normal);
|
Bot.Client.Self.Chat(randomf, 0, ChatType.Normal);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void Close()
|
||||||
|
{
|
||||||
|
Bot.Client.Self.Jump(false);
|
||||||
|
}
|
||||||
|
|
||||||
private string[] readexcuses()
|
private string[] readexcuses()
|
||||||
{
|
{
|
||||||
string allexcuses = "";
|
string allexcuses = "";
|
||||||
|
|
|
@ -209,7 +209,17 @@ namespace pCampBot
|
||||||
public bool RemoveBehaviour(string abbreviatedName)
|
public bool RemoveBehaviour(string abbreviatedName)
|
||||||
{
|
{
|
||||||
lock (Behaviours)
|
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()
|
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
|
// XXX: This is a really shitty way of yielding so that behaviours can be added/removed
|
||||||
Thread.Sleep(100);
|
Thread.Sleep(100);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lock (Behaviours)
|
||||||
|
foreach (IBehaviour b in Behaviours.Values)
|
||||||
|
b.Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
@ -50,6 +50,14 @@ namespace pCampBot.Interfaces
|
||||||
/// <param name="bot"></param>
|
/// <param name="bot"></param>
|
||||||
void Initialize(Bot bot);
|
void Initialize(Bot bot);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Close down this behaviour.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// This is triggered if a behaviour is removed via explicit command and when a bot is disconnected
|
||||||
|
/// </remarks>
|
||||||
|
void Close();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Action to take when this behaviour is invoked.
|
/// Action to take when this behaviour is invoked.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
Loading…
Reference in New Issue