Restrictions for Card.isValidCard
Post MTG Forge Related Programming Questions Here
Moderators: timmermac, Agetian, friarsol, Blacksmith, KrazyTheFox, CCGHQ Admins
18 posts
• Page 1 of 2 • 1, 2
Restrictions for Card.isValidCard
by Rob Cashwalker » 28 Aug 2010, 20:40
Card.isValidCard takes a string array as a parameter. Each element follows the form:
CardType{.restriction}{+furtherRestriction}
The restrictions are optional.
CardType may be any type, generally the supertypes like Creature, Artifact, Enchantment, Land, etc. However, it could also be Elf or Goblin... though that would also include Elf Enchantments, for example. To specify an Elf Creature, then it should be "Creature.Elf". "Permanent" represents any permanent....
Restrictions other than type that are interpreted: (case sensitive)
Examples:
"Artifact or Enchantment" would be represented as a 2 element string array one element is "Artifact" the other "Enchantment"
"non-black, non-artifact creature" would be represented as a 1 element array - "Creature.nonBlack+nonArtifact"
"creature with power 2 or less" would be "Creature.powerLE2"
"nonbasic land" is "Land.nonBasic"
"creature with flying" is "Creature.withFlying"
CardType{.restriction}{+furtherRestriction}
The restrictions are optional.
CardType may be any type, generally the supertypes like Creature, Artifact, Enchantment, Land, etc. However, it could also be Elf or Goblin... though that would also include Elf Enchantments, for example. To specify an Elf Creature, then it should be "Creature.Elf". "Permanent" represents any permanent....
Restrictions other than type that are interpreted: (case sensitive)
- Color, nonColor (White, nonWhite, etc)
- Colorless, nonColorless
- Multicolor, nonMulticolor
- with{Keyword}, without{Keyword}
- tapped, untapped
- enchanted, unenchanted, enchanting
- token, nonToken
- power{cmp}{X or #}
- toughness{cmp}{X or #}
- cmc{cmp}{X or #} {cmp} is a comparator:
- LT - Less Than
- LE - Less than or Equal
- EQ - EQual
- GE - Greater than or Equal
- GT - Greater Than
Examples:
"Artifact or Enchantment" would be represented as a 2 element string array one element is "Artifact" the other "Enchantment"
"non-black, non-artifact creature" would be represented as a 1 element array - "Creature.nonBlack+nonArtifact"
"creature with power 2 or less" would be "Creature.powerLE2"
"nonbasic land" is "Land.nonBasic"
"creature with flying" is "Creature.withFlying"
Last edited by Rob Cashwalker on 04 Sep 2010, 23:26, edited 1 time in total.
Reason: Fixed syntax
Reason: Fixed syntax
The Force will be with you, Always.
-

Rob Cashwalker - Programmer
- Posts: 2167
- Joined: 09 Sep 2008, 15:09
- Location: New York
- Has thanked: 5 times
- Been thanked: 40 times
Re: Restrictions for Card.isValidCard
by Rob Cashwalker » 04 Sep 2010, 23:25
I was recently reminded of the correct syntax - "+" between restrictions. For example:
non-black, non-artifact creature" would be represented as a 1 element array - "Creature.nonBlack+nonArtifact"
The Force will be with you, Always.
-

Rob Cashwalker - Programmer
- Posts: 2167
- Joined: 09 Sep 2008, 15:09
- Location: New York
- Has thanked: 5 times
- Been thanked: 40 times
Re: Restrictions for Card.isValidCard
by Sloth » 05 Nov 2010, 21:27
I just added counters{cmp}{X or #}{countername}
(it only takes single digits for # though).
Not to forget: YouCtrl, YouDontCtrl, Self, Other, Attached. But these are only avaiable if getValidCard is updated to send a Player and a Card variable. Note that these restrictions have to be at the end! Normal restrictions after that will be ignored.
(it only takes single digits for # though).
- Code: Select all
Example: Creature.countersGE4LEVEL+Self
Not to forget: YouCtrl, YouDontCtrl, Self, Other, Attached. But these are only avaiable if getValidCard is updated to send a Player and a Card variable. Note that these restrictions have to be at the end! Normal restrictions after that will be ignored.
-

Sloth - Programmer
- Posts: 3498
- Joined: 23 Jun 2009, 19:40
- Has thanked: 125 times
- Been thanked: 507 times
Re: Restrictions for Card.isValidCard
by friarsol » 05 Nov 2010, 21:46
I copy/pasted this block into the Wiki but it can deal with some major formatting help.
http://www.slightlymagic.net/wiki/Forge_ValidCards
http://www.slightlymagic.net/wiki/Forge_ValidCards
- friarsol
- Global Moderator
- Posts: 7593
- Joined: 15 May 2010, 04:20
- Has thanked: 243 times
- Been thanked: 965 times
Re: Restrictions for Card.isValidCard
by slapshot5 » 16 Nov 2010, 16:51
Is there a way to do the following with Valid?
I want to target a creature with power LE source creature's power.
I tried:
The specific card in question to determine targeting is Old Man of the Sea. I am only concerned with the initial targeting, not the "as long as..."
Thanks,
slapshot5
I want to target a creature with power LE source creature's power.
I tried:
- Code: Select all
A:AB$...|ValidTgts$Creature.powerLEX|...
SVar:X:Count$CardPower
The specific card in question to determine targeting is Old Man of the Sea. I am only concerned with the initial targeting, not the "as long as..."
Thanks,
slapshot5
- slapshot5
- Programmer
- Posts: 1391
- Joined: 03 Jan 2010, 17:47
- Location: Mac OS X
- Has thanked: 25 times
- Been thanked: 68 times
Re: Restrictions for Card.isValidCard
by Sloth » 16 Nov 2010, 17:53
Actually hasProperty searches for the SVar X on the card to check, which is really senseless. We would have to change hasProperty to take a source card as variable. I would be willing to change this, but it would mean a lot of cleanup and possible bugs (since all getValidCard calls must deliver a Card variable).slapshot5 wrote:Is there a way to do the following with Valid?
I want to target a creature with power LE source creature's power.
I tried:But the X doesn't get interpreted until each individual card checks it, so I end up checking a card's power against 0 (since that card doesn't have the SVar, only the source card does...)
- Code: Select all
A:AB$...|ValidTgts$Creature.powerLEX|...
SVar:X:Count$CardPower
EDIT: Since this is long overdue and much cleaner, I'm gonna do this.
-

Sloth - Programmer
- Posts: 3498
- Joined: 23 Jun 2009, 19:40
- Has thanked: 125 times
- Been thanked: 507 times
Re: Restrictions for Card.isValidCard
by slapshot5 » 16 Nov 2010, 21:40
Yeah, that's kind of what I thought. I started to pass a source Card through, but quickly found out it was much bigger than I'd hoped. Thought I'd better post for someone who is more familiar with this code than I.Sloth wrote:Actually hasProperty searches for the SVar X on the card to check, which is really senseless. We would have to change hasProperty to take a source card as variable. I would be willing to change this, but it would mean a lot of cleanup and possible bugs (since all getValidCard calls must deliver a Card variable).
Excellent. Thanks. I'm happy to help squash any bugs that come up.Sloth wrote:EDIT: Since this is long overdue and much cleaner, I'm gonna do this.
-slapshot5
- slapshot5
- Programmer
- Posts: 1391
- Joined: 03 Jan 2010, 17:47
- Location: Mac OS X
- Has thanked: 25 times
- Been thanked: 68 times
Re: Restrictions for Card.isValidCard
by slapshot5 » 16 Nov 2010, 22:40
Ok, maybe that was too easy. Can Valid handle this targeting:
target creature whose controller controls an Island
?
-slapshot5
target creature whose controller controls an Island
?
-slapshot5
- slapshot5
- Programmer
- Posts: 1391
- Joined: 03 Jan 2010, 17:47
- Location: Mac OS X
- Has thanked: 25 times
- Been thanked: 68 times
Re: Restrictions for Card.isValidCard
by Sloth » 17 Nov 2010, 07:24
Not really. I think I broke the restriction Other, but I can't find the mistake.slapshot5 wrote:Ok, maybe that was too easy.
It's possible, but anything more advanced like "target creature whose controller controls a blue permanent" would be a pain to find a syntax for.slapshot5 wrote:Can Valid handle this targeting:
target creature whose controller controls an Island
?
-slapshot5
Once I fixed the bug with Other, I will try to add a restriction like this:
ControllerControls[Type]
Is it to keyword Seasinger?
-

Sloth - Programmer
- Posts: 3498
- Joined: 23 Jun 2009, 19:40
- Has thanked: 125 times
- Been thanked: 507 times
Re: Restrictions for Card.isValidCard
by slapshot5 » 17 Nov 2010, 07:33
yep.Sloth wrote:Is it to keyword Seasinger?
- slapshot5
- Programmer
- Posts: 1391
- Joined: 03 Jan 2010, 17:47
- Location: Mac OS X
- Has thanked: 25 times
- Been thanked: 68 times
Re: Restrictions for Card.isValidCard
by Sloth » 17 Nov 2010, 07:40
The issue is fixed. I will give it a try now.
EDIT: ControllerControls[Type] is now usable, as well as YouOwn and YouDontOwn.
EDIT: ControllerControls[Type] is now usable, as well as YouOwn and YouDontOwn.
-

Sloth - Programmer
- Posts: 3498
- Joined: 23 Jun 2009, 19:40
- Has thanked: 125 times
- Been thanked: 507 times
Re: Restrictions for Card.isValidCard
by slapshot5 » 18 Nov 2010, 19:49
How do I use the ControllerControls?
I did this for Seasinger:
-slapshot5
I did this for Seasinger:
- Code: Select all
|ValidTgts$Creature.ControllerControlsIsland|
-slapshot5
- slapshot5
- Programmer
- Posts: 1391
- Joined: 03 Jan 2010, 17:47
- Location: Mac OS X
- Has thanked: 25 times
- Been thanked: 68 times
Re: Restrictions for Card.isValidCard
by friarsol » 18 Nov 2010, 20:11
Sloth, is ControllerControls supposed to care about the card we're checking or the source?
Cause it looks like right now it's checking the Source. I'm not sure but maybe it could be something like:
Cause it looks like right now it's checking the Source. I'm not sure but maybe it could be something like:
- Code: Select all
else if (Property.startsWith("ControllerControls")) {
String type = Property.substring(18);
CardList list = AllZoneUtil.getPlayerCardsInPlay(getController());
if (list.getType(type).isEmpty()) return false;
}
- friarsol
- Global Moderator
- Posts: 7593
- Joined: 15 May 2010, 04:20
- Has thanked: 243 times
- Been thanked: 965 times
Re: Restrictions for Card.isValidCard
by slapshot5 » 18 Nov 2010, 20:27
It's supposed to care about the card we're checking. I tested Sol's change locally and it works. Seasinger is the only card that uses this, so I'll go ahead and commit this.
Thanks Sol.
-slapshot5
Thanks Sol.
-slapshot5
- slapshot5
- Programmer
- Posts: 1391
- Joined: 03 Jan 2010, 17:47
- Location: Mac OS X
- Has thanked: 25 times
- Been thanked: 68 times
Re: Restrictions for Card.isValidCard
by Sloth » 18 Nov 2010, 20:48
Uh, ... Yes. This is what I intended. It seems I wasn't really into it. Sorry slapshot5.
-

Sloth - Programmer
- Posts: 3498
- Joined: 23 Jun 2009, 19:40
- Has thanked: 125 times
- Been thanked: 507 times
18 posts
• Page 1 of 2 • 1, 2
Who is online
Users browsing this forum: No registered users and 10 guests