/// <summary> /// Subscribes a IBattleArtificialIntelligence member on one of the designated lists /// to be processed. /// </summary> /// <param name="e"></param> public static void Subscribe(IBattleArtificialIntelligence e) { //If the object is subscribed cancel if (e.BattleState.IsSubscribed == true) return; int index = FindBestThreadStateToSubscribe(); Subscribe(e, index); }
/// <summary> /// Unsubscribes a IBattleArtificialIntelligence member on one of the designated lists /// to be processed. /// </summary> /// <param name="e"></param> public static void Unsubscribe(IBattleArtificialIntelligence e) { //If the object is not subscribed cancel if (e.BattleState.IsSubscribed == false) return; int index = e.BattleState.ThreadIndex; Unsubscribe(e, index); }
/// <summary> /// Removes the requested /// IBattleArtificialIntelligence /// </summary> /// <param name="e"></param> public void Remove(IBattleArtificialIntelligence e) { lock (e) { this.processinglist.Remove(e); } }
/// <summary> /// Adds the requested IBattleArtificialIntelligence. /// </summary> /// <param name="e"></param> public void Add(IBattleArtificialIntelligence e) { lock (e) { this.processinglist.Add(e); } }
/// <summary> /// Processes all list members /// </summary> private void Process() { while (!Environment.HasShutdownStarted) { try { //Process all mobs for (int i = 0; i < this.processinglist.Count; i++) { try { IBattleArtificialIntelligence ai = this.processinglist[i]; ai.Process(); } catch (ThreadAbortException ex) { throw ex; } catch (Exception e) { Console.WriteLine(e); } } //Sleep one sec Thread.Sleep(1); } catch (ThreadAbortException) { break; } } }
private static void Subscribe(IBattleArtificialIntelligence e, int index) { if (index < ThreadStateList.Count) { ThreadState current = ThreadStateList[index]; current.Add(e); e.BattleState.Subscribe(index); } }
private static void Unsubscribe(IBattleArtificialIntelligence e, int index) { if (index < ThreadStateList.Count) { //Actual ubsubscribement ThreadState current = ThreadStateList[index]; current.Remove(e); e.BattleState.Unsubscribe(index); } }
/// <summary> /// Unsubscribes a IBattleArtificialIntelligence member on one of the designated lists /// to be processed. /// </summary> /// <param name="e"></param> public static void Unsubscribe(IBattleArtificialIntelligence e) { //If the object is not subscribed cancel if (e.BattleState.IsSubscribed == false) { return; } int index = e.BattleState.ThreadIndex; Unsubscribe(e, index); }
/// <summary> /// Subscribes a IBattleArtificialIntelligence member on one of the designated lists /// to be processed. /// </summary> /// <param name="e"></param> public static void Subscribe(IBattleArtificialIntelligence e) { //If the object is subscribed cancel if (e.BattleState.IsSubscribed == true) { return; } int index = FindBestThreadStateToSubscribe(); Subscribe(e, index); }
/// <summary> /// Checks if a threadstate contains the requested /// IBattleArtificialIntelligence /// </summary> /// <param name="e"></param> public void Contains(IBattleArtificialIntelligence e) { this.processinglist.Contains(e); }