Mercurial > wow > breuesk
comparison State.lua @ 79:7b8fcea357d2
Rolls are active
author | John@Yosemite-PC |
---|---|
date | Thu, 12 Apr 2012 23:50:56 -0400 |
parents | 5b507f4125d4 |
children | 40c882db34f8 |
comparison
equal
deleted
inserted
replaced
78:5b507f4125d4 | 79:7b8fcea357d2 |
---|---|
162 printf("Disregarding bid/roll from %s because they are not on the list", v.textPlain) | 162 printf("Disregarding bid/roll from %s because they are not on the list", v.textPlain) |
163 end | 163 end |
164 end | 164 end |
165 return t | 165 return t |
166 end | 166 end |
167 local function SortByRoll(values,unordered) | |
168 local t = {} | |
169 for r = 100,1,-1 do -- 100:1 | |
170 if values[r] then | |
171 for i,v in pairs(unordered) do | |
172 if v.value == values[r].value then | |
173 print("Sort time: insert", v.value, r) | |
174 table.insert(t,v) | |
175 table.remove(unordered,i) | |
176 break | |
177 end | |
178 end | |
179 end | |
180 end | |
181 if getn(t) > 0 then | |
182 for i,v in pairs(unordered) do | |
183 printf("Disregarding bid/roll from %s because they are not on the list", v.textPlain) | |
184 end | |
185 end | |
186 return t | |
187 end | |
167 function ReceivedBid(packet) -- no state transition, but only matters during one state | 188 function ReceivedBid(packet) -- no state transition, but only matters during one state |
168 local person, roll = unpack(packet) | 189 local person, roll = unpack(packet) |
169 | 190 |
170 if state == "bidding" then | 191 if state == "bidding" then |
171 local lref = LootLists:Select(stateactivelist) | |
172 | |
173 if roll then | 192 if roll then |
174 table.insert(statebids,person) -- todo: keep sorted | 193 print("RB: ",person.value,roll) |
194 table.insert(staterolls,person) | |
195 staterollvalues[roll] = person | |
196 staterolls = SortByRoll(staterollvalues,staterolls) | |
175 else | 197 else |
176 table.insert(statebids,person) -- todo: | 198 local lref = LootLists:Select(stateactivelist) |
199 table.insert(statebids,person) | |
177 statebids = SortByList(lref,statebids) | 200 statebids = SortByList(lref,statebids) |
178 end | 201 end |
179 AlertRollListeners() | 202 AlertRollListeners() |
180 end | 203 end |
181 | 204 |
192 if person and person.value == v.value then | 215 if person and person.value == v.value then |
193 print(person.value .. " is already on the list") | 216 print(person.value .. " is already on the list") |
194 return -- no double adds please | 217 return -- no double adds please |
195 end | 218 end |
196 end | 219 end |
220 for i,v in pairs(staterolls) do | |
221 if person and person.value == v.value then | |
222 print(person.value .. " is already on the list") | |
223 return -- no double adds please | |
224 end | |
225 end | |
197 Comm:SendStateChange("RB",person,roll) | 226 Comm:SendStateChange("RB",person,roll) |
198 end | 227 end |
199 end | 228 end |
200 --}}} | 229 --}}} |
201 -- Retration {{{ | 230 -- Retration {{{ |
203 local person = unpack(packet) | 232 local person = unpack(packet) |
204 if state == "bidding" then | 233 if state == "bidding" then |
205 for i,v in pairs(statebids) do | 234 for i,v in pairs(statebids) do |
206 if v.value == person.value then | 235 if v.value == person.value then |
207 table.remove(statebids,i) | 236 table.remove(statebids,i) |
237 AlertRollListeners() | |
238 return | |
239 end | |
240 end | |
241 for i,v in pairs(staterolls) do | |
242 if v.value == person.value then | |
243 table.remove(staterolls,i) | |
208 AlertRollListeners() | 244 AlertRollListeners() |
209 return | 245 return |
210 end | 246 end |
211 end | 247 end |
212 end | 248 end |
249 | 285 |
250 function InitiateCloseLooting() | 286 function InitiateCloseLooting() |
251 Comm:SendStateChange("CL") | 287 Comm:SendStateChange("CL") |
252 end | 288 end |
253 --}}} | 289 --}}} |
290 function RollRequest(packet) | |
291 local person = unpack(packet) | |
292 | |
293 if state == "bidding" and admin then -- todo: admin should be ML | |
294 local roll | |
295 for i,v in pairs(staterollvalues) do | |
296 if v and v.value == person.value then | |
297 roll = i | |
298 break | |
299 end | |
300 end | |
301 if not roll then -- roll isn't on cache | |
302 repeat -- random until you find a good value | |
303 roll = _G.random(100) | |
304 until staterollvalues[roll] == nil | |
305 print("rolling! ", roll) | |
306 staterollvalues[roll] = person | |
307 end | |
308 InitiateBid(person,roll) | |
309 end | |
310 end | |
311 function InitiateRollRequest(person) | |
312 if state == "bidding" then | |
313 if not person then | |
314 print("You cannot bid becuase you are not on the list") | |
315 return | |
316 end | |
317 for i,v in pairs(staterolls) do | |
318 if person and person.value == v.value then | |
319 print(person.value .. " is already on the list") | |
320 return -- no double adds please | |
321 end | |
322 end | |
323 for i,v in pairs(statebids) do | |
324 if person and person.value == v.value then | |
325 print(person.value .. " is already on the list") | |
326 return -- no double adds please | |
327 end | |
328 end | |
329 Comm:SendStateChange("IR",person,roll) | |
330 end | |
331 end | |
254 function DispatchState(packet) | 332 function DispatchState(packet) |
255 local state = table.remove(packet,1) | 333 local state = table.remove(packet,1) |
256 print("Dispatching", state) | 334 print("Dispatching", state) |
257 if state == "RB" then | 335 if state == "RB" then |
258 ReceivedBid(packet) | 336 ReceivedBid(packet) |
266 CloseBidding(packet) | 344 CloseBidding(packet) |
267 elseif state == "CL" then | 345 elseif state == "CL" then |
268 CloseLooting(packet) | 346 CloseLooting(packet) |
269 elseif state == "AL" then | 347 elseif state == "AL" then |
270 ActivateList(packet) | 348 ActivateList(packet) |
349 elseif state == "IR" then | |
350 RollRequest(packet) | |
271 else -- todo ... | 351 else -- todo ... |
272 | 352 |
273 end | 353 end |
274 end | 354 end |
275 | 355 |
276 function InitializeState() | 356 function InitializeState() |
357 -- basically, find a value for stateactivelist. it really doesn't matter | |
358 -- which one, but I decided on trying to choose one that has entries on it | |
359 -- so the whole thing isn't all empty. stateactivelist being anything | |
360 -- besides a valid ID could trigger errors | |
277 local ltemp = 0 | 361 local ltemp = 0 |
278 local lids = LootLists:GetAllIds() | 362 local lids = LootLists:GetAllIds() |
279 for _,v in pairs(lids) do | 363 for _,v in pairs(lids) do |
280 local l = LootLists:Select(v) | 364 local l = LootLists:Select(v) |
281 if l:GetLength() > 0 then | 365 if l:GetLength() > 0 then |