It is currently 04 Sep 2025, 03:48
   
Text Size

Ability Controller Work

Post MTG Forge Related Programming Questions Here

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

Ability Controller Work

Postby friarsol » 16 Jul 2010, 19:01

So I was looking to adding some of the cards that any player can activate, such as Volrath's Dungeon, but it seems there's an intermediary step that needs to be done. I think I should be able to manage it, but figured I'd see if anyone has looked into this (or if rares knows a good place to start unraveling the knot) before I started.

Basically the problem boils down to that (a lot of) cards assume that whoever controls the card is the same person who is activating the ability. While this is the case 98% of the time, there are a few situations where this isn't actually the case. The first, as stated above, is cards like Aluren, AEther Storm, and a bunch of crappy cards from Masques cycle. According to magiccards.info, there are 53 cards that use the phrase "any player may." Some of these are the "extortion" spells which can be handled differently, but for permanents there needs to be a clear distinction between card controller and ability controller.

The other situation is: I activate an ability that is non-targeting like creating a token. Then I lose control of the permanent creating the token while the ability is on the stack. When the ability resolves, the current controller of the card is the one gaining the token.

If you want to see this in action, make the following decks.
8 Island, 4 Old Man of the Sea.
8 Mountain, 4 Rakka Mar.

You play the Old Man deck, let the computer play Rakka.
Cast your Old Man on turn 3, let your opponent cast his Rakka on turn 4.
Now don't activate your Old Man until after he activates his Rakka on turn 5. You will sucessfully steal Rakka and the token your opponent paid to generate.

So yea, just let me know if anyone has looked into this before, or anything of the like. My current dive in point is GameAction.playCard but maybe there's a better spot.

Thanks
Sol.
friarsol
Global Moderator
 
Posts: 7593
Joined: 15 May 2010, 04:20
Has thanked: 243 times
Been thanked: 965 times

Re: Ability Controller Work

Postby DennisBergkamp » 16 Jul 2010, 22:52

Whoa, yeah this is tricky stuff.... I've looked at that exact code at times, but it's been awhile.

The problem for the token creation part is that it's checked on resolution. We would somehow have to finalize the controller of the token right as it's being put on the stack.
I'd have to think about this one...
User avatar
DennisBergkamp
AI Programmer
 
Posts: 2602
Joined: 09 Sep 2008, 15:46
Has thanked: 0 time
Been thanked: 0 time

Re: Ability Controller Work

Postby friarsol » 17 Jul 2010, 04:20

So I've added a variable that sets itself as the Ability Controller when the ability is activated. The goal is to check spellAbility.getActivatingPlayer() instead of the card.getController() whenever ANY ability requires it. This will probably affect lots and lots of cards. My local copy of the SVN has fixed my sample problem of Rakka Mar, by using the following function along with the getActivatingPlayer() call:

Code: Select all
public static CardList makeToken(String name, String imageName, String controller, String manaCost, String[] types, int baseAttack, int baseDefense, String[] intrinsicKeywords) {
instead of

Code: Select all
public static CardList makeToken(String name, String imageName, Card source, String manaCost, String[] types, int baseAttack, int baseDefense, String[] intrinsicKeywords) {
Since the first function already existed, it was pretty painless to just send in the ability, and it was mostly just finding the two bottlenecks to set the activating player appropriately.

So instead of sending in the source of the card, I'll be sending in the activating player. Unfortunately, there's 150+ cards that use the Card source function for making tokens alone. So I'll slowly be switching things over to use the new method. Maybe I'll just do a handful of cases for the first submission. And hopefully over a decent amount of time the rest will get swapped, tested and fixed.
friarsol
Global Moderator
 
Posts: 7593
Joined: 15 May 2010, 04:20
Has thanked: 243 times
Been thanked: 965 times

Re: Ability Controller Work

Postby DennisBergkamp » 17 Jul 2010, 05:31

Hey, that's cool, and it looks like that'll do the trick :)

It reminds me of when I started adding protection functionality, I had to add canTarget(source, target) checks all over the place... it took hours.
150+ cards is not THAT many, let me tell you. I wouldn't mind helping either 8)
User avatar
DennisBergkamp
AI Programmer
 
Posts: 2602
Joined: 09 Sep 2008, 15:46
Has thanked: 0 time
Been thanked: 0 time


Return to Developer's Corner

Who is online

Users browsing this forum: No registered users and 25 guests

Main Menu

User Menu

Our Partners


Who is online

In total there are 25 users online :: 0 registered, 0 hidden and 25 guests (based on users active over the past 10 minutes)
Most users ever online was 7303 on 15 Jul 2025, 20:46

Users browsing this forum: No registered users and 25 guests

Login Form