示例#1
0
        public static async Task <bool> ClearReadEffects(string userId, string lastReadEffectId)
        {
            if (effectsQueues.TryGetValue(userId, out EffectsQueue effectQueue))
            {
                if (!effectQueue.ClearTo(lastReadEffectId))
                {
                    return(false);
                }
                await effectQueue.PostEffects();

                return(true);
            }

            //This method could be called while the user is not being tracked (not active) so pull one if it's there
            IEnumerable <GameInfoEffectBase> effects = await Program.DataStore.GetGameInfoEffects(userId);

            effectQueue = new EffectsQueue(userId, effects);

            //If there was no effets stored on the server, this will always return false, as expected
            if (!effectQueue.ClearTo(lastReadEffectId))
            {
                return(false);
            }

            await effectQueue.PostEffects();

            return(true);
        }
示例#2
0
        static async Task <EffectsQueue> GetEffectQueue(string userId)
        {
            if (effectsQueues.TryGetValue(userId, out EffectsQueue queue))
            {
                return(queue);
            }

            IEnumerable <GameInfoEffectBase> effects = await Program.DataStore.GetGameInfoEffects(userId);

            queue = new EffectsQueue(userId, effects);

            effectsQueues.TryAdd(userId, queue);
            return(queue);
        }
示例#3
0
        /// <summary>
        /// Applies the effect to the user's <see cref="GameInfo"/>, and <see cref="EffectsQueue"/>
        /// </summary>
        /// <param name="user"></param>
        /// <param name="effect"></param>
        /// <param name="shouldPost">If true, then evenything will be posted to the datastore</param>
        /// <returns></returns>
        static async Task AddNewEffect(string userId, GameInfoEffectBase effect, bool shouldPost = false)
        {
            GameInfo gameInfo = await GetGameInfo(userId);

            gameInfo += effect;

            if (shouldPost)
            {
                await Program.DataStore.PostGameInfo(userId, gameInfo);
            }

            EffectsQueue effectsQueue = await GetEffectQueue(userId);

            effectsQueue.AddEffect(effect);

            if (shouldPost)
            {
                await effectsQueue.PostEffects();
            }
        }