spDestroyTgt keyword
Post MTG Forge Related Programming Questions Here
Moderators: timmermac, Blacksmith, KrazyTheFox, Agetian, friarsol, CCGHQ Admins
54 posts
• Page 3 of 4 • 1, 2, 3, 4
Re: spDestroyTgt keyword
by DennisBergkamp » 24 Jul 2009, 23:09
Ok, I've merged the code... but I don't think I'm using it right. I tested it with:
Deathmark
B
Sorcery
Destroy target green or white creature.
spDestroyTgt:Creature,Green,White
But I'm able to destroy blue creatures.
Deathmark
B
Sorcery
Destroy target green or white creature.
spDestroyTgt:Creature,Green,White
But I'm able to destroy blue creatures.
-
DennisBergkamp - AI Programmer
- Posts: 2602
- Joined: 09 Sep 2008, 15:46
- Has thanked: 0 time
- Been thanked: 0 time
Re: spDestroyTgt keyword
by Chris H. » 25 Jul 2009, 00:54
Try it like this, I'm not sure if it will work ?DennisBergkamp wrote:Ok, I've merged the code... but I don't think I'm using it right. I tested it with:
Deathmark
B
Sorcery
Destroy target green or white creature.
spDestroyTgt:Creature,Green,White
But I'm able to destroy blue creatures.
Deathmark
B
Sorcery
Destroy target green or white creature.
spDestroyTgt:Creature.Green,Creature.White
Rob had some info as part of message:
http://www.slightlymagic.net/forum/viewtopic.php?f=52&t=1338&start=15#p16860
-
Chris H. - Forge Moderator
- Posts: 6320
- Joined: 04 Nov 2008, 12:11
- Location: Mac OS X Yosemite
- Has thanked: 644 times
- Been thanked: 643 times
Re: spDestroyTgt keyword
by Rob Cashwalker » 25 Jul 2009, 02:01
Yes, I think this would be the syntaxChris H. wrote:Try it like this, I'm not sure if it will work ?
Deathmark
B
Sorcery
Destroy target green or white creature.
spDestroyTgt:Creature.Green,Creature.White
Rob had some info as part of message:
http://www.slightlymagic.net/forum/viewtopic.php?f=52&t=1338&start=15#p16860
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: spDestroyTgt keyword
by Chris H. » 25 Jul 2009, 10:27
With your recent modifications to the syntax, did you find it necessary to change the "It can't be regenerated" syntax. Will the following for Terror work:Rob Cashwalker wrote:Yes, I think this would be the syntax
Terror
1 B
Sorcery
Destroy target nonblack, nonartifact creature. It can't be regenerated.
spDestroyTgt:Creature.nonBlack+nonArtifact:NoRegen
-
Chris H. - Forge Moderator
- Posts: 6320
- Joined: 04 Nov 2008, 12:11
- Location: Mac OS X Yosemite
- Has thanked: 644 times
- Been thanked: 643 times
Re: spDestroyTgt keyword
by DennisBergkamp » 25 Jul 2009, 11:02
Cool, yes this seems to work, thanks guys 
(I wasn't able to destroy an artifact creature, but I could kill the green and white critters).

(I wasn't able to destroy an artifact creature, but I could kill the green and white critters).
-
DennisBergkamp - AI Programmer
- Posts: 2602
- Joined: 09 Sep 2008, 15:46
- Has thanked: 0 time
- Been thanked: 0 time
Re: spDestroyTgt keyword
by Rob Cashwalker » 25 Jul 2009, 15:03
The way the code was written, it really didn't care if it was "NoRegen" or "lkdsjfldsfjlsdjf". It triggered as long as there was a third parameter. I'm leaving it open for other options.
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: spDestroyTgt keyword
by mtgrares » 28 Jul 2009, 17:09
I'm a little late to the conversation but since there are so many restriction on "what is a valid target" you could just use one line of Java source code that would be "injected" into a CardListFilter.
Terror
1 B
Instant
Target non-black, non-artifact creature.
DestroyTarget: !CardUtil.getColors(card).equals(Constant.Color.Block) && !card.isArtifact()
In CardFactory, code that reads the DestroyTarget lines

Terror
1 B
Instant
Target non-black, non-artifact creature.
DestroyTarget: !CardUtil.getColors(card).equals(Constant.Color.Block) && !card.isArtifact()
In CardFactory, code that reads the DestroyTarget lines
- Code: Select all
CardList all = get all permanents that are on the board for both players
CardList validTarget = all.filter(
new CardListFilter()
{
public boolean addCard(Card card)
{
//insert line from Cards.txt DestroyTarget
}
}
);

- mtgrares
- DEVELOPER
- Posts: 1352
- Joined: 08 Sep 2008, 22:10
- Has thanked: 3 times
- Been thanked: 12 times
Re: spDestroyTgt keyword
by Rob Cashwalker » 29 Jul 2009, 11:45
Java on the fly you say? Why didn't you tell us we could do that?
That may have its uses elsewhere. But in this case, the syntax I came up with is cleaner and easier for a non-coder to work with, IMHO. Plus it's generic enough for other cards that need to limit any given CardList, which is why I decided it deserved to be in the CardList object itself. It's just as useful for limiting a library search as it is for limiting targets on the battlefield. Many of the existing CardListFilters could be reduced to this method, resulting in a cleaner CardFactory.
That may have its uses elsewhere. But in this case, the syntax I came up with is cleaner and easier for a non-coder to work with, IMHO. Plus it's generic enough for other cards that need to limit any given CardList, which is why I decided it deserved to be in the CardList object itself. It's just as useful for limiting a library search as it is for limiting targets on the battlefield. Many of the existing CardListFilters could be reduced to this method, resulting in a cleaner CardFactory.
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: spDestroyTgt keyword
by zerker2000 » 30 Jul 2009, 10:46
Something to do with the JavaCompiler class, I believe.
O forest, hold thy wand'ring son
Though fears assail the door.
O foliage, cloak thy ravaged one
In vestments cut for war.
--Eladamri, the Seed of Freyalise
Though fears assail the door.
O foliage, cloak thy ravaged one
In vestments cut for war.
--Eladamri, the Seed of Freyalise
- zerker2000
- Programmer
- Posts: 569
- Joined: 09 May 2009, 21:40
- Location: South Pasadena, CA
- Has thanked: 0 time
- Been thanked: 0 time
Re: spDestroyTgt keyword
by silly freak » 30 Jul 2009, 20:35
i'm probably also a little late on the discussion, but check this out^^
It's not exactly by me, i found it on https://privateer.dev.java.net/source/b ... 53#dirlist
Here is an example of its use:
EDIT: the API does exist, but i'm not sure if the compiler is always available. say, when running in a JRE environment as opposed to JDK.
MemoryCompiler.zip
It's not exactly by me, i found it on https://privateer.dev.java.net/source/b ... 53#dirlist
Here is an example of its use:
- Code: Select all
//Declare the source code
String src =
"package compile;\n" +
"public class ToCompile {\n" +
"\tstatic {\n\t\tSystem.out.println(\"loaded\");\n\t}\n" +
"\tprivate String s;\n" +
"\tpublic ToCompile() {\n\t\tthis(\"Hello, World!\");\n\t}\n" +
"\tpublic ToCompile(String s) {\n\t\tthis.s = s;\n\t}\n" +
"\tpublic String toString() {\n\t\treturn s;\n\t}\n" +
"\tpublic void print() {\n\t\tSystem.out.println(s);\n\t}\n" +
"}";
//To examine the code, this is probably the best. it's nicely formatted ;)
System.out.println(src);
//Make a compiler job. This is the only thing written by me (with much copy/paste),
//just to make thing more convenient ;)
MemCompilerJob j = new MemCompilerJob();
//Add the source to the virtual project structure, taking the declared package and class name into account
j.addSourceFile("compile/ToCompile", src);
//compile the whole source
j.compile();
//Retrieve the class object
Class<?> cl = j.getClass("compile/ToCompile");
//create an object on it via default constructor
Object o = cl.newInstance();
//call a method inherited from Object
System.out.println(o.toString());
//create an object on it via other constructor
Constructor<?> c = cl.getConstructor(String.class);
o = c.newInstance("!dlroW ,olleH");
//call a method declared only in the class
Method m = cl.getMethod("print");
m.invoke(o);
EDIT: the API does exist, but i'm not sure if the compiler is always available. say, when running in a JRE environment as opposed to JDK.
___
where's the "trust me, that will work!" switch for the compiler?
Laterna Magica - blog, forum, project, 2010/09/06 release!
where's the "trust me, that will work!" switch for the compiler?
Laterna Magica - blog, forum, project, 2010/09/06 release!
- silly freak
- DEVELOPER
- Posts: 598
- Joined: 26 Mar 2009, 07:18
- Location: Vienna, Austria
- Has thanked: 93 times
- Been thanked: 25 times
Re: spDestroyTgt keyword
by Rob Cashwalker » 31 Jul 2009, 03:19
Wow... very interesting.
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: spDestroyTgt keyword
by mtgrares » 31 Jul 2009, 16:44
That is really good. It is amazing how often you have to use CardListFilter. I would have never guessed that so many Magic cards would require a filter because Magic players do it automatically in their head.Rob Cashwalker wrote:But in this case, the syntax I came up with is cleaner and easier for a non-coder to work with, IMHO. Plus it's generic enough for other cards that need to limit any given CardList, which is why I decided it deserved to be in the CardList object itself. It's just as useful for limiting a library search as it is for limiting targets on the battlefield. Many of the existing CardListFilters could be reduced to this method, resulting in a cleaner CardFactory.
- mtgrares
- DEVELOPER
- Posts: 1352
- Joined: 08 Sep 2008, 22:10
- Has thanked: 3 times
- Been thanked: 12 times
Re: spDestroyTgt keyword
by mtgrares » 06 Nov 2009, 18:13
This is from the JavaDocs for java.Compiler and yes the user has to have the Java compiler on their computer in order to "compile on the fly". The user has to have the Java JDK and not only the runtime (more common) Java JRE.
The Compiler class is provided to support Java-to-native-code compilers and related services. By design, the Compiler class does nothing; it serves as a placeholder for a JIT compiler implementation.
When the Java Virtual Machine first starts, it determines if the system property java.compiler exists. (System properties are accessible through getProperty, a method defined by the System class.) If so, it is assumed to be the name of a library (with a platform-dependent exact location and type); the loadLibrary method in class System is called to load that library. If this loading succeeds, the function named java_lang_Compiler_start() in that library is called.
If no compiler is available, these methods do nothing.
- mtgrares
- DEVELOPER
- Posts: 1352
- Joined: 08 Sep 2008, 22:10
- Has thanked: 3 times
- Been thanked: 12 times
Re: spDestroyTgt keyword
by Chris H. » 05 Jan 2010, 15:22
I found a card in my todo list and felt that there was a good chance that it would work … and it did. Good job on the keyword, Rob.

- Code: Select all
Eyeblight's Ending
2 B
Tribal Instant Elf
Destroy target non-Elf creature.
spDestroyTgt:Creature.nonElf
-
Chris H. - Forge Moderator
- Posts: 6320
- Joined: 04 Nov 2008, 12:11
- Location: Mac OS X Yosemite
- Has thanked: 644 times
- Been thanked: 643 times
Re: spDestroyTgt keyword
by Rob Cashwalker » 05 Jan 2010, 17:40
BTW, even though I wrote it, I currently have no clue how my targeting restriction function works.... Seriously... I was looking at it the other day because I wanted to see if I could easily integrate a targeting restirction clause in the other keywords. The short-answer, is yeah, probably... but WTF was I thinking?
The long answer involves a bunch of divine inspiration while drooling over the various elements of nantuko's elegant approach....
Anyway.. glad that it worked out.
The long answer involves a bunch of divine inspiration while drooling over the various elements of nantuko's elegant approach....
Anyway.. glad that it worked out.
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
54 posts
• Page 3 of 4 • 1, 2, 3, 4
Who is online
Users browsing this forum: No registered users and 28 guests