Restricted use mana
Post MTG Forge Related Programming Questions Here
Moderators: timmermac, Blacksmith, KrazyTheFox, Agetian, friarsol, CCGHQ Admins
Re: Restricted use mana
by ArsenalNut » 14 May 2012, 18:51
Switching your project to use a branch is fairly simple but dealing with modified code into an existing branch can be a hassle (mostly in making sure all the version line up correctly). It may be easier to create a new branch with your modified workspace as the starting point. If you want to post a patch relative to the current trunk head revision, I can get your code changes integrated into a branch you can work with.FabioFLX wrote:Well, I must admit that after another couple of experiments I understood that - for the moment - the ManaPool does not need to be absolutely rewritten.
Instead, I achieved the functionality with some minor code inside the Mana class and a very little modification at the ManaPool class.
I haven't tested the code enough to say it's ready, but finally it allows cards like Grand Architect to work as expected.
Thanks for the branch. How can I share the code with other programmers without impacting on the actual code in the svn?
Thank you,
Fabio
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 » 14 May 2012, 19:49
Ok, thanks.ArsenalNut wrote:Switching your project to use a branch is fairly simple but dealing with modified code into an existing branch can be a hassle (mostly in making sure all the version line up correctly). It may be easier to create a new branch with your modified workspace as the starting point. If you want to post a patch relative to the current trunk head revision, I can get your code changes integrated into a branch you can work with.
Tomorrow I will continue working on the project.
I will share my code with you as soon as possible, maybe tomorrow itself.
See you!
Re: Restricted use mana
by Max mtg » 14 May 2012, 21:26
I got the idea how the ManaCost class works!
It keeps the mana yet to pay and decides where to spend mana from a source. I can convert it to use my shards instead of a variety of classes!
Will commit into the branch then.
It keeps the mana yet to pay and decides where to spend mana from a source. I can convert it to use my shards instead of a variety of classes!
Will commit into the branch then.
Single class for single responsibility.
- Max mtg
- Programmer
- Posts: 1997
- Joined: 02 Jul 2011, 14:26
- Has thanked: 173 times
- Been thanked: 334 times
Re: Restricted use mana
by Max mtg » 14 May 2012, 23:33
I have commited (into the aforementioned branch @15547) a change that simplifies the rules for mana filtering to cast a spell or ability. Old mana classes had incapsulted priority checks, code to check if certain mana can pay for this ManaPart and paid/unpaid flag inside.
The new ManaCostShard represents just an symbol in the card manacost - it has no other logics inside. So the decisions on which manasymbol to pay for first is taken by the controller class now (ManaCost in our case)
I removed the manapart family of classes and placed the ManaCostShard class to forge.card.mana package. Anyone who is about to introduce restrictions on mana usage won't have to deal with ugly manaparts anymore.
This should have been done long ago, but had no good chance till now (when I got insight on how the mana system works). I sincerely hope that this change will make the deploying of mana restrictions simplier.
The new ManaCostShard represents just an symbol in the card manacost - it has no other logics inside. So the decisions on which manasymbol to pay for first is taken by the controller class now (ManaCost in our case)
I removed the manapart family of classes and placed the ManaCostShard class to forge.card.mana package. Anyone who is about to introduce restrictions on mana usage won't have to deal with ugly manaparts anymore.
This should have been done long ago, but had no good chance till now (when I got insight on how the mana system works). I sincerely hope that this change will make the deploying of mana restrictions simplier.
Single class for single responsibility.
- Max mtg
- Programmer
- Posts: 1997
- Joined: 02 Jul 2011, 14:26
- Has thanked: 173 times
- Been thanked: 334 times
Re: Restricted use mana
by ArsenalNut » 15 May 2012, 13:28
Hey Max,
Is there a particular reason that you renamed the Mana class to ManaPaid? Functionally you didn't really change anything. Conceptually, it seems odd that the ManaPool now contains ManaPaid objects instead of just Mana objects waiting to be used. If the change was for clarity, I personally I find harder to read the code now.
Is there a particular reason that you renamed the Mana class to ManaPaid? Functionally you didn't really change anything. Conceptually, it seems odd that the ManaPool now contains ManaPaid objects instead of just Mana objects waiting to be used. If the change was for clarity, I personally I find harder to read the code now.
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 » 15 May 2012, 15:20
To simplify all of my work on the new pool I created a new ManaRestricted class that is stored into an ArrayList of the Mana class.
When a card with a mana ability has certain specific params (for example $UseOnlyForType) they are stored in this array.
As today, what I done is that every time a SpellAbility ask for mana at subtractOne(), this ask to a new getManaFrom() that is able to check for restrictions in the ManaRestricted array I described before.
This seems to allow the functinality, but of course it still needs strong testing.
See you,
Fabio
When a card with a mana ability has certain specific params (for example $UseOnlyForType) they are stored in this array.
As today, what I done is that every time a SpellAbility ask for mana at subtractOne(), this ask to a new getManaFrom() that is able to check for restrictions in the ManaRestricted array I described before.
This seems to allow the functinality, but of course it still needs strong testing.
See you,
Fabio
Re: Restricted use mana
by Max mtg » 15 May 2012, 18:54
It was exactly for clarity. I needed this to reengineer ManaCost. 'Mana' is too common to describe the entity (piece-of-mana-that-can-be-spent). Although I've renamed the class back, I suggest that someone finds a more specific name for it.ArsenalNut wrote:Hey Max,
Is there a particular reason that you renamed the Mana class to ManaPaid? Functionally you didn't really change anything. Conceptually, it seems odd that the ManaPool now contains ManaPaid objects instead of just Mana objects waiting to be used. If the change was for clarity, I personally I find harder to read the code now.
Single class for single responsibility.
- Max mtg
- Programmer
- Posts: 1997
- Joined: 02 Jul 2011, 14:26
- Has thanked: 173 times
- Been thanked: 334 times
Re: Restricted use mana
by moomarc » 15 May 2012, 19:40
Some quick suggestions that might be suitable:Max mtg wrote:It was exactly for clarity. I needed this to reengineer ManaCost. 'Mana' is too common to describe the entity (piece-of-mana-that-can-be-spent). Although I've renamed the class back, I suggest that someone finds a more specific name for it.ArsenalNut wrote:Hey Max,
Is there a particular reason that you renamed the Mana class to ManaPaid? Functionally you didn't really change anything. Conceptually, it seems odd that the ManaPool now contains ManaPaid objects instead of just Mana objects waiting to be used. If the change was for clarity, I personally I find harder to read the code now.
- ManaPooled (propably most descriptive grammatically and describes where it is)
- ManaAdded
-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 friarsol » 15 May 2012, 19:47
Mana that is Floating in a ManaPool could just be FloatingMana/ManaFloating, right?moomarc wrote:Some quick suggestions that might be suitable:Max mtg wrote:It was exactly for clarity. I needed this to reengineer ManaCost. 'Mana' is too common to describe the entity (piece-of-mana-that-can-be-spent). Although I've renamed the class back, I suggest that someone finds a more specific name for it.ArsenalNut wrote:Hey Max,
Is there a particular reason that you renamed the Mana class to ManaPaid? Functionally you didn't really change anything. Conceptually, it seems odd that the ManaPool now contains ManaPaid objects instead of just Mana objects waiting to be used. If the change was for clarity, I personally I find harder to read the code now.
- ManaPooled (propably most descriptive grammatically and describes where it is)
- ManaAdded
- 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 » 16 May 2012, 05:08
I disagree that the Mana class really even needs to be renamed. Mana is a fundamental object that gets produced when a Mana ability is activated and placed in the ManaPool. I believe the confusion with Mana and ManaCost is due to poor names for the containers that hold Mana objects and some of the names used in the function calls that subtract Mana from the ManaPool. For example, take the following line from ManaPool.subtractManaMax mtg wrote:It was exactly for clarity. I needed this to reengineer ManaCost. 'Mana' is too common to describe the entity (piece-of-mana-that-can-be-spent). Although I've renamed the class back, I suggest that someone finds a more specific name for it.ArsenalNut wrote:Hey Max,
Is there a particular reason that you renamed the Mana class to ManaPaid? Functionally you didn't really change anything. Conceptually, it seems odd that the ManaPool now contains ManaPaid objects instead of just Mana objects waiting to be used. If the change was for clarity, I personally I find harder to read the code now.
- Code: Select all
m = this.subtractMultiple(sa, cost, m);
Rewritten as
- Code: Select all
manaCostLeftToPay = this.subtractMultiple(spellAbilityBeingPaidFor, manaToBeSubtracted, manaCostLeftToPay);
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 » 16 May 2012, 05:21
I checked in some code that implements checking a "RestrictValid" parameter in a Mana Ability. It is only implemented so far for the human player and only when directly tapping a source to pay a cost. I was looking at how the same code could be reused in the ManaPool to handle the case where the Mana already resides in the pool. Is there any reason a mana object couldn't reference the source Mana ability either in addition to or instead of the source card?
Edit: I added support so AI won't try to use restricted mana abilities for costs that don't meet the restrictions.
Edit: I added support so AI won't try to use restricted mana abilities for costs that don't meet the restrictions.
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 » 16 May 2012, 10:17
Hi all,
my version of Forge allows AI to use restrictions in the mana abilities, because these are stored inside the ManaAbility and Mana classes.
When AI cycles the Spell_Ability's for avaiable mana these classes know the source and eventually apply saved restrictions.
The code is not yet complete but as now I'm having both the AI and the Human playing Grand Architect and Ancient Ziggurat without problems.
my version of Forge allows AI to use restrictions in the mana abilities, because these are stored inside the ManaAbility and Mana classes.
When AI cycles the Spell_Ability's for avaiable mana these classes know the source and eventually apply saved restrictions.
The code is not yet complete but as now I'm having both the AI and the Human playing Grand Architect and Ancient Ziggurat without problems.
Re: Restricted use mana
by silly freak » 16 May 2012, 12:04
Do you use Mana as a name in another place, too? I think that Mana is a good name for what is contained in a Mana pool, but FloatingMana sounds ok too. In my program, I'm using Mana, ManaSymbol (with subclasses like Snow, Colored, Generic, Variable and Hybrid, which is recursive), ManaSequence (generic container for both costs and Mana producing abilities), ManaCost (contains the logic for a cost defined as a ManaSequence), just in case you're looking for names for something...Max mtg wrote:It was exactly for clarity. I needed this to reengineer ManaCost. 'Mana' is too common to describe the entity (piece-of-mana-that-can-be-spent). Although I've renamed the class back, I suggest that someone finds a more specific name for it.ArsenalNut wrote:Hey Max,
Is there a particular reason that you renamed the Mana class to ManaPaid? Functionally you didn't really change anything. Conceptually, it seems odd that the ManaPool now contains ManaPaid objects instead of just Mana objects waiting to be used. If the change was for clarity, I personally I find harder to read the code now.
___
where's the "trust me, that will work!" switch for the compiler?
Laterna Magica - blog, forum, project, 2010/09/06 release!
where's the "trust me, that will work!" switch for the compiler?
Laterna Magica - blog, forum, project, 2010/09/06 release!
- silly freak
- DEVELOPER
- Posts: 598
- Joined: 26 Mar 2009, 07:18
- Location: Vienna, Austria
- Has thanked: 93 times
- Been thanked: 25 times
Re: Restricted use mana
by friarsol » 16 May 2012, 12:14
Nope, storing the generating Ability is fine, and the source card should be able to be gleaned through that if it's really necessary. I don't have the code with me, what do we use the source card for? Undoing costs?ArsenalNut wrote:Is there any reason a mana object couldn't reference the source Mana ability either in addition to or instead of the source card?
- friarsol
- Global Moderator
- Posts: 7593
- Joined: 15 May 2010, 04:20
- Has thanked: 243 times
- Been thanked: 965 times
Re: Restricted use mana
by FabioFLX » 16 May 2012, 13:01
This is interesting.friarsol wrote:Nope, storing the generating Ability is fine, and the source card should be able to be gleaned through that if it's really necessary. I don't have the code with me, what do we use the source card for? Undoing costs?ArsenalNut wrote:Is there any reason a mana object couldn't reference the source Mana ability either in addition to or instead of the source card?
My version of Mana, ManaPool and ManaAbility classes are using modified methods that know the requesting SpellAbility.
Mana restrictions of the cards are stored while processing the card params, so the A.I. only see the ManaAbility which are really playable for each SpellAbility.
For the Human player this is even easier because the application can avoid a restricted Mana to be used for a not valid SpellAbility.
CU
Fabio
---
News:
I created a fictional deck with Ancient Ziggurat, Grand Architect and Chimeric Mass cards only.
It seems working good: the A.I. uses the Ancient Ziggurat just to cast the Grand Architect and uses this to cast and activate the Chimeric Mass. Meanwhile human player can play these cards just in this way as well.
Can you tell me how can I share my provvisory code with you? I'm not familiar with SVN...
Last edited by FabioFLX on 16 May 2012, 14:14, edited 2 times in total.
Who is online
Users browsing this forum: No registered users and 30 guests