-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLootManager.lua
184 lines (171 loc) · 4.76 KB
/
LootManager.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
--[[
* Copyright (c) 2011-2012 by Adam Hellberg.
*
* This file is part of Command.
*
* Command is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Command is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Command. If not, see <http://www.gnu.org/licenses/>.
--]]
-- Upvalues
local type = type
-- API Upvalues
local UnitName = UnitName
local GetLootMethod = GetLootMethod
local SetLootMethod = SetLootMethod
local GetOptOutOfLoot = GetOptOutOfLoot
local SetOptOutOfLoot = SetOptOutOfLoot
local SetLootThreshold = SetLootThreshold
local C = Command
--- Table holding all LootManager methods.
-- This is referenced "LM" in LootManager.lua.
-- @name Command.LootManager
-- @class table
--
C.LootManager = {}
local L = C.LocaleManager
local LM = C.LootManager
local GT = C.GroupTools
local function ParseLootMethod(method)
if type(method) ~= "string" then return "group" end
method = method:lower()
if method:match("^f") then
return "freeforall"
elseif method:match("^g") then
return "group"
elseif method:match("^m") then
return "master"
elseif method:match("^n") then
return "needbeforegreed"
elseif method:match("^r") then
return "roundrobin"
end
return "group"
end
local function PrettyMethod(method)
if type(method) ~= "string" then return L("LOOT_METHOD_GROUP") end
method = method:lower()
if method:match("^f") then
return L("LOOT_METHOD_FFA")
elseif method:match("^g") then
return L("LOOT_METHOD_GROUP")
elseif method:match("^m") then
return L("LOOT_METHOD_MASTER")
elseif method:match("^n") then
return L("LOOT_METHOD_NEEDGREED")
elseif method:match("^r") then
return L("LOOT_METHOD_ROUNDROBIN")
end
return method
end
local function ParseThreshold(threshold)
if type(threshold) == "string" then
threshold = threshold:lower()
if threshold:match("^[ug]") then -- Uncommon/Green
return 2
elseif threshold:match("^[rsb]") then -- Rare/Superior/Blue
return 3
elseif threshold:match("^[ep]") then -- Epic/Purple
return 4
elseif threshold:match("^[lo]") then -- Legendary/Orange
return 5
elseif threshold:match("^a") then -- Artifact
return 6
elseif threshold:match("^h") then -- Heirloom
return 7
end
elseif type(threshold) == "number" then
return threshold
end
return 0
end
local function PrettyThreshold(level)
if level == 2 then
return L("LOOT_THRESHOLD_UNCOMMON")
elseif level == 3 then
return L("LOOT_THRESHOLD_RARE")
elseif level == 4 then
return L("LOOT_THRESHOLD_EPIC")
elseif level == 5 then
return L("LOOT_THRESHOLD_LEGENDARY")
elseif level == 6 then
return L("LOOT_THRESHOLD_ARTIFACT")
elseif level == 7 then
return L("LOOT_THRESHOLD_HEIRLOOM")
end
return L("LOOT_THRESHOLD_UNKNOWN")
end
function LM:SetLootMethod(method, master)
if not GT:IsGroupLeader() then
return false, "LOOT_SM_NOLEAD"
end
method = ParseLootMethod(method)
if method == GetLootMethod() then
return false, "LOOT_SM_DUPE", {PrettyMethod(method)}
elseif method == "master" then
if not master then
master = UnitName("player")
elseif not GT:IsInGroup(master) then
return false, "LOOT_MASTER_NOEXIST", {master}
end
SetLootMethod(method, master)
return "LOOT_SM_SUCCESSMASTER", {PrettyMethod(method), master}
end
SetLootMethod(method)
return "LOOT_SM_SUCCESS", {PrettyMethod(method)}
end
function LM:SetLootMaster(master)
if not GT:IsGroupLeader() then
return false, "LOOT_SLM_NOLEAD"
end
local method = GetLootMethod()
if method ~= "master" then
return false, "LOOT_SLM_METHOD", {method}
end
if not master then
return false, "LOOT_SLM_SPECIFY"
elseif not GT:IsInGroup(master) then
return false, "LOOT_MASTER_NOEXIST", {master}
end
SetLootMethod("master", master)
return "LOOT_SLM_SUCCESS", {master}
end
function LM:SetLootThreshold(threshold)
if not GT:IsGroupLeader() then
return false, "LOOT_ST_NOLEAD"
end
threshold = ParseThreshold(threshold)
if threshold < 2 or threshold > 7 then
return false, "LOOT_ST_INVALID"
end
SetLootThreshold(threshold)
return "LOOT_ST_SUCCESS", {PrettyThreshold(threshold)}
end
function LM:SetLootPass(pass)
local p = false
if type(pass) == "nil" then
local current = GetOptOutOfLoot()
SetOptOutOfLoot(not current)
if not current then
p = true
end
else
SetOptOutOfLoot(pass)
if pass then
p = true
end
end
if p then
return "LOOT_SP_PASS", {UnitName("player")}
end
return "LOOT_SP_ROLL", {UnitName("player")}
end