Global rules changes
Post MTG Forge Related Programming Questions Here
Moderators: timmermac, Agetian, friarsol, Blacksmith, KrazyTheFox, CCGHQ Admins
10 posts
• Page 1 of 1
Global rules changes
by Sloth » 13 Nov 2012, 20:53
In order to remove some hard-coded cards that have unique static abilities which globally change the rules (like Mirror Gallery), i'm thinking about storing these effects somewhere like "keywords". This was done for player "keywords" like "You can't lose the game." quite successfully.
The only question i have is: in which object should i add this "keyword" list?
I'm tending towards GameState (ColorChanger is also stored there). Any thoughts?
The only question i have is: in which object should i add this "keyword" list?
I'm tending towards GameState (ColorChanger is also stored there). Any thoughts?
-

Sloth - Programmer
- Posts: 3498
- Joined: 23 Jun 2009, 19:40
- Has thanked: 125 times
- Been thanked: 507 times
Re: Global rules changes
by Max mtg » 13 Nov 2012, 21:46
GameState, yes... maybe create a sub-class to hold these rules overrides (and probably hold all static abilities in the long run)
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: Global rules changes
by Sloth » 13 Nov 2012, 22:04
I can put it into StaticEffects. This object already holds the info of all continuous static abilities.
-

Sloth - Programmer
- Posts: 3498
- Joined: 23 Jun 2009, 19:40
- Has thanked: 125 times
- Been thanked: 507 times
Re: Global rules changes
by Max mtg » 14 Nov 2012, 15:58
I heathly welcome disappearance of hardcoded card names from code in favour of rules checks.
But why are you putting all those fields with their getters and setters right into StaticEffects class? A dedicated class to hold the fields you are adding would be a most natural thing. That class may stay inside static effects or in gamestate - at any siutable place.
The next idea that comes up to my mind (good for fields rules which have no parameters) is declare an enum like GlobalRuleType and have an EnumSet<GlobalRuleType> hold the effective rules. Adding a getter like "isRuleInEffect(GlobalRuleType.ManaPoolsDontEmpty)" and setter setRule(GlobalRuleType rule, boolean newValue) might get rid all of us from adding that may getters/setters
But why are you putting all those fields with their getters and setters right into StaticEffects class? A dedicated class to hold the fields you are adding would be a most natural thing. That class may stay inside static effects or in gamestate - at any siutable place.
The next idea that comes up to my mind (good for fields rules which have no parameters) is declare an enum like GlobalRuleType and have an EnumSet<GlobalRuleType> hold the effective rules. Adding a getter like "isRuleInEffect(GlobalRuleType.ManaPoolsDontEmpty)" and setter setRule(GlobalRuleType rule, boolean newValue) might get rid all of us from adding that may getters/setters
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: Global rules changes
by Sloth » 14 Nov 2012, 17:33
Will do. I knew you wouldn't be content with the implementation, I was just lazy. 
-

Sloth - Programmer
- Posts: 3498
- Joined: 23 Jun 2009, 19:40
- Has thanked: 125 times
- Been thanked: 507 times
Re: Global rules changes
by Max mtg » 14 Nov 2012, 17:55
I suppose that by writing cleaner code, you and everyone else would have to put less efforts in understanding and further extension of that code.Sloth wrote:Will do. I knew you wouldn't be content with the implementation, I was just lazy.
=)
It's like being lazy after you wrote a good initial framework.
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: Global rules changes
by Max mtg » 14 Nov 2012, 19:07
Hey, Sloth,
Who will be dreaming to add numberless checks there?
Come on,
Who will be dreaming to add numberless checks there?
- Code: Select all
if (params.get("GlobalRule").equals("Damage can't be prevented.")) {
effects.setGlobalRuleChange(GlobalRuleChange.noPrevention);
} else if (params.get("GlobalRule").equals("All damage is dealt as though it's source had wither.")) {
effects.setGlobalRuleChange(GlobalRuleChange.alwaysWither);
} else if (params.get("GlobalRule").equals("The legend rule doesn't apply.")) {
effects.setGlobalRuleChange(GlobalRuleChange.noLegendRule);
} else if (params.get("GlobalRule").equals("Mana pools don't empty as steps and phases end.")) {
effects.setGlobalRuleChange(GlobalRuleChange.manapoolsDontEmpty);
} else if (params.get("GlobalRule").equals("Players can't cycle cards.")) {
effects.setGlobalRuleChange(GlobalRuleChange.noCycling);
} else if (params.get("GlobalRule").equals("Creatures entering the battlefield don't cause abilities to trigger.")) {
effects.setGlobalRuleChange(GlobalRuleChange.noCreatureETBTriggers);
} else if (params.get("GlobalRule").equals("No more than one creature can block each combat.")) {
effects.setGlobalRuleChange(GlobalRuleChange.onlyOneBlocker);
} else if (params.get("GlobalRule").equals("No more than one creature can attack each turn.")) {
effects.setGlobalRuleChange(GlobalRuleChange.onlyOneAttackerATurn);
} else if (params.get("GlobalRule").equals("No more than one creature can attack each combat.")) {
effects.setGlobalRuleChange(GlobalRuleChange.onlyOneAttackerACombat);
}
Come on,
- Code: Select all
alwaysWither("TEXT FROM cardname.txt"),
manapoolsDontEmpty("TEXT FROM cardname.txt"),
noCycling("TEXT FROM cardname.txt"),
noCreatureETBTriggers("TEXT FROM cardname.txt"),
// ....
private final String cardFileText;
private GlobalRuleChange(String text) {
cardFileText = text;
}
public static GlobalRuleChange fromString(String cardfileText) {
// Iterate over GlobalRuleChange.values(), return one with matching cardfileText or null
}
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: Global rules changes
by Sloth » 14 Nov 2012, 21:43
You are a mean slavedriver Max.Max mtg wrote:Hey, Sloth,...
Come on,...
But seriously, i really needed your advice to produce some better code. As a hobby coder i'm happy to improve a little from time to time. So thanks for your patience Max.
-

Sloth - Programmer
- Posts: 3498
- Joined: 23 Jun 2009, 19:40
- Has thanked: 125 times
- Been thanked: 507 times
Re: Global rules changes
by Max mtg » 15 Nov 2012, 21:20
didn't mean to be a slavedriver, yet I'll insist on writing some better code for new subsystems... and yes, I'll share the what I know about 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: Global rules changes
by silly freak » 17 Nov 2012, 18:57
enums have some funny initialization rules, but it should be possible to store a private Map<String, GlobalRuleChange> inside the enum to avoid the linear search. That's micro optimization, but I though I'd point out the possibility
___
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
10 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 12 guests