Cycle cards
Post MTG Forge Related Programming Questions Here
Moderators: timmermac, Blacksmith, KrazyTheFox, Agetian, friarsol, CCGHQ Admins
Cycle cards
by Chris H. » 12 Sep 2009, 22:09
Thanks to Dennis I finally got Akroma's Vengeance working. I had to look at the code for Hush ... this gave me the hint that I needed ... I also had to enter an additional line
"spell.setDescription("Destroy all artifacts, creatures, and enchantments.");"
Add this to cards.txt:
This replaces the Jokulhaups code section in CardFactory.java:
EDIT:
This older code was missing the stack description, please see the corrected version of the code in the next message.
.
This is the jpg url for Akroma's Vengeance:
.
"spell.setDescription("Destroy all artifacts, creatures, and enchantments.");"
Add this to cards.txt:
- Code: Select all
Akroma's Vengeance
4 W W
Sorcery
no text
This replaces the Jokulhaups code section in CardFactory.java:
EDIT:
This older code was missing the stack description, please see the corrected version of the code in the next message.
.
This is the jpg url for Akroma's Vengeance:
.
- Attachments
-
- Akroma's Vengeance jpg picture url.zip
- (727 Bytes) Downloaded 199 times
Last edited by Chris H. on 13 Sep 2009, 02:11, edited 1 time in total.
-
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: Cycle cards
by Chris H. » 13 Sep 2009, 02:09
Dang it, I need to learn how to test better.Chris H. wrote:I also had to enter an additional line
"spell.setDescription("Destroy all artifacts, creatures, and enchantments.");"
Turns out that I had to also add:
"spell.setStackDescription("Akroma's Vengeance - Destroy all artifacts, creatures, and enchantments.");"
This is the updated version of the Jokulhaups and Akroma's Vengeance code:
EDIT:
This older code is being replaced by the newer version in a latter message.
Last edited by Chris H. on 13 Sep 2009, 13:09, edited 1 time in total.
-
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: Cycle cards
by Sloth » 13 Sep 2009, 10:30
That's a nice new card to have in Forge Chris H! Thank you.
If you want to add similar cards to this batch of code, I would like to suggest Devastation, Purify and Shatterstorm.
If you want to add similar cards to this batch of code, I would like to suggest Devastation, Purify and Shatterstorm.
-
Sloth - Programmer
- Posts: 3498
- Joined: 23 Jun 2009, 19:40
- Has thanked: 125 times
- Been thanked: 507 times
Re: Cycle cards
by Chris H. » 13 Sep 2009, 13:03
Thank you Sloth, three more spells.
Add this additional data to add to cards.txt:
This is the new and improved code and now includes all five spells:
This archive contains the card picture urls to add to card-pictures.txt for the three new spells Devastation, Purify and Shatterstorm:
.
Add this additional data to add to cards.txt:
- Code: Select all
Devastation
5 R R
Sorcery
Destroy all creatures and lands.
Purify
3 W W
Sorcery
Destroy all artifacts and enchantments.
Shatterstorm
2 R R
Sorcery
Destroy all artifacts. They can't be regenerated.
This is the new and improved code and now includes all five spells:
- Code: Select all
//*************** START *********** START **************************
if(cardName.equals("Akroma's Vengeance") ||
cardName.equals("Devastation") ||
cardName.equals("Jokulhaups") ||
cardName.equals("Purify") ||
cardName.equals("Shatterstorm"))
{
final SpellAbility spell = new Spell(card)
{
private static final long serialVersionUID = -7384618531690849205L;
public void resolve()
{
CardList all = new CardList();
all.addAll(AllZone.Human_Play.getCards());
all.addAll(AllZone.Computer_Play.getCards());
for(int i = 0; i < all.size(); i++)
{
Card c = all.get(i);
if(cardName.equals("Akroma's Vengeance") & (c.isCreature() || c.isArtifact() || c.isEnchantment())) // Destroy Enchantment rather than Land
AllZone.GameAction.destroy(c); // Can regenerate
if(cardName.equals("Devastation") & (c.isCreature() || c.isLand()))
AllZone.GameAction.destroy(c); // Can regenerate
if(cardName.equals("Jokulhaups") & (c.isCreature() || c.isArtifact() || c.isLand()))
AllZone.GameAction.destroyNoRegeneration(c); // CAN'T regenerate
if(cardName.equals("Purify") & (c.isArtifact() || c.isEnchantment()))
AllZone.GameAction.destroy(c); // Can regenerate
if(cardName.equals("Shatterstorm") & (c.isArtifact()))
AllZone.GameAction.destroyNoRegeneration(c); // CAN'T regenerate
}
}//resolve()
};//SpellAbility
if(cardName.equals("Akroma's Vengeance"))
{
spell.setStackDescription("Akroma's Vengeance - Destroy all artifacts, creatures, and enchantments."); // add stack description
spell.setDescription("Destroy all artifacts, creatures, and enchantments."); // add spell detail description
}
card.clearSpellAbility();
card.addSpellAbility(spell);
if(cardName.equals("Akroma's Vengeance")) //add cycling
card.addSpellAbility(CardFactoryUtil.ability_cycle(card, "3"));
}//*************** END ************ END **************************
This archive contains the card picture urls to add to card-pictures.txt for the three new spells Devastation, Purify and Shatterstorm:
.
- Attachments
-
- Sloths Three spells urls.zip
- (688 Bytes) Downloaded 215 times
-
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: Cycle cards
by Rob Cashwalker » 13 Sep 2009, 14:19
I'd encourage you to try to revise this code to work as a keyword. "Destroy All ___" shows up at least once each block...
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: Cycle cards
by Chris H. » 13 Sep 2009, 15:25
Turning "Destroy All ___" into a keyword would be great. I am not up to the challenge quite yet.Rob Cashwalker wrote:I'd encourage you to try to revise this code to work as a keyword. "Destroy All ___" shows up at least once each block...
I also noticed that the original Jokulhaups code had no AI section. This made it a little easier for me to add a few cards. I took a peek at Wrath of God, but I do not understand the AI code at this time. I guess that the computer does not cast the spell if it has an advantage in number of creatures in play.
-
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: Cycle cards
by DennisBergkamp » 13 Sep 2009, 19:16
Yeah, I think it won't cast Wrath of God unless it can destroy at least 2 or 3 more creatures of the human player.
By the way, I noticed something funny with the text of Wrath of God, in my version it used to say "Destroy all creature. They can't be regenerated."
I've fixed it in my version, not sure if it's something I accidentally changed ...
By the way, I noticed something funny with the text of Wrath of God, in my version it used to say "Destroy all creature. They can't be regenerated."
I've fixed it in my version, not sure if it's something I accidentally changed ...
-
DennisBergkamp - AI Programmer
- Posts: 2602
- Joined: 09 Sep 2008, 15:46
- Has thanked: 0 time
- Been thanked: 0 time
Re: Cycle cards
by Chris H. » 14 Sep 2009, 00:52
I have spent some time looking at CardFactory.java and there is a lot of complicated code in this file. I am having a difficult time seeing the "big picture" and at this time my efforts to help will have to be limited.
I am still trying to figure out how to handle Rob's suggestion in reference to moving the keyword code and the effect that this will have on cycling spells.
I figured out how to create a basic shell for a spell and have added 5 new spDestroyTgt keyword + Cycling spells to this shell. It works correctly from what I can tell.
If we can get Rob's suggestion working, we can then remove this code and convert these five spells to using just keywords. This is the best that I can do at this time.
Add this to cards.txt:
Add this to CardFactory.java:
Add this to card-pictures.txt:
.
I am still trying to figure out how to handle Rob's suggestion in reference to moving the keyword code and the effect that this will have on cycling spells.
I figured out how to create a basic shell for a spell and have added 5 new spDestroyTgt keyword + Cycling spells to this shell. It works correctly from what I can tell.
If we can get Rob's suggestion working, we can then remove this code and convert these five spells to using just keywords. This is the best that I can do at this time.
Add this to cards.txt:
- Code: Select all
Break Asunder
2 G G
Sorcery
Destroy target artifact or enchantment.
spDestroyTgt:Artifact,Enchantment
Clear
1 W
Instant
Destroy target enchantment.
spDestroyTgt:Enchantment
Molten Frame
1 R
Instant
Destroy target artifact creature.
spDestroyTgt:Creature.Artifact
Scrap
2 R
Instant
Destroy target artifact.
spDestroyTgt:Artifact
Volcanic Submersion
4 R
Sorcery
Destroy target artifact or land.
spDestroyTgt:Artifact,Land
Add this to CardFactory.java:
- Code: Select all
//*************** START *********** START **************************
if(cardName.equals("Break Asunder") ||
cardName.equals("Clear") ||
cardName.equals("Molten Frame") ||
cardName.equals("Scrap") ||
cardName.equals("Volcanic Submersion"))
{
final SpellAbility spell = new Spell(card)
{
private static final long serialVersionUID = -8988655754666544759L;
public void resolve()
{
}//resolve()
};//SpellAbility
if(cardName.equals("Break Asunder"))
spell.setDescription("Destroy target artifact or enchantment."); // add spell detail description
if(cardName.equals("Clear"))
spell.setDescription("Destroy target enchantment.");
if(cardName.equals("Molten Frame"))
spell.setDescription("Destroy target artifact creature.");
if(cardName.equals("Scrap"))
spell.setDescription("Destroy target artifact.");
if(cardName.equals("Volcanic Submersion"))
spell.setDescription("Destroy target artifact or land.");
// card.clearSpellAbility();
// card.addSpellAbility(spell);
if(cardName.equals("Break Asunder") || //add cycling
cardName.equals("Clear") ||
cardName.equals("Molten Frame") ||
cardName.equals("Scrap") ||
cardName.equals("Volcanic Submersion"))
card.addSpellAbility(CardFactoryUtil.ability_cycle(card, "2"));
}//*************** END ************ END **************************
Add this to card-pictures.txt:
.
- Attachments
-
- Cycling and spDestroyTgt pic urls.zip
- (770 Bytes) Downloaded 170 times
-
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: Cycle cards
by Rob Cashwalker » 14 Sep 2009, 04:04
The keywording thing is half-written for you already. Combine most of the parsing shell for spDestroyTgt with the resolve() method of the "Destroy All ___" code. Mix in some AI and fine tune where necessary.
The Cycling part will work without explicit code, if you move it to the very end of the getCard2() method, after squirrel nest:
The Cycling part will work without explicit code, if you move it to the very end of the getCard2() method, after squirrel nest:
- Code: Select all
stopSetNext(CardFactoryUtil.input_targetSpecific(spell, land, "Select target land", true));
}
};
spell.setBeforePayMana(runtime);
}//Squirrel Nest *************** END ************ END **************************
// Cards with Cycling abilities
// -1 means keyword "Cycling" not found
if (shouldCycle(card) != -1)
{
int n = shouldCycle(card);
if (n != -1)
{
String parse = card.getKeyword().get(n).toString();
card.removeIntrinsicKeyword(parse);
String k[] = parse.split(":");
final String manacost = k[1];
card.addSpellAbility(CardFactoryUtil.ability_cycle(card, manacost));
}
}//Cycling
return card;
}//getCard2
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: Cycle cards
by mtgrares » 14 Sep 2009, 14:31
I'll try to help you a little. The problem that CardFactory solves is how do you make brand new copies of objects? The easiest what is to create an new object and return it. In Java you can use the brackets {} to nest as much as you want to.Chris H. wrote:I have spent some time looking at CardFactory.java and there is a lot of complicated code in this file. I am having a difficult time seeing the "big picture" and at this time my efforts to help will have to be limited.
- Code: Select all
{ //1
{//2 - can access 1 variables
{//3 - can access level 1 and 2 variables
}
}//2 - can't access 3
}3 - can't access 2 or 3
CardFactory is confusing with just hundreds of card objects and becomes more confusing by adding "scripting keywords" which have to go before all of the other code in CardFactory. And you have to make sure that the code that handles the "scripting keywords" is in the correct order and that each part of the code only handles the keywords that it should, otherwise you will have no idea what is the problem when something doesn't work when you are coding a new keyword.
I hope that helps a little.
- mtgrares
- DEVELOPER
- Posts: 1352
- Joined: 08 Sep 2008, 22:10
- Has thanked: 3 times
- Been thanked: 12 times
Re: Cycle cards
by Chris H. » 14 Sep 2009, 15:09
It has been many, many years since I took an introductory COBOL class in college. My memory has of course faded over time. I remember breaking up the code into smaller sets of self-contained sections of code, procedures(?)mtgrares wrote:CardFactory is confusing with just hundreds of card objects and becomes more confusing by adding "scripting keywords" which have to go before all of the other code in CardFactory. And you have to make sure that the code that handles the "scripting keywords" is in the correct order and that each part of the code only handles the keywords that it should, otherwise you will have no idea what is the problem when something doesn't work when you are coding a new keyword.
CardFactory is an extreme case. I'm getting to the point where I can understand the shorter and simpler card objects. The keyword section is more complicated, but I am learning as time passes.
-
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: Cycle cards
by Chris H. » 14 Sep 2009, 15:13
OK, at the start of CardFactory.java we have a check to see if the cycling is present. We leave this code here since it is just a test and returns a boolean value.Rob Cashwalker wrote:The Cycling part will work without explicit code, if you move it to the very end of the getCard2() method, after squirrel nest:
We move the section of the cycling code that you pointed out to underneath the Squirrel Nest code and before the "return card;" statement.
I deleted the spell shell that I had created for the 5 new spDestroyTgt + Cycling spells and added the "Cycling:2" keyword to these cards. Tested it, and it works, awesome.
Good job Rob.
Last edited by Chris H. on 14 Sep 2009, 18:12, edited 1 time in total.
-
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: Cycle cards
by mtgrares » 14 Sep 2009, 18:04
Yeah, procedures or methods (which are the same thing). I divided up CardFactory by each "if" statement. The keyword scripting is tough because it tends to be really big. Some Magic cards have very simple code like Wrath of God. End of Turn abilities are more complicated. Royal Assassin's code shows a "non-mana" activated ability.Chris H. wrote:I remember breaking up the code into smaller sets of self-contained sections of code, procedures(?)
- mtgrares
- DEVELOPER
- Posts: 1352
- Joined: 08 Sep 2008, 22:10
- Has thanked: 3 times
- Been thanked: 12 times
13 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 106 guests