Page 1 of 1

New card - Triumph of Ferocity

PostPosted: 30 May 2014, 05:23
by PhilistineAu
Hi,

I've tried putting together a new card, "Triumph of Ferocity". The trigger is: At the beginning of your upkeep, draw a card if you control the creature with the greatest power or tied for the greatest power.

This is what I have cobbled together so far. I have the may line in there just to see if it works, but I'll need to take that out.

Right now the problem I am having is that the card works, but when I have two played it will only draw one card. It asks me twice if I want to activate the ability, and I click yes both times, but only 1 card is drawn.

As a general programming question, I'm not sure what local max_opponent_power = -10000 or the equivalent for player at -10001 is doing.... I'm assuming those are the starting values but why so negative? Is the player 1 lower to stop the player drawing a card when there are no creatures on the board?


If anyone has any suggestions for how to fix the bug / improvement I would gratefully hear them and incorporate them.

Thanks,

Phil


Code: Select all
<TRIGGER value="BEGINNING_OF_PLAYERS_STEP" simple_qualifier="controller">
    return MTG():GetStep() == STEP_UPKEEP
    </TRIGGER>
      <MAY always_prompt="1" />
      <RESOLUTION_TIME_ACTION>
    local num_starting_players = MTG():GetNumberOfStartingPlayers()
    local max_opponent_power = -10000
    local max_player_power = -10001
    local filter = ClearFilter()
    for i=0,(num_starting_players-1) do
       local player = MTG():GetNthStartingPlayer(i)
       if player ~= nil then
          if player ~= EffectController() then
             filter:Clear()
             filter:Add( FE_TYPE, OP_IS, CARD_TYPE_CREATURE )
             filter:Add( FE_CONTROLLER, OP_IS, player)
             local num_creatures = filter:EvaluateObjects()
             for j=0,(num_creatures-1) do
                current_power = filter:GetNthEvaluatedObject(j):GetCurrentCharacteristics():Power_Get()
                if current_power &gt; max_opponent_power then
                   max_opponent_power = current_power          
                end
             end
          else
             filter:Clear()
             filter:Add( FE_TYPE, OP_IS, CARD_TYPE_CREATURE )
             filter:Add( FE_CONTROLLER, OP_IS, player)
             local num_creatures = filter:EvaluateObjects()
             for j=0,(num_creatures-1) do
                current_power = filter:GetNthEvaluatedObject(j):GetCurrentCharacteristics():Power_Get()
                if current_power &gt; max_player_power then
                   max_player_power = current_power
                end
             end
          end
       end
    end
    if max_player_power &gt;= max_opponent_power then
       filter:Clear()
   EffectController():DrawCards(1)
  </RESOLUTION_TIME_ACTION>
  </TRIGGERED_ABILITY>

Re: New card - Triumph of Ferocity

PostPosted: 30 May 2014, 05:31
by PhilistineAu
Also, I need to add an "end" after the "if" statement for card draw, just before </RESOLUTION_TIME_ACTION>.

Re: New card - Triumph of Ferocity

PostPosted: 30 May 2014, 08:21
by thefiremind
This is how I code Triumph of Ferocity:
Code: Select all
    <TRIGGER value="BEGINNING_OF_PLAYERS_STEP" simple_qualifier="controller">
    return MTG():GetStep() == STEP_UPKEEP
    </TRIGGER>
    <RESOLUTION_TIME_ACTION>
    local player = EffectController()
    local filter = ClearFilter()
    filter:Add(FE_TYPE, OP_IS, CARD_TYPE_CREATURE)
    local count = filter:CountStopAt(1)
    if count == 1 then
       local power = -1
       while count == 1 do
          power = power + 1
          filter:Clear()
          filter:Add(FE_TYPE, OP_IS, CARD_TYPE_CREATURE)
          filter:Add(FE_POWER, OP_GREATER_THAN, power)
          count = filter:CountStopAt(1)
       end
       -- now "power" is equal to the greatest power
       filter:Clear()
       filter:Add(FE_TYPE, OP_IS, CARD_TYPE_CREATURE)
       filter:Add(FE_POWER, OP_GREATER_THAN_OR_EQUAL_TO, power)
       filter:Add(FE_CONTROLLER, OP_IS, player)
       if filter:CountStopAt(1) == 1 then
         player:DrawCards(1)
       end
    end
    </RESOLUTION_TIME_ACTION>
I see if there's at least a creature with more than 0 power, then more than 1 power, then more than 2, and so on. When I find no creatures it means the latest power I had was the greatest one, so I just have to verify if I control at least a creature with such power.

By the way, this card doesn't need a MAY, the card drawing is mandatory.

Re: New card - Triumph of Ferocity

PostPosted: 30 May 2014, 12:55
by PhilistineAu
Thank you!

Is this in one of your packs and I just missed it?

Best regards,

Phil

Re: New card - Triumph of Ferocity

PostPosted: 30 May 2014, 14:44
by thefiremind
PhilistineAu wrote:Is this in one of your packs and I just missed it?
No, don't worry... at first I thought it was, but then after a search on my DotP folder I found it among the cards that were meant to be in decks that I have never finished.