当前位置: 首页>>代码示例>>C#>>正文


C# Dice.ChooseByRoll方法代码示例

本文整理汇总了C#中Dice.ChooseByRoll方法的典型用法代码示例。如果您正苦于以下问题:C# Dice.ChooseByRoll方法的具体用法?C# Dice.ChooseByRoll怎么用?C# Dice.ChooseByRoll使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Dice的用法示例。


在下文中一共展示了Dice.ChooseByRoll方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: BuildAnimal

        public static Animal BuildAnimal(string terrainType, string animalClassName = null, int evolutionRolls = 0)
        {
            var dice = new Dice();

            //Options
            var selectedTerrainType = TerrainTypeList.Single(x => x.Name == terrainType);
            var terrainPenalty = 0;

            if (animalClassName == null)
            {
                var animalClassNotes = dice.ChooseWithOdds(selectedTerrainType.AnimalClasses);
                animalClassName = animalClassNotes.AnimalClass;
                terrainPenalty = animalClassNotes.Penalty;
            }
            else
            {
                var animalClassNotes = selectedTerrainType.AnimalClasses.SingleOrDefault(ac => ac.AnimalClass == animalClassName);
                if (animalClassNotes == null)
                    terrainPenalty = -5; //What is it doing here?
                else
                    terrainPenalty = animalClassNotes.Penalty;
            }
            var animalClass = AnimalClassList.Single(x => x.Name == animalClassName);

            //Type
            var result = new Animal() { TerrainType = selectedTerrainType.Name, AnimalClass = animalClassName, EvolutionRolls = evolutionRolls };
            var movement = dice.ChooseByRoll(selectedTerrainType.MovementChart, "D6");
            result.Movement = !string.IsNullOrWhiteSpace(animalClass.Movement) ? animalClass.Movement : movement.Movement;
            result.InitiativeDM += animalClass.InitiativeDM;

            //Starting Skills
            foreach (var skill in animalClass.Skills)
                if (skill.ScoreSpecified)
                    result.Skills.Add(skill.Name, skill.Score);
                else
                    result.Skills.Increase(skill.Name, skill.Bonus);

            //Class features
            if (animalClass.Features != null)
                foreach (var feature in animalClass.Features)
                    result.Features.Add(feature.Text);

            //Diet
            var diet = dice.ChooseWithOdds(animalClass.Diets);
            result.Diet = diet.Diet;
            if (diet.Skills != null)
                foreach (var skill in diet.Skills)
                    if (skill.ScoreSpecified)
                        result.Skills.Add(skill.Name, skill.Score);
                    else
                        result.Skills.Increase(skill.Name, skill.Bonus);

            foreach (var att in diet.Attribute)
                result.Increase(att.Name, dice.D(att.Bonus));

            var weaponDM = 0;
            switch (result.Diet)
            {
                case "Carnivore":
                    result.InitiativeDM += 1;
                    weaponDM = 8;
                    break;
                case "Omnivore":
                    weaponDM = 4;
                    break;
                case "Herbivore":
                    result.InitiativeDM += -1;
                    weaponDM = -6;
                    break;
            }

            //Behavior
            var behaviorMeta = dice.ChooseByRoll(diet.Behaviors, "1D");
            var behavior = BehaviorList.Single(x => x.Name == behaviorMeta.Behavior);

            result.Behavior = behaviorMeta.Behavior;
            result.Attack = behavior.Attack.ToIntOrNull();
            result.Flee = behavior.Flee.ToIntOrNull();
            result.InitiativeDM += behavior.InitiativeDM;

            //subtract the reaction to make it act like a DM
            result.Attack -= behaviorMeta.Reaction;
            result.Flee -= behaviorMeta.Reaction;

            AddBehavior(result, behavior, dice);

            result.QuirkRolls += dice.D("D6") == 6 ? 1 : 0;

            //We do this in a loop because each chart can add rolls to other charts
            while (result.QuirkRolls > 0 || result.EvolutionRolls > 0 || result.PhysicalSkills > 0 || result.SocialSkills > 0 || result.EvolutionSkills > 0)
            {

                //Evolution Rolls
                while (result.EvolutionRolls > 0)
                {
                    result.EvolutionRolls -= 1;
                    if (dice.D(2) == 0)
                        RollOnChart(result, animalClass.Chart.Single(x => x.Name == "AdditionalSkills"), dice, $"1D6+{result.EvolutionDM}");
                    else
                        RollOnChart(result, animalClass.Chart.Single(x => x.Name == "OtherBenefits"), dice, $"1D6+{result.EvolutionDM}");
//.........这里部分代码省略.........
开发者ID:Grauenwolf,项目名称:TravellerTools,代码行数:101,代码来源:AnimalBuilderAE.cs

示例2: RollOnChart

        static void RollOnChart(Animal result, Chart chart, Dice dice, string dieCode = "D6")
        {
            var option = dice.ChooseByRoll(chart.Option, dieCode);

            if (option.Attributes != null)
                foreach (var att in option.Attributes)
                    result.Increase(att.Name, dice.D(att.Bonus));

            if (option.Charts != null)
                foreach (var subChart in option.Charts)
                {
                    RollOnChart(result, subChart, dice, subChart.Roll);
                }

            if (option.Features != null)
                foreach (var feature in option.Features)
                    result.Features.Add(feature.Text);

            if (option.PostScripts != null)
                foreach (var script in option.PostScripts)
                    result.PostScripts.Add(script.Text);

            if (option.Skills != null)
                foreach (var skill in option.Skills)
                    if (skill.ScoreSpecified)
                        result.Skills.Add(skill.Name, skill.Score);
                    else
                        result.Skills.Increase(skill.Name, skill.Bonus);

            if (option.Behaviors != null)
                foreach (var behaviorMeta in option.Behaviors)
                {
                    var behavior = BehaviorList.SingleOrDefault(x => x.Name == behaviorMeta.Name);
                    if (behavior == null)
                        throw new BookException($"Chart {chart.Name} referes to unknown behavior named '{behaviorMeta.Name}'");
                    result.Behavior = result.Behavior + ", " + behavior.Name;
                    AddBehavior(result, behavior, dice);
                }
        }
开发者ID:Grauenwolf,项目名称:TravellerTools,代码行数:39,代码来源:AnimalBuilderAE.cs


注:本文中的Dice.ChooseByRoll方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。