/// <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); }
/// <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); }
public ConcurrentDictionary <short, ContributionStage> GetContributionStageDictionary(uint targetCharacterId) { List <PlayerContribution> contributionList; ContributionDictionary.TryGetValue(targetCharacterId, out contributionList); return(GetContributionStageDictionary(contributionList, ContributionFactors)); }
/// <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); }
/// <summary> /// Clear the contribution dictionary /// </summary> public void Clear() { ContributionDictionary.Clear(); }
/// <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)); }