Overriding spell playing
General Discussion of the Intricacies
Moderator: CCGHQ Admins
Overriding spell playing
by Incantus » 10 Aug 2009, 01:07
How do other rules-engine projects implement effects that can modify how cards are cast? For example, allowing them to be played from the graveyard (Flashback), or whenever instants can be played (Flash)? Or effects that modify casting costs? I'm stuck on a design for doing this, so I'd love to hear how others have handled it.
Re: Overriding spell playing
by telengard » 10 Aug 2009, 01:16
I just do these with hooks, for example the casting cost default implementation would just return the cost as printed on the cards. Cards that change the cost (i.e. maybe cost 1 less colorless) would add themselves to the hook functions and modify it on the fly. As for casting, I have a hook for that also and if something can be done from the graveyard it adds itself to the list of things that can be cast as a hook.
That's how I do it for modifying spawn costs (similar to casting costs). I can post some code if it would help.
~telengard
That's how I do it for modifying spawn costs (similar to casting costs). I can post some code if it would help.
~telengard
Author of Dreamblade:
viewtopic.php?f=51&t=1215
viewtopic.php?f=51&t=1215
-
telengard - DEVELOPER
- Posts: 379
- Joined: 23 May 2009, 23:04
- Has thanked: 2 times
- Been thanked: 27 times
Re: Overriding spell playing
by Arch » 11 Aug 2009, 08:10
Seems to me like you're asking for a bunch of different effects here and I would treat them all as separate problems. My implementation is not up to this level yet but this is how I see myself solving them in the future.
Flashback To me this is just another ability of a card. I do not have a general "play" mechanic but rather a play ability on each card. Adding another version which allows allows it to be played from the graveyard would be rather easy. (Making it be exiled instead of graveyarded would be a bit more complicated though.)
Flash I don't see how this would affect how anything could be played. The effect of getting the creature into play is part of this card and not the creature card. Figuring out the additional (optional) cost would probably require an implementation of manamathics though...
Casting cost Most values of my cards are calculated by taking the default (oracle) value and applying a number of functions to it in succession. Any card can register functions with other cards. Ballyrush Banneret for instance would just register a -1 modifier (manamathics again) with all affected cards.
In short; pretty much the same solution as telengard.
Flashback To me this is just another ability of a card. I do not have a general "play" mechanic but rather a play ability on each card. Adding another version which allows allows it to be played from the graveyard would be rather easy. (Making it be exiled instead of graveyarded would be a bit more complicated though.)
Flash I don't see how this would affect how anything could be played. The effect of getting the creature into play is part of this card and not the creature card. Figuring out the additional (optional) cost would probably require an implementation of manamathics though...
Casting cost Most values of my cards are calculated by taking the default (oracle) value and applying a number of functions to it in succession. Any card can register functions with other cards. Ballyrush Banneret for instance would just register a -1 modifier (manamathics again) with all affected cards.
In short; pretty much the same solution as telengard.
Re: Overriding spell playing
by Incantus » 11 Aug 2009, 12:37
Hi Arch, that's initially how I did it (not have a play/cast mechanic, but using a play ability that is structured similar to activated abilities, since it goes through the same motions). This worked well when only one effect modified the way something was played (Flashback) but not when 2 effects would modify it. For example, say you had Call of the Herd (Call of the Herd|2G|Sorcery|Put a 3/3 green Elephant creature token into play.|Flashback 3G) in your graveyard. Since it's a sorcery, you can only play it from your graveyard when you could play a sorcery. Now, supposing you also had Vedalken Orrery in play(You may play nonland cards as though they had flash). Now, you could flashback Call of the Herd whenever you could play an instant. If I followed the original design, there is no way to combine the 2 additional "play" abilities, since they don't know about the other.Arch wrote:Seems to me like you're asking for a bunch of different effects here and I would treat them all as separate problems. My implementation is not up to this level yet but this is how I see myself solving them in the future.
Flashback To me this is just another ability of a card. I do not have a general "play" mechanic but rather a play ability on each card. Adding another version which allows allows it to be played from the graveyard would be rather easy. (Making it be exiled instead of graveyarded would be a bit more complicated though.)
Re: Overriding spell playing
by mtgrares » 11 Aug 2009, 17:33
In MTG Forge all Card objects hold SpellAbility objects which are used for all spells and abilities. SpellAbility has the canPlay() method which returns true if it can be played. For flash SpellAbility.canPlay() always returns true, for flashback SpellAbility.canPlay() checks to see what zone it is in and returns true if it is in the graveyard.Incantus wrote:How do other rules-engine projects implement effects that can modify how cards are cast? For example, allowing them to be played from the graveyard (Flashback), or whenever instants can be played (Flash)? Or effects that modify casting costs? I'm stuck on a design for doing this, so I'd love to hear how others have handled it.
Using Card objects to hold one or more SpellAbility objects has worked great, let me use Elvish Piper as an example. Elvish Piper has two SpellAbility objects: one for the normal creature summon and the other one for the activated ability. The SpellAbility representing the activated ability checks to see what zone it is in and canPlay() only returns true if the card is in play.
For other cards that say something like "All cards cost 1 less" I don't really have any idea. You could change the code that askes the user for the cost, it could check to see if any cards that reduce the mana cost are in play.
On a side note much of the AI is programmed into each card. SpellAbility.canPlayAI() returns true if the computer should play the card. For Shock the canPlayAI() method returns true if you, the human player, have a 2/2 flyer or if you are at 2 or less life. The drawback is when the AI has two Shocks and you are at 4 life, the AI won't use both shocks to kill you.
Last edited by mtgrares on 17 Aug 2009, 16:05, edited 1 time in total.
- mtgrares
- DEVELOPER
- Posts: 1352
- Joined: 08 Sep 2008, 22:10
- Has thanked: 3 times
- Been thanked: 12 times
Re: Overriding spell playing
by Arch » 11 Aug 2009, 18:20
I would not want the abilities to interact directly. Instead I would introduce an abstration to solve it; something like adding 'cast-speed' to all cards (or abilities) which could default to 'sorcery'.Incantus wrote:.....If I followed the original design, there is no way to combine the 2 additional "play" abilities, since they don't know about the other.
The following parts would have to be updated/implemented:
- Each cast/play ability on each card would have to look at this value to determine when it could be cast instead of it's type (or whatever the current mechanic would be).
- Vedalken Orrery would have to (on a multitude of occations) register/deregister functions for the value with each affected card.
This would allow the functionality not to be "hardcoded" so to speak.
Re: Overriding spell playing
by mtgrares » 17 Aug 2009, 16:04
I presume you are talking about evoke cards like Briarhorn. In MTG Forge I have two "play" abilities: evoke and non-evoke. That isn't great but it works good enough for me.If I followed the original design, there is no way to combine the 2 additional "play" abilities, since they don't know about the other.
- mtgrares
- DEVELOPER
- Posts: 1352
- Joined: 08 Sep 2008, 22:10
- Has thanked: 3 times
- Been thanked: 12 times
7 posts
• Page 1 of 1
Return to Magic Rules Engine Programming
Who is online
Users browsing this forum: No registered users and 23 guests