Board index Programs with AI or Rules Enforcement Magic: The Gathering - Duels of the Planeswalkers Programming Talk
Kinship ability - basic method
Moderator: CCGHQ Admins
Kinship ability - basic method
by kevlahnota » 22 Jul 2012, 06:48
well here is a sample of basic Kinship ability. Hope this is useful.
the code checks whether the instance of the card with kinship ability (the card itself) has any subtypes of the chosen card. Now I don't have any idea if this works with cards that has changeling ability. I just think that GetSubType returns a table of
subtypes with values 1 or 0. something like on or off.
this is what I think:
subtypes = {CREATURE_TYPE_HUMAN=0,CREATURE_TYPE_TREEFOLK=1,...}
something like that.
example code for Leaf-Crowned Elder:
the code checks whether the instance of the card with kinship ability (the card itself) has any subtypes of the chosen card. Now I don't have any idea if this works with cards that has changeling ability. I just think that GetSubType returns a table of
subtypes with values 1 or 0. something like on or off.
this is what I think:
subtypes = {CREATURE_TYPE_HUMAN=0,CREATURE_TYPE_TREEFOLK=1,...}
something like that.
example code for Leaf-Crowned Elder:
- Code: Select all
<?xml version='1.0'?>
<CARD_V2>
<FILENAME text="LEAFCROWNED_ELDER_888152682" />
<CARDNAME text="LEAFCROWNED_ELDER" />
<TITLE>
<LOCALISED_TEXT LanguageCode="en-US"><![CDATA[Leaf-Crowned Elder]]></LOCALISED_TEXT>
<LOCALISED_TEXT LanguageCode="de-DE"><![CDATA[Leaf-Crowned Elder]]></LOCALISED_TEXT>
<LOCALISED_TEXT LanguageCode="es-ES"><![CDATA[Leaf-Crowned Elder]]></LOCALISED_TEXT>
<LOCALISED_TEXT LanguageCode="fr-FR"><![CDATA[Leaf-Crowned Elder]]></LOCALISED_TEXT>
<LOCALISED_TEXT LanguageCode="it-IT"><![CDATA[Leaf-Crowned Elder]]></LOCALISED_TEXT>
<LOCALISED_TEXT LanguageCode="jp-JA"><![CDATA[Leaf-Crowned Elder]]></LOCALISED_TEXT>
<LOCALISED_TEXT LanguageCode="ko-KR"><![CDATA[Leaf-Crowned Elder]]></LOCALISED_TEXT>
<LOCALISED_TEXT LanguageCode="ru-RU"><![CDATA[Leaf-Crowned Elder]]></LOCALISED_TEXT>
<LOCALISED_TEXT LanguageCode="pt-BR"><![CDATA[Leaf-Crowned Elder]]></LOCALISED_TEXT>
</TITLE>
<MULTIVERSEID value="888152682" />
<ARTID value="888152682" />
<ARTIST name="Wayne Reynolds" />
<CASTING_COST cost="{2}{G}{G}" />
<TYPE metaname="Creature" />
<SUB_TYPE metaname="Treefolk" order_de-DE="0" order_es-ES="0" order_fr-FR="0" order_it-IT="0" order_jp-JA="0" order_ko-KR="0" order_pt-BR="0" order_ru-RU="0" />
<SUB_TYPE metaname="Shaman" order_de-DE="0" order_es-ES="0" order_fr-FR="0" order_it-IT="0" order_jp-JA="0" order_ko-KR="0" order_pt-BR="0" order_ru-RU="0" />
<EXPANSION value="DPG" />
<RARITY metaname="R" />
<POWER value="3" />
<TOUGHNESS value="5" />
<TRIGGERED_ABILITY>
<LOCALISED_TEXT LanguageCode="en-US"><![CDATA[|Kinship| — At the beginning of your upkeep, you may look at the top card of your library. If it shares a creature type with Leaf-Crowned Elder, you may reveal it. If you do, you may play that card without paying its mana cost.]]></LOCALISED_TEXT>
<LOCALISED_TEXT LanguageCode="de-DE"><![CDATA[|Kinship| — At the beginning of your upkeep, you may look at the top card of your library. If it shares a creature type with Leaf-Crowned Elder, you may reveal it. If you do, you may play that card without paying its mana cost.]]></LOCALISED_TEXT>
<LOCALISED_TEXT LanguageCode="es-ES"><![CDATA[|Kinship| — At the beginning of your upkeep, you may look at the top card of your library. If it shares a creature type with Leaf-Crowned Elder, you may reveal it. If you do, you may play that card without paying its mana cost.]]></LOCALISED_TEXT>
<LOCALISED_TEXT LanguageCode="fr-FR"><![CDATA[|Kinship| — At the beginning of your upkeep, you may look at the top card of your library. If it shares a creature type with Leaf-Crowned Elder, you may reveal it. If you do, you may play that card without paying its mana cost.]]></LOCALISED_TEXT>
<LOCALISED_TEXT LanguageCode="it-IT"><![CDATA[|Kinship| — At the beginning of your upkeep, you may look at the top card of your library. If it shares a creature type with Leaf-Crowned Elder, you may reveal it. If you do, you may play that card without paying its mana cost.]]></LOCALISED_TEXT>
<LOCALISED_TEXT LanguageCode="jp-JA"><![CDATA[|Kinship| — At the beginning of your upkeep, you may look at the top card of your library. If it shares a creature type with Leaf-Crowned Elder, you may reveal it. If you do, you may play that card without paying its mana cost.]]></LOCALISED_TEXT>
<LOCALISED_TEXT LanguageCode="ko-KR"><![CDATA[|Kinship| — At the beginning of your upkeep, you may look at the top card of your library. If it shares a creature type with Leaf-Crowned Elder, you may reveal it. If you do, you may play that card without paying its mana cost.]]></LOCALISED_TEXT>
<LOCALISED_TEXT LanguageCode="ru-RU"><![CDATA[|Kinship| — At the beginning of your upkeep, you may look at the top card of your library. If it shares a creature type with Leaf-Crowned Elder, you may reveal it. If you do, you may play that card without paying its mana cost.]]></LOCALISED_TEXT>
<LOCALISED_TEXT LanguageCode="pt-BR"><![CDATA[|Kinship| — At the beginning of your upkeep, you may look at the top card of your library. If it shares a creature type with Leaf-Crowned Elder, you may reveal it. If you do, you may play that card without paying its mana cost.]]></LOCALISED_TEXT>
<TRIGGER value="BEGINNING_OF_STEP" simple_qualifier="controller">
return ( (MTG():GetStep() == STEP_UPKEEP) and (TriggerPlayer() == EffectController()) and (TriggerPlayer():MyTurn() ~= 0) and (TriggerPlayer():Library_GetNth(0) ~= nil))
</TRIGGER>
<RESOLUTION_TIME_ACTION>
local filter = Object():GetFilter()
local player = EffectController()
filter:Clear()
filter:NotTargetted()
filter:SetPlayer( player )
filter:SetZone( ZONE_LIBRARY )
filter:SetPortion( 1 )
player:SetTargetCount( 1 )
player:SetTargetPrompt( 0, "CARD_QUERY_PLAY" )
player:ChooseTargetsWithFlags( NO_VALIDATION, EffectDC():Make_Targets(0), QUERY_FLAG_CAN_BE_FINISHED_EARLY + QUERY_FLAG_CAN_BE_FINISHED_EARLY_FOR_AI_AS_WELL )
</RESOLUTION_TIME_ACTION>
<RESOLUTION_TIME_ACTION>
local spell = EffectDC():Get_Targets(0):Get_CardPtr(0)
local player = EffectController()
if ( spell ~= nil ) then
local effectSource = Object()
local spellSubtypes = spell:GetSubType()
local filter = Object():GetFilter()
filter:Clear()
filter:SetZone( ZONE_IN_PLAY )
filter:SetSubTypes( spellSubtypes )
filter:SetController( player )
filter:SetCardInstance( effectSource )
filter:AddExtra( FILTER_EXTRA_ANY_SUB_TYPE )
filter:NotTargetted()
local mycount = filter:Count()
if mycount > 0 then
if spell:CanBePlayed( player ) then
spell:PlayFreeFromAnywhere( player )
end
end
end
</RESOLUTION_TIME_ACTION>
</TRIGGERED_ABILITY>
<SFX text="COMBAT_BLUNT_LARGE_ATTACK" power_boundary_min="4" power_boundary_max="-1" />
<SFX text="COMBAT_BLUNT_SMALL_ATTACK" power_boundary_min="1" power_boundary_max="3" />
<AI_BASE_SCORE score="600" zone="ZONE_IN_PLAY" />
</CARD_V2>
-
kevlahnota - Programmer
- Posts: 825
- Joined: 19 Jul 2010, 17:45
- Location: Philippines
- Has thanked: 14 times
- Been thanked: 264 times
Re: Kinship ability - basic method
by kevlahnota » 22 Jul 2012, 07:21
just additional info, you can test lua code online here: http://www.lua.org/cgi-bin/demo
if you put this code below and run, its a sample of what I think inside the tables from GetSubType().
if you put this code below and run, its a sample of what I think inside the tables from GetSubType().
- Code: Select all
local function findme(table, element)
for _, value in pairs(table) do
if value == element then
return true
end
end
return false
end
a1 = {CREATURE_TYPE_HUMAN=1,CREATURE_TYPE_ANGEL=1,CREATURE_TYPE_MERFOLK=1}
b1 = {CREATURE_TYPE_MERFOLK=0,CREATURE_TYPE_HUMAN=1}
local element = nil
local found = 0
for element in pairs (b1) do
if findme(a1, b1[element]) ~= false then
found=found+1
end
end
print(found)
- Code: Select all
<RESOLUTION_TIME_ACTION>
local spell = EffectDC():Get_Targets(0):Get_CardPtr(0)
local player = EffectController()
if ( spell ~= nil ) then
local effectSourceSubtypes = Object():GetSubType()
local spellSubtypes = spell:GetSubType()
local found = 0
local obj_element = nil
local function findme(table, element)
for _, value in pairs(table) do
if value == element then
return true
end
end
return false
end
for obj_element in pairs (spellSubtypes) do
if findme(effectSourceSubtypes, spellSubtypes[obj_element]) ~= false then
found=found+1
end
end
if found > 0 then
if spell:CanBePlayed( player ) then
spell:PlayFreeFromAnywhere( player )
end
end
end
</RESOLUTION_TIME_ACTION>
-
kevlahnota - Programmer
- Posts: 825
- Joined: 19 Jul 2010, 17:45
- Location: Philippines
- Has thanked: 14 times
- Been thanked: 264 times
Re: Kinship ability - basic method
by thefiremind » 22 Jul 2012, 08:47
Does this mean that Leaf-Crowned Elder still has some flaw? I can't understand if you managed to fix it 100% or not. If you need something that surely works, you could try to make a function like this:kevlahnota wrote:I tried putting it and the game runs without error (of course slightly modified code) but you can only play it if they have the same subtypes .
- Code: Select all
ShareAnySubType = function(object1, object2)
-- returns true if object1 and object2 share at least one sub-type
-- (only for creature sub-types, it could be extended if needed)
if object1 == nil or object2 == nil then
return false
end
local min = CREATURE_TYPE_HUMAN
local max = CREATURE_TYPE_GERM -- this could change in the future (hopefully not)
for i=min,max do
if object1:GetSubType():Test(i) ~= 0 and object2:GetSubType():Test(i) ~= 0 then
return true
end
end
return false
end
< 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
Re: Kinship ability - basic method
by RiiakShiNal » 22 Jul 2012, 13:03
This should also work as it asks the filter if the top card of the library has any sub-type in common with the Object:
- Code: Select all
RSN_Kinship = function()
if (EffectController():Library_Count() > 0) then
local oFilter = Object():GetFilter()
oFilter:Clear()
oFilter:SetZone( ZONE_LIBRARY )
oFilter:SetPlayer( EffectController() )
oFilter:SetSubTypes( Object():GetSubType() )
oFilter:AddExtra( FILTER_EXTRA_ANY_SUB_TYPE )
oFilter:SetPortion( 1 )
return (oFilter:CountStopAt( 1 ) == 1)
else
return false
end
end
Just getting started: Xander9009's DotP 2014 Community Wad
Need a deck builder: DotP 2014 Deck Builder
Problems Modding: DotP 2014 Frequent Modding Mistakes
Need a deck builder: DotP 2014 Deck Builder
Problems Modding: DotP 2014 Frequent Modding Mistakes
- RiiakShiNal
- Programmer
- Posts: 2185
- Joined: 16 May 2011, 21:37
- Has thanked: 75 times
- Been thanked: 497 times
Re: Kinship ability - basic method
by thefiremind » 22 Jul 2012, 13:26
I'm always in doubt about what FILTER_EXTRA_ANY_SUB_TYPE really means, but thinking about Alpha Status from DotP2012, I think it should be correct.RiiakShiNal wrote:This should also work as it asks the filter if the top card of the library has any sub-type in common with the Object
< 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
Re: Kinship ability - basic method
by RiiakShiNal » 22 Jul 2012, 14:54
FILTER_EXTRA_ANY_SUB_TYPE seems to work perfectly well for counting cards that share at least one sub type with those that have been added to the filter (either through SetSubTypes or AddSubType) and I use it for a couple of cards like Coat of Arms and Quest for Ula's Temple.thefiremind wrote:I'm always in doubt about what FILTER_EXTRA_ANY_SUB_TYPE really means, but thinking about Alpha Status from DotP2012, I think it should be correct.
Just getting started: Xander9009's DotP 2014 Community Wad
Need a deck builder: DotP 2014 Deck Builder
Problems Modding: DotP 2014 Frequent Modding Mistakes
Need a deck builder: DotP 2014 Deck Builder
Problems Modding: DotP 2014 Frequent Modding Mistakes
- RiiakShiNal
- Programmer
- Posts: 2185
- Joined: 16 May 2011, 21:37
- Has thanked: 75 times
- Been thanked: 497 times
Re: Kinship ability - basic method
by kevlahnota » 22 Jul 2012, 23:52
thanks for the tips guys , the flaw of my code is what if the effectsource leaves play, then I have a problem, but if inverting the check that way I think it will be good.
-
kevlahnota - Programmer
- Posts: 825
- Joined: 19 Jul 2010, 17:45
- Location: Philippines
- Has thanked: 14 times
- Been thanked: 264 times
Re: Kinship ability - basic method
by nabeshin » 25 Jul 2012, 21:28
it is pleasant to read your works, prompt who knows as to copy tokens without entering them into game, crushes constantly take off. Can the last patch is necessary? wanted to put the morphing in a new part, it did not turn out... but suspend is easily done.
Re: Kinship ability - basic method
by thefiremind » 25 Jul 2012, 21:37
From what we tested, it seems impossible. The best workaround so far is to make the token without types, so that it doesn't trigger anything and it stays invisible: you can put it in play for a brief moment, just to copy it, then you remove it from the game. If you need to give it types, you can give them from a CONTINUOUS_ACTION.nabeshin wrote:prompt who knows as to copy tokens without entering them into game
If you ever find a better method, please keep all of us informed.
Oh and about suspend, I made something:
viewtopic.php?f=63&t=7623
the problem is that the AI won't suspend anything if I don't force it with a trigger.
< 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
Re: Kinship ability - basic method
by nabeshin » 25 Jul 2012, 22:41
thx for hints, it means the only option at the moment special card.thefiremind wrote:From what we tested, it seems impossible. The best workaround so far is to make the token without types, so that it doesn't trigger anything and it stays invisible: you can put it in play for a brief moment, just to copy it, then you remove it from the game. If you need to give it types, you can give them from a CONTINUOUS_ACTION.nabeshin wrote:prompt who knows as to copy tokens without entering them into game
If you ever find a better method, please keep all of us informed.
Oh and about suspend, I made something:
viewtopic.php?f=63&t=7623
the problem is that the AI won't suspend anything if I don't force it with a trigger.
Re: Kinship ability - basic method
by nabeshin » 27 Jul 2012, 14:16
sorry bro, GetSubType return table with pointer to userdata variable (c-class obj, its contains methods and data for subtype obj, )kevlahnota wrote:well here is a sample of basic Kinship ability. Hope this is useful.
the code checks whether the instance of the card with kinship ability (the card itself) has any subtypes of the chosen card. Now I don't have any idea if this works with cards that has changeling ability. I just think that GetSubType returns a table of
subtypes with values 1 or 0. something like on or off.
this is what I think:
subtypes = {CREATURE_TYPE_HUMAN=0,CREATURE_TYPE_TREEFOLK=1,...}
something like that.
example code for Leaf-Crowned Elder:
- Code: Select all
<?xml version='1.0'?>
<CARD_V2>
<FILENAME text="LEAFCROWNED_ELDER_888152682" />
<CARDNAME text="LEAFCROWNED_ELDER" />
<TITLE>
<LOCALISED_TEXT LanguageCode="en-US"><![CDATA[Leaf-Crowned Elder]]></LOCALISED_TEXT>
<LOCALISED_TEXT LanguageCode="de-DE"><![CDATA[Leaf-Crowned Elder]]></LOCALISED_TEXT>
<LOCALISED_TEXT LanguageCode="es-ES"><![CDATA[Leaf-Crowned Elder]]></LOCALISED_TEXT>
<LOCALISED_TEXT LanguageCode="fr-FR"><![CDATA[Leaf-Crowned Elder]]></LOCALISED_TEXT>
<LOCALISED_TEXT LanguageCode="it-IT"><![CDATA[Leaf-Crowned Elder]]></LOCALISED_TEXT>
<LOCALISED_TEXT LanguageCode="jp-JA"><![CDATA[Leaf-Crowned Elder]]></LOCALISED_TEXT>
<LOCALISED_TEXT LanguageCode="ko-KR"><![CDATA[Leaf-Crowned Elder]]></LOCALISED_TEXT>
<LOCALISED_TEXT LanguageCode="ru-RU"><![CDATA[Leaf-Crowned Elder]]></LOCALISED_TEXT>
<LOCALISED_TEXT LanguageCode="pt-BR"><![CDATA[Leaf-Crowned Elder]]></LOCALISED_TEXT>
</TITLE>
<MULTIVERSEID value="888152682" />
<ARTID value="888152682" />
<ARTIST name="Wayne Reynolds" />
<CASTING_COST cost="{2}{G}{G}" />
<TYPE metaname="Creature" />
<SUB_TYPE metaname="Treefolk" order_de-DE="0" order_es-ES="0" order_fr-FR="0" order_it-IT="0" order_jp-JA="0" order_ko-KR="0" order_pt-BR="0" order_ru-RU="0" />
<SUB_TYPE metaname="Shaman" order_de-DE="0" order_es-ES="0" order_fr-FR="0" order_it-IT="0" order_jp-JA="0" order_ko-KR="0" order_pt-BR="0" order_ru-RU="0" />
<EXPANSION value="DPG" />
<RARITY metaname="R" />
<POWER value="3" />
<TOUGHNESS value="5" />
<TRIGGERED_ABILITY>
<LOCALISED_TEXT LanguageCode="en-US"><![CDATA[|Kinship| — At the beginning of your upkeep, you may look at the top card of your library. If it shares a creature type with Leaf-Crowned Elder, you may reveal it. If you do, you may play that card without paying its mana cost.]]></LOCALISED_TEXT>
<LOCALISED_TEXT LanguageCode="de-DE"><![CDATA[|Kinship| — At the beginning of your upkeep, you may look at the top card of your library. If it shares a creature type with Leaf-Crowned Elder, you may reveal it. If you do, you may play that card without paying its mana cost.]]></LOCALISED_TEXT>
<LOCALISED_TEXT LanguageCode="es-ES"><![CDATA[|Kinship| — At the beginning of your upkeep, you may look at the top card of your library. If it shares a creature type with Leaf-Crowned Elder, you may reveal it. If you do, you may play that card without paying its mana cost.]]></LOCALISED_TEXT>
<LOCALISED_TEXT LanguageCode="fr-FR"><![CDATA[|Kinship| — At the beginning of your upkeep, you may look at the top card of your library. If it shares a creature type with Leaf-Crowned Elder, you may reveal it. If you do, you may play that card without paying its mana cost.]]></LOCALISED_TEXT>
<LOCALISED_TEXT LanguageCode="it-IT"><![CDATA[|Kinship| — At the beginning of your upkeep, you may look at the top card of your library. If it shares a creature type with Leaf-Crowned Elder, you may reveal it. If you do, you may play that card without paying its mana cost.]]></LOCALISED_TEXT>
<LOCALISED_TEXT LanguageCode="jp-JA"><![CDATA[|Kinship| — At the beginning of your upkeep, you may look at the top card of your library. If it shares a creature type with Leaf-Crowned Elder, you may reveal it. If you do, you may play that card without paying its mana cost.]]></LOCALISED_TEXT>
<LOCALISED_TEXT LanguageCode="ko-KR"><![CDATA[|Kinship| — At the beginning of your upkeep, you may look at the top card of your library. If it shares a creature type with Leaf-Crowned Elder, you may reveal it. If you do, you may play that card without paying its mana cost.]]></LOCALISED_TEXT>
<LOCALISED_TEXT LanguageCode="ru-RU"><![CDATA[|Kinship| — At the beginning of your upkeep, you may look at the top card of your library. If it shares a creature type with Leaf-Crowned Elder, you may reveal it. If you do, you may play that card without paying its mana cost.]]></LOCALISED_TEXT>
<LOCALISED_TEXT LanguageCode="pt-BR"><![CDATA[|Kinship| — At the beginning of your upkeep, you may look at the top card of your library. If it shares a creature type with Leaf-Crowned Elder, you may reveal it. If you do, you may play that card without paying its mana cost.]]></LOCALISED_TEXT>
<TRIGGER value="BEGINNING_OF_STEP" simple_qualifier="controller">
return ( (MTG():GetStep() == STEP_UPKEEP) and (TriggerPlayer() == EffectController()) and (TriggerPlayer():MyTurn() ~= 0) and (TriggerPlayer():Library_GetNth(0) ~= nil))
</TRIGGER>
<RESOLUTION_TIME_ACTION>
local filter = Object():GetFilter()
local player = EffectController()
filter:Clear()
filter:NotTargetted()
filter:SetPlayer( player )
filter:SetZone( ZONE_LIBRARY )
filter:SetPortion( 1 )
player:SetTargetCount( 1 )
player:SetTargetPrompt( 0, "CARD_QUERY_PLAY" )
player:ChooseTargetsWithFlags( NO_VALIDATION, EffectDC():Make_Targets(0), QUERY_FLAG_CAN_BE_FINISHED_EARLY + QUERY_FLAG_CAN_BE_FINISHED_EARLY_FOR_AI_AS_WELL )
</RESOLUTION_TIME_ACTION>
<RESOLUTION_TIME_ACTION>
local spell = EffectDC():Get_Targets(0):Get_CardPtr(0)
local player = EffectController()
if ( spell ~= nil ) then
local effectSource = Object()
local spellSubtypes = spell:GetSubType()
local filter = Object():GetFilter()
filter:Clear()
filter:SetZone( ZONE_IN_PLAY )
filter:SetSubTypes( spellSubtypes )
filter:SetController( player )
filter:SetCardInstance( effectSource )
filter:AddExtra( FILTER_EXTRA_ANY_SUB_TYPE )
filter:NotTargetted()
local mycount = filter:Count()
if mycount > 0 then
if spell:CanBePlayed( player ) then
spell:PlayFreeFromAnywhere( player )
end
end
end
</RESOLUTION_TIME_ACTION>
</TRIGGERED_ABILITY>
<SFX text="COMBAT_BLUNT_LARGE_ATTACK" power_boundary_min="4" power_boundary_max="-1" />
<SFX text="COMBAT_BLUNT_SMALL_ATTACK" power_boundary_min="1" power_boundary_max="3" />
<AI_BASE_SCORE score="600" zone="ZONE_IN_PLAY" />
</CARD_V2>
11 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 26 guests