Functions for mana cost retrieval

I just inserted the following functions in my GENERAL_FUNCTIONS.LOL file:
As I wrote in the file, I think they could generate wrong results with hybrid or phyrexian mana. You must also be careful not to use those functions while you are setting another filter, otherwise you would clear it and screw what you are doing (same as CountCardsInHand and similar).
- Code: Select all
ManaCost = function(object, colour)
-- returns the amount of mana of the selected colour in object's cost
local filter = Object():GetFilter()
filter:Clear()
filter:NotTargetted()
filter:SetCardInstance(object)
return filter:ChromaCount(colour)
end
ManaCostString = function(object, colour)
-- same as ManaCost, but it generates a string (useful for TapLand, CanAfford, etc.)
local amount = ManaCost(object, colour)
if amount > 0 then
local colour_table = {"{W}", "{U}", "{B}", "{R}", "{G}"}
local string = ""
for i=1,amount do
string = string..colour_table[colour]
end
return string
else
return "{0}"
end
end
FullManaCostString = function(object)
-- returns the full mana cost string (I think it won't work properly with hybrid or phyrexian mana, for obvious reasons)
local cmc = object:GetConvertedManaCost()
if cmc > 0 then
local string = ""
local coloured_mana = 0
for i=1,5 do
local amount = ManaCost(object, i)
coloured_mana = coloured_mana + amount
if amount > 0 then
string = string..ManaCostString(object, i)
end
end
if cmc > coloured_mana then
string = "{"..(cmc-coloured_mana).."}"..string
end
return string
else
return "{0}"
end
end
As I wrote in the file, I think they could generate wrong results with hybrid or phyrexian mana. You must also be careful not to use those functions while you are setting another filter, otherwise you would clear it and screw what you are doing (same as CountCardsInHand and similar).