It is currently 29 Oct 2025, 09:28
   
Text Size

Restrictions for Card.isValidCard

Post MTG Forge Related Programming Questions Here

Moderators: timmermac, Agetian, friarsol, Blacksmith, KrazyTheFox, CCGHQ Admins

Restrictions for Card.isValidCard

Postby 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)

  • 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
    X is parsed from "SVar:X:Count$___"

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
The Force will be with you, Always.
User avatar
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

Postby 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.
User avatar
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

Postby Sloth » 05 Nov 2010, 21:27

I just added counters{cmp}{X or #}{countername}
(it only takes single digits for # though).
Code: Select all
Example: Creature.countersGE4LEVEL+Self
Although not on the list are: MonoColor, nonMonoColor, equipped, unequipped, equipping, attacking, notattacking and blocking.

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.
User avatar
Sloth
Programmer
 
Posts: 3498
Joined: 23 Jun 2009, 19:40
Has thanked: 125 times
Been thanked: 507 times

Re: Restrictions for Card.isValidCard

Postby 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
friarsol
Global Moderator
 
Posts: 7593
Joined: 15 May 2010, 04:20
Has thanked: 243 times
Been thanked: 965 times

Re: Restrictions for Card.isValidCard

Postby 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:
Code: Select all
A:AB$...|ValidTgts$Creature.powerLEX|...
SVar:X:Count$CardPower
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...)

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

Postby Sloth » 16 Nov 2010, 17:53

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:
Code: Select all
A:AB$...|ValidTgts$Creature.powerLEX|...
SVar:X:Count$CardPower
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...)
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).

EDIT: Since this is long overdue and much cleaner, I'm gonna do this.
User avatar
Sloth
Programmer
 
Posts: 3498
Joined: 23 Jun 2009, 19:40
Has thanked: 125 times
Been thanked: 507 times

Re: Restrictions for Card.isValidCard

Postby slapshot5 » 16 Nov 2010, 21:40

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).
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:EDIT: Since this is long overdue and much cleaner, I'm gonna do this.
Excellent. Thanks. I'm happy to help squash any bugs that come up.

-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

Postby 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
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

Postby Sloth » 17 Nov 2010, 07:24

slapshot5 wrote:Ok, maybe that was too easy.
Not really. I think I broke the restriction Other, but I can't find the mistake.


slapshot5 wrote:Can Valid handle this targeting:

target creature whose controller controls an Island

?

-slapshot5
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.

Once I fixed the bug with Other, I will try to add a restriction like this:
ControllerControls[Type]

Is it to keyword Seasinger?
User avatar
Sloth
Programmer
 
Posts: 3498
Joined: 23 Jun 2009, 19:40
Has thanked: 125 times
Been thanked: 507 times

Re: Restrictions for Card.isValidCard

Postby slapshot5 » 17 Nov 2010, 07:33

Sloth wrote:Is it to keyword Seasinger?
yep.
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

Postby 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.
User avatar
Sloth
Programmer
 
Posts: 3498
Joined: 23 Jun 2009, 19:40
Has thanked: 125 times
Been thanked: 507 times

Re: Restrictions for Card.isValidCard

Postby slapshot5 » 18 Nov 2010, 19:49

How do I use the ControllerControls?

I did this for Seasinger:

Code: Select all
|ValidTgts$Creature.ControllerControlsIsland|
and it didn't restrict properly. Do I use the []?

-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

Postby 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:
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

Postby 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
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

Postby Sloth » 18 Nov 2010, 20:48

Uh, ... Yes. This is what I intended. It seems I wasn't really into it. Sorry slapshot5.
User avatar
Sloth
Programmer
 
Posts: 3498
Joined: 23 Jun 2009, 19:40
Has thanked: 125 times
Been thanked: 507 times

Next

Return to Developer's Corner

Who is online

Users browsing this forum: No registered users and 10 guests

Main Menu

User Menu

Our Partners


Who is online

In total there are 10 users online :: 0 registered, 0 hidden and 10 guests (based on users active over the past 10 minutes)
Most users ever online was 9298 on 10 Oct 2025, 12:54

Users browsing this forum: No registered users and 10 guests

Login Form