-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.lua
226 lines (204 loc) · 7.02 KB
/
Main.lua
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
-- app global vars
PVPTools = LibStub("AceAddon-3.0"):NewAddon("PVPTools", "AceConsole-3.0", "AceEvent-3.0")
local L = LibStub("AceLocale-3.0"):GetLocale("PVPTools")
local AceConfigDialog = LibStub("AceConfigDialog-3.0")
local AceGUI = LibStub("AceGUI-3.0")
local AppName = "PVPTools"
local BtnFrame, BtnSafe, BtnEnemy, BtnNotifyStealth
BINDING_HEADER_PVPTools = "PVPTools";
BINDING_NAME_PVPTools_Enemy_Coming = L["keyEnemyComing"]
-- default config
local options = {
name = AppName,
handler = PVPTools,
type = "group",
args = {
showMessageAuto = {
type = "toggle",
name = L["showMessageAuto"],
desc = L["textShowMessageAuto"],
get = function(info)
return PVPTools.db.profile.showMessageAuto
end,
set = function(info, value)
PVPTools.db.profile.showMessageAuto = value or false
end,
},
isPlayer = {
type = "toggle",
name = L["isPlayer"],
desc = L["textIsPlayer"],
get = function(info)
return PVPTools.db.profile.isPlayer
end,
set = function(info, value)
PVPTools.db.profile.isPlayer = value or false
end,
},
top = {
type = "input",
name = "top",
desc = L["top"],
get = function(info)
return PVPTools.db.profile.frameTop
end,
set = function(info, value)
PVPTools.db.profile.frameTop = value or -540
BtnFrame:SetPoint("CENTER", UIParent, "CENTER", PVPTools.db.profile.frameLeft, PVPTools.db.profile.frameTop)
end,
},
left = {
type = "input",
name = "left",
desc = L["left"],
get = function(info)
return PVPTools.db.profile.frameLeft
end,
set = function(info, value)
PVPTools.db.profile.frameLeft = value or 550
BtnFrame:SetPoint("CENTER", UIParent, "CENTER", PVPTools.db.profile.frameLeft, PVPTools.db.profile.frameTop)
end,
},
},
}
local defaults = {
profile = {
notifyStealth = true,
enemy = {},
showMessageAuto = true,
isPlayer = true,
frameTop = -540,
frameLeft = 550,
},
}
function PVPTools:OnInitialize()
-- Called when the addon is loaded
self.db = LibStub("AceDB-3.0"):New("PVPToolsDB", defaults, true)
LibStub("AceConfig-3.0"):RegisterOptionsTable(AppName, options, { "pt", "pvptools" })
self.optionsFrame = AceConfigDialog:AddToBlizOptions(AppName, AppName)
self:RegisterChatCommand("pt", "ShowConfig")
self:RegisterChatCommand("pvptools", "ShowConfig")
end
function PVPTools:ShowConfig()
AceConfigDialog:SetDefaultSize(AppName, 800, 600)
AceConfigDialog:Open(AppName)
end
function PVPTools:OnEnable()
PVPTools.db.profile.enemy = {}
PVPTools_Init_Frame()
if PVPTools.db.profile.notifyStealth == true then
PVPTools:RegisterEvent("NAME_PLATE_UNIT_ADDED")
end
end
function SendMessageByUnit(unit)
--print("SendMessageByUnit:" .. unit)
local unitName, _ = UnitName(unit)
local className, _ = UnitClass(unit)
local zone = GetSubZoneText()
if not zone then
return
end
local notifyText = L["textEnemy"] .. "「" .. unitName .. "-" .. className .. "」" .. L["textNotifyEnemy"] .. "「" .. zone .. "」," .. L["textHelp"];
SendMessage(notifyText)
end
function SendMessage(notifyText)
if PVPTools.db.profile.showMessageAuto == true then
if UnitInRaid("player") then
--SendChatMessage(notifyText, "RAID");
SendChatMessage(notifyText, "INSTANCE_CHAT");
elseif UnitInParty("player") then
SendChatMessage(notifyText, "PARTY");
else
SendChatMessage(notifyText, "SAY");
end
else
PVPTools:Print(notifyText);
end
end
function PVPTools_Enemy_Coming(unit)
--print("PVPTools_Enemy_Coming:" .. unit)
local unitName, _ = UnitName(unit)
local className, _ = UnitClass(unit)
if PVPTools.db.profile.isPlayer == true then
if not UnitIsPlayer(unit) then
return
end
end
if not UnitIsEnemy("player", unit) then
return
end
local zone = GetSubZoneText()
if not zone then
return
end
local notifyText = L["textEnemy"] .. "「" .. unitName .. "-" .. className .. "」" .. L["textNotifyEnemy"] .. "「" .. zone .. "」," .. L["textHelp"];
SendMessage(notifyText)
end
function PVPTools:NAME_PLATE_UNIT_ADDED(_, unitToken)
self:Print("NAME_PLATE_UNIT_ADDED")
local unit = unitToken;
if not UnitIsPlayer(unit) then
return
end
if not UnitIsEnemy("player", unit) then
return
end
local className, classFileName, _ = UnitClass(unitToken)
if classFileName == "HUNTER" and classFileName == "ROGUE" and classFileName == "DRUID" then
if CheckInteractDistance("target", 1) then
SendMessageByUnit(unit)
else
print("too far");
end
else
print("not stealth");
end
end
function PVPTools_Init_Frame()
-- Create a container frame
BtnFrame = AceGUI:Create("ScrollFrame")
BtnFrame:SetWidth(300)
BtnFrame:SetHeight(100)
BtnFrame:SetLayout("Flow")
BtnFrame:SetPoint("CENTER", UIParent, "CENTER", PVPTools.db.profile.frameLeft, PVPTools.db.profile.frameTop)
--end
BtnSafe = AceGUI:Create("Button")
BtnSafe:SetWidth(70)
BtnSafe:SetText(L["textSafe"])
BtnSafe:SetCallback("OnClick", function()
local zone = GetSubZoneText()
if zone then
local notifyText = "【" .. zone .. "】已安全,两点之间的机动点留人随时支援!"
SendMessage(notifyText)
end
end)
BtnFrame:AddChild(BtnSafe)
BtnEnemy = AceGUI:Create("Button")
BtnEnemy:SetWidth(70)
BtnEnemy:SetText(L["textEnemy"])
BtnEnemy:SetCallback("OnClick", function()
PVPTools_Enemy_Coming("target")
end)
BtnFrame:AddChild(BtnEnemy)
BtnNotifyStealth = AceGUI:Create("Button")
BtnNotifyStealth:SetWidth(90)
if PVPTools.db.profile.notifyStealth == false then
BtnNotifyStealth:SetText(L["textStealth"] .. ":" .. L["close"])
PVPTools:UnregisterEvent("NAME_PLATE_UNIT_ADDED");
else
BtnNotifyStealth:SetText(L["textStealth"] .. ":" .. L["open"])
PVPTools:RegisterEvent("NAME_PLATE_UNIT_ADDED")
end
BtnNotifyStealth:SetCallback("OnClick", function()
if PVPTools.db.profile.notifyStealth == true then
BtnNotifyStealth:SetText(L["textStealth"] .. ":" .. L["close"])
PVPTools:UnregisterEvent("NAME_PLATE_UNIT_ADDED");
PVPTools.db.profile.notifyStealth = false
else
BtnNotifyStealth:SetText(L["textStealth"] .. ":" .. L["open"])
PVPTools.db.profile.notifyStealth = true
PVPTools:RegisterEvent("NAME_PLATE_UNIT_ADDED")
end
end)
BtnFrame:AddChild(BtnNotifyStealth)
end