private DieRoll MakeRoll()
        {
            DieRoll roll = new DieRoll();

            if (_Steps.Count > 0)
            {
                roll.die   = _Steps[0].Die;
                roll.count = _Steps[0].Count;


                if (_Steps.Count > 1)
                {
                    roll.extraRolls = new List <DieStep>();
                    for (int i = 1; i < _Steps.Count; i++)
                    {
                        roll.extraRolls.Add(_Steps[i]);
                    }
                }
            }


            if (HasToughness)
            {
                roll.mod = _Mod.Value == 0?HPstatmod * roll.TotalCount + (roll.TotalCount < 3 ? 3 : roll.TotalCount):roll.mod = _Mod.Value;
            }
            else
            {
                roll.mod = _Mod.Value == 0? HPstatmod * roll.TotalCount : roll.mod = _Mod.Value;
            }


            return(roll);
        }
Example #2
0
        private void CopyFrom(DieRoll old)
        {
            if (old == null)
            {
                count = 0;
                die   = 0;
                mod   = 0;
            }
            else
            {
                count    = old.count;
                fraction = old.fraction;
                die      = old.die;
                mod      = old.mod;


                if (old.extraRolls != null)
                {
                    extraRolls = new List <DieStep>();

                    foreach (DieStep step in old.extraRolls)
                    {
                        extraRolls.Add(new DieStep(old.count, old.die));
                    }
                }
                else
                {
                    extraRolls = null;
                }
            }
        }
Example #3
0
        public override bool Equals(object obj)
        {
            if (obj.GetType() != typeof(DieRoll))
            {
                return(false);
            }
            DieRoll roll = (DieRoll)obj;

            if (roll.extraRolls == null ^ extraRolls == null)
            {
                return(false);
            }

            if (extraRolls != null)
            {
                if (roll.extraRolls.Count != extraRolls.Count)
                {
                    return(false);
                }

                for (int i = 0; i < extraRolls.Count; i++)
                {
                    if (roll.extraRolls[i] != extraRolls[i])
                    {
                        return(false);
                    }
                }
            }

            return(roll.count == count && roll.die == die && roll.fraction == fraction && roll.mod == mod);
        }
Example #4
0
        private static DieRoll StepUpDieRoll(DieRoll roll)
        {
            DieRoll outRoll = roll;

            DieStep step = new DieStep(roll.count, roll.die);

            if (stepUpList.ContainsKey(step))
            {
                step = stepUpList[step];
            }
            else
            {
                if (step.Count < 2)
                {
                    step.Count += 1;
                }
                else
                {
                    step.Count += 2;
                }
            }

            outRoll.count = step.Count;
            outRoll.die   = step.Die;

            return(outRoll);
        }
Example #5
0
        public DieRoll SizeDamageDie(MonsterSize size)
        {
            if (DamageDie == null)
            {
                return(null);
            }

            return(DieRoll.StepDie(DamageDie, (size - MonsterSize.Medium)));
        }
Example #6
0
 public Attack(int count, string name, DieRoll damage, string plus)
 {
     Count          = count;
     Name           = name;
     Bonus          = new List <int>();
     Damage         = damage;
     Plus           = plus;
     CritRange      = 20;
     CritMultiplier = 2;
 }
Example #7
0
 private static string DieText(DieRoll roll)
 {
     if (roll.die == 1)
     {
         return(roll.count.ToString());
     }
     else
     {
         return(roll.Text);
     }
 }
Example #8
0
        private void CreateWeaponItem(Weapon weapon)
        {
            WeaponItem item = new WeaponItem(weapon);

            DieRoll roll = DieRoll.FromString(item.Weapon.DmgM);

            roll      = DieRoll.StepDie(roll, ((int)SizeMods.GetSize(monster.Size)) - (int)MonsterSize.Medium);
            item.Step = roll.Step;

            WeaponItem = item;
        }
Example #9
0
        public bool TryParseHP()
        {
            DieRoll dr = DieRoll.FromString(monster.HD);

            if (dr != null)
            {
                HP = dr.Roll().Total;
                return(true);
            }

            return(false);
        }
Example #10
0
        private static DieRoll GetDie(string text)
        {
            DieRoll dieroll;

            dieroll = Monster.FindNextDieRoll(text);

            if (dieroll == null)
            {
                dieroll = new DieRoll(int.Parse(text), 1, 0);
            }

            return(dieroll);
        }
Example #11
0
 private void UpdateWeaponItemFields()
 {
     if (weaponItem != null && this.IsLoaded)
     {
         if (weaponItem.Step == null)
         {
             DieRoll roll = DieRoll.FromString(weaponItem.Weapon.DmgM);
             roll            = DieRoll.StepDie(roll, ((int)SizeMods.GetSize(monster.Size)) - (int)MonsterSize.Medium);
             weaponItem.Step = roll.Step;
         }
         AttackDamage.Text        = weaponItem.Step.Text;
         AttackName.Text          = weaponItem.Name;
         AttackType.Text          = weaponItem.Weapon.Light ? "Secondary" : "Primary";
         AttackCountComboBox.Text = weaponItem.Count.ToString();
         PlusTextBox.Text         = weaponItem.Plus;
     }
 }
        private void HDButton_Click(object sender, RoutedEventArgs e)
        {
            DieRollEditWindow editWindow = new DieRollEditWindow();

            editWindow.Roll         = DieRoll.FromString(Monster.HD);
            editWindow.HasToughness = _Monster.HasFeat("Toughness");

            editWindow.HPstatmod = (int)(_Monster.Type != "undead" ?
                                         ((((_Monster.Constitution != null)?_Monster.Constitution:10) / 2) - 5) :
                                         ((((_Monster.Charisma != null)?_Monster.Charisma:10) / 2) - 5));
            editWindow.Owner = this;
            editWindow.WindowStartupLocation = WindowStartupLocation.CenterOwner;
            if (editWindow.ShowDialog() == true)
            {
                Monster.HD = "(" + editWindow.Roll.Text + ")";
                Monster.HP = editWindow.Roll.AverageRoll();
            }
        }
Example #13
0
 public Affliction(Affliction a)
 {
     _Name     = a._Name;
     _Type     = a._Type;
     _Cause    = a._Cause;
     _SaveType = a._SaveType;
     _Save     = a._Save;
     if (a._Onset != null)
     {
         _Onset = (DieRoll)a._Onset.Clone();
     }
     _OnsetUnit     = a._OnsetUnit;
     _Immediate     = a._Immediate;
     _Frequency     = a._Frequency;
     _FrequencyUnit = a._FrequencyUnit;
     _Limit         = a._Limit;
     _LimitUnit     = a._LimitUnit;
     _Once          = a._Once;
     if (a._DamageDie != null)
     {
         _DamageDie = (DieRoll)a._DamageDie.Clone();
     }
     _DamageType    = a._DamageType;
     _IsDamageDrain = a.IsDamageDrain;
     if (a._SecondaryDamageDie != null)
     {
         _SecondaryDamageDie = (DieRoll)a._SecondaryDamageDie.Clone();
     }
     _SecondaryDamageType    = a._SecondaryDamageType;
     _IsSecondaryDamageDrain = a._IsSecondaryDamageDrain;
     _DamageExtra            = a._DamageExtra;
     _SpecialEffectName      = a._SpecialEffectName;
     if (a._SpecialEffectTime != null)
     {
         _SpecialEffectTime = (DieRoll)a._SpecialEffectTime.Clone();
     }
     _SpecialEffectUnit = a._SpecialEffectUnit;
     _OtherEffect       = a.OtherEffect;
     _Cure    = a._Cure;
     _Details = a._Details;
     _Cost    = a._Cost;
 }
Example #14
0
        public static DieRoll StepDie(DieRoll roll, int diff)
        {
            DieRoll outRoll = new DieRoll(roll);

            if (diff > 0)
            {
                for (int i = 0; i < diff; i++)
                {
                    outRoll = StepUpDieRoll(outRoll);
                }
            }
            if (diff < 0)
            {
                for (int i = 0; i > diff; i--)
                {
                    outRoll = StepDownDieRoll(outRoll);
                }
            }

            return(outRoll);
        }
Example #15
0
        private static DieRoll StepDownDieRoll(DieRoll roll)
        {
            DieRoll outRoll = roll;

            DieStep step = new DieStep(roll.count, roll.die);

            if (stepDownList.ContainsKey(step))
            {
                step = stepDownList[step];
            }
            else
            {
                if (step.Count > 3)
                {
                    step.Count -= 3;
                }
                else if (step.Count > 1)
                {
                    step.Count -= 1;
                }
                else if (step.Die > 1)
                {
                    {
                        step.Die -= 1;
                    }
                }
                else
                {
                    step.Count = 0;
                    step.Die   = 1;
                }
            }

            outRoll.count = step.Count;
            outRoll.die   = step.Die;

            return(outRoll);
        }
Example #16
0
        public string SizeDamageText(MonsterSize size)
        {
            DieRoll roll = SizeDamageDie(size);

            if (roll == null)
            {
                return("");
            }

            string critText = "";

            if (CritRange != 20)
            {
                critText += "/" + CritRange + "-20";
            }

            if (CritMultiplier != 2)
            {
                critText += "/x" + CritMultiplier;
            }

            return(roll.Text + critText);
        }
Example #17
0
        public NaturalAttackWindow()
        {
            InitializeComponent();

            weaponView         = new ListCollectionView(new List <Weapon>(Weapon.Weapons.Values));
            weaponView.Filter += new Predicate <object>(NaturalWeaponFilter);
            weaponView.SortDescriptions.Add(
                new SortDescription("Name", ListSortDirection.Ascending));
            weaponView.MoveCurrentToFirst();
            weaponView.CurrentChanged     += new EventHandler(weaponView_CurrentChanged);
            NaturalAttackListBox.GotFocus += new RoutedEventHandler(NaturalAttackListBox_GotFocus);

            NaturalAttackListBox.DataContext = weaponView;

            DieRoll step = new DieRoll(0, 1, 0);

            for (int i = 0; i < 12; i++)
            {
                ComboBoxItem item = new ComboBoxItem();

                item.DataContext = step.Step;
                item.Content     = step.Text;
                AttackDamage.Items.Add(item);
                step = DieRoll.StepDie(step, 1);
            }

            for (int i = 1; i < 12; i++)
            {
                ComboBoxItem item = new ComboBoxItem();

                item.DataContext = i;
                item.Content     = i.ToString();
                AttackCountComboBox.Items.Add(item);
            }

            EnableOK();
        }
Example #18
0
        private void OKButton_Click(object sender, RoutedEventArgs e)
        {
            if (weaponItem == null)
            {
                weaponItem = new WeaponItem();
            }
            Weapon weapon  = null;
            string atkname = AttackName.Text.Trim();

            if (Weapon.Weapons.ContainsKey(atkname))
            {
                weapon = Weapon.Weapons[atkname];
            }

            if (weapon == null)
            {
                weapon       = new Weapon();
                weapon.Name  = atkname;
                weapon.Hands = "One-Handed";
                weapon.Class = "Natural";
                DieRoll roll = DieRoll.FromString(AttackDamage.Text);
                roll              = DieRoll.StepDie(roll, ((int)SizeMods.GetSize(monster.Size)) - (int)MonsterSize.Medium);
                weapon.DmgM       = roll.Text;
                weapon.DmgS       = DieRoll.StepDie(roll, -1).Text;
                weaponItem.Weapon = weapon;
            }


            weaponItem.Weapon = weapon;
            weaponItem.Count  = AttackCountComboBox.SelectedIndex + 1;
            weaponItem.Plus   = PlusTextBox.Text;
            weaponItem.Step   = DieRoll.FromString(AttackDamage.Text).Step;

            DialogResult = true;
            Close();
        }
Example #19
0
        //create a blank weapon from an attack
        public Weapon(Attack attack, bool ranged, MonsterSize size)
        {
            _Name = attack.Name;

            DieRoll medRoll = DieRoll.StepDie(attack.Damage, ((int)MonsterSize.Medium) - (int)size);
            DieRoll smRoll  = DieRoll.StepDie(attack.Damage, -1);

            _DmgM = new DieStep(medRoll).ToString();
            _DmgS = new DieStep(smRoll).ToString();

            _CritRange      = attack.CritRange;
            _CritMultiplier = attack.CritMultiplier;

            if (attack.Bonus.Count > 1)
            {
                _Class = "Martial";
            }
            else
            {
                _Class = "Natural";
            }

            if (ranged)
            {
                _Hands = "Ranged";
            }
            else
            {
                _Hands = "One-Handed";
            }

            _RangedTouch    = attack.RangedTouch;
            _AltDamage      = attack.AltDamage;
            _AltDamageStat  = attack.AltDamageStat;
            _AltDamageDrain = attack.AltDamageDrain;
        }
Example #20
0
        public static DieStep StepDie(DieStep step, int diff)
        {
            DieRoll r = new DieRoll(step.Count, step.Die, 0);

            return(StepDie(r, diff).Step);
        }
Example #21
0
 public DieRoll(DieRoll old)
 {
     CopyFrom(old);
 }
 private void OKButton_Click(object sender, System.Windows.RoutedEventArgs e)
 {
     Roll         = MakeRoll();
     DialogResult = true;
     Close();
 }
Example #23
0
        public static DieRoll FromString(string text, int start)
        {
            DieRoll roll = null;

            if (text != null)
            {
                try
                {
                    Regex regRoll = new Regex(DieRollRegexString);

                    Match match = regRoll.Match(text, start);

                    if (match.Success)
                    {
                        roll = new DieRoll();

                        roll.count = int.Parse(match.Groups[1].Value);


                        if (match.Groups[2].Success)
                        {
                            roll.fraction = int.Parse(match.Groups[2].Value.Substring(1));
                        }
                        else
                        {
                            roll.fraction = 1;
                        }

                        roll.die = int.Parse(match.Groups[3].Value);


                        if (roll.die == 0)
                        {
                            throw new FormatException("Invalid Die Roll");
                        }

                        if (match.Groups["extra"].Success)
                        {
                            roll.extraRolls = new List <DieStep>();

                            Regex extraReg = new Regex("([0-9]+)d([0-9]+)");

                            foreach (Match d in extraReg.Matches(match.Groups["extra"].Value))
                            {
                                DieStep step = new DieStep();
                                step.Count = int.Parse(d.Groups[1].Value);
                                step.Die   = int.Parse(d.Groups[2].Value);


                                if (step.Die == 0)
                                {
                                    throw new FormatException("Invalid Die Roll");
                                }

                                roll.extraRolls.Add(step);
                            }
                        }

                        if (match.Groups[7].Success)
                        {
                            roll.mod = int.Parse(match.Groups[7].Value);
                        }
                    }
                }
                catch (FormatException)
                {
                    roll = null;
                }
                catch (OverflowException)
                {
                    roll = null;
                }
            }

            return(roll);
        }
Example #24
0
 public DieStep(DieRoll roll)
 {
     this.Count = roll.count; this.Die = roll.die;
 }
        void RollAlternateInitDiceBox_TextChanged(object sender, TextChangedEventArgs e)
        {
            DieRoll dr = DieRoll.FromString(RollAlternateInitDiceBox.Text);

            OKButton.IsEnabled = (dr != null);
        }