Page 1 of 1
Global rules changes

Posted:
13 Nov 2012, 20:53
by Sloth
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?
Re: Global rules changes

Posted:
13 Nov 2012, 21:46
by Max mtg
GameState, yes... maybe create a sub-class to hold these rules overrides (and probably hold all static abilities in the long run)
Re: Global rules changes

Posted:
13 Nov 2012, 22:04
by Sloth
I can put it into StaticEffects. This object already holds the info of all continuous static abilities.
Re: Global rules changes

Posted:
14 Nov 2012, 15:58
by Max mtg
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
Re: Global rules changes

Posted:
14 Nov 2012, 17:33
by Sloth
Will do. I knew you wouldn't be content with the implementation, I was just lazy.

Re: Global rules changes

Posted:
14 Nov 2012, 17:55
by Max mtg
Sloth wrote:Will do. I knew you wouldn't be content with the implementation, I was just lazy.

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.
=)
It's like being lazy after you wrote a good initial framework.
Re: Global rules changes

Posted:
14 Nov 2012, 19:07
by Max mtg
Hey, Sloth,
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);
}
Yet this must be just a beginning.
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
}
You'll have to add bare enum member and text after that, just like in refactored AFs
Re: Global rules changes

Posted:
14 Nov 2012, 21:43
by Sloth
Max mtg wrote:Hey, Sloth,...
Come on,...
You are a mean slavedriver Max.

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.
Re: Global rules changes

Posted:
15 Nov 2012, 21:20
by Max mtg
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.
Re: Global rules changes

Posted:
17 Nov 2012, 18:57
by silly freak
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