From b726b07cdf73c7743e637a437f5931c12b697754 Mon Sep 17 00:00:00 2001 From: gmriggs Date: Fri, 4 Jan 2019 13:06:33 -0500 Subject: [PATCH] Adding mana usage from casting implement for built-in spells --- .../ACE.Server/WorldObjects/Player_Magic.cs | 30 +++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/Source/ACE.Server/WorldObjects/Player_Magic.cs b/Source/ACE.Server/WorldObjects/Player_Magic.cs index 4f75367c2f..d8fe814fdc 100644 --- a/Source/ACE.Server/WorldObjects/Player_Magic.cs +++ b/Source/ACE.Server/WorldObjects/Player_Magic.cs @@ -493,6 +493,11 @@ public void CreatePlayerSpell(WorldObject target, TargetCategory targetCategory, else player.IsBusy = true; + // TODO: if casting implement has spell built in, + // use spellcraft from the item, instead of player's magic skill? + var caster = GetEquippedWand(); + var isWeaponSpell = IsWeaponSpell(spell); + // Grab player's skill level in the spell's Magic School var magicSkill = player.GetCreatureSkill(spell.School).Current; @@ -548,7 +553,11 @@ public void CreatePlayerSpell(WorldObject target, TargetCategory targetCategory, // Calculate mana usage uint manaUsed = CalculateManaUsage(player, spell, target); - if (manaUsed > player.Mana.Current) + var currentMana = player.Mana.Current; + if (isWeaponSpell) + currentMana = (uint)(caster.ItemCurMana ?? 0); + + if (manaUsed > currentMana) { player.Session.Network.EnqueueSend(new GameEventUseDone(player.Session, WeenieError.YouDontHaveEnoughManaToCast)); IsBusy = false; // delay? @@ -557,7 +566,11 @@ public void CreatePlayerSpell(WorldObject target, TargetCategory targetCategory, // begin spellcasting Proficiency.OnSuccessUse(player, player.GetCreatureSkill(Skill.ManaConversion), spell.PowerMod); - player.UpdateVitalDelta(player.Mana, -(int)manaUsed); + + if (!isWeaponSpell) + player.UpdateVitalDelta(player.Mana, -(int)manaUsed); + else + caster.ItemCurMana -= (int)manaUsed; spell.Formula.GetPlayerFormula(player); @@ -1189,5 +1202,18 @@ public bool HasFoci(MagicSchool school) var wcid = FociWCIDs[school]; return Inventory.Values.FirstOrDefault(i => i.WeenieClassId == wcid) != null; } + + /// + /// Returns TRUE if the currently equipped casting implement + /// has a built-in spell + /// + public bool IsWeaponSpell(Spell spell) + { + var caster = GetEquippedWand(); + if (caster == null || caster.SpellDID == null) + return false; + + return caster.SpellDID == spell.Id; + } } }