Mercurial > wow > breuesk
comparison State.lua @ 73:7eb2963eea7d
Further splitting up GUI and State
Starting to integrate looting events
author | John@Yosemite-PC |
---|---|
date | Sun, 08 Apr 2012 22:13:17 -0400 |
parents | 9e5b0a2368ad |
children | ed1c9fd4cc95 |
comparison
equal
deleted
inserted
replaced
72:9e5b0a2368ad | 73:7eb2963eea7d |
---|---|
39 | 39 |
40 state = "neutral" -- states that are possible: neutral, looting, bidding | 40 state = "neutral" -- states that are possible: neutral, looting, bidding |
41 local looting = false | 41 local looting = false |
42 stateactive = nil | 42 stateactive = nil |
43 stateitem = nil | 43 stateitem = nil |
44 stateitemlist = {} | |
44 statebids = {} | 45 statebids = {} |
45 staterolls = {} | 46 staterolls = {} |
46 stateactivelist = nil | 47 stateactivelist = nil |
47 | 48 |
48 local rollListeners = {} | 49 local rollListeners = {} |
49 function RegisterListenerRolls(listener) | 50 function RegisterListenerRolls(listener) |
50 table.insert(rollListeners,listener) | 51 table.insert(rollListeners,listener) |
51 end | 52 end |
76 print("state out") | 77 print("state out") |
77 v["StateEvent"](v) | 78 v["StateEvent"](v) |
78 end | 79 end |
79 end | 80 end |
80 | 81 |
81 function BeginLoot(listValue) | 82 local itemListListeners = {} |
83 function RegisterItemListListener(listener) | |
84 table.insert(itemListListeners,listener) | |
85 end | |
86 function AlertItemListListeners() | |
87 for i,v in pairs(itemListListeners) do | |
88 print("item change") | |
89 v["ItemListEvent"](v) | |
90 end | |
91 end | |
92 | |
93 function BeginLoot(packet) | |
94 local items, listValue = unpack(packet) | |
82 if state == "neutral" then | 95 if state == "neutral" then |
83 state = "looting" | 96 state = "looting" |
84 looting = true | 97 stateactivelist = listValue |
85 active = listValue | 98 stateitemlist = items |
99 AlertItemListListeners() | |
100 CreateGUI() -- todo: bad spot, but that's ok for now | |
86 else | 101 else |
87 _G.error("Bad state transition", state, "looting") | 102 _G.error("Bad state transition", state, "looting") |
88 end | 103 end |
89 end | 104 end |
90 | 105 |
106 function InitiateBeginLoot(items,listValue) | |
107 if state == "neutral" then | |
108 Comm:SendStateChange("BL",items,listValue) | |
109 end | |
110 end | |
91 | 111 |
92 -- Activate List {{{ | 112 -- Activate List {{{ |
93 function ActivateList(packet) -- doesn't cause a transition, but we only enforce a list selection during certain times | 113 function ActivateList(packet) -- doesn't cause a transition, but we only enforce a list selection during certain times |
94 local list = unpack(packet) | 114 local list = unpack(packet) |
95 if state == "looting" then | 115 if state == "looting" then |
105 end | 125 end |
106 --}}} | 126 --}}} |
107 -- Open Bidding {{{ | 127 -- Open Bidding {{{ |
108 function OpenBid(packet) | 128 function OpenBid(packet) |
109 local item = unpack(packet) | 129 local item = unpack(packet) |
110 --if state == "looting" then | 130 if state == "looting" then |
111 state = "bidding" | 131 state = "bidding" |
132 AlertStateChangeListeners() | |
112 item = value | 133 item = value |
113 --end | 134 end |
114 end | 135 end |
115 | 136 |
116 function InitiateOpenBid(item) | 137 function InitiateOpenBid(item) |
117 --if state == "looting" then | 138 if state == "looting" then |
118 Comm:SendStateChange("OB",item) | 139 Comm:SendStateChange("OB",item) |
119 --end | 140 end |
120 end | 141 end |
121 --}}} | 142 --}}} |
122 -- Bid {{{ | 143 -- Bid {{{ |
123 function ReceivedBid(packet) -- no state transition, but only matters during one state | 144 function ReceivedBid(packet) -- no state transition, but only matters during one state |
124 local person, roll = unpack(packet) | 145 local person, roll = unpack(packet) |
169 --}}} | 190 --}}} |
170 -- Close Bidding {{{ | 191 -- Close Bidding {{{ |
171 function CloseBidding(packet) | 192 function CloseBidding(packet) |
172 local awardedTo = unpack(packet) | 193 local awardedTo = unpack(packet) |
173 state = "looting" | 194 state = "looting" |
195 AlertStateChangeListeners() | |
174 -- remove the item from the window, record history | 196 -- remove the item from the window, record history |
175 end | 197 end |
176 | 198 |
177 function InitiateCloseBidding(awardedTo) | 199 function InitiateCloseBidding(awardedTo) |
178 Comm:SendStateChange("CB",awardedTo) | 200 Comm:SendStateChange("CB",awardedTo) |
179 end | 201 end |
180 --}}} | 202 --}}} |
181 | 203 -- Close Looting {{{ |
182 function CloseLooting(packet) | 204 function CloseLooting(packet) |
183 state = "neutral" | 205 state = "neutral" |
184 active = nil | 206 stateactive = nil |
185 item = nil | 207 stateitem = nil |
186 bids = {} | 208 stateitemlist = {} |
187 rolls = {} | 209 statebids = {} |
210 staterolls = {} | |
211 AlertStateChangeListeners() | |
212 AlertItemListListeners() | |
188 end | 213 end |
189 | 214 |
190 function InitiateCloseLooting() | 215 function InitiateCloseLooting() |
191 Comm:SendStateChange("CL") | 216 Comm:SendStateChange("CL") |
192 end | 217 end |
193 | 218 --}}} |
194 function DispatchState(packet) | 219 function DispatchState(packet) |
195 local state = table.remove(packet,1) | 220 local state = table.remove(packet,1) |
196 print("Dispatching", state) | 221 print("Dispatching", state) |
197 if state == "RB" then | 222 if state == "RB" then |
198 ReceivedBid(packet) | 223 ReceivedBid(packet) |
224 elseif state == "BL" then | |
225 BeginLoot(packet) | |
199 elseif state == "RR" then | 226 elseif state == "RR" then |
200 ReceivedRetraction(packet) | 227 ReceivedRetraction(packet) |
201 elseif state == "OB" then | 228 elseif state == "OB" then |
202 OpenBid(packet) | 229 OpenBid(packet) |
203 elseif state == "CB" then | 230 elseif state == "CB" then |
204 CloseBidding(packet) | 231 CloseBidding(packet) |
205 elseif state == "CB" then | 232 elseif state == "CL" then |
206 CloseLooting(packet) | 233 CloseLooting(packet) |
207 elseif state == "AL" then | 234 elseif state == "AL" then |
208 ActivateList(packet) | 235 ActivateList(packet) |
209 else -- todo ... | 236 else -- todo ... |
210 | 237 |
211 end | 238 end |
212 end | 239 end |
213 | 240 |
241 function InitializeState() | |
242 local ltemp = 0 | |
243 local lids = LootLists:GetAllIds() | |
244 for _,v in pairs(lids) do | |
245 local l = LootLists:Select(v) | |
246 if l:GetLength() > 0 then | |
247 if ltemp == 0 then | |
248 ltemp = l:GetId() | |
249 end | |
250 end | |
251 end | |
252 stateactivelist = ltemp | |
253 end | |
254 |