changeset 79:7b8fcea357d2

Rolls are active
author John@Yosemite-PC
date Thu, 12 Apr 2012 23:50:56 -0400
parents 5b507f4125d4
children 40c882db34f8
files Gui.lua Looting.lua State.lua
diffstat 3 files changed, 117 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/Gui.lua	Thu Apr 12 22:19:15 2012 -0400
+++ b/Gui.lua	Thu Apr 12 23:50:56 2012 -0400
@@ -262,7 +262,26 @@
     ["RollEvent"] = function(self) self:Redraw() end,
     ["Release"] = function(self) self.widget = nil end,
     ["Redraw"] = function(self)
-        self.widget:SetList(statebids)
+        local list = {}
+        for i,v in pairs(statebids) do
+            table.insert(list,v)
+        end
+        for i,v in pairs(staterolls) do
+            local roll
+            for r,s in pairs(staterollvalues) do
+                if s.value == v.value then
+                    roll = r
+                    break
+                end
+            end
+            print("Inserting a roll ", v.value, roll)
+
+            local c = copy(v)
+            c.disabled = false
+            c.text = c.text .. " (roll "..roll..")"
+            table.insert(list,c)
+        end
+        self.widget:SetList(list)
         RListEventDispatch:Event("Redraw")
     end,
     ["SetWidget"] = function(self,w)
@@ -279,12 +298,12 @@
         --end
         self:Redraw()
     end,
-    ["Force"] = function(self,who)
+    ["Force"] = function(self,who) -- todo: remove this and the horse it rode in on
         local new = self.Convert(who,72)
         InitiateBid(new)
         --self:Redraw()
     end,
-    ["Retract"] = function(self,who)
+    ["Retract"] = function(self,who) -- todo: remove this and the horse it rode in on
         -- todo
         --for i,v in pairs(self.data) do
         --    if who.value == v.value then
@@ -350,7 +369,11 @@
             local rollButton = AceGUI:Create("Button")
             rollButton:SetText("Offset Roll")
             rollButton:SetWidth(100)
-            -- todo: callback
+            rollButton:SetCallback("OnClick", function(widget) InitiateRollRequest(SListPopulator:GetMe()) end) -- todo: wrong behavior. GetMe will nil if the person isn't on the currently selected loot list. this could easily happen. return a new thingy instead
+            local retractButton = AceGUI:Create("Button")
+            retractButton:SetText("Retract")
+            retractButton:SetWidth(100)
+            retractButton:SetCallback("OnClick", function(widget) InitiateRetract(SListPopulator:GetMe()) end)
 
             RListEventDispatch:SetTarget(b1)
             RListPopulator:SetWidget(b1)
@@ -407,7 +430,7 @@
                 g1:AddChildren(adminForce,adminRetract)
             end
 
-            self.group:AddChildren(spacer,label,biddingOn,bidRetractButton,rollButton,spacer2,bidTitle,b1)
+            self.group:AddChildren(spacer,label,biddingOn,bidRetractButton,rollButton,retractButton,spacer2,bidTitle,b1)
             if admin then self.group:AddChildren(g1) end
 
         else
--- a/Looting.lua	Thu Apr 12 22:19:15 2012 -0400
+++ b/Looting.lua	Thu Apr 12 23:50:56 2012 -0400
@@ -81,7 +81,7 @@
     end
     if getn(staterolls) > 0 then
         if FreeLoot(item,staterolls[1]) then
-            lref:SuicidePerson(staterolls[1].value)
+            --lref:SuicidePerson(staterolls[1].value)
         else
             printf("Could not suicide %s for item; they are ineligible or offline",staterolls[1].textPlain)
         end
--- a/State.lua	Thu Apr 12 22:19:15 2012 -0400
+++ b/State.lua	Thu Apr 12 23:50:56 2012 -0400
@@ -164,16 +164,39 @@
     end
     return t
 end
+local function SortByRoll(values,unordered)
+    local t = {}
+    for r = 100,1,-1 do -- 100:1
+        if values[r] then
+            for i,v in pairs(unordered) do
+                if v.value == values[r].value then
+                    print("Sort time: insert", v.value, r)
+                    table.insert(t,v)
+                    table.remove(unordered,i)
+                    break
+                end
+            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
+            print("RB: ",person.value,roll)
+            table.insert(staterolls,person)
+            staterollvalues[roll] = person
+            staterolls = SortByRoll(staterollvalues,staterolls)
         else
-            table.insert(statebids,person) -- todo:
+            local lref = LootLists:Select(stateactivelist)
+            table.insert(statebids,person)
             statebids = SortByList(lref,statebids)
         end
         AlertRollListeners()
@@ -194,6 +217,12 @@
                 return -- no double adds please
             end
         end
+        for i,v in pairs(staterolls) do
+            if person and person.value == v.value then
+                print(person.value .. " is already on the list")
+                return -- no double adds please
+            end
+        end
         Comm:SendStateChange("RB",person,roll)
     end
 end
@@ -209,6 +238,13 @@
                 return
             end
         end
+        for i,v in pairs(staterolls) do
+            if v.value == person.value then
+                table.remove(staterolls,i)
+                AlertRollListeners()
+                return
+            end
+        end
     end
 end
 
@@ -251,6 +287,48 @@
     Comm:SendStateChange("CL")
 end
 --}}}
+function RollRequest(packet)
+    local person = unpack(packet)
+    
+    if state == "bidding" and admin then -- todo: admin should be ML
+        local roll
+        for i,v in pairs(staterollvalues) do
+            if v and v.value == person.value then
+                roll = i
+                break
+            end
+        end
+        if not roll then -- roll isn't on cache
+            repeat -- random until you find a good value
+                roll = _G.random(100)
+            until staterollvalues[roll] == nil
+            print("rolling! ", roll)
+            staterollvalues[roll] = person
+        end
+        InitiateBid(person,roll)
+    end
+end
+function InitiateRollRequest(person)
+    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(staterolls) do
+            if person and person.value == v.value then
+                print(person.value .. " is already on the list")
+                return -- no double adds please
+            end
+        end
+        for i,v in pairs(statebids) do
+            if person and person.value == v.value then
+                print(person.value .. " is already on the list")
+                return -- no double adds please
+            end
+        end
+        Comm:SendStateChange("IR",person,roll)
+    end
+end
 function DispatchState(packet)
     local state = table.remove(packet,1)
     print("Dispatching", state)
@@ -268,12 +346,18 @@
         CloseLooting(packet)
     elseif state == "AL" then
         ActivateList(packet)
+    elseif state == "IR" then
+        RollRequest(packet)
     else -- todo ...
 
     end
 end
 
 function InitializeState()
+    -- basically, find a value for stateactivelist. it really doesn't matter
+    -- which one, but I decided on trying to choose one that has entries on it
+    -- so the whole thing isn't all empty. stateactivelist being anything
+    -- besides a valid ID could trigger errors
     local ltemp = 0
     local lids = LootLists:GetAllIds()
     for _,v in pairs(lids) do