It is currently 08 Sep 2025, 05:33
   
Text Size

new keywords: Whenever CARDNAME blocks a creature, destroy

Post MTG Forge Related Programming Questions Here

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

new keywords: Whenever CARDNAME blocks a creature, destroy

Postby 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:
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
Examples:
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
User avatar
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

Postby 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. :mrgreen: The code looks nice and the StringBuilder is an added plus.
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: new keywords: Whenever CARDNAME blocks a creature, destr

Postby 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?
User avatar
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

Postby 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. :D
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: new keywords: Whenever CARDNAME blocks a creature, destr

Postby Sloth » 15 Sep 2010, 15:28

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. :D
Thank you. I did just that.
User avatar
Sloth
Programmer
 
Posts: 3498
Joined: 23 Jun 2009, 19:40
Has thanked: 125 times
Been thanked: 507 times


Return to Developer's Corner

Who is online

Users browsing this forum: No registered users and 39 guests

Main Menu

User Menu

Our Partners


Who is online

In total there are 39 users online :: 0 registered, 0 hidden and 39 guests (based on users active over the past 10 minutes)
Most users ever online was 7303 on 15 Jul 2025, 20:46

Users browsing this forum: No registered users and 39 guests

Login Form