Quantcast

Signed-off-by: BillLive <bill@live.com.au>

BillLive [01-01-16 - 16:19]
Signed-off-by: BillLive <bill@live.com.au>
Filename
Elementarist.lua
modules/elemental.lua
diff --git a/Elementarist.lua b/Elementarist.lua
index b3db05b..f0c6d70 100755
--- a/Elementarist.lua
+++ b/Elementarist.lua
@@ -1,5 +1,5 @@
 -------------------------------------------------------------------------------
--- Elementarist 3.5.3
+-- Elementarist 3.6.1b
 --
 -- Shows the advised spell for an elemental shaman for optimal DPS output.
 -------------------------------------------------------------------------------
@@ -8,13 +8,14 @@ Elementarist = {Locals = {}}

 local L = Elementarist.Locals

-Elementarist.versionNumber = '3.5.3';
+Elementarist.versionNumber = '3.6.1';
 Elementarist.enabled = true;
 Elementarist.playerName = UnitName("player")
 Elementarist.playerGUID = UnitGUID("player")
 Elementarist.targetGUID = nil
 Elementarist.spellHaste = GetCombatRatingBonus(20)
 Elementarist.timeSinceLastUpdate = 0
+Elementarist.inCombat = false
 Elementarist.AuraTrackerUpdate = 0
 Elementarist.shieldTrackerUpdate = 0
 Elementarist.spellPower = GetSpellBonusDamage(4);	-- nature spell bonus
@@ -303,6 +304,7 @@ function Elementarist.events.ADDON_LOADED(addon)
 	Elementarist.eventFrame:RegisterEvent("COMBAT_RATING_UPDATE") -- Monitor the all-mighty haste
 	Elementarist.eventFrame:RegisterEvent("PLAYER_TARGET_CHANGED")
 	Elementarist.eventFrame:RegisterEvent("PLAYER_REGEN_ENABLED") -- Left combat, clean up all enemy GUIDs
+	Elementarist.eventFrame:RegisterEvent("PLAYER_REGEN_DISABLED") -- Entering combat
 	Elementarist.eventFrame:RegisterEvent("PLAYER_TALENT_UPDATE")
 	Elementarist.eventFrame:RegisterEvent("PARTY_MEMBERS_CHANGED")

@@ -453,7 +455,7 @@ function Elementarist:RemoveFromTables(guid)
 	if (Elementarist.person["foe"][guid]) and (Elementarist.person["foe"][guid] ~= 0) then
 		Elementarist.person["foe"][guid] = 0
 		Elementarist.person["foeCount"] = Elementarist.person["foeCount"] - 1
-		Elementarist:Debug('Enemy died:', Elementarist.person["foeCount"] .. " " .. guid)
+--		Elementarist:Debug('Enemy died:', Elementarist.person["foeCount"] .. " " .. guid)
 	end
 	if (Elementarist.auraCooldowns[guid]) then
 		Elementarist.auraCooldowns[guid]=nil
@@ -473,7 +475,7 @@ function Elementarist:PurgePersonTable()
 			if ( Elementarist.person["foe"][i] ~= 0) then
 				Elementarist.person["foe"][i] = 0	-- mark as inactive
 				Elementarist.person["foeCount"] = Elementarist.person["foeCount"] - 1
-				Elementarist:Debug('Enemy removed:', Elementarist.person["foeCount"])
+--				Elementarist:Debug('Enemy removed:', Elementarist.person["foeCount"])
 			end
 		end
 	end
@@ -483,7 +485,7 @@ function Elementarist:PurgePersonTable()
 			if ( Elementarist.person["friend"][i] ~= 0 ) then
 				Elementarist.person["friend"][i] = 0	-- mark as inactive
 				Elementarist.person["friendCount"] = Elementarist.person["friendCount"] - 1
-				Elementarist:Debug('Friend removed:', Elementarist.person["friendCount"])
+--				Elementarist:Debug('Friend removed:', Elementarist.person["friendCount"])
 			end
 		end
 	end
@@ -493,30 +495,30 @@ end
 function Elementarist:CountPerson(time, event, sguid, sname, sflags, dguid, dname, dflags)
 	local suffix = event:match(".+(_.-)$")
 	if Elementarist.HostileFilter[suffix] then
-		Elementarist:Debug('DGUID:', dguid);
+--		Elementarist:Debug('DGUID:', dguid);
 		if (bit.band(dflags, COMBATLOG_OBJECT_REACTION_HOSTILE) == COMBATLOG_OBJECT_REACTION_HOSTILE) and (bit.band(dflags, COMBATLOG_OBJECT_AFFILIATION_OUTSIDER) == COMBATLOG_OBJECT_AFFILIATION_OUTSIDER) then
 			if (not Elementarist.person["foe"][dguid]) then
 				Elementarist.person["foeCount"] = Elementarist.person["foeCount"] + 1
-				Elementarist:Debug('Enemy added', Elementarist.person["foeCount"] .. " " .. dguid .. " " .. dflags)
+--				Elementarist:Debug('Enemy added', Elementarist.person["foeCount"] .. " " .. dguid .. " " .. dflags)
 			end
 			Elementarist.person["foe"][dguid] = GetTime()
     	elseif (bit.band(sflags, COMBATLOG_OBJECT_REACTION_HOSTILE) == COMBATLOG_OBJECT_REACTION_HOSTILE) and (bit.band(sflags, COMBATLOG_OBJECT_AFFILIATION_OUTSIDER) == COMBATLOG_OBJECT_AFFILIATION_OUTSIDER) then
 			if ((not Elementarist.person["foe"][sguid]) or (Elementarist.person["foe"][sguid]==0)) then
 				Elementarist.person["foeCount"] = Elementarist.person["foeCount"] + 1
-				Elementarist:Debug('Enemy added', Elementarist.person["foeCount"] .. " " .. sguid .. " flags: " .. dflags)
+--				Elementarist:Debug('Enemy added', Elementarist.person["foeCount"] .. " " .. sguid .. " flags: " .. dflags)
 			end
 			Elementarist.person["foe"][sguid] = GetTime()
 		end
 		if (bit.band(dflags, COMBATLOG_OBJECT_REACTION_FRIENDLY) == COMBATLOG_OBJECT_REACTION_FRIENDLY) then
 			if ((not Elementarist.person["friend"][dguid]) or (Elementarist.person["friend"][dguid]==0)) then
 				Elementarist.person["friendCount"] = Elementarist.person["friendCount"] + 1
-				Elementarist:Debug('Friend added', Elementarist.person["friendCount"] .. " " .. dguid .. " flags: " .. dflags)
+--				Elementarist:Debug('Friend added', Elementarist.person["friendCount"] .. " " .. dguid .. " flags: " .. dflags)
 			end
 			Elementarist.person["friend"][dguid] = GetTime()
     	elseif (bit.band(sflags, COMBATLOG_OBJECT_REACTION_FRIENDLY) == COMBATLOG_OBJECT_REACTION_FRIENDLY) then
 			if ((not Elementarist.person["friend"][sguid]) or (Elementarist.person["friend"][sguid]==0)) then
 				Elementarist.person["friendCount"] = Elementarist.person["friendCount"] + 1
-				Elementarist:Debug('Friend added', Elementarist.person["friendCount"] .. " " .. sguid .. " " .. sflags)
+--				Elementarist:Debug('Friend added', Elementarist.person["friendCount"] .. " " .. sguid .. " " .. sflags)
 			end
 			Elementarist.person["friend"][sguid] = GetTime()
 		end
@@ -652,8 +654,16 @@ function Elementarist.events.PLAYER_TARGET_CHANGED(...)
 	Elementarist:DecideSpells()
 end

+function Elementarist.events.PLAYER_REGEN_DISABLED(...)
+	-- Entered combat
+	Elementarist.inCombat = true
+	Elementarist:Debug('Entering Combat:', GetTime() )
+end
+
 function Elementarist.events.PLAYER_REGEN_ENABLED(...)
 	-- left combat
+	Elementarist.inCombat = false
+	Elementarist:Debug('Exited Combat:', GetTime() )
 	Elementarist.person["friend"] = {}
 	Elementarist.person["friendCount"] = 0
 	Elementarist.person["foe"] = {}
@@ -742,6 +752,7 @@ function Elementarist:UpdateAuraTracker()
 		Elementarist:SetTexture(Elementarist.textureList["debuff_" .. tostring(m)],"")
 		Elementarist.auraCooldownFrame["mini_" .. tostring(m)]:SetCooldown( 0, 0)
 		Elementarist.auraCooldownFrame["mini_" .. tostring(m)]:SetDrawBling(false)
+		m = m + 1
 	end

 	-- update main frame
@@ -757,7 +768,7 @@ function Elementarist:UpdateAuraTracker()
 			Elementarist.textList["debuff"]:SetText("")
 			Elementarist.auraCooldownFrame["main"]:SetCooldown(0, 0)
 			Elementarist.auraCooldownFrame["main"]:SetDrawBling(false)
-			m = m + 1
+			m = m - 1
 		end
 	end;
 end
@@ -956,10 +967,11 @@ function Elementarist:DecideSpells()
 			end
 		end
 		Elementarist:SetTexture(Elementarist.textureList["next"],GetSpellTexture(spell))
-
+

 		local count = GetSpellCharges(spell)
-		if spell == Elementarist.SpellList["Earth Shock"] then 	_, _, _, count = Elementarist:hasBuff("player",Elementarist.SpellList["Lightning Shield"]) end
+		if spell == Elementarist.SpellList["Earth Shock"] then 	_, _, _, count = Elementarist:hasBuff("player",Elementarist.SpellList["Lightning Shield"]) end
+		if spell == Elementarist.SpellList["Flame Shock"] then 	_, _, _, count = Elementarist:hasBuff("player",Elementarist.SpellList["Elemental Fusion"]) end

  		if count then
  			Elementarist.textList["next"]:SetText(count)
@@ -981,6 +993,7 @@ function Elementarist:DecideSpells()

 		count = GetSpellCharges(spell1)
 		if spell1 == Elementarist.SpellList["Earth Shock"] then 	_, _, _, count = Elementarist:hasBuff("player",Elementarist.SpellList["Lightning Shield"]) end
+		if spell1 == Elementarist.SpellList["Flame Shock"] then 	_, _, _, count = Elementarist:hasBuff("player",Elementarist.SpellList["Elemental Fusion"]) end
 		if count then
 			Elementarist.textList["next1"]:SetText(count)
 		else
@@ -1000,7 +1013,8 @@ function Elementarist:DecideSpells()
 		Elementarist:SetTexture(Elementarist.textureList["next2"],GetSpellTexture(spell2))

 		count = GetSpellCharges(spell2)
-		if spell2 == Elementarist.SpellList["Earth Shock"] then 	_, _, _, count = Elementarist:hasBuff("player",Elementarist.SpellList["Lightning Shield"]) end
+		if spell2 == Elementarist.SpellList["Earth Shock"] then 	_, _, _, count = Elementarist:hasBuff("player",Elementarist.SpellList["Lightning Shield"]) end
+		if spell2 == Elementarist.SpellList["Flame Shock"] then 	_, _, _, count = Elementarist:hasBuff("player",Elementarist.SpellList["Elemental Fusion"]) end
 		if count then
 			Elementarist.textList["next2"]:SetText(count)
 		else
diff --git a/modules/elemental.lua b/modules/elemental.lua
index 8da49e9..eb33ddd 100755
--- a/modules/elemental.lua
+++ b/modules/elemental.lua
@@ -41,29 +41,26 @@ Elementarist.elemental = {
 		Elementarist.trackFilter = "PLAYER|HARMFUL";
 		Elementarist.trackDuration = 39;
 	end;
+
+-----------------------------------------------------
+-- Determine next spell to display
+-----------------------------------------------------
+
 	NextSpell = function(self,timeshift,exspell1,exspell2)
 		local guid = UnitGUID("target")
 		local currentTime = GetTime()
 		local s,d,e
-		local name, fsDuration, fsExpiration, unitCaster
 		local haveFireTotem,fireTotemName,fireTotemStart,fireTotemDuration
 		local lastSpell
 		local doFS = false
 		local _
-		local lscount,efCount
 		local EBTalent = (Elementarist.tier6Talent == 19267)
-		local UFTalent =  (Elementarist.tier6Talent == 21773)
+		local UFTalent = (Elementarist.tier6Talent == 21773)
 		local EFTalent = (Elementarist.tier7Talent == 21198)
-
+		local LMTalent = (Elementarist.tier7Talent == 21200)
 		local fsRefreshPercentage=0.3
 		if Elementarist.hasT18_Class_Trinket then fsRefreshPercentage=fsRefreshPercentage + 0.48 end
 		if UFTalent then fsRefreshPercentage=fsRefreshPercentage + 0.22 end
-		Elementarist:Debug(fsRefreshPercentage,  "fsRefreshPercentage",1)
-
-		 _, _, _, efCount = Elementarist:hasBuff("player",Elementarist.SpellList["Elemental Fusion"])
-		 if (efCount == nil) then
-		   efCount = 0
-		 end

 		if (exspell1) then
 			if (exspell2) then
@@ -75,11 +72,11 @@ Elementarist.elemental = {
 			lastSpell = Elementarist.lastSpell
 		end

-		Elementarist.lastBaseGCD = 1.5 - (1.5 * Elementarist.spellHaste * .01)
-
 		local flameshockavail = false
-		local LvBct = 2 - (2 * Elementarist.spellHaste * .01)

+		-----------------------------------------------------
+		-- Timing calulatutions
+		-----------------------------------------------------

 		-- check Shock CD
 		s, d = GetSpellCooldown(Elementarist.SpellList["Flame Shock"])
@@ -90,17 +87,17 @@ Elementarist.elemental = {
 		if (d) and (d>0) and (s == 0) then
 			Elementarist.lastShockCD = d
 		end
-		_, _, _, lscount = Elementarist:hasBuff("player",Elementarist.SpellList["Lightning Shield"])

-		-- if target is dead, return ""
-		if (UnitHealth("target")<=0) then
-			return ""
-		end
+

-		if (not timeshift) then
-			timeshift = 0
-		end
+		-- set minimuim amount of flameshock remaining for a lava burst
+		local LvBct = 2 - (2 * Elementarist.spellHaste * .01)
+
+		--  Set Global Coolodown
+		Elementarist.lastBaseGCD = 1.5 - (1.5 * Elementarist.spellHaste * .01)

+		if (not timeshift) then	timeshift = 0 end
+
 		-- check current spell
 		local spellInCast, _, _, _, sICstartTime, sICendTime = UnitCastingInfo("player")

@@ -111,11 +108,12 @@ Elementarist.elemental = {
 			Elementarist.lastCastTime = sICendTime;
 			timeshift = timeshift + (sICendTime / 1000) - GetTime()
 		else
-			-- to prevent tick in current spell, check if last one finished in short time
-			if (Elementarist.lastCastTime) and ((Elementarist.lastCastTime / 1000) + Elementarist.lastBaseGCD >= GetTime() ) then
-				spellInCast = Elementarist.lastSpell;
-			end
-			-- no spell in cast, check global cd via Ghost Wolf
+--			-- to prevent tick in current spell, check if last one finished in short time
+--			if (Elementarist.lastCastTime) and ((Elementarist.lastCastTime / 1000) + Elementarist.lastBaseGCD >= GetTime() ) then
+--				spellInCast = Elementarist.lastSpell;
+--			end
+
+--			-- no spell in cast, check global cd via Ghost Wolf
 			if (Elementarist.SpellList["Ghost Wolf"]) then
 				local ftcd = Elementarist:GetSpellCooldownRemaining(Elementarist.SpellList["Ghost Wolf"])
 				if (ftcd) then
@@ -128,25 +126,74 @@ Elementarist.elemental = {
 			end
 		end

-		-- if item level >575 and Earthquake is enabled
-		if (ElementaristDB.EnableEQ) then
-			if (Elementarist.iLvl>=575) or (Elementarist.person["foeCount"]>1) then
-				local eqCharges, maxEqCharges, cdStart, cdLength  = GetSpellCharges(Elementarist.SpellList["Earthquake"]);
-				if (eqCharges<maxEqCharges) and (((cdStart + cdLength)- GetTime()) - timeshift <= 0) then
-					eqCharges = eqCharges + 1;
+		-----------------------------------------------------
+		-- buffs and debuff status
+		-----------------------------------------------------
+
+		-- set lightning shield count
+		local _, _, _, lscount = Elementarist:hasBuff("player",Elementarist.SpellList["Lightning Shield"])
+
+
+		-- get targets flame shock debuff information
+		name, _, _, _, _, fsDuration,fsExpiration, unitCaster = Elementarist:hasDeBuff("target", Elementarist.SpellList["Flame Shock"], "player");
+		if (not fsExpiration) then fsExpiration = 0 fsDuration = 0 end
+
+		-- get lava burst charges
+		local lvbCharges, maxLvbCharges, cdStart, cdLength  = GetSpellCharges(Elementarist.SpellList["Lava Burst"]);
+		local lvbChargesRaw = lvbCharges
+		lvbCharges = lvbCharges - Elementarist:Count(Elementarist.SpellList["Lava Burst"], spellInCast,exspell1,exspell2);
+		if (((cdStart + cdLength)- GetTime()) - timeshift <= 0) then lvbCharges = lvbCharges + 1 end
+
+
+		-- Set elemental fussion buff count
+		local _, _, _, efCount = Elementarist:hasBuff("player",Elementarist.SpellList["Elemental Fusion"])
+		if (efCount == nil) then efCount = 0 end
+		if (efCount < 2)and (EFTalent) then if (Elementarist:Count(Elementarist.SpellList["Lava Burst"],spellInCast,exspell1,exspell2) == 0) then efCount = efCount +1 end end
+
+		-- check if assendance active
+		local ascendance, _, _, _, _, _, ascendanceExp = Elementarist:hasBuff("player",Elementarist.SpellList["AscendanceElementalBuff"]);
+		if (ascendance == nil) then
+			ascendanceExp = 0
+		end
+
+		-----------------------------------------------------
+		-- Spell Priorities for Next Spell to be recommeneded
+		-----------------------------------------------------
+
+		-- if target is dead, return ""
+		if (UnitHealth("target")<=0) then
+			return ""
+		end
+
+		-- if not in combat Recommend Pre-combat and spells
+
+		if 	Elementarist.inCombat == false then
+		    -- confirm out of combat
+			if UnitAffectingCombat ("player") then Elementarist.inCombat = true end
+				if 	Elementarist.inCombat == false then
+
+				-- Searing Totem
+				if (Elementarist:Count(Elementarist.SpellList["Searing Totem"],spellInCast,exspell1,exspell2) == 0) then
+					local haveFireTotem,fireTotemName,fireTotemStart,fireTotemDuration = GetTotemInfo(1);
+					if (fireTotemName == "") or (fireTotemDuration and (fireTotemStart + fireTotemDuration - GetTime() ) <= timeshift) then
+						return Elementarist.SpellList["Searing Totem"];
+					end
 				end
-				eqCharges = eqCharges - Elementarist:Count(Elementarist.SpellList["Earthquake"],spellInCast,exspell1,exspell2);
-				if (eqCharges > 0) then
-					d = Elementarist:GetSpellCooldownRemaining(Elementarist.SpellList["Earthquake"])
-					if (d) and (d<0.5) then
-						return Elementarist.SpellList["Earthquake"]
+
+				-- Opening Uleash flame  prior to combat
+				if (Elementarist:Count(Elementarist.SpellList["Unleash Flame"],spellInCast,exspell1,exspell2) == 0) then
+					d = Elementarist:GetSpellCooldownRemaining(Elementarist.SpellList["Unleash Flame"])
+					if (d-timeshift <= 0) then
+						return Elementarist.SpellList["Unleash Flame"];
 					end
 				end
 			end
 		end
-
+
+
+		-- Priority 1
 		-- if Tier7 talent is Liquid Magma and fire totem has 10 sec or more, use it
-		if (Elementarist.tier7Talent == 21200) and (not ElementaristDB.DisableLM) then
+		if (LMTalent) and (not ElementaristDB.DisableLM) then
 			if (Elementarist:Count(Elementarist.SpellList["Liquid Magma"],spellInCast,exspell1,exspell2) == 0) then
 				haveFireTotem,fireTotemName,fireTotemStart,fireTotemDuration = GetTotemInfo(1);
 				if ((fireTotemName ~= "") and (fireTotemDuration and (fireTotemStart + fireTotemDuration - GetTime() ) >= timeshift + 15)) or
@@ -165,37 +212,9 @@ Elementarist.elemental = {
 			end
 		end

-		-- check if Flame shock applied on target first
-		name, _, _, _, _, fsDuration,fsExpiration, unitCaster = Elementarist:hasDeBuff("target", Elementarist.SpellList["Flame Shock"], "player");
-		if (not fsExpiration) then fsExpiration = 0 fsDuration = 0 end
-		if (Elementarist:Count(Elementarist.SpellList["Flame Shock"],spellInCast,exspell1,exspell2) == 0 and Elementarist:Count(Elementarist.SpellList["Earth Shock"],spellInCast,exspell1,exspell2) == 0) then
-			if IsSpellInRange(Elementarist.SpellList["Flame Shock"], "target") == 1 then
-				d = Elementarist:GetSpellCooldownRemaining(Elementarist.SpellList["Flame Shock"])
-				if ((d - timeshift) <= 0) then
-					flameshockavail = true
-					if (unitCaster ~= "player") then	-- fs debuff is not casted by the player
-						name = false
-						fsExpiration = 0
-					end
-					if (not name) then 	-- no fs debuff on target
-						fsExpiration = 0
-					end
-					if (ElementaristDB.Behavior == Elementarist.Behaviors["1"]) then
-						doFS = true
-					else	-- if fs before lvb, check lvb cd
-						d = Elementarist:GetSpellCooldownRemaining(Elementarist.SpellList["Lava Burst"])
-						if (d) and (d <= (timeshift + Elementarist.lastBaseGCD)) then
-							doFS = true
-						end
-					end
-					if (doFS) and ((fsExpiration - GetTime() - timeshift) < 2 * Elementarist.lastBaseGCD) then
-						return Elementarist.SpellList["Flame Shock"]
-					end
-				end
-			end
-		end
-
+		-- 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) then
 			d = Elementarist:GetSpellCooldownRemaining(Elementarist.SpellList["Earth Shock"])
 			if ( (d) and ((d-timeshift) <= 0) and (lscount) and (lscount>=20)) then
@@ -203,35 +222,29 @@ Elementarist.elemental = {
 			end
 		end

-		-- Flame shock if 2 stacks Elemental Fussion and Unleashed Flame buff active
+		-- Priority 3
+		-- 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) then
 			d = Elementarist:GetSpellCooldownRemaining(Elementarist.SpellList["Flame Shock"])
 			if ((d - timeshift) <= 0) then
-				if (
-				   (efCount==2) and
-				   (Elementarist:hasBuff("player",Elementarist.SpellList["Unleash Flame"]) or Elementarist:Count(Elementarist.SpellList["Unleash Flame"],spellInCast,exspell1,exspell2) > 0) and 					   (fsExpiration - currentTime - timeshift) < (fsDuration * fsRefreshPercentage )
-				   ) then
-					return Elementarist.SpellList["Flame Shock"]
+				if (efCount==2) then
+					if (Elementarist:hasBuff("player",Elementarist.SpellList["Unleash Flame"]) or Elementarist:Count(Elementarist.SpellList["Unleash Flame"],spellInCast,exspell1,exspell2) > 0)then
+						if (fsExpiration - currentTime - timeshift) < (fsDuration * fsRefreshPercentage ) then
+							return Elementarist.SpellList["Flame Shock"]
+						end
+					end
 				end
 			end
 		end

+		-- Priority 4
 		-- Lava Burst if not on Cooldown
-		local ascendance, _, _, _, _, _, ascendanceExp = Elementarist:hasBuff("player",Elementarist.SpellList["AscendanceElementalBuff"]);
-		if (ascendance == nil) then
-			ascendanceExp = 0
-		end
-		local lvbCharges, maxLvbCharges, cdStart, cdLength  = GetSpellCharges(Elementarist.SpellList["Lava Burst"]);
-		if (lvbCharges<maxLvbCharges) and (((cdStart + cdLength)- GetTime()) - timeshift <= 0) then
-			lvbCharges = lvbCharges + 1;
-		end
-		lvbCharges = lvbCharges - Elementarist:Count(Elementarist.SpellList["Lava Burst"],spellInCast,exspell1,exspell2);
+		-- lava_burst,if=dot.flame_shock.remains>cast_time

-		if (
-			(lvbCharges > 0)
-			or
-			((ascendanceExp-GetTime()-timeshift) > 0)
-		) then
+
+		if ( (lvbCharges > 0) or((ascendanceExp-GetTime()-timeshift) > 0)  )then
 			if (IsSpellInRange(Elementarist.SpellList["Flame Shock"], "target") == 1) and
 			(
 				((fsExpiration~=0) and ((fsExpiration-GetTime()-timeshift) > LvBct)) or
@@ -243,8 +256,10 @@ Elementarist.elemental = {
 				end
 			end
 		end
-
+
+		-- 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) then
 			if ( (fsExpiration - GetTime() - timeshift) > Elementarist.lastShockCD ) then
 				d = Elementarist:GetSpellCooldownRemaining(Elementarist.SpellList["Earth Shock"])
@@ -260,7 +275,9 @@ Elementarist.elemental = {
 			end
 		end

-		-- refresh FS at 30% duration
+		-- 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) then
 				d = Elementarist:GetSpellCooldownRemaining(Elementarist.SpellList["Flame Shock"])
 			if ((d - timeshift) <= 0) then
@@ -271,7 +288,9 @@ Elementarist.elemental = {
 		end


+		-- Priority 7
 		-- 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
@@ -284,29 +303,52 @@ Elementarist.elemental = {
 			end
 		end

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

+		-- Priority 9
+		-- If Tier6 talent is Unleashed Fury cast Unleash Flame or (buffs & cooldowns & reamaining time are correct)
+		-- Unleash_flame,if=talent.unleashed_fury.enabled&!buff.ascendance.up|(talent.elemental_fusion.enabled&buff.elemental_fusion.stack=2&(dot.flame_shock.remains)<(dot.flame_shock.duration*(0.3+t18_class_trinket*(0.48+talent.unleashed_fury.enabled*0.22)))&cooldown.flame_shock.remains<gcd)

-		-- if Tier6 talent is Unleashed Fury cast Unleash Flame
-		if (UFTalent)  or
+
+		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) then
-				e = Elementarist:GetSpellCooldownRemaining(Elementarist.SpellList["Unleash Flame"])
-				if (e-timeshift <= 0) then
+				d = Elementarist:GetSpellCooldownRemaining(Elementarist.SpellList["Unleash Flame"])
+				if (d-timeshift <= 0) then
 					return Elementarist.SpellList["Unleash Flame"];
 				end
 			end
 		end


+		-- Priority 9b (optional)
+		-- if item level >575 and Earthquake is enabled
+		if (ElementaristDB.EnableEQ) then
+			if (Elementarist.iLvl>=575) or (Elementarist.person["foeCount"]>1) then
+				local eqCharges, maxEqCharges, cdStart, cdLength  = GetSpellCharges(Elementarist.SpellList["Earthquake"]);
+				if (eqCharges<maxEqCharges) and (((cdStart + cdLength)- GetTime()) - timeshift <= 0) then
+					eqCharges = eqCharges + 1;
+				end
+				eqCharges = eqCharges - Elementarist:Count(Elementarist.SpellList["Earthquake"],spellInCast,exspell1,exspell2);
+				eclBuff, _, _, _, _, _, eclExp = Elementarist:hasBuff("player",Elementarist.SpellList["EnhancedChainLightningBuff"]);
+						if (eqCharges > 0) and (eclBuff) then
+					d = Elementarist:GetSpellCooldownRemaining(Elementarist.SpellList["Earthquake"])
+					if (d) and (d<0.5) then
+						return Elementarist.SpellList["Earthquake"]
+					end
+				end
+			end
+		end
+

+		-- Priority 10
 		-- otherwise lightning bolt
 		if IsSpellInRange(Elementarist.SpellList["Lightning Bolt"], "target") == 1 then
 			return Elementarist.SpellList["Lightning Bolt"]
@@ -486,7 +528,7 @@ Elementarist.elemental = {
 				if ( (status) and (threatpct>80) and (Elementarist.person["friendCount"]>1) and (Elementarist.inParty>0)) then
 					return Elementarist.SpellList["Wind Shear"]
 				end
-
+
 				--- windshear to interupt channel spell
 				spell, _, _, _, _, _, _, notInterruptible = UnitChannelInfo("target")
 				if (spell) and (not notInterruptible) then