Page 1 of 1

[DotP2013] Simic Manipulator

PostPosted: 15 Mar 2013, 14:57
by BETenner
I thought this card would be very difficult to implement.
I tried my solution, but it leads to crash (yes, crash, not error)
Is there a way to implement this card?

Here's my code:
Code: Select all
  <ACTIVATED_ABILITY filter_zone="ZONE_IN_PLAY">
    <COST type="TapSelf"/>
    <TARGET_DEFINITION id="0">
      local filter = Object():GetFilter()
      filter:Clear()
      filter:AddCardType(CARD_TYPE_CREATURE)
      filter:SetZone(ZONE_IN_PLAY)
    </TARGET_DEFINITION>
    <TARGET_DETERMINATION>
      return AtLeastOneTargetFromDefinition(0)
    </TARGET_DETERMINATION>
    <PLAY_TIME_ACTION>
      local index = ObjectDC():Get_Int(0)
      EffectController():ChooseTarget( 0, "CARD_QUERY_CHOOSE_CREATURE_TO_GAIN_CONTROL", EffectDC():Make_Targets(index) )
    </PLAY_TIME_ACTION>
    <PLAY_TIME_ACTION>
      EffectController():BeginNewNumericalChoice()
      EffectController():AddNumericalChoiceAnswer(Object():CountCounters(MTG():PlusOnePlusOneCounters()))
      EffectController():AskNumericalChoiceQuestion("CARD_QUERY_CHOOSE_REMOVE_X_1_1_COUNTER")
    </PLAY_TIME_ACTION>
    <RESOLUTION_TIME_ACTION>
      local index = ObjectDC():Get_Int(0)
      local target = EffectDC():Get_Targets(index) and EffectDC():Get_Targets(index):Get_CardPtr(0)
      local x = Object():GetNumericalChoiceResult()
      if (target ~= nil and
        Object():CountCounters(MTG():PlusOnePlusOneCounters()) &gt; x - 1 and
        target:GetCurrentPower() &lt; x + 1) then
        Object():RemoveCounters(MTG():PlusOnePlusOneCounters(), x)
        ObjectDC():Set_CardPtr(index, target)
        ObjectDC():Set_Int(0, index + 1)
      end
    </RESOLUTION_TIME_ACTION>
    <CONTINUOUS_ACTION layer="4">
      local count = ObjectDC():Get_Int(0)
      for i=0,count do
        local target = ObjectDC():Get_CardPtr(i)
        if (target ~= nil) then
          target:SetController(Object():GetController())
        end
      end
    </CONTINUOUS_ACTION>
  </ACTIVATED_ABILITY>

Re: [DotP2013] Simic Manipulator

PostPosted: 15 Mar 2013, 15:40
by RiiakShiNal
Try this for the second ability of Simic Manipulator:

Code: Select all
  <ACTIVATED_ABILITY filter_zone="ZONE_IN_PLAY">
    <COST type="TapSelf"/>
    <TARGET_DEFINITION id="0">
      local filter = Object():GetFilter()
      filter:Clear()
      filter:AddCardType(CARD_TYPE_CREATURE)
      filter:SetZone(ZONE_IN_PLAY)
      filter:SetPowerMax(Object():CountCounters(MTG():PlusOnePlusOneCounters())
    </TARGET_DEFINITION>
    <TARGET_DETERMINATION>
      return AtLeastOneTargetFromDefinition(0)
    </TARGET_DETERMINATION>
    <PLAY_TIME_ACTION>
      EffectController():ChooseTarget( 0, "CARD_QUERY_CHOOSE_CREATURE_TO_GAIN_CONTROL", EffectDC():Make_Targets(0) )
    </PLAY_TIME_ACTION>
    <PLAY_TIME_ACTION>
      local target = EffectDC():Get_Targets(0):Get_CardPtr(0)
      if (target ~= nil) then
        local countersRemoved = target:GetCurrentCharacteristics():Power_Get()
        Object():RemoveCounters(MTG():PlusOnePlusOneCounters(), countersRemoved)
        EffectDC():Int_Set(1, countersRemoved)
      end
    </PLAY_TIME_ACTION>
    <RESOLUTION_TIME_ACTION>
      local target = EffectDC():Get_Targets(0):Get_CardPtr(0)
      local countersRemoved = EffectDC():Int_Get(1)
      if (target ~= nil) then
        if (target:GetCurrentCharacteristics():Power_Get() &lt;= countersRemoved) then
          target:SetPermanentController(EffectController())
        end
      end
    </RESOLUTION_TIME_ACTION>
  </ACTIVATED_ABILITY>
Edit: Forgot to check current power on resolution as well (as per ruling), now added.

This is a simplistic method and does not allow for padding the amount removed, that could be added, but makes things a bit more complicated.

Edit 2: Updated to use GetCurrentCharacteristics():Power_Get() instead of GetCurrentPower().

Re: [DotP2013] Simic Manipulator

PostPosted: 15 Mar 2013, 16:02
by thefiremind
Proliferate is also coded in a "best result with least effort" way, so I think this solution is perfectly acceptable.

Just one warning: if you see strange things happening, like you gain control of the target even after its power has been raised, it's because GetCurrentPower sometimes doesn't get updated results, I don't know why. If that's the case, just substitute target:GetCurrentPower() with target:GetCurrentCharacteristics():Power_Get() which always works.

Re: [DotP2013] Simic Manipulator

PostPosted: 15 Mar 2013, 16:08
by RiiakShiNal
Fair enough, updated to use GetCurrentCharacteristics():Power_Get() instead of GetCurrentPower().

Re: [DotP2013] Simic Manipulator

PostPosted: 16 Mar 2013, 02:39
by BETenner
Thanks!
Due to the ruling, you can't remove 0 +1/+1 counter to gain control of a creature with 0 or less power. So I added a check in the resolution to make sure you removed at least 1 +1/+1 counter.

Re: [DotP2013] Simic Manipulator

PostPosted: 16 Mar 2013, 03:26
by RiiakShiNal
Good catch, an oversight on my part, though since removing the counters is actually part of the cost it should be done in the PLAY_TIME_ACTION (where the counters are normally removed) instead of at resolution time. So the action would become this:
Code: Select all
    <PLAY_TIME_ACTION>
      local target = EffectDC():Get_Targets(0):Get_CardPtr(0)
      if (target ~= nil) then
        local countersRemoved = target:GetCurrentCharacteristics():Power_Get()
        if (countersRemoved &lt; 1) then
          countersRemoved = 1
        end
        Object():RemoveCounters(MTG():PlusOnePlusOneCounters(), countersRemoved)
        EffectDC():Int_Set(1, countersRemoved)
      end
    </PLAY_TIME_ACTION>