Example #1
0
 public SpellModel(SpellInfo spellInfo, SpellDuration spellDuration, SpellCasting spellCasting, SpellAscension spellAscension, SpellComponents spellComponents)
 {
     SpellInfo       = spellInfo;
     SpellDuration   = spellDuration;
     SpellCasting    = spellCasting;
     SpellAscension  = spellAscension;
     SpellComponents = spellComponents;
 }
Example #2
0
        public static JsonSpellComponents FromXml(SpellComponents components)
        {
            if (components == null)
            {
                return(null);
            }

            return(new JsonSpellComponents
            {
                Kinds = components.Kinds.ToFlagsArray(),
                Description = components.Description.EmptyAsNull()
            });
        }
Example #3
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);
        }
        /// <summary>
        /// Gets the trait which is added to a spell when the spell has this spell component.
        /// </summary>
        /// <param name="spellComponent">The spell component.</param>
        /// <returns>The <see cref="Trait"/> associated with the spell component.</returns>
        public static Trait GetAssociatedTrait(this SpellComponents spellComponent)
        {
            switch (spellComponent)
            {
            case SpellComponents.Focus:
            case SpellComponents.Material:
            case SpellComponents.Somatic:
                return(Trait.Manipulate);

            case SpellComponents.Verbal:
                return(Trait.Concentrate);

            default:
                throw new InvalidEnumArgumentException(nameof(spellComponent), (int)spellComponent, spellComponent.GetType());
            }
        }
Example #5
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);
        }
Example #6
0
        private Spell MapValues(Spell spell, string userId)
        {
            CastingTime time = _ctx.CastingTimes.FirstOrDefault(c => c.Amount == spell.CastingTime.Amount && c.Unit == spell.CastingTime.Unit && c.ReactionCondition == spell.CastingTime.ReactionCondition && c.Type == (int)spell.CastingTime.Type);

            if (time != null)
            {
                spell.CastingTime   = time;
                spell.CastingTimeID = time.ID;
            }

            SpellComponents components = _ctx.SpellComponents.FirstOrDefault(c => c.Somatic == spell.SpellComponents.Somatic && c.Verbal == spell.SpellComponents.Verbal && spell.SpellComponents.Material == c.Material);

            if (components != null)
            {
                spell.SpellComponents   = components;
                spell.SpellComponentsID = components.ID;
            }

            SpellDuration duration = _ctx.SpellDurations.FirstOrDefault(d => d.Amount == spell.SpellDuration.Amount && d.Concentration == spell.SpellDuration.Concentration && d.Type == spell.SpellDuration.Type && d.Unit == spell.SpellDuration.Unit && d.UpTo == spell.SpellDuration.UpTo);

            if (duration != null)
            {
                spell.SpellDuration   = duration;
                spell.SpellDurationID = duration.ID;
            }

            SpellRange range = _ctx.SpellRanges.FirstOrDefault(r => r.Amount == spell.SpellRange.Amount && r.Type == spell.SpellRange.Type && r.Shape == spell.SpellRange.Shape && r.Unit == spell.SpellRange.Unit);

            if (range != null)
            {
                spell.SpellRange   = range;
                spell.SpellRangeID = range.ID;
            }

            spell.Campaign   = _ctx.Campaigns.Where(c => c.ID == spell.CampaignID && c.AppUserId == userId).Single();
            spell.CampaignID = spell.Campaign.ID;

            return(spell);
        }
Example #7
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);
        }
Example #8
0
 internal void GetComponentLevels()
 {
     SpellComponents.Clear();
     for (int i = 0; i < Machine.Core.Filter <FileService>().ComponentTable.Length; i++)
     {
         using (WorldObjectCollection collection = Machine.Core.WorldFilter.GetInventory())
         {
             collection.SetFilter(new ByNameFilter(Machine.Core.Filter <FileService>().ComponentTable[i].Name));
             if (collection.Quantity > 0)
             {
                 if (SpellComponents.ContainsKey(Machine.Core.Filter <FileService>().ComponentTable[i].Name))
                 {
                     SpellComponents[Machine.Core.Filter <FileService>().ComponentTable[i].Name] = collection.Quantity;
                 }
                 else if (!SpellComponents.ContainsKey(Machine.Core.Filter <FileService>().ComponentTable[i].Name))
                 {
                     SpellComponents.Add(Machine.Core.Filter <FileService>().ComponentTable[i].Name, collection.Quantity);
                 }
             }
         }
     }
     CheckComponentThresholds();
 }
Example #9
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);
        }
Example #10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MagicMissile"/> class.
 /// </summary>
 /// <param name="metadata">Metadata for <see cref="MagicMissile"/>.</param>
 public MagicMissile(IRulesElementMetadata metadata)
     : base(metadata, Trait.Evocation)
 {
     Components = new SpellComponents[] { SpellComponents.Somatic, SpellComponents.Verbal };
     Traits     = new Trait[] { Trait.Force, Trait.Arcane, Trait.Occult };
 }