From b703d60a5ce05bdfbb0256c1f30dd2d9b33e0909 Mon Sep 17 00:00:00 2001
From: Tercio Jose <terciob19@hotmail.com>
Date: Mon, 21 Dec 2020 14:23:37 -0300
Subject: [PATCH] Added mythic dungeon settings

---
 Libs/DF/spells.lua                     |  4 +-
 Libs/LibRaidStatus/LibRaidStatus.lua   |  2 +-
 Libs/LibRaidStatus/ThingsToMantain.lua |  9 +--
 classes/class_combat.lua               |  2 +-
 core/gears.lua                         |  8 ++-
 core/parser.lua                        |  8 ++-
 frames/window_options2.lua             |  6 +-
 frames/window_options2_sections.lua    | 86 ++++++++++++++++++++++++++
 functions/profiles.lua                 |  2 +-
 functions/spells.lua                   | 11 +---
 10 files changed, 115 insertions(+), 23 deletions(-)

diff --git a/Libs/DF/spells.lua b/Libs/DF/spells.lua
index 45c5f529a..cdf5bf344 100644
--- a/Libs/DF/spells.lua
+++ b/Libs/DF/spells.lua
@@ -768,9 +768,9 @@ DF.CrowdControlSpells = {
 	[50259] = "DRUID", --Dazed (from Wild Charge)
 	[209753] = "DRUID", --Cyclone (from pvp talent)
 	[33786] = "DRUID", --Cyclone (from pvp talent - resto druid)
+	[155722] = "DRUID", --Rake
 	
-    [3355] = "HUNTER", --Freezing Trap
-	[3355] = "HUNTER", --Diamond Ice (from pvp talent)
+    [3355] = "HUNTER", --Freezing Trap / Diamond Ice (from pvp talent)
 	[19577] = "HUNTER", --Intimidation
 	[190927] = "HUNTER", --Harpoon
 	[162480] = "HUNTER", --Steel Trap
diff --git a/Libs/LibRaidStatus/LibRaidStatus.lua b/Libs/LibRaidStatus/LibRaidStatus.lua
index 981b0b2f8..40ccc0a9a 100644
--- a/Libs/LibRaidStatus/LibRaidStatus.lua
+++ b/Libs/LibRaidStatus/LibRaidStatus.lua
@@ -1,6 +1,6 @@
 
 local major = "LibRaidStatus-1.0"
-local CONST_LIB_VERSION = 10
+local CONST_LIB_VERSION = 11
 LIB_RAID_STATUS_CAN_LOAD = false
 
 --declae the library within the LibStub
diff --git a/Libs/LibRaidStatus/ThingsToMantain.lua b/Libs/LibRaidStatus/ThingsToMantain.lua
index 556f907d1..3cd22a5f7 100644
--- a/Libs/LibRaidStatus/ThingsToMantain.lua
+++ b/Libs/LibRaidStatus/ThingsToMantain.lua
@@ -214,7 +214,7 @@ LIB_RAID_STATUS_COOLDOWNS_BY_SPEC = {
 			[104773] = 2, --Unending Resolve
 			[108416] = 2, --Dark Pact (talent)
 			[30283] = 5, --Shadowfury
-			[6789] = 5, --Mortal Coil (talent)
+			--[6789] = 5, --Mortal Coil (talent)
 			[333889] = 5, --Fel Domination
 		},
 		--demonology
@@ -229,7 +229,7 @@ LIB_RAID_STATUS_COOLDOWNS_BY_SPEC = {
 			[108416] = 2, --Dark Pact (talent)
 			
 			[30283] = 5, --Shadowfury
-			[6789] = 5, --Mortal Coil (talent)
+			--[6789] = 5, --Mortal Coil (talent)
 			[5484] = 5, --Howl of Terror (talent)
 			[333889] = 5, --Fel Domination
 		},
@@ -240,7 +240,7 @@ LIB_RAID_STATUS_COOLDOWNS_BY_SPEC = {
 			[113858] = 1, --Dark Soul: Instability (talent)
 			[104773] = 2, --Unending Resolve
 			[108416] = 2, --Dark Pact (talent)
-			[6789] = 5, --Mortal Coil (talent)
+			--[6789] = 5, --Mortal Coil (talent)
 			[30283] = 5, --Shadowfury
 			[333889] = 5, --Fel Domination
 		},
@@ -619,7 +619,8 @@ LIB_RAID_STATUS_COOLDOWNS_INFO = {
 	[113858] = {cooldown = 120, duration = 20, talent = 23092, charges = 1, class = "WARLOCK", type = 1}, --Dark Soul: Instability (talent)
 	[30283] = {cooldown = 60, duration = 3, talent = false, charges = 1, class = "WARLOCK", type = 5}, --Shadowfury
 	[333889] = {cooldown = 180, duration = 15, talent = false, charges = 1, class = "WARLOCK", type = 5}, --Fel Domination
-	
+	--[6789] = {cooldown = 45, duration = 3, talent = 19291, charges = 1, class = "WARLOCK", type = 5}, --Mortal Coil (talent)
+
 	--> shaman
 	[198067] = {cooldown = 150, duration = 30, talent = false, charges = 1, class = "SHAMAN", type = 1}, --Fire Elemental
 	[192249] = {cooldown = 150, duration = 30, talent = 19272, charges = 1, class = "SHAMAN", type = 1}, --Storm Elemental (talent)
diff --git a/classes/class_combat.lua b/classes/class_combat.lua
index a7c6cfea0..f9cf2d476 100644
--- a/classes/class_combat.lua
+++ b/classes/class_combat.lua
@@ -411,7 +411,7 @@
 				tremove(container._ActorTable, index)
 
 				--remap
-				self:Remap()
+				container:Remap()
 			end
 		end
 	end
diff --git a/core/gears.lua b/core/gears.lua
index ba2bfa17f..29dac3ce6 100644
--- a/core/gears.lua
+++ b/core/gears.lua
@@ -1536,6 +1536,9 @@ function Details.Database.StoreWipe(combat)
 	
 	--database
 		local db = Details.Database.LoadDB()
+		if (not db) then
+			return
+		end
 
 		local diff_storage = db [diff]
 		if (not diff_storage) then
@@ -1604,7 +1607,10 @@ function Details.Database.StoreEncounter(combat)
 	
 	--database
 		local db = Details.Database.LoadDB()
-
+		if (not db) then
+			return
+		end
+		
 		local diff_storage = db [diff]
 		if (not diff_storage) then
 			db [diff] = {}
diff --git a/core/parser.lua b/core/parser.lua
index 75d627e51..0208e3810 100755
--- a/core/parser.lua
+++ b/core/parser.lua
@@ -711,6 +711,12 @@
 			alvo_name = alvo_name .. " <" .. alvo_dono.nome .. ">"
 		
 		end
+
+		if (not jogador_alvo) then
+			local instanceName, _, _, _, _, _, _, instanceId = GetInstanceInfo()
+			Details:Msg("Report 0x885488", alvo_name, instanceName, instanceId, damage_cache[alvo_serial] and "true")
+			return
+		end
 		
 		--> last event
 		este_jogador.last_event = _tempo
@@ -4527,7 +4533,7 @@ local SPELL_POWER_PAIN = SPELL_POWER_PAIN or (PowerEnum and PowerEnum.Pain) or 1
 			return
 		end
 
-		--> leave the current combat when the encounter start, if is doing a mythic plus dungeons, check if the options alows to create a dedicated segment for the boss fight
+		--> leave the current combat when the encounter start, if is doing a mythic plus dungeons, check if the options allows to create a dedicated segment for the boss fight
 		if ((_in_combat and not _detalhes.tabela_vigente.is_boss) and (not _detalhes.MythicPlus.Started or _detalhes.mythic_plus.boss_dedicated_segment)) then
 			_detalhes:SairDoCombate()
 		end
diff --git a/frames/window_options2.lua b/frames/window_options2.lua
index 413647a55..0559e5111 100644
--- a/frames/window_options2.lua
+++ b/frames/window_options2.lua
@@ -210,12 +210,14 @@ function Details.options.InitializeOptionsWindow(instance)
         [16] = Loc ["STRING_OPTIONSMENU_SPELLS"],
         [17] = Loc ["STRING_OPTIONSMENU_DATACHART"],
 
+        [18] = "Mythic Dungeon",
+
     }
 
     local optionsSectionsOrder = {
-        1, "", 3, 4, "", 5, 6, 7, 12, 13, "", 9, 2, 8, 10, 11, "", 14, 15, 16, 17--, 18, 19
+        1, "", 3, 4, "", 5, 6, 7, 12, 13, "", 9, 2, 8, 10, 11, 18, "", 14, 15, 16, 17--, 18, 19
     }
-    local maxSectionIds = 17
+    local maxSectionIds = 18
     Details.options.maxSectionIds = maxSectionIds
 
     local buttonYPosition = -40
diff --git a/frames/window_options2_sections.lua b/frames/window_options2_sections.lua
index 82fefeb1f..daefda778 100644
--- a/frames/window_options2_sections.lua
+++ b/frames/window_options2_sections.lua
@@ -22,6 +22,7 @@ end
     ~15 - broadcaster
     ~16 - custom spells
     ~17 - charts data
+    ~18 - mythic dungeon
 --]]
 
 
@@ -6253,6 +6254,91 @@ do
     tinsert(Details.optionsSection, buildSection)
 end
 
+do
+    local buildSection = function(sectionFrame)
+
+        local sectionOptions = {
+            {type = "label", get = function() return Loc["STRING_OPTIONS_GENERAL_ANCHOR"] end, text_template = subSectionTitleTextTemplate},
+            {--always in combat
+                type = "toggle",
+                get = function() return Details.mythic_plus.always_in_combat end,
+                set = function (self, fixedparam, value)
+                    Details.mythic_plus.always_in_combat = value
+                end,
+                name = "Always in Combat",
+                desc = "Details won't create new segments for trash or boss and treat the run as a single segment.",
+            },
+
+            {--dedicated segment for bosses
+                type = "toggle",
+                get = function() return Details.mythic_plus.boss_dedicated_segment end,
+                set = function (self, fixedparam, value)
+                    Details.mythic_plus.boss_dedicated_segment = value
+                end,
+                name = "Boss Dedicated Segment",
+                desc = "If a boss is pulled while in combat, Details! close the combat and start a new one for the boss.",
+            },
+
+            {--make overall when done
+                type = "toggle",
+                get = function() return Details.mythic_plus.make_overall_when_done end,
+                set = function (self, fixedparam, value)
+                    Details.mythic_plus.make_overall_when_done = value
+                end,
+                name = "Make Overall Segment",
+                desc = "When the run is done, make an overall segment.",
+            },
+
+            {--overall only with bosses
+                type = "toggle",
+                get = function() return Details.mythic_plus.make_overall_boss_only end,
+                set = function (self, fixedparam, value)
+                    Details.mythic_plus.make_overall_boss_only = value
+                end,
+                name = "Overall Segment Boss Only",
+                desc = "Only add boss segments on the overall.",
+            },
+
+            {--merge trash
+                type = "toggle",
+                get = function() return Details.mythic_plus.merge_boss_trash end,
+                set = function (self, fixedparam, value)
+                    Details.mythic_plus.merge_boss_trash = value
+                end,
+                name = "Merge Trash",
+                desc = "Merge Trash",
+            },
+
+            {--delete merged trash
+                type = "toggle",
+                get = function() return Details.mythic_plus.delete_trash_after_merge end,
+                set = function (self, fixedparam, value)
+                    Details.mythic_plus.delete_trash_after_merge = value
+                end,
+                name = "Delete Merged Trash Segments",
+                desc = "After have the segment merged, if this option is enabled it'll delete those merged segments.",
+            },            
+
+            {--show chart popup
+                type = "toggle",
+                get = function() return Details.mythic_plus.show_damage_graphic end,
+                set = function (self, fixedparam, value)
+                    Details.mythic_plus.show_damage_graphic = value
+                end,
+                name = "Show Damage Charts",
+                desc = "Show Damage Charts",
+            },
+
+
+        }
+
+        DF:BuildMenu(sectionFrame, sectionOptions, startX, startY-20, heightSize, true, options_text_template, options_dropdown_template, options_switch_template, true, options_slider_template, options_button_template)
+    end
+
+    tinsert(Details.optionsSection, buildSection)
+end
+
+
 --[[]
 do
     local buildSection = function(sectionFrame)
diff --git a/functions/profiles.lua b/functions/profiles.lua
index 2573e006b..713529f08 100644
--- a/functions/profiles.lua
+++ b/functions/profiles.lua
@@ -1303,7 +1303,7 @@ local default_global_data = {
 	--> mythic plus config
 		mythic_plus = {
 			always_in_combat = false, --
-			merge_boss_trash = false, --
+			merge_boss_trash = true, --
 			delete_trash_after_merge = true, --
 			--merge_boss_with_trash = false, --this won't be used
 			boss_dedicated_segment = true, --
diff --git a/functions/spells.lua b/functions/spells.lua
index bdc41fde0..e418266cc 100644
--- a/functions/spells.lua
+++ b/functions/spells.lua
@@ -512,9 +512,6 @@ do
 	[200025]        =       65,     --      Beacon of Virtue
 	[223306]        =       65,     --      Bestow Faith
 	[4987]  =       65,     --      Cleanse
-	[231667]        =       65,     --      Crusader Strike
-	[342348]        =       65,     --      Crusader Strike
-	[35395] =       65,     --      Crusader Strike
 	[196926]        =       65,     --      Crusader's Might
 	[498]   =       65,     --      Divine Protection
 	[325966]        =       65,     --      Glimmer of Light
@@ -546,7 +543,6 @@ do
 	[204019]        =       66,     --      Blessed Hammer
 	[229976]        =       66,     --      Blessed Hammer
 	[204018]        =       66,     --      Blessing of Spellwarding
-	[204054]        =       66,     --      Consecrated Ground
 	[204023]        =       66,     --      Crusader's Judgment
 	[204077]        =       66,     --      Final Stand
 	[203776]        =       66,     --      First Avenger
@@ -556,14 +552,13 @@ do
 	[337287]        =       66,     --      Hammer of the Righteous
 	[53595] =       66,     --      Hammer of the Righteous
 	[315924]        =       66,     --      Hand of the Protector
-	[152261]        =       66,     --      Holy Shield
 	[327193]        =       66,     --      Moment of Glory
 	[280373]        =       66,     --      Redoubt
 	[204074]        =       66,     --      Righteous Protector
 	[161800]        =       66,     --      Riposte
 	[321136]        =       66,     --      Shining Light
 
-
+	
 	-- Retribution Paladin:
 	[267344]        =       70,     --      Art of War
 	[317912]        =       70,     --      Art of War
@@ -574,15 +569,11 @@ do
 	[53385] =       70,     --      Divine Storm
 	[326732]        =       70,     --      Empyrean Power
 	[343527]        =       70,     --      Execution Sentence
-	[205191]        =       70,     --      Eye for an Eye
 	[343721]        =       70,     --      Final Reckoning
 	[203316]        =       70,     --      Fires of Justice
 	[183218]        =       70,     --      Hand of Hindrance
-	[326734]        =       70,     --      Healing Hands
 	[215661]        =       70,     --      Justicar's Vengeance
 	[267610]        =       70,     --      Righteous Verdict
-	[85804] =       70,     --      Selfless Healer
-	[184662]        =       70,     --      Shield of Vengeance
 	[85256] =       70,     --      Templar's Verdict
 	[255937]        =       70,     --      Wake of Ashes
 	[269569]        =       70,     --      Zeal