new keywords: Whenever CARDNAME blocks a creature, destroy
Post MTG Forge Related Programming Questions Here
Moderators: timmermac, Blacksmith, KrazyTheFox, Agetian, friarsol, CCGHQ Admins
5 posts
• Page 1 of 1
new keywords: Whenever CARDNAME blocks a creature, destroy
by Sloth » 15 Sep 2010, 12:33
I've added two keywords:
Whenever CARDNAME blocks a creature, destroy that creature at end of combat:<Restrictions>
Whenever CARDNAME becomes blocked by a creature, destroy that creature at end of combat:<Restrictions>
Restrictions are parsed with isValidCard.
Code:
Whenever CARDNAME blocks a creature, destroy that creature at end of combat:<Restrictions>
Whenever CARDNAME becomes blocked by a creature, destroy that creature at end of combat:<Restrictions>
Restrictions are parsed with isValidCard.
Code:
- Code: Select all
if(b.hasStartOfKeyword("Whenever CARDNAME blocks a creature, destroy that creature at end of combat")) {
int KeywordPosition = b.getKeywordPosition("Whenever CARDNAME blocks a creature, destroy that creature at end of combat");
String parse = b.getKeyword().get(KeywordPosition).toString();
String k[] = parse.split(":");
final String restrictions[] = k[1].split(",");
if(a.isValidCard(restrictions)) {
final Card attacker = a;
final Ability ability = new Ability(b, "0") {
@Override
public void resolve() {
if(AllZone.GameAction.isCardInPlay(attacker)) {
AllZone.GameAction.destroy(attacker);
}
}
};
StringBuilder sb = new StringBuilder();
sb.append(b).append(" - destroy blocked creature.");
ability.setStackDescription(sb.toString());
final Command atEOC = new Command() {
private static final long serialVersionUID = 5854485314766349980L;
public void execute() {
AllZone.Stack.add(ability);
}
};
AllZone.EndOfCombat.addAt(atEOC);
}
}// Whenever CARDNAME blocks a creature, destroy that creature at end of combat
if(a.hasStartOfKeyword("Whenever CARDNAME becomes blocked by a creature, destroy that creature at end of combat")) {
int KeywordPosition = a.getKeywordPosition("Whenever CARDNAME becomes blocked by a creature, destroy that creature at end of combat");
String parse = a.getKeyword().get(KeywordPosition).toString();
String k[] = parse.split(":");
final String restrictions[] = k[1].split(",");
if(b.isValidCard(restrictions)) {
final Card blocker = b;
final Ability ability = new Ability(a, "0") {
@Override
public void resolve() {
AllZone.GameAction.destroy(blocker);
}
};
StringBuilder sb = new StringBuilder();
sb.append(a).append(" - destroy blocking creature.");
ability.setStackDescription(sb.toString());
final Command atEOC = new Command() {
private static final long serialVersionUID = -9077416427198135373L;
public void execute() {
if(AllZone.GameAction.isCardInPlay(blocker)) AllZone.Stack.add(ability);
}
};
AllZone.EndOfCombat.addAt(atEOC);
}
}//Whenever CARDNAME becomes blocked by a creature, destroy that creature at end of combat
- Code: Select all
Name:Abomination
ManaCost:3 B B
Types:Creature Horror
Text:Whenever Abomination blocks or becomes blocked by a green or white creature, destroy that creature at end of combat.
PT:2/6
K:Whenever CARDNAME blocks a creature, destroy that creature at end of combat:Creature.Green,Creature.White
K:Whenever CARDNAME becomes blocked by a creature, destroy that creature at end of combat:Creature.Green,Creature.White
Name:Gorgon Recluse
ManaCost:3 B B
Types:Creature Gorgon
Text:Whenever Gorgon Recluse blocks or becomes blocked by a nonblack creature, destroy that creature at end of combat.
PT:2/4
K:Whenever CARDNAME blocks a creature, destroy that creature at end of combat:Creature.nonBlack
K:Whenever CARDNAME becomes blocked by a creature, destroy that creature at end of combat:Creature.nonBlack
K:Madness:B B
-
Sloth - Programmer
- Posts: 3498
- Joined: 23 Jun 2009, 19:40
- Has thanked: 125 times
- Been thanked: 507 times
Re: new keywords: Whenever CARDNAME blocks a creature, destr
by Chris H. » 15 Sep 2010, 13:53
Nice work Sloth. I had considered adding a keyword in there and just got busy with everything else.
The code looks nice and the StringBuilder is an added plus.

-
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: new keywords: Whenever CARDNAME blocks a creature, destr
by Sloth » 15 Sep 2010, 13:59
There is one problem at the moment:
The new Keywords are shown in the desription of the cards. Since when is this the default for keywords and how do I stop this?
The new Keywords are shown in the desription of the cards. Since when is this the default for keywords and how do I stop this?
-
Sloth - Programmer
- Posts: 3498
- Joined: 23 Jun 2009, 19:40
- Has thanked: 125 times
- Been thanked: 507 times
Re: new keywords: Whenever CARDNAME blocks a creature, destr
by Chris H. » 15 Sep 2010, 14:46
`Sloth wrote:There is one problem at the moment:
The new Keywords are shown in the desription of the cards. Since when is this the default for keywords and how do I stop this?
No problem, at some point we will make Rob's suggested change over and Card.getText will no longer build the text description that we see in game. Instead, we will have the "Text:" field for the cards displayed.
In the meantime we have to resort to a hack. In Card.getText we have the following code for permanents:
- Code: Select all
StringBuilder sb = new StringBuilder();
StringBuilder sbLong = new StringBuilder();
StringBuilder sbMana = new StringBuilder();
ArrayList<String> keyword = getKeyword();
for (int i = 0; i < keyword.size(); i++) {
if (!keyword.get(i).toString().contains("CostChange")) {
if (keyword.get(i).toString().contains("WheneverKeyword")) {
String k[] = keyword.get(i).split(":");
sbLong.append(k[9]).append("\r\n");
} else if (keyword.get(i).toString().contains("StaticEffect")) {
String k[] = keyword.get(i).split(":");
sbLong.append(k[5]).append("\r\n");
} else if (keyword.get(i).endsWith(".")) {
sbLong.append(keyword.get(i).toString()).append("\r\n");
} else if (keyword.get(i).contains("At the beginning of your upkeep, ")
&& keyword.get(i).contains(" unless you pay:")) {
sbLong.append(keyword.get(i).toString()).append("\r\n");
} else if (keyword.get(i).toString().contains("tap: add ")) {
sbMana.append(keyword.get(i).toString()).append("\r\n");
} else {
if (i != 0 && sb.length() != 0) sb.append(", ");
sb.append(keyword.get(i).toString());
}
}
}
if (sb.length() > 0) sb.append("\r\n\r\n");
if (sbLong.length() > 0) sbLong.append("\r\n");
sb.append(sbLong);
sb.append(sbMana);
Add your two new keywords in to this test:
- Code: Select all
if (!keyword.get(i).toString().contains("CostChange")) {
and your two new keywords will not get added to the StringBuilder work that is taking place.

-
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: new keywords: Whenever CARDNAME blocks a creature, destr
by Sloth » 15 Sep 2010, 15:28
Thank you. I did just that.Chris H. wrote:Add your two new keywords in to this test:`
- Code: Select all
if (!keyword.get(i).toString().contains("CostChange")) {
and your two new keywords will not get added to the StringBuilder work that is taking place.
-
Sloth - Programmer
- Posts: 3498
- Joined: 23 Jun 2009, 19:40
- Has thanked: 125 times
- Been thanked: 507 times
5 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 39 guests