Board index Programs with AI or Rules Enforcement Magic: The Gathering - Duels of the Planeswalkers Programming Talk
Solution for copying a spell that left the stack
Moderator: CCGHQ Admins
Solution for copying a spell that left the stack
by thefiremind » 07 Aug 2013, 12:13
After a lot of tries, I finally found the solution to the problem that afflicted kevlahnota and sumomole: how to correctly copy a spell even if it leaves the stack (for example because it has been countered). The problem is that the copy of a spell that already left the stack loses its original targets, and the ChooseNewTargets function requires the spell to actually have targets in order to replace them with new ones.
So here's the idea: I checked the famous intricated code for Precursor Golem in DotP2013, and remembered that the CopySpell function has an optional second parameter that accepts a data chest. This allows us to save the targets of the original spell inside the trigger condition, and then pass them to the spell copy during resolution.
This is the fixed code for storm, you can easily adapt it to other cards.
So here's the idea: I checked the famous intricated code for Precursor Golem in DotP2013, and remembered that the CopySpell function has an optional second parameter that accepts a data chest. This allows us to save the targets of the original spell inside the trigger condition, and then pass them to the spell copy during resolution.
This is the fixed code for storm, you can easily adapt it to other cards.
- Code: Select all
<TRIGGERED_ABILITY active_zone="ZONE_STACK">
<LOCALISED_TEXT LanguageCode="en-US"><![CDATA[Storm]]></LOCALISED_TEXT>
<LOCALISED_TEXT LanguageCode="fr-FR"><![CDATA[Déluge]]></LOCALISED_TEXT>
<LOCALISED_TEXT LanguageCode="es-ES"><![CDATA[Tormenta]]></LOCALISED_TEXT>
<LOCALISED_TEXT LanguageCode="de-DE"><![CDATA[Sturm]]></LOCALISED_TEXT>
<LOCALISED_TEXT LanguageCode="it-IT"><![CDATA[Tempesta]]></LOCALISED_TEXT>
<LOCALISED_TEXT LanguageCode="jp-JA"><![CDATA[ストーム]]></LOCALISED_TEXT>
<LOCALISED_TEXT LanguageCode="ko-KR"><![CDATA[Storm]]></LOCALISED_TEXT>
<LOCALISED_TEXT LanguageCode="ru-RU"><![CDATA[Шторм]]></LOCALISED_TEXT>
<LOCALISED_TEXT LanguageCode="pt-BR"><![CDATA[Rajada]]></LOCALISED_TEXT>
<TRIGGER value="SPELL_PLAYED" simple_qualifier="self">
EffectDC():Make_Chest(0):CopyFrom( TriggerObject():GetDataChest() )
return true
</TRIGGER>
<RESOLUTION_TIME_ACTION>
local interrogation = MTG():ClearInterrogationQuery()
local storm_count = interrogation:Count(INTERROGATE_SPELLS_CAST, INTERROGATE_THIS_TURN) - 1
if storm_count > 0 then
for i=1,storm_count do
local copy = EffectController():CopySpell( TriggerObjectLKI(), EffectDC():Get_Chest(0) )
EffectController():ChooseNewTargets(copy)
end
end
</RESOLUTION_TIME_ACTION>
</TRIGGERED_ABILITY>
< Former DotP 2012/2013/2014 modder >
Currently busy with life...
Currently busy with life...
-
thefiremind - Programmer
- Posts: 3515
- Joined: 07 Nov 2011, 10:55
- Has thanked: 118 times
- Been thanked: 721 times
-
kevlahnota - Programmer
- Posts: 825
- Joined: 19 Jul 2010, 17:45
- Location: Philippines
- Has thanked: 14 times
- Been thanked: 264 times
2 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 11 guests