Quantcast

Broker plugin now has options to announce stats to chat.

F16Gaming [09-02-12 - 19:45]
Broker plugin now has options to announce stats to chat.

Fixed issue with KillTrack.ResetSession.
Filename
Broker.lua
KillTrack.lua
Tools.lua
diff --git a/Broker.lua b/Broker.lua
index e184201..b298fa4 100644
--- a/Broker.lua
+++ b/Broker.lua
@@ -26,18 +26,12 @@ KT.Broker = {
 	}
 }

+local KTT = KillTrack_Tools
 local KTB = KT.Broker

 local UPDATE = 1
 local t = 0

-local function FormatSeconds(seconds)
-	local hours = floor(seconds / 3600)
-	local minutes = floor(seconds / 60) - hours * 60
-	local seconds = seconds - minutes * 60 - hours * 3600
-	return ("%02d:%02d:%02d"):format(hours, minutes, seconds)
-end
-
 local ldb = LibStub:GetLibrary("LibDataBroker-1.1")

 local frame = CreateFrame("Frame")
@@ -51,16 +45,25 @@ local data = {
 	tocname = KT.Name
 }

-local obj = ldb:NewDataObject("Broker_KillTrack", data)
-
--- Debug
+local clickFunctions = {
+	ctrl = {
+		LeftButton = function() KT:Announce("GROUP") end, -- Announce to group/say
+		RightButton = function() KT:Announce("GUILD") end -- Announce to guild
+	},
+	none = {
+		LeftButton = function() KT.MobList:ShowGUI() end,
+		MiddleButton = function() KTB:ToggleTextMode() end,
+		RightButton = function() KT:ResetSession() end
+	}
+}

+local obj = ldb:NewDataObject("Broker_KillTrack", data)

 function obj:OnTooltipShow()
 	self:AddLine(("%s |cff00FF00(%s)|r"):format(KT.Name, KT.Version), 1, 1, 1)
 	self:AddLine(" ")
 	local _, kpm, kph, length = KT:GetSessionStats()
-	self:AddDoubleLine("Session Length", ("|cffFFFFFF%s|r"):format(FormatSeconds(length)))
+	self:AddDoubleLine("Session Length", ("|cffFFFFFF%s|r"):format(KTT:FormatSeconds(length)))
 	self:AddDoubleLine("Kills Per Minute", ("|cffFFFFFF%.2f|r"):format(kpm))
 	self:AddDoubleLine("Kills Per Hour", ("|cffFFFFFF%.2f|r"):format(kph))
 	self:AddLine(" ")
@@ -88,16 +91,15 @@ function obj:OnTooltipShow()
 	self:AddDoubleLine("Left Click", "Open mob database", 0, 1, 0, 0, 1, 0)
 	self:AddDoubleLine("Middle Click", "Toggle short/long text", 0, 1, 0, 0, 1, 0)
 	self:AddDoubleLine("Right Click", "Reset session statistics", 0, 1, 0, 0, 1, 0)
+	self:AddDoubleLine("Ctrl + Left Click", "Announce to group/say", 0, 1, 0, 0, 1, 0)
+	self:AddDoubleLine("Ctrl + Right Click", "Announce to guild", 0, 1, 0, 0, 1, 0)
 end

 function obj:OnClick(button)
-	if button == "LeftButton" then
-		KT.MobList:ShowGUI()
-	elseif button == "MiddleButton" then
-		KTB:ToggleTextMode()
-	elseif button == "RightButton" then
-		KT:ResetSession()
-	end
+	local mod = ((IsControlKeyDown() and "ctrl") or (IsShiftKeyDown() and "shift")) or "none"
+	if not clickFunctions[mod] then return end
+	local func = clickFunctions[mod][button]
+	if func then func() end
 end

 function obj:OnEnter()
diff --git a/KillTrack.lua b/KillTrack.lua
index 4764397..7799869 100644
--- a/KillTrack.lua
+++ b/KillTrack.lua
@@ -37,6 +37,9 @@ KillTrack = {
 	Session = {
 		Count = 0,
 		Kills = {}
+	},
+	Messages = {
+		Announce = "[KillTrack] Session Length: %s. Session Kills: %d. Kills Per Minute: %.2f."
 	}
 }

@@ -229,7 +232,7 @@ end
 function KT:ResetSession()
 	wipe(self.Session.Kills)
 	self.Session.Count = 0
-	self.Session.Start = time() / 60
+	self.Session.Start = time()
 end

 function KT:GetKills(id)
@@ -289,6 +292,15 @@ function KT:PrintKills(identifier)
 	end
 end

+function KT:Announce(target)
+	if target == "GROUP" then
+		target = ((IsInRaid() and "RAID") or (IsInGroup() and "PARTY")) or "SAY"
+	end
+	local _, kpm, _, length = self:GetSessionStats()
+	local msg = self.Messages.Announce:format(KTT:FormatSeconds(length), self.Session.Count, kpm)
+	SendChatMessage(msg, target)
+end
+
 function KT:Msg(msg)
 	DEFAULT_CHAT_FRAME:AddMessage("\124cff00FF00[KillTrack]\124r " .. msg)
 end
diff --git a/Tools.lua b/Tools.lua
index f18cb61..bdd43ec 100644
--- a/Tools.lua
+++ b/Tools.lua
@@ -22,6 +22,17 @@ KillTrack_Tools = {}
 local KTT = KillTrack_Tools

 ------------------
+-- NUMBER TOOLS --
+------------------
+
+function KTT:FormatSeconds(seconds)
+	local hours = floor(seconds / 3600)
+	local minutes = floor(seconds / 60) - hours * 60
+	local seconds = seconds - minutes * 60 - hours * 3600
+	return ("%02d:%02d:%02d"):format(hours, minutes, seconds)
+end
+
+------------------
 -- STRING TOOLS --
 ------------------