コード例 #1
0
ファイル: AwardsComponent.cs プロジェクト: bradleat/trafps
        /// <summary>
        /// Helper function. Acquires the AwardProgress for the given award and gamer.
        /// </summary>
        /// <param name="award">The award to search for.</param>
        /// <param name="gamertag">The gamer unlocking the award.</param>
        /// <param name="makeIfNotFound">
        /// True if a new AwardProgress should be created if it does not exist.
        /// </param>
        /// <returns>The appropriate AwardProgress object, or null if not found or created.</returns>
        private AwardProgress GetAwardProgress(Award award, string gamertag, bool makeIfNotFound)
        {
            // Try to find the AwardProgress.
            AwardProgress findProgress = currentAwards.Find(a => a.Award == award &&
                                                            a.Gamertag == gamertag);

            // If we didn't find it, make a new one if requested.
            if (findProgress == null && makeIfNotFound)
            {
                findProgress = new AwardProgress
                {
                    Award    = award,
                    Gamertag = gamertag
                };
                currentAwards.Add(findProgress);
            }

            return(findProgress);
        }
コード例 #2
0
 /// <summary>
 /// Creates a new AwardUnlockedEventArgs with the given award.
 /// </summary>
 /// <param name="award">The award that was unlocked.</param>
 /// <param name="gamertag">The gamer who unlocked it.</param>
 public AwardUnlockedEventArgs(Award award, string gamertag)
 {
     Award    = award;
     Gamertag = gamertag;
 }
コード例 #3
0
ファイル: AwardsComponent.cs プロジェクト: bradleat/trafps
        /// <summary>
        /// Helper function. Acquires the AwardProgress for the given award and gamer.
        /// </summary>
        /// <param name="award">The award to search for.</param>
        /// <param name="gamertag">The gamer unlocking the award.</param>
        /// <param name="makeIfNotFound">
        /// True if a new AwardProgress should be created if it does not exist.
        /// </param>
        /// <returns>The appropriate AwardProgress object, or null if not found or created.</returns>
        private AwardProgress GetAwardProgress(Award award, string gamertag, bool makeIfNotFound)
        {
            // Try to find the AwardProgress.
            AwardProgress findProgress = currentAwards.Find(a => a.Award == award &&
                                                                 a.Gamertag == gamertag);

            // If we didn't find it, make a new one if requested.
            if (findProgress == null && makeIfNotFound)
            {
                findProgress = new AwardProgress
                {
                    Award = award,
                    Gamertag = gamertag
                };
                currentAwards.Add(findProgress);
            }

            return findProgress;
        }
コード例 #4
0
ファイル: AwardsComponent.cs プロジェクト: bradleat/trafps
        /// <summary>
        /// Unlocks an award.
        /// </summary>
        /// <param name="award">The award to unlock.</param>
        /// <param name="gamertag">The gamer who unlocked the award.</param>
        public void UnlockAward(Award award, string gamertag)
        {
            // Make sure the award is in our list.
            if (Awards.Contains(award))
            {
                // Get the progress, make a new one if not found.
                AwardProgress findAward = GetAwardProgress(award, gamertag, true);

                // Only unlock if it hasn't been yet.
                if (!findAward.IsUnlocked)
                {
                    // Set the award's progress.
                    findAward.Progress = award.ProgressNeeded;

                    // Add it to the notification queue.
                    notifyList.Enqueue(findAward);

                    // Invoke the event.
                    if (AwardUnlocked != null)
                        AwardUnlocked(this, new AwardUnlockedEventArgs(award, gamertag));
                }
            }
        }
コード例 #5
0
ファイル: AwardsComponent.cs プロジェクト: bradleat/trafps
        /// <summary>
        /// Determines if a given award has been unlocked.
        /// </summary>
        /// <param name="award"></param>
        /// <param name="gamertag"></param>
        /// <returns></returns>
        public bool IsAwardUnlocked(Award award, string gamertag)
        {
            // Find the AwardProgress, don't create it if it isn't there.
            AwardProgress findAward = GetAwardProgress(award, gamertag, false);

            // Return whether we found it and if it's unlocked.
            return findAward != null && findAward.IsUnlocked;
        }
コード例 #6
0
ファイル: AwardsComponent.cs プロジェクト: bradleat/trafps
        /// <summary>
        /// Adds progress points to an award for a gamer, unlocking it if needed.
        /// </summary>
        /// <param name="award">The award to add progress.</param>
        /// <param name="gamertag">The gamer progressing the award.</param>
        /// <param name="progress">The number of progress points obtained.</param>
        public void AddAwardProgress(Award award, string gamertag, int progress)
        {
            // Make sure the award is in our list.
            if (Awards.Contains(award))
            {
                // Get the progress, make a new one if not found.
                AwardProgress findAward = GetAwardProgress(award, gamertag, true);

                // Only add points if it hasn't been unlocked yet.
                if (!findAward.IsUnlocked)
                {
                    // Get the last progress increment reached.
                    int lastIncrement = findAward.Progress / award.ProgressIncrement;

                    // Add to the award's progress and get the new progress increment.
                    findAward.Progress += progress;
                    int nextIncrement = findAward.Progress / award.ProgressIncrement;

                    // First, check again if it is unlocked.
                    if (findAward.IsUnlocked)
                    {
                        // Add it to the notification queue.
                        notifyList.Enqueue(findAward);

                        // Invoke the event.
                        if (AwardUnlocked != null)
                            AwardUnlocked(this, new AwardUnlockedEventArgs(award, gamertag));
                    }
                    // Otherwise, check for a partial progress notification.
                    else if (lastIncrement < nextIncrement)
                    {
                        // Round down the progress points and add it to the notification queue.
                        int roundedProgress = nextIncrement * award.ProgressIncrement;
                        notifyList.Enqueue(new AwardProgress
                        {
                            Award = award,
                            Gamertag = gamertag,
                            Progress = roundedProgress
                        });
                    }
                }
            }
        }
コード例 #7
0
 /// <summary>
 /// Creates a new AwardUnlockedEventArgs with the given award.
 /// </summary>
 /// <param name="award">The award that was unlocked.</param>
 /// <param name="gamertag">The gamer who unlocked it.</param>
 public AwardUnlockedEventArgs(Award award, string gamertag)
 {
     Award = award;
     Gamertag = gamertag;
 }