From e2805dca84b7debf925ec2adbc7fd99183d52c53 Mon Sep 17 00:00:00 2001 From: Baptiste Marie Date: Thu, 1 Aug 2024 14:45:16 +0200 Subject: [PATCH] Replace every usage of `SkillBase.FindSpell` with `SkillBase.GetSpellByID` * 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. --- GameServer/gameobjects/GameInventoryItem.cs | 138 +++++-------- GameServer/gameobjects/GameLiving.cs | 33 ++- GameServer/gameobjects/GamePlayer.cs | 192 ++++++++---------- GameServer/gameutils/SkillBase.cs | 27 --- .../Client/168/DetailDisplayHandler.cs | 142 ++++++------- GameServer/packets/Server/PacketLib1109.cs | 53 ++--- GameServer/packets/Server/PacketLib182.cs | 53 ++--- GameServer/packets/Server/PacketLib189.cs | 53 ++--- GameServer/spells/AllRegenBuff.cs | 15 +- GameServer/spells/AllStatsBuff.cs | 15 +- 10 files changed, 275 insertions(+), 446 deletions(-) diff --git a/GameServer/gameobjects/GameInventoryItem.cs b/GameServer/gameobjects/GameInventoryItem.cs index c579628a27..a947182701 100644 --- a/GameServer/gameobjects/GameInventoryItem.cs +++ b/GameServer/gameobjects/GameInventoryItem.cs @@ -611,34 +611,26 @@ protected virtual void WriteMagicalBonuses(List 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(" "); @@ -658,34 +650,26 @@ protected virtual void WriteMagicalBonuses(List 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(" "); @@ -694,36 +678,29 @@ protected virtual void WriteMagicalBonuses(List 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"); } } @@ -733,38 +710,35 @@ protected virtual void WriteMagicalBonuses(List 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(" "); } diff --git a/GameServer/gameobjects/GameLiving.cs b/GameServer/gameobjects/GameLiving.cs index 86942c8908..3056252e88 100644 --- a/GameServer/gameobjects/GameLiving.cs +++ b/GameServer/gameobjects/GameLiving.cs @@ -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 @@ -1113,17 +1108,15 @@ public virtual void CheckWeaponMagicalEffect(AttackData ad, DbInventoryItem weap /// 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) { diff --git a/GameServer/gameobjects/GamePlayer.cs b/GameServer/gameobjects/GamePlayer.cs index aa18455b1e..6030441a7a 100644 --- a/GameServer/gameobjects/GamePlayer.cs +++ b/GameServer/gameobjects/GamePlayer.cs @@ -2008,26 +2008,27 @@ public virtual void OnRevive(DOLEvent e, object sender, EventArgs args) if (player.IsUnderwater && player.CanBreathUnderWater == false) player.UpdateWaterBreathState(eWaterBreath.Holding); + //We need two different sickness spells because RvR sickness is not curable by Healer NPC -Unty if (applyRezSick) + { switch (DeathType) { case eDeathType.RvR: - SpellLine rvrsick = SkillBase.GetSpellLine(GlobalSpellsLines.Realm_Spells); - if (rvrsick == null) return; - Spell rvrillness = SkillBase.FindSpell(8181, rvrsick); - //player.CastSpell(rvrillness, rvrsick); - CastSpell(rvrillness, rvrsick); + { + Spell rvrIllness = SkillBase.GetSpellByID(8181); + CastSpell(rvrIllness, SkillBase.GetSpellLine(GlobalSpellsLines.Realm_Spells)); break; + } case eDeathType.PvP: //PvP sickness is the same as PvE sickness - Curable case eDeathType.PvE: - SpellLine pvesick = SkillBase.GetSpellLine(GlobalSpellsLines.Realm_Spells); - if (pvesick == null) return; - Spell pveillness = SkillBase.FindSpell(2435, pvesick); - //player.CastSpell(pveillness, pvesick); - CastSpell(pveillness, pvesick); + { + Spell pveIllness = SkillBase.GetSpellByID(2435); + CastSpell(pveIllness, SkillBase.GetSpellLine(GlobalSpellsLines.Realm_Spells)); break; + } } + } GameEventMgr.RemoveHandler(this, GamePlayerEvent.Revive, new DOLEventHandler(OnRevive)); m_deathtype = eDeathType.None; @@ -6221,44 +6222,41 @@ protected virtual void TryReactiveEffect(DbInventoryItem reactiveItem, GameLivin if (requiredLevel <= Level) { - SpellLine reactiveEffectLine = SkillBase.GetSpellLine(GlobalSpellsLines.Item_Effects); + SpellLine reactiveEffectLine = SkillBase.GetSpellLine(GlobalSpellsLines.Item_Effects); - if (reactiveEffectLine != null) + if (reactiveItem.ProcSpellID != 0) { - if (reactiveItem.ProcSpellID != 0) + Spell spell = SkillBase.GetSpellByID(reactiveItem.ProcSpellID); + + if (spell != null) { - Spell spell = SkillBase.FindSpell(reactiveItem.ProcSpellID, reactiveEffectLine); + int chance = reactiveItem.ProcChance > 0 ? reactiveItem.ProcChance : 10; - if (spell != null) + if (Util.Chance(chance)) { - int chance = reactiveItem.ProcChance > 0 ? reactiveItem.ProcChance : 10; - - if (Util.Chance(chance)) + ISpellHandler spellHandler = ScriptMgr.CreateSpellHandler(this, spell, reactiveEffectLine); + if (spellHandler != null) { - ISpellHandler spellHandler = ScriptMgr.CreateSpellHandler(this, spell, reactiveEffectLine); - if (spellHandler != null) - { - spellHandler.StartSpell(target, reactiveItem); - } + spellHandler.StartSpell(target, reactiveItem); } } } + } + + if (reactiveItem.ProcSpellID1 != 0) + { + Spell spell = SkillBase.GetSpellByID(reactiveItem.ProcSpellID1); - if (reactiveItem.ProcSpellID1 != 0) + if (spell != null) { - Spell spell = SkillBase.FindSpell(reactiveItem.ProcSpellID1, reactiveEffectLine); + int chance = reactiveItem.ProcChance > 0 ? reactiveItem.ProcChance : 10; - if (spell != null) + if (Util.Chance(chance)) { - int chance = reactiveItem.ProcChance > 0 ? reactiveItem.ProcChance : 10; - - if (Util.Chance(chance)) + ISpellHandler spellHandler = ScriptMgr.CreateSpellHandler(this, spell, reactiveEffectLine); + if (spellHandler != null) { - ISpellHandler spellHandler = ScriptMgr.CreateSpellHandler(this, spell, reactiveEffectLine); - if (spellHandler != null) - { - spellHandler.StartSpell(target, reactiveItem); - } + spellHandler.StartSpell(target, reactiveItem); } } } @@ -7847,7 +7845,7 @@ public virtual void UseSlot(int slot, int type) if (useItem.Item_Type == 41) potionEffectLine = SkillBase.GetSpellLine(GlobalSpellsLines.Item_Effects); - Spell spell = SkillBase.FindSpell(useItem.SpellID, potionEffectLine); + Spell spell = SkillBase.GetSpellByID(useItem.SpellID); if (spell != null) { @@ -7859,86 +7857,81 @@ public virtual void UseSlot(int slot, int type) Out.SendMessage(LanguageMgr.GetTranslation(Client.Account.Language, "GamePlayer.UseSlot.MustWaitBeforeUse", (nextPotionAvailTime - CurrentRegion.Time) / 1000), eChatType.CT_System, eChatLoc.CL_SystemWindow); else { - if (potionEffectLine != null) - { - int requiredLevel = useItem.Template.LevelRequirement > 0 ? useItem.Template.LevelRequirement : Math.Min(MaxLevel, useItem.Level); + int requiredLevel = useItem.Template.LevelRequirement > 0 ? useItem.Template.LevelRequirement : Math.Min(MaxLevel, useItem.Level); - if (requiredLevel <= Level) + if (requiredLevel <= Level) + { + if (spell.CastTime > 0 && attackComponent.AttackState) + Out.SendMessage(LanguageMgr.GetTranslation(Client.Account.Language, "GamePlayer.UseSlot.CantUseInCombat"), eChatType.CT_System, eChatLoc.CL_SystemWindow); + else if ((IsStunned && !(Steed != null && Steed.Name == "Forceful Zephyr")) || IsMezzed || !IsAlive) + Out.SendMessage(LanguageMgr.GetTranslation(Client.Account.Language, "GamePlayer.UseSlot.CantUseState", useItem.GetName(0, false)), eChatType.CT_System, eChatLoc.CL_SystemWindow); + else if (spell.CastTime > 0 && IsCasting) + Out.SendMessage(LanguageMgr.GetTranslation(Client.Account.Language, "GamePlayer.UseSlot.CantUseCast", useItem.GetName(0, false)), eChatType.CT_System, eChatLoc.CL_SystemWindow); + else { - if (spell.CastTime > 0 && attackComponent.AttackState) - Out.SendMessage(LanguageMgr.GetTranslation(Client.Account.Language, "GamePlayer.UseSlot.CantUseInCombat"), eChatType.CT_System, eChatLoc.CL_SystemWindow); - else if ((IsStunned && !(Steed != null && Steed.Name == "Forceful Zephyr")) || IsMezzed || !IsAlive) - Out.SendMessage(LanguageMgr.GetTranslation(Client.Account.Language, "GamePlayer.UseSlot.CantUseState", useItem.GetName(0, false)), eChatType.CT_System, eChatLoc.CL_SystemWindow); - else if (spell.CastTime > 0 && IsCasting) - Out.SendMessage(LanguageMgr.GetTranslation(Client.Account.Language, "GamePlayer.UseSlot.CantUseCast", useItem.GetName(0, false)), eChatType.CT_System, eChatLoc.CL_SystemWindow); - else + if (ScriptMgr.CreateSpellHandler(this, spell, potionEffectLine) is SpellHandler spellHandler) { - if (ScriptMgr.CreateSpellHandler(this, spell, potionEffectLine) is SpellHandler spellHandler) - { - GameLiving target = TargetObject as GameLiving; + GameLiving target = TargetObject as GameLiving; - if (spellHandler is AllStatsBarrel) - target = this; + if (spellHandler is AllStatsBarrel) + target = this; - if (spellHandler is AllRegenBuff) - target = this; - - if (spell.Target == eSpellTarget.ENEMY) - { - if (!GameServer.ServerRules.IsAllowedToAttack(this, target, true)) - { - Out.SendMessage("You need a target for this ability!", eChatType.CT_System, eChatLoc.CL_SystemWindow); - return; - } - } + if (spellHandler is AllRegenBuff) + target = this; - if (spell.IsHealing && spell.CastTime == 0 && IsAttacking) + if (spell.Target == eSpellTarget.ENEMY) + { + if (!GameServer.ServerRules.IsAllowedToAttack(this, target, true)) { - Out.SendMessage(LanguageMgr.GetTranslation(Client.Account.Language, "GamePlayer.UseSlot.CantUseAttacking", useItem.GetName(0, false)), eChatType.CT_System, eChatLoc.CL_SystemWindow); + Out.SendMessage("You need a target for this ability!", eChatType.CT_System, eChatLoc.CL_SystemWindow); return; } + } - Stealth(false); + if (spell.IsHealing && spell.CastTime == 0 && IsAttacking) + { + Out.SendMessage(LanguageMgr.GetTranslation(Client.Account.Language, "GamePlayer.UseSlot.CantUseAttacking", useItem.GetName(0, false)), eChatType.CT_System, eChatLoc.CL_SystemWindow); + return; + } - if (useItem.Item_Type == (int) eInventorySlot.FirstBackpack) - { - Emote(eEmote.Drink); + Stealth(false); - if (spell.CastTime > 0) - TempProperties.SetProperty(NEXT_SPELL_AVAIL_TIME_BECAUSE_USE_POTION, 6 * 1000 + CurrentRegion.Time); - } + if (useItem.Item_Type == (int) eInventorySlot.FirstBackpack) + { + Emote(eEmote.Drink); - if (spellHandler.StartSpell(target, useItem)) + if (spell.CastTime > 0) + TempProperties.SetProperty(NEXT_SPELL_AVAIL_TIME_BECAUSE_USE_POTION, 6 * 1000 + CurrentRegion.Time); + } + + if (spellHandler.StartSpell(target, useItem)) + { + if (useItem.Count > 1) { - if (useItem.Count > 1) + Inventory.RemoveCountFromStack(useItem, 1); + InventoryLogging.LogInventoryAction(this, "(potion)", eInventoryActionType.Other, useItem.Template); + } + else + { + useItem.Charges--; + + if (useItem.Charges < 1) { Inventory.RemoveCountFromStack(useItem, 1); InventoryLogging.LogInventoryAction(this, "(potion)", eInventoryActionType.Other, useItem.Template); } - else - { - useItem.Charges--; - - if (useItem.Charges < 1) - { - Inventory.RemoveCountFromStack(useItem, 1); - InventoryLogging.LogInventoryAction(this, "(potion)", eInventoryActionType.Other, useItem.Template); - } - } - - Out.SendMessage(LanguageMgr.GetTranslation(Client.Account.Language, "GamePlayer.UseSlot.Used", useItem.GetName(0, false)), eChatType.CT_System, eChatLoc.CL_SystemWindow); - TempProperties.SetProperty($"{NEXT_POTION_AVAIL_TIME}_Type{spell.SharedTimerGroup}", useItem.CanUseEvery * 1000 + CurrentRegion.Time); } + + Out.SendMessage(LanguageMgr.GetTranslation(Client.Account.Language, "GamePlayer.UseSlot.Used", useItem.GetName(0, false)), eChatType.CT_System, eChatLoc.CL_SystemWindow); + TempProperties.SetProperty($"{NEXT_POTION_AVAIL_TIME}_Type{spell.SharedTimerGroup}", useItem.CanUseEvery * 1000 + CurrentRegion.Time); } - else - Out.SendMessage($"Potion effect ID {spell.ID} is not implemented yet.", eChatType.CT_System, eChatLoc.CL_SystemWindow); } + else + Out.SendMessage($"Potion effect ID {spell.ID} is not implemented yet.", eChatType.CT_System, eChatLoc.CL_SystemWindow); } - else - Out.SendMessage(LanguageMgr.GetTranslation(Client.Account.Language, "GamePlayer.UseSlot.NotEnouthPower"), eChatType.CT_System, eChatLoc.CL_SystemWindow); } else - Out.SendMessage("Potion effect line not found", eChatType.CT_System, eChatLoc.CL_SystemWindow); + Out.SendMessage(LanguageMgr.GetTranslation(Client.Account.Language, "GamePlayer.UseSlot.NotEnouthPower"), eChatType.CT_System, eChatLoc.CL_SystemWindow); } } else @@ -8157,13 +8150,9 @@ protected virtual void UseItemCharge(DbInventoryItem useItem, int type) Spell spell = null; if (type == 1) - { - spell = SkillBase.FindSpell(useItem.SpellID, chargeEffectLine); - } + spell = SkillBase.GetSpellByID(useItem.SpellID); else - { - spell = SkillBase.FindSpell(useItem.SpellID1, chargeEffectLine); - } + spell = SkillBase.GetSpellByID(useItem.SpellID1); if (spell != null) { @@ -8281,17 +8270,13 @@ protected virtual bool UseMagicalItem(DbInventoryItem item, int type) return false; } - SpellLine itemSpellLine = SkillBase.GetSpellLine(GlobalSpellsLines.Item_Effects); - - if (itemSpellLine == null) - return false; - if (type == 1 || type == 0) { - Spell spell = SkillBase.FindSpell(item.SpellID, itemSpellLine); + Spell spell = SkillBase.GetSpellByID(item.SpellID); if (spell != null) { + SpellLine itemSpellLine = SkillBase.GetSpellLine(GlobalSpellsLines.Item_Effects); int requiredLevel = item.Template.LevelRequirement > 0 ? item.Template.LevelRequirement : Math.Min(MaxLevel, item.Level); if (requiredLevel > Level) @@ -8322,6 +8307,7 @@ protected virtual bool UseMagicalItem(DbInventoryItem item, int type) } } } + return false; } diff --git a/GameServer/gameutils/SkillBase.cs b/GameServer/gameutils/SkillBase.cs index 085b8d4c4c..0c6a8caf50 100644 --- a/GameServer/gameutils/SkillBase.cs +++ b/GameServer/gameutils/SkillBase.cs @@ -2895,33 +2895,6 @@ public static Spell GetSpellByTooltipID(ushort ttid) return null; } - /// - /// Will attempt to find either in the spell line given or in the list of all spells - /// - /// - /// - /// - public static Spell FindSpell(int spellID, SpellLine line) - { - Spell spell = null; - - if (line != null) - { - List spells = GetSpellList(line.KeyName); - foreach (Spell lineSpell in spells) - { - if (lineSpell.ID == spellID) - { - spell = lineSpell; - break; - } - } - } - - spell ??= GetSpellByID(spellID); - return spell; - } - /// /// Get display name of property /// diff --git a/GameServer/packets/Client/168/DetailDisplayHandler.cs b/GameServer/packets/Client/168/DetailDisplayHandler.cs index e26f8c8b73..8bc9cec966 100644 --- a/GameServer/packets/Client/168/DetailDisplayHandler.cs +++ b/GameServer/packets/Client/168/DetailDisplayHandler.cs @@ -1444,34 +1444,26 @@ public void WriteMagicalBonuses(List output, DbInventoryItem item, GameC spellNote = LanguageMgr.GetTranslation(client.Account.Language, "DetailDisplayHandler.WriteMagicalBonuses.StrikeArmor"); } - SpellLine line = SkillBase.GetSpellLine(GlobalSpellsLines.Item_Effects); - if (line != null) - { - Spell procSpell = SkillBase.FindSpell(item.ProcSpellID, line); + Spell procSpell = SkillBase.GetSpellByID(item.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: " + item.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: " + item.ProcSpellID); } output.Add(" "); @@ -1491,34 +1483,26 @@ public void WriteMagicalBonuses(List output, DbInventoryItem item, GameC spellNote = LanguageMgr.GetTranslation(client.Account.Language, "DetailDisplayHandler.WriteMagicalBonuses.StrikeArmor"); } - SpellLine line = SkillBase.GetSpellLine(GlobalSpellsLines.Item_Effects); - if (line != null) - { - Spell procSpell = SkillBase.FindSpell(item.ProcSpellID1, line); + Spell procSpell = SkillBase.GetSpellByID(item.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: " + item.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: " + item.ProcSpellID1); } output.Add(" "); @@ -1527,38 +1511,35 @@ public void WriteMagicalBonuses(List output, DbInventoryItem item, GameC #region Charge1 if (item.SpellID != 0) { - SpellLine chargeEffectsLine = SkillBase.GetSpellLine(GlobalSpellsLines.Item_Effects); - if (chargeEffectsLine != null) + Spell spell = SkillBase.GetSpellByID(item.SpellID); + + if (spell != null) { - Spell spell = SkillBase.FindSpell(item.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 (item.MaxCharges > 0) { - if (item.MaxCharges > 0) - { - output.Add(LanguageMgr.GetTranslation(client.Account.Language, "DetailDisplayHandler.WriteMagicalBonuses.ChargedMagic")); - output.Add(LanguageMgr.GetTranslation(client.Account.Language, "DetailDisplayHandler.WriteMagicalBonuses.Charges", item.Charges)); - output.Add(LanguageMgr.GetTranslation(client.Account.Language, "DetailDisplayHandler.WriteMagicalBonuses.MaxCharges", item.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", item.Charges)); + output.Add(LanguageMgr.GetTranslation(client.Account.Language, "DetailDisplayHandler.WriteMagicalBonuses.MaxCharges", item.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: " + item.SpellID); + output.Add("- Item_Effects Spell Line Missing"); } } + else + { + output.Add("- Spell Not Found: " + item.SpellID); + } output.Add(" "); } @@ -1566,38 +1547,35 @@ public void WriteMagicalBonuses(List output, DbInventoryItem item, GameC #region Charge2 if (item.SpellID1 != 0) { - SpellLine chargeEffectsLine = SkillBase.GetSpellLine(GlobalSpellsLines.Item_Effects); - if (chargeEffectsLine != null) + Spell spell = SkillBase.GetSpellByID(item.SpellID1); + + if (spell != null) { - Spell spell = SkillBase.FindSpell(item.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 (item.MaxCharges > 0) { - if (item.MaxCharges > 0) - { - output.Add(LanguageMgr.GetTranslation(client.Account.Language, "DetailDisplayHandler.WriteMagicalBonuses.ChargedMagic")); - output.Add(LanguageMgr.GetTranslation(client.Account.Language, "DetailDisplayHandler.WriteMagicalBonuses.Charges", item.Charges)); - output.Add(LanguageMgr.GetTranslation(client.Account.Language, "DetailDisplayHandler.WriteMagicalBonuses.MaxCharges", item.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", item.Charges)); + output.Add(LanguageMgr.GetTranslation(client.Account.Language, "DetailDisplayHandler.WriteMagicalBonuses.MaxCharges", item.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: " + item.SpellID1); + output.Add("- Item_Effects Spell Line Missing"); } } + else + { + output.Add("- Spell Not Found: " + item.SpellID1); + } output.Add(" "); } diff --git a/GameServer/packets/Server/PacketLib1109.cs b/GameServer/packets/Server/PacketLib1109.cs index 9efd8d8b0b..e85fa3e935 100644 --- a/GameServer/packets/Server/PacketLib1109.cs +++ b/GameServer/packets/Server/PacketLib1109.cs @@ -1,22 +1,3 @@ -/* - * DAWN OF LIGHT - The first free open source DAoC server emulator - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - */ - using System; using System.Collections; using System.Reflection; @@ -223,29 +204,25 @@ protected override void WriteItemData(GSTCPPacketOut pak, DbInventoryItem item) string spell_name2 = ""; if (item.Object_Type != (int)eObjectType.AlchemyTincture) { - SpellLine chargeEffectsLine = SkillBase.GetSpellLine(GlobalSpellsLines.Item_Effects); - - if (chargeEffectsLine != null) + if (item.SpellID > 0/* && item.Charges > 0*/) { - if (item.SpellID > 0/* && item.Charges > 0*/) + Spell spell = SkillBase.GetSpellByID(item.SpellID); + if (spell != null) { - Spell spell = SkillBase.FindSpell(item.SpellID, chargeEffectsLine); - if (spell != null) - { - flag |= 0x08; - icon1 = spell.Icon; - spell_name1 = spell.Name; // or best spl.Name ? - } + flag |= 0x08; + icon1 = spell.Icon; + spell_name1 = spell.Name; // or best spl.Name ? } - if (item.SpellID1 > 0/* && item.Charges > 0*/) + } + + if (item.SpellID1 > 0/* && item.Charges > 0*/) + { + Spell spell = SkillBase.GetSpellByID(item.SpellID1); + if (spell != null) { - Spell spell = SkillBase.FindSpell(item.SpellID1, chargeEffectsLine); - if (spell != null) - { - flag |= 0x10; - icon2 = spell.Icon; - spell_name2 = spell.Name; // or best spl.Name ? - } + flag |= 0x10; + icon2 = spell.Icon; + spell_name2 = spell.Name; // or best spl.Name ? } } } diff --git a/GameServer/packets/Server/PacketLib182.cs b/GameServer/packets/Server/PacketLib182.cs index 6569a56fc8..4e1c31d381 100644 --- a/GameServer/packets/Server/PacketLib182.cs +++ b/GameServer/packets/Server/PacketLib182.cs @@ -1,22 +1,3 @@ -/* - * DAWN OF LIGHT - The first free open source DAoC server emulator - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - */ - using System.Collections.Generic; using System.Reflection; using DOL.Database; @@ -166,29 +147,25 @@ protected override void SendInventorySlotsUpdateRange(ICollection slots, eI string spell_name2 = ""; if (item.Object_Type != (int)eObjectType.AlchemyTincture) { - SpellLine chargeEffectsLine = SkillBase.GetSpellLine(GlobalSpellsLines.Item_Effects); - - if (chargeEffectsLine != null) + if (item.SpellID > 0/* && item.Charges > 0*/) { - if (item.SpellID > 0/* && item.Charges > 0*/) + Spell spell = SkillBase.GetSpellByID(item.SpellID); + if (spell != null) { - Spell spell = SkillBase.FindSpell(item.SpellID, chargeEffectsLine); - if (spell != null) - { - flag |= 0x08; - icon1 = spell.Icon; - spell_name1 = spell.Name; // or best spl.Name ? - } + flag |= 0x08; + icon1 = spell.Icon; + spell_name1 = spell.Name; // or best spl.Name ? } - if (item.SpellID1 > 0/* && item.Charges > 0*/) + } + + if (item.SpellID1 > 0/* && item.Charges > 0*/) + { + Spell spell = SkillBase.GetSpellByID(item.SpellID1); + if (spell != null) { - Spell spell = SkillBase.FindSpell(item.SpellID1, chargeEffectsLine); - if (spell != null) - { - flag |= 0x10; - icon2 = spell.Icon; - spell_name2 = spell.Name; // or best spl.Name ? - } + flag |= 0x10; + icon2 = spell.Icon; + spell_name2 = spell.Name; // or best spl.Name ? } } } diff --git a/GameServer/packets/Server/PacketLib189.cs b/GameServer/packets/Server/PacketLib189.cs index 69141832a4..2900c98b29 100644 --- a/GameServer/packets/Server/PacketLib189.cs +++ b/GameServer/packets/Server/PacketLib189.cs @@ -1,22 +1,3 @@ -/* - * DAWN OF LIGHT - The first free open source DAoC server emulator - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - */ - using System.Collections.Generic; using System.Linq; using System.Reflection; @@ -350,29 +331,25 @@ protected virtual void WriteItemData(GSTCPPacketOut pak, DbInventoryItem item) if (item.Object_Type != (int)eObjectType.AlchemyTincture) { - SpellLine chargeEffectsLine = SkillBase.GetSpellLine(GlobalSpellsLines.Item_Effects); - - if (chargeEffectsLine != null) + if (item.SpellID > 0/* && item.Charges > 0*/) { - if (item.SpellID > 0/* && item.Charges > 0*/) + Spell spell = SkillBase.GetSpellByID(item.SpellID); + if (spell != null) { - Spell spell = SkillBase.FindSpell(item.SpellID, chargeEffectsLine); - if (spell != null) - { - flag |= 0x08; - icon1 = spell.Icon; - spell_name1 = spell.Name; // or best spl.Name ? - } + flag |= 0x08; + icon1 = spell.Icon; + spell_name1 = spell.Name; // or best spl.Name ? } - if (item.SpellID1 > 0/* && item.Charges > 0*/) + } + + if (item.SpellID1 > 0/* && item.Charges > 0*/) + { + Spell spell = SkillBase.GetSpellByID(item.SpellID1); + if (spell != null) { - Spell spell = SkillBase.FindSpell(item.SpellID1, chargeEffectsLine); - if (spell != null) - { - flag |= 0x10; - icon2 = spell.Icon; - spell_name2 = spell.Name; // or best spl.Name ? - } + flag |= 0x10; + icon2 = spell.Icon; + spell_name2 = spell.Name; // or best spl.Name ? } } } diff --git a/GameServer/spells/AllRegenBuff.cs b/GameServer/spells/AllRegenBuff.cs index 744ab44b87..c60bfe1599 100644 --- a/GameServer/spells/AllRegenBuff.cs +++ b/GameServer/spells/AllRegenBuff.cs @@ -1,6 +1,4 @@ -using System; using System.Collections.Generic; -using DOL.GS.Effects; using DOL.GS.PacketHandler; namespace DOL.GS.Spells @@ -20,15 +18,14 @@ public override bool StartSpell(GameLiving target) { SpellLine potionEffectLine = SkillBase.GetSpellLine(GlobalSpellsLines.Potions_Effects); - Spell pomSpell = SkillBase.FindSpell(pomID, potionEffectLine); + Spell pomSpell = SkillBase.GetSpellByID(pomID); SpellHandler pomSpellHandler = ScriptMgr.CreateSpellHandler(target, pomSpell, potionEffectLine) as SpellHandler; - Spell endSpell = SkillBase.FindSpell(endID, potionEffectLine); + Spell endSpell = SkillBase.GetSpellByID(endID); SpellHandler endSpellHandler = ScriptMgr.CreateSpellHandler(target, endSpell, potionEffectLine) as SpellHandler; - Spell healSpell = SkillBase.FindSpell(healID, potionEffectLine); + Spell healSpell = SkillBase.GetSpellByID(healID); SpellHandler healthConSpellHandler = ScriptMgr.CreateSpellHandler(target, healSpell, potionEffectLine) as SpellHandler; - pomSpellHandler.StartSpell(target); endSpellHandler.StartSpell(target); @@ -84,13 +81,13 @@ public override bool StartSpell(GameLiving target) target = Caster; SpellLine potionEffectLine = SkillBase.GetSpellLine(GlobalSpellsLines.Potions_Effects); - Spell pomSpell = SkillBase.FindSpell(pomID, potionEffectLine); + Spell pomSpell = SkillBase.GetSpellByID(pomID); SpellHandler pomSpellHandler = ScriptMgr.CreateSpellHandler(target, pomSpell, potionEffectLine) as SpellHandler; - Spell endSpell = SkillBase.FindSpell(endID, potionEffectLine); + Spell endSpell = SkillBase.GetSpellByID(endID); SpellHandler endSpellHandler = ScriptMgr.CreateSpellHandler(target, endSpell, potionEffectLine) as SpellHandler; - Spell healSpell = SkillBase.FindSpell(healID, potionEffectLine); + Spell healSpell = SkillBase.GetSpellByID(healID); SpellHandler healthConSpellHandler = ScriptMgr.CreateSpellHandler(target, healSpell, potionEffectLine) as SpellHandler; pomSpellHandler.StartSpell(target); diff --git a/GameServer/spells/AllStatsBuff.cs b/GameServer/spells/AllStatsBuff.cs index 48f9afd5ae..bc135d79c6 100644 --- a/GameServer/spells/AllStatsBuff.cs +++ b/GameServer/spells/AllStatsBuff.cs @@ -1,6 +1,3 @@ -using System; -using DOL.GS.Effects; -using DOL.GS.PacketHandler; using System.Collections.Generic; namespace DOL.GS.Spells @@ -24,22 +21,22 @@ public override bool StartSpell(GameLiving target) { SpellLine potionEffectLine = SkillBase.GetSpellLine(GlobalSpellsLines.Potions_Effects); - Spell strengthSpell = SkillBase.FindSpell(strengthID, potionEffectLine); + Spell strengthSpell = SkillBase.GetSpellByID(strengthID); SpellHandler strenghtSpellHandler = ScriptMgr.CreateSpellHandler(target, strengthSpell, potionEffectLine) as SpellHandler; - Spell conSpell = SkillBase.FindSpell(conID, potionEffectLine); + Spell conSpell = SkillBase.GetSpellByID(conID); SpellHandler conSpellHandler = ScriptMgr.CreateSpellHandler(target, conSpell, potionEffectLine) as SpellHandler; - Spell strengthConSpell = SkillBase.FindSpell(strenghtConID, potionEffectLine); + Spell strengthConSpell = SkillBase.GetSpellByID(strenghtConID); SpellHandler strenghtConSpellHandler = ScriptMgr.CreateSpellHandler(target, strengthConSpell, potionEffectLine) as SpellHandler; - Spell dexSpell = SkillBase.FindSpell(dexID, potionEffectLine); + Spell dexSpell = SkillBase.GetSpellByID(dexID); SpellHandler dexSpellHandler = ScriptMgr.CreateSpellHandler(target, dexSpell, potionEffectLine) as SpellHandler; - Spell dexQuickSpell = SkillBase.FindSpell(dexQuickID, potionEffectLine); + Spell dexQuickSpell = SkillBase.GetSpellByID(dexQuickID); SpellHandler dexQuickSpellHandler = ScriptMgr.CreateSpellHandler(target, dexQuickSpell, potionEffectLine) as SpellHandler; - Spell acuitySpell = SkillBase.FindSpell(acuityID, potionEffectLine); + Spell acuitySpell = SkillBase.GetSpellByID(acuityID); SpellHandler acuitySpellHandler = ScriptMgr.CreateSpellHandler(target, acuitySpell, potionEffectLine) as SpellHandler; //Spell hasteSpell = SkillBase.FindSpell(hasteID, potionEffectLine);