示例#1
0
        /// <summary>
        /// Merges the current player type with the specified player type
        /// </summary>
        public void MergeWith(HudPlayerType playerType)
        {
            if (playerType == null)
            {
                return;
            }

            MinSample           = playerType.MinSample;
            EnablePlayerProfile = playerType.EnablePlayerProfile;
            DisplayPlayerIcon   = playerType.DisplayPlayerIcon;
            Name       = playerType.Name;
            Image      = playerType.Image;
            ImageAlias = playerType.ImageAlias;

            var statsToMerge = (from currentStat in Stats
                                join stat in playerType.Stats on currentStat.Stat equals stat.Stat into gj
                                from grouped in gj.DefaultIfEmpty()
                                where grouped != null
                                select new { CurrentStat = currentStat, Stat = grouped }).ToArray();

            statsToMerge.ForEach(s =>
            {
                s.CurrentStat.Low  = s.Stat.Low;
                s.CurrentStat.High = s.Stat.High;
            });
        }
        private Tuple <bool, decimal, decimal> GetMatchRatio(IEnumerable <StatInfo> stats, HudPlayerType hudPlayerType)
        {
            var matchRatios = (from stat in hudPlayerType.Stats
                               let low = stat.Low ?? -1
                                         let high = stat.High ?? 100
                                                    let average = (high + low) / 2
                                                                  let isStatDefined = stat.Low.HasValue || stat.High.HasValue
                                                                                      join hudElementStat in stats on stat.Stat equals hudElementStat.Stat into gj
                                                                                      from grouped in gj.DefaultIfEmpty()
                                                                                      let inRange = grouped != null ? (grouped.CurrentValue >= low && grouped.CurrentValue <= high) : !isStatDefined
                                                                                                    let isGroupAndStatDefined = grouped != null && isStatDefined
                                                                                                                                let matchRatio = isGroupAndStatDefined ? Math.Abs(grouped.CurrentValue - average) : 0
                                                                                                                                                 let extraMatchRatio = (isGroupAndStatDefined && (grouped.Stat == Stat.VPIP || grouped.Stat == Stat.PFR)) ? matchRatio : 0
                                                                                                                                                                       select
                                                                                                                                                                       new
            {
                Ratio = matchRatio,
                InRange = inRange,
                IsStatDefined = isStatDefined,
                ExtraMatchRatio = extraMatchRatio
            }).ToArray();

            return
                (new Tuple <bool, decimal, decimal>(
                     matchRatios.All(x => x.InRange) && matchRatios.Any(x => x.IsStatDefined),
                     matchRatios.Sum(x => x.Ratio), matchRatios.Sum(x => x.ExtraMatchRatio)));
        }