From ccb5341c21d54f4f6104935269c10cfdf5844558 Mon Sep 17 00:00:00 2001 From: hondacrx Date: Fri, 6 Oct 2023 17:33:20 -0400 Subject: [PATCH] Some misc cleansup. --- Source/Game/AI/CoreAI/PetAI.cs | 2 +- Source/Game/Entities/Creature/Creature.cs | 6 +++--- Source/Game/Entities/Object/WorldObject.cs | 2 +- Source/Game/Entities/Player/Player.Spells.cs | 6 +++--- Source/Game/Entities/Unit/Unit.Fields.cs | 4 ++-- Source/Game/Entities/Unit/Unit.Spells.cs | 19 +++++++++---------- Source/Game/Handlers/SpellHandler.cs | 2 +- Source/Game/Handlers/TradeHandler.cs | 4 ++-- Source/Game/Scripting/ScriptManager.cs | 6 ------ Source/Game/Spells/Auras/Aura.cs | 2 +- Source/Game/Spells/Auras/AuraEffect.cs | 6 +++--- Source/Game/Spells/Spell.cs | 11 +++-------- Source/Game/Spells/SpellManager.cs | 2 +- 13 files changed, 30 insertions(+), 42 deletions(-) diff --git a/Source/Game/AI/CoreAI/PetAI.cs b/Source/Game/AI/CoreAI/PetAI.cs index 846334981..1ca002d2e 100644 --- a/Source/Game/AI/CoreAI/PetAI.cs +++ b/Source/Game/AI/CoreAI/PetAI.cs @@ -37,7 +37,7 @@ namespace Game.AI if (me.GetVictim() && me.GetVictim().IsAlive()) { // is only necessary to stop casting, the pet must not exit combat - if (!me.GetCurrentSpell(CurrentSpellTypes.Channeled) && // ignore channeled spells (Pin, Seduction) + if (me.GetCurrentSpell(CurrentSpellTypes.Channeled) == null && // ignore channeled spells (Pin, Seduction) (me.GetVictim() && me.GetVictim().HasBreakableByDamageCrowdControlAura(me))) { me.InterruptNonMeleeSpells(false); diff --git a/Source/Game/Entities/Creature/Creature.cs b/Source/Game/Entities/Creature/Creature.cs index a86b21394..889597f81 100644 --- a/Source/Game/Entities/Creature/Creature.cs +++ b/Source/Game/Entities/Creature/Creature.cs @@ -3178,7 +3178,7 @@ namespace Game.Entities return false; } - if (focusSpell) + if (focusSpell != null) return focusSpell == _spellFocusInfo.Spell; else return _spellFocusInfo.Spell != null || _spellFocusInfo.Delay != 0; @@ -3186,11 +3186,11 @@ namespace Game.Entities public void ReleaseSpellFocus(Spell focusSpell = null, bool withDelay = true) { - if (!_spellFocusInfo.Spell) + if (_spellFocusInfo.Spell == null) return; // focused to something else - if (focusSpell && focusSpell != _spellFocusInfo.Spell) + if (focusSpell != null && focusSpell != _spellFocusInfo.Spell) return; if (_spellFocusInfo.Spell.GetSpellInfo().HasAttribute(SpellAttr5.AiDoesntFaceTarget)) diff --git a/Source/Game/Entities/Object/WorldObject.cs b/Source/Game/Entities/Object/WorldObject.cs index 72bac5a0c..2812ed72e 100644 --- a/Source/Game/Entities/Object/WorldObject.cs +++ b/Source/Game/Entities/Object/WorldObject.cs @@ -2453,7 +2453,7 @@ namespace Game.Entities if (spell.m_CastItem == null && info.HasAttribute(SpellAttr2.RetainItemCast)) { - if (args.TriggeringSpell) + if (args.TriggeringSpell != null) spell.m_CastItem = args.TriggeringSpell.m_CastItem; else if (args.TriggeringAura != null && !args.TriggeringAura.GetBase().GetCastItemGUID().IsEmpty()) { diff --git a/Source/Game/Entities/Player/Player.Spells.cs b/Source/Game/Entities/Player/Player.Spells.cs index 95c00e5e8..f931823a8 100644 --- a/Source/Game/Entities/Player/Player.Spells.cs +++ b/Source/Game/Entities/Player/Player.Spells.cs @@ -1000,7 +1000,7 @@ namespace Game.Entities return; // Call not from spell cast, send cooldown event for item spells if no in combat - if (!spell) + if (spell == null) { // spell/item pair let set proper cooldown (except not existed charged spell cooldown spellmods for potions) ItemTemplate proto = Global.ObjectMgr.GetItemTemplate(m_lastPotionId); @@ -2946,7 +2946,7 @@ namespace Game.Entities pct = 1.0f; // Drop charges for triggering spells instead of triggered ones - if (m_spellModTakingSpell) + if (m_spellModTakingSpell != null) spell = m_spellModTakingSpell; switch (op) @@ -3114,7 +3114,7 @@ namespace Game.Entities return false; // First time this aura applies a mod to us and is out of charges - if (spell && mod.ownerAura.IsUsingCharges() && mod.ownerAura.GetCharges() == 0 && !spell.m_appliedMods.Contains(mod.ownerAura)) + if (spell != null && mod.ownerAura.IsUsingCharges() && mod.ownerAura.GetCharges() == 0 && !spell.m_appliedMods.Contains(mod.ownerAura)) return false; switch (mod.op) diff --git a/Source/Game/Entities/Unit/Unit.Fields.cs b/Source/Game/Entities/Unit/Unit.Fields.cs index 7241cfcb5..393b76a1e 100644 --- a/Source/Game/Entities/Unit/Unit.Fields.cs +++ b/Source/Game/Entities/Unit/Unit.Fields.cs @@ -198,7 +198,7 @@ namespace Game.Entities public SpellInfo GetSpellInfo() { - if (_spell) + if (_spell != null) return _spell.GetSpellInfo(); if (_damageInfo != null) return _damageInfo.GetSpellInfo(); @@ -209,7 +209,7 @@ namespace Game.Entities } public SpellSchoolMask GetSchoolMask() { - if (_spell) + if (_spell != null) return _spell.GetSpellInfo().GetSchoolMask(); if (_damageInfo != null) return _damageInfo.GetSchoolMask(); diff --git a/Source/Game/Entities/Unit/Unit.Spells.cs b/Source/Game/Entities/Unit/Unit.Spells.cs index 66bac1d49..6ef665dfa 100644 --- a/Source/Game/Entities/Unit/Unit.Spells.cs +++ b/Source/Game/Entities/Unit/Unit.Spells.cs @@ -733,7 +733,7 @@ namespace Game.Entities } // call script handlers - if (spell) + if (spell != null) spell.CallScriptCalcCritChanceHandlers(this, ref crit_chance); else aurEff.GetBase().CallScriptEffectCalcCritChanceHandlers(aurEff, aurEff.GetBase().GetApplicationOfTarget(GetGUID()), this, ref crit_chance); @@ -1620,7 +1620,7 @@ namespace Game.Entities Player modOwner = GetSpellModOwner(); if (modOwner) { - if (modOwner != this && spell) + if (modOwner != this && spell != null) { List modAuras = new(); foreach (var itr in modOwner.GetAppliedAuras()) @@ -1648,7 +1648,7 @@ namespace Game.Entities void TriggerAurasProcOnEvent(ProcEventInfo eventInfo, List> aurasTriggeringProc) { Spell triggeringSpell = eventInfo.GetProcSpell(); - bool disableProcs = triggeringSpell && triggeringSpell.IsProcDisabled(); + bool disableProcs = triggeringSpell != null && triggeringSpell.IsProcDisabled(); int oldProcChainLength = m_procChainLength; @@ -1746,7 +1746,7 @@ namespace Game.Entities } case CurrentSpellTypes.AutoRepeat: { - if (GetCurrentSpell(CSpellType) && GetCurrentSpell(CSpellType).GetState() == SpellState.Idle) + if (GetCurrentSpell(CSpellType) != null && GetCurrentSpell(CSpellType).GetState() == SpellState.Idle) GetCurrentSpell(CSpellType).SetState(SpellState.Finished); // only Auto Shoot does not break anything @@ -1780,9 +1780,7 @@ namespace Game.Entities // generic spells are cast when they are not finished and not delayed var currentSpell = GetCurrentSpell(CurrentSpellTypes.Generic); - if (currentSpell && - (currentSpell.GetState() != SpellState.Finished) && - (withDelayed || currentSpell.GetState() != SpellState.Delayed)) + if (currentSpell != null && (currentSpell.GetState() != SpellState.Finished) && (withDelayed || currentSpell.GetState() != SpellState.Delayed)) { if (!skipInstant || currentSpell.GetCastTime() != 0) { @@ -1790,17 +1788,18 @@ namespace Game.Entities return true; } } + currentSpell = GetCurrentSpell(CurrentSpellTypes.Channeled); // channeled spells may be delayed, but they are still considered cast - if (!skipChanneled && currentSpell && - (currentSpell.GetState() != SpellState.Finished)) + if (!skipChanneled && currentSpell != null && (currentSpell.GetState() != SpellState.Finished)) { if (!isAutoshoot || !currentSpell.m_spellInfo.HasAttribute(SpellAttr2.DoNotResetCombatTimers)) return true; } + currentSpell = GetCurrentSpell(CurrentSpellTypes.AutoRepeat); // autorepeat spells may be finished or delayed, but they are still considered cast - if (!skipAutorepeat && currentSpell) + if (!skipAutorepeat && currentSpell != null) return true; return false; diff --git a/Source/Game/Handlers/SpellHandler.cs b/Source/Game/Handlers/SpellHandler.cs index 69d020f9d..edb8db25a 100644 --- a/Source/Game/Handlers/SpellHandler.cs +++ b/Source/Game/Handlers/SpellHandler.cs @@ -672,7 +672,7 @@ namespace Game { Unit caster = Global.ObjAccessor.GetUnit(GetPlayer(), packet.Guid); Spell spell = caster ? caster.GetCurrentSpell(CurrentSpellTypes.Generic) : null; - if (!spell || spell.m_spellInfo.Id != packet.SpellID || spell.m_castId != packet.CastID || !spell.m_targets.HasDst() || !spell.m_targets.HasSrc()) + if (spell == null || spell.m_spellInfo.Id != packet.SpellID || spell.m_castId != packet.CastID || !spell.m_targets.HasDst() || !spell.m_targets.HasSrc()) return; Position pos = spell.m_targets.GetSrcPos(); diff --git a/Source/Game/Handlers/TradeHandler.cs b/Source/Game/Handlers/TradeHandler.cs index d66fa4599..f68f808b9 100644 --- a/Source/Game/Handlers/TradeHandler.cs +++ b/Source/Game/Handlers/TradeHandler.cs @@ -476,10 +476,10 @@ namespace Game trader.ModifyMoney(-(long)his_trade.GetMoney()); trader.ModifyMoney((long)my_trade.GetMoney()); - if (my_spell) + if (my_spell != null) my_spell.Prepare(my_targets); - if (his_spell) + if (his_spell != null) his_spell.Prepare(his_targets); // cleanup diff --git a/Source/Game/Scripting/ScriptManager.cs b/Source/Game/Scripting/ScriptManager.cs index edf3db252..79a6da947 100644 --- a/Source/Game/Scripting/ScriptManager.cs +++ b/Source/Game/Scripting/ScriptManager.cs @@ -283,12 +283,6 @@ namespace Game.Scripting public void IncrementScriptCount() { ++_ScriptCount; } public uint GetScriptCount() { return _ScriptCount; } - //Reloading - public void Reload() - { - - } - //Unloading public void Unload() { diff --git a/Source/Game/Spells/Auras/Aura.cs b/Source/Game/Spells/Auras/Aura.cs index be76a5207..56b192783 100644 --- a/Source/Game/Spells/Auras/Aura.cs +++ b/Source/Game/Spells/Auras/Aura.cs @@ -1696,7 +1696,7 @@ namespace Game.Spells // check spell triggering us Spell spell = eventInfo.GetProcSpell(); - if (spell) + if (spell != null) { // Do not allow auras to proc from effect triggered from itself if (spell.IsTriggeredByAura(m_spellInfo)) diff --git a/Source/Game/Spells/Auras/AuraEffect.cs b/Source/Game/Spells/Auras/AuraEffect.cs index 7f665a458..49421cafa 100644 --- a/Source/Game/Spells/Auras/AuraEffect.cs +++ b/Source/Game/Spells/Auras/AuraEffect.cs @@ -637,7 +637,7 @@ namespace Game.Spells break; case AuraType.ModCastingSpeedNotStack: // skip melee hits and instant cast spells - if (!eventInfo.GetProcSpell() || eventInfo.GetProcSpell().GetCastTime() == 0) + if (eventInfo.GetProcSpell() == null || eventInfo.GetProcSpell().GetCastTime() == 0) return false; break; case AuraType.ModSchoolMaskDamageFromCaster: @@ -651,7 +651,7 @@ namespace Game.Spells { // Skip melee hits and spells with wrong school or zero cost if (spellInfo == null || !Convert.ToBoolean((int)spellInfo.GetSchoolMask() & GetMiscValue()) // School Check - || !eventInfo.GetProcSpell()) + || eventInfo.GetProcSpell() == null) return false; // Costs Check @@ -1963,7 +1963,7 @@ namespace Game.Spells for (var i = CurrentSpellTypes.Melee; i < CurrentSpellTypes.Max; ++i) { Spell spell = target.GetCurrentSpell(i); - if (spell) + if (spell != null) if (spell.m_spellInfo.PreventionType.HasAnyFlag(SpellPreventionType.NoActions)) // Stop spells on prepare or casting state target.InterruptSpell(i, false); diff --git a/Source/Game/Spells/Spell.cs b/Source/Game/Spells/Spell.cs index 0b7faa81e..bfa6e43e0 100644 --- a/Source/Game/Spells/Spell.cs +++ b/Source/Game/Spells/Spell.cs @@ -106,7 +106,7 @@ namespace Game.Spells for (var i = 0; i < m_loadedScripts.Count; ++i) m_loadedScripts[i]._Unload(); - if (m_referencedFromCurrentSpell && m_selfContainer && m_selfContainer == this) + if (m_referencedFromCurrentSpell && m_selfContainer != null && m_selfContainer == this) { // Clean the reference to avoid later crash. // If this error is repeating, we may have to add an ASSERT to better track down how we get into this case. @@ -2722,13 +2722,13 @@ namespace Game.Spells if (modOwner) { lastSpellMod = modOwner.m_spellModTakingSpell; - if (lastSpellMod) + if (lastSpellMod != null) modOwner.SetSpellModTakingSpell(lastSpellMod, false); } _cast(skipCheck); - if (lastSpellMod) + if (lastSpellMod != null) modOwner.SetSpellModTakingSpell(lastSpellMod, true); } @@ -8086,11 +8086,6 @@ namespace Game.Spells public int GetTimer() { return m_timer; } - public static implicit operator bool(Spell spell) - { - return spell != null; - } - #region Fields Dictionary _executeLogEffects = new(); PathGenerator m_preGeneratedPath; diff --git a/Source/Game/Spells/SpellManager.cs b/Source/Game/Spells/SpellManager.cs index bcc835e6f..9e8413d87 100644 --- a/Source/Game/Spells/SpellManager.cs +++ b/Source/Game/Spells/SpellManager.cs @@ -468,7 +468,7 @@ namespace Game.Entities // check power requirement if (procEntry.AttributesMask.HasAnyFlag(ProcAttributes.ReqPowerCost)) { - if (!eventInfo.GetProcSpell()) + if (eventInfo.GetProcSpell() == null) return false; var costs = eventInfo.GetProcSpell().GetPowerCost();