public float GetAbsorbMod(Creature target) { switch (target.CombatMode) { case CombatMode.Melee: // does target have shield equipped? var shield = target.GetEquippedShield(); if (shield != null && shield.AbsorbMagicDamage != null) return GetShieldMod(target, shield); break; case CombatMode.Missile: var weapon = target.GetEquippedMissileWeapon(); if (weapon != null && weapon.AbsorbMagicDamage != null) return AbsorbMagic(target, weapon); break; case CombatMode.Magic: weapon = target.GetEquippedWand(); if (weapon != null && weapon.AbsorbMagicDamage != null) return AbsorbMagic(target, weapon); break; } return 1.0f; }
public uint CalculateManaUsage(Creature caster, Spell spell, WorldObject target = null) { var baseCost = spell.BaseMana; // for casting spells built into a casting implement, use the ItemManaCost var castItem = caster.GetEquippedWand(); if (castItem != null && (castItem.SpellDID ?? 0) == spell.Id) { baseCost = (uint)(castItem.ItemManaCost ?? 0); } uint mana_conversion_skill = caster.GetCreatureSkill(Skill.ManaConversion).Current; uint difficulty = spell.PowerMod; // modified power difficulty double baseManaPercent = 1.0; if (mana_conversion_skill > difficulty) { baseManaPercent = (double)difficulty / mana_conversion_skill; } uint preCost = 0; if ((spell.School == MagicSchool.ItemEnchantment) && (spell.MetaSpellType == SpellType.Enchantment)) { var targetPlayer = target as Player; int numTargetItems = 1; if (targetPlayer != null) { numTargetItems = targetPlayer.EquippedObjects.Count; } preCost = (uint)Math.Round((baseCost + (spell.ManaMod * numTargetItems)) * baseManaPercent); } else { preCost = (uint)Math.Round(baseCost * baseManaPercent); } if (preCost < 1) { preCost = 1; } uint manaUsed = ThreadSafeRandom.Next(1, preCost); return(manaUsed); }
public uint CalculateManaUsage(Creature caster, Spell spell, WorldObject target = null) { var baseCost = spell.BaseMana; // for casting spells built into a casting implement, use the ItemManaCost var castItem = caster.GetEquippedWand(); if (castItem != null && (castItem.SpellDID ?? 0) == spell.Id) { baseCost = (uint)(castItem.ItemManaCost ?? 0); } if ((spell.School == MagicSchool.ItemEnchantment) && (spell.MetaSpellType == SpellType.Enchantment) && (spell.Category >= SpellCategory.ArmorValueRaising) && (spell.Category <= SpellCategory.AcidicResistanceLowering) && target is Player targetPlayer) { var numTargetItems = 1; if (targetPlayer != null) { numTargetItems = targetPlayer.EquippedObjects.Values.Count(i => (i is Clothing || i.IsShield) && i.IsEnchantable); } baseCost += spell.ManaMod * (uint)numTargetItems; } else if ((spell.Flags & SpellFlags.FellowshipSpell) != 0) { var numFellows = 1; if (this is Player player && player.Fellowship != null) { numFellows = player.Fellowship.FellowshipMembers.Count; } baseCost += spell.ManaMod * (uint)numFellows; } var manaConversion = caster.GetCreatureSkill(Skill.ManaConversion); if (manaConversion.AdvancementClass < SkillAdvancementClass.Trained || spell.Flags.HasFlag(SpellFlags.IgnoresManaConversion)) { return(baseCost); } var difficulty = spell.PowerMod; // modified power difficulty var mana_conversion_skill = (uint)Math.Round(manaConversion.Current * GetWeaponManaConversionModifier(caster)); var manaCost = GetManaCost(difficulty, baseCost, mana_conversion_skill); return(manaCost); }
public float GetAbsorbMod(Creature target) { switch (target.CombatMode) { case CombatMode.Melee: // does target have shield equipped? var shield = target.GetEquippedShield(); if (shield != null && shield.AbsorbMagicDamage != null) { return(GetShieldMod(target, shield)); } break; case CombatMode.Missile: var missileLauncherOrShield = target.GetEquippedMissileLauncher() ?? target.GetEquippedShield(); if (missileLauncherOrShield != null && missileLauncherOrShield.AbsorbMagicDamage != null) { return(AbsorbMagic(target, missileLauncherOrShield)); } break; case CombatMode.Magic: var caster = target.GetEquippedWand(); if (caster != null && caster.AbsorbMagicDamage != null) { return(AbsorbMagic(target, caster)); } break; } return(1.0f); }
public uint CalculateManaUsage(Creature caster, Spell spell, WorldObject target = null) { var baseCost = spell.BaseMana; // for casting spells built into a casting implement, use the ItemManaCost var castItem = caster.GetEquippedWand(); if (castItem != null && (castItem.SpellDID ?? 0) == spell.Id) { baseCost = (uint)(castItem.ItemManaCost ?? 0); } uint mana_conversion_skill = (uint)Math.Round(caster.GetCreatureSkill(Skill.ManaConversion).Current *GetWeaponManaConversionModifier(caster)); uint difficulty = spell.PowerMod; // modified power difficulty double baseManaPercent = 1.0; if (mana_conversion_skill > difficulty) { baseManaPercent = (double)difficulty / mana_conversion_skill; } uint preCost = 0; if ((spell.School == MagicSchool.ItemEnchantment) && (spell.MetaSpellType == SpellType.Enchantment) && (spell.Category >= SpellCategory.ArmorValueRaising) && (spell.Category <= SpellCategory.AcidicResistanceLowering) && target is Player targetPlayer) { int numTargetItems = 1; if (targetPlayer != null) { numTargetItems = targetPlayer.EquippedObjects.Values.Count(i => (i is Clothing || i.IsShield) && i.IsEnchantable); } preCost = (uint)Math.Round((baseCost + (spell.ManaMod * numTargetItems)) * baseManaPercent); } else if ((spell.Flags & SpellFlags.FellowshipSpell) != 0) { int numFellows = 1; var player = this as Player; if (player != null && player.Fellowship != null) { numFellows = player.Fellowship.FellowshipMembers.Count; } preCost = (uint)Math.Round((baseCost + (spell.ManaMod * numFellows)) * baseManaPercent); } else { preCost = (uint)Math.Round(baseCost * baseManaPercent); } if (preCost < 1) { preCost = 1; } uint manaUsed = ThreadSafeRandom.Next(1, preCost); return(manaUsed); }