Mercurial > wow > breuesk
changeset 78:5b507f4125d4
Finalized bid handling
author | John@Yosemite-PC |
---|---|
date | Thu, 12 Apr 2012 22:19:15 -0400 |
parents | 0a3f590f69e6 |
children | 7b8fcea357d2 |
files | Gui.lua Looting.lua State.lua |
diffstat | 3 files changed, 47 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/Gui.lua Thu Apr 12 22:18:05 2012 -0400 +++ b/Gui.lua Thu Apr 12 22:19:15 2012 -0400 @@ -210,7 +210,7 @@ ["Redraw"]= function(self) self.data = {} for i,v in pairs(stateitemlist) do - local entry = {value=i, text=v, link=v} + local entry = {value=i, text=v.link, link=v.link, mlid=v.mlid} table.insert(self.data,entry) end if self.widget then @@ -374,7 +374,7 @@ adminForce:SetDisabled(true) end adminForce:SetWidth(160) - adminForce:SetCallback("OnClick",function(widget) RListPopulator:Force(SListEventDispatch:LatestValue()) end) + adminForce:SetCallback("OnClick",function(widget) InitiateBid(SListEventDispatch:LatestValue()) end) adminForce.userdata = { widget = adminForce, @@ -501,6 +501,7 @@ self.assignButton:SetCallback("OnClick", function(widget) FreeLoot(LListEventDispatch:LatestValue(),SListEventDispatch:LatestValue()) end) self.suicideButton:SetText("Suicide") self.suicideButton:SetDisabled(false) + self.suicideButton:SetCallback("OnClick", function(widget) DirectSuicideLoot(LListEventDispatch:LatestValue(),SListEventDispatch:LatestValue(),SListPopulator.lref) end) else self.assignButton:SetText("Assign") self.assignButton:SetDisabled(true)
--- a/Looting.lua Thu Apr 12 22:18:05 2012 -0400 +++ b/Looting.lua Thu Apr 12 22:19:15 2012 -0400 @@ -44,8 +44,8 @@ for i = 1,n do local link = _G.GetLootSlotLink(i) if link then - table.insert(items,link) - print("Item: ", link) + table.insert(items,{link=link,mlid=i}) + print("Item: ", link, i) end end if not isMasterLootEvent then return end @@ -53,11 +53,7 @@ print("Let's get started SKing") -- todo: check that I am ML and that I'm an admin! - -- make state: gather all item links, transmit them plus the new looting - -- state - -- InitiateBeginLoot(items,stateactivelist) - end function FreeLoot(item,person) @@ -65,8 +61,8 @@ PrintTable(person) for ci = 1, 40 do if _G.GetMasterLootCandidate(ci) == person.textPlain then - print("GML",item.value,ci) - _G.GiveMasterLoot(item.value, ci) + print("GML",item.mlid,ci) + _G.GiveMasterLoot(item.mlid, ci) return true end end @@ -75,7 +71,6 @@ end function ExpensiveLoot(item,lref) - local person if getn(statebids) > 0 then if FreeLoot(item,statebids[1]) then lref:SuicidePerson(statebids[1].value) @@ -95,6 +90,14 @@ _G.error("Trying to suicide+loot without bids or rolls") end +function DirectSuicideLoot(item,person,lref) + if FreeLoot(item,person) then + lref:SuicidePerson(person.value) + else + printf("Could not suicide %s for item; they are ineligible or offline", person.textPlain) + end +end + function InitializeLooting() event:RegisterEvent("OPEN_MASTER_LOOT_LIST",OpenMasterLootList) event:RegisterEvent("UPDATE_MASTER_LOOT_LIST",UpdateMasterLootList)
--- 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