示例#1
0
        static SpellRangeType GetRangeType(SpellDto spellDto)
        {
            string range = spellDto.range.ToLower();

            if (range == "touch")
            {
                return(SpellRangeType.Touch);
            }
            if (range == "special")
            {
                return(SpellRangeType.Special);
            }
            if (range == "sight")
            {
                return(SpellRangeType.Sight);
            }
            if (range == "unlimited")
            {
                return(SpellRangeType.Unlimited);
            }

            if (range.IndexOf("self") >= 0)
            {
                if (range.IndexOf("cone") >= 0)
                {
                    return(SpellRangeType.SelfPlusCone);
                }
                if (range.IndexOf("line") >= 0)
                {
                    return(SpellRangeType.SelfPlusFeetLine);
                }
                if (range.IndexOf("cube") >= 0)
                {
                    return(SpellRangeType.SelfPlusCube);
                }
                if (range.IndexOf("sphere") >= 0)
                {
                    return(SpellRangeType.SelfPlusSphereRadius);
                }
                if (range.IndexOf("radius") >= 0)
                {
                    return(SpellRangeType.SelfPlusFlatRadius);
                }

                return(SpellRangeType.Self);
            }

            if (range.IndexOf("mile") >= 0)
            {
                return(SpellRangeType.DistanceMiles);
            }


            if (range.IndexOf("feet") >= 0 || range.IndexOf("foot") >= 0)
            {
                return(SpellRangeType.DistanceFeet);
            }

            throw new NotImplementedException();
        }
示例#2
0
        static Ability GetSavingThrowAbility(SpellDto spellDto)
        {
            string savingThrow = spellDto.saving_throw.ToLower();

            if (string.IsNullOrWhiteSpace(savingThrow))
            {
                return(Ability.none);
            }
            if (savingThrow == "strength")
            {
                return(Ability.strength);
            }
            if (savingThrow == "charisma")
            {
                return(Ability.charisma);
            }
            if (savingThrow == "constitution")
            {
                return(Ability.constitution);
            }
            if (savingThrow == "dexterity")
            {
                return(Ability.dexterity);
            }
            if (savingThrow == "intelligence")
            {
                return(Ability.intelligence);
            }
            if (savingThrow == "wisdom")
            {
                return(Ability.wisdom);
            }
            return(Ability.none);
        }
示例#3
0
        public static Spell Get(string spellName, int spellSlotLevel = -1, int spellCasterLevel = 0, int spellcastingAbilityModifier = int.MinValue)
        {
            SpellDto spell = Spells.FirstOrDefault(x => string.Compare(x.name, spellName, true) == 0);

            if (spell != null)
            {
                return(Spell.FromDto(spell, spellSlotLevel, spellCasterLevel, spellcastingAbilityModifier));
            }
            return(null);
        }
示例#4
0
        public static Spell Get(string spellName, int spellSlotLevel = -1, int spellCasterLevel = 0, int spellcastingAbilityModifier = int.MinValue)
        {
            if (string.IsNullOrEmpty(spellName))
            {
                return(null);
            }
            SpellDto spell = GetDto(spellName);

            return(Spell.FromDto(spell, spellSlotLevel, spellCasterLevel, spellcastingAbilityModifier));
        }
示例#5
0
        private static SpellType GetSpellType(SpellDto spellDto)
        {
            if (!string.IsNullOrWhiteSpace(spellDto.attack_type))
            {
                string attackType = spellDto.attack_type.ToLower();
                if (attackType.IndexOf("melee") >= 0)
                {
                    return(SpellType.MeleeSpell);
                }
                if (attackType.IndexOf("ranged") >= 0)
                {
                    return(SpellType.RangedSpell);
                }
                if (attackType.IndexOf("damage") >= 0)
                {
                    return(SpellType.DamageSpell);
                }
            }

            if (!string.IsNullOrWhiteSpace(spellDto.saving_throw))              // Some spells, like Ice Knife, can be both a saving throw and a ranged attack.
            // TODO: Remove enum element SpellType.SavingThrowSpell and make it a boolean property of Spell.
            {
                return(SpellType.SavingThrowSpell);
            }

            string dieStr = spellDto.die_str.ToLower();

            if (!string.IsNullOrWhiteSpace(dieStr))
            {
                if (dieStr.StartsWith("^"))
                {
                    return(SpellType.StartNextTurnSpell);
                }
                if (dieStr.StartsWith("+"))
                {
                    return(SpellType.HitBonusSpell);
                }
                if (dieStr.IndexOf("healing") >= 0)
                {
                    return(SpellType.HealingSpell);
                }
                if (dieStr.IndexOf("hpcapacity") >= 0)
                {
                    return(SpellType.HpCapacitySpell);
                }
                return(SpellType.DamageSpell);
            }

            return(SpellType.OtherSpell);
        }
示例#6
0
        public static Spell FromDto(SpellDto spellDto, int spellSlotLevel, int spellCasterLevel, int spellcastingAbilityModifier)
        {
            SpellComponents spellComponents = GetSpellComponents(spellDto);

            const string concentrationHeader = "Concentration, ";
            string       spellDuration       = spellDto.duration;

            if (spellDuration.StartsWith(concentrationHeader))
            {
                spellDuration = spellDuration.Substring(concentrationHeader.Length).Trim();
            }

            int   spellLevel = GetLevel(spellDto.level);
            Spell spell      = new Spell()
            {
                CastingTime           = GetCastingTime(spellDto.casting_time),
                Components            = spellComponents,
                Description           = spellDto.description,
                Duration              = DndTimeSpan.FromDurationStr(spellDuration),
                Material              = spellDto.components_materials_description,
                Level                 = spellLevel,
                Name                  = spellDto.name,
                RangeType             = GetRangeType(spellDto),
                SpellType             = GetSpellType(spellDto),
                SavingThrowAbility    = GetSavingThrowAbility(spellDto),
                RequiresConcentration = GetRequiresConcentration(spellDto),
                BonusThreshold        = spellDto.bonus_threshold,
                OriginalDieStr        = spellDto.die_str,
                BonusPerLevel         = spellDto.bonus_per_level,
                PerLevelBonus         = spellDto.bonus_per_level.GetFirstDouble(),
                SpellCasterLevel      = spellCasterLevel,
                SpellSlotLevel        = spellSlotLevel >= 0 ? spellSlotLevel: spellLevel,
                OnCast                = spellDto.onCast,
                OnCasting             = spellDto.onCasting,
                OnPlayerAttacks       = spellDto.onPlayerAttacks,
                OnPlayerHitsTarget    = spellDto.onPlayerHitsTarget,
                OnDispel              = spellDto.onDispel,
                Hue1                  = spellDto.hue1,
                Bright1               = spellDto.bright1,
                Hue2                  = spellDto.hue2,
                Bright2               = spellDto.bright2,
                CastWith              = spellDto.cast_with,
                AvailableWhen         = spellDto.availableWhen
            };

            spell.RecalculateDieStr(spell.SpellSlotLevel, spellCasterLevel, spellcastingAbilityModifier);
            spell.Range = GetRange(spellDto, spell.RangeType);
            return(spell);
        }
示例#7
0
 static int GetRange(SpellDto spellDto, SpellRangeType rangeType)
 {
     switch (rangeType)
     {
     case SpellRangeType.DistanceFeet:
     case SpellRangeType.SelfPlusFeetLine:
     case SpellRangeType.DistanceMiles:
     case SpellRangeType.SelfPlusFlatRadius:
     case SpellRangeType.SelfPlusSphereRadius:
     case SpellRangeType.SelfPlusCone:
     case SpellRangeType.SelfPlusCube:
         return(spellDto.range.GetFirstInt());
     }
     return(0);
 }
示例#8
0
        private static SpellType GetSpellType(SpellDto spellDto)
        {
            if (!string.IsNullOrWhiteSpace(spellDto.saving_throw))
            {
                return(SpellType.SavingThrowSpell);
            }
            if (!string.IsNullOrWhiteSpace(spellDto.attack_type))
            {
                string attackType = spellDto.attack_type.ToLower();
                if (attackType.IndexOf("melee") >= 0)
                {
                    return(SpellType.MeleeSpell);
                }
                if (attackType.IndexOf("ranged") >= 0)
                {
                    return(SpellType.RangedSpell);
                }
                if (attackType.IndexOf("damage") >= 0)
                {
                    return(SpellType.DamageSpell);
                }
            }

            string dieStr = spellDto.die_str.ToLower();

            if (!string.IsNullOrWhiteSpace(dieStr))
            {
                if (dieStr.StartsWith("^"))
                {
                    return(SpellType.StartNextTurnSpell);
                }
                if (dieStr.StartsWith("+"))
                {
                    return(SpellType.HitBonusSpell);
                }
                if (dieStr.IndexOf("healing") >= 0)
                {
                    return(SpellType.HealingSpell);
                }
                if (dieStr.IndexOf("hpcapacity") >= 0)
                {
                    return(SpellType.HpCapacitySpell);
                }
                return(SpellType.DamageSpell);
            }

            return(SpellType.OtherSpell);
        }
示例#9
0
        private static SpellComponents GetSpellComponents(SpellDto spellDto)
        {
            SpellComponents spellComponents = SpellComponents.None;

            if (spellDto.components_material)
            {
                spellComponents |= SpellComponents.Material;
            }
            if (spellDto.components_somatic)
            {
                spellComponents |= SpellComponents.Somatic;
            }
            if (spellDto.components_verbal)
            {
                spellComponents |= SpellComponents.Verbal;
            }
            return(spellComponents);
        }
示例#10
0
        static string GetComponentsStr(SpellComponents spellComponents, SpellDto spellDto)
        {
            string result = "";

            if ((spellComponents & SpellComponents.Verbal) == SpellComponents.Verbal)
            {
                result += "V, ";
            }
            if ((spellComponents & SpellComponents.Somatic) == SpellComponents.Somatic)
            {
                result += "S, ";
            }
            if ((spellComponents & SpellComponents.Material) == SpellComponents.Material)
            {
                result += $"M ";
                if (!string.IsNullOrWhiteSpace(spellDto.components_materials_description))
                {
                    result += $"({spellDto.components_materials_description})";
                }
            }
            result = result.Trim(new char[] { ' ', ',' });
            return(result);
        }
示例#11
0
 static string GetCastingTimeStr(SpellDto spellDto)
 {
     return(spellDto.casting_time);
 }
示例#12
0
 static string GetDurationStr(SpellDto spellDto)
 {
     return(spellDto.duration);
 }
示例#13
0
 static string GetRangeStr(SpellDto spellDto)
 {
     return(spellDto.range);
 }
示例#14
0
        public static Spell FromDto(SpellDto spellDto, int spellSlotLevel, int spellCasterLevel, int spellcastingAbilityModifier)
        {
            if (spellDto == null)
            {
                return(null);
            }

            SpellComponents spellComponents = GetSpellComponents(spellDto);

            const string concentrationHeader = "Concentration, ";
            string       spellDuration       = spellDto.duration;

            if (spellDuration.StartsWith(concentrationHeader))
            {
                spellDuration = spellDuration.Substring(concentrationHeader.Length).Trim();
            }

            int   spellLevel = GetLevel(spellDto.level);
            Spell spell      = new Spell()
            {
                CastingTime            = GetCastingTime(spellDto.casting_time),
                Components             = spellComponents,
                Description            = spellDto.description,
                Duration               = DndTimeSpan.FromDurationStr(spellDuration),
                Material               = spellDto.components_materials_description,
                Level                  = spellLevel,
                Name                   = spellDto.name,
                Index                  = spellDto.index,
                RangeType              = GetRangeType(spellDto),
                SpellType              = GetSpellType(spellDto),
                SavingThrowAbility     = GetSavingThrowAbility(spellDto),
                RequiresConcentration  = GetRequiresConcentration(spellDto),
                BonusThreshold         = spellDto.bonus_threshold,
                BonusMax               = MathUtils.GetInt(spellDto.bonus_max),
                OriginalDieStr         = spellDto.die_str,
                BonusPerLevel          = spellDto.bonus_per_level,
                PerLevelBonus          = spellDto.bonus_per_level.GetFirstDouble(),
                SpellCasterLevel       = spellCasterLevel,
                SpellSlotLevel         = spellSlotLevel >= 0 ? spellSlotLevel : spellLevel,
                OnCast                 = spellDto.onCast,
                OnValidate             = spellDto.onValidate,
                OnReceived             = spellDto.onReceived,
                OnPreparing            = spellDto.onPreparing,
                OnPreparationComplete  = spellDto.onPreparationComplete,
                OnTargetFailsSave      = spellDto.onTargetFailsSave,
                OnTargetSaves          = spellDto.onTargetSaves,
                OnGetAttackAbility     = spellDto.onGetAttackAbility,
                OnPlayerPreparesAttack = spellDto.onPlayerPreparesAttack,
                OnDieRollStopped       = spellDto.onDieRollStopped,
                OnPlayerAttacks        = spellDto.onPlayerAttacks,
                OnPlayerHitsTarget     = spellDto.onPlayerHitsTarget,
                OnDispel               = spellDto.onDispel,
                Hue1                   = spellDto.hue1,
                Bright1                = spellDto.bright1,
                RangeStr               = GetRangeStr(spellDto),
                ComponentsStr          = GetComponentsStr(spellComponents, spellDto),
                DurationStr            = GetDurationStr(spellDto),
                SchoolOfMagic          = DndUtils.ToSchoolOfMagic(spellDto.school),
                CastingTimeStr         = GetCastingTimeStr(spellDto),
                Hue2                   = spellDto.hue2,
                Bright2                = spellDto.bright2,
                CastWith               = spellDto.cast_with,
                AvailableWhen          = spellDto.availableWhen
            };

            if (spell.SpellSlotLevel < spellLevel)
            {
                spell.SpellSlotLevel = spellLevel;
            }

            spell.OriginalAmmoCount = spellDto.ammo_count;             // Must be set before calculating dice and ammo.
            spell.RecalculateDiceAndAmmo(spell.SpellSlotLevel, spellCasterLevel, spellcastingAbilityModifier);
            spell.Range = GetRange(spellDto, spell.RangeType);
            return(spell);
        }
示例#15
0
 static bool GetRequiresConcentration(SpellDto spellDto)
 {
     return(spellDto.duration.StartsWith("Concentration"));
 }