view Looting.lua @ 78:5b507f4125d4

Finalized bid handling
author John@Yosemite-PC
date Thu, 12 Apr 2012 22:19:15 -0400
parents 39be9328acd0
children 7b8fcea357d2
line wrap: on
line source
local bsk=bsk
local _G=_G
local table=table 
local pairs=pairs
local setmetatable=setmetatable
local ipairs=ipairs
local string=string
local sformat=string.format
local tostring=tostring
local type=type
local getn=getn

local event = LibStub("AceEvent-3.0")

setfenv(1,bsk)

local isMasterLootEvent = false

local function OpenMasterLootList()
    print("Open!")
    isMasterLootEvent = true
end

local function UpdateMasterLootList()
    print("Update MLL!")
end

local function LootClosed()
    print("Close!")
    if isMasterLootEvent then
        isMasterLootEvent = false -- end the event
        InitiateCloseLooting()
    end
end

local function LootOpened()
    print("Open loot!")
    isMasterLootEvent = false
    local n = _G.GetNumLootItems()
    for i = 1,n do
        _G.LootSlot(i)
    end
    local items = {}
    for i = 1,n do
        local link = _G.GetLootSlotLink(i)
        if link then
            table.insert(items,{link=link,mlid=i})
            print("Item: ", link, i)
        end
    end
    if not isMasterLootEvent then return end

    print("Let's get started SKing")
    -- todo: check that I am ML and that I'm an admin!

    InitiateBeginLoot(items,stateactivelist)
end

function FreeLoot(item,person)
    PrintTable(item)
    PrintTable(person)
    for ci = 1, 40 do
        if _G.GetMasterLootCandidate(ci) == person.textPlain then
            print("GML",item.mlid,ci)
            _G.GiveMasterLoot(item.mlid, ci)
            return true
        end
    end
    
    print("Could not assign loot to ", person.textPlain)
end

function ExpensiveLoot(item,lref)
    if getn(statebids) > 0 then
        if FreeLoot(item,statebids[1]) then
            lref:SuicidePerson(statebids[1].value)
        else
            printf("Could not suicide %s for item; they are ineligible or offline",statebids[1].textPlain)
        end
        return
    end
    if getn(staterolls) > 0 then
        if FreeLoot(item,staterolls[1]) then
            lref:SuicidePerson(staterolls[1].value)
        else
            printf("Could not suicide %s for item; they are ineligible or offline",staterolls[1].textPlain)
        end
        return
    end
    _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)
    event:RegisterEvent("LOOT_CLOSED",LootClosed)
    event:RegisterEvent("LOOT_OPENED",LootOpened)

    -- todo: what are these
    event:RegisterEvent("LOOT_SLOT_CLEARED",function() print("LSCleared") end)
    event:RegisterEvent("LOOT_SLOT_CHANGED",function() print("LSChanged") end)
end