It is currently 29 Oct 2025, 05:04
   
Text Size

Global rules changes

Post MTG Forge Related Programming Questions Here

Moderators: timmermac, Agetian, friarsol, Blacksmith, KrazyTheFox, CCGHQ Admins

Global rules changes

Postby 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?
User avatar
Sloth
Programmer
 
Posts: 3498
Joined: 23 Jun 2009, 19:40
Has thanked: 125 times
Been thanked: 507 times

Re: Global rules changes

Postby 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

Postby Sloth » 13 Nov 2012, 22:04

I can put it into StaticEffects. This object already holds the info of all continuous static abilities.
User avatar
Sloth
Programmer
 
Posts: 3498
Joined: 23 Jun 2009, 19:40
Has thanked: 125 times
Been thanked: 507 times

Re: Global rules changes

Postby 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
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

Postby Sloth » 14 Nov 2012, 17:33

Will do. I knew you wouldn't be content with the implementation, I was just lazy. :D
User avatar
Sloth
Programmer
 
Posts: 3498
Joined: 23 Jun 2009, 19:40
Has thanked: 125 times
Been thanked: 507 times

Re: Global rules changes

Postby Max mtg » 14 Nov 2012, 17:55

Sloth wrote:Will do. I knew you wouldn't be content with the implementation, I was just lazy. :D
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.
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

Postby Max mtg » 14 Nov 2012, 19:07

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
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

Postby Sloth » 14 Nov 2012, 21:43

Max mtg wrote:Hey, Sloth,...
Come on,...
You are a mean slavedriver Max. :wink:

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.
User avatar
Sloth
Programmer
 
Posts: 3498
Joined: 23 Jun 2009, 19:40
Has thanked: 125 times
Been thanked: 507 times

Re: Global rules changes

Postby 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

Postby 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!
silly freak
DEVELOPER
 
Posts: 598
Joined: 26 Mar 2009, 07:18
Location: Vienna, Austria
Has thanked: 93 times
Been thanked: 25 times


Return to Developer's Corner

Who is online

Users browsing this forum: No registered users and 12 guests

Main Menu

User Menu

Our Partners


Who is online

In total there are 12 users online :: 0 registered, 0 hidden and 12 guests (based on users active over the past 10 minutes)
Most users ever online was 9298 on 10 Oct 2025, 12:54

Users browsing this forum: No registered users and 12 guests

Login Form