-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCore.lua
More file actions
132 lines (113 loc) · 4.82 KB
/
Core.lua
File metadata and controls
132 lines (113 loc) · 4.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
-- my Ace3 Addon object
BGRaider = LibStub("AceAddon-3.0"):NewAddon("BGRaider", "AceConsole-3.0", "AceEvent-3.0", "AceComm-3.0");
local addon = BGRaider;
local AceGUI = LibStub("AceGUI-3.0");
local db = nil;
local addonQueued = nil;
local lastBGStatus = "";
-- EVENT HANDLERS --
function addon:OnInitialize()
-- pre-alpha for private testing only
--local guildName = GetGuildInfo("player");
--if(guildName ~= "The Returners") then return end;
self.db = LibStub("AceDB-3.0"):New("BGRaiderDB");
db = self.db.profile;
-- BG Raider Button
addon.guiButton = CreateFrame("Button", nil, PVPHonorFrame, "OptionsButtonTemplate");
addon.guiButton:SetPoint("BOTTOMRIGHT", 0, 0);
addon.guiButton:SetSize(108,22);
addon.guiButton:SetText("BG Raider");
addon.guiButton:SetScript("OnClick", function() BGRaider:OpenGui() end);
if(db.ready) then addon.guiButton:Enable(db.ready) else addon.guiButton:Disable(db.ready) end
-- Ready Check Button
addon.readyButton = CreateFrame("CheckButton", "BGRReadyCheck", PVPHonorFrame, "UICheckButtonTemplate");
addon.readyButton:SetPoint("BOTTOMRIGHT", -140, 0);
addon.readyButton:SetSize(22,22);
addon.readyButton.tooltip = "Toggle your availablity status";
BGRReadyCheckText:SetText("Ready");
addon.readyButton:SetScript("OnClick", function() BGRaider:ToggleReady() end);
addon.readyButton:SetChecked(db.ready);
-- register all commands and events
addon:RegisterChatCommand("bgr", "OnChatCommand");
addon:RegisterChatCommand("bgraider", "OnChatCommand");
addon:RegisterEvent("UPDATE_BATTLEFIELD_STATUS", OnBattlefieldStatus);
addon:RegisterComm("BGR_STATUS","OnCommStatus");
addon:RegisterComm("BGR_REQUEST","OnCommRequest");
end
function OnBattlefieldStatus(msg)
if(not addonQueued) then return end;
local msg;
local status = GetBattlefieldStatus(1);
if(lastBGStatus ~= status) then
lastBGStatus = status;
if(status == "queued") then
msg = "QUEUED";
elseif(status == "confirm") then
msg = "CONFIRM";
addonQueued = nil;
else
addonQueued = nil;
return;
end
if(GetRealNumPartyMembers() > 0) then
msg = msg .. " +" .. GetRealNumPartyMembers();
end
addon:SendCommMessage("BGR_STATUS", msg, "GUILD");
end
end
-- ADDON COMM HANDLERS --
function addon:OnCommStatus(prefix, message, distribution, sender)
addon:Print(date("[%H:%M:%S] ") .. sender .. " sent status " .. message);
end
function addon:OnCommRequest(prefix, message, distribution, sender)
addon:Print(date("[%H:%M:%S] ") .. sender .. " sent request " .. message);
local command, args = strsplit(" ", message, 2);
if(command == "STATUS") then
addon:SendCommMessage("BGR_STATUS", "READY", distribution, sender);
elseif(command == "QUEUE") then
local level, scroll, button = strsplit(" ", args);
addon:QueueForBG(level, scroll, button);
end
end
-- /script BGRaider:SendCommMessage("BGR_REQUEST", "QUEUE 85 0 3", "GUILD");
-- COMMAND HANDLERS --
function addon:OnChatCommand(input)
if(input == "status") then
addon:SendStatusRequest();
elseif(input == "ready") then
addon.readyButton:SetChecked(not db.ready);
addon:ToggleReady(true);
end
end
-- ADDON METHODS --
function addon:SendStatusRequest()
addon:SendCommMessage("BGR_REQUEST", "STATUS", "GUILD");
end
function addon:QueueForBG(level, scroll, button)
if(not db.ready) then
addon:Print("Queue Request ignored: Not Ready (type /bgr ready)");
elseif(level ~= ""..UnitLevel("player")) then
addon:Print("Queue Request ignored: Wrong Level");
elseif(GetRealNumPartyMembers() > 0 and not UnitIsPartyLeader("player")) then
addon:Print("Queue Request ignored: Not Party Leader");
else
PVPHonorFrameTypeScrollFrame:SetVerticalScroll(scroll);
PVPHonor_ButtonClicked(_G["PVPHonorFrameBgButton" .. button]);
JoinBattlefield(1, UnitIsPartyLeader("player"));
addonQueued = true;
end
end
function addon:OpenGui()
-- later this will open the gui, but for now it will send a queue request immediately
local level = UnitLevel("player");
local scroll = strsplit(".", PVPHonorFrameTypeScrollFrame:GetVerticalScroll());
local button = PVPHonorFrame.selectedButtonIndex;
addon:SendCommMessage("BGR_REQUEST", "QUEUE "..level.." "..scroll.." "..button, "GUILD");
end
function addon:ToggleReady(verbose)
db.ready = BGRReadyCheck:GetChecked();
if(db.ready) then addon.guiButton:Enable(db.ready) else addon.guiButton:Disable(db.ready) end
if(verbose) then
addon:Print(db.ready and "Ready" or "Not Ready");
end
end