comparison State.lua @ 78:5b507f4125d4

Finalized bid handling
author John@Yosemite-PC
date Thu, 12 Apr 2012 22:19:15 -0400
parents 39be9328acd0
children 7b8fcea357d2
comparison
equal deleted inserted replaced
77:0a3f590f69e6 78:5b507f4125d4
42 stateactive = nil 42 stateactive = nil
43 stateitem = nil 43 stateitem = nil
44 stateitemlist = {} 44 stateitemlist = {}
45 statebids = {} 45 statebids = {}
46 staterolls = {} 46 staterolls = {}
47 staterollvalues = {}
47 stateactivelist = nil 48 stateactivelist = nil
48 49
49 -- todo: protect initiators to admin only 50 -- todo: protect initiators to admin only
50 51
51 local rollListeners = {} 52 local rollListeners = {}
141 Comm:SendStateChange("OB",item) 142 Comm:SendStateChange("OB",item)
142 end 143 end
143 end 144 end
144 --}}} 145 --}}}
145 -- Bid {{{ 146 -- Bid {{{
147 local function SortByList(lref,unordered)
148 local t = {}
149 for le in lref:OrderedListEntryIter() do
150 local lid = le:GetId()
151 for i,v in pairs(unordered) do
152 if v.value == lid then
153 print("Sort time: insert", lid)
154 table.insert(t,v)
155 table.remove(unordered,i)
156 break -- done with this inner iteration
157 end
158 end
159 end
160 if getn(t) > 0 then
161 for i,v in pairs(unordered) do
162 printf("Disregarding bid/roll from %s because they are not on the list", v.textPlain)
163 end
164 end
165 return t
166 end
146 function ReceivedBid(packet) -- no state transition, but only matters during one state 167 function ReceivedBid(packet) -- no state transition, but only matters during one state
147 local person, roll = unpack(packet) 168 local person, roll = unpack(packet)
148 169
149 if state == "bidding" then 170 if state == "bidding" then
171 local lref = LootLists:Select(stateactivelist)
172
150 if roll then 173 if roll then
174 table.insert(statebids,person) -- todo: keep sorted
175 else
151 table.insert(statebids,person) -- todo: 176 table.insert(statebids,person) -- todo:
152 else 177 statebids = SortByList(lref,statebids)
153 table.insert(statebids,person) -- todo: keep sorted
154 end 178 end
155 AlertRollListeners() 179 AlertRollListeners()
156 end 180 end
157 181
158 -- else ignore ... 182 -- else ignore ...
159 end 183 end
160 184
161 function InitiateBid(person,roll) 185 function InitiateBid(person,roll)
162 if state == "bidding" then 186 if state == "bidding" then
187 if not person then
188 print("You cannot bid becuase you are not on the list")
189 return
190 end
163 for i,v in pairs(statebids) do 191 for i,v in pairs(statebids) do
164 if person.value == v.value then 192 if person and person.value == v.value then
165 print(person.value .. " is already on the list") 193 print(person.value .. " is already on the list")
166 return -- no double adds please 194 return -- no double adds please
167 end 195 end
168 end 196 end
169 Comm:SendStateChange("RB",person,roll) 197 Comm:SendStateChange("RB",person,roll)
212 stateactive = nil 240 stateactive = nil
213 stateitem = nil 241 stateitem = nil
214 stateitemlist = {} 242 stateitemlist = {}
215 statebids = {} 243 statebids = {}
216 staterolls = {} 244 staterolls = {}
245 staterollvalues = {}
217 AlertStateChangeListeners() 246 AlertStateChangeListeners()
218 AlertItemListListeners() 247 AlertItemListListeners()
219 end 248 end
220 249
221 function InitiateCloseLooting() 250 function InitiateCloseLooting()