It is currently 11 Sep 2025, 12:54
   
Text Size

Copying a SpellAbility?

Post MTG Forge Related Programming Questions Here

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

Re: Copying a SpellAbility?

Postby zerker2000 » 08 Mar 2010, 07:23

Actually, I think that should be in SpellAbility: getBeforePayMana() should setSource(this) for the value returned.
O forest, hold thy wand'ring son
Though fears assail the door.
O foliage, cloak thy ravaged one
In vestments cut for war.


--Eladamri, the Seed of Freyalise
zerker2000
Programmer
 
Posts: 569
Joined: 09 May 2009, 21:40
Location: South Pasadena, CA
Has thanked: 0 time
Been thanked: 0 time

Re: Copying a SpellAbility?

Postby Rob Cashwalker » 08 Mar 2010, 12:41

Err, I'm confused....
The Force will be with you, Always.
User avatar
Rob Cashwalker
Programmer
 
Posts: 2167
Joined: 09 Sep 2008, 15:09
Location: New York
Has thanked: 5 times
Been thanked: 40 times

Re: Copying a SpellAbility?

Postby zerker2000 » 08 Mar 2010, 12:48

Instead of relying on separate parsing code to do so, simply ensure all returned inputs have the returner set as source...I'm not making this any clearer am I? Basically, add "if(!bforePayMana == null)beforePayMana.setSourceSpellAbility(this);" to SpellAbility.getBeforePayMana().
O forest, hold thy wand'ring son
Though fears assail the door.
O foliage, cloak thy ravaged one
In vestments cut for war.


--Eladamri, the Seed of Freyalise
zerker2000
Programmer
 
Posts: 569
Joined: 09 May 2009, 21:40
Location: South Pasadena, CA
Has thanked: 0 time
Been thanked: 0 time

Re: Copying a SpellAbility?

Postby Rob Cashwalker » 08 Mar 2010, 14:25

still losing me...

The Input class doesn't have a constructor method, as best I can tell. When the CardFactoryUtil functions return an Input object for the setBeforePayMana method, no code has actually been executed yet.
In my understanding, if there was a constructor method, and it was overridable, then any code contained therein would execute. Normally, no code would execute (the default constructor). But the CardFactoryUtil.Input_ functions would include a constructor that took the spell parameter and set it with "Input.setSourceSA"
The Force will be with you, Always.
User avatar
Rob Cashwalker
Programmer
 
Posts: 2167
Joined: 09 Sep 2008, 15:09
Location: New York
Has thanked: 5 times
Been thanked: 40 times

Re: Copying a SpellAbility?

Postby mtgrares » 08 Mar 2010, 22:12

Hopefully this helps a little but feel free to disregard it if it doesn't.

The "guts" of the program (somewhere in GameAction.playCard(Card) or something similar, see Input_Main1 which will show you) checks to see if SpellAbility.setBeforePayMana() returns null or not. If null the program goes on but if not null then that Input is used, typically to choose targets or any decision that is done before the SpellAbility is put on the stack.

The method Input.getMessage() is always going to be the first method called so it can act like a constructor.
mtgrares
DEVELOPER
 
Posts: 1352
Joined: 08 Sep 2008, 22:10
Has thanked: 3 times
Been thanked: 12 times

Re: Copying a SpellAbility?

Postby Rob Cashwalker » 09 Mar 2010, 04:34

Hmmm... so maybe that would take care of the version of the Input that the normal Spell will use. Then the buyback version will reassign the SourceSA....
The Force will be with you, Always.
User avatar
Rob Cashwalker
Programmer
 
Posts: 2167
Joined: 09 Sep 2008, 15:09
Location: New York
Has thanked: 5 times
Been thanked: 40 times

Re: Copying a SpellAbility?

Postby zerker2000 » 09 Mar 2010, 07:33

I was just saying, why not have the SpellAbility reassign the sourceSA(to itself) on return?
O forest, hold thy wand'ring son
Though fears assail the door.
O foliage, cloak thy ravaged one
In vestments cut for war.


--Eladamri, the Seed of Freyalise
zerker2000
Programmer
 
Posts: 569
Joined: 09 May 2009, 21:40
Location: South Pasadena, CA
Has thanked: 0 time
Been thanked: 0 time

Re: Copying a SpellAbility?

Postby Rob Cashwalker » 14 Mar 2010, 14:44

zerker2000 wrote:I was just saying, why not have the SpellAbility reassign the sourceSA(to itself) on return?
OK, so I looked at all the static input_ mthods in CardFactoryUtil. I found that almost all of them declare a new Input, then return it. So there is a point where I can squeeze in the setSourceSA. Except for this one:
Code: Select all
    public static Input input_targetValid(final SpellAbility sa, final String[] Tgts, final String message)
    {
       return new Input() {
        private static final long serialVersionUID = -142142142142L;
       
        @Override
        public void showMessage() {
            CardList allCards = new CardList();
...
It just needs to be tweaked to be like this:
Code: Select all
    public static Input input_targetSpecific(final SpellAbility spell, final CardList choices, final String message, final Command paid, final boolean targeted, final boolean free) {
        Input target = new Input() {
            private static final long serialVersionUID = -1779224307654698954L;
           
            @Override
            public void showMessage() {
                AllZone.Display.showMessage(message);
...
...
        return target;
    }//input_targetSpecific()
And then all of them get this tweak at the end:
Code: Select all
...
      target.setSourceSA(sa);
      return target;
    }//some type of target input
Also making sure to change the code to reference getSourceSA instead of the passed parameter.
The Force will be with you, Always.
User avatar
Rob Cashwalker
Programmer
 
Posts: 2167
Joined: 09 Sep 2008, 15:09
Location: New York
Has thanked: 5 times
Been thanked: 40 times

Re: Copying a SpellAbility?

Postby nantuko84 » 14 Mar 2010, 17:17

all this Input code...
this was the first thing I changed when started migrating MTGForge architecture to MagicWars
actually I don't like the idea that Input (that is view in Modal-View-Controller architecture) goes with the card so at that time I replaced them with code like spellAbility.setNeedsTargetCreature(true) that is on server side, calling Input later on client side. I believe that was the reason why it was so easy to implement copy spellAbility stuff
nantuko84
DEVELOPER
 
Posts: 266
Joined: 08 Feb 2009, 21:14
Has thanked: 2 times
Been thanked: 9 times

Re: Copying a SpellAbility?

Postby mtgrares » 15 Mar 2010, 19:11

That is interesting nantuko. You did a good job of porting Forge's code into a client-server archetecture.

You can't really copy Card or SpellAbility objects, you can only get new ones from CardFactory. In order to get a card like Clone to work, you just have to get a new copy of the card from CardFactory. When cards are put into the graveyard they are "cloned", ie. a new copy is made by getting a new object from CardFactory and then calling Card.setUniqueID(int) with the same number as the card you are copying.

CardFactory could be refactored and you could put redundant code could be put somewhere else. InputFactory could handle creating and returned all inputs, InputFactory.getInput("target nonland") and ResolveFactory would return Command objects that would be used by SpellAbility.resolve().
mtgrares
DEVELOPER
 
Posts: 1352
Joined: 08 Sep 2008, 22:10
Has thanked: 3 times
Been thanked: 12 times

Re: Copying a SpellAbility?

Postby Rob Cashwalker » 16 Mar 2010, 03:21

Baby steps, Rares, baby steps..

Cloning the SpellAbility seems to work just fine, with the caveats we've uncovered here.

Cloning a card in Magic is different because the clone copies the printed card, not any added attributes.

CardFactoryUtil holds a lot of assorted code, and probably should be broken up along the lines you're suggesting.
We have quite a number of Ability generators. (which I need to learn to use, because my keyword code has been done entirely in CardFactory, while much of everyone else's has been in these generators...)
We have a handful of Input generators.
We have a bunch of AI stuff.
And all the really assorted stuff.
The Force will be with you, Always.
User avatar
Rob Cashwalker
Programmer
 
Posts: 2167
Joined: 09 Sep 2008, 15:09
Location: New York
Has thanked: 5 times
Been thanked: 40 times

Re: Copying a SpellAbility?

Postby mtgrares » 18 Mar 2010, 19:02

Rob Cashwalker wrote:Baby steps, Rares, baby steps..
I try to help but I'm just the "old guy" that doesn't do much coding nowadays. :lol:

I'm only 31 so I'm just having a good laugh at myself. I'm not old until I'm 32 (joke).

You guys probably understand the code (and its limitations) as much as I do.
mtgrares
DEVELOPER
 
Posts: 1352
Joined: 08 Sep 2008, 22:10
Has thanked: 3 times
Been thanked: 12 times

Re: Copying a SpellAbility?

Postby Rob Cashwalker » 18 Mar 2010, 20:29

Watch it.. I'm 32....
The Force will be with you, Always.
User avatar
Rob Cashwalker
Programmer
 
Posts: 2167
Joined: 09 Sep 2008, 15:09
Location: New York
Has thanked: 5 times
Been thanked: 40 times

Re: Copying a SpellAbility?

Postby mtgrares » 19 Mar 2010, 17:44

32 years young :)

Age and money are just numbers. All code is just 1s and 0s anyways, ha.
mtgrares
DEVELOPER
 
Posts: 1352
Joined: 08 Sep 2008, 22:10
Has thanked: 3 times
Been thanked: 12 times

Re: Copying a SpellAbility?

Postby Rob Cashwalker » 19 Mar 2010, 21:57

mtgrares wrote:32 years young :)

Age and money are just numbers. All code is just 1s and 0s anyways, ha.
So in that case, I'm 10000....
The Force will be with you, Always.
User avatar
Rob Cashwalker
Programmer
 
Posts: 2167
Joined: 09 Sep 2008, 15:09
Location: New York
Has thanked: 5 times
Been thanked: 40 times

PreviousNext

Return to Developer's Corner

Who is online

Users browsing this forum: No registered users and 47 guests

Main Menu

User Menu

Our Partners


Who is online

In total there are 47 users online :: 0 registered, 0 hidden and 47 guests (based on users active over the past 10 minutes)
Most users ever online was 7967 on 09 Sep 2025, 23:08

Users browsing this forum: No registered users and 47 guests

Login Form