annotate Plugins/ItemCountAddons/DataStore (with guilds).lua @ 142:56f33abee1e3

Always making sure the mover window is not there and making the frame when all data is ready, rather than before checking if the confirmation should even appear.
author Zerotorescue
date Tue, 18 Jan 2011 23:00:18 +0100
parents de18ef96983b
children 314943963155
rev   line source
Zerotorescue@17 1 do
Zerotorescue@17 2
Zerotorescue@17 3 local function GetTotalCount(itemId)
Zerotorescue@17 4 local realm = GetRealmName();
Zerotorescue@17 5
Zerotorescue@17 6 local totalCount = 0;
Zerotorescue@17 7
Zerotorescue@17 8 local guilds = {};
Zerotorescue@17 9
Zerotorescue@17 10 -- Process all accounts
Zerotorescue@17 11 for accountName in pairs(DataStore:GetAccounts()) do
Zerotorescue@17 12
Zerotorescue@17 13 -- Process all charracters
Zerotorescue@17 14 for characterName, character in pairs(DataStore:GetCharacters(realm, accountName)) do
Zerotorescue@17 15 -- Get only useful info (currency / gear shouldn't contain the stuff we are interested in)
Zerotorescue@118 16 local bag, bank = DataStore:GetContainerItemCount(character, itemId);
Zerotorescue@118 17 bag = (bag or 0); bank = (bank or 0);
Zerotorescue@54 18 local auctionHouse = DataStore:GetAuctionHouseItemCount(character, itemId) or 0;
Zerotorescue@54 19 local mail = DataStore:GetMailItemCount(character, itemId) or 0;
Zerotorescue@17 20
Zerotorescue@17 21 totalCount = totalCount + bag + bank + auctionHouse + mail;
Zerotorescue@17 22 end
Zerotorescue@17 23
Zerotorescue@17 24 -- Process all guilds
Zerotorescue@17 25 for guildName, guild in pairs(DataStore:GetGuilds(realm, accountName)) do
Zerotorescue@17 26 if not guilds[guildName] then
Zerotorescue@17 27 -- We don't want itemcounts from a single guild to be counted twice, so first to present data wins
Zerotorescue@17 28
Zerotorescue@17 29 guilds[guildName] = true;
Zerotorescue@17 30
Zerotorescue@54 31 local guild = DataStore:GetGuildBankItemCount(guild, itemId) or 0;
Zerotorescue@17 32
Zerotorescue@17 33 totalCount = totalCount + guild;
Zerotorescue@17 34 end
Zerotorescue@17 35 end
Zerotorescue@17 36 end
Zerotorescue@17 37
Zerotorescue@17 38 return totalCount or -1;
Zerotorescue@17 39 end
Zerotorescue@17 40
Zerotorescue@17 41 local function GetCharacterCount(itemId)
Zerotorescue@17 42 local character = DataStore:GetCharacter();
Zerotorescue@17 43
Zerotorescue@118 44 local bag, bank = DataStore:GetContainerItemCount(character, itemId);
Zerotorescue@118 45 bag = (bag or 0); bank = (bank or 0);
Zerotorescue@54 46 local auctionHouse = DataStore:GetAuctionHouseItemCount(character, itemId) or 0;
Zerotorescue@54 47 local mail = DataStore:GetMailItemCount(character, itemId) or 0;
Zerotorescue@17 48
Zerotorescue@17 49 return bag, bank, auctionHouse, mail;
Zerotorescue@17 50 end
Zerotorescue@17 51
Zerotorescue@17 52 local function IsEnabled()
Zerotorescue@17 53 return (DataStore and DataStore.GetContainerItemCount and DataStore.GetAuctionHouseItemCount and DataStore.GetMailItemCount);
Zerotorescue@17 54 end
Zerotorescue@17 55
Zerotorescue@17 56 IMRegisterItemCountAddon("DataStore (with guilds)", GetTotalCount, GetCharacterCount, IsEnabled);
Zerotorescue@17 57
Zerotorescue@17 58 end