Example #1
0
    /// <summary>
    /// Remove every single status reported by the given tracker across all rooms
    /// </summary>
    /// <param name="trackerId"></param>
    /// <returns>The amount of statuses removed per content</returns>
    public async Task <Dictionary <long, int> > RemoveStatusesByTrackerAsync(int trackerId)
    {
        UserStatusCollection?  statusCollection;
        Dictionary <long, int> removed = new Dictionary <long, int>();

        foreach (var key in statuses.Keys.ToList())
        {
            if (statuses.TryGetValue(key, out statusCollection))
            {
                await statusCollection !.CollectionLock.WaitAsync();

                try
                {
                    var thisRemoved = statusCollection !.Statuses.RemoveAll(x => x.trackerId == trackerId);

                    if (thisRemoved > 0)
                    {
                        removed.Add(key, thisRemoved);
                    }
                }
                finally
                {
                    statusCollection !.CollectionLock.Release();
                }
            }
        }

        return(removed);
    }
Example #2
0
 /// <summary>
 /// Removes a status from the player, if he is already affected by that status
 /// </summary>
 /// <param name="status">The status to remove to the player</param>
 /// <exception cref="PlayerStatusNotPresentException">If the player was not actually affected by that status</exception>
 public void RemoveStatus(PlayerStatus status)
 {
     if (Statuses.Any(x => x.Status == status))
     {
         Statuses.RemoveAll(x => x.Status == status);
     }
     else
     {
         throw new PlayerStatusNotPresentException();
     }
 }