It is currently 26 Apr 2024, 20:03
   
Text Size

Cantrip keyword and milling

Post MTG Forge Related Programming Questions Here

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

Cantrip keyword and milling

Postby Rob Cashwalker » 04 Jun 2009, 04:49

First post in the new forum! =D>

I thought I had once posted some code that might allow cantrips to be handled as a keyword. (Cantrips are spells or permanents, which also draw a card on resolution, such as Accelrate or Carven Caryatid)

I figured out where in the code any given SpellAbility's Resolve method is called.
Code: Select all
 C:\MTGForge0517\source\ComputerUtil.java (1 hits)
   Line 61:       sa.resolve();
  C:\MTGForge0517\source\Input_StackNotEmpty.java (1 hits)
   Line 31:     sa.resolve();
On the following lines for both, place the following code:
Code: Select all
If (sa.getSourceCard().getKeywords().Contains("Cantrip"))
  GameAction.drawCard(sa.getSourceCard().getController());
Meanwhile, permanents would need a comesIntoPlayCommand generated by a keyword script that should look something like this:
Code: Select all
    if(card.getKeyword().contains("When this card comes into play, draw a card."))
    {
      card.setComesIntoPlay(new Command()
      {
      private static final long serialVersionUID = 203335252453049234L;

      public void execute()
        {
          GameAction.drawCard(card.getController());
        }
      });
    }//if "Comes into play tapped."
Speaking of GameAction.drawCard(), I think this code should make milling a loss condition:
Code: Select all
if(library.size() != 0)
    {
     
      Card c = library.get(0);
      library.remove(0);
      hand.add(c);
     
      GameActionUtil.executeDrawCardTriggeredEffects(player);
    }
   else
   {
     PlayerLife life = AllZone.GameAction.getPlayerLife(player);
     life.setLife(0);
   }
Stole the setLife concept from Battle of Wits....
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: Cantrip keyword and milling

Postby DennisBergkamp » 04 Jun 2009, 16:56

Cool stuff, Rob :)

I'll add the cantrip (and comes into play) code to the next version. I'll hold off on the milling part (I've done something similar in GameActionUtil by the way - and I also stole the setLife(0) part from Battle of Wits ;) ), but I never really liked this enabled because it makes testing cards so difficult ( I like to test cards by creating decks that consist of 7 - 8 cards). But I'll add some button in the GUI somewhere that could enable and disable milling as a win/loss condition.
User avatar
DennisBergkamp
AI Programmer
 
Posts: 2602
Joined: 09 Sep 2008, 15:46
Has thanked: 0 time
Been thanked: 0 time

Re: Cantrip keyword and milling

Postby mtgrares » 04 Jun 2009, 18:07

Sounds good. Card.getKeyword() has been very useful since more and more stuff can be added to it.
mtgrares
DEVELOPER
 
Posts: 1352
Joined: 08 Sep 2008, 22:10
Has thanked: 3 times
Been thanked: 12 times

Re: Cantrip keyword and milling

Postby Rob Cashwalker » 04 Jun 2009, 18:09

DennisBergkamp wrote:Cool stuff, Rob :)

I'll add the cantrip (and comes into play) code to the next version. I'll hold off on the milling part (I've done something similar in GameActionUtil by the way - and I also stole the setLife(0) part from Battle of Wits ;) ), but I never really liked this enabled because it makes testing cards so difficult ( I like to test cards by creating decks that consist of 7 - 8 cards). But I'll add some button in the GUI somewhere that could enable and disable milling as a win/loss condition.
I'd suggest making the enable/disable similar to how the quest decks can be edited - the presence or lack of a file. It's the sort of thing that 99% of the time should be enabled.... I usually make test decks a full 40 cards... but 8 or 10 copies of the card to be tested.
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: Cantrip keyword and milling

Postby frwololo » 15 Jun 2009, 10:43

Rob Cashwalker wrote:
Code: Select all
    if(card.getKeyword().contains("When this card comes into play, draw a card."))
    {
     
      card.setComesIntoPlay(new Command()
      {
      private static final long serialVersionUID = 203335252453049234L;

      public void execute()
        {
          GameAction.drawCard(card.getController());
        }
      });
    }//if "Comes into play tapped."
I have forgotten Java, but this could probably be improved to draw as many cards as you want, with the following (sorry, pseudo code):
Code: Select all
    if(card.getKeyword().contains("When this card comes into play, draw:"))
    {
      Integer nbCards = card.getKeyword().everythingAfter(":").toInteger;
      card.setComesIntoPlay(new Command()
      {
      private static final long serialVersionUID = 203335252453049234L;

      public void execute()
        {
          for (i=1 to nbCards) {
              GameAction.drawCard(card.getController());
          }
        }
      });
    }//if "Comes into play tapped."
Then you could call : When this card comes into play, draw:3 for example
frwololo
DEVELOPER
 
Posts: 265
Joined: 21 Jun 2008, 04:33
Has thanked: 0 time
Been thanked: 3 times

Re: Cantrip keyword and milling

Postby Rob Cashwalker » 15 Jun 2009, 15:36

There are currently only two cards that draw more than 1 card when they come into play - Flight of Fancy and Mulldrifter.
Not that this should prevent us from allowing the keyword form you're suggesting... just that it's not needed... yet.
No doubt though, that there will be a spDrawCards:# keyword for spells that specifically just 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: Cantrip keyword and milling

Postby Rob Cashwalker » 20 Jun 2009, 03:15

Dennis-

I see the Cantrip check was added. But the comes into play draw ability wasn't. Oversight or didn't work? Did Cantrip work as expected?
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: Cantrip keyword and milling

Postby DennisBergkamp » 20 Jun 2009, 03:32

Oh, haven't tested either actually. I guess I must've forgotten to add in the Comes into play cantrip... I'll try to add it in next.
User avatar
DennisBergkamp
AI Programmer
 
Posts: 2602
Joined: 09 Sep 2008, 15:46
Has thanked: 0 time
Been thanked: 0 time


Return to Developer's Corner

Who is online

Users browsing this forum: No registered users and 86 guests


Who is online

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

Login Form