AbilityFactory refactoring
Post MTG Forge Related Programming Questions Here
Moderators: timmermac, Agetian, friarsol, Blacksmith, KrazyTheFox, CCGHQ Admins
29 posts
• Page 2 of 2 • 1, 2
Re: AbilityFactory refactoring
by friarsol » 06 Nov 2012, 03:52
Not sure what's going on with Charm, but it seems to be incorrect, since you need to choose the Mode before doing any other prespell stuff (choosing targets, paying costs) currently, you choose the mode on resolution, which doesn't make sense since no targets are chosen or anything.
- friarsol
- Global Moderator
- Posts: 7593
- Joined: 15 May 2010, 04:20
- Has thanked: 243 times
- Been thanked: 965 times
Re: AbilityFactory refactoring
by Max mtg » 06 Nov 2012, 05:36
I know - have made choices on resolve, but according to rules one should choose when spell is cast.friarsol wrote:Not sure what's going on with Charm, but it seems to be incorrect, since you need to choose the Mode before doing any other prespell stuff (choosing targets, paying costs) currently, you choose the mode on resolution, which doesn't make sense since no targets are chosen or anything.
Will take care right now... done. r17870
Some problems with stack descriptions remain.
We have StackDescription, SpellDescription and the own description and effect may provide. What will a common rule be? The rule to choose which text to display.
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: AbilityFactory refactoring
by friarsol » 06 Nov 2012, 12:51
SpellDescription is what is used when the spell is in your hand. StackDescription tries to append useful Stack relevant information (Targets, etc) and is displayed in the stack panel. Plain old description I believe is the same as SpellDescription, just with an overwritable getter. And I'd imagine the effect description should be trying to "overwrite" the StackDescription, since that's when it's relevant.Max mtg wrote:We have StackDescription, SpellDescription and the own description and effect may provide. What will a common rule be? The rule to choose which text to display.
- friarsol
- Global Moderator
- Posts: 7593
- Joined: 15 May 2010, 04:20
- Has thanked: 243 times
- Been thanked: 965 times
Re: AbilityFactory refactoring
by Sloth » 06 Nov 2012, 21:18
Just fyi:
I've moved all the drawback checks of the ai functions to SpellAiLogic. I will see what else can be generalized to reduce duplicate code.
I've moved all the drawback checks of the ai functions to SpellAiLogic. I will see what else can be generalized to reduce duplicate code.
-

Sloth - Programmer
- Posts: 3498
- Joined: 23 Jun 2009, 19:40
- Has thanked: 125 times
- Been thanked: 507 times
Re: AbilityFactory refactoring
by Max mtg » 06 Nov 2012, 21:36
That's great, yet there are a few things to add:Sloth wrote:Just fyi:
I've moved all the drawback checks of the ai functions to SpellAiLogic. I will see what else can be generalized to reduce duplicate code.
- the wrapped canPlay no longer needs to be public.
- it also has to be abstract to prevent empty descendants.
I've already commited these changes.
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: AbilityFactory refactoring
by Max mtg » 06 Nov 2012, 21:58
you may also removeSloth wrote:Just fyi:
I've moved all the drawback checks of the ai functions to SpellAiLogic. I will see what else can be generalized to reduce duplicate code.
- Code: Select all
public boolean chkAIDrawback(final Map<String, String> params, final SpellAbility sa, final Player aiPlayer) {
return true;
}
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: AbilityFactory refactoring
by Max mtg » 07 Nov 2012, 06:41
ChangeZone converted.
The process is finished.
The process is finished.
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: AbilityFactory refactoring
by Max mtg » 07 Nov 2012, 18:16
There is a harcoded card of Wing Puncture - if anyone converts it into script, there will remain no other descendants of AbilitySub than the CommonDrawback class!
Could anybody do it?
Could anybody do it?
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: AbilityFactory refactoring
by Sloth » 07 Nov 2012, 18:40
I will do it.Max mtg wrote:There is a harcoded card of Wing Puncture - if anyone converts it into script, there will remain no other descendants of AbilitySub than the CommonDrawback class!
Could anybody do it?
EDIT: Done.
-

Sloth - Programmer
- Posts: 3498
- Joined: 23 Jun 2009, 19:40
- Has thanked: 125 times
- Been thanked: 507 times
Re: AbilityFactory refactoring
by Max mtg » 07 Nov 2012, 19:31
Great! Thank you.Sloth wrote:I will do it.Max mtg wrote:There is a harcoded card of Wing Puncture - if anyone converts it into script, there will remain no other descendants of AbilitySub than the CommonDrawback class!
Could anybody do it?
EDIT: Done.
Now it's possible to get rid of AbilitySub class and replace it with CommonDrawback - yet this needs some evaluation.
Actually AbilitySubs form a double-linked list of abilities. At least that double-linked list functionality might be performed by some standard container... or not?
getCopy might be replaced with clone() for sure, making Spellability implement Cloneable
What I also would love to reach here is to remove a reference to factory from ability classes - so that factory products become independent.
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: AbilityFactory refactoring
by Sloth » 07 Nov 2012, 22:31
The only use of backtracking from the ability to the factory is that AI functions can easily evaluate what a spell on a stack is doing. Of course only the api and the parameters are necessary, so maybe this could be handled in another way.Max mtg wrote:What I also would love to reach here is to remove a reference to factory from ability classes - so that factory products become independent.
-

Sloth - Programmer
- Posts: 3498
- Joined: 23 Jun 2009, 19:40
- Has thanked: 125 times
- Been thanked: 507 times
Re: AbilityFactory refactoring
by Max mtg » 08 Nov 2012, 05:00
That's awesome.Sloth wrote:The only use of backtracking from the ability to the factory is that AI functions can easily evaluate what a spell on a stack is doing. Of course only the api and the parameters are necessary, so maybe this could be handled in another way.Max mtg wrote:What I also would love to reach here is to remove a reference to factory from ability classes - so that factory products become independent.
Let then SA hold only api and paramters, and both are readonly fields I guess. So that the main AF class may become singleton one day.
I guess the reference to AF in SA can be replaced with these 3 methods.
- Code: Select all
public String getParam(String key) {
return params == null ? null : params.get(key);
}
public boolean hasParam(String key) {
return params == null ? false: params.containsKey(key);
}
// If this is not null, then ability was made in a factory
public final ApiType getApi() {
return api;
}
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: AbilityFactory refactoring
by Max mtg » 08 Nov 2012, 07:41
Well... noone stopped me, so it's already there, in 17906.
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: AbilityFactory refactoring
by Sloth » 08 Nov 2012, 08:43
I think this way a very good change. Well done Max.Max mtg wrote:Let then SA hold only api and paramters, and both are readonly fields I guess. So that the main AF class may become singleton one day.
I guess the reference to AF in SA can be replaced with these 3 methods.Similiarly, all the methods of AF-Effects and AF-AIs no longer need a Map<String,String> params as an argument, because SA has all that data incapsulated
- Code: Select all
public String getParam(String key) {
return params == null ? null : params.get(key);
}
public boolean hasParam(String key) {
return params == null ? false: params.containsKey(key);
}
// If this is not null, then ability was made in a factory
public final ApiType getApi() {
return api;
}
Now that the spellability itself holds the parameters, we are one step closer to implementing cards like Magical Hack and Sleight of Mind (at least for spell targets).
-

Sloth - Programmer
- Posts: 3498
- Joined: 23 Jun 2009, 19:40
- Has thanked: 125 times
- Been thanked: 507 times
29 posts
• Page 2 of 2 • 1, 2
Who is online
Users browsing this forum: ArchieRoW and 11 guests