It is currently 27 Apr 2024, 06:26
   
Text Size

Protection from colored spells (fixed)

Moderator: CCGHQ Admins

Protection from colored spells (fixed)

Postby sumomole » 29 Jun 2013, 04:39

When I code Emrakul, the Aeons Torn, I found something that hasn't been noticed before, or it isn't the same as before, anyway, I haven't tried in DotP2013. #-o
If you would cast a spell, when you choose target, the card is regarded as on the stack, so "protection from stack" can prevent it, similarly, when you choose target for a ability, the ability is regarded as on the stack too, but the card that has the ability not. So, protection from colored spells is easy to code, as the following:
Code: Select all
  <STATIC_ABILITY>
    <LOCALISED_TEXT LanguageCode="en-US"><![CDATA[Protection from colored spells]]></LOCALISED_TEXT>
    <CONTINUOUS_ACTION layer="0">
    if EffectSource() ~= nil then
       local filter = ClearFilter()
      filter:Add( FE_NUM_COLOURS, OP_GREATER_THAN, 0 )
      filter:Add( FE_LUA_CONDITION, 0, EffectController())
       EffectSource():Protection()
    end
    </CONTINUOUS_ACTION>
    <FILTER_CONDITION id="0">
    if FilteredCard() ~= nil and FilteredCard():GetZone() == ZONE_STACK then
       return true
    else
       return false
    end
    </FILTER_CONDITION>
  </STATIC_ABILITY>
If you find any problems, please tell me, thank you. :)

EDIT:I found I missed something, if don't add this code, the the spell card in hand can still be cast even if Emrakul, the Aeons Torn is the only creature on the battlefield, just can't target Emrakul, the Aeons Torn and will be back to hand.
Code: Select all
  <TRIGGERED_ABILITY replacement_effect="1" linked_ability_group="1">
    <TRIGGER value="CONSIDERED_FOR_CAST" pre_trigger="1">
    return (TriggerObject():GetCardType():Test( CARD_TYPE_SORCERY ) or TriggerObject():GetCardType():Test( CARD_TYPE_INSTANT ) or TriggerObject():GetSubType():Test( ENCHANTMENT_TYPE_AURA ))
    </TRIGGER>
    <RESOLUTION_TIME_ACTION>
    local current_card = TriggerObject()
    if current_card ~= nil then
      local i=0
      local chest = LinkedDC():Get_Chest(0)
      if chest == nil then
        chest = LinkedDC():Make_Chest(0)
      else
        local card = chest:Get_CardPtr(i)
        while card ~= nil do
          if card == current_card then
            return
          end
          i=i+1
          card = chest:Get_CardPtr(i)
        end
      end
      chest:Set_CardPtr(i, current_card)
    end
    </RESOLUTION_TIME_ACTION>
  </TRIGGERED_ABILITY>
  <TRIGGERED_ABILITY replacement_effect="1" linked_ability_group="1">
    <TRIGGER value="CARD_CONSIDERED_FOR_TARGETTING" simple_qualifier="self" pre_trigger="1">
    local chest = LinkedDC():Get_Chest(0)
    if chest ~= nil and SecondaryObject() ~= nil and SecondaryObject():GetColour():GetNumColours() &gt; 0 then
      for i=0,999 do
        local card = chest:Get_CardPtr(i)
        if card ~= nil and card == SecondaryObject() then
            return true
         end
       end
    end
    return false
    </TRIGGER>
  </TRIGGERED_ABILITY>
User avatar
sumomole
Programmer
 
Posts: 611
Joined: 07 Jun 2011, 08:34
Has thanked: 51 times
Been thanked: 234 times

Return to Programming Talk

Who is online

Users browsing this forum: No registered users and 33 guests


Who is online

In total there are 33 users online :: 0 registered, 0 hidden and 33 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 33 guests

Login Form