It is currently 04 Jun 2020, 11:56
   
Text Size

Overriding spell playing

General Discussion of the Intricacies

Moderator: CCGHQ Admins

Overriding spell playing

Postby 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.
Incantus
DEVELOPER
 
Posts: 267
Joined: 29 May 2008, 15:53
Has thanked: 0 time
Been thanked: 3 times

Re: Overriding spell playing

Postby 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
Author of Dreamblade:
viewtopic.php?f=51&t=1215
User avatar
telengard
DEVELOPER
 
Posts: 374
Joined: 23 May 2009, 23:04
Has thanked: 0 time
Been thanked: 25 times

Re: Overriding spell playing

Postby 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.
User avatar
Arch
Programmer
 
Posts: 206
Joined: 04 Jul 2009, 09:35
Has thanked: 0 time
Been thanked: 15 times

Re: Overriding spell playing

Postby Incantus » 11 Aug 2009, 12:37

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.)
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.
Incantus
DEVELOPER
 
Posts: 267
Joined: 29 May 2008, 15:53
Has thanked: 0 time
Been thanked: 3 times

Re: Overriding spell playing

Postby mtgrares » 11 Aug 2009, 17:33

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

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

Postby Arch » 11 Aug 2009, 18:20

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

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.
User avatar
Arch
Programmer
 
Posts: 206
Joined: 04 Jul 2009, 09:35
Has thanked: 0 time
Been thanked: 15 times

Re: Overriding spell playing

Postby mtgrares » 17 Aug 2009, 16:04

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.
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.
mtgrares
DEVELOPER
 
Posts: 1352
Joined: 08 Sep 2008, 22:10
Has thanked: 3 times
Been thanked: 12 times


Return to Magic Rules Engine Programming

Who is online

Users browsing this forum: No registered users and 1 guest


Who is online

In total there is 1 user online :: 0 registered, 0 hidden and 1 guest (based on users active over the past 10 minutes)
Most users ever online was 1371 on 09 Feb 2020, 16:22

Users browsing this forum: No registered users and 1 guest

Login Form