Page 1 of 1

Cantrip keyword and milling

PostPosted: 04 Jun 2009, 04:49
by Rob Cashwalker
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....

Re: Cantrip keyword and milling

PostPosted: 04 Jun 2009, 16:56
by DennisBergkamp
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.

Re: Cantrip keyword and milling

PostPosted: 04 Jun 2009, 18:07
by mtgrares
Sounds good. Card.getKeyword() has been very useful since more and more stuff can be added to it.

Re: Cantrip keyword and milling

PostPosted: 04 Jun 2009, 18:09
by Rob Cashwalker
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.

Re: Cantrip keyword and milling

PostPosted: 15 Jun 2009, 10:43
by frwololo
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

Re: Cantrip keyword and milling

PostPosted: 15 Jun 2009, 15:36
by Rob Cashwalker
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.

Re: Cantrip keyword and milling

PostPosted: 20 Jun 2009, 03:15
by Rob Cashwalker
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?

Re: Cantrip keyword and milling

PostPosted: 20 Jun 2009, 03:32
by DennisBergkamp
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.