Restricted use mana
Post MTG Forge Related Programming Questions Here
Moderators: timmermac, Blacksmith, KrazyTheFox, Agetian, friarsol, CCGHQ Admins
Re: Restricted use mana
by FabioFLX » 17 May 2012, 15:20
Yew, ManaPool has an ArrayList of Mana but the program often uses a String representation of the cost.ArsenalNut wrote:I am confused. The ManaPool already keeps an ArrayList of Mana objects i.e. floatingMana. ManaPool is the only class that creates Mana objects and all of the methods in Manapool add and remove Mana objects without creating new ones. It's not clear to me how your objects are losing their restrictions.
It would really help if you could share out the code base you're using. Is there something preventing you from posting a patch or checking it into a branch?
What I'm saying is that this should be avoided in favor of a Mana ArrayList for every mana recipient.
In a specific case, when A.I. uses ComputerUtil class to test for its SpellAbility's to be castable checking its mana cost, it substracts the Mana from the player.manapool instance.
This is ok but, when the test is over, ComputerUtil rollbacks this mana recreating the pool, and so each Mana loses any previous restricion.
I'd like to check my code into a branch but I still haven't exactly understood how to

Re: Restricted use mana
by ArsenalNut » 17 May 2012, 16:01
The exact Mana objects are stored with the ability that the player is trying to pay for. The refund methods move the objects from the list held in the spellAbility back to the floating mana array without making any copies. We can argue about which object the list of mana paid should be associated but the list does currently exist.Max mtg wrote:I agree. Moreover, ManaCost (which tracks the payment) should hold the mana items spent to pay it - so that they could be released into manapool intact.
I believe this is the most likely source of your bug. None of the existing methods in the ManaPool ever made copies so the original Mana objects were left intact and just added and removed to various ArrayLists.FabioFLX wrote:At the moment, I'm using a copy() method I added to the ManaPool class that, in my opinion, could simplify handling of rollbacks.
So many cards, so little time
-
ArsenalNut - Posts: 512
- Joined: 08 Jul 2011, 03:49
- Has thanked: 27 times
- Been thanked: 121 times
Re: Restricted use mana
by ArsenalNut » 17 May 2012, 16:03
How about making a patch? Do you know how to do that?FabioFLX wrote:I'd like to check my code into a branch but I still haven't exactly understood how to
So many cards, so little time
-
ArsenalNut - Posts: 512
- Joined: 08 Jul 2011, 03:49
- Has thanked: 27 times
- Been thanked: 121 times
Re: Restricted use mana
by FabioFLX » 17 May 2012, 16:50
No ArsenalNut, this is not where the bug comes from, indeed I added the copy() method to avoid the loss of restrictions bug.ArsenalNut wrote:I believe this is the most likely source of your bug. None of the existing methods in the ManaPool ever made copies so the original Mana objects were left intact and just added and removed to various ArrayLists.
Anyway I'm rewriting my code because it is my first try in developing for Forge and so it is all but standard... A patch with my code as-it-is-now may result in making things worse than now for following modifications.
New code is really pretty and it avoids rubbish in touched classes.
By the way it's time to stop developing for today. I think a patch with working restrictions to be ready for tomorrow.
Re: Restricted use mana
by ArsenalNut » 18 May 2012, 18:23
I found the culprit in ManaPool that is probably deleting your mana restrictions. There is function that creates an array list of new mana object from a parent object based on the amount in the parent object.FabioFLX wrote:No ArsenalNut, this is not where the bug comes from, indeed I added the copy() method to avoid the loss of restrictions bug.ArsenalNut wrote:I believe this is the most likely source of your bug. None of the existing methods in the ManaPool ever made copies so the original Mana objects were left intact and just added and removed to various ArrayLists.
After looking at what ManaPool was doing, I decided it would be more efficient if the Mana object switched paradigms from being able to represent any amount of a given color to representing a single piece of mana in a given color so something like Black Lotus would now produce three mana objects rather than one with an amount of three. Changing to this paradigm, allows the logic in ManaPool to be much simpler and straight forward because you don't have to keep track of how much of the mana was used. I also means no additional Mana objects are created and I could reduce the reliance of string based operations. I have most ManaPool rewritten to use this paradigm. I have one function left to address then I'll check my code into the branch
So many cards, so little time
-
ArsenalNut - Posts: 512
- Joined: 08 Jul 2011, 03:49
- Has thanked: 27 times
- Been thanked: 121 times
Re: Restricted use mana
by ArsenalNut » 21 May 2012, 05:10
I checked my updated Mana and ManaPool code into the branch. I have mana restrictions implemented but there is an issue with multikicker. I makes my head hurt to look at the multikicker code but from what I can tell there is no way to tell what source card the multikicker is associated with when the multikicker is being paid. This makes it impossible to tell whether or not a restricted mana can be used to pay a multikicker cost. Any thoughts on how to fix this?
So many cards, so little time
-
ArsenalNut - Posts: 512
- Joined: 08 Jul 2011, 03:49
- Has thanked: 27 times
- Been thanked: 121 times
Re: Restricted use mana
by Sloth » 21 May 2012, 06:13
Multikicker needs to be completely rewritten, so don't bother with it. Just make it not payable with this mana (which should be correct for 90% of these cards anyway).ArsenalNut wrote:I checked my updated Mana and ManaPool code into the branch. I have mana restrictions implemented but there is an issue with multikicker. I makes my head hurt to look at the multikicker code but from what I can tell there is no way to tell what source card the multikicker is associated with when the multikicker is being paid. This makes it impossible to tell whether or not a restricted mana can be used to pay a multikicker cost. Any thoughts on how to fix this?
-
Sloth - Programmer
- Posts: 3498
- Joined: 23 Jun 2009, 19:40
- Has thanked: 125 times
- Been thanked: 507 times
Re: Restricted use mana
by moomarc » 21 May 2012, 06:42
Just to throw a small spanner in the works, do the restrictions interact correctly with Doubling Cube (and possibly other mana copying, not too sure which cards to check though). Here's the 12/1/2004 ruling:
Any restrictions on the mana in your mana pool aren't copied. For example, if you have![]()
![]()
![]()
with no restrictions on it in your mana pool and
![]()
![]()
that can be used only to cast artifact spells, you'll end up with
![]()
![]()
![]()
![]()
![]()
![]()
,
![]()
![]()
that can be used only to cast artifact spells, and
![]()
![]()
that can be used for anything.
-Marc
-
moomarc - Pixel Commander
- Posts: 2091
- Joined: 04 Jun 2010, 15:22
- Location: Johannesburg, South Africa
- Has thanked: 371 times
- Been thanked: 372 times
Re: Restricted use mana
by ArsenalNut » 21 May 2012, 13:38
The way that Doubling Cube is scripted, it uses its own mana abilities to "copy" the amounts in the mana pool so the new mana has no restrictions.moomarc wrote:Just to throw a small spanner in the works, do the restrictions interact correctly with Doubling Cube (and possibly other mana copying, not too sure which cards to check though). Here's the 12/1/2004 ruling:Any restrictions on the mana in your mana pool aren't copied. For example, if you have![]()
![]()
![]()
with no restrictions on it in your mana pool and
![]()
![]()
that can be used only to cast artifact spells, you'll end up with
![]()
![]()
![]()
![]()
![]()
![]()
,
![]()
![]()
that can be used only to cast artifact spells, and
![]()
![]()
that can be used for anything.
A couple of question about doubling cube though
1) Shouldn't it double the amount of colorless mana as well? It currently does not.
2) Strictly speaking, is the use of mana ability correct i.e. Doubling Cube is not really a mana ability? It seems like there is a potential issue with TapsForMana triggers that happens to be avoided because all the currently implemented TapsForMana triggers involve lands being tapped.
So many cards, so little time
-
ArsenalNut - Posts: 512
- Joined: 08 Jul 2011, 03:49
- Has thanked: 27 times
- Been thanked: 121 times
Re: Restricted use mana
by ArsenalNut » 21 May 2012, 14:07
I checked in a version that allows mana to make spells paid with it uncounterable. The version includes a working Cavern of Souls.
I am not completely happy with my solution though. I couldn't see a clean way to add the keyword "CARDNAME can't be countered" to a card and then remove the keyword when the card left the stack. I ended up adding a property to the Card class that ManaPool could set as appropriate. It would be cleaner if I could check the mana used to pay for a spell when its on the stack but all the array lists with this information get reset when a spellAbility is put on the stack. Is there reason why these array lists need to be cleared when the spell is put on the stack? Does it break anything if this step is done when the spell is removed from the stack?
I am not completely happy with my solution though. I couldn't see a clean way to add the keyword "CARDNAME can't be countered" to a card and then remove the keyword when the card left the stack. I ended up adding a property to the Card class that ManaPool could set as appropriate. It would be cleaner if I could check the mana used to pay for a spell when its on the stack but all the array lists with this information get reset when a spellAbility is put on the stack. Is there reason why these array lists need to be cleared when the spell is put on the stack? Does it break anything if this step is done when the spell is removed from the stack?
So many cards, so little time
-
ArsenalNut - Posts: 512
- Joined: 08 Jul 2011, 03:49
- Has thanked: 27 times
- Been thanked: 121 times
Re: Restricted use mana
by friarsol » 21 May 2012, 15:07
You can probably move this information over to StackInstance, so it's available when the SpellAbility is retransformed for checking if it can be countered?ArsenalNut wrote:It would be cleaner if I could check the mana used to pay for a spell when its on the stack but all the array lists with this information get reset when a spellAbility is put on the stack. Is there reason why these array lists need to be cleared when the spell is put on the stack? Does it break anything if this step is done when the spell is removed from the stack?
- friarsol
- Global Moderator
- Posts: 7593
- Joined: 15 May 2010, 04:20
- Has thanked: 243 times
- Been thanked: 965 times
Re: Restricted use mana
by ArsenalNut » 21 May 2012, 15:32
Good thought but the payingMana array list gets cleared before StackInstance gets created. From what I see, the payment history gets cleared almost immediately after a cost is completely paid. I am trying to figure what the design reason is for this behavior. Any ideas?friarsol wrote:You can probably move this information over to StackInstance, so it's available when the SpellAbility is retransformed for checking if it can be countered?ArsenalNut wrote:It would be cleaner if I could check the mana used to pay for a spell when its on the stack but all the array lists with this information get reset when a spellAbility is put on the stack. Is there reason why these array lists need to be cleared when the spell is put on the stack? Does it break anything if this step is done when the spell is removed from the stack?
So many cards, so little time
-
ArsenalNut - Posts: 512
- Joined: 08 Jul 2011, 03:49
- Has thanked: 27 times
- Been thanked: 121 times
Re: Restricted use mana
by friarsol » 21 May 2012, 16:20
Not at my codebase, but I'd guess it's leftover from before StackInstances even existed.ArsenalNut wrote:Good thought but the payingMana array list gets cleared before StackInstance gets created. From what I see, the payment history gets cleared almost immediately after a cost is completely paid. I am trying to figure what the design reason is for this behavior. Any ideas?
What happens if you switch these lines in SpellAbilityRequirements all the way at the end of the file
AllZone.getHumanPlayer().getManaPool().clearPay(this.ability, false);
AllZone.getStack().addAndUnfreeze(this.ability);
And inside the StackInstance Creation, grab the Payment list?
- friarsol
- Global Moderator
- Posts: 7593
- Joined: 15 May 2010, 04:20
- Has thanked: 243 times
- Been thanked: 965 times
Re: Restricted use mana
by ArsenalNut » 22 May 2012, 05:39
No luck with switching the lines. StackInstance still gets created after clearPay is called when I run through with the debugger if the stack is not frozen.friarsol wrote:Not at my codebase, but I'd guess it's leftover from before StackInstances even existed.ArsenalNut wrote:Good thought but the payingMana array list gets cleared before StackInstance gets created. From what I see, the payment history gets cleared almost immediately after a cost is completely paid. I am trying to figure what the design reason is for this behavior. Any ideas?
What happens if you switch these lines in SpellAbilityRequirements all the way at the end of the file
AllZone.getHumanPlayer().getManaPool().clearPay(this.ability, false);
AllZone.getStack().addAndUnfreeze(this.ability);
And inside the StackInstance Creation, grab the Payment list?
For now my implementation works, it's just not as clean as it could be. I am going to work on play testing and creating all the restricted mana cards. I'll take another crack at it after that.
So many cards, so little time
-
ArsenalNut - Posts: 512
- Joined: 08 Jul 2011, 03:49
- Has thanked: 27 times
- Been thanked: 121 times
Re: Restricted use mana
by FabioFLX » 22 May 2012, 07:09
So, you too noticed that the arrays in the ManaPool was redundant, and that the most of the problems about the mana restrictions came from the use of two different storages for the same information.ArsenalNut wrote:No luck with switching the lines. StackInstance still gets created after clearPay is called when I run through with the debugger if the stack is not frozen.friarsol wrote:Not at my codebase, but I'd guess it's leftover from before StackInstances even existed.ArsenalNut wrote:Good thought but the payingMana array list gets cleared before StackInstance gets created. From what I see, the payment history gets cleared almost immediately after a cost is completely paid. I am trying to figure what the design reason is for this behavior. Any ideas?
What happens if you switch these lines in SpellAbilityRequirements all the way at the end of the file
AllZone.getHumanPlayer().getManaPool().clearPay(this.ability, false);
AllZone.getStack().addAndUnfreeze(this.ability);
And inside the StackInstance Creation, grab the Payment list?
For now my implementation works, it's just not as clean as it could be. I am going to work on play testing and creating all the restricted mana cards. I'll take another crack at it after that.
A simple "for" cycle for cards that have an Amount$ of produced mana greater that 1 should make the trick.
I had restrictions working without problems some days ago, but Saturday was my birthday and I had no time to work on the code since last friday. Should I discard my work or should it be usefull to post it anyway in some branch?
Who is online
Users browsing this forum: No registered users and 19 guests