-- 提醒换装
	local framenoss = CreateFrame("Frame")
	framenoss:RegisterEvent("ZONE_CHANGED_NEW_AREA")
	framenoss:SetScript("OnEvent", function(self, event)
		if event ~= "ZONE_CHANGED_NEW_AREA" or not IsInInstance() then return end
		local spec = GetSpecialization()
		if not spec then return NONE, NONE end
		local _, TalentName = GetSpecializationInfo(spec)
		RaidNotice_AddMessage(RaidWarningFrame, "你现在的天赋是 |cffEE3A8C(".. TalentName.. ")|r, 请检查|cff00FF00装备|r是否符合", ChatTypeInfo["RAID_WARNING"])
		--ElvUIAlertRun("你现在的天赋是 |cffEE3A8C(".. TalentName.. ")|r, 请检查|cff00FF00装备|r是否符合", 0, 1, 1)
		DEFAULT_CHAT_FRAME:AddMessage(string.format("你现在的天赋是 |cffEE3A8C(".. TalentName.. ")|r, 请检查|cff00FF00装备|r是否符合."), 0, 1, 1)
	end)
	

--[[------------------------     HideFishingBobberTooltip     -----------------------------------
local HideFishingBobberTooltip = CreateFrame("Frame")
HideFishingBobberTooltip:RegisterEvent("PLAYER_LOGIN")
HideFishingBobberTooltip:SetScript("OnEvent", function()
  local Fish = {
    deDE = "Angelschwimmer",
    enUS = "Fishing Bobber",
    esES = "Corcho de pesca",
    frFR = "Flotteur",
    ptBR = "Flutador para Pesca",
    ruRU = "Поплавок",
    -- itIT = "",
    -- esMX = "",
    -- koKR = "",
    zhCN = "鱼漂",
    zhTW = "魚漂",
  }
  GameTooltip:HookScript("OnShow", function()
    local tooltipText = GameTooltipTextLeft1
    if tooltipText and tooltipText:GetText() == Fish[GetLocale()] then GameTooltip:Hide() end
  end)
end)]]

--------------------- Bag Space Checker Created by BrknSoul on 17th January 2014 --
--Frame creation and event registration
local frameBSC=CreateFrame("FRAME")
--frameBSC:RegisterEvent("BAG_UPDATE_DELAYED")
frameBSC:RegisterEvent("BAG_UPDATE")
frameBSC:SetScript("OnEvent",function(self)  --Event Handlers
    local BSCSpace = 0
    for i=0,NUM_BAG_SLOTS do 
      BSCSpace = BSCSpace + C_Container.GetContainerNumFreeSlots(i)
    end
    if BSCSpace <= 8 then
      --SendChatMessage(REMINDER_BAGS_SPACE..BSCSpace,"SAY")
      --RaidNotice_AddMessage(RaidWarningFrame, REMINDER_BAGS_SPACE..BSCSpace, ChatTypeInfo["RAID_WARNING"])
      UIErrorsFrame:AddMessage(REMINDER_BAGS_SPACE..BSCSpace)
      elseif BSCSpace <= 8 then
      --PlaySoundFile(540594, "Master")  --"Sound\\SPELLS\\SPELL_Treasure_Goblin_Coin_Toss_09.OGG"
    end
end)

--------------------------------------------------------------------------- m4xLegendary
local m4xLegendary = CreateFrame("Frame")
m4xLegendary:RegisterEvent("SHOW_LOOT_TOAST_LEGENDARY_LOOTED")
m4xLegendary:SetScript("OnEvent", function(self) PlaySoundFile("Interface\\AddOns\\OrzUI\\Media\\Sounds\\Legendary.ogg", "Master") end)

--[[--- only replace the function when the achievement frame is opened (before that it doesn't exist)
local AchievementDisplayFrame = CreateFrame("Frame")
AchievementDisplayFrame:RegisterEvent("ADDON_LOADED")
AchievementDisplayFrame:SetScript("OnEvent", function (self, event, arg)
	if arg == "Blizzard_AchievementUI" then
			local originalDisplayAchievement = AchievementButton_DisplayAchievement
	function AchievementButton_DisplayAchievement(button, category, achievement, selectionID, renderOffScreen)
		originalDisplayAchievement(button, category, achievement, selectionID, renderOffScreen)
		local id, name, points, completed, month, day, year, description, flags, icon, rewardText, isGuild, wasEarnedByMe, earnedBy = GetAchievementInfo(category, achievement);
		if ( completed and not wasEarnedByMe ) then
			--- if an achievement was not earned by this char, hide the date completed and show the shield as grey
			button.dateCompleted:Hide();
			button:Desaturate();
		end
		return id
	end 
	end
end)]]


local CombatNotificationAlertFrame = CreateFrame("Frame", "CombatNotificationAlertFrame", UIParent)
CombatNotificationAlertFrame:RegisterEvent("PLAYER_REGEN_ENABLED")
CombatNotificationAlertFrame:RegisterEvent("PLAYER_REGEN_DISABLED")
CombatNotificationAlertFrame:SetSize(360, 43)
CombatNotificationAlertFrame:SetPoint("TOP", 0, -260)
CombatNotificationAlertFrame.Bg = CombatNotificationAlertFrame:CreateTexture(nil, "BACKGROUND")
CombatNotificationAlertFrame.Bg:SetTexture("Interface\\LEVELUP\\MinorTalents")
CombatNotificationAlertFrame.Bg:SetPoint("TOP")
CombatNotificationAlertFrame.Bg:SetSize(380, 42)
CombatNotificationAlertFrame.Bg:SetTexCoord(0, 400 / 512, 341 / 512, 407 / 512)
CombatNotificationAlertFrame.Bg:SetVertexColor(1, 1, 1, 0.4)
CombatNotificationAlertFrame.text = CombatNotificationAlertFrame:CreateFontString(nil, "OVERLAY")  --ARTWORK", "GameFont_Gigantic"
CombatNotificationAlertFrame.text:SetFont(GameFontNormal:GetFont(), 26, 'OUTLINE')	-- 字体
CombatNotificationAlertFrame.text:SetShadowOffset(0,0)
CombatNotificationAlertFrame.text:SetPoint("CENTER")
CombatNotificationAlertFrame:Hide()
CombatNotificationAlertFrame:SetScript("OnShow", function()
    CombatNotificationAlertFrame.totalTime = 0.8
    CombatNotificationAlertFrame.timer = 0
end)
CombatNotificationAlertFrame:SetScript("OnUpdate", function(self, elapsed)
    CombatNotificationAlertFrame.timer = CombatNotificationAlertFrame.timer + elapsed
    if (CombatNotificationAlertFrame.timer > CombatNotificationAlertFrame.totalTime) then CombatNotificationAlertFrame:Hide() end
    --if (CombatNotificationAlertFrame.timer <= 0.6) then
        --CombatNotificationAlertFrame:SetAlpha(CombatNotificationAlertFrame.timer * 2)
    --elseif (CombatNotificationAlertFrame.timer > 0.8) then
        --CombatNotificationAlertFrame:SetAlpha(1 - CombatNotificationAlertFrame.timer / CombatNotificationAlertFrame.totalTime)
    --end
end)
CombatNotificationAlertFrame:SetScript("OnEvent", function(self, event)
    CombatNotificationAlertFrame:Hide()
    if (event == "PLAYER_REGEN_DISABLED") then
        CombatNotificationAlertFrame.text:SetText("|cFFFF0000"..COMBATNOTIFICATIONINFO_combat_enter.."|r")
    elseif (event == "PLAYER_REGEN_ENABLED") then
        CombatNotificationAlertFrame.text:SetText("|cff00ff00"..COMBATNOTIFICATIONINFO_combat_leave.."|r")
    end
    CombatNotificationAlertFrame:Show()
end)

--[[PetHealthAlarm------------------## Version: 1.2 ## Author: Dephotian
local PetHealthAlarm = CreateFrame("ScrollingMessageFrame", "PetHealthAlarm", UIParent)
PetHealthAlarm.Warned = false
PetHealthAlarm:RegisterEvent("PLAYER_LOGIN")
PetHealthAlarm:RegisterEvent("UNIT_HEALTH")
PetHealthAlarm:SetScript("OnEvent", function(self, event, Arg1, ...)
    if(event == "PLAYER_LOGIN") then
        PetHealthAlarm:SetWidth(450)
        PetHealthAlarm:SetHeight(200)
        PetHealthAlarm:SetPoint("CENTER", UIParent, "CENTER", 0, 120)
        PetHealthAlarm:SetFont("Interface\\AddOns\\OrzUI\\Media\\Fonts\\RedCircl.TTF",36,"THICKOUTLINE")
        PetHealthAlarm:SetShadowColor(0.00, 0.00, 0.00, 0.75)
        PetHealthAlarm:SetShadowOffset(3.00, -3.00)
        PetHealthAlarm:SetJustifyH("CENTER")
        PetHealthAlarm:SetMaxLines(2)
        PetHealthAlarm:SetTimeVisible(2)
        PetHealthAlarm:SetFadeDuration(1)
        return
    end
    if(event == "UNIT_HEALTH" and Arg1 == "pet") then
        if(floor((UnitHealth("pet") / UnitHealthMax("pet")) * 100) <= 40 and PetHealthAlarm.Warned == false) then
			PlaySoundFile("Interface\\AddOns\\OrzUI\\Media\\Sounds\\Beep.ogg")	
			--UIErrorsFrame:AddMessage("|cFFFF0000".."- CRITICAL PET HEALTH -")
			--RaidNotice_AddMessage(RaidWarningFrame, "|cFFFF0000".."- CRITICAL PET HEALTH -", ChatTypeInfo["RAID_WARNING"])
        if (UnitName("pet") ~= "Pacifist Rig") then
        	PetHealthAlarm:AddMessage("|cFFFF0000".."- CRITICAL PET HEALTH -", 1, 0, 0, nil, 5)  ---- How long until message fades " - " .. petName .. " needs healing!"
        	PetHealthAlarm.Warned = true
        end
            return
        end
        if(floor((UnitHealth("pet") / UnitHealthMax("pet")) * 100) > 40) then PetHealthAlarm.Warned = false return end
        return
    end
end)]]
--[[------------------------------	Announce enemy drinking in arena(by Duffed)----------------------------------
local drinkSpell = {
	[C_Spell.GetSpellInfo(118358)] = true,	-- Drink
	[C_Spell.GetSpellInfo(167152)] = true,	-- Refreshment
	[C_Spell.GetSpellInfo(167268)] = true,	-- Ba'ruun's Bountiful Bloom
}

local AnenemyDrink = CreateFrame("Frame")
AnenemyDrink:RegisterEvent("UNIT_SPELLCAST_SUCCEEDED")
AnenemyDrink:SetScript("OnEvent", function(self, event, ...)
	if not (event == "UNIT_SPELLCAST_SUCCEEDED" and GetZonePVPInfo() == "arena") then return end
	local unit, _, spellID = ...
	if UnitIsEnemy("player", unit) and drinkSpell[C_Spell.GetSpellInfo(spellID)] then
		SendChatMessage(UnitClass(unit).." "..UnitName(unit)..TUTORIAL_TITLE11, "YELL")
	end
end)]]

--------------------------------	Kill count ----------------------------------
local NextLimit = { 100, 500, 1000, 5000, 10000, 25000, 50000, 100000,250000,500000,1000000 }
local GetNextLimit = function(kills)
	for i =1, #NextLimit do
		if kills < NextLimit[i] then return NextLimit[i]
		elseif kills >= NextLimit[#NextLimit] then return
		end
	end
end
local oldKills = GetPVPLifetimeStats()
UIErrorsFrame:SetScript("OnUpdate",function(self,elapsed)
	self.nextUpdate = 0 + elapsed
	if self.nextUpdate > 1 then
		local newTime = GetTime()
		local newKills = GetPVPLifetimeStats()
		if newKills > oldKills then
			self:AddMessage(string.format(PVPPP_KILL_MSG, newKills, GetNextLimit(newKills)),1,1,0,1)
			oldKills = newKills
		elseif newKills == NextLimit[#NextLimit] then
			self:SetScript("OnUpdate",nil)
		end
		self.nextUpdate = 0
	end
end)

--[[--------------------------------------------------------- KillingBlows---------------------------------------------------------
local KB_FILTER_ENEMY = bit.bor(
	COMBATLOG_OBJECT_AFFILIATION_PARTY,
	COMBATLOG_OBJECT_AFFILIATION_RAID,
	COMBATLOG_OBJECT_AFFILIATION_OUTSIDER,
	COMBATLOG_OBJECT_REACTION_NEUTRAL,
	COMBATLOG_OBJECT_REACTION_HOSTILE,
	COMBATLOG_OBJECT_CONTROL_PLAYER,
	COMBATLOG_OBJECT_TYPE_PLAYER
)
local Killmsg = CreateFrame("MessageFrame", "KilledItMessageFrame", UIParent)
Killmsg:SetWidth(512);
Killmsg:SetHeight(200);
Killmsg:SetPoint("TOP", 0, -200, "CENTER", 0, 200);
Killmsg:SetHeight(44)
Killmsg:SetInsertMode("TOP")
Killmsg:SetFrameStrata("HIGH")
Killmsg:SetTimeVisible(1.0)
Killmsg:SetFadeDuration(0.7)
Killmsg:SetScale(1.1)
Killmsg:SetFont(STANDARD_TEXT_FONT, 36, "OUTLINE")

local KillingBlows = CreateFrame("Frame") --Frame, nil, UIParent
KillingBlows:RegisterEvent("VARIABLES_LOADED")
KillingBlows:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
KillingBlows:SetScript("OnEvent", function(self, event, ...)
	if (event == "VARIABLES_LOADED") then self:UnregisterEvent("VARIABLES_LOADED")
	elseif (event == "COMBAT_LOG_EVENT_UNFILTERED") then
		local _, cmbEvent, _, sGUID, _, _, _, _, _, dFlag = select(1, ...)
		if (cmbEvent == "PARTY_KILL") then
			if (sGUID == UnitGUID("player") and CombatLog_Object_IsA(dFlag, KB_FILTER_ENEMY)) then
				PlaySoundFile("Interface\\Addons\\OrzUI\\Media\\Sounds\\Sonar.ogg", "Master")
				Killmsg:AddMessage("KILLING BLOW!", 1, 0, 0)
			end
		end
	end
end)

----------------------------------------------------------- DuelCountdown------------## Author: meribold   ## Version: 1.0.3
DuelCountdown = {_G = _G}
setfenv(1, DuelCountdown)

local DuelCountdown = _G.DuelCountdown
local string, math, table = _G.string, _G.math, _G.table
local pairs, ipairs = _G.pairs, _G.ipairs
local assert, select, print = _G.assert, _G.select, _G.print
local MAGIC_NUMBER = 3
local handlerFrame = _G.CreateFrame("Frame")

-- Value of GetTime() at the start of the countdown timer animation.
local startTime

function startTimer()
  assert(_G.TimerTracker)
  _G.TimerTracker_OnEvent(_G.TimerTracker, "PLAYER_ENTERING_WORLD")
  _G.GetPlayerFactionGroup = function()
    return "Neutral"
  end
  _G.TimerTracker_OnEvent(_G.TimerTracker, "START_TIMER", _G.TIMER_TYPE_PVP, 3, 3)
  _G.GetPlayerFactionGroup = DuelCountdown.GetPlayerFactionGroup
  startTime = _G.GetTime()
end

function stopTimer()
  assert(_G.TimerTracker)
  _G.TimerTracker_OnEvent(_G.TimerTracker, "PLAYER_ENTERING_WORLD")
end

function handlerFrame:ADDON_LOADED(name)
  self:UnregisterEvent("ADDON_LOADED")

  assert(_G.GetPlayerFactionGroup)
  GetPlayerFactionGroup = _G.GetPlayerFactionGroup

  handlerFrame:RegisterEvent("DUEL_REQUESTED")
  handlerFrame:RegisterEvent("DUEL_INBOUNDS")
  --handlerFrame:RegisterEvent("DUEL_OUTOFBOUNDS")
  handlerFrame:RegisterEvent("DUEL_FINISHED")
  handlerFrame:RegisterEvent("CHAT_MSG_SYSTEM")

  self.ADDON_LOADED = nil
end

function handlerFrame:DUEL_FINISHED()
  --print("DuelCountdown: handlerFrame:DUEL_FINISHED called")
  if startTime and _G.GetTime() - startTime < MAGIC_NUMBER then
    DuelCountdown.stopTimer()
    startTime = nil
  end
end

function handlerFrame:CHAT_MSG_SYSTEM(message, _, _, _, _, _, _, channelNumber)
  if string.find(message, _G.DUEL_COUNTDOWN) then
    if string.find(message, '3') then DuelCountdown.startTimer() end
  end
end

handlerFrame:SetScript("OnEvent", function(self, event, ...) return self[event] and self[event](self, ...) end)
handlerFrame:RegisterEvent("ADDON_LOADED")]]


--[[--------------------------------------------------------------------------------------
--	Auto cancel various buffs(by Unknown)
----------------------------------------------------------------------------------------
local function SpellName(id)
	local name = C_Spell.GetSpellInfo(id)
	if name then
		return name
	else
		print("|cffff0000BadBuffs spell ID ["..tostring(id).."] no longer exists!|r")
		return "Empty"
	end
end

local BadBuffs = {
	[SpellName(58493)] = true,	-- Mohawked!
	[SpellName(44212)] = true,	-- Jack-o'-Lanterned!
	[SpellName(61716)] = true,	-- Rabbit Costume
	[SpellName(172010)] = true,	-- Abomination Costume
	[SpellName(24732)] = true,	-- Bat Costume
	[SpellName(172015)] = true,	-- Geist Costume
	[SpellName(24735)] = true,	-- Ghost Costume
	[SpellName(172008)] = true,	-- Ghoul Costume
	[SpellName(24712)] = true,	-- Leper Gnome Costume
	[SpellName(24710)] = true,	-- Ninja Costume
	[SpellName(24709)] = true,	-- Pirate Costume
	[SpellName(24723)] = true,	-- Skeleton Costume
	[SpellName(172003)] = true,	-- Slime Costume
	[SpellName(172020)] = true,	-- Spider Costume
	[SpellName(24740)] = true,	-- Wisp Costume
	[SpellName(61781)] = true,	-- Turkey Feathers
	[SpellName(61734)] = true,	-- Noblegarden Bunny
}

local UnitBuff = function(unit, auraIndex, filter)
	return AuraUtil.UnpackAuraData(C_UnitAuras.GetBuffDataByIndex(unit, auraIndex, filter))
end

local frame = CreateFrame("Frame")
frame:RegisterEvent("UNIT_AURA")
frame:SetScript("OnEvent", function(_, event, unit)
	if event == "UNIT_AURA" and unit == "player" and not InCombatLockdown() then
		local i = 1
		while true do
			local name = UnitBuff(unit, i)
			if not name then return end
			if BadBuffs[name] then
				CancelSpellByName(name)
				print("|cffffff00"..ACTION_SPELL_AURA_REMOVED.." ["..name.."].|r")
			end
			i = i + 1
		end
	end
end)]]

--[[SimpleBattlefieldAlert  --## Author: cc27
local function CreateButton(name, label, func, point, relativeTo, relativePoint, offsetX, offsetY)
    local button = CreateFrame("Button", name, UIParent, "UIPanelButtonTemplate")
    button:SetSize(70, 50)
    button:SetPoint(point, relativeTo, relativePoint, offsetX, offsetY)

    local buttonText = button:CreateFontString(nil, "OVERLAY", "GameFontNormal")
    buttonText:SetPoint("CENTER")
    buttonText:SetText(label)
    buttonText:SetJustifyH("CENTER")
    buttonText:SetJustifyV("MIDDLE")

    button:SetMovable(true)
    button:EnableMouse(true)
    button:RegisterForDrag("LeftButton")
    button:SetScript("OnDragStart", function(self)
        if IsShiftKeyDown() then
            self:StartMoving()
        end
    end)
    button:SetScript("OnDragStop", function(self)
        self:StopMovingOrSizing()
    end)

    button:SetScript("OnClick", func)

    button:Hide() 
    return button
end

local function GetLocalizedText()
    local locale = GetLocale()
    if locale == "zhCN" then
        return "安全", "警报", "【%s】有%d个敌人！", "【%s】安全。"
    elseif locale == "zhTW" then
        return "安全", "警報", "【%s】有%d個敵人！", "【%s】安全。"
    else
        return "Safe", "Alert", "[%s] There are %d enemies!", "[%s] is safe."
    end
end


local safeText, alertText, alertMessageFormat, safeMessageFormat = GetLocalizedText()

local enemyCount, lastPressTime, alertDelay = 0, 0, 5
local function BattlefieldAlert()
    local currentTime = GetTime()
    if currentTime - lastPressTime > alertDelay then
        enemyCount = 0
    end
    enemyCount = enemyCount + 1
    lastPressTime = currentTime
    local playerSubZone = GetSubZoneText() or "Unknown Location"
    SendChatMessage(format(alertMessageFormat, playerSubZone, enemyCount), "INSTANCE_CHAT")
end

local function BattlefieldSafe()
    local playerSubZone = GetSubZoneText() or "Unknown Location"
    SendChatMessage(format(safeMessageFormat, playerSubZone), "INSTANCE_CHAT")
end

local forceShowButtons = false

local safeButton = CreateButton("SafeButton", safeText, BattlefieldSafe, "CENTER", UIParent, "CENTER", 300, -120)
local alertButton = CreateButton("AlertButton", alertText, BattlefieldAlert, "CENTER", UIParent, "CENTER", 370, -120)

local function UpdateButtonVisibility()
    if C_PvP.IsBattleground() or forceShowButtons then
        safeButton:Show()
        alertButton:Show()
    else
        safeButton:Hide()
        alertButton:Hide()
    end
end

SLASH_SIMPLEBA1 = '/SimpleBA'
SlashCmdList["SIMPLEBA"] = function(msg)
    if msg == "show" then
        forceShowButtons = true
        UpdateButtonVisibility()
    end
end

local frame = CreateFrame("Frame")
frame:RegisterEvent("PLAYER_ENTERING_WORLD")
frame:RegisterEvent("ZONE_CHANGED_NEW_AREA") 
frame:SetScript("OnEvent", function(self, event, ...)
    UpdateButtonVisibility()
end)]]

--[[----------------------------------------------ParagonBars  ## Version: 12.0.0  ## Author: Sanex (Arathor EU)
hooksecurefunc(ReputationFrame.ScrollBox, "Update", function(self, ...)
	local childFrames = { self.ScrollTarget:GetChildren() }
	for i = 1, #childFrames do
		if childFrames[i] and (not childFrames[i].elementData.isHeader) then -- Not all childFrames have ReputationBar in them, but all with a child named "Content" have it
			local factionID = childFrames[i].factionID -- https://www.townlong-yak.com/framexml/11.0.2/Blizzard_UIPanels_Game/ReputationFrame.lua#208
			local factionBar = childFrames[i].Content.ReputationBar -- https://www.townlong-yak.com/framexml/11.0.2/Blizzard_UIPanels_Game/ReputationFrame.lua#308

			if factionID and C_Reputation.IsFactionParagon(factionID) then
				local currentValue, threshold, _, hasRewardPending = C_Reputation.GetFactionParagonInfo(factionID)

				if currentValue then
					local value = mod(currentValue, threshold)
					if hasRewardPending then
						value = value + threshold
					end

					-- https://www.townlong-yak.com/framexml/11.0.2/Blizzard_UIPanels_Game/ReputationFrame.lua#656 / 665 / 662
					factionBar:UpdateBarValues(0, threshold, value)
					factionBar:UpdateBarProgressText(HIGHLIGHT_FONT_COLOR:WrapTextInColorCode(REPUTATION_PROGRESS_FORMAT:format(BreakUpLargeNumbers(value), BreakUpLargeNumbers(threshold))))
					factionBar:SetStatusBarColor(0.26, 0.42, 1)
				end
			end
		end
	end
end)]] -- If we don't hook to ScrollBox, the bar re-coloring gets borked when scrolling