Skip to content

Commit

Permalink
Adding mana usage from casting implement for built-in spells
Browse files Browse the repository at this point in the history
  • Loading branch information
gmriggs committed Jan 4, 2019
1 parent 57c7cd7 commit b726b07
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions Source/ACE.Server/WorldObjects/Player_Magic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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?
Expand All @@ -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);

Expand Down Expand Up @@ -1189,5 +1202,18 @@ public bool HasFoci(MagicSchool school)
var wcid = FociWCIDs[school];
return Inventory.Values.FirstOrDefault(i => i.WeenieClassId == wcid) != null;
}

/// <summary>
/// Returns TRUE if the currently equipped casting implement
/// has a built-in spell
/// </summary>
public bool IsWeaponSpell(Spell spell)
{
var caster = GetEquippedWand();
if (caster == null || caster.SpellDID == null)
return false;

return caster.SpellDID == spell.Id;
}
}
}

0 comments on commit b726b07

Please sign in to comment.