public Spell Clone(Character player, int spellSlotLevel) { Spell result = new Spell(); RecalculateDiceAndAmmo(spellSlotLevel, player.level, player.SpellcastingAbilityModifier); result.BonusPerLevel = BonusPerLevel; result.BonusThreshold = BonusThreshold; result.BonusMax = BonusMax; result.CastingTime = CastingTime; result.Components = Components; result.Description = Description; result.DieStr = DieStr; result.Duration = Duration; result.Level = Level; result.Material = Material; result.Name = Name; result.Index = Index; result.OnCast = OnCast; result.OnValidate = OnValidate; result.OnReceived = OnReceived; result.OnPreparing = OnPreparing; result.OnPreparationComplete = OnPreparationComplete; result.OnTargetFailsSave = OnTargetFailsSave; result.OnGetAttackAbility = OnGetAttackAbility; result.OnDispel = OnDispel; result.OnPlayerPreparesAttack = OnPlayerPreparesAttack; result.OnDieRollStopped = OnDieRollStopped; result.OnPlayerAttacks = OnPlayerAttacks; result.OnPlayerHitsTarget = OnPlayerHitsTarget; result.OriginalDieStr = OriginalDieStr; result.OriginalAmmoCount = OriginalAmmoCount; result.AmmoCount = AmmoCount; result.PerLevelBonus = PerLevelBonus; result.Range = Range; result.RangeType = RangeType; result.RequiresConcentration = RequiresConcentration; result.SavingThrowAbility = SavingThrowAbility; result.AvailableWhen = AvailableWhen; result.SpellCasterLevel = SpellCasterLevel; result.SpellType = SpellType; result.SchoolOfMagic = SchoolOfMagic; result.CastingTimeStr = CastingTimeStr; result.DurationStr = DurationStr; result.RangeStr = RangeStr; result.ComponentsStr = ComponentsStr; result.Bright1 = Bright1; result.Bright2 = Bright2; result.Hue1 = Hue1; result.Hue2 = Hue2; // Override... result.OwnerId = player != null ? player.playerID : -1; result.SpellSlotLevel = spellSlotLevel; result.RecalculateDiceAndAmmo(spellSlotLevel, player.level, player.GetSpellcastingAbilityModifier()); return(result); }
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); }