示例#1
0
        public static int?TryProgress(this TrackableDictionary <int, UserAchievement> dict,
                                      AchievementKey key, int increment)
        {
            UserAchievement ach;

            if (dict.TryGetValue((int)key, out ach))
            {
                if (ach.AchieveTime.HasValue)
                {
                    return(null);
                }

                ach = new UserAchievement {
                    Value = ach.Value + increment
                };
                dict[(int)key] = ach;
            }
            else
            {
                ach = new UserAchievement {
                    Value = increment
                };
                dict.Add((int)key, ach);
            }
            return(ach.Value);
        }
示例#2
0
        public static bool IsAchieved(this TrackableDictionary <int, UserAchievement> dict,
                                      AchievementKey key)
        {
            UserAchievement ach;

            return(dict.TryGetValue((int)key, out ach) && ach.AchieveTime.HasValue);
        }
示例#3
0
        public static bool TryAchieved(this TrackableDictionary <int, UserAchievement> dict,
                                       AchievementKey key)
        {
            UserAchievement ach;

            if (dict.TryGetValue((int)key, out ach))
            {
                if (ach.AchieveTime.HasValue)
                {
                    return(false);
                }

                ach = new UserAchievement {
                    AchieveTime = DateTime.UtcNow, Value = ach.Value
                };
                dict[(int)key] = ach;
            }
            else
            {
                ach = new UserAchievement {
                    AchieveTime = DateTime.UtcNow
                };
                dict.Add((int)key, ach);
            }
            return(true);
        }
        public void TestTryGetValue(bool track)
        {
            var acc = new Accumulator("test");
            var dic = new TrackableDictionary <string, int>(acc, track)
            {
                { "one", 1 }, { "two", 2 }
            };

            Assert.IsTrue(dic.TryGetValue("one", out var val));
            Assert.AreEqual(1, val);
            Assert.IsTrue(dic.ContainsKey("one"));

            Assert.IsFalse(dic.TryGetValue("four", out val));

            if (track)
            {
                Assert.AreEqual(2, acc.Records.Count);
            }
            else
            {
                Assert.AreEqual(0, acc.Records.Count);
            }
        }