changeset 160:08b887885bd5

Forgot to include guilds in the ?DataStore (current account only)? item count plugin.
author Zerotorescue
date Sat, 22 Jan 2011 21:30:02 +0100
parents d45806866255
children fcc95c62d232
files Plugins/ItemCountAddons/DataStore (current account only).lua
diffstat 1 files changed, 53 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/Plugins/ItemCountAddons/DataStore (current account only).lua	Sat Jan 22 19:28:02 2011 +0100
+++ b/Plugins/ItemCountAddons/DataStore (current account only).lua	Sat Jan 22 21:30:02 2011 +0100
@@ -1,4 +1,38 @@
 do
+	local disabledGuilds = {};
+	
+	local function GetGuildNames()
+		local guilds = {};
+		
+		local realm = GetRealmName();
+		
+		-- Process all accounts
+		for accountName in pairs(DataStore:GetAccounts()) do
+			for guildName, guild in pairs(DataStore:GetGuilds(realm, accountName)) do
+			
+				if disabledGuilds[guildName] then
+					guilds[guildName] = false;
+				else
+					guilds[guildName] = true;
+				end
+				
+			end
+		end
+		
+		return guilds;
+	end
+	
+	local function SetGuildState(guildName, state)
+		if guildName and type(guildName) == "table" then
+			disabledGuilds = guildName;
+		else
+			if not state then
+				disabledGuilds[guildName] = true;
+			else
+				disabledGuilds[guildName] = nil;
+			end
+		end
+	end
 	
 	local function GetTotalCount(itemId)
 		local realm = GetRealmName();
@@ -16,6 +50,24 @@
 			totalCount = totalCount + bag + bank + auctionHouse + mail;
 		end
 		
+		local guilds = {};
+		
+		-- Process all accounts
+		for accountName in pairs(DataStore:GetAccounts()) do
+			-- Process all guilds
+			for guildName, guild in pairs(DataStore:GetGuilds(realm, accountName)) do
+				if not guilds[guildName] and not disabledGuilds[guildName] then
+					-- We don't want itemcounts from a single guild to be counted twice, so first to present data wins
+					
+					guilds[guildName] = true;
+					
+					local guild = DataStore:GetGuildBankItemCount(guild, itemId) or 0;
+				
+					totalCount = totalCount + guild;
+				end
+			end
+		end
+		
 		return totalCount or -1;
 	end
 	
@@ -34,6 +86,6 @@
 		return (DataStore and DataStore.GetContainerItemCount and DataStore.GetAuctionHouseItemCount and DataStore.GetMailItemCount);
 	end
 	
-	IMRegisterItemCountAddon("DataStore (current account only)", GetTotalCount, GetCharacterCount, IsEnabled);
+	IMRegisterItemCountAddon("DataStore (current account only)", GetTotalCount, GetCharacterCount, IsEnabled, nil, GetGuildNames, SetGuildState);
 	
 end