--COMBAT_LOG_EVENT_UNFILTERED UPDATE REMOVE PLAYER_ALIVE
function(e, ...)
	if e == "COMBAT_LOG_EVENT_UNFILTERED" then
		local se = select(2, ...)
		if se == "UNIT_DIED" then
			local name = select(9, ...)
			if name:match(aura_env.farmanimal) then
				local date = date()
				local h, m, s = date:match("%w+ %w+ %d* (%d*)%:(%d*)%:(%d*)") or 0, 0, 0
				WeakAurasSaved.CustomTrash.Farm[aura_env.farmanimal][#WeakAurasSaved.CustomTrash.Farm[aura_env.farmanimal] + 1] = {["h"] = h, ["m"] = m, ["s"] = s}
				WeakAurasSaved.CustomTrash.Farm[aura_env.farmanimal].Count = WeakAurasSaved.CustomTrash.Farm[aura_env.farmanimal].Count + 1
				return true
			end
		end
	elseif e == "UPDATE" then
		return true
	elseif e == "REMOVE" then
		for i = 1, #WeakAurasSaved.CustomTrash.Farm[aura_env.farmanimal] do
			WeakAurasSaved.CustomTrash.Farm[aura_env.farmanimal][i] = nil
		end
		return true
	elseif e == "PLAYER_ALIVE" and IsInInstance() == false then
		ResetInstances()
		return true
	end
end

--DISPLAY
function()
	local output = #WeakAurasSaved.CustomTrash.Farm[aura_env.farmanimal] .. " " .. WeakAurasSaved.CustomTrash.Farm[aura_env.farmanimal].Count .. " " .. WeakAurasSaved.CustomTrash.Farm[aura_env.farmanimal].Count * aura_env.prob .. "%\n"
	local date = date()
	local h, m, s = date:match("%w+ %w+ %d* (%d*)%:(%d*)%:(%d*)") or 0, 0, 0
	for k,v in ipairs(WeakAurasSaved.CustomTrash.Farm[aura_env.farmanimal]) do
		output = output .. v.h .. ":" .. v.m .. ":" .. v.s .. " -" .. aura_env.round((s - v.s + (m - v.m) * 60 + (h - v.h) * 3600) / 60, 0)  .. "m" .. "\n"
	end
	return output
end

--INIT
aura_env.farmanimal = "Altairus"
aura_env.prob = 0.8
if not WeakAurasSaved.CustomTrash.Farm[aura_env.farmanimal] then WeakAurasSaved.CustomTrash.Farm[aura_env.farmanimal] = {}; WeakAurasSaved.CustomTrash.Farm[aura_env.farmanimal].Count = 0 end
aura_env.ticker = C_Timer.NewTicker(10, function() WeakAuras.ScanEvents("UPDATE") end)
if WeakAuras.IsOptionsOpen() then
	aura_env.ticker:Cancel()
end
aura_env.round = function(var, n)
	if (n) then
		var = math.floor((var * 10^n) + 0.5) / (10^n)
	else
		var = math.floor(var+0.5)
	end
	return var
end