It is currently 29 Oct 2025, 05:27
   
Text Size

Need help with a Computer Upkeep cost

Post MTG Forge Related Programming Questions Here

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

Need help with a Computer Upkeep cost

Postby jeffwadsworth » 13 Nov 2010, 18:48

Here is some working code (human) for the card Demonic Hordes (located in GameActionUtil). The computer can use it fine except for paying the Upkeep cost. I based this off the Genesis code <Thanks zenchristo>. I just need to know how to get the computer to pay the Upkeep cost. Thanks.

Code: Select all
//upkeep_Demonic_Hordes
   
   private static void upkeep_Demonic_Hordes() {
      
      /*
       * At the beginning of your upkeep, unless you pay BBB,
       * tap Demonic Hordes and sacrifice a land of an opponent's choice.
       */
      
      final Player player = AllZone.Phase.getPlayerTurn();
      final CardList cards = AllZoneUtil.getPlayerCardsInPlay(player, "Demonic Hordes");
      
      for(int i = 0; i < cards.size(); i++) {
         
         final Card c = cards.get(i);
         
         final Ability noPay = new Ability(c, "B B B") {
            private static final long serialVersionUID = 4820011390853920644L;
            @Override
               public void resolve() {
                  PlayerZone play = AllZone.getZone(Constant.Zone.Play, player);
                  PlayerZone graveyard = AllZone.getZone(Constant.Zone.Graveyard, player);
                  CardList playerLand = AllZoneUtil.getPlayerLandsInPlay(player);
                  
                  if((c.getController().equals(AllZone.ComputerPlayer)) && (playerLand.size() > 0)) {
                     AllZone.InputControl.setInput(CardFactoryUtil.input_sacrificePermanent(playerLand, c.getName()+" - Select a land to sacrifice."));
                     play.remove(playerLand);
                     graveyard.add(playerLand);
                     c.tap();
                  }
                  else {
                     if((c.getController().equals(AllZone.ComputerPlayer)) && (playerLand.size() == 0)) {
                        c.tap();
                     }
                  }
                  if((c.getController().equals(AllZone.HumanPlayer)) && (playerLand.size() > 0)) {
                        Card target = CardFactoryUtil.AI_getBestLand(playerLand);
                        play.remove(target);
                        graveyard.add(target);
                        c.tap();
                     }
                  else {
                     if((c.getController().equals(AllZone.HumanPlayer)) && (playerLand.size() == 0)) {
                        c.tap();
                     }
                  }
               } //end resolve()
         }; //end noPay ability
         
         if(c.getController().equals(AllZone.HumanPlayer)) {
            String[] choices = {"Yes", "No"};
            Object choice = AllZone.Display.getChoice("Pay Demonic Hordes upkeep cost?", choices);
            if(choice.equals("Yes")) {
               final Ability pay = new Ability(c, "0") {
                  private static final long serialVersionUID = 4820011440853920644L;
                  public void resolve() {
                     if (AllZone.getZone(c).is(Constant.Zone.Play)) {
                        GameActionUtil.payManaDuringAbilityResolve("Pay cost for " + c + "\r\n", noPay.getManaCost(), Command.Blank, Command.Blank);
                     }
                  } //end resolve()
               }; //end pay ability
               pay.setStackDescription("Demonic Hordes - Upkeep Cost");
               AllZone.Stack.add(pay);
            } //end choice
            else {
               StringBuilder sb = new StringBuilder();
               sb.append(c.getName()).append(" - is tapped and you must sacrifice a land of opponent's choice");
               noPay.setStackDescription(sb.toString());
               AllZone.Stack.add(noPay);
            }
         } //end human
         else { //computer
            if((c.getController().equals(AllZone.ComputerPlayer) && (ComputerUtil.canPayCost(noPay)))) {
               final Ability computerPay = new Ability(c, "0") {
                  private static final long serialVersionUID = 4820011440852868644L;
                  public void resolve() {
                     ComputerUtil.payManaCost(noPay);
                  }
               };
               computerPay.setStackDescription("Computer pays Demonic Hordes upkeep cost");
               AllZone.Stack.add(computerPay);
            }
            else {
               AllZone.Stack.add(noPay);
            }
         } //end computer
         
      } //end for loop
         
   } //end Demonic Hordes Upkeep method
Here is the Demonic Hordes card itself.

Code: Select all
Name:Demonic Hordes
ManaCost:3 B B B
Types:Creature Demon
Text:At the beginning of your upkeep, unless you pay BBB, tap Demonic Hordes and sacrifice a land of an opponent's choice.
PT:5/5
A:AB$Destroy|ValidTgts$Land|TgtPrompt$Select target land.|Cost$T|SpellDescription$Destroy target land.
SVar:PlayMain1:FALSE
SVar:Rarity:Rare
SVar:Picture:http://www.wizards.com/global/images/magic/general/demonic_hordes.jpg
End

Last edited by jeffwadsworth on 17 Nov 2010, 09:37, edited 6 times in total.
jeffwadsworth
Super Tester Elite
 
Posts: 1172
Joined: 20 Oct 2010, 04:47
Location: USA
Has thanked: 287 times
Been thanked: 70 times

Re: Need help with a Computer Upkeep cost

Postby Sloth » 13 Nov 2010, 21:06

I would try using an empty ability with a cost of "B B B" called just after this block, starting with else:

Code: Select all
} else
            if(!(ComputerUtil.canPayCost(noPay))) { //computer can not pay
               StringBuilder sb = new StringBuilder();
               sb.append(c.getName()).append(" - Computer loses a land of your choice");
               noPay.setStackDescription(sb.toString());
               AllZone.Stack.add(noPay);
            }
And please try to use the exact oracle wording found in gatherer for the abilities and the type.
User avatar
Sloth
Programmer
 
Posts: 3498
Joined: 23 Jun 2009, 19:40
Has thanked: 125 times
Been thanked: 507 times

Re: Need help with a Computer Upkeep cost

Postby jeffwadsworth » 13 Nov 2010, 23:38

Sloth wrote:I would try using an empty ability with a cost of "B B B" called just after this block, starting with else:

Code: Select all
} else
            if(!(ComputerUtil.canPayCost(noPay))) { //computer can not pay
               StringBuilder sb = new StringBuilder();
               sb.append(c.getName()).append(" - Computer loses a land of your choice");
               noPay.setStackDescription(sb.toString());
               AllZone.Stack.add(noPay);
            }
And please try to use the exact oracle wording found in gatherer for the abilities and the type.
Thanks for the help. I just wanted to make sure there wasn't a simpler method. Oracle text fixed. :)
jeffwadsworth
Super Tester Elite
 
Posts: 1172
Joined: 20 Oct 2010, 04:47
Location: USA
Has thanked: 287 times
Been thanked: 70 times

Re: Need help with a Computer Upkeep cost

Postby jeffwadsworth » 14 Nov 2010, 17:55

Ahh. ComputerUtil.payManaCost(ability); was the simple method I was looking for. Thanks.
jeffwadsworth
Super Tester Elite
 
Posts: 1172
Joined: 20 Oct 2010, 04:47
Location: USA
Has thanked: 287 times
Been thanked: 70 times

Re: Need help with a Computer Upkeep cost

Postby friarsol » 14 Nov 2010, 18:16

Oh yea. Gotta check if they can pay it, and then have them pay it. I just missed adding it back in when I was refactoring Genesis.
friarsol
Global Moderator
 
Posts: 7593
Joined: 15 May 2010, 04:20
Has thanked: 243 times
Been thanked: 965 times

Re: Need help with a Computer Upkeep cost

Postby Chris H. » 17 Nov 2010, 18:48

Thank you for submitting Demonic Hordes.

Google's SVN can sometimes have problems. I sometimes have to wait for awhile and later that day I will find that I can once again access the SVN.
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: Need help with a Computer Upkeep cost

Postby jeffwadsworth » 17 Nov 2010, 22:36

Actually, I think it may have been my screw-up. I had Subclipse installed but not Subversion. It allowed me to post the new card.txt but it balked at me committing to an existing file. No error popped up but it obviously wasn't working. Anyway, both are now configured and everything looks good. Thanks for your "How to get Started" postings. That really helped.
jeffwadsworth
Super Tester Elite
 
Posts: 1172
Joined: 20 Oct 2010, 04:47
Location: USA
Has thanked: 287 times
Been thanked: 70 times

Re: Need help with a Computer Upkeep cost

Postby Chris H. » 17 Nov 2010, 22:53

jeffwadsworth wrote:Actually, I think it may have been my screw-up. I had Subclipse installed but not Subversion. It allowed me to post the new card.txt but it balked at me committing to an existing file. No error popped up but it obviously wasn't working. Anyway, both are now configured and everything looks good. Thanks for your "How to get Started" postings. That really helped.
`
Yeah, you need all three pieces. Subclipse and Subversion should be matched with one another. Once you get everything working the only challenge left is to make sure that you resolve conflicts. :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


Return to Developer's Corner

Who is online

Users browsing this forum: No registered users and 10 guests

Main Menu

User Menu

Our Partners


Who is online

In total there are 10 users online :: 0 registered, 0 hidden and 10 guests (based on users active over the past 10 minutes)
Most users ever online was 9298 on 10 Oct 2025, 12:54

Users browsing this forum: No registered users and 10 guests

Login Form