Page 1 of 1

Need help with a Computer Upkeep cost

PostPosted: 13 Nov 2010, 18:48
by jeffwadsworth
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


Re: Need help with a Computer Upkeep cost

PostPosted: 13 Nov 2010, 21:06
by Sloth
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.

Re: Need help with a Computer Upkeep cost

PostPosted: 13 Nov 2010, 23:38
by jeffwadsworth
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. :)

Re: Need help with a Computer Upkeep cost

PostPosted: 14 Nov 2010, 17:55
by jeffwadsworth
Ahh. ComputerUtil.payManaCost(ability); was the simple method I was looking for. Thanks.

Re: Need help with a Computer Upkeep cost

PostPosted: 14 Nov 2010, 18:16
by friarsol
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.

Re: Need help with a Computer Upkeep cost

PostPosted: 17 Nov 2010, 18:48
by Chris H.
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.

Re: Need help with a Computer Upkeep cost

PostPosted: 17 Nov 2010, 22:36
by jeffwadsworth
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.

Re: Need help with a Computer Upkeep cost

PostPosted: 17 Nov 2010, 22:53
by Chris H.
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