Page 1 of 1

How do you handle replacement effects?

PostPosted: 09 Jun 2009, 18:31
by mtgrares
MTG Forge doesn't implement any replacement effects like Yixlid Jailer but I know that Incantus does, how do you do it? And does anyone else have any ideas about replacement effects. Could events be replaced, changed, or filtered? This reminds of me of software pattern Chain of Responsibility but I'm not sure if it would be useful.

Re: How do you handle replacement effects?

PostPosted: 09 Jun 2009, 19:42
by MageKing17
mtgrares wrote:MTG Forge doesn't implement any replacement effects like Yixlid Jailer but I know that Incantus does, how do you do it? And does anyone else have any ideas about replacement effects. Could events be replaced, changed, or filtered? This reminds of me of software pattern Chain of Responsibility but I'm not sure if it would be useful.
Yixlid Jailer isn't a replacement effect. It's just a static ability that removes all abilities from cards in graveyards. We do that by simply having a static_tracking ability track the graveyard and say card.abilities.remove_all() for each card in the graveyard.

Replacement effects in Incantus are done by taking a function and replacing it with an object that pretends to be a function and winds up calling various replacement effects after asking the user which replacement effects to use first. It's one of those advanced constructs that I don't really understand the specifics of all that well, although I know (in general terms) what it's doing.

Re: How do you handle replacement effects?

PostPosted: 11 Jun 2009, 18:28
by mtgrares
Thanks MageKing. In Python you can replace an object's method, so you can change the method
RulesEngine.goToGraveyard(Card) so that it removes the card from the game instead. I'm using Java which doesn't have that kind of flexibility.

Re: How do you handle replacement effects?

PostPosted: 12 Jun 2009, 02:04
by telengard
My engine would do something a little different.

A call to get[activated/static/triggered]_abilities would be hooked by the piece that removes the abilities and would then when called just check for being in the graveyard, if they were it would remove them from the list of abilities. I would probably have stuck this (if it existed in my game) in the negative replacement list (see below).

All hooks have a default implementation (in this case just return the piece's abilities as printed on the miniature). Each hook also has 4 lists, positive modifiers, positive replacements, negative modifiers, and negative replacements. These are used for cant trumps can etc. So far it's working well.

I have yet to implement choosing the order of applying modifiers (I have to do that to support 2 particular abilities).

~telengard

Re: How do you handle replacement effects?

PostPosted: 12 Jun 2009, 02:58
by MageKing17
mtgrares wrote:RulesEngine.goToGraveyard(Card)
Far simpler. Card.move_to(Zone). :)