Mercurial > wow > breuesk
comparison State.lua @ 71:d5e2dfe0c269
Starting to track loot state separately
author | John@Yosemite-PC |
---|---|
date | Tue, 03 Apr 2012 23:23:22 -0400 |
parents | |
children | 9e5b0a2368ad |
comparison
equal
deleted
inserted
replaced
70:236117ab8a49 | 71:d5e2dfe0c269 |
---|---|
1 local bsk=bsk | |
2 local _G=_G | |
3 local table=table | |
4 local pairs=pairs | |
5 local setmetatable=setmetatable | |
6 local ipairs=ipairs | |
7 local string=string | |
8 local sformat=string.format | |
9 local tostring=tostring | |
10 local type=type | |
11 local unpack=unpack | |
12 local getn=getn | |
13 setfenv(1,bsk) | |
14 | |
15 -- simple state machine | |
16 | |
17 --Begin loot | |
18 --Activate list ... only during looting? | |
19 --open bidding/rolling | |
20 --bid/roll occurred | |
21 --remove bid/roll | |
22 --close bidding | |
23 --remove item | |
24 | |
25 | |
26 -- we'll track state, but that may or may not result in a GUI change until down | |
27 -- the road | |
28 | |
29 -- todo: transmit this all to only the raid, not the guild? | |
30 | |
31 -- sample procedure | |
32 -- person B opens GUI. | |
33 -- person A begins looting, sets a list | |
34 -- person A begins bidding, transmists the state | |
35 -- person B goes into bidding state, their button activates | |
36 -- person B clicks the button. button changes state. | |
37 -- person B broadcasts their bid. if a bid, everyone just accepts it. | |
38 -- - if a roll, then the master does the roll and rebroadcasts | |
39 | |
40 state = "neutral" | |
41 local looting = false | |
42 stateactive = nil | |
43 stateitem = nil | |
44 statebids = {} | |
45 staterolls = {} | |
46 | |
47 local rollListeners = {} | |
48 function RegisterListenerRolls(listener) | |
49 table.insert(rollListeners,listener) | |
50 end | |
51 function AlertRollListeners() | |
52 for i,v in pairs(rollListeners) do | |
53 print("roll out") | |
54 v["RollEvent"](v) | |
55 end | |
56 end | |
57 | |
58 function BeginLoot(listValue) | |
59 if state == "neutral" then | |
60 state = "looting" | |
61 looting = true | |
62 active = listValue | |
63 else | |
64 _G.error("Bad state transition", state, "looting") | |
65 end | |
66 end | |
67 | |
68 function ActivateList(value) -- doesn't cause a transition, but we only enforce a list selection during certain times | |
69 if state == "looting" then | |
70 active = value | |
71 end | |
72 end | |
73 | |
74 function OpenBid(packet) | |
75 local item = unpack(packet) | |
76 --if state == "looting" then | |
77 state = "bidding" | |
78 item = value | |
79 --end | |
80 end | |
81 | |
82 function InitiateOpenBid(item) | |
83 --if state == "looting" then | |
84 Comm:SendStateChange("OB",item) | |
85 --end | |
86 end | |
87 | |
88 function DispatchState(packet) | |
89 local state = table.remove(packet,1) | |
90 print("Dispatching", state) | |
91 if state == "RB" then | |
92 ReceivedBid(packet) | |
93 elseif state == "RR" then | |
94 ReceivedRetraction(packet) | |
95 elseif state == "OB" then | |
96 OpenBid(packet) | |
97 else -- todo ... | |
98 | |
99 end | |
100 end | |
101 | |
102 function ReceivedBid(packet) -- no state transition, but only matters during one state | |
103 local person, roll = unpack(packet) | |
104 | |
105 if state == "bidding" then | |
106 if roll then | |
107 table.insert(statebids,person) -- todo: | |
108 else | |
109 table.insert(statebids,person) -- todo: keep sorted | |
110 end | |
111 AlertRollListeners() | |
112 end | |
113 | |
114 -- else ignore ... | |
115 end | |
116 | |
117 function InitiateBid(person,roll) | |
118 if state == "bidding" then | |
119 for i,v in pairs(statebids) do | |
120 if person.value == v.value then | |
121 print(person.value .. " is already on the list") | |
122 return -- no double adds please | |
123 end | |
124 end | |
125 Comm:SendStateChange("RB",person,roll) | |
126 end | |
127 end | |
128 | |
129 | |
130 function ReceivedRetraction(packet) | |
131 local person = unpack(packet) | |
132 if state == "bidding" then | |
133 for i,v in pairs(statebids) do | |
134 if v.value == person.value then | |
135 table.remove(statebids,i) | |
136 AlertRollListeners() | |
137 return | |
138 end | |
139 end | |
140 end | |
141 end | |
142 | |
143 function InitiateRetract(person) | |
144 if state == "bidding" then | |
145 Comm:SendStateChange("RR",person,roll) | |
146 end | |
147 end | |
148 | |
149 function CloseBidding(awardedTo) | |
150 state = "looting" | |
151 -- remove the item, record history | |
152 end | |
153 | |
154 function CloseLooting() | |
155 state = "neutral" | |
156 active = nil | |
157 item = nil | |
158 bids = {} | |
159 rolls = {} | |
160 end |