private void FillInformation(List <Guid> r)
        {
            Debug.Assert(r.Count() != 0);

            // TODO optimize
            StatisticResult st = new StatisticResult(r);

            researchInfoTable.Rows.Add("Research ID", r[0].ToString());
            researchInfoTable.Rows.Add("Research Name", StatSessionManager.GetResearchName(r[0]));
            researchInfoTable.Rows.Add("Research Type", StatSessionManager.GetResearchType(r[0]));
            researchInfoTable.Rows.Add("Model Type", StatSessionManager.GetResearchModelType(r[0]));
            researchInfoTable.Rows.Add("Realization Count", st.RealizationCountSum);
            researchInfoTable.Rows.Add("Date", StatSessionManager.GetResearchDate(r[0]));
            researchInfoTable.Rows.Add("Size", StatSessionManager.GetResearchNetworkSize(r[0]));
            researchInfoTable.Rows.Add("Edges", st.EdgesCountAvg);

            int i = researchInfoTable.Rows.Add("Parameters", "");

            researchInfoTable.Rows[i].DefaultCellStyle.BackColor = Color.LightGray;

            Dictionary <ResearchParameter, object>   rValues = StatSessionManager.GetResearchParameterValues(r[0]);
            Dictionary <GenerationParameter, object> gValues = StatSessionManager.GetGenerationParameterValues(r[0]);

            foreach (ResearchParameter rr in rValues.Keys)
            {
                researchInfoTable.Rows.Add(rr.ToString(), rValues[rr].ToString());
            }
            foreach (GenerationParameter g in gValues.Keys)
            {
                researchInfoTable.Rows.Add(g.ToString(), gValues[g].ToString());
            }
        }
Esempio n. 2
0
            public async Task <RuntimeResult> TagSkillsAsync(Skill tag1, Skill tag2, Skill tag3)
            {
                if (!_progOptions.UseOldProgression ||
                    !_progOptions.OldProgression.UseNewVegasRules)
                {
                    return(StatisticResult.NotUsingNewVegasRules());
                }

                var userInfo  = Context.User;
                var character = await _charService.GetCharacterAsync(userInfo.Id);

                if (character == null)
                {
                    return(CharacterResult.CharacterNotFound());
                }

                if (_skillsService.AreSkillsSet(character))
                {
                    return(StatisticResult.SkillsAlreadyTagged());
                }

                try
                {
                    await _skillsService.TagSkills(character, tag1, tag2, tag3);

                    return(GenericResult.FromSuccess(Messages.SKILLS_SET_SUCCESS));
                }
                catch (Exception e)
                {
                    return(GenericResult.FromError($"{Messages.FAILURE_EMOJI} {e.Message}"));
                }
            }
Esempio n. 3
0
        /// <summary>
        /// Gets the character associated with the id and checks
        /// if their specified statistic is higher than the given value.
        /// </summary>
        /// <param name="id">The id of the character to get.</param>
        /// <param name="statName">The name of the statistic to get.</param>
        /// <param name="minimum">Checks if the character's StatisticValue is greater than or equal to this value.</param>
        /// <returns>
        /// A result detailing if the operation was successful or why it failed.
        /// </returns>
        public async Task <IResult> CheckStatisticAsync(ulong id, string statName)
        {
            var character = await _charProvider.GetActiveCharacterAsync(id);

            if (character == null)
            {
                return(CharacterResult.CharacterNotFound());
            }

            var stat = await _statProvider.GetStatisticAsync(statName);

            if (stat == null)
            {
                return(StatisticResult.StatisticNotFound());
            }

            var statValue = character.GetStatistic(stat);

            if (statValue == null)
            {
                return(StatisticResult.StatisticNotFound());
            }

            return(StatisticResult.StatisticCheck(character.Name, stat.Name, statValue.Value));
        }
Esempio n. 4
0
            public async Task <RuntimeResult> SetSkillsAsync(Skill tag, int points)
            {
                if (ExperienceService.UseOldProgression)
                {
                    return(StatisticResult.UsingOldProgression());
                }

                var userInfo  = Context.User;
                var character = await _charService.GetCharacterAsync(userInfo.Id);

                if (character == null)
                {
                    return(CharacterResult.CharacterNotFound());
                }
                if (_skillsService.AreSkillsSet(character))
                {
                    return(StatisticResult.SkillsAlreadyTagged());
                }

                try
                {
                    await _skillsService.TagSkill(character, tag, points);

                    return(GenericResult.FromSuccess(Messages.SKILLS_SET_SUCCESS));
                }
                catch (Exception e)
                {
                    return(GenericResult.FromError($"{Messages.FAILURE_EMOJI} {e.Message}"));
                }
            }
Esempio n. 5
0
        /// <summary>
        /// Performs a roll on a character's statistic and returns the result.
        /// </summary>
        /// <param name="callerId">Discord ID of the caller.</param>
        /// <param name="statName">The statistic name.</param>
        /// <returns>The result of the roll.</returns>
        public async Task <IResult> RollStatisticAsync(ulong callerId, string statName, bool useEffects = false)
        {
            var character = await _provider.GetActiveCharacterAsync(callerId);

            if (character == null)
            {
                return(CharacterResult.CharacterNotFound());
            }

            var stat = await _statProvider.GetStatisticAsync(statName);

            if (stat == null)
            {
                return(StatisticResult.StatisticNotFound());
            }

            string result = _strategy.GetRollMessage(stat, character, useEffects);

            if (!string.IsNullOrEmpty(result))
            {
                return(RollResult.Roll(result));
            }

            return(RollResult.RollFailed());
        }
Esempio n. 6
0
 public DistributedOptionsWindow(List <Guid> r, List <AnalyzeOption> o)
 {
     researches       = r;
     options          = o;
     statisticResults = new StatisticResult(researches);
     InitializeComponent();
 }
Esempio n. 7
0
        /// <summary>
        /// Sets the statistic effects of the specified effect.
        /// </summary>
        /// <param name="effectName">The name of the effect to set the value to.</param>
        /// <param name="statName">The name of the statistic to associate the value with.</param>
        /// <param name="value">The value to add (or subtract) to the statistic.</param>
        /// <returns>
        /// A result detailing if the operation was successful or why it failed.
        /// </returns>
        public async Task <IResult> SetStatisticEffectAsync(string effectName, string statName, int value)
        {
            var effect = await _effectProvider.GetEffectAsync(effectName);

            if (effect == null)
            {
                return(EffectResult.EffectNotFound());
            }

            var stat = await _statProvider.GetStatisticAsync(statName);

            if (stat == null)
            {
                return(StatisticResult.StatisticNotFound());
            }

            var match = effect.StatisticEffects.FirstOrDefault(x => x.Statistic.Equals(stat));

            if (match == null)
            {
                effect.StatisticEffects.Add(new StatisticMapping(stat, new StatisticValue(value)));
            }
            else
            {
                match.StatisticValue.Value = value;
            }

            await _effectProvider.UpdateEffectAsync(effect);

            return(EffectResult.EffectUpdatedSucessfully());
        }
Esempio n. 8
0
        public async Task SetProficiencyAsync_SetFalse_ReturnSuccess()
        {
            // Arrange
            var charProvider = new MockCharacterProvider();
            var statProvider = new MockStatisticProvider();

            var statOptions = new StatisticOptions
            {
                InitialAttributeMin         = 1,
                InitialAttributeMax         = 10,
                InitialAttributePoints      = 40,
                InitialAttributesAtMax      = 7,
                InitialAttributesProficient = 0
            };

            var controller = new StatisticController(charProvider, statProvider, new GenericProgressionStrategy(statProvider, statOptions));
            var character  = await charProvider.GetActiveCharacterAsync(1);

            await controller.SetStatisticAsync(1, "strength", 10);

            // Act
            var result = await controller.SetProficiencyAsync(1, "strength", false);

            // Assert
            Assert.Equal(StatisticResult.StatisticSetSucessfully(), result);
        }
Esempio n. 9
0
        public async Task SetStatisticAsync_LevelTooHighButAttributesUnset_ReturnSuccess()
        {
            // Arrange
            var charProvider = new MockCharacterProvider();
            var character    = await charProvider.CreateCharacterAsync(100, "TooHigh");

            // the important bit
            character.Experience = 50000;

            var statProvider = new MockStatisticProvider();
            var statOptions  = new StatisticOptions
            {
                InitialAttributeMin    = 1,
                InitialAttributeMax    = 10,
                InitialAttributePoints = 10,
                InitialSetupMaxLevel   = 1
            };

            var controller = new StatisticController(charProvider, statProvider, new GenericProgressionStrategy(statProvider, statOptions));

            // Act
            var result = await controller.SetStatisticAsync(100, "strength", 3);

            // Assert
            Assert.Equal(StatisticResult.StatisticSetSucessfully(), result);
        }
Esempio n. 10
0
        /// <summary>
        /// Performs a duel between two characters rolling a statistic and returns the result.
        /// </summary>
        /// <param name="callerId">Discord ID of the caller.</param>
        /// <param name="targetId">Discord ID of the target.</param>
        /// <param name="statName">The statistic name.</param>
        /// <returns>The result of the roll.</returns>
        public async Task <IResult> RollStatisticAgainstAsync(ulong callerId, ulong targetId, string statName, bool useEffects = false)
        {
            var caller = await _provider.GetActiveCharacterAsync(callerId);

            if (caller == null)
            {
                return(CharacterResult.CharacterNotFound());
            }

            var target = await _provider.GetActiveCharacterAsync(targetId);

            if (target == null)
            {
                return(CharacterResult.CharacterNotFound());
            }

            var stat = await _statProvider.GetStatisticAsync(statName);

            if (stat == null)
            {
                return(StatisticResult.StatisticNotFound());
            }

            double?callerRoll = _strategy.RollStatistic(stat, caller, useEffects);
            double?targetRoll = _strategy.RollStatistic(stat, target, useEffects);

            if (callerRoll.HasValue && targetRoll.HasValue)
            {
                return(RollResult.RollAgainst(caller.Name, target.Name, callerRoll.Value, targetRoll.Value));
            }

            return(RollResult.RollFailed());
        }
Esempio n. 11
0
 private void ShowStatisticResult(StatisticResult result)
 {
     CountTextBlock.Text         = result.Count.ToString();
     ExceedAmountTextBlock.Text  = result.ExceedAmount.ToString();
     UnderAmountTextBlock.Text   = result.UnderAmount.ToString();
     ExceedPercentTextBlock.Text = String.Format("{0:f2}%", result.ExceedPercent * 100);
     UnderPercentTextBlock.Text  = String.Format("{0:f2}%", result.UnderPercent * 100);
 }
Esempio n. 12
0
 public void Setup()
 {
     data = new double[]
     {
         6, 6, 7, 13, 15, 20, 21, 22, 23, 27, 28, 29, 31, 36, 40, 41, 46,
         47, 48, 49, 52, 55, 56, 57, 58, 61, 63, 65, 67, 74, 82, 98
     };
     result = Statistics.Statistic(data);
 }
Esempio n. 13
0
        private StatisticResult[] StatRegionData(out string str_error, int id)
        {
            str_error = "";
            List <StatisticResult> results = new List <StatisticResult>();

            string sql   = "exec StatSubRegionData " + id + "," + ConfCenter.ImportantUserRoleLevel + "," + ConfCenter.AdministratorUserRoleLevel + "," + ConfCenter.LoginAdminRoleLevel;
            string error = "";

            try
            {
                DataTable dt = DataBaseHelper.ExecuteTable(sql, out error);
                if (error == "")
                {
                    if (dt.Rows.Count > 0)
                    {
                        foreach (DataRow dr in dt.Rows)
                        {
                            StatisticResult result   = new StatisticResult();
                            string          name     = dr[0].ToString();
                            string          alias    = dr[1].ToString();
                            int             dCount   = Convert.ToInt32(dr[2]);
                            int             uCount   = Convert.ToInt32(dr[3]);
                            int             uCountL1 = Convert.ToInt32(dr[4]);
                            int             uCountL2 = Convert.ToInt32(dr[5]);
                            int             uCountL3 = Convert.ToInt32(dr[6]);
                            result.name = alias == "" ? name : alias;
                            result.data.Add("社区数目", dCount);
                            result.data.Add("用户总数", uCount);
                            result.data.Add("戒毒人员", uCountL1);
                            result.data.Add("社工", uCountL2);
                            result.data.Add("民警", uCountL3);
                            if (uCountL1 + uCountL2 + uCountL3 < uCount)
                            {
                                result.data.Add("其他", uCount - uCountL1 - uCountL2 - uCountL3);
                            }
                            results.Add(result);
                        }
                    }
                    else
                    {
                        throw new Exception("没有查到该行政区的数据");
                    }
                }
                else
                {
                    throw new Exception(error);
                }
            }
            catch (Exception ex)
            {
                str_error = ex.Message;
                SystemLog.WriteErrorLog("统计行政区基本信息失败", "1031", ex.Message, ex.StackTrace);
            }

            return(results.ToArray());
        }
Esempio n. 14
0
        public async Task CreateSkillAsync_AlreadyExists_ReturnNameAlreadyExists()
        {
            var charProvider = new MockCharacterProvider();
            var statProvider = new MockStatisticProvider();
            var controller   = new StatisticController(charProvider, statProvider, null);

            var result = await controller.CreateSkillAsync("Powerlifting", "Strength");

            Assert.Equal(StatisticResult.NameAlreadyExists(), result);
        }
Esempio n. 15
0
        public async Task CreateAttributeAsync_ValidInput_ReturnSuccess()
        {
            var charProvider = new MockCharacterProvider();
            var statProvider = new MockStatisticProvider();
            var controller   = new StatisticController(charProvider, statProvider, null);

            var result = await controller.CreateAttributeAsync("Wisdom");

            Assert.Equal(StatisticResult.StatisticCreatedSuccessfully(), result);
        }
Esempio n. 16
0
        public async Task CreateSkillAsync_ValidInput_ReturnSuccess()
        {
            var charProvider = new MockCharacterProvider();
            var statProvider = new MockStatisticProvider();
            var controller   = new StatisticController(charProvider, statProvider, null);

            var result = await controller.CreateSkillAsync("Intimidation", "Strength");

            Assert.Equal(StatisticResult.StatisticCreatedSuccessfully(), result);
        }
Esempio n. 17
0
        public async Task CreateSkillAsync_InvalidAttributeName_ReturnCreationFailed()
        {
            var charProvider = new MockCharacterProvider();
            var statProvider = new MockStatisticProvider();
            var controller   = new StatisticController(charProvider, statProvider, null);

            var result = await controller.CreateSkillAsync("Intimidation", "STR");

            Assert.Equal(StatisticResult.StatisticCreationFailed(), result);
        }
Esempio n. 18
0
        public async Task DeleteStatistic_InvalidStatName_ReturnNotFound()
        {
            // Arrange
            var charProvider = new MockCharacterProvider();
            var statProvider = new MockStatisticProvider();
            var controller   = new StatisticController(charProvider, statProvider, new GenericProgressionStrategy(statProvider, new StatisticOptions()));

            // Act
            var result = await controller.DeleteStatisticAsync("bacon");

            // Assert
            Assert.Equal(result, StatisticResult.StatisticNotFound());
        }
Esempio n. 19
0
        public async Task DeleteStatistic_ValidInput_ReturnSuccess()
        {
            // Arrange
            var charProvider = new MockCharacterProvider();
            var statProvider = new MockStatisticProvider();
            var controller   = new StatisticController(charProvider, statProvider, new GenericProgressionStrategy(statProvider, new StatisticOptions()));

            // Act
            var result = await controller.DeleteStatisticAsync("strength");

            // Assert
            Assert.Equal(result, StatisticResult.StatisticDeletedSuccessfully());
        }
Esempio n. 20
0
        public async Task <RuntimeResult> AddAliasAsync(Statistic stat, string alias)
        {
            if (_statService.NameOrAliasExists(alias))
            {
                return(StatisticResult.StatisticAlreadyExists());
            }

            stat.Aliases += alias + "/";

            await _statService.SaveStatisticAsync(stat);

            return(GenericResult.FromSuccess("Alias added successfully."));
        }
Esempio n. 21
0
        /// <summary>
        /// Deletes a statistic in the database.
        /// </summary>
        /// <param name="statName">The name for the new skill.</param>
        /// A result detailing if the operation was successful or why it failed.
        /// </returns>
        public async Task <IResult> DeleteStatisticAsync(string statName)
        {
            var statistic = await _statProvider.GetStatisticAsync(statName);

            if (statistic == null)
            {
                return(StatisticResult.StatisticNotFound());
            }

            await _statProvider.DeleteStatisticAsync(statistic);

            return(StatisticResult.StatisticDeletedSuccessfully());
        }
Esempio n. 22
0
        public async Task Roll_InvalidStat_ReturnStatNotFound()
        {
            // Arrange
            var provider     = new MockCharacterProvider();
            var statProvider = new MockStatisticProvider();
            var controller   = new RollController(provider, statProvider, new MockRollStrategy());

            // Act
            var result = await controller.RollStatisticAsync(1, "invalid");

            // Assert
            Assert.True(StatisticResult.StatisticNotFound().Equals(result));
        }
Esempio n. 23
0
        public async Task <RuntimeResult> RenameStatAsync(Statistic stat, string newName)
        {
            if (_statService.NameExists(newName))
            {
                return(StatisticResult.StatisticAlreadyExists());
            }

            stat.Name    = newName;
            stat.Aliases = newName + "/";

            await _statService.SaveStatisticAsync(stat);

            return(GenericResult.FromSuccess("Statistic renamed successfully."));
        }
Esempio n. 24
0
        /// <summary>
        /// Clears the aliases of an already existing statistic.
        /// </summary>
        /// <param name="statName">The name of the statistic to add an alias to.</param>
        /// <returns>A result detailing if the operation was successful or why it failed.</returns>
        public async Task <IResult> ClearAliasesAsync(string statName)
        {
            var stat = await _statProvider.GetStatisticAsync(statName);

            if (stat == null)
            {
                return(StatisticResult.StatisticNotFound());
            }

            stat.Aliases = stat.Name + "/";
            await _statProvider.UpdateStatisticAsync(stat);

            return(StatisticResult.StatisticUpdatedSucessfully());
        }
Esempio n. 25
0
        /// <summary>
        /// Sets the order of an already existing statistic.
        /// </summary>
        /// <param name="statName">The name of the statistic to set the order of.</param>
        /// <param name="order">The order to sort the statistic in a descending manner.</param>
        /// <returns>A result detailing if the operation was successful or why it failed.</returns>
        public async Task <IResult> SetOrderAsync(string statName, int order)
        {
            var stat = await _statProvider.GetStatisticAsync(statName);

            if (stat == null)
            {
                return(StatisticResult.StatisticNotFound());
            }

            stat.Order = order;
            await _statProvider.UpdateStatisticAsync(stat);

            return(StatisticResult.StatisticUpdatedSucessfully());
        }
Esempio n. 26
0
        public async Task SetStatisticAsync_InvalidStatisticName_ReturnStatisticNotFound()
        {
            // Arrange
            var charProvider             = new MockCharacterProvider();
            var statProvider             = new MockStatisticProvider();
            StatisticOptions statOptions = new StatisticOptions();

            var controller = new StatisticController(charProvider, statProvider, new GenericProgressionStrategy(statProvider, statOptions));

            // Act
            var result = await controller.SetStatisticAsync(1, "invalid", 5);

            // Assert
            Assert.Equal(StatisticResult.StatisticNotFound(), result);
        }
Esempio n. 27
0
        /// <summary>
        /// Creates a new Skill in the database.
        /// </summary>
        /// <param name="statName">The name for the new skill.</param>
        /// <param name="attribName">The name of the attribute to go with the skill. Must exist in the database beforehand.</param>
        /// <returns>
        /// A result detailing if the operation was successful or why it failed.
        /// </returns>
        public async Task <IResult> CreateSkillAsync(string statName, string attribName)
        {
            if (await _statProvider.GetStatisticAsync(statName) != null)
            {
                return(StatisticResult.NameAlreadyExists());
            }

            var result = await _statProvider.CreateSkillAsync(statName, attribName);

            if (result == null)
            {
                return(StatisticResult.StatisticCreationFailed());
            }
            return(StatisticResult.StatisticCreatedSuccessfully());
        }
Esempio n. 28
0
        public async Task SetStatisticEffectAsync_InvalidStatisticName_ReturnStatisticNotFound()
        {
            // Arrange
            var charProvider   = new MockCharacterProvider();
            var effectProvider = new MockEffectProvider();
            var statProvider   = new MockStatisticProvider();

            var controller = new EffectController(charProvider, effectProvider, statProvider, null);

            await effectProvider.CreateEffectAsync(1, "ValidInput");

            var result = await controller.SetStatisticEffectAsync("ValidInput", "DoesNotExist", 1);

            Assert.Equal(StatisticResult.StatisticNotFound(), result);
        }
Esempio n. 29
0
        /// <summary>
        /// Used to set a character's attributes up.
        /// </summary>
        /// <param name="callerId">The user identifier of the caller.</param>
        /// <param name="values">What to set the initial attributes to.</param>
        public async Task <IResult> SetStatisticAsync(ulong callerId, string statName, int?newValue = null, bool force = false)
        {
            var character = await _charProvider.GetActiveCharacterAsync(callerId);

            if (character == null)
            {
                return(CharacterResult.CharacterNotFound());
            }

            var statistic = await _statProvider.GetStatisticAsync(statName);

            if (statistic == null)
            {
                return(StatisticResult.StatisticNotFound());
            }

            try
            {
                if (force)
                {
                    var statValue = character.GetStatistic(statistic);

                    if (newValue.HasValue)
                    {
                        statValue.Value = newValue.Value;
                    }
                }
                else
                {
                    await _strategy.SetStatistic(character, statistic, newValue);
                }

                await _charProvider.UpdateCharacterAsync(character);

                return(StatisticResult.StatisticSetSucessfully());
            }
            catch (System.Exception e)
            {
                if (!(e is ProgressionException))
                {
                    System.Console.WriteLine(e);
                }

                return(GenericResult.Failure(e.Message));

                throw e;
            }
        }
Esempio n. 30
0
            public async Task <RuntimeResult> UpgradeSpecialAsync(Special special)
            {
                var userInfo  = Context.User;
                var character = await _charService.GetCharacterAsync(userInfo.Id);

                if (character == null)
                {
                    return(CharacterResult.CharacterNotFound());
                }
                if (!_specService.IsSpecialSet(character))
                {
                    return(StatisticResult.SpecialNotSet());
                }

                return(_specService.UpgradeSpecial(character, special));
            }