Beispiel #1
0
        public async Task EntityFramework_CharacterStatistics_EntityMatchesInput()
        {
            var context = new RpgContext(new GeneralOptions
            {
                UseInMemoryDatabase = true,
                DatabaseName        = "CharacterStatistics_EntityMatchesInput"
            });

            var provider     = new EfCharacterProvider(context);
            var statProvider = new EfStatisticProvider(context);

            ulong  userIdentifier = 305847674974896128;
            string name           = "Melon Head";
            int    id             = 1;

            var strength = await statProvider.CreateAttributeAsync("Strength");

            var value = new StatisticValue(5);
            await provider.CreateCharacterAsync(id, userIdentifier, true, name);

            var result = await provider.GetActiveCharacterAsync(userIdentifier);

            result.SetStatistic(strength, value);
            await provider.UpdateCharacterAsync(result);

            result = await provider.GetActiveCharacterAsync(userIdentifier);

            Assert.True(result.Statistics.Count > 0);
        }
Beispiel #2
0
 public ChartLine(StatisticType statisticType, StatisticValue valueType)
 {
     MinHeight = 0;
     Title     = $"{valueType.ToString()} {statisticType.ToString().ToLower()}";
     Values    = new ChartValues <double>();
     Statistic = statisticType;
     Value     = valueType;
 }
Beispiel #3
0
    public static int TryGetInStatistics(this GetPlayerStatisticsResult Result, string Identifier, int PreviousValue)
    {
        StatisticValue statistic = Result.Statistics.Find(T => T.StatisticName == Identifier);

        if (statistic != null)
        {
            return(statistic.Value);
        }
        return(PreviousValue);
    }
    /// <summary>
    /// クラス内に保存されている統計情報の取得
    /// </summary>
    /// <param name="StatisticName">統計情報名</param>
    /// <returns>統計情報名が見つからない場合は0を返す</returns>
    public int GetStatisticValue(string StatisticName)
    {
        StatisticValue staValue = valueList.Find(n => n.StatisticName == StatisticName);

        if (staValue == null)
        {
            return(0);
        }
        return(staValue.Value);
    }
        protected override void HandleGetStat(XboxLiveUser user, string statName)
        {
            this.isLocalUserAdded = true;
            StatisticValue statValue = XboxLive.Instance.StatsManager.GetStatistic(user, statName);

            if (statValue != null)
            {
                this.Value = statValue.AsNumber;
            }
        }
Beispiel #6
0
        /// <summary>
        /// Sets the specified Statistic to the given StatisticValue if it exists.
        /// Otherwise, add a new StatisticMapping entry to the list.
        /// </summary>
        /// <param name="stat">The statistic to set.</param>
        /// <param name="newValue">The StatisticValue to associate with the Statistic.</param>
        public void SetStatistic(Statistic stat, StatisticValue newValue)
        {
            var statMap = Statistics.FirstOrDefault(x => x.Statistic.Equals(stat));

            if (statMap == null)
            {
                Statistics.Add(new StatisticMapping(stat, newValue));
                return;
            }

            statMap.StatisticValue = newValue;
        }
        object GetStatValue(StatisticValue value)
        {
            switch (value.DataType)
            {
            case StatisticDataType.Number:
                return(value.AsInteger);

            case StatisticDataType.String:
                return(value.AsString);

            default:
                return(value.AsNumber);
            }
        }
        private void LoadbaseData(StatisticValue stat)
        {
            if (stat.Equals(null))
            {
                return;
            }

            maxValue          = stat.MaxValue;
            initialLevel      = stat.InitialLevel;
            maxLevel          = stat.MaxLevel;
            maximizeOnUpgrade = stat.MaximizeOnUpgrade;
            valueUpgrade      = stat.ValueUpgrade;

            level = initialLevel;
            value = stat.MaxValue;
        }
Beispiel #9
0
        public void Stats()
        {
            var stat = new StatisticValue<AgentStatistic, int>(AgentStatistic.Memory, 100);
            Assert.IsFalse(stat.IsBuffed);
            Assert.IsFalse(stat.IsDebuffed);

            stat.Alter(110);
            Assert.IsTrue(stat > 100);
            Assert.IsTrue(stat.IsBuffed);
            Assert.IsFalse(stat.IsDebuffed);

            stat.Alter(90);
            Assert.IsTrue(stat < 100);
            Assert.IsFalse(stat.IsBuffed);
            Assert.IsTrue(stat.IsDebuffed);
        }
 protected override void HandleGetStat(XboxLiveUser user, string statName)
 {
     this.isLocalUserAdded = true;
     try
     {
         StatisticValue statValue = XboxLive.Instance.StatsManager.GetStatistic(user, statName);
         if (statValue != null)
         {
             this.Value = statValue.AsNumber;
         }
     }
     catch (Exception)
     {
         // GetStatistic will fail with an exception if if its the
         // first time reading the stat for example.
     }
 }
        private StatisticValue[] ParseStats(SkyrimSavegame savegame)
        {
            List <StatisticValue> stats = new List <StatisticValue>();
            var orderedMiscStats        = savegame.GetMiscStats().OrderBy(p => p.category).ThenBy(n => n.name);

            foreach (var ms in orderedMiscStats)
            {
                StatisticValue sv = new StatisticValue();

                StatisticCategoryType catType = (StatisticCategoryType)ms.category;

                sv.CategoryId = (int)catType;
                sv.Name       = ms.name;
                sv.Value      = ms.value;

                stats.Add(sv);
            }
            return(stats.ToArray());
        }
Beispiel #12
0
        private void AllOther(HttpContext context)
        {
            Granularity granularity = Granularity.Day;

            int estPoints = GetRangeDays();
            int maxPoints = imageWidth / POINT_SPACE;
            int step      = 1;
            int maxSteps  = imageWidth / LABLE_SPACE;

            if (estPoints > maxPoints)
            {
                estPoints   = GetRangeMonths();
                granularity = Granularity.Month;
            }

            if (estPoints > maxPoints)
            {
                estPoints   = GetRangeYears();
                granularity = Granularity.Year;
            }

            while (estPoints > maxSteps)
            {
                estPoints = estPoints / 2;
                step++;
            }

            StatisticResult result = null;

            switch (statisticsType)
            {
            case StatisticsType.CountCommunityMembers:
                result = Statistics.GetObjectCountCommunityMembers(dateFrom, dateTo, groupBy, granularity, parentObjectID, include);
                break;

            case StatisticsType.CountProfileFriends:
                result = Statistics.GetObjectCountProfileFriends(dateFrom, dateTo, groupBy, granularity, parentObjectID, include);
                break;

            case StatisticsType.TotalObjectsCount:
                result = Statistics.GetObjectCountCommunityTotal(parentObjectID, groupBy).Results[0];
                break;

            case StatisticsType.CreationObjects:
                if (!ignoreCommunity && parentObjectID.HasValue)
                {
                    if (parentObjectType == Helper.GetObjectTypeNumericID("Community"))
                    {
                        result = Statistics.GetObjectCreationCommunityObjects(dateFrom, dateTo, groupBy, granularity, parentObjectID, include);
                    }
                    else if (parentObjectType == Helper.GetObjectTypeNumericID("ProfileCommunity"))
                    {
                        result = Statistics.GetObjectCreationProfileObjects(dateFrom, dateTo, groupBy, granularity, parentObjectID, include);
                    }
                    else
                    {
                        result = Statistics.GetObjectCreationObjects(dateFrom, dateTo, groupBy, granularity, include);
                    }
                }
                else
                {
                    result = Statistics.GetObjectCreationObjects(dateFrom, dateTo, groupBy, granularity, include);
                }
                break;
            }

            if (result == null || result.Series.Count < 1)
            {
                context.Response.ContentType = "text/plain";
                context.Response.StatusCode  = 501;
                context.Response.AddHeader("IDS", string.Concat(chartId, "|", errorId));
                context.Response.Write(language.GetString("MessageStatisticNoData"));
                return;
            }

            List <string> colors   = GetColors(result.Series.Count);
            DateTime      minDate  = DateTime.MaxValue;
            DateTime      maxDate  = DateTime.MinValue;
            DateTime      lastDate = DateTime.MinValue;

            Graph graph = new Graph();

            graph.Bgcolor = "#FFFFFF";

            if (!string.IsNullOrEmpty(result.LabelX))
            {
                Legend xLegend = new Legend();
                xLegend.Text   = result.LabelX;
                xLegend.Style  = "color: #444444; font-size: 12px;";
                graph.X_Legend = xLegend;
            }

            if (!string.IsNullOrEmpty(result.LabelY))
            {
                Legend yLegend = new Legend();
                yLegend.Text   = result.LabelY;
                yLegend.Style  = "color: #444444; font-size: 12px;";
                graph.Y_Legend = yLegend;
            }

            XAxis xAxis = new XAxis();

            xAxis.Colour     = "#444444";
            xAxis.GridColour = "#CCCCCC";
            xAxis.Steps      = step;
            graph.X_Axis     = xAxis;

            YAxis yAxis = new YAxis();

            yAxis.Colour     = "#444444";
            yAxis.GridColour = "#CCCCCC";
            int y = result.MaxY - result.MinY;

            yAxis.Steps  = y / 5;
            graph.Y_Axis = yAxis;

            string toolTip = language.GetString("LableStatisticCalls");

            for (int i = 0; i < result.Series.Count; i++)
            {
                ChartBase chart = null;

                switch (chartType)
                {
                case ChartType.Bar:
                    chart = new Bar();
                    break;

                case ChartType.Line:
                    chart = new Line();
                    break;

                case ChartType.Column:
                    chart = new HBar();
                    break;

                case ChartType.Pie:
                    chart = new Pie();
                    break;
                }

                chart.Colour = colors[i];
                //chart.Text = result.Series[i].Label.ToLowerInvariant();
                chart.Text = result.Series[i].Label;

                if (statisticsType == StatisticsType.PageView)
                {
                    chart.Tooltip = string.Format("#val# {0} ({1})", toolTip, chart.Text);
                }
                else
                {
                    chart.Tooltip = string.Format("#val#");
                }

                chart.Fontsize = 9;

                for (int j = 0; j < result.Series[i].Values.Count; j++)
                {
                    StatisticValue value  = result.Series[i].Values[j];
                    string         xLabel = string.Empty;

                    if (value is StatisticValueDateTimeInt)
                    {
                        StatisticValueDateTimeInt valueDateTime = (StatisticValueDateTimeInt)value;

                        if (lastDate == DateTime.MinValue)
                        {
                            lastDate = valueDateTime.X;
                        }

                        if (valueDateTime.X > maxDate)
                        {
                            maxDate = valueDateTime.X;
                        }

                        if (valueDateTime.X < minDate)
                        {
                            minDate = valueDateTime.X;
                        }

                        if (j % xAxis.Steps == 0)
                        {
                            if (granularity == Granularity.Year)
                            {
                                xLabel = valueDateTime.X.ToString("yyyy");
                            }
                            else if (granularity == Granularity.Month)
                            {
                                if (lastDate.Year != valueDateTime.X.Year || valueDateTime.X.Month == 1)
                                {
                                    lastDate = valueDateTime.X;
                                    xLabel   = valueDateTime.X.ToString("MMM. yy");
                                }
                                else
                                {
                                    xLabel = valueDateTime.X.ToString("MMM.");
                                }
                            }
                            else if (granularity == Granularity.Day)
                            {
                                if (lastDate.Year != valueDateTime.X.Year || lastDate.Month != valueDateTime.X.Month || valueDateTime.X.Day == 1)
                                {
                                    lastDate = valueDateTime.X;
                                    xLabel   = valueDateTime.X.ToString("d.M.");
                                }
                                else
                                {
                                    xLabel = valueDateTime.X.ToString("d.");
                                }
                            }
                        }
                    }
                    else if (value is StatisticValueStringInt)
                    {
                        xLabel = ((StatisticValueStringInt)value).X;
                    }

                    var val = chart.NewValue(xLabel, value.Y);
                    chart.Values.Add(val);
                }

                graph.Title = new Title(GetTitle(granularity));
                graph.AddElement(chart);
            }

            //context.Response.ContentType = "application/json";

            context.Response.ContentType = "text/plain";
            context.Response.AddHeader("IDS", string.Concat(chartId, "|", errorId));
            context.Response.Write(graph.ToString());
        }
        protected async Task <bool> SetInitialStatistic(Character character, Statistic statistic, int newValue)
        {
            int statMin, statMax, statsAtMax, points, level = GetCharacterLevel(character);

            // This is either an array of all the character's attributes or skills, never both.
            int[] stats;

            // Set variables
            if (statistic is Attribute attrib)
            {
                statMin    = _statOptions.InitialAttributeMin;
                statMax    = _statOptions.InitialAttributeMax;
                points     = _statOptions.InitialAttributePoints;
                statsAtMax = _statOptions.InitialAttributesAtMax;

                stats = character.Statistics.Where(x => x.Statistic is Attribute).Select(x => x.StatisticValue.Value).ToArray();

                if (level > _statOptions.InitialSetupMaxLevel && await InitialAttributesSet(character))
                {
                    throw new ProgressionException(Messages.CHAR_LEVEL_TOO_HIGH);
                }
            }
            else
            {
                statMin    = _statOptions.InitialSkillMin;
                statMax    = _statOptions.InitialSkillMax;
                points     = _statOptions.InitialSkillPoints;
                statsAtMax = _statOptions.InitialSkillsAtMax;

                stats = character.Statistics.Where(x => x.Statistic is Skill).Select(x => x.StatisticValue.Value).ToArray();

                if (level > _statOptions.InitialSetupMaxLevel && await InitialSkillsSet(character))
                {
                    throw new ProgressionException(Messages.CHAR_LEVEL_TOO_HIGH);
                }
            }

            if (newValue < statMin)
            {
                throw new ProgressionException(Messages.TOO_LOW);
            }
            if (newValue > statMax)
            {
                throw new ProgressionException(Messages.TOO_HIGH);
            }

            int sum = stats.Sum(x => x);

            StatisticValue currentVal = character.GetStatistic(statistic);

            if (currentVal == null)
            {
                currentVal = new StatisticValue(0);
            }

            // Make sure the character has enough remaining points to do that
            // (we refund the current stat value since we're overwriting it)
            var newSum = sum - currentVal.Value + newValue;

            if (points - newSum < 0)
            {
                throw new ProgressionException(string.Format(Messages.STAT_NOT_ENOUGH_POINTS, newSum, points));
            }

            // Check if they go over the limit for attributes set to the max
            // Example: InitialAttributesAtMax is set to 2 and InitialAttributeMax is set to 10
            // If we already have 2 attributes with a value of 10 and we try to set a third, disallow it.
            if (statsAtMax > 0 &&
                newValue == statMax &&
                stats.Count(x => x == statMax) + 1 > statsAtMax)
            {
                throw new ProgressionException(String.Format(Messages.STAT_TOO_MANY_AT_MAX, statsAtMax));
            }

            currentVal.Value = newValue;

            return(true);
        }
 public void Load(StatisticValue stat)
 {
     ResetStatsData();
     LoadbaseData(stat);
 }
Beispiel #15
0
 public StatisticMapping(Statistic statistic, StatisticValue value)
 {
     Statistic      = statistic;
     StatisticValue = value;
 }
Beispiel #16
0
        public static StatisticInfo <T>?GetStatisticMeta <TCollect, T>(ref TCollect collect, StatisticValue value)
            where TCollect : struct, ICollectionWrapper <T>
        {
            if (collect.HasIndexOverhead)
            {
                if (collect.HasNext)
                {
                    var item    = collect.Value;
                    var count   = 1u;
                    var sum     = item;
                    var product = item;
                    var minus   = item;

                    switch (value)
                    {
                    case StatisticValue.Sum:
                        while (collect.HasNext)
                        {
                            item = collect.Value;
                            checked
                            {
                                sum = NumberOperators <T> .Sum(sum, item);

                                count += 1;
                            }
                        }

                        return(new StatisticInfo <T>
                        {
                            Sum = new Option <T>(sum),
                            Count = count,
                        });

                    case StatisticValue.Minus:
                        while (collect.HasNext)
                        {
                            item = collect.Value;
                            checked
                            {
                                minus = NumberOperators <T> .Minus(minus, item);

                                count += 1;
                            }
                        }

                        return(new StatisticInfo <T>
                        {
                            Count = count,
                            Minus = new Option <T>(minus),
                        });

                    case StatisticValue.Product:
                        while (collect.HasNext)
                        {
                            item = collect.Value;
                            checked
                            {
                                product = NumberOperators <T> .Product(product, item);

                                count += 1;
                            }
                        }

                        return(new StatisticInfo <T>
                        {
                            Count = count,
                            Product = new Option <T>(product),
                        });

                    case StatisticValue.All:
                        while (collect.HasNext)
                        {
                            item = collect.Value;
                            checked
                            {
                                sum = NumberOperators <T> .Sum(sum, item);

                                minus = NumberOperators <T> .Minus(minus, item);

                                product = NumberOperators <T> .Product(product, item);

                                count += 1;
                            }
                        }

                        return(new StatisticInfo <T>
                        {
                            Sum = new Option <T>(sum),
                            Count = count,
                            Minus = new Option <T>(minus),
                            Product = new Option <T>(product),
                        });

                    case StatisticValue.SumMinus:
                        while (collect.HasNext)
                        {
                            item = collect.Value;
                            checked
                            {
                                sum = NumberOperators <T> .Sum(sum, item);

                                minus = NumberOperators <T> .Minus(minus, item);

                                count += 1;
                            }
                        }

                        return(new StatisticInfo <T>
                        {
                            Sum = new Option <T>(sum),
                            Count = count,
                            Minus = new Option <T>(minus),
                        });

                    case StatisticValue.SumProduct:
                        while (collect.HasNext)
                        {
                            item = collect.Value;
                            checked
                            {
                                sum = NumberOperators <T> .Sum(sum, item);

                                product = NumberOperators <T> .Product(product, item);

                                count += 1;
                            }
                        }

                        return(new StatisticInfo <T>
                        {
                            Sum = new Option <T>(sum),
                            Count = count,
                            Product = new Option <T>(product),
                        });

                    case StatisticValue.MinusProduct:
                        while (collect.HasNext)
                        {
                            item = collect.Value;
                            checked
                            {
                                minus = NumberOperators <T> .Minus(minus, item);

                                product = NumberOperators <T> .Product(product, item);

                                count += 1;
                            }
                        }

                        return(new StatisticInfo <T>
                        {
                            Count = count,
                            Minus = new Option <T>(minus),
                            Product = new Option <T>(product),
                        });
                    }
                }
            }
            else
            {
                var size = collect.Size;
                if (size > 0)
                {
                    var item    = collect[0];
                    var count   = 1u;
                    var sum     = item;
                    var minus   = item;
                    var product = item;

                    switch (value)
                    {
                    case StatisticValue.Sum:
                        while (count < size)
                        {
                            item = collect[count];
                            checked
                            {
                                sum = NumberOperators <T> .Sum(sum, item);

                                count += 1;
                            }
                        }

                        return(new StatisticInfo <T>
                        {
                            Sum = new Option <T>(sum),
                            Count = count,
                        });

                    case StatisticValue.Minus:
                        while (count < size)
                        {
                            item = collect[count];
                            checked
                            {
                                minus = NumberOperators <T> .Minus(minus, item);

                                count += 1;
                            }
                        }

                        return(new StatisticInfo <T>
                        {
                            Count = count,
                            Minus = new Option <T>(minus),
                        });

                    case StatisticValue.Product:
                        while (count < size)
                        {
                            item = collect[count];
                            checked
                            {
                                product = NumberOperators <T> .Product(product, item);

                                count += 1;
                            }
                        }

                        return(new StatisticInfo <T>
                        {
                            Count = count,
                            Product = new Option <T>(product),
                        });

                    case StatisticValue.All:
                        while (count < size)
                        {
                            item = collect[count];
                            checked
                            {
                                sum = NumberOperators <T> .Sum(sum, item);

                                minus = NumberOperators <T> .Minus(minus, item);

                                product = NumberOperators <T> .Product(product, item);

                                count += 1;
                            }
                        }

                        return(new StatisticInfo <T>
                        {
                            Sum = new Option <T>(sum),
                            Count = count,
                            Minus = new Option <T>(minus),
                            Product = new Option <T>(product),
                        });

                    case StatisticValue.SumMinus:
                        while (count < size)
                        {
                            item = collect[count];
                            checked
                            {
                                sum = NumberOperators <T> .Sum(sum, item);

                                minus = NumberOperators <T> .Minus(minus, item);

                                count += 1;
                            }
                        }

                        return(new StatisticInfo <T>
                        {
                            Sum = new Option <T>(sum),
                            Count = count,
                            Minus = new Option <T>(minus),
                        });

                    case StatisticValue.SumProduct:
                        while (count < size)
                        {
                            item = collect[count];
                            checked
                            {
                                sum = NumberOperators <T> .Sum(sum, item);

                                product = NumberOperators <T> .Product(product, item);

                                count += 1;
                            }
                        }

                        return(new StatisticInfo <T>
                        {
                            Sum = new Option <T>(sum),
                            Count = count,
                            Product = new Option <T>(product),
                        });

                    case StatisticValue.MinusProduct:
                        while (count < size)
                        {
                            item = collect[count];
                            checked
                            {
                                minus = NumberOperators <T> .Minus(minus, item);

                                product = NumberOperators <T> .Product(product, item);

                                count += 1;
                            }
                        }

                        return(new StatisticInfo <T>
                        {
                            Count = count,
                            Minus = new Option <T>(minus),
                            Product = new Option <T>(product),
                        });
                    }
                }
            }

            return(null);
        }
Beispiel #17
0
        /// </inheritdoc>
        public double?RollStatistic(Statistic stat, Character character, bool useEffects = false)
        {
            StatisticValue sv = character?.GetStatistic(stat, useEffects);

            if (character == null || sv == null)
            {
                return(null);
            }

            int    rng = GameRandom.Between(1, 100);
            double maxSuccessRoll;

            int statNum = sv.Value;

            if (statNum <= 0)
            {
                return(-999);
            }

            if (stat is Attribute)
            {
                maxSuccessRoll = Math.Round(32.2 * Math.Sqrt(statNum) - 7);
            }
            else
            {
                maxSuccessRoll = Math.Round(10 * Math.Sqrt(statNum) - 0.225 * statNum - 1);
            }

            Attribute luckStat       = character.Statistics.Select(x => x.Statistic).OfType <Attribute>().FirstOrDefault(x => x.Aliases.ContainsIgnoreCase("luck"));
            double    luckInfluence  = 1.0;
            int       luckDifference = 0;

            if (luckStat != null)
            {
                // each point of LCK above/below 5 prolly shoulda been +/-1% flat chance max
                // Do that, but ALSO make each point in luck a +/-0.1% chance for  mega crit

                int luckValue = character.GetStatistic(luckStat, useEffects).Value;
                luckDifference = luckValue - 5;

                luckInfluence  += luckDifference * 0.01;
                maxSuccessRoll *= luckInfluence;
            }

            maxSuccessRoll = Math.Min(maxSuccessRoll, HIGHEST_MAX_SUCCESS_ROLL);

            double resultPercent = (maxSuccessRoll - rng) / maxSuccessRoll;

            int critRng = GameRandom.Between(1, 1000);

            // Success
            if (resultPercent >= 0)
            {
                double maxCritSuccessRoll = 1 + (1 * luckDifference);

                // Minimum 1, maximum 10
                maxCritSuccessRoll = Math.Max(1, Math.Min(maxCritSuccessRoll, 10));

                if (critRng <= maxCritSuccessRoll)
                {
                    return(999);
                }
            }
            // Failure
            else
            {
                double maxCritFailRoll = 6 - (1 * luckDifference);
                maxCritFailRoll = Math.Min(maxCritFailRoll, 10);

                if (critRng <= maxCritFailRoll)
                {
                    return(-999);
                }
            }

            return(Math.Round(resultPercent * 100.0, 1));
        }