Exemplo n.º 1
0
        static DiceDto FromRoll(Roll roll, string dieBackColor, string dieFontColor, int creatureId, string playerName)
        {
            // TODO: Set color for creature, set label, set player name.
            DiceDto result = new DiceDto();

            result.DamageType = DndUtils.ToDamage(roll.Descriptor);
            if (IsDamage(result.DamageType))
            {
                result.DieCountsAs = DieCountsAs.damage;
            }
            result.Quantity        = (int)roll.Count;
            result.BackColor       = dieBackColor;
            result.FontColor       = dieFontColor;
            result.Label           = roll.Label;
            result.PlayerName      = playerName;
            result.CreatureId      = creatureId;
            result.Sides           = roll.Sides;
            result.ScoreMultiplier = roll.ScoreMultiplier;


            return(result);
        }
Exemplo n.º 2
0
        string GetDieStr(int spellSlotLevel, int spellCasterLevel, int spellcastingAbilityModifier)
        {
            DieRollDetails details = DieRollDetails.From(OriginalDieStr, spellcastingAbilityModifier);

            string dieStr = details.ToString();

            if (string.IsNullOrWhiteSpace(BonusThreshold))
            {
                return(dieStr);
            }

            if (!GetMultiplier(spellSlotLevel, spellCasterLevel, out double multiplier))
            {
                return(dieStr);
            }

            DieRollDetails bonusDetails = DieRollDetails.From(BonusPerLevel, spellcastingAbilityModifier);

            foreach (Roll bonusRoll in bonusDetails.Rolls)
            {
                Roll matchingRoll = details.GetRoll(bonusRoll.Sides);
                if (matchingRoll == null)
                {
                    details.AddRoll(bonusRoll.ToString());
                }
                else if (multiplier != 0)
                {
                    matchingRoll.Count += (int)Math.Floor(bonusRoll.Count * multiplier);
                    if (BonusMax > 0 && matchingRoll.Count > BonusMax)
                    {
                        matchingRoll.Count = BonusMax;
                    }
                    matchingRoll.Offset += (int)Math.Floor(bonusRoll.Offset * multiplier);
                }
            }

            return(details.ToString());
        }
Exemplo n.º 3
0
        public static Roll From(string dieStr, int spellcastingAbilityModifier = int.MinValue)
        {
            int dPos = dieStr.IndexOf("d");

            if (dPos < 0)
            {
                return(null);
            }
            double count    = 1;
            string countStr = dieStr.Substring(0, dPos);

            if (!string.IsNullOrEmpty(countStr))
            {
                double.TryParse(countStr, out count);
            }

            int    offset    = 0;
            string offsetStr = dieStr.EverythingAfter("+");

            if (!string.IsNullOrWhiteSpace(offsetStr))
            {
                offsetStr = offsetStr.ToLower().Trim();
                if (offsetStr.StartsWith(STR_SpellcastingAbilityModifier))
                {
                    if (spellcastingAbilityModifier == int.MinValue)
                    {
                        offset = 0;
                    }
                    else
                    {
                        offset = spellcastingAbilityModifier;
                    }
                }
                else
                {
                    offset = offsetStr.GetFirstInt();
                }
            }
            string sidesStr = dieStr.Substring(dPos);
            int    sides    = sidesStr.GetFirstInt();

            if (sides == 0)
            {
                return(null);
            }
            string descriptor = dieStr.EverythingAfter("(");

            if (descriptor != null)
            {
                descriptor = descriptor.EverythingBefore(")").Trim();
                descriptor = "(" + descriptor + ")";
            }
            else
            {
                descriptor = string.Empty;
            }

            Roll roll = new Roll();

            roll.Count      = count;
            roll.Sides      = sides;
            roll.Offset     = offset;
            roll.Descriptor = descriptor;

            return(roll);
        }