Quantcast

Some code cleanup and optimizations

Taracque [01-29-16 - 18:23]
Some code cleanup and optimizations
Filename
Elementarist.lua
modules/elemental.lua
modules/enhancement.lua
diff --git a/Elementarist.lua b/Elementarist.lua
index 71684de..d339bc1 100755
--- a/Elementarist.lua
+++ b/Elementarist.lua
@@ -833,6 +833,11 @@ function Elementarist:Count(needle,...)
 	return c;
 end

+-- Utility function to check if spell available, and has 0 count in list
+function Elementarist:ZeroCount(needle,...)
+	return (Elementarist:SpellAvailable(needle)) and (Elementarist:Count(needle,...))
+end
+
 function Elementarist:hasGlyph(glyph)
 	local i, _, enabled, glyphSpellID;

diff --git a/modules/elemental.lua b/modules/elemental.lua
index 73020fb..bcd8c0f 100755
--- a/modules/elemental.lua
+++ b/modules/elemental.lua
@@ -166,12 +166,11 @@ Elementarist.elemental = {

 		if 	Elementarist.inCombat == false then
 		    -- confirm out of combat
-			if UnitAffectingCombat ("player") then Elementarist.inCombat = true end
-				if 	Elementarist.inCombat == false then
-
+			if UnitAffectingCombat ("player") then
+				Elementarist.inCombat = true
+			else
 				-- Searing Totem
-				if (Elementarist:Count(Elementarist.SpellList["Searing Totem"],spellInCast,exspell1,exspell2) == 0) and
-					Elementarist:SpellAvailable(Elementarist.SpellList["Searing Totem"])then
+				if (Elementarist:ZeroCount(Elementarist.SpellList["Searing Totem"],spellInCast,exspell1,exspell2)) then
 					local haveFireTotem,fireTotemName,fireTotemStart,fireTotemDuration = GetTotemInfo(1);
 					if (fireTotemName == "") or (fireTotemDuration and (fireTotemStart + fireTotemDuration - GetTime() ) <= timeshift) then
 						return Elementarist.SpellList["Searing Totem"];
@@ -179,8 +178,7 @@ Elementarist.elemental = {
 				end

 				-- Opening Uleash flame  prior to combat
-				if (Elementarist:Count(Elementarist.SpellList["Unleash Flame"],spellInCast,exspell1,exspell2) == 0) and
-					Elementarist:SpellAvailable(Elementarist.SpellList["Unleash Flame"]) then
+				if (Elementarist:ZeroCount(Elementarist.SpellList["Unleash Flame"],spellInCast,exspell1,exspell2)) then
 					d = Elementarist:GetSpellCooldownRemaining(Elementarist.SpellList["Unleash Flame"])
 					if (d-timeshift <= 0) then
 						return Elementarist.SpellList["Unleash Flame"];
@@ -193,8 +191,7 @@ Elementarist.elemental = {
 		-- Priority 1
 		-- if Tier7 talent is Liquid Magma and fire totem has 10 sec or more, use it
 		if (LMTalent) and (not ElementaristDB.DisableLM) then
-			if (Elementarist:Count(Elementarist.SpellList["Liquid Magma"],spellInCast,exspell1,exspell2) == 0) and
-				Elementarist:SpellAvailable(Elementarist.SpellList["Liquid Magma"])then
+			if (Elementarist:ZeroCount(Elementarist.SpellList["Liquid Magma"],spellInCast,exspell1,exspell2)) then
 				haveFireTotem,fireTotemName,fireTotemStart,fireTotemDuration = GetTotemInfo(1);
 				if ((fireTotemName ~= "") and (fireTotemDuration and (fireTotemStart + fireTotemDuration - GetTime() ) >= timeshift + 15)) or
 					(Elementarist:Count(Elementarist.SpellList["Searing Totem"],spellInCast,exspell1,exspell2) ~= 0) then
@@ -203,8 +200,7 @@ Elementarist.elemental = {
 						return Elementarist.SpellList["Liquid Magma"]
 					end
 				else
-					if (Elementarist:Count(Elementarist.SpellList["Searing Totem"],spellInCast,exspell1,exspell2) == 0) and
-						Elementarist:SpellAvailable(Elementarist.SpellList["Searing Totem"])and
+					if (Elementarist:ZeroCount(Elementarist.SpellList["Searing Totem"],spellInCast,exspell1,exspell2)) and
 						((fireTotemName == "") or (fireTotemDuration and (fireTotemStart + fireTotemDuration - GetTime() ) <= timeshift))
 					then
 						return Elementarist.SpellList["Searing Totem"];
@@ -216,9 +212,8 @@ Elementarist.elemental = {
 		-- Priority 2
 		-- Earth shock if Lightning Shield count >=20
 		-- earth_shock,if=buff.lightning_shield.react=buff.lightning_shield.max_stack
-		if (Elementarist:Count(Elementarist.SpellList["Flame Shock"],spellInCast,exspell1,exspell2) == 0 and
-			Elementarist:Count(Elementarist.SpellList["Earth Shock"],spellInCast,exspell1,exspell2) == 0 and
-			Elementarist:SpellAvailable(Elementarist.SpellList["Earth Shock"])) then
+		if (Elementarist:ZeroCount(Elementarist.SpellList["Flame Shock"],spellInCast,exspell1,exspell2) and
+			Elementarist:ZeroCount(Elementarist.SpellList["Earth Shock"],spellInCast,exspell1,exspell2)) then
 			d = Elementarist:GetSpellCooldownRemaining(Elementarist.SpellList["Earth Shock"])
 			if ( (d) and ((d-timeshift) <= 0) and (lscount) and (lscount>=20)) then
 				return Elementarist.SpellList["Earth Shock"]
@@ -229,9 +224,8 @@ Elementarist.elemental = {
 		-- Flame shock if 2 stacks Elemental Fussion and Unleashed Flame buff active
 		-- flame_shock,cycle_targets=1,if=(talent.elemental_fusion.enabled&buff.elemental_fusion.stack=2&buff.unleash_flame.up&dot.flame_shock.remains<(dot.flame_shock.duration*(0.3+t18_class_trinket*(0.48+talent.unleashed_fury.enabled*0.22))))

-		if (Elementarist:Count(Elementarist.SpellList["Flame Shock"],spellInCast,exspell1,exspell2) == 0 and
-			Elementarist:Count(Elementarist.SpellList["Earth Shock"],spellInCast,exspell1,exspell2) == 0 and
-			Elementarist:SpellAvailable(Elementarist.SpellList["Flame Shock"])) then
+		if (Elementarist:ZeroCount(Elementarist.SpellList["Flame Shock"],spellInCast,exspell1,exspell2) and
+			Elementarist:ZeroCount(Elementarist.SpellList["Earth Shock"],spellInCast,exspell1,exspell2)) then
 			d = Elementarist:GetSpellCooldownRemaining(Elementarist.SpellList["Flame Shock"])
 			if ((d - timeshift) <= 0) then
 				if (efCount>=2) then
@@ -267,9 +261,8 @@ Elementarist.elemental = {
 		-- Priority 5
 		-- Earth shock if Lightning Shield count >=15 and not on cd, and FS debuff remaining > FS cooldown, or FS debuff remaining between FS and FS cd + 2sec and LS count>=13, or has T17 4pcs and LS Count >= 12
 		-- Earth_shock,if=(set_bonus.tier17_4pc&buff.lightning_shield.react>=12&!buff.lava_surge.up)|(!set_bonus.tier17_4pc&buff.lightning_shield.react>15)
-		if (Elementarist:Count(Elementarist.SpellList["Flame Shock"],spellInCast,exspell1,exspell2) == 0 and
-			Elementarist:Count(Elementarist.SpellList["Earth Shock"],spellInCast,exspell1,exspell2) == 0)and
-			Elementarist:SpellAvailable(Elementarist.SpellList["Earth Shock"]) then
+		if (Elementarist:ZeroCount(Elementarist.SpellList["Flame Shock"],spellInCast,exspell1,exspell2) and
+			Elementarist:ZeroCount(Elementarist.SpellList["Earth Shock"],spellInCast,exspell1,exspell2)) then
 			if ( (fsExpiration - GetTime() - timeshift) > Elementarist.lastShockCD ) then
 				d = Elementarist:GetSpellCooldownRemaining(Elementarist.SpellList["Earth Shock"])
 				if (
@@ -287,9 +280,8 @@ Elementarist.elemental = {
 		-- Priority 6
 		-- Flameshock if not present or at less than 30% duration
 		-- lame_shock,cycle_targets=1,if=dot.flame_shock.remains<=(dot.flame_shock.duration*0.3)
-		if 	(Elementarist:Count(Elementarist.SpellList["Flame Shock"],spellInCast,exspell1,exspell2) == 0) and
-			(Elementarist:Count(Elementarist.SpellList["Earth Shock"],spellInCast,exspell1,exspell2) == 0) and
-			Elementarist:SpellAvailable(Elementarist.SpellList["Flame Shock"]) then
+		if 	(Elementarist:ZeroCount(Elementarist.SpellList["Flame Shock"],spellInCast,exspell1,exspell2) and
+			Elementarist:ZeroCount(Elementarist.SpellList["Earth Shock"],spellInCast,exspell1,exspell2)) then
 				d = Elementarist:GetSpellCooldownRemaining(Elementarist.SpellList["Flame Shock"])
 			if ((d - timeshift) <= 0) then
 				if ((fsExpiration - GetTime() - timeshift) < (9) ) then
@@ -309,9 +301,8 @@ Elementarist.elemental = {
 		-- if Tier6 talent is Elemental Blast use it
 		-- elemental_blast
 		if (EBTalent) then
-			if ((Elementarist:Count(Elementarist.SpellList["Elemental Blast"],spellInCast,exspell1,exspell2) == 0) and
-				(IsSpellInRange(Elementarist.SpellList["Elemental Blast"], "target") == 1) and
-				Elementarist:SpellAvailable(Elementarist.SpellList["Elemental Blast"])	) then
+			if (Elementarist:ZeroCount(Elementarist.SpellList["Elemental Blast"],spellInCast,exspell1,exspell2) and
+				(IsSpellInRange(Elementarist.SpellList["Elemental Blast"], "target") == 1) ) then
 				d = Elementarist:GetSpellCooldownRemaining(Elementarist.SpellList["Elemental Blast"])
 				if ((d - timeshift) <= 0) then
 					return Elementarist.SpellList["Elemental Blast"]
@@ -321,8 +312,7 @@ Elementarist.elemental = {

 		-- Priority 8
 		-- Searing Totem
-		if (Elementarist:Count(Elementarist.SpellList["Searing Totem"],spellInCast,exspell1,exspell2) == 0) and
-			Elementarist:SpellAvailable(Elementarist.SpellList["Searing Totem"]) then
+		if (Elementarist:ZeroCount(Elementarist.SpellList["Searing Totem"],spellInCast,exspell1,exspell2)) then
 			local haveFireTotem,fireTotemName,fireTotemStart,fireTotemDuration = GetTotemInfo(1);
 			if (fireTotemName == "") or (fireTotemDuration and (fireTotemStart + fireTotemDuration - GetTime() ) <= timeshift) then
 				return Elementarist.SpellList["Searing Totem"];
@@ -336,8 +326,7 @@ Elementarist.elemental = {

 		if (UFTalent)  or
 		   (efCount==2 and ( (fsExpiration - currentTime - timeshift) < (fsDuration * fsRefreshPercentage )  and (fsExpiration - currentTime - timeshift) > Elementarist.lastShockCD)    ) then
-			if (Elementarist:Count(Elementarist.SpellList["Unleash Flame"],spellInCast,exspell1,exspell2) == 0) and
-				Elementarist:SpellAvailable(Elementarist.SpellList["Unleash Flame"])then
+			if (Elementarist:ZeroCount(Elementarist.SpellList["Unleash Flame"],spellInCast,exspell1,exspell2)) then
 				d = Elementarist:GetSpellCooldownRemaining(Elementarist.SpellList["Unleash Flame"])
 				if (d-timeshift <= 0) then
 					return Elementarist.SpellList["Unleash Flame"];
diff --git a/modules/enhancement.lua b/modules/enhancement.lua
index 2d15901..65668c7 100755
--- a/modules/enhancement.lua
+++ b/modules/enhancement.lua
@@ -119,8 +119,7 @@ Elementarist.enhancement = {
 		--------------------------- start of priority list ----------------

 		----Priority 1 ---  Searing Totem if no fire totem or fire totem about to expire
-		if (Elementarist:Count(Elementarist.SpellList["Searing Totem"],spellInCast,exspell1,exspell2) == 0) and
-			Elementarist:SpellAvailable(Elementarist.SpellList["Searing Totem"])then
+		if (Elementarist:ZeroCount(Elementarist.SpellList["Searing Totem"],spellInCast,exspell1,exspell2)) then
 			haveFireTotem,fireTotemName,fireTotemStart,fireTotemDuration = GetTotemInfo(1);
 			if (fireTotemName == "") or (fireTotemDuration and (fireTotemStart + fireTotemDuration - currentTime ) -timeshift <= 0) then
  				return Elementarist.SpellList["Searing Totem"];
@@ -129,8 +128,7 @@ Elementarist.enhancement = {

 		----Priority 2 ---  -- if Tier6 talent is Unleashed Fury then use Unleash Elements
 		if (EFTalent) then
-			if (Elementaris:Count(Elementarist.SpellList["Unleash Elements"],spellInCast,exspell1,exspell2) == 0) and
-				Elementarist:SpellAvailable(Elementarist.SpellList["Unleash Elements"]) then
+			if (Elementaris:ZeroCount(Elementarist.SpellList["Unleash Elements"],spellInCast,exspell1,exspell2)) then
 				d = Elementarist:GetSpellCooldownRemaining(Elementarist.SpellList["Unleash Elements"])
 				if (d-timeshift <= 0) then
 					return Elementarist.SpellList["Unleash Elements"];
@@ -141,9 +139,8 @@ Elementarist.enhancement = {
 		----Priority 3	-- if Tier6 talent is Elemental Blast use it with 5 Maelstrom Weapon stacks (8 with 4 set)
 		if EBTalent then
 			if  ( (  (not Elementarist.hasT18_4pcs) and (MWcount >= 5))  or ( (Elementarist.hasT18_4pcs) and (MWcount >= 8)) )  then
-				if ( Elementarist:Count(Elementarist.SpellList["Elemental Blast"],spellInCast,exspell1,exspell2) == 0) and
-					(IsSpellInRange(Elementarist.SpellList["Elemental Blast"], "target") == 1) and
-					Elementarist:SpellAvailable(Elementarist.SpellList["Elemental Blast"]) 	then
+				if ( Elementarist:ZeroCount(Elementarist.SpellList["Elemental Blast"],spellInCast,exspell1,exspell2) == 0) and
+					(IsSpellInRange(Elementarist.SpellList["Elemental Blast"], "target") == 1) then
 					d = Elementarist:GetSpellCooldownRemaining(Elementarist.SpellList["Elemental Blast"])
 					if ((d - timeshift) <= 0) then
 						return Elementarist.SpellList["Elemental Blast"]
@@ -175,8 +172,7 @@ Elementarist.enhancement = {
 		if ( ( (MWcount >= 5) and ( not Elementarist.hasT18_4pcs) ) or
 			(MWcount >= 8)	) then
 			if ((IsSpellInRange(Elementarist.SpellList["Lightning Bolt"], "target") == 1) and
-				(Elementarist:Count(Elementarist.SpellList["Lightning Bolt"],exspell1,exspell2) == 0) and
-				Elementarist:SpellAvailable(Elementarist.SpellList["Lightning Bolt"]) ) then
+				(Elementarist:ZeroCount(Elementarist.SpellList["Lightning Bolt"],exspell1,exspell2)) ) then
 				return Elementarist.SpellList["Lightning Bolt"]
 			end
 		end
@@ -217,9 +213,8 @@ Elementarist.enhancement = {
 			fsExpiration = 0
 		end
 		if (Elementarist:hasBuff("player",Elementarist.SpellList["Unleash Flame"])) and
-			(Elementarist:Count(Elementarist.SpellList["Frost Shock"],exspell1,exspell2) == 0) and
-			(Elementarist:Count(Elementarist.SpellList["Flame Shock"],exspell1,exspell2) == 0) and
-			Elementarist:SpellAvailable(Elementarist.SpellList["Flame Shock"]) then
+			(Elementarist:ZeroCount(Elementarist.SpellList["Frost Shock"],exspell1,exspell2)) and
+			(Elementarist:ZeroCount(Elementarist.SpellList["Flame Shock"],exspell1,exspell2)) then
 			if IsSpellInRange(Elementarist.SpellList["Flame Shock"], "target") == 1 then
 				d = Elementarist:GetSpellCooldownRemaining(Elementarist.SpellList["Flame Shock"])
 				if (
@@ -233,8 +228,7 @@ Elementarist.enhancement = {
 		end

 		-- Priority 9 : Unleash Elements
-		if (Elementarist:Count(Elementarist.SpellList["Unleash Elements"],spellInCast,exspell1,exspell2) == 0) and
-			Elementarist:SpellAvailable(Elementarist.SpellList["Unleash Elements"]) then
+		if (Elementarist:ZeroCount(Elementarist.SpellList["Unleash Elements"],spellInCast,exspell1,exspell2)) then
 			d = Elementarist:GetSpellCooldownRemaining(Elementarist.SpellList["Unleash Elements"])
 			if (d) and ((d - timeshift) <= 0) then
 				return Elementarist.SpellList["Unleash Elements"]
@@ -290,8 +284,8 @@ Elementarist.enhancement = {
 		if Elementarist:SpellAvailable(Elementarist.SpellList["Frost Shock"]) then
 			d = Elementarist:GetSpellCooldownRemaining(Elementarist.SpellList["Frost Shock"])
 			if ( d and ((d - timeshift) <= 0) and
-			(Elementarist:Count(Elementarist.SpellList["Frost Shock"],exspell1,exspell2) == 0) and
-			(Elementarist:Count(Elementarist.SpellList["Flame Shock"],exspell1,exspell2) == 0) ) then
+			(Elementarist:ZeroCount(Elementarist.SpellList["Frost Shock"],exspell1,exspell2)) and
+			(Elementarist:ZeroCount(Elementarist.SpellList["Flame Shock"],exspell1,exspell2)) ) then
 				if (EFTalent and ((fsExpiration - currentTime - timeshift) < 16)) or (not EFTalent) then
 					return Elementarist.SpellList["Frost Shock"]
 				end
@@ -299,9 +293,8 @@ Elementarist.enhancement = {
 		end

 		-- Priority 15 : Elemental Blast if T18 4 piece and 2 or more Maelstom Weapon
-		if EBTalent and Elementarist.hasT18_4pcs and (MWcount >=2) and
-			Elementarist:SpellAvailable(Elementarist.SpellList["Elemental Blast"]) then
-			if 	( (Elementarist:Count(Elementarist.SpellList["Elemental Blast"],spellInCast,exspell1,exspell2) == 0) and
+		if EBTalent and Elementarist.hasT18_4pcs and (MWcount >=2) then
+			if 	( (Elementarist:ZeroCount(Elementarist.SpellList["Elemental Blast"],spellInCast,exspell1,exspell2)) and
 				(IsSpellInRange(Elementarist.SpellList["Elemental Blast"], "target") == 1)) then
 				d = Elementarist:GetSpellCooldownRemaining(Elementarist.SpellList["Elemental Blast"])
 				if ((d - timeshift) <= 0) then
@@ -336,8 +329,7 @@ Elementarist.enhancement = {
 		end

 		-- Priority 19 : Searing Totem if less than 20 seconds until it expires
-		if (Elementarist:Count(Elementarist.SpellList["Searing Totem"],spellInCast,exspell1,exspell2) == 0) and
-			Elementarist:SpellAvailable(Elementarist.SpellList["Searing Totem"]) then
+		if (Elementarist:ZeroCount(Elementarist.SpellList["Searing Totem"],spellInCast,exspell1,exspell2)) then
 			if (fireTotemName == "") or (fireTotemDuration and (fireTotemStart + fireTotemDuration - currentTime ) -timeshift <= 20) then
  				return Elementarist.SpellList["Searing Totem"];
 			end