It is currently 03 May 2024, 00:12
   
Text Size

CARDNAME can't be blocked by creatures with power...

Post MTG Forge Related Programming Questions Here

Moderators: timmermac, Blacksmith, KrazyTheFox, Agetian, friarsol, CCGHQ Admins

CARDNAME can't be blocked by creatures with power...

Postby slapshot5 » 15 Apr 2010, 14:42

Logical followup from Chris's earlier post...

This is based on the type of ability the Amrou Kithkin has.

The keyword will look like:

Code: Select all
CARDNAME can't be blocked by creatures with power {rest of string}
right after Chris's code in CombatUtil.canBlock():

Code: Select all
// CARDNAME can't be blocked by creatures with power ...

        int powerLimit2[] = {0};
        int keywordPosition2 = 0;
        boolean hasKeyword2 = false;
       
        //ArrayList<String> blockerKeywords = blocker.getKeyword();
        for (int i = 0; i < blockerKeywords.size(); i++) {
           if (blockerKeywords.get(i).toString().startsWith("CARDNAME can't be blocked by creatures with power")) {
              hasKeyword2 = true;
              keywordPosition2 = i;
           }
        }
       
        if (hasKeyword2) {    // The keyword "CARDNAME can't be blocked by creatures with power" ... is present
           String tmpString = blocker.getKeyword().get(keywordPosition2).toString();
           String asSeparateWords[]  = tmpString.trim().split(" ");
           
           if (asSeparateWords.length >= 9) {
              if (asSeparateWords[8].matches("[0-9][0-9]?")) {
                 powerLimit2[0] = Integer.parseInt((asSeparateWords[8]).trim());
                 
                 if (blocker.getNetAttack() >= powerLimit2[0] && attacker.getKeyword().contains
                       ("CARDNAME can't be blocked by creatures with power " + powerLimit2[0] + " or greater.")) return false;
                 if (blocker.getNetAttack() <= powerLimit2[0] && attacker.getKeyword().contains
                       ("CARDNAME can't be blocked by creatures with power " + powerLimit2[0] + " or less.")) return false;
              }
           }
           
           if (blocker.getNetAttack() > attacker.getNetAttack()
               && blocker.getKeyword().contains("CARDNAME can't be blocked by creatures with power greater than CARDNAME's power.")) return false;
           if (blocker.getNetAttack() >= attacker.getNetDefense()
                 && blocker.getKeyword().contains("CARDNAME can't be blocked by creatures with power equal to or greater than CARDNAME's toughness.")) return false;
           
        }// hasKeyword CARDNAME can't be blocked by creatures with power ...
cards.txt would look like:
Code: Select all
Amrou Kithkin
W W
Creature Kithkin
no text
1/1
CARDNAME can't be blocked by creatures with power 2 or greater.
This would need to be committed. Then added to the Keywords thread.

-slapshot5
slapshot5
Programmer
 
Posts: 1391
Joined: 03 Jan 2010, 17:47
Location: Mac OS X
Has thanked: 25 times
Been thanked: 68 times

Re: CARDNAME can't be blocked by creatures with power...

Postby slapshot5 » 15 Apr 2010, 14:44

This would allow the following cards:
Amrou Kithkin
Fleet-Footed Monk
Goldmeadow Dodger (already included, but it is special cased. change to keyword)
Sneaky Homunculus


Code: Select all
Amrou Kithkin
W W
Creature Kithkin
no text
1/1
CARDNAME can't be blocked by creatures with power 2 or greater.

Fleet-Footed Monk
1 W
Creature Human Monk
no text
1/1
CARDNAME can't be blocked by creatures with power 2 or greater.

Goldmeadow Dodger
W
Creature Kithkin Rogue
no text
1/1
CARDNAME can't be blocked by creatures with power 4 or greater.

Sneaky Homunculus
1 U
Creature Homunculus Illusion
no text
1/1
CARDNAME can't be blocked by creatures with power 2 or greater.
CARDNAME can't block creatures with power 2 or greater.
-slapshot5
slapshot5
Programmer
 
Posts: 1391
Joined: 03 Jan 2010, 17:47
Location: Mac OS X
Has thanked: 25 times
Been thanked: 68 times

Re: CARDNAME can't be blocked by creatures with power...

Postby slapshot5 » 15 Apr 2010, 14:46

I should also point out, the following line in CombatUtil.canBlock() can then be commented out:

Code: Select all
if(attacker.getName().equals("Goldmeadow Dodger")) return blocker.getNetAttack() < 4;
-slapshot5
slapshot5
Programmer
 
Posts: 1391
Joined: 03 Jan 2010, 17:47
Location: Mac OS X
Has thanked: 25 times
Been thanked: 68 times

Re: CARDNAME can't be blocked by creatures with power...

Postby Chris H. » 15 Apr 2010, 14:59

Awesome work. :D

Thank you, I will try to get it committed sometime tomorrow or the next day. Thank you.
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 be blocked by creatures with power...

Postby Chris H. » 15 Apr 2010, 17:41

I have your code merged into my local copy and ran a test with Amrou Kithkin and the ability/restriction was not in effect. :( I looked at the code for a while and it dawned on me that the code which creates a ArrayList<String> and then tests for the keyword needed to be changed to look at the attacker's keywords.

I made the change and it appears to work now. :mrgreen:

Code: Select all
        ArrayList<String> attackerKeywords = attacker.getKeyword();
        for (int i = 0; i < attackerKeywords.size(); i++) {
           if (attackerKeywords.get(i).toString().startsWith("CARDNAME can't be blocked by creatures with power")) {
              hasKeyword2 = true;
              keywordPosition2 = i;
           }
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 be blocked by creatures with power...

Postby slapshot5 » 15 Apr 2010, 18:45

Chris H. wrote:I made the change and it appears to work now.
D'oh! #-o

That's what copy&paste will get you.
slapshot5
Programmer
 
Posts: 1391
Joined: 03 Jan 2010, 17:47
Location: Mac OS X
Has thanked: 25 times
Been thanked: 68 times


Return to Developer's Corner

Who is online

Users browsing this forum: No registered users and 47 guests


Who is online

In total there are 47 users online :: 0 registered, 0 hidden and 47 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 47 guests

Login Form