Mercurial > wow > ouroloot
diff core.lua @ 24:61d932f0e8f2
Reassigning loot in the main tab also updates entries in the history tab.
author | Farmbuyer of US-Kilrogg <farmbuyer@gmail.com> |
---|---|
date | Wed, 21 Sep 2011 06:21:48 +0000 |
parents | 8664134bba4f |
children | cb9635999171 |
line wrap: on
line diff
--- a/core.lua Fri Sep 09 00:56:13 2011 +0000 +++ b/core.lua Wed Sep 21 06:21:48 2011 +0000 @@ -1537,8 +1537,10 @@ count = e.count, } tinsert (h, 1, n) + e.history_unique = n.id .. ' ' .. n.when end + -- Create new history table based on current loot. function addon:rewrite_history (realmname) local r = assert(realmname) self.history_all[r] = self:_prep_new_history_category (nil, r) @@ -1561,6 +1563,7 @@ end end + -- Clears all but latest entry for each player. function addon:preen_history (realmname) local r = assert(realmname) for i,h in ipairs(self.history) do @@ -1570,6 +1573,50 @@ end end end + + function addon:reassign_loot (index, name_to) + local e = assert(g_loot[index], "trying to reassign nonexistant entry") + assert(e.kind=='loot', "trying to reassign something that isn't loot") + assert(type(name_to)=='string' and name_to:len()>0) + + local name_from = e.person + local tag = e.history_unique + local errtxt + + if not tag then + errtxt = "Entry for %s is missing a history tag!" + else + local from_i,from_h = self:get_loot_history(name_from) + local to_i,to_h = self:get_loot_history(name_to) + + local hi + for i,h in ipairs(from_h) do + local unique = h.id .. ' ' .. h.when + if unique == tag then + hi = i + break + end + end + if not hi then + -- 1) loot an item, 2) clear old history, 3) reassign from current loot + -- Bah. Anybody that tricky is already recoding the tables directly anyhow. + errtxt = "There is no record of %s ever having been assigned!" + else + hi = tremove (from_h, hi) + tinsert (to_h, 1, hi) + tsort (from_h, comp) + tsort (to_h, comp) + end + end + + if errtxt then + self:Print(errtxt .. " Loot will be reassigned but history will NOT be updated.", e.itemlink) + end + e.person = name_to + e.person_class = select(2,UnitClass(name_to)) + + self:Print("Reassigned entry %d from '%s' to '%s'.", index, name_from, name_to) + end end