It is currently 04 Sep 2025, 06:00
   
Text Size

An approximation of "add one mana of any color"

Moderator: CCGHQ Admins

An approximation of "add one mana of any color"

Postby thefiremind » 12 Aug 2012, 19:16

I don't want to delude you: I didn't find the ultimate trick, it's just an approximation that works good for very specific purposes. I'm showing you because maybe someone could get inspiration for something better.

I was browsing through the Magic expansions looking at the theme decks, and suddenly I wanted to make a deck inspired from the Sunburst theme deck. Yes, it's crazy, knowing the limitations that we have on mana abilities. But if you think about it, sunburst just requires to spend as many colors of mana as possible, it doesn't matter which ones. So in most cases we want to access the mana that we can't already access. That could be achieved with an "if" chain of GrantAbility: if you can't afford white, then grant the ability for white mana, else if you can't afford blue, then grant the ability for blue mana, else etc...
Looks good, but not good enough. I wanted to give the "if" chain a slight adaptability, so that it tries to grant the most useful mana colors first.
This is what I came up with (ColourToString is a function I had already made some time ago):
Code: Select all
ColourToString = function(colour)
-- converts color constants (i.e. COLOUR_RED) to mana strings (i.e. "{R}")
   local mana_table = {"{W}", "{U}", "{B}", "{R}", "{G}"}
   return mana_table[colour]
end

GetTopColour = function(position, zone, player)
-- makes a top 5 of the most recurrent mana symbols in zone (eventually limited by player), then returns the specified position (as a color constant)
   local filter = Object():GetFilter()
   local temp_table = {}
   local top_table = {}
   for i=1,5 do
      filter:Clear()
      filter:SetZone(zone)
      if player ~= nil then
         filter:SetPlayer(player)
      end
      temp_table[i] = filter:ChromaCount(i)
   end
   for j=1,5 do
      local best_position = 1
      for i=2,5 do
         if temp_table[i] > temp_table[best_position] then
            best_position = i
         end   
      end
      temp_table[best_position] = -1
      top_table[j] = best_position
   end
   if position > 0 and position < 6 then
      return top_table[position]
   else
      return 0
   end
end

GrantManaAbilityByTopColour = function()
-- grants a mana ability according to the top 5 of the most recurrent mana symbols in EffectController's hand
   local top_table = {}
   local player = EffectController()
   for i=1,5 do
      top_table[i] = GetTopColour(i, ZONE_HAND, player)
   end
   if player:CanAfford( ColourToString(top_table[1]) ) == 0 then
      Object():GetCurrentCharacteristics():GrantAbility(top_table[1])
   elseif player:CanAfford( ColourToString(top_table[2]) ) == 0 then
      Object():GetCurrentCharacteristics():GrantAbility(top_table[2])
   elseif player:CanAfford( ColourToString(top_table[3]) ) == 0 then
      Object():GetCurrentCharacteristics():GrantAbility(top_table[3])
   elseif player:CanAfford( ColourToString(top_table[4]) ) == 0 then
      Object():GetCurrentCharacteristics():GrantAbility(top_table[4])
   elseif player:CanAfford( ColourToString(top_table[5]) ) == 0 then
      Object():GetCurrentCharacteristics():GrantAbility(top_table[5])
   else
      Object():GetCurrentCharacteristics():GrantAbility(top_table[1])
   end
end
With these functions in a LOL file, all I need to write on the card is a static ability with:
Code: Select all
    <CONTINUOUS_ACTION>
    GrantManaAbilityByTopColour()
    </CONTINUOUS_ACTION>
and the mana abilities, each with the resource_id equal to the corresponding color constant value.

I don't even have to give you a list of the possible cases where this method doesn't grant the mana you really need, it's obvious that you can't always rely on this automation. But for the purpose of a sunburst deck, some copies of Birds of Paradise and/or Darksteel Ingot with this code will be useful.

EDIT: A possible variation:
Code: Select all
GrantManaAbilityByLeastAvailableColour = function()
-- grants a mana ability according to the least available mana color for EffectController, checking in top 5 order (as the previous function)
   local top_table = {}
   local availability_table = {}
   local player = EffectController()
   for i=1,5 do
      top_table[i] = GetTopColour(i, ZONE_HAND, player)
   end
   for i=1,5 do
      availability_table[i] = GetTotalManaOfColour(player, top_table[i])
   end
   local worst_position = 1
   for i=2,5 do
      if availability_table[i] < availability_table[worst_position] then
         worst_position = i
      end
   end
   Object():GetCurrentCharacteristics():GrantAbility(top_table[worst_position])
end
This uses the GetTotalManaOfColour function that I invented for the "spend only <color> mana this way" mechanic, and grants the least available mana. So it's slightly better than the previous one (I think I'll use this one), but still with flaws of course.
< Former DotP 2012/2013/2014 modder >
Currently busy with life...
User avatar
thefiremind
Programmer
 
Posts: 3515
Joined: 07 Nov 2011, 10:55
Has thanked: 118 times
Been thanked: 722 times

Return to Programming Talk

Who is online

Users browsing this forum: No registered users and 4 guests

Main Menu

User Menu

Our Partners


Who is online

In total there are 4 users online :: 0 registered, 0 hidden and 4 guests (based on users active over the past 10 minutes)
Most users ever online was 7303 on 15 Jul 2025, 20:46

Users browsing this forum: No registered users and 4 guests

Login Form