It is currently 30 Apr 2025, 18:48
   
Text Size

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

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

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

Postby 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...
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: CARDNAME can't attack if defending player controls an un

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


Return to Developer's Corner

Who is online

Users browsing this forum: No registered users and 35 guests


Who is online

In total there are 35 users online :: 0 registered, 0 hidden and 35 guests (based on users active over the past 10 minutes)
Most users ever online was 4143 on 23 Jan 2024, 08:21

Users browsing this forum: No registered users and 35 guests

Login Form