CARDNAME can't attack if defending player controls an untapp
Post MTG Forge Related Programming Questions Here
Moderators: timmermac, Blacksmith, KrazyTheFox, Agetian, friarsol, CCGHQ Admins
CARDNAME can't attack if defending player controls an untapp
by Chris H. » 15 Apr 2010, 13:07
CARDNAME can't attack if defending player controls an untapped creature with power {rest of text string}
This keyword is for the various cards that are based upon the Orgg and Goblin Mutant type of ability. The keyword currently has this format:
The only forms supported at this time will look like:
The cards.txt entries will look like this:
Near the top of CombatUtil.java in the canAttack() method:
This keyword is for the various cards that are based upon the Orgg and Goblin Mutant type of ability. The keyword currently has this format:
- Code: Select all
CARDNAME can't attack if defending player controls an untapped creature with power {rest of text string}
The only forms supported at this time will look like:
- Code: Select all
CARDNAME can't attack if defending player controls an untapped creature with power {num} or {"greater." or "less."}
The cards.txt entries will look like this:
- Code: Select all
Goblin Mutant
2 R R
Creature Goblin Mutant
no text
5/3
Trample
CARDNAME can't attack if defending player controls an untapped creature with power 3 or greater.
CARDNAME can't block creatures with power 3 or greater.
Mogg Jailer
1 R
Creature Goblin
no text
2/2
CARDNAME can't attack if defending player controls an untapped creature with power 2 or less.
Orgg
3 R R
Creature Orgg
no text
6/6
Trample
CARDNAME can't attack if defending player controls an untapped creature with power 3 or greater.
CARDNAME can't block creatures with power 3 or greater.
Near the top of CombatUtil.java in the canAttack() method:
- Code: Select all
// CARDNAME can't attack if defending player controls an untapped creature with power ...
final int powerLimit[] = {0};
int keywordPosition = 0;
boolean hasKeyword = false;
ArrayList<String> attackerKeywords = c.getKeyword();
for (int i = 0; i < attackerKeywords.size(); i++) {
if (attackerKeywords.get(i).toString().startsWith("CARDNAME can't attack if defending player controls an untapped creature with power")) {
hasKeyword = true;
keywordPosition = i;
}
}
if (hasKeyword) { // The keyword "CARDNAME can't attack if defending player controls an untapped creature with power" ... is present
String tmpString = c.getKeyword().get(keywordPosition).toString();
final String asSeparateWords[] = tmpString.trim().split(" ");
if (asSeparateWords.length >= 15) {
if (asSeparateWords[12].matches("[0-9][0-9]?")) {
powerLimit[0] = Integer.parseInt((asSeparateWords[12]).trim());
CardList list = null;
if (c.getController().equals(Constant.Player.Human)) {
list = new CardList(AllZone.Computer_Play.getCards());
} else {
list = new CardList(AllZone.Human_Play.getCards());
}
list = list.getType("Creature");
list = list.filter(new CardListFilter() {
public boolean addCard(Card ct) {
return ((ct.isUntapped() && ct.getNetAttack() >= powerLimit[0] && asSeparateWords[14].contains("greater")) ||
(ct.isUntapped() && ct.getNetAttack() <= powerLimit[0] && asSeparateWords[14].contains("less")));
}
});
if (!list.isEmpty()) return false;
}
}
} // hasKeyword = CARDNAME can't attack if defending player controls an untapped creature with power ...
-
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: CARDNAME can't attack if defending player controls an un
by Rob Cashwalker » 15 Apr 2010, 14:27
May I suggest using some helper methods in CardFactoryUtil, (like xCount is for variable scale spells) where a simple boolean is returned based on parsing various condition strings.
CARDNAME:CanNot:AttackIf:DefPlayerCtrlTypeUntapped.Creature/PowerGreater.3
CARDNAME:CanNot:AttackIf:DefPlayerCtrlType.Island
CARDNAME:CanNot:Block:PowerGreater.3
CARDNAME:Can:BlockOnly:WithKeyword.Flying
etc...
CARDNAME:CanNot:AttackIf:DefPlayerCtrlTypeUntapped.Creature/PowerGreater.3
CARDNAME:CanNot:AttackIf:DefPlayerCtrlType.Island
CARDNAME:CanNot:Block:PowerGreater.3
CARDNAME:Can:BlockOnly:WithKeyword.Flying
etc...
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: CARDNAME can't attack if defending player controls an un
by Chris H. » 15 Apr 2010, 14:51
Yes, I had considered something along those lines. The canAttack() and canBlock() methods are fairly short and simple. I suspect that this code is called frequently through the course of a game. As it is, I commented out 2 lines of code and added in almost 100 lines into these two methods.
And I am still learning java and how to code. I can see that I am learning and my code is improving with time. I do like your idea of one keyword for each method that in turn could give us all of the various possibilities via parameter parsing. At some point I may be capable of writing code this complex and sophisticated.
And I am still learning java and how to code. I can see that I am learning and my code is improving with time. I do like your idea of one keyword for each method that in turn could give us all of the various possibilities via parameter parsing. At some point I may be capable of writing code this complex and sophisticated.

-
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
3 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 35 guests