コード例 #1
0
        /// <summary>
        /// Update the dictionary of contribution held by the server for the character. Can hold unlimited numbers
        /// of contributions, these will be culled in a later stage of the process.
        /// </summary>
        /// <param name="targetCharacterId">The character receiving the contribution</param>
        /// <param name="contributionId">Reference contribution Id</param>
        /// <returns></returns>
        public List <PlayerContribution> UpdateContribution(uint targetCharacterId, byte contributionId)
        {
            var contributionDefinition = ContributionFactors.Single(x => x.ContributionId == contributionId);

            RewardLogger.Trace(
                $"Assigning contibution Id {contributionId} ({contributionDefinition.ContributionDescription}) value of {contributionDefinition.ContributionValue} to {targetCharacterId}");

            //filteredResults.AddOrUpdate(unfilteredResult.Key, new List<int> { number }, (k, v) => v.Add(number));
            var result = ContributionDictionary.AddOrUpdate(targetCharacterId,
                                                            new List <PlayerContribution>
            {
                new PlayerContribution
                {
                    ContributionId = contributionId,
                    Timestamp      = FrameWork.TCPManager.GetTimeStamp()
                }
            }, (k, v) =>
            {
                v.Add(new PlayerContribution
                {
                    ContributionId = contributionId,
                    Timestamp      = FrameWork.TCPManager.GetTimeStamp()
                });
                return(v);
            });

            return(result);
        }
コード例 #2
0
        /// <summary>
        /// Get the list of playercontributions
        /// </summary>
        /// <param name="targetCharacterId"></param>
        /// <returns></returns>
        public List <PlayerContribution> GetContribution(uint targetCharacterId)
        {
            List <PlayerContribution> contributionList;

            ContributionDictionary.TryGetValue(targetCharacterId, out contributionList);

            return(contributionList);
        }
コード例 #3
0
        public ConcurrentDictionary <short, ContributionStage> GetContributionStageDictionary(uint targetCharacterId)
        {
            List <PlayerContribution> contributionList;

            ContributionDictionary.TryGetValue(targetCharacterId, out contributionList);

            return(GetContributionStageDictionary(contributionList, ContributionFactors));
        }
コード例 #4
0
        /// <summary>
        /// Get the total contribution value for the character.
        /// </summary>
        /// <param name="targetCharacterId"></param>
        /// <returns></returns>
        public short GetContributionValue(uint targetCharacterId)
        {
            List <PlayerContribution> contributionList;

            ContributionDictionary.TryGetValue(targetCharacterId, out contributionList);

            short contributionValue = 0;

            if (contributionList == null)
            {
                return(contributionValue);
            }

            if (ContributionFactors == null)
            {
                return(contributionValue);
            }

            var stagedContribution = GetContributionStageDictionary(contributionList, ContributionFactors);

            foreach (var contributionStage in stagedContribution)
            {
                contributionValue += contributionStage.Value.ContributionStageSum;
            }

            // double check something is not right.
            if (contributionValue > short.MaxValue)
            {
                RewardLogger.Error(
                    $"ContributionManagerInstance exceeds max (over short.maxvalue) for Character {targetCharacterId}. {contributionList.Count} contribution records.");
                contributionValue = short.MaxValue;
            }

            if (contributionValue > MAXIMUM_CONTRIBUTION)
            {
                RewardLogger.Error(
                    $"ContributionManagerInstance exceeds max ({MAXIMUM_CONTRIBUTION}) for Character {targetCharacterId}. {contributionList.Count} contribution records.");
                contributionValue = MAXIMUM_CONTRIBUTION;
            }

            RewardLogger.Trace($"Returning contributionValue of {contributionValue} for {targetCharacterId} ");

            return(contributionValue);
        }
コード例 #5
0
 /// <summary>
 /// Clear the contribution dictionary
 /// </summary>
 public void Clear()
 {
     ContributionDictionary.Clear();
 }
コード例 #6
0
        /// <summary>
        /// Remove Character from ContributionManagerInstance Dict
        /// </summary>
        /// <param name="characterId"></param>
        public bool RemoveCharacter(uint characterId)
        {
            List <PlayerContribution> contribution;

            return(ContributionDictionary.TryRemove(characterId, out contribution));
        }