public void Start(BotTaskType _taskType)
        {
            if (p_tasks.ContainsKey(_taskType))
            {
                return;
            }
            CancellableTaskProc proc;

            switch (_taskType)
            {
            case BotTaskType.NotificationAboutEvent:
                proc = p_eventNotificator.StartProcLoop;
                break;

            //case BotTaskType.NotificationAboutPartyAction:
            //    proc = p_partyActionNotificator.StartProcLoop;
            //    break;
            default:
                throw new ArgumentOutOfRangeException(nameof(_taskType), _taskType, null);
            }
            var task = new CancellableTask(proc, TaskCreationOptions.LongRunning, $"BotTask_{_taskType}");

            p_tasks[_taskType] = task;
            task.Start();
        }
Beispiel #2
0
 /// <summary>
 /// Reserves the pod for the given bot.
 /// </summary>
 /// <param name="pod">The pod to reserve.</param>
 /// <param name="bot">The bot that reserves the pod.</param>
 /// <param name="purpose">The purpose for claiming the pod.</param>
 public void ClaimPod(Pod pod, Bot bot, BotTaskType purpose)
 {
     // Sanity check
     if (_usedPods.ContainsKey(pod) && _usedPods[pod] != bot)
     {
         throw new InvalidOperationException("Pod is already claimed by another bot!");
     }
     // Claim it
     _usedPods[pod] = bot;
     _unusedPods.Remove(pod);
     // Notify the instance about the operation
     _instance.NotifyPodClaimed(pod, bot, purpose);
 }
        public void Stop(BotTaskType _taskType)
        {
            if (!p_tasks.ContainsKey(_taskType))
            {
                return;
            }
            var task = p_tasks[_taskType];

            p_tasks.Remove(_taskType);
            if (task.TokenSource != null && task.TokenSource.IsCancellationRequested)
            {
                return;
            }
            StopTask(task);
        }
Beispiel #4
0
 /// <summary>
 /// Resets all statistics.
 /// </summary>
 public void ResetStatistics()
 {
     StatNumberOfPickups          = 0;
     StatNumberOfSetdowns         = 0;
     StatNumCollisions            = 0;
     StatDistanceTraveled         = 0;
     StatDistanceEstimated        = 0;
     StatDistanceRequestedOptimal = 0;
     StatAssignedTasks            = 0;
     StatTotalTimeMoving          = 0;
     StatTotalTimeQueueing        = 0;
     StatLastTask         = BotTaskType.None;
     StatLastState        = BotStateType.Rest;
     StatLastWaypoint     = null;
     StatTotalTaskTimes   = new Dictionary <BotTaskType, double>(Enum.GetValues(typeof(BotTaskType)).Cast <BotTaskType>().ToDictionary(k => k, v => 0.0));
     StatTotalStateTimes  = new Dictionary <BotStateType, double>(Enum.GetValues(typeof(BotStateType)).Cast <BotStateType>().ToDictionary(k => k, v => 0.0));
     StatTotalTaskCounts  = new Dictionary <BotTaskType, int>(Enum.GetValues(typeof(BotTaskType)).Cast <BotTaskType>().ToDictionary(k => k, v => 0));
     StatTotalStateCounts = new Dictionary <BotStateType, int>(Enum.GetValues(typeof(BotStateType)).Cast <BotStateType>().ToDictionary(k => k, v => 0));
 }
Beispiel #5
0
 /// <summary>
 /// Notifies the instance that a pod was picked up.
 /// </summary>
 /// <param name="pod">The pod that was pickep up.</param>
 /// <param name="bot">The bot that picked up the pod.</param>
 /// <param name="purpose">The purpose the pod was claimed for.</param>
 internal void NotifyPodClaimed(Pod pod, Bot bot, BotTaskType purpose)
 {
     // Raise the event
     PodClaimed?.Invoke(pod, bot, purpose);
 }