Skip to content

Commit

Permalink
Replace every usage of SkillBase.FindSpell with `SkillBase.GetSpell…
Browse files Browse the repository at this point in the history
…ByID`

* Similar to bdd6b59.
* Avoids slow cloning and iterations.
* Gets rid of the spell line restriction for procs and other effects, which would silently prevent them from working if spell x spell lines associations weren't correct.
  • Loading branch information
bm01 committed Aug 1, 2024
1 parent bdd6b59 commit e2805dc
Show file tree
Hide file tree
Showing 10 changed files with 275 additions and 446 deletions.
138 changes: 56 additions & 82 deletions GameServer/gameobjects/GameInventoryItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -611,34 +611,26 @@ protected virtual void WriteMagicalBonuses(List<string> output, GameClient clien
spellNote = LanguageMgr.GetTranslation(client.Account.Language, "DetailDisplayHandler.WriteMagicalBonuses.StrikeArmor");
}

SpellLine line = SkillBase.GetSpellLine(GlobalSpellsLines.Item_Effects);
if (line != null)
{
Spell procSpell = SkillBase.FindSpell(ProcSpellID, line);
Spell procSpell = SkillBase.GetSpellByID(ProcSpellID);

if (procSpell != null)
if (procSpell != null)
{
ISpellHandler spellHandler = ScriptMgr.CreateSpellHandler(client.Player, procSpell, SkillBase.GetSpellLine(GlobalSpellsLines.Item_Effects));
if (spellHandler != null)
{
ISpellHandler spellHandler = ScriptMgr.CreateSpellHandler(client.Player, procSpell, line);
if (spellHandler != null)
{
output.AddRange(spellHandler.DelveInfo);
output.Add(" ");
}
else
{
output.Add("-" + procSpell.Name + " (Spell Handler Not Implemented)");
}

output.Add(spellNote);
output.AddRange(spellHandler.DelveInfo);
output.Add(" ");
}
else
{
output.Add("- Spell Not Found: " + ProcSpellID);
output.Add("-" + procSpell.Name + " (Spell Handler Not Implemented)");
}

output.Add(spellNote);
}
else
{
output.Add("- Item_Effects Spell Line Missing");
output.Add("- Spell Not Found: " + ProcSpellID);
}

output.Add(" ");
Expand All @@ -658,34 +650,26 @@ protected virtual void WriteMagicalBonuses(List<string> output, GameClient clien
spellNote = LanguageMgr.GetTranslation(client.Account.Language, "DetailDisplayHandler.WriteMagicalBonuses.StrikeArmor");
}

SpellLine line = SkillBase.GetSpellLine(GlobalSpellsLines.Item_Effects);
if (line != null)
{
Spell procSpell = SkillBase.FindSpell(ProcSpellID1, line);
Spell procSpell = SkillBase.GetSpellByID(ProcSpellID1);

if (procSpell != null)
if (procSpell != null)
{
ISpellHandler spellHandler = ScriptMgr.CreateSpellHandler(client.Player, procSpell, SkillBase.GetSpellLine(GlobalSpellsLines.Item_Effects));
if (spellHandler != null)
{
ISpellHandler spellHandler = ScriptMgr.CreateSpellHandler(client.Player, procSpell, line);
if (spellHandler != null)
{
output.AddRange(spellHandler.DelveInfo);
output.Add(" ");
}
else
{
output.Add("-" + procSpell.Name + " (Spell Handler Not Implemented)");
}

output.Add(spellNote);
output.AddRange(spellHandler.DelveInfo);
output.Add(" ");
}
else
{
output.Add("- Spell Not Found: " + ProcSpellID1);
output.Add("-" + procSpell.Name + " (Spell Handler Not Implemented)");
}

output.Add(spellNote);
}
else
{
output.Add("- Item_Effects Spell Line Missing");
output.Add("- Spell Not Found: " + ProcSpellID1);
}

output.Add(" ");
Expand All @@ -694,36 +678,29 @@ protected virtual void WriteMagicalBonuses(List<string> output, GameClient clien
#region Charge1
if (SpellID != 0)
{
SpellLine chargeEffectsLine = SkillBase.GetSpellLine(GlobalSpellsLines.Item_Effects);
if (chargeEffectsLine != null)
Spell spell = SkillBase.GetSpellByID(SpellID);

if (spell != null)
{
Spell spell = SkillBase.FindSpell(SpellID, chargeEffectsLine);
if (spell != null)
{
ISpellHandler spellHandler = ScriptMgr.CreateSpellHandler(client.Player, spell, chargeEffectsLine);
ISpellHandler spellHandler = ScriptMgr.CreateSpellHandler(client.Player, spell, SkillBase.GetSpellLine(GlobalSpellsLines.Item_Effects));

if (spellHandler != null)
if (spellHandler != null)
{
if (MaxCharges > 0)
{
if (MaxCharges > 0)
{
output.Add(LanguageMgr.GetTranslation(client.Account.Language, "DetailDisplayHandler.WriteMagicalBonuses.ChargedMagic"));
output.Add(LanguageMgr.GetTranslation(client.Account.Language, "DetailDisplayHandler.WriteMagicalBonuses.Charges", Charges));
output.Add(LanguageMgr.GetTranslation(client.Account.Language, "DetailDisplayHandler.WriteMagicalBonuses.MaxCharges", MaxCharges));
output.Add(" ");
}

output.AddRange(spellHandler.DelveInfo);
output.Add(LanguageMgr.GetTranslation(client.Account.Language, "DetailDisplayHandler.WriteMagicalBonuses.ChargedMagic"));
output.Add(LanguageMgr.GetTranslation(client.Account.Language, "DetailDisplayHandler.WriteMagicalBonuses.Charges", Charges));
output.Add(LanguageMgr.GetTranslation(client.Account.Language, "DetailDisplayHandler.WriteMagicalBonuses.MaxCharges", MaxCharges));
output.Add(" ");
output.Add("- This spell is cast when the item is used.");
}
else
{
output.Add("- Item_Effects Spell Line Missing");
}

output.AddRange(spellHandler.DelveInfo);
output.Add(" ");
output.Add("- This spell is cast when the item is used.");
}
else
{
output.Add("- Spell Not Found: " + SpellID);
output.Add("- Item_Effects Spell Line Missing");
}
}

Expand All @@ -733,38 +710,35 @@ protected virtual void WriteMagicalBonuses(List<string> output, GameClient clien
#region Charge2
if (SpellID1 != 0)
{
SpellLine chargeEffectsLine = SkillBase.GetSpellLine(GlobalSpellsLines.Item_Effects);
if (chargeEffectsLine != null)
Spell spell = SkillBase.GetSpellByID(SpellID1);

if (spell != null)
{
Spell spell = SkillBase.FindSpell(SpellID1, chargeEffectsLine);
if (spell != null)
{
ISpellHandler spellHandler = ScriptMgr.CreateSpellHandler(client.Player, spell, chargeEffectsLine);
ISpellHandler spellHandler = ScriptMgr.CreateSpellHandler(client.Player, spell, SkillBase.GetSpellLine(GlobalSpellsLines.Item_Effects));

if (spellHandler != null)
if (spellHandler != null)
{
if (MaxCharges > 0)
{
if (MaxCharges > 0)
{
output.Add(LanguageMgr.GetTranslation(client.Account.Language, "DetailDisplayHandler.WriteMagicalBonuses.ChargedMagic"));
output.Add(LanguageMgr.GetTranslation(client.Account.Language, "DetailDisplayHandler.WriteMagicalBonuses.Charges", Charges1));
output.Add(LanguageMgr.GetTranslation(client.Account.Language, "DetailDisplayHandler.WriteMagicalBonuses.MaxCharges", MaxCharges1));
output.Add(" ");
}

output.AddRange(spellHandler.DelveInfo);
output.Add(LanguageMgr.GetTranslation(client.Account.Language, "DetailDisplayHandler.WriteMagicalBonuses.ChargedMagic"));
output.Add(LanguageMgr.GetTranslation(client.Account.Language, "DetailDisplayHandler.WriteMagicalBonuses.Charges", Charges1));
output.Add(LanguageMgr.GetTranslation(client.Account.Language, "DetailDisplayHandler.WriteMagicalBonuses.MaxCharges", MaxCharges1));
output.Add(" ");
output.Add("- This spell is cast when the item is used.");
}
else
{
output.Add("- Item_Effects Spell Line Missing");
}

output.AddRange(spellHandler.DelveInfo);
output.Add(" ");
output.Add("- This spell is cast when the item is used.");
}
else
{
output.Add("- Spell Not Found: " + SpellID1);
output.Add("- Item_Effects Spell Line Missing");
}
}
else
{
output.Add("- Spell Not Found: " + SpellID1);
}

output.Add(" ");
}
Expand Down
33 changes: 13 additions & 20 deletions GameServer/gameobjects/GameLiving.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1051,33 +1051,28 @@ public virtual void CheckWeaponMagicalEffect(AttackData ad, DbInventoryItem weap
//Error protection and log for Item Proc's
Spell procSpell = null;
Spell procSpell1 = null;

if (this is GamePlayer)
{
SpellLine line = SkillBase.GetSpellLine(GlobalSpellsLines.Item_Effects);
if (line != null)
{
procSpell = SkillBase.FindSpell(weapon.ProcSpellID, line);
procSpell1 = SkillBase.FindSpell(weapon.ProcSpellID1, line);
procSpell = SkillBase.GetSpellByID(weapon.ProcSpellID);
procSpell1 = SkillBase.GetSpellByID(weapon.ProcSpellID1);

if (procSpell == null && weapon.ProcSpellID != 0)
{
log.ErrorFormat("- Proc ID {0} Not Found on item: {1} ", weapon.ProcSpellID, weapon.Template.Id_nb);
}
if (procSpell1 == null && weapon.ProcSpellID1 != 0)
{
log.ErrorFormat("- Proc1 ID {0} Not Found on item: {1} ", weapon.ProcSpellID1, weapon.Template.Id_nb);
}
if (procSpell == null && weapon.ProcSpellID != 0)
{
log.ErrorFormat("- Proc ID {0} Not Found on item: {1} ", weapon.ProcSpellID, weapon.Template.Id_nb);
}
if (procSpell1 == null && weapon.ProcSpellID1 != 0)
{
log.ErrorFormat("- Proc1 ID {0} Not Found on item: {1} ", weapon.ProcSpellID1, weapon.Template.Id_nb);
}
}

// Proc #1
if (procSpell != null && Util.Chance(procChance))

StartWeaponMagicalEffect(weapon, ad, SkillBase.GetSpellLine(GlobalSpellsLines.Item_Effects), weapon.ProcSpellID, false);

// Proc #2
if (procSpell1 != null && Util.Chance(procChance))

StartWeaponMagicalEffect(weapon, ad, SkillBase.GetSpellLine(GlobalSpellsLines.Item_Effects), weapon.ProcSpellID1, false);

// Poison
Expand Down Expand Up @@ -1113,17 +1108,15 @@ public virtual void CheckWeaponMagicalEffect(AttackData ad, DbInventoryItem weap
/// </summary>
protected virtual void StartWeaponMagicalEffect(DbInventoryItem weapon, AttackData ad, SpellLine spellLine, int spellID, bool ignoreLevel)
{
if (weapon == null)
if (ad == null || weapon == null)
return;

if (spellLine == null)
{
spellLine = SkillBase.GetSpellLine(GlobalSpellsLines.Item_Effects);
}

if (spellLine != null && ad != null && weapon != null)
if (ad != null)
{
Spell procSpell = SkillBase.FindSpell(spellID, spellLine);
Spell procSpell = SkillBase.GetSpellByID(spellID);

if (procSpell != null)
{
Expand Down
Loading

0 comments on commit e2805dc

Please sign in to comment.