Thread: Math Help
View Single Post
01-27-12, 03:56 PM   #37
Grimsin
A Molten Giant
 
Grimsin's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 990
the code for the function to get durability as well as the tooltip function thats supposed to display the repair cost...
Code:
-- Durability Frame --
local equipCost = 0;
local bagCost = 0;
local totalCost = 0;
local pEquipDura = { min=0, max=0};
local pBagDura = { min=0, max=0};
local slots = { "HeadSlot", "ShoulderSlot", "ChestSlot", "WaistSlot", "WristSlot", "HandsSlot", "LegsSlot", "FeetSlot", "MainHandSlot", "SecondaryHandSlot", "RangedSlot" }
slots[0] = 'AmmoSlot'
local myTip = nil
function GUI_DashDurability:GetDurabilityInfo()
	pEquipDura = { min=0, max=0};
	pBagDura = { min=0, max=0};
	if not tmpTip then tmpTip = CreateFrame("GameTooltip", "GUITT") end
	equipCost = 0
	for _, slotName in ipairs(slots) do
		local item = _G["Character" .. slotName]
		local hasItem, _, repairCost = tmpTip:SetInventoryItem("player", item:GetID())
		local Minimum, Maximum = GetInventoryItemDurability(item:GetID())
		if hasItem and repairCost and repairCost > 0 then
			equipCost = equipCost + repairCost
		end
		if Minimum and Maximum then
			pEquipDura.min = pEquipDura.min + Minimum
			pEquipDura.max = pEquipDura.max + Maximum
		end
	end
	bagCost = 0
	for bag = 0, 4 do
		for slot = 1, GetContainerNumSlots(bag) do
			local hasCooldown, repairCost = tmpTip:SetBagItem(bag, slot)
			local Minimum, Maximum = GetContainerItemDurability(bag, slot)
			if repairCost and repairCost > 0 then
				bagCost = bagCost + repairCost
			end
			if Minimum and Maximum then
				pBagDura.min = pBagDura.min + Minimum
				pBagDura.max = pBagDura.max + Maximum
			end
		end
	end
	if bagCost < 0 then bagCost = 0 end
	totalCost = equipCost + bagCost
end
local function GUI_DashDurability_OnEnter(self)
	if not myTip then
		myTip = CreateFrame('GameTooltip')
		myTip:Hide()
	end
	local cP = (pEquipDura.max > 0 and floor(pEquipDura.min / pEquipDura.max * 100)) or 100
	local bP = (pBagDura.max > 0 and floor(pBagDura.min / pBagDura.max * 100)) or 100
	local tP = ((pEquipDura.max + pBagDura.max) > 0 and floor( (pEquipDura.min + pBagDura.min) / (pEquipDura.max + pBagDura.max) * 100)) or 100
	if cP > 100 then cP = 100 end
	if bP > 100 then bP = 100 end
	if tP > 100 then tP = 100 end
	GUI_ToolTipSetup(self)
	GameTooltip:AddLine(_G['REPAIR_COST'])
	GameTooltip:AddLine(" ")
	GameTooltip:AddDoubleLine(_G['CURRENTLY_EQUIPPED'].." ("..addon:DurColor(cP)..cP.."%|r".."):", addon:MoneyToString(equipCost, true))
	GameTooltip:AddDoubleLine("Inventory".." ("..addon:DurColor(bP)..bP.."%|r".."):", addon:MoneyToString(bagCost, true))
	GameTooltip:AddLine(" ")
	GameTooltip:AddDoubleLine(_G['REPAIR_ALL_ITEMS'].." ("..addon:DurColor(tP)..tP.."%|r".."):", addon:MoneyToString(totalCost, true))
	GameTooltip:AddDoubleLine("Friendly Discount", addon:MoneyToString(math.floor(totalCost * 0.95), true))
	GameTooltip:AddDoubleLine("Honored Discount", addon:MoneyToString(math.floor(totalCost * 0.9), true))
	GameTooltip:AddDoubleLine("Revered Discount", addon:MoneyToString(math.floor(totalCost * 0.85), true))
	GameTooltip:AddDoubleLine("Exaulted Discount", addon:MoneyToString(math.floor(totalCost * 0.8), true))
	GameTooltip:AddLine(" ")
	GameTooltip:AddLine("|cffeda55fLeft Click|r toggle Auto-Repair  " .. (addon.settings.autoRepair and "|cff88ff88on|r" or "|cffff8888off|r"), 0.2, 1, 0.2)
	GameTooltip:AddLine("|cffeda55fRight Click|r toggle Guild Funds  " .. (addon.settings.GuildRepair and "|cff88ff88on|r" or "|cffff8888off|r"), 0.2, 1, 0.2)
	GameTooltip:Show()
end
GUI_DashDurability:SetScript('OnEnter', GUI_DashDurability_OnEnter)
__________________
"Are we there yet?"

GrimUI
[SIGPIC][/SIGPIC]
  Reply With Quote