It is currently 27 Apr 2024, 17:53
   
Text Size

Mana Pool

Post MTG Forge Related Programming Questions Here

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

Re: Mana Pool

Postby zerker2000 » 30 May 2009, 15:55

Also, since mana burn is at end of phase, the code for my "mana tokens" would have to be tweaked a little, since as is they die at end of turn.
O forest, hold thy wand'ring son
Though fears assail the door.
O foliage, cloak thy ravaged one
In vestments cut for war.


--Eladamri, the Seed of Freyalise
zerker2000
Programmer
 
Posts: 569
Joined: 09 May 2009, 21:40
Location: South Pasadena, CA
Has thanked: 0 time
Been thanked: 0 time

Re: Mana Pool

Postby frwololo » 01 Jun 2009, 07:22

zerker2000 wrote:As for the spells automatically taking mana from the pool, that could be problematic... here, let me make up a story:

Your main phase begins, you only have one life left, {B} {B} in your mana pool, and only one (an untapped Rakdos Carnarium thankfully) land. Though without it you would have surely been toast (when the computer swung out that 57/57 Mycoloth, and later started making tons of 1/1 s with Nemata, Grove Guardian while having a Mycologist out ... who knew a saproling deck could be so powerful in the computer's hands?), your Altar of Shadows has simply been a nuisance lately, bringing you down from 4 to 3 and last turn 1 since that computer Armageddon -ed your 14 lands. However, you did kill off all the serious threats, and now you just need a blocker... you have a Fiery Temper and an Avatar of Discord in hand, so you tap the land, play the avatar, discard your remaining two hards... and notice that forge just played your Avatar for {R} {B} {B}, so you
a) can't deal the 3 damage to stop his Elspeth, Knight-Errant from making his permanents indestructible,
about which you don't care since
b) you're going to die of mana burn. So there you are, dead of a leech-ridden {B} because of a mana pool usability problem.

How was the final chapter of "The Autobiography of Rob Planeswaker"? :P
This is entirely true, although most of the time this is not an issue. You could imagine, though, that the spells automatically get the mana from the manapool, but ask you to select which ones to use if there are several possibilities.
In Wagic the engine just computes one solution to the mana payment problem and goes with it. 99% of the time it does what you expect and I find it good enough.
Note that the rules of Magic say that you have to declare the Spell THEN tap your lands, so the way Forge does it right now is closer to the rules than what we do with Wagic.
frwololo
DEVELOPER
 
Posts: 265
Joined: 21 Jun 2008, 04:33
Has thanked: 0 time
Been thanked: 3 times

Re: Mana Pool

Postby zerker2000 » 01 Jun 2009, 13:53

What?
Magic: The Gathering Comprehensive Rules wrote:The player determines the total cost of the spell or ability. Usually this is just the mana cost (for spells) or activation cost (for abilities). Some cards list additional or alternative costs in their text. Some effects may increase or reduce the cost to pay, or may provide other alternative costs. Costs may include paying mana, tapping permanents, sacrificing permanents, discarding cards, and so on. The total cost is the mana cost, activation cost, or alternative cost (as determined in rule 409.1b), plus all additional costs and cost increases, and minus all cost reductions. If the mana component of the total cost is reduced to nothing by cost reduction effects, it is considered to be {0}. It can't be reduced to less than {0}. Once the total cost is determined, it becomes "locked in." If effects would change the total cost after this time, they have no effect.


409.1g If the total cost includes a mana payment, the player then has a chance to play mana abilities (see rule 411, "Playing Mana Abilities"). Mana abilities must be played before costs are paid.
It sure looks like you could play them anytime during the phase...
O forest, hold thy wand'ring son
Though fears assail the door.
O foliage, cloak thy ravaged one
In vestments cut for war.


--Eladamri, the Seed of Freyalise
zerker2000
Programmer
 
Posts: 569
Joined: 09 May 2009, 21:40
Location: South Pasadena, CA
Has thanked: 0 time
Been thanked: 0 time

Re: Mana Pool

Postby GandoTheBard » 01 Jun 2009, 17:00

You can tap something to produce a mana ability at any time. The confusion often occurs when people try to play a spell and THEN tap for mana, They tap it wrong, they untap, they tap something else. The confusion grows. An alert opponent who is a stickler will make them keep the mana they tapped for without allowing the correction. The thing is when playing on a computer there are unintentional errors that have nothing to do with confusion over cost and everything to do with mechanical failure or UI difficulties which is why it is possible in MTGO for instance to tap for mana then untap (with Alt-U or the right click Undo feature).
visit my personal homepage here: http://outofthebrokensky.com

Listen to my podcast with famed AJ_Impy "Freed from the Real" on http://puremtgo.com
User avatar
GandoTheBard
Tester
 
Posts: 1043
Joined: 06 Sep 2008, 18:43
Has thanked: 0 time
Been thanked: 0 time

Re: Mana Pool

Postby Rob Cashwalker » 01 Jun 2009, 17:06

frowolo wrote:Note that the rules of Magic say that you have to declare the Spell THEN tap your lands
No, you declare the spell then PAY its costs. Paying mana costs actually requires mana in the pool already, and you then specify which mana in the pool you will use to pay it. 409.1g basically allows you the opportunity to play mana abilities to add the required mana, THEN declare how the spell will be payed for. In general players tend to blur the process, and we usually understand that costs are paid for by tapping lands. Following the actual process is critical when mana sources other than mana abilites are used, such as enchantments that just make mana appear in the pool.

Most people I've played with tend to tap lands and then announce the spell. It works with the rules, however it's a "tell" to your opponent, what you may be playing, and he has more opportunity to choose a response.

edit - Gando and I are on the same page
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: Mana Pool

Postby mtgrares » 01 Jun 2009, 17:47

I think these are the steps are are needed to implement a mana pool. The mana pool has 6 mana types: WUBRG and colorless. (I tend to forget this and only remember WUBRG.)

1. add the mana pool to the gui

2. all mouse input is through subclasses of Input. Input doesn't have a method to click on a mana pool so you either have to add a method or abuse clickCard(Card c) and make the card name something like "add mana - G".

3. update Input_Main, Input_StackNotEmpty (and probably a few more) to add mana to the mana pool when the user clicks on a land

4. update Input_PayManaCost and Input_PayManaCostAbility (and possible a few other classes) so that they can accept mana from the mana pool when the user clicks on it

5. implement mana burn somehow

And to make things easier the AI probably wouldn't have or use a mana pool.
mtgrares
DEVELOPER
 
Posts: 1352
Joined: 08 Sep 2008, 22:10
Has thanked: 3 times
Been thanked: 12 times

Re: Mana Pool

Postby zerker2000 » 01 Jun 2009, 23:19

Err snow mana? I still think the easiest way would be to implement mana in the pool as a type of non-targetable token. So:

1.Add it to the interface by adding a third row for mana tokens GUI, similarly to lands (except it should be a lot narrower, with the tokens having {W} {U} {B} {R} {G} {1} for card pictures)

2.While paying for mana, you can click on the token to sacrifice it and pay that part of the cost (and of course since the ability will be something like "Sacrifice <name>: Add <color>", it will go through regular color/snowiness checks: if the token was produced by a snow mana source, it should also have the Snow supertype)

3.Update mana ability interface so that they can be used to make mana tokens when not paying costs (If you are paying a cost anyways, it's obviously easier to just click on the card with the mana ability than to click first on the card and then on the "mana" in the pool ... thought that might be an optional setting for those of us wanting to follow the rules as closely as possible).

4.Update mana abilities to support multi-mana abilities, which should be automatically converted into mana tokens regardless of situation.

5.At the end of each phase, remove all mana tokens. Each token removed this way deals one damage to its controller.
EDIT: Sorry, I'm beginning to sound like oracle-all.txt :oops:, just basically add an end-of-phase check.

As for AI, that is another reason why there should be an option to play single mana sources directly, and leave the tokens on option for AI development.
O forest, hold thy wand'ring son
Though fears assail the door.
O foliage, cloak thy ravaged one
In vestments cut for war.


--Eladamri, the Seed of Freyalise
zerker2000
Programmer
 
Posts: 569
Joined: 09 May 2009, 21:40
Location: South Pasadena, CA
Has thanked: 0 time
Been thanked: 0 time

Re: Mana Pool

Postby frwololo » 02 Jun 2009, 00:32

Ah, thanks for the precisions on the rules, everyone :)
frwololo
DEVELOPER
 
Posts: 265
Joined: 21 Jun 2008, 04:33
Has thanked: 0 time
Been thanked: 3 times

Re: Mana Pool

Postby MageKing17 » 02 Jun 2009, 07:29

Trying to deal with Snow mana (and all mana restrictions having to do with where the mana came from) can be a serious problem. Incantus still doesn't do it right, since the mana pool is just a collection of integers, but we've had plenty of time to think about what would be needed to do it "properly."

Basically, you need to make each point of mana a separate object. If you don't do this, trying to deal with restrictions like "spend this mana only on creature spells" will be a pain in the ass. Once you've made each point of mana a separate object, you need the UI to handle selecting these individual points of mana (and viewing any restrictions/extra characteristics (such as being from a Snow source) on that mana). Now, I'm not exactly a UI expert (read: UIs are hard :P), so I've no clue how to handle that last part. A few of us agree, though, that it would be totally sweet to see little floating orbs of mana hovering over your lands after you tap them, and those orbs coalescing into spells and abilities on the stack. Good luck trying to make something like that, though. :P
User avatar
MageKing17
Programmer
 
Posts: 473
Joined: 12 Jun 2008, 20:40
Has thanked: 5 times
Been thanked: 9 times

Re: Mana Pool

Postby zerker2000 » 02 Jun 2009, 13:50

MageKing17 wrote:Basically, you need to make each point of mana a separate object. If you don't do this, trying to deal with restrictions like "spend this mana only on creature spells" will be a pain in the ass. Once you've made each point of mana a separate object, you need the UI to handle selecting these individual points of mana (and viewing any restrictions/extra characteristics (such as being from a Snow source) on that mana).
Which is the exact advantage as my tokens. However you code "Add <amount>+/&<color>+/&<restrictions on playing it> to your mana pool", It shouldn't be hard to make the ability give you $amount tokens that inherit "Add <color>+/&<restrictions on playing it> to your mana pool" from the original object. Also, about the little orbs of mana, you just gave me an interesting UI idea that belongs in the stacking thread... I'l quote it into here once I post it.
O forest, hold thy wand'ring son
Though fears assail the door.
O foliage, cloak thy ravaged one
In vestments cut for war.


--Eladamri, the Seed of Freyalise
zerker2000
Programmer
 
Posts: 569
Joined: 09 May 2009, 21:40
Location: South Pasadena, CA
Has thanked: 0 time
Been thanked: 0 time

Re: Mana Pool

Postby Rob Cashwalker » 07 Jun 2009, 12:21

I started dabbling in adding a mana pool, but it's causing the game to start with an exception of some sort. I'll post my code anyway, to get some discussion. There's no GUI portion yet, I don't have that skill, this is purely something behind the scenes at the moment.

EDIT:
So, after debugging, I find that CardFactory, Line 14059 (in my copy of 5/17, this is the last line of Meloku, the Clouded Mirror) attempts to create a new Input_PayManaCost. It then bombs on this: "AllZone.Human_ManaPool.getManaPool();".
So obviously, Input_PayManaCost.Input_PayManaCost isn't the right place to put this code....

Created a new class, Pool.java
Code: Select all
public class Pool {
   private String manaPool = new String();
   
   public void addMana(String mana)
   {
      manaPool.concat(mana);
   }
   
   public void remMana(String mana)
   {
      manaPool.replaceFirst(mana, "");
   }
   
   public String getManaPool()
   {
      return manaPool;
   }
   
   public void setManaPool(String mPool)
   {
      manaPool = mPool;
   }
   
   public Pool()
   {
      manaPool = "";
   }
}
Now, it has to be declared somewhere for global access. AllZone.java?
Code: Select all
...
    public final static PlayerZone Computer_Removed   = new DefaultPlayerZone(Constant.Zone.Removed_From_Play, Constant.Player.Computer);

    public static Display Display = new GuiDisplay2();

>>    public static Pool Human_ManaPool = new Pool();
   
    private final static Map<String,PlayerZone> map = new HashMap<String,PlayerZone>();
...
Now, to make use of it in paying costs in Input_PayManaCost.java
Code: Select all
public class Input_PayManaCost extends Input
{
  private static final long serialVersionUID = 3467312982164195091L;

  private final String originalManaCost;
>>  private final String originalManaPool;

  private final Card originalCard;
  private ManaCost manaCost;

  private final ArrayList<Card> tappedLand = new ArrayList<Card>();
  private final SpellAbility spell;

  public Input_PayManaCost(SpellAbility sa)
  {
    originalManaCost = sa.getManaCost();
    originalCard = sa.getSourceCard();
>>    originalManaPool = AllZone.Human_ManaPool.getManaPool();

    spell = sa;
   
    String tMC = sa.getManaCost();
>>    String tMP = originalManaPool;
       
    manaCost = new ManaCost(tMC);
   
>>    for (int i=0; i <= tMP.length(); i++)
>>    {
>>        manaCost.subtractMana(tMP.substring(i, i + 1));
>>               AllZone.Human_ManaPool.remMana(tMP.substring(i, i + 1));
>>    }

  }
  private void resetManaCost()
  {
      manaCost = new ManaCost(originalManaCost);
>>   AllZone.Human_ManaPool.setManaPool(originalManaPool);
  }
...
And finally, a card to make some mana in CardFactory.java
Code: Select all
    if (cardName.equals("Seething Song"))
    {
       final SpellAbility spell = new Spell(card)
       {
          private static final long serialVersionUID = 113811381138L;
          
          public void resolve()
          {
             AllZone.Human_ManaPool.addMana("RRR");
          }
          public boolean canPlayAI()
          {
             return false;
          }
       };
       
        card.clearSpellAbility();
        card.addSpellAbility(spell);

        return card;
    }
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: Mana Pool

Postby DennisBergkamp » 08 Jun 2009, 20:39

Nice :) I quickly skimmed the code (I'll look at it more in depth later), but what was the exception you got after compiling and starting the game?

EDIT: oh I see now, line 14059 doesn't like it...
User avatar
DennisBergkamp
AI Programmer
 
Posts: 2602
Joined: 09 Sep 2008, 15:46
Has thanked: 0 time
Been thanked: 0 time

Re: Mana Pool

Postby Rob Cashwalker » 09 Jun 2009, 01:40

It was "null"... but I'm sure if I threw an exception message in there it could be anything I want....

Yeah, once I figured out how to get into debug mode, I was able to pinpoint the offending call to Input_PayManaCost. Now I understand the flow a little bit more, and that the cards are built completely during startup including any function calls they make. So the Input object gets created a stored away along with the card, until the card becomes useable. It doesn't seem like the Input object gets called each time a mana cost is needing to be paid.

BTW, from what I can tell, the existing ManaPool object isn't actually referenced anywhere in the code. It seems somewhat functional, but I think the string implementation I have is simpler, because the ManaCost.subtractMana method operates on mana characters.
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: Mana Pool

Postby DennisBergkamp » 09 Jun 2009, 02:18

Damn, I feel bad, I could've told you how to use the debugger (to fix some of the MTGForge bugs I pretty much have to, I've become quite good with it actually :) ).
And I think you're right, ManaPool isn't referenced at all. Rares might have been experimenting with that one...

Anyway, my thoughts are kind of stuck on trying to get Auras working, once I've finished that, I'll try and help you with the ManaPool.
User avatar
DennisBergkamp
AI Programmer
 
Posts: 2602
Joined: 09 Sep 2008, 15:46
Has thanked: 0 time
Been thanked: 0 time

Re: Mana Pool

Postby Rob Cashwalker » 09 Jun 2009, 11:49

As a VB programmer, I'm used to just always being in debug mode.... I've occasionally gone into debug mode in Visual C++ with my boss at my shoulder.... And now I realize what had happened the last time I accidentally got into debug mode. It changed the look of the environment, and I didn't notice the buttons on the top right to switch between Java mode and debug mode... so at the time I deleted eclipse and re-installed.

I'm still curious exactly what Java is complaining about. There are a number of references in CardFactory to other members of AllZone, so it doesn't seem to me like it's just not initialized yet. Maybe there's a more appropriate place to declare a global instance of the Pool? There's a PlayerZone and PlayerLife, but no "Player" object.

No rush... I hope mtgrares will pop in with some guidance....
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

PreviousNext

Return to Developer's Corner

Who is online

Users browsing this forum: No registered users and 89 guests


Who is online

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

Login Form