John@0
|
1 -- ideas: last attended data and/or remove people who haven't attended in X days
|
John@0
|
2
|
John@0
|
3 -- order of implementation
|
John@31
|
4 -- (*) lists fully functional (/script interface)
|
John@31
|
5 -- (*) lists single-user functional via command line interface
|
John@27
|
6 -- (*) all actions should reference the player list rather than player names
|
John@27
|
7 -- (?) player entries should persist as long as any list or change references
|
John@18
|
8 -- (*) lists store number slots rather than flat indexing
|
John@86
|
9 -- (*) database and comm versioning
|
John@77
|
10 -- (_) limited communication - everyone trusts the loot master
|
John@85
|
11 -- (*) single user + admin gui (manual suicides)
|
John@85
|
12 -- (*) single user + admin gui (master loot)
|
John@84
|
13 -- (*) whisper UI
|
John@85
|
14 -- (_) communication and list merging/trimming
|
John@85
|
15 -- (_) admins
|
John@77
|
16 -- (*) players gui
|
John@35
|
17 -- ( ) undo
|
John@0
|
18 -- ( ) crypto / protection against tampering
|
John@0
|
19 -- ( ) alt tracking
|
John@70
|
20 -- (*) reserves
|
John@91
|
21 -- ( ) comparison vs currently equipped item
|
John@32
|
22
|
John@42
|
23 local _G=_G
|
John@42
|
24 local strsplit=strsplit
|
John@42
|
25 local string=string
|
John@42
|
26 local sformat=string.format
|
John@43
|
27 local bsk = LibStub("AceAddon-3.0"):NewAddon("bsk","AceConsole-3.0")
|
John@42
|
28 _G.bsk=bsk
|
John@42
|
29 local L = LibStub("AceLocale-3.0"):GetLocale("bsk", false)
|
John@42
|
30 setfenv(1,bsk)
|
John@42
|
31
|
John@34
|
32 local pkgrev = " @project-revision@ "
|
John@0
|
33
|
John@0
|
34 -- important things to remember:
|
John@1
|
35 -- 1) ipairs iterates from 1 until the first missing int index -> no gaps if int
|
John@1
|
36 -- indexing
|
John@0
|
37 -- 2) a.x === a["x"]
|
John@0
|
38 -- 3) a["1"] =/= a[1]
|
John@5
|
39 -- 4) table.remove() works ok if reverse iterating, terrible at anything else
|
John@5
|
40 -- 5) pairs() does not have a guaranteed iteration order
|
John@0
|
41
|
John@86
|
42 dbversion = 1
|
John@86
|
43 commversion = 1
|
John@86
|
44
|
John@42
|
45 function OnInitialize()
|
John@0
|
46
|
John@69
|
47 debug = true
|
John@69
|
48
|
John@42
|
49 db = _G.LibStub("AceDB-3.0"):New("BskDB", defaults, "Default")
|
John@0
|
50
|
John@42
|
51 options.args.profile = _G.LibStub("AceDBOptions-3.0"):GetOptionsTable(db)
|
John@42
|
52 _G.LibStub("AceConfig-3.0"):RegisterOptionsTable("bsk", options)
|
John@42
|
53 --optionsFrame = LibStub("AceConfigDialog-3.0"):AddToBlizOptions("bsk", "bsk")
|
John@0
|
54
|
John@74
|
55 admin = db.profile.admin
|
John@86
|
56 if not db.profile.dbversion or db.profile.dbversion < dbversion then
|
John@86
|
57 UpgradeDB()
|
John@86
|
58 end
|
John@74
|
59
|
John@42
|
60 local HandlePassThrough = function(...) HandleCommand(...) end
|
John@42
|
61 bsk:RegisterChatCommand("bsk", HandlePassThrough)
|
John@68
|
62 bsk:OnInitializeSetStaticData()
|
John@70
|
63 InitializeComm()
|
John@73
|
64 InitializeLooting()
|
John@0
|
65 end
|
John@0
|
66
|
John@42
|
67 function OnEnable()
|
John@42
|
68 CreateWorkingStateFromChanges(db.profile.changes)
|
John@73
|
69 InitializeState()
|
John@0
|
70 end
|
John@0
|
71
|
John@42
|
72 function HandleCommand(paramIn)
|
John@0
|
73 local param = { strsplit(" ", paramIn) }
|
John@8
|
74 local FixPersonName = function(p)
|
John@0
|
75 p = p:lower()
|
John@0
|
76 -- next two lines from sylvanaar
|
John@0
|
77 local MULTIBYTE_FIRST_CHAR = "^([\192-\255]?%a?[\128-\191]*)"
|
John@0
|
78 return string.gsub(p, MULTIBYTE_FIRST_CHAR, string.upper, 1)
|
John@0
|
79 end
|
John@49
|
80 action,arg1,arg2,arg3 = bsk:GetArgs(paramIn,4)
|
John@0
|
81
|
John@49
|
82 if not action then
|
John@43
|
83 print("need args")
|
John@0
|
84 return
|
John@0
|
85 end
|
John@49
|
86 if action == "persons" then
|
John@42
|
87 PrintPersons()
|
John@49
|
88 elseif action == "changes" then
|
John@42
|
89 PrintChanges()
|
John@49
|
90 elseif action == "selfdestruct" then
|
John@49
|
91 SelfDestruct()
|
John@49
|
92 elseif action == "delete" or action == "remove" then
|
John@49
|
93 if not arg1 or not arg2 then
|
John@42
|
94 PrintTable(param)
|
John@21
|
95 return
|
John@21
|
96 end
|
John@49
|
97 if arg1 == "list" then
|
John@49
|
98 DeleteList(arg2)
|
John@49
|
99 elseif arg1 == "personfromlist" or "fromlist" then
|
John@49
|
100 if not arg3 then
|
John@42
|
101 PrintTable(param)
|
John@22
|
102 return
|
John@22
|
103 end
|
John@49
|
104 local person = FixPersonName(arg2)
|
John@49
|
105 RemovePersonFromList(person, arg3)
|
John@49
|
106 elseif arg1 == "person" then
|
John@49
|
107 local person = FixPersonName(arg2)
|
John@42
|
108 RemovePerson(person)
|
John@21
|
109 else
|
John@49
|
110 printf("Deleting anything of type %s is not supported",arg1)
|
John@21
|
111 end
|
John@49
|
112 elseif action == "nuke" then
|
John@49
|
113 if not arg1 then
|
John@42
|
114 PrintTable(param)
|
John@30
|
115 return
|
John@30
|
116 end
|
John@49
|
117 local person = FixPersonName(arg1)
|
John@42
|
118 NukePerson(person)
|
John@49
|
119 elseif action == "add" or action == "create" then
|
John@49
|
120 if not arg1 or not arg2 then
|
John@42
|
121 PrintTable(param)
|
John@0
|
122 return
|
John@0
|
123 end
|
John@49
|
124 if arg1 == "person" then
|
John@49
|
125 if arg2 == "all" or arg2 == "missing" then
|
John@49
|
126 PersonList:AddMissing()
|
John@1
|
127 else
|
John@49
|
128 local person = FixPersonName(arg2)
|
John@42
|
129 AddPerson(person)
|
John@1
|
130 end
|
John@49
|
131 elseif arg1 == "list" then
|
John@49
|
132 CreateList(arg2)
|
John@49
|
133 elseif arg1 == "tolist" then
|
John@49
|
134 if not arg3 then
|
John@42
|
135 PrintTable(param)
|
John@9
|
136 return
|
John@9
|
137 end
|
John@49
|
138 local person = FixPersonName(arg2)
|
John@49
|
139 AddPersonToListEnd(person,arg3)
|
John@49
|
140 elseif arg1 == "tolistrandom" then
|
John@49
|
141 if not arg3 then
|
John@42
|
142 PrintTable(param)
|
John@11
|
143 return
|
John@11
|
144 end
|
John@49
|
145 local person = FixPersonName(arg2)
|
John@49
|
146 AddPersonToListRandom(person,arg3)
|
John@0
|
147 end
|
John@49
|
148 elseif action == "populate" then
|
John@49
|
149 if not arg1 then
|
John@42
|
150 PrintTable(param)
|
John@3
|
151 return
|
John@3
|
152 end
|
John@3
|
153 -- list = p2
|
John@49
|
154 PopulateListRandom(arg1)
|
John@49
|
155 elseif action == "suicide" then
|
John@49
|
156 if not arg1 or not arg2 then
|
John@42
|
157 PrintTable(param)
|
John@0
|
158 return
|
John@0
|
159 end
|
John@49
|
160 local person = FixPersonName(arg1)
|
John@49
|
161 SuicidePerson(person,arg2)
|
John@49
|
162 elseif action == "lists" then
|
John@49
|
163 if not arg1 then
|
John@42
|
164 PrettyPrintLists()
|
John@14
|
165 return
|
John@14
|
166 else
|
John@49
|
167 PrettyPrintList(arg1)
|
John@14
|
168 end
|
John@49
|
169 elseif action == "reserve" then
|
John@49
|
170 if not arg1 then
|
John@49
|
171 PrintTable(param)
|
John@49
|
172 return
|
John@49
|
173 end
|
John@49
|
174 local person = FixPersonName(arg1)
|
John@49
|
175 ReservePerson(person)
|
John@49
|
176 elseif action == "trim" then
|
John@49
|
177 if not arg1 then
|
John@42
|
178 printtable(param)
|
John@0
|
179 return
|
John@0
|
180 end
|
John@49
|
181 TrimLists(arg1)
|
John@49
|
182 elseif action == "rename" then
|
John@49
|
183 if not arg1 or not arg2 then
|
John@49
|
184 PrintTable(param)
|
John@5
|
185 return
|
John@5
|
186 end
|
John@49
|
187 RenameList(arg1,arg2)
|
John@66
|
188 elseif action == "generate" then
|
John@66
|
189 if not arg1 then
|
John@66
|
190 PrintTable(param)
|
John@66
|
191 return
|
John@66
|
192 end
|
John@66
|
193 PersonList:AddMissing()
|
John@66
|
194 CreateList(arg1)
|
John@66
|
195 PopulateListRandom(arg1)
|
John@77
|
196 elseif action == "liststatus" then
|
John@77
|
197 local lids = LootLists:GetAllIds()
|
John@77
|
198 for _,v in _G.pairs(lids) do
|
John@77
|
199 local lref = LootLists:Select(v)
|
John@77
|
200 printf("List %s, modified %s (%s)", lref:GetName(), _G.date("%m/%d/%y %H:%M:%S",lref:GetTime()), lref:GetTime())
|
John@77
|
201 end
|
John@72
|
202 elseif action == "push" then
|
John@72
|
203 Comm:Push()
|
John@72
|
204 elseif action == "state" then
|
John@72
|
205 print(state)
|
John@38
|
206 else
|
John@42
|
207 CreateGUI()
|
John@0
|
208 end
|
John@0
|
209 end
|
John@0
|
210
|
John@42
|
211 defaults = {
|
John@0
|
212 profile = {
|
John@91
|
213 time = 0,
|
John@8
|
214 persons = {},
|
John@0
|
215 changes = {},
|
John@34
|
216 lists = {}
|
John@0
|
217 }
|
John@0
|
218 }
|
John@0
|
219
|
John@86
|
220 function UpgradeDB()
|
John@86
|
221 local mydbver = db.profile.dbversion or 0
|
John@86
|
222
|
John@86
|
223 if mydbver == 0 then -- difference between 0 and 1 is whether this field is present
|
John@86
|
224 db.profile.dbversion = 1
|
John@86
|
225 mydbver = 1
|
John@86
|
226 end
|
John@86
|
227
|
John@86
|
228
|
John@86
|
229 end
|