/// <summary>
        /// Createas an instance of a Weapon using a JS-Object as initializer
        /// </summary>
        /// <param name="weaponJS">JSON Object to create the Weapon with</param>
        public Weapon(SingleWeaponJS weaponJS)
        {
            DiceInterpreter weaponDamageConverter = new DiceInterpreter();

            Name         = weaponJS.Name;
            PierceDamage = weaponDamageConverter.getDice(weaponJS.PierceDamageString);
            BashDamage   = weaponDamageConverter.getDice(weaponJS.BashDamageString);
            CutDamage    = weaponDamageConverter.getDice(weaponJS.CutDamageString);
            Length       = weaponJS.Length;
            Weight       = weaponJS.Weight;

            foreach (string effectName in weaponJS.StatusEffects)
            {
                if (effectName == AvailableAfflictions.Bleed.ToString())
                {
                    Afflictions.Add(new CauseBleed());
                }
                else if (effectName == AvailableAfflictions.BreakBones.ToString())
                {
                    Afflictions.Add(new CauseBreakBones());
                }
                else if (effectName == AvailableAfflictions.Unconsciousness.ToString())
                {
                    Afflictions.Add(new CauseUnconsciousness());
                }
                else
                {
                    System.Diagnostics.Debug.WriteLine("Invalid Status Effect {0} detected", effectName);
                }
            }
        }
Exemple #2
0
        public void diceFormulaDoesNotThrowException()
        {
            DiceInterpreter diceEngine = new DiceInterpreter();

            Dictionary <string, bool> diceFormulaTestStrings = new Dictionary <string, bool>();

            diceFormulaTestStrings.Add("2", true);
            diceFormulaTestStrings.Add("1w6", true);
            diceFormulaTestStrings.Add("3w2+1", true);
            diceFormulaTestStrings.Add("9w4-3", true);
            diceFormulaTestStrings.Add("10w31-20", true);
            diceFormulaTestStrings.Add("123w456+789", true);

            foreach (string testStr in diceFormulaTestStrings.Keys)
            {
                try
                {
                    Dice dice   = diceEngine.getDice(testStr);
                    int  result = dice.Throw();
                    TestContext.WriteLine("Evaluating \t{0} returns {1}", testStr, result);
                }
                catch (Exception ex)
                {
                    Assert.Fail(ex.Message.ToString());
                    return;
                }
            }

            Assert.Pass("No Exception thrown");
        }