Mercurial > wow > breuesk
diff State.lua @ 78:5b507f4125d4
Finalized bid handling
author | John@Yosemite-PC |
---|---|
date | Thu, 12 Apr 2012 22:19:15 -0400 |
parents | 39be9328acd0 |
children | 7b8fcea357d2 |
line wrap: on
line diff
--- a/State.lua Thu Apr 12 22:18:05 2012 -0400 +++ b/State.lua Thu Apr 12 22:19:15 2012 -0400 @@ -44,6 +44,7 @@ stateitemlist = {} statebids = {} staterolls = {} +staterollvalues = {} stateactivelist = nil -- todo: protect initiators to admin only @@ -143,14 +144,37 @@ end --}}} -- Bid {{{ +local function SortByList(lref,unordered) + local t = {} + for le in lref:OrderedListEntryIter() do + local lid = le:GetId() + for i,v in pairs(unordered) do + if v.value == lid then + print("Sort time: insert", lid) + table.insert(t,v) + table.remove(unordered,i) + break -- done with this inner iteration + end + end + end + if getn(t) > 0 then + for i,v in pairs(unordered) do + printf("Disregarding bid/roll from %s because they are not on the list", v.textPlain) + end + end + return t +end function ReceivedBid(packet) -- no state transition, but only matters during one state local person, roll = unpack(packet) if state == "bidding" then + local lref = LootLists:Select(stateactivelist) + if roll then + table.insert(statebids,person) -- todo: keep sorted + else table.insert(statebids,person) -- todo: - else - table.insert(statebids,person) -- todo: keep sorted + statebids = SortByList(lref,statebids) end AlertRollListeners() end @@ -160,8 +184,12 @@ function InitiateBid(person,roll) if state == "bidding" then + if not person then + print("You cannot bid becuase you are not on the list") + return + end for i,v in pairs(statebids) do - if person.value == v.value then + if person and person.value == v.value then print(person.value .. " is already on the list") return -- no double adds please end @@ -214,6 +242,7 @@ stateitemlist = {} statebids = {} staterolls = {} + staterollvalues = {} AlertStateChangeListeners() AlertItemListListeners() end