It is currently 26 Apr 2024, 21:35
   
Text Size

spDrawCards v2

Post MTG Forge Related Programming Questions Here

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

spDrawCards v2

Postby Rob Cashwalker » 31 Oct 2009, 15:14

Basically a revision of existing spDrawCards keyword that takes the same advanced syntax as the recent spDamageTgt keyword.

CardFactory.java
Code: Select all
    if (shouldSpDrawCards(card) != -1)
    {
       int n = shouldSpDrawCards(card);
       String parse = card.getKeyword().get(n).toString();
        card.removeIntrinsicKeyword(parse);
       
        String k[] = parse.split(":");
       
        final boolean Tgt[] = {false};
        Tgt[0] = k[0].contains("Tgt");
       
        final int NumCards[] = {-1};
        final String NumCardsX[] = {"none"};

        if (k[1].length() <= 2)
           NumCards[0] = Integer.parseInt(k[1]);
        else
        {
           if (k[1].startsWith("Count$"))
           {             
             String kk[] = k[1].split("\\$");
              NumCardsX[0] = kk[1];
           }
        }
       
        // drawbacks and descriptions
        final String DrawBack[] = {"none"};
        final String spDesc[] = {"none"};
        final String stDesc[] = {"none"};
        if (k.length > 2)
        {
           if (k[2].contains("Drawback$"))
           {
              String kk[] = k[2].split("\\$");
              DrawBack[0] = kk[1];
              if (k.length > 3)
                 spDesc[0] = k[3];
              if (k.length > 4)
                 stDesc[0] = k[4];
           }
           else
           {
              if (k.length > 2)
                 spDesc[0] = k[2];
              if (k.length > 3)
                 stDesc[0] = k[3];
           }
        }
       
        final SpellAbility spDraw = new Spell(card)
        {
           private static final long serialVersionUID = -7049779241008089696L;

           private int ncards;
           
           public int getNumCards()
           {
              if (NumCards[0] != -1)
                 return NumCards[0];

              if (! NumCardsX[0].equals("none"))
                 return CardFactoryUtil.xCount(card, NumCardsX[0]);
             
              return 0;
           }

           public boolean canPlayAI()
           {
              ncards = getNumCards();
              int h = AllZone.getZone(Constant.Zone.Hand, Constant.Player.Computer).size();
              int hl = AllZone.getZone(Constant.Zone.Library, Constant.Player.Human).size();
              int cl = AllZone.getZone(Constant.Zone.Library, Constant.Player.Computer).size();
              Random r = new Random();

              if (((hl - ncards) < 2) && Tgt[0])
              {
                 setTargetPlayer(Constant.Player.Computer);
                 return true;
              }
             
              if (((h + ncards) <= 7) && !((cl - ncards) < 1) && (r.nextInt(10) > 4))
              {
                 setTargetPlayer(Constant.Player.Computer);
                 return true;
              }
             
              return false;
           }

           public void resolve()
           {
              ncards = getNumCards();

              String TgtPlayer = card.getController();
              if (Tgt[0])
                 TgtPlayer = getTargetPlayer();

              for (int i=0; i < ncards; i++)
                 AllZone.GameAction.drawCard(TgtPlayer);

              if (! DrawBack[0].equals("none"))
                 CardFactoryUtil.doDrawBack(DrawBack[0], ncards, card.getController(), AllZone.GameAction.getOpponent(card.getController()), TgtPlayer, card, null);
           }
        };

        if (Tgt[0])
           spDraw.setBeforePayMana(CardFactoryUtil.input_targetPlayer(spDraw));

        if (! spDesc[0].equals("none"))
           spDraw.setDescription(spDesc[0]);
        else
           spDraw.setDescription("Draw " + NumCards[0] + " cards.");
       
        if (! stDesc[0].equals("none"))
           spDraw.setStackDescription(stDesc[0]);
        else
           spDraw.setStackDescription("You draw " + NumCards[0] + " cards.");
       
        card.clearSpellAbility();
        card.addSpellAbility(spDraw);
    }//spDrawCards
Existing cards that are hardcoded in CardFactory:
Code: Select all
Night's Whisper
1 B
Sorcery
no text
spDrawCards:2:Drawback$YouLoseLife/2:You draw two cards and you lose 2 life.:Night's Whisper - draw 2 cards and lose 2 life.


Words of Wisdom
1 U
Instant
no text
spDrawCards:2:Drawback$OppDraw/1:You draw two cards, then each other player draws a card.:Words of Wisdom - draw 2 cards and opponent draws 1 card.


Counsel of the Soratami
2 U
Sorcery
no text
spDrawCards:2:Draw two cards.:Counsel of the Soratami - draw 2 cards.


Touch of Brilliance
3 U
Sorcery
no text
spDrawCards:2:Draw two cards.:Touch of Brilliance - draw 2 cards.


Inspiration
3 U
Sorcery
no text
spDrawCards:2:Draw two cards.:Inspiration - draw 2 cards.


Concentrate
2 U U
Sorcery
no text
spDrawCards:3:Draw three cards.:Concentrate - draw 3 cards.


Harmonize
2 G G
Sorcery
no text
spDrawCards:3:Draw three cards.:Harmonize - draw 3 cards.


Ancestral Recall
U
Instant
no text
spDrawCardsTgt:3:Target player draws three cards.:Ancestral Recall - draw 3 cards.


Minions' Murmurs
2 B B
Sorcery
no text
spDrawCards:Count$TypeYouCtrl.Creature:Drawback$YouLoseLife/X:You draw X cards and you lose X life, where X is the number of creatures you control.:Minion's Murmurs - draw cards and lose life.


Brainstorm
U
Instant
no text
spDrawCards:3:Drawback$YouHandToLibrary/2/Top:Draw three cards, then put two cards from your hand on top of your library in any order.:Brainstorm - draw 3 cards and put 2 on top of your library.
A few of the new cards:
Code: Select all
Airborne Aid
3 U
Sorcery
no text
spDrawCards:Count$TypeOnBattlefield.Bird:Draw a card for each Bird on the battlefield.:Airborne Aid - draw cards.


Borrowing 100,000 Arrows
2 U
Sorcery
no text
spDrawCards:Count$TappedTypeOppCtrl.Creature:Draw a card for each tapped creature target opponent controls.:Borrowing 100,000 Arrows - draw cards.


Collective Unconscious
4 G G
Sorcery
no text
spDrawCards:Count$TypeYouCtrl.Creature:Draw a card for each creature you control.:Collective Unconscious - draw cards.
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: spDrawCards v2

Postby Sloth » 31 Oct 2009, 22:14

If I understand correctly and the keyword now allows all drawback and count parameters as spDamageTgt, the following cards are now possible:

cards.txt:
Code: Select all
Borrowing 100,000 Arrows
2 U
Sorcery
no text
spDrawCards:Count$TypeOppCtrlTapped.Creature:Draw a card for each tapped creature target opponent controls.:Borrowing 100,000 Arrows - Draw cards.

Cruel Bargain
B B B
Sorcery
no text
spDrawCards:4:Drawback$LoseLifeYou/Count$YourLifeTotal/HalfUp:Draw four cards.:You lose half your life, rounded up.:Cruel Bargain - Draw cards and lose half your life, rounded up.

Infernal Contract
B B B
Sorcery
no text
spDrawCards:4:Drawback$LoseLifeYou/Count$YourLifeTotal/HalfUp:Draw four cards.:You lose half your life, rounded up.:Infernal Contract - Draw cards and lose half your life, rounded up.

Nature's Resurgence
2 G G
Sorcery
no text
spDrawCards:Count$TypeInYourYard.Creature:Drawback$DrawOpp/Count$TypeInOppYard.Creature:Each player draws a card for each creature card in his or her graveyard.:Nature's Resurgence - Draw cards.

Theft of Dreams
2 U
Sorcery
no text
spDrawCards:Count$TypeOppCtrlTapped.Creature:Draw a card for each tapped creature target opponent controls.:Theft of Dreams - Draw cards.
card-pictures.txt:
Code: Select all
borrowing_100000_arrows.jpg         http://www.wizards.com/global/images/magic/general/borrowing_100000_arrows.jpg
cruel_bargain.jpg            http://resources.wizards.com/magic/cards/po/en-us/card4214.jpg
infernal_contract.jpg            http://www.wizards.com/global/images/magic/general/infernal_contract.jpg
natures_resurgence.jpg         http://www.wizards.com/global/images/magic/general/natures_resurgence.jpg
theft_of_dreams.jpg                 http://www.wizards.com/global/images/magic/general/theft_of_dreams.jpg
Another card I thought about, but which probably has some issues is:
Code: Select all
Balance of Power
3 U U
Sorcery
no text
spDrawCards:Count$InYourHand/Minus.Count$InOppHand:If target opponent has more cards in hand than you, draw cards equal to the difference.
The question is: What happens if you have more cards in hand than your opponent?
User avatar
Sloth
Programmer
 
Posts: 3498
Joined: 23 Jun 2009, 19:40
Has thanked: 125 times
Been thanked: 507 times

Re: spDrawCards v2

Postby Rob Cashwalker » 01 Nov 2009, 02:41

The Count$ can only be used for the primary effect number. Like the number of cards drawn. I hadn't thought to put it in the Drawback$ handler or to compound it in one Count$.
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: spDrawCards v2

Postby Sloth » 01 Nov 2009, 13:30

So I guess only these 4 are possible at the moment:

cards.txt:
Code: Select all
Borrowing 100,000 Arrows
2 U
Sorcery
no text
spDrawCards:Count$TypeOppCtrlTapped.Creature:Draw a card for each tapped creature target opponent controls.:Borrowing 100,000 Arrows - Draw cards.

Cruel Bargain
B B B
Sorcery
no text
spDrawCards:4:Drawback$LoseLifeYou/Count$YourLifeTotal/HalfUp:Draw four cards.:You lose half your life, rounded up.:Cruel Bargain - Draw cards and lose half your life, rounded up.

Infernal Contract
B B B
Sorcery
no text
spDrawCards:4:Drawback$LoseLifeYou/Count$YourLifeTotal/HalfUp:Draw four cards.:You lose half your life, rounded up.:Infernal Contract - Draw cards and lose half your life, rounded up.

Theft of Dreams
2 U
Sorcery
no text
spDrawCards:Count$TypeOppCtrlTapped.Creature:Draw a card for each tapped creature target opponent controls.:Theft of Dreams - Draw cards.
card-pictures.txt:
Code: Select all
borrowing_100000_arrows.jpg         http://www.wizards.com/global/images/magic/general/borrowing_100000_arrows.jpg
cruel_bargain.jpg            http://resources.wizards.com/magic/cards/po/en-us/card4214.jpg
infernal_contract.jpg            http://www.wizards.com/global/images/magic/general/infernal_contract.jpg
theft_of_dreams.jpg                 http://www.wizards.com/global/images/magic/general/theft_of_dreams.jpg
User avatar
Sloth
Programmer
 
Posts: 3498
Joined: 23 Jun 2009, 19:40
Has thanked: 125 times
Been thanked: 507 times

Re: spDrawCards v2

Postby Rob Cashwalker » 02 Nov 2009, 04:31

Actually, just the Arrows and Theft of Dreams.

The drawbacks on Draw Card spells were the basis of the entire Drawback$ system... likewise the variations on counting were the basis of the Count$ system. Since I'm going over the old keywords while I'm at it....

BTW, I started this update from the 10/07 code base, before Dennis and the others got the SVN figured out. I'll work from there from now on. But still post about the details.
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: spDrawCards v2

Postby DennisBergkamp » 02 Nov 2009, 05:21

Ah, so Cruel Bargain and Infernal Contract currently do not work, and should be taken out of the latest Beta?
User avatar
DennisBergkamp
AI Programmer
 
Posts: 2602
Joined: 09 Sep 2008, 15:46
Has thanked: 0 time
Been thanked: 0 time

Re: spDrawCards v2

Postby Chris H. » 05 Nov 2009, 01:46

I found 22 cards which used the first version of the spDrawCards keyword. After some testing I realized that these cards should be converted over to the newest version. This data should be merged into the cards.txt file for the next release.

Code: Select all
Airborne Aid
3 U
Sorcery
no text
spDrawCards:Count$TypeOnBattlefield.Bird:Draw a card for each Bird on the battlefield.:Airborne Aid - draw cards.

Ambition's Cost
3 B
Sorcery
no text
spDrawCards:3:Drawback$YouLoseLife/3:You draw three cards and you lose 3 life.:Ambition's Cost - draw 3 cards and lose 3 life.

Ancient Craving
3 B
Sorcery
no text
spDrawCards:3:Drawback$YouLoseLife/3:You draw three cards and you lose 3 life.:Ancient Craving - draw 3 cards and lose 3 life.

Biomantic Mastery
4 UG UG UG
Sorcery
no text
spDrawCards:Count$TypeOnBattlefield.Creature:Draw a card for each creature target player controls, then draw a card for each creature another target player controls.:Biomantic Mastery - Draw cards.

Brilliant Plan
4 U
Sorcery
no text
spDrawCards:3:Draw three cards.:Brilliant Plan - Draw 3 cards.

Careful Study
U
Sorcery
no text
spDrawCards:2:Drawback$YouDiscard/2:Draw two cards, then discard two cards.:Careful Study - Draw 2 cards, then discard 2 cards.

Catalog
2 U
Instant
no text
spDrawCards:2:Drawback$YouDiscard/1:Draw two cards, then discard a card.:Catalog - Draw 2 cards, then discard 1 card.

Collective Unconscious
4 G G
Sorcery
no text
spDrawCards:Count$TypeYouCtrl.Creature:Draw a card for each creature you control.:Collective Unconscious - draw cards.

Compulsive Research
2 U
Sorcery
no text
spDrawCardsTgt:3:Drawback$TgtDiscard/2/UnlessDiscardType.Land:Target player draws three cards. Then that player discards two cards unless he or she discards a land card.:Compulsive Research - draw 3 cards, then discards 2 unless discards a land.

Control of the Court
1 R
Sorcery
no text
spDrawCards:4:Drawback$YouDiscard/3/AtRandom:Draw four cards, then discard three cards at random.:Control of the Court - Draw 4 cards, then discard 3 at random.

Divination
2 U
Sorcery
no text
spDrawCards:2:Draw two cards.:Divination - Draw 2 cards.

Dream Cache
2 U
Sorcery
no text
spDrawCards:3:Drawback$YouHandToLibrary/2/TopOrBottom:Draw three cards, then put two cards from your hand both on top of your library or both on the bottom of your library.:Dream Cache - Draw 3 cards, then put 2 back.

Flow of Ideas
5 U
Sorcery
no text
spDrawCards:Count$TypeYouCtrl.Island:Draw a card for each Island you control.:Flow of Ideas - draw cards.

Goblin Lore
1 R
Sorcery
no text
spDrawCards:4:Drawback$YouDiscard/3/AtRandom:Draw four cards, then discard three cards at random.:Goblin Lore - Draw 4 cards, then discard 3 at random.

Opportunity
4 U U
Instant
no text
spDrawCardsTgt:4:Target player draws four cards.:Opportunity - Target player draws 4 cards.

Ribbons of the Reikai
4 U
Sorcery Arcane
no text
spDrawCards:Count$TypeYouCtrl.Spirit:Draw a card for each Spirit you control.:Ribbons of the Reikai - draw cards.

Sift
3 U
Sorcery
no text
spDrawCards:3:Drawback$YouDiscard/1:Draw three cards, then discard a card.:Sift - Draw 3 cards, then discard 1 card.

Sign in Blood
B B
Sorcery
no text
spDrawCardsTgt:2:Drawback$LoseLifeTgt/2:Target player draws two cards and loses 2 life.:Sign in Blood - Target player draws 2 cards and loses 2 life.

Thirst for Knowledge
2 U
Instant
no text
spDrawCards:3:Drawback$YouDiscard/2/UnlessDiscardType.Artifact:Draw three cards. Then discard two cards unless you discard an artifact card.:Thirst for Knowledge - Draw 3 cards, then discard 2 cards unless you discard an artifact.

Tidings
3 U U
Sorcery
no text
spDrawCards:4:Draw four cards.:Tidings - Draw 4 cards.

Vision Skeins
1 U
Instant
no text
spDrawCards:2:Drawback$OppDraw/2:Each player draws two cards.:Both players draws 2 cards.

Wistful Thinking
2 U
Sorcery
no text
spDrawCardsTgt:2:Drawback$TgtDiscard/4:Target player draws two cards, then discards four cards.:Wistful Thinking - Target player draws 2 cards, then discards 4 cards.
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: spDrawCards v2

Postby Rob Cashwalker » 24 Nov 2009, 03:15

FYI:

My next update will be for the Pump Abilities. I will be including support for the Drawback number to include a Count$ function. HOWEVER the delimiter will be "," (comma) ONLY for the Count$ in Drawback$. (Actually, I just replace the comma with slash before passing it to the xCount method, but for string parsing reasons, it needs to be different)
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


Return to Developer's Corner

Who is online

Users browsing this forum: No registered users and 102 guests


Who is online

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

Login Form