It is currently 09 Sep 2025, 17:28
   
Text Size

screwed over by input again...

Post MTG Forge Related Programming Questions Here

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

screwed over by input again...

Postby slapshot5 » 06 May 2010, 06:01

Everytime I think I start to understand input and abilities better, I run into something that screws me over.

Mana Vault is my latest example. In GameActionUtil, I have an upkeep method to handle this:

"At the beginning of your upkeep, you may pay 4. If you do, untap Mana Vault."

So, the code looks like:

Code: Select all
private static void upkeep_Mana_Vault() {
      //this card is filtered out for the computer, so we will only worry about Human here
      final String player = AllZone.Phase.getActivePlayer();
      CardList vaults = AllZoneUtil.getPlayerCardsInPlay(player, "Mana Vault");
      for(Card vault:vaults) {
         if(vault.isTapped()) {
            final Card thisVault = vault;
            final String[] choices = {"Yes", "No"};
            Object o = AllZone.Display.getChoice("Untap Mana Vault?", choices);
            String choice = (String) o;
            if(choice.equals("Yes")) {
               //prompt for pay mana cost, then untap
               final SpellAbility untap = new Ability(thisVault, "4") {
                  @Override
                  public void resolve() {
                     thisVault.untap();
                  }
               };//Ability
               untap.setStackDescription("Untap "+thisVault);
               untap.setBeforePayMana(new Input_PayManaCost(untap));
               //AllZone.Stack.add(untap);
            }
         }
      }
   }
But, this doesn't get added onto the stack like I expect.

1) in it's current form, no mana cost is prompted to be paid
2) nothing is put on the stack
3) the resolve() is thus, expectedly ignored

If I uncomment the AllZone.Stack.add(untap), then it goes on the stack, but mana is not prompted for.

Obviously, my untap.setBeforePayMana(new Input_PayManaCost(untap)); is doing nothing.

What bonehead thing am I doing wrong?

Thanks,
-slapshot5
slapshot5
Programmer
 
Posts: 1391
Joined: 03 Jan 2010, 17:47
Location: Mac OS X
Has thanked: 25 times
Been thanked: 68 times

Re: screwed over by input again...

Postby DennisBergkamp » 06 May 2010, 16:01

I'm in the same boat, I still get stumped by those annoying inputs sometimes...
But in this case, nothing happens because nothing gets put on the stack... what if you replace the commented line //AllZone.Stack.add(untap) with "AllZone.GameAction.playSpellAbility(untap);" ?
User avatar
DennisBergkamp
AI Programmer
 
Posts: 2602
Joined: 09 Sep 2008, 15:46
Has thanked: 0 time
Been thanked: 0 time

Re: screwed over by input again...

Postby Chris H. » 06 May 2010, 16:15

DennisBergkamp wrote:I'm in the same boat,
`
I think we all get stumped at one point or another. I found an input while working in CardFactory_Auras. I guess that it was either Dennis or Triadasoul who wrote the code for that one aura.

That one input made sense to me. And yet most of the code is still beyond me. :wink:
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: screwed over by input again...

Postby slapshot5 » 06 May 2010, 16:19

DennisBergkamp wrote: what if you replace the commented line //AllZone.Stack.add(untap) with "AllZone.GameAction.playSpellAbility(untap);" ?
Thanks Dennis. That seems to be just what I needed.

-slapshot5
slapshot5
Programmer
 
Posts: 1391
Joined: 03 Jan 2010, 17:47
Location: Mac OS X
Has thanked: 25 times
Been thanked: 68 times

Re: screwed over by input again...

Postby mtgrares » 06 May 2010, 21:42

Input is just really confusing. I tried to make Input simple but it just isn't. I understand it, but of course I wrote it, so I hope I understand it.
mtgrares
DEVELOPER
 
Posts: 1352
Joined: 08 Sep 2008, 22:10
Has thanked: 3 times
Been thanked: 12 times

Re: screwed over by input again...

Postby slapshot5 » 07 May 2010, 02:45

Bad luck streak with input. I'm trying to program Recall.

"Discard X cards, then return a card from your graveyard to your hand for each card discarded this way. Exile Recall."

Seems easy enough since the "X X" mana cost is handled.

But, I tried this:

Code: Select all
//*************** START *********** START **************************
        else if(cardName.equals("Recall")) {

           final SpellAbility spell = new Spell(card) {
              @Override
              public boolean canPlayAI() {
                 return false;
              }

              @Override
              public void resolve() {
                 int numCards = card.getXManaCostPaid();
                 final String player = card.getController();
                 int maxCards = AllZoneUtil.getPlayerHand(player).size();
                 numCards = Math.min(numCards, maxCards);
                 CardList grave = AllZoneUtil.getPlayerGraveyard(card.getController());
                 if(player.equals(Constant.Player.Human)){
                    AllZone.InputControl.setInput(CardFactoryUtil.input_discard(numCards));
                    for(int i = 1; i <= numCards; i++) {
                       String title = "Return card from grave to hand";
                       Object o = AllZone.Display.getChoice(title, grave.toArray());
                       if(o == null) break;
                       Card toHand = (Card) o;
                       grave.remove(toHand);
                       AllZone.GameAction.moveToHand(toHand);
                    }
                 }
                 else { //computer
                    AllZone.GameAction.discardRandom(Constant.Player.Computer, numCards);
                    for(int i = 1; i <= numCards; i ++) {
                       Card t1 = CardFactoryUtil.AI_getBestCreature(grave);
                       if(null != t1) {
                          t1 = grave.get(0);
                          grave.remove(t1);
                          AllZone.GameAction.moveToHand(t1);
                       }
                    }
                 }
                 AllZone.GameAction.removeFromGame(card);
                 System.out.println("Recall: x is: "+card.getXManaCostPaid());
              }//resolve()
           };//SpellAbility

           spell.setStackDescription(card.getName()+" - discard X cards and return X cards to your hand.");
           card.clearSpellAbility();
           card.addSpellAbility(spell);
        }//*************** END ************ END **************************
But, it prompts for input, but doesn't wait for input before popping up the AllZone.Display.getChoice(...) code.

I must be missing something simple. Does input_discard just not wait?

I think my idea is right.

-slapshot5
slapshot5
Programmer
 
Posts: 1391
Joined: 03 Jan 2010, 17:47
Location: Mac OS X
Has thanked: 25 times
Been thanked: 68 times

Re: screwed over by input again...

Postby mtgrares » 07 May 2010, 18:39

input_discard waits kinda. Input_Discard waits in the user interface, not in the code so that is why is just zips through and shows Display.getChoice(). I think you have to create a new Input that discards and in Input.clickCard() put

Code: Select all
                    for(int i = 1; i <= numCards; i++) {
                       String title = "Return card from grave to hand";
                       Object o = AllZone.Display.getChoice(title, grave.toArray());
                       if(o == null) break;
                       Card toHand = (Card) o;
                       grave.remove(toHand);
                       AllZone.GameAction.moveToHand(toHand);
                    }
The only way to do something after an Input, is to create your own Input and have Input call whatever code after the user clicks on a player or clicks on a card.

Although Dennis is probably better at this than I am. :)
mtgrares
DEVELOPER
 
Posts: 1352
Joined: 08 Sep 2008, 22:10
Has thanked: 3 times
Been thanked: 12 times

Re: screwed over by input again...

Postby slapshot5 » 08 May 2010, 06:18

Thanks Rares! I got it working. I feel good about Input gain because I have bent it to my will. :)

-slapshot5
slapshot5
Programmer
 
Posts: 1391
Joined: 03 Jan 2010, 17:47
Location: Mac OS X
Has thanked: 25 times
Been thanked: 68 times

Re: screwed over by input again...

Postby mtgrares » 11 May 2010, 15:31

If it helps, Input is just the State Pattern. So if you read up on it, that might help.

From wikpedia, "This pattern is used in computer programming to represent the state of an object. This is a clean way for an object to partially change its type at runtime."

Input represents the "state" of the mouse and cards/phases change the state.
mtgrares
DEVELOPER
 
Posts: 1352
Joined: 08 Sep 2008, 22:10
Has thanked: 3 times
Been thanked: 12 times


Return to Developer's Corner

Who is online

Users browsing this forum: No registered users and 61 guests

Main Menu

User Menu

Our Partners


Who is online

In total there are 61 users online :: 0 registered, 0 hidden and 61 guests (based on users active over the past 10 minutes)
Most users ever online was 7303 on 15 Jul 2025, 20:46

Users browsing this forum: No registered users and 61 guests

Login Form