comparison Plugins/ItemCountAddons/DataStore (all accounts).lua @ 157:e136c99fe5bb

You can now select which guilds to include in the item count when selecting an item count supporting this. Renamed DataStore (with guilds) to ?all accounts?. Removed DataStore (without guilds) option.
author Zerotorescue
date Sat, 22 Jan 2011 19:24:48 +0100
parents
children
comparison
equal deleted inserted replaced
156:314943963155 157:e136c99fe5bb
1 do
2 local disabledGuilds = {};
3
4 local function GetGuildNames()
5 local guilds = {};
6
7 local realm = GetRealmName();
8
9 -- Process all accounts
10 for accountName in pairs(DataStore:GetAccounts()) do
11 for guildName, guild in pairs(DataStore:GetGuilds(realm, accountName)) do
12
13 if disabledGuilds[guildName] then
14 guilds[guildName] = false;
15 else
16 guilds[guildName] = true;
17 end
18
19 end
20 end
21
22 return guilds;
23 end
24
25 local function SetGuildState(guildName, state)
26 if guildName and type(guildName) == "table" then
27 disabledGuilds = guildName;
28 else
29 if not state then
30 disabledGuilds[guildName] = true;
31 else
32 disabledGuilds[guildName] = nil;
33 end
34 end
35 end
36
37 local function GetTotalCount(itemId)
38 local realm = GetRealmName();
39
40 local totalCount = 0;
41
42 local guilds = {};
43
44 -- Process all accounts
45 for accountName in pairs(DataStore:GetAccounts()) do
46 -- Process all charracters
47 for characterName, character in pairs(DataStore:GetCharacters(realm, accountName)) do
48 -- Get only useful info (currency / gear shouldn't contain the stuff we are interested in)
49 local bag, bank = DataStore:GetContainerItemCount(character, itemId);
50 bag = (bag or 0); bank = (bank or 0);
51 local auctionHouse = DataStore:GetAuctionHouseItemCount(character, itemId) or 0;
52 local mail = DataStore:GetMailItemCount(character, itemId) or 0;
53
54 totalCount = totalCount + bag + bank + auctionHouse + mail;
55 end
56
57 -- Process all guilds
58 for guildName, guild in pairs(DataStore:GetGuilds(realm, accountName)) do
59 if not guilds[guildName] and not disabledGuilds[guildName] then
60 -- We don't want itemcounts from a single guild to be counted twice, so first to present data wins
61
62 guilds[guildName] = true;
63
64 local guild = DataStore:GetGuildBankItemCount(guild, itemId) or 0;
65
66 totalCount = totalCount + guild;
67 end
68 end
69 end
70
71 return totalCount or -1;
72 end
73
74 local function GetCharacterCount(itemId)
75 local character = DataStore:GetCharacter();
76
77 local bag, bank = DataStore:GetContainerItemCount(character, itemId);
78 bag = (bag or 0); bank = (bank or 0);
79 local auctionHouse = DataStore:GetAuctionHouseItemCount(character, itemId) or 0;
80 local mail = DataStore:GetMailItemCount(character, itemId) or 0;
81
82 return bag, bank, auctionHouse, mail;
83 end
84
85 local function IsEnabled()
86 return (DataStore and DataStore.GetContainerItemCount and DataStore.GetAuctionHouseItemCount and DataStore.GetMailItemCount);
87 end
88
89 IMRegisterItemCountAddon("DataStore (all accounts)", GetTotalCount, GetCharacterCount, IsEnabled, nil, GetGuildNames, SetGuildState);
90
91 end