annotate Plugins/ItemCountAddons/DataStore (with guilds).lua @ 156:314943963155

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