annotate Plugins/ItemCountAddons/DataStore (current account only).lua @ 249:fa21e06ca268 tip

Added tag v1.0.1-ALPHA for changeset 50aece0904ec
author Zerotorescue
date Tue, 08 Mar 2011 12:07:24 +0100
parents 08b887885bd5
children
rev   line source
Zerotorescue@17 1 do
Zerotorescue@160 2 local disabledGuilds = {};
Zerotorescue@160 3
Zerotorescue@160 4 local function GetGuildNames()
Zerotorescue@160 5 local guilds = {};
Zerotorescue@160 6
Zerotorescue@160 7 local realm = GetRealmName();
Zerotorescue@160 8
Zerotorescue@160 9 -- Process all accounts
Zerotorescue@160 10 for accountName in pairs(DataStore:GetAccounts()) do
Zerotorescue@160 11 for guildName, guild in pairs(DataStore:GetGuilds(realm, accountName)) do
Zerotorescue@160 12
Zerotorescue@160 13 if disabledGuilds[guildName] then
Zerotorescue@160 14 guilds[guildName] = false;
Zerotorescue@160 15 else
Zerotorescue@160 16 guilds[guildName] = true;
Zerotorescue@160 17 end
Zerotorescue@160 18
Zerotorescue@160 19 end
Zerotorescue@160 20 end
Zerotorescue@160 21
Zerotorescue@160 22 return guilds;
Zerotorescue@160 23 end
Zerotorescue@160 24
Zerotorescue@160 25 local function SetGuildState(guildName, state)
Zerotorescue@160 26 if guildName and type(guildName) == "table" then
Zerotorescue@160 27 disabledGuilds = guildName;
Zerotorescue@160 28 else
Zerotorescue@160 29 if not state then
Zerotorescue@160 30 disabledGuilds[guildName] = true;
Zerotorescue@160 31 else
Zerotorescue@160 32 disabledGuilds[guildName] = nil;
Zerotorescue@160 33 end
Zerotorescue@160 34 end
Zerotorescue@160 35 end
Zerotorescue@17 36
Zerotorescue@17 37 local function GetTotalCount(itemId)
Zerotorescue@17 38 local realm = GetRealmName();
Zerotorescue@17 39
Zerotorescue@17 40 local totalCount = 0;
Zerotorescue@17 41
Zerotorescue@17 42 -- Process all charracters on this account (GetCharacters defaults to THIS_ACCOUNT)
Zerotorescue@17 43 for characterName, character in pairs(DataStore:GetCharacters(realm, nil)) do
Zerotorescue@17 44 -- Get only useful info (currency / gear shouldn't contain the stuff we are interested in)
Zerotorescue@118 45 local bag, bank = DataStore:GetContainerItemCount(character, itemId);
Zerotorescue@118 46 bag = (bag or 0); bank = (bank or 0);
Zerotorescue@54 47 local auctionHouse = DataStore:GetAuctionHouseItemCount(character, itemId) or 0;
Zerotorescue@54 48 local mail = DataStore:GetMailItemCount(character, itemId) or 0;
Zerotorescue@17 49
Zerotorescue@17 50 totalCount = totalCount + bag + bank + auctionHouse + mail;
Zerotorescue@17 51 end
Zerotorescue@17 52
Zerotorescue@160 53 local guilds = {};
Zerotorescue@160 54
Zerotorescue@160 55 -- Process all accounts
Zerotorescue@160 56 for accountName in pairs(DataStore:GetAccounts()) do
Zerotorescue@160 57 -- Process all guilds
Zerotorescue@160 58 for guildName, guild in pairs(DataStore:GetGuilds(realm, accountName)) do
Zerotorescue@160 59 if not guilds[guildName] and not disabledGuilds[guildName] then
Zerotorescue@160 60 -- We don't want itemcounts from a single guild to be counted twice, so first to present data wins
Zerotorescue@160 61
Zerotorescue@160 62 guilds[guildName] = true;
Zerotorescue@160 63
Zerotorescue@160 64 local guild = DataStore:GetGuildBankItemCount(guild, itemId) or 0;
Zerotorescue@160 65
Zerotorescue@160 66 totalCount = totalCount + guild;
Zerotorescue@160 67 end
Zerotorescue@160 68 end
Zerotorescue@160 69 end
Zerotorescue@160 70
Zerotorescue@17 71 return totalCount or -1;
Zerotorescue@17 72 end
Zerotorescue@17 73
Zerotorescue@17 74 local function GetCharacterCount(itemId)
Zerotorescue@17 75 local character = DataStore:GetCharacter();
Zerotorescue@17 76
Zerotorescue@118 77 local bag, bank = DataStore:GetContainerItemCount(character, itemId);
Zerotorescue@118 78 bag = (bag or 0); bank = (bank or 0);
Zerotorescue@54 79 local auctionHouse = DataStore:GetAuctionHouseItemCount(character, itemId) or 0;
Zerotorescue@54 80 local mail = DataStore:GetMailItemCount(character, itemId) or 0;
Zerotorescue@17 81
Zerotorescue@17 82 return bag, bank, auctionHouse, mail;
Zerotorescue@17 83 end
Zerotorescue@17 84
Zerotorescue@17 85 local function IsEnabled()
Zerotorescue@17 86 return (DataStore and DataStore.GetContainerItemCount and DataStore.GetAuctionHouseItemCount and DataStore.GetMailItemCount);
Zerotorescue@17 87 end
Zerotorescue@17 88
Zerotorescue@160 89 IMRegisterItemCountAddon("DataStore (current account only)", GetTotalCount, GetCharacterCount, IsEnabled, nil, GetGuildNames, SetGuildState);
Zerotorescue@17 90
Zerotorescue@17 91 end