It is currently 09 Sep 2025, 17:53
   
Text Size

Code from slapshot5

Post MTG Forge Related Programming Questions Here

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

Re: Code from slapshot5

Postby slapshot5 » 18 Apr 2010, 23:30

Here is Consume the Meek from Rise of the Eldrazi:

cards.txt:
Code: Select all
Consume the Meek
3 B B
Instant
Destroy each creature with converted mana cost 3 or less. They can't be regenerated.
URL:
Code: Select all
consume_the_meek.jpg      http://www.wizards.com/global/images/magic/general/consume_the_meek.jpg
CardFactory.java:
Code: Select all
  //*************** START *********** START **************************
        else if(cardName.equals("Consume the Meek")) {
           /* Destroy each creature with converted mana cost 3 or less.
            * They can't be regenerated.
            */
            SpellAbility spell = new Spell(card) {
      private static final long serialVersionUID = 9127892501403187034L;

      @Override
                public void resolve() {
                    CardList all = new CardList();
                    all.addAll(getHumanCreatures().toArray());
                    all.addAll(getComputerCreatures().toArray());
                   
                    for(int i = 0; i < all.size(); i++) {
                        Card c = all.get(i);
                        System.out.println("Consume the Meek: " + c);
                        AllZone.GameAction.destroyNoRegeneration(c);
                    }
                }// resolve()
            
      CardListFilter filter = new CardListFilter() {
         public boolean addCard(Card c) {
            return c.isCreature() && CardUtil.getConvertedManaCost(c) <= 3;
         }
      };
            
      private CardList getHumanCreatures() {
         CardList human = new CardList();
         human.addAll(AllZone.Human_Play.getCards());
         human = human.filter(filter);
         return human;
      }
            
            private CardList getComputerCreatures() {
               CardList comp = new CardList();
               comp.addAll(AllZone.Computer_Play.getCards());
               comp = comp.filter(filter);
               return comp;
            }
               
                @Override
                public boolean canPlayAI() {
                    CardList human = getHumanCreatures();
                    CardList computer = getComputerCreatures();
                   
                    // the computer will at least destroy 2 more human creatures
                    return  AllZone.Phase.getPhase().equals(Constant.Phase.Main2) &&
                          (computer.size() < human.size() - 1
                            || (AllZone.Computer_Life.getLife() < 7 && !human.isEmpty()));
                }
            };// SpellAbility
            card.clearSpellAbility();
            card.addSpellAbility(spell);
        }// *************** END ************ END **************************
I tested, and it seems to work for Human and AI. Basically copied from Wrath of God with a couple filters thrown in.

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

Re: Code from slapshot5

Postby slapshot5 » 19 Apr 2010, 00:10

Here is Near-Death Experience - also from Rise of the Eldrazi.

cards.txt:
Code: Select all
Near-Death Experience
2 W W W
Enchantment
At the beginning of your upkeep, if you have exactly 1 life, you win the game.
URL:
Code: Select all
near_death_experience.jpg      http://www.wizards.com/global/images/magic/general/near_death_experience.jpg
GameActionUtil.java:
Code: Select all
upkeep_Near_Death_Experience();
GameActionUtil.java:
Code: Select all
private static void upkeep_Near_Death_Experience() {
        final String player = AllZone.Phase.getActivePlayer();
        PlayerZone playZone = AllZone.getZone(Constant.Zone.Play, player);
        PlayerLife life = AllZone.GameAction.getPlayerLife(player);
       
        CardList list = new CardList(playZone.getCards());
        list = list.getName("Near-Death Experience");
       
        if(0 < list.size() && life.getLife() == 1) {
            Ability ability = new Ability(list.get(0), "0") {
                @Override
                public void resolve() {
                    String opponent = AllZone.GameAction.getOpponent(player);
                    PlayerLife oppLife = AllZone.GameAction.getPlayerLife(opponent);
                   
                    int gameNumber = 0;
                    if (Constant.Runtime.WinLose.getWin()==1)
                       gameNumber = 1;
                    Constant.Runtime.WinLose.setWinMethod(gameNumber,"Near-Death Experience");
                   
                    oppLife.setLife(0);
                }
            };// Ability
           
            ability.setStackDescription("Near-Death Experience - " + player + " wins the game");
            AllZone.Stack.add(ability);
        }// if
    }// upkeep_Near_Death_Experience
Copied and tweaked from Epic Struggle

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

Re: Code from slapshot5

Postby slapshot5 » 19 Apr 2010, 00:44

Here's Giant Tortoise from Arabian Nights:
cards.txt:
Code: Select all
Giant Tortoise
1 U
Creature Turtle
As long as Giant Tortoise is untapped, it gets +0/+3.
1/1
GameActionUtil.java:
Code: Select all
commands.put("Giant_Tortoise", Giant_Tortoise);
GameActionUtil.java:
Code: Select all
public static Command Giant_Tortoise = new Command() {
      private static final long serialVersionUID = -8191148876633239167L;
      
      CardList old = new CardList();
      int pump = 3;

      public void execute() {
         Card c;
         // reset all previous cards stats
         for(int i = 0; i < old.size(); i++) {
            c = old.get(i);
            c.addSemiPermanentDefenseBoost(-pump);
         }
         old.clear();

         CardList list = getCard("Giant Tortoise");
         for(int i = 0; i < list.size(); i++) {
            c = list.get(i);
            // only add boost if card is untapped
            if(c.isUntapped()) {
               c.addSemiPermanentDefenseBoost(pump);
               old.add(c);
            }
         }// for
      }// execute()

      CardList getCard(String name) {
         CardList list = new CardList();
         list.addAll(AllZone.Human_Play.getCards());
         list.addAll(AllZone.Computer_Play.getCards());
         list = list.getName(name);
         return list;
      }// getCard()
   }; // Giant Tortoise
Copied from Castle Raptors

-slapshot5

Edit:
Crap. I think this needs to be added to StaticEffects.java also:

Code: Select all
cardToEffectsList.put("Giant Tortoise", new String[] {"Giant_Tortoise"});
slapshot5
Programmer
 
Posts: 1391
Joined: 03 Jan 2010, 17:47
Location: Mac OS X
Has thanked: 25 times
Been thanked: 68 times

Re: Code from slapshot5

Postby slapshot5 » 19 Apr 2010, 04:06

Here's Fracturing Gust from Shadowmoor:

Code: Select all
cards.txt:
Fracturing Gust
2 GW GW GW
Instant
Destroy all artifacts and enchantments. You gain 2 life for each permanent destroyed this way.
URL:
Code: Select all
http://www.wizards.com/global/images/magic/general/fracturing_gust.jpg
CardFactory.java:
Code: Select all
//*************** START *********** START **************************
        else if(cardName.equals("Fracturing Gust")) {
           /*
            * Destroy all artifacts and enchantments.
            * You gain 2 life for each permanent destroyed this way.
            */
            SpellAbility spell = new Spell(card) {
            private static final long serialVersionUID = 6940814538785932457L;

            @Override
                public void resolve() {
               final String player = AllZone.Phase.getActivePlayer();
                    CardList all = new CardList();
                    all.addAll(AllZone.Human_Play.getCards());
                    all.addAll(AllZone.Computer_Play.getCards());
                    all = all.filter(artAndEn);
                   
                    for(int i = 0; i < all.size(); i++) {
                        Card c = all.get(i);
                        AllZone.GameAction.destroy(c);
                    }
                    AllZone.GameAction.addLife(player, all.size()*2);
                }// resolve()
               
                @Override
                public boolean canPlayAI() {
                    CardList human = new CardList(AllZone.Human_Play.getCards());
                    CardList computer = new CardList(AllZone.Computer_Play.getCards());
                   
                    human = human.filter(artAndEn);
                    computer = computer.filter(artAndEn);                   

                    if(human.size() == 0) return false;
                   
                    // the computer will at least destroy 2 more human enchantments
                    return computer.size() < human.size() - 1
                            || (AllZone.Computer_Life.getLife() < 7 && !human.isEmpty());
                }//canPlayAI
               
                private CardListFilter artAndEn = new CardListFilter() {
                   public boolean addCard(Card c) {
                      return c.isArtifact() || c.isEnchantment();
                   }
                };
               
            };// SpellAbility
            spell.setStackDescription(card.getName() + " - destroy all artifacts and enchantments.");
            card.clearSpellAbility();
            card.addSpellAbility(spell);
        }// *************** END ************ END **************************
Copied from Tranquility and tweaked.

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

Re: Code from slapshot5

Postby slapshot5 » 19 Apr 2010, 15:15

Dennis or Rob -

I'm happy to keep posting code for others to commit.

-or-

I do feel comfortable now committing changes myself. I've got everything set up. If you're willing to grant me commit privileges, please PM me with questions or needed info.

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

Re: Code from slapshot5

Postby Rob Cashwalker » 19 Apr 2010, 15:17

Doing a one-shot upkeep effect should be easy as-is. I was considering adding the "draw a card on next upkeep" as a "drawback" for other keywords.

We already have a Command list for upkeep effects. Just create a Command to draw the card, then deletes itself when executed.
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: Code from slapshot5

Postby DennisBergkamp » 19 Apr 2010, 16:14

slapshot5 wrote:Dennis or Rob -

I'm happy to keep posting code for others to commit.

-or-

I do feel comfortable now committing changes myself. I've got everything set up. If you're willing to grant me commit privileges, please PM me with questions or needed info.

-slapshot5
Just pm me your email address (I think it has to be associated with a Google account). That's all I need :)
User avatar
DennisBergkamp
AI Programmer
 
Posts: 2602
Joined: 09 Sep 2008, 15:46
Has thanked: 0 time
Been thanked: 0 time

Re: Code from slapshot5

Postby slapshot5 » 20 Apr 2010, 03:57

DennisBergkamp wrote:
Just pm me your email address (I think it has to be associated with a Google account). That's all I need :)
Thanks Dennis. Looking forward to all the fun. :)
slapshot5
Programmer
 
Posts: 1391
Joined: 03 Jan 2010, 17:47
Location: Mac OS X
Has thanked: 25 times
Been thanked: 68 times

Re: Code from slapshot5

Postby DennisBergkamp » 20 Apr 2010, 06:05

Welcome aboard :mrgreen:
User avatar
DennisBergkamp
AI Programmer
 
Posts: 2602
Joined: 09 Sep 2008, 15:46
Has thanked: 0 time
Been thanked: 0 time

Re: Code from slapshot5

Postby Chris H. » 20 Apr 2010, 10:42

slapshot5 wrote:Looking forward to all the fun. :)
`
I see that you have had a busy night at the SVN. :D Good job.
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

Previous

Return to Developer's Corner

Who is online

Users browsing this forum: No registered users and 50 guests

Main Menu

User Menu

Our Partners


Who is online

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

Login Form