It is currently 18 Apr 2024, 13:07
   
Text Size

[DotP2013] Simic Manipulator

Moderator: CCGHQ Admins

[DotP2013] Simic Manipulator

Postby BETenner » 15 Mar 2013, 14:57

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>
BETenner
 
Posts: 36
Joined: 07 Mar 2013, 14:20
Has thanked: 7 times
Been thanked: 4 times

Re: [DotP2013] Simic Manipulator

Postby RiiakShiNal » 15 Mar 2013, 15:40

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().
Last edited by RiiakShiNal on 15 Mar 2013, 16:07, edited 1 time in total.
RiiakShiNal
Programmer
 
Posts: 2185
Joined: 16 May 2011, 21:37
Has thanked: 75 times
Been thanked: 496 times

Re: [DotP2013] Simic Manipulator

Postby thefiremind » 15 Mar 2013, 16:02

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.
Last edited by thefiremind on 15 Mar 2013, 16:35, edited 1 time in total.
< 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: 721 times

Re: [DotP2013] Simic Manipulator

Postby RiiakShiNal » 15 Mar 2013, 16:08

Fair enough, updated to use GetCurrentCharacteristics():Power_Get() instead of GetCurrentPower().
RiiakShiNal
Programmer
 
Posts: 2185
Joined: 16 May 2011, 21:37
Has thanked: 75 times
Been thanked: 496 times

Re: [DotP2013] Simic Manipulator

Postby BETenner » 16 Mar 2013, 02:39

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.
BETenner
 
Posts: 36
Joined: 07 Mar 2013, 14:20
Has thanked: 7 times
Been thanked: 4 times

Re: [DotP2013] Simic Manipulator

Postby RiiakShiNal » 16 Mar 2013, 03:26

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>
RiiakShiNal
Programmer
 
Posts: 2185
Joined: 16 May 2011, 21:37
Has thanked: 75 times
Been thanked: 496 times


Return to Programming Talk

Who is online

Users browsing this forum: No registered users and 16 guests

cron

Who is online

In total there are 16 users online :: 0 registered, 0 hidden and 16 guests (based on users active over the past 10 minutes)
Most users ever online was 4143 on 23 Jan 2024, 08:21

Users browsing this forum: No registered users and 16 guests

Login Form