changeset 89:b89558d3e833

Master looter detection. Starting to filter certain actions to only the ML.
author John@Yosemite-PC
date Mon, 16 Apr 2012 07:06:19 -0400
parents f844309a0e35
children dcbe1f04bb31
files Looting.lua State.lua
diffstat 2 files changed, 25 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/Looting.lua	Mon Apr 16 07:05:37 2012 -0400
+++ b/Looting.lua	Mon Apr 16 07:06:19 2012 -0400
@@ -50,6 +50,7 @@
         if link and rarity >= threshold then
             table.insert(items,{link=link,mlid=i})
             print("Item: ", link, i)
+            isMasterLootEvent = true
         end
     end
     if not isMasterLootEvent then return end
@@ -57,13 +58,15 @@
     print("Let's get started SKing")
     -- todo: check that I am ML and that I'm an admin!
 
-    InitiateBeginLoot(items,stateactivelist)
+    if masterLooterIsMe and admin then
+        InitiateBeginLoot(items,stateactivelist)
 
-    local chan -- todo: idiom
-    if _G.GetNumRaidMembers() > 0 then chan = "RAID" else chan = "PARTY" end
-    _G.SendChatMessage("The following items are available -",chan)
-    for i,v in pairs(items) do
-        _G.SendChatMessage(v.link,chan)
+        local chan -- todo: idiom
+        if _G.GetNumRaidMembers() > 0 then chan = "RAID" else chan = "PARTY" end
+        _G.SendChatMessage("The following items are available -",chan)
+        for i,v in pairs(items) do
+            _G.SendChatMessage(v.link,chan)
+        end
     end
 end
 
@@ -129,7 +132,7 @@
         end
     end
 
-    if state == "bidding" and admin then -- todo: should only be ML
+    if state == "bidding" and admin and masterLooterIsMe then
         message = _G.strtrim(message)
         message = _G.strlower(message)
         if message == "bid" then
@@ -159,7 +162,6 @@
 
 function UpdateML()
     local lootmethod, masterlooterPartyID, masterlooterRaidID = _G.GetLootMethod()
-    print("lm",lootmethod)
     if lootmethod == "master" then
         local oldMasterLooter
         oldMasterLooter = masterLooter
@@ -172,10 +174,13 @@
             masterLooter = _G.UnitName("player") 
             masterLooterIsMe = true
         end
-        print("master looter is", masterLooter)
 
         if masterLooter ~= oldMasterLooter then
             statelistener:StateEvent() -- todo: this isn't how to fire an event!
+
+            if not masterLooterIsMe then
+                Comm:RequestCatchup()
+            end
         end
     else
         masterLooter = nil
--- a/State.lua	Mon Apr 16 07:05:37 2012 -0400
+++ b/State.lua	Mon Apr 16 07:06:19 2012 -0400
@@ -134,7 +134,7 @@
         state = "bidding"
         stateitem = item
         AlertStateChangeListeners()
-        if admin then -- todo: only ML
+        if admin and masterLooterIsMe then
             local chan
             if _G.GetNumRaidMembers() > 0 then chan = "RAID" else chan = "PARTY" end
             _G.SendChatMessage("Bidding is now open for "..item.link.."!",chan)
@@ -205,7 +205,7 @@
             statebids = SortByList(lref,statebids)
         end
         AlertRollListeners()
-        if admin then -- todo: make ML
+        if admin and masterLooterIsMe then
             local leader
             if getn(statebids) > 0 then
                 leader = statebids[1].textPlain
@@ -277,14 +277,18 @@
 end
 --}}}
 -- Close Bidding {{{
-function CloseBidding(packet) -- todo: does not clear enough state
-    local awardedTo = unpack(packet) 
+function CloseBidding(packet)
+    local awardedTo = unpack(packet)  -- todo: unused
     if state == "bidding" then
         state = "looting"
+        stateitem = nil
+        statebids = {}
+        staterolls = {}
+        staterollvalues = {}
         AlertStateChangeListeners()
+        AlertItemListListeners()
         -- todo: record history
         if admin then
-            local chan -- todo: pattern
             local chan -- todo: this idiom is wearing on me already
             if _G.GetNumRaidMembers() > 0 then chan = "RAID" else chan = "PARTY" end
             _G.SendChatMessage("Bidding is closed",chan)
@@ -318,7 +322,7 @@
 function RollRequest(packet)
     local person = unpack(packet)
     
-    if state == "bidding" and admin then -- todo: admin should be ML
+    if state == "bidding" and admin and masterLooterIsMe then
         local roll
         for i,v in pairs(staterollvalues) do
             if v and v.value == person.value then
@@ -397,7 +401,7 @@
         RollRequest(packet)
     elseif state == "SC" then
         LootSlotCleared(packet)
-    else -- todo ...
+    else
         _G.error("Cannot dispatch message of type:",state)
     end
 end