Game Modification - How to Use the 'GenericTargetAbility'?

If you have a question about the SVN and the code, or if you have code to propose then please post in this forum.
Do not post request here.

Game Modification - How to Use the 'GenericTargetAbility'?

Postby rodrigo.demoura » Wed May 18, 2011 10:02 pm

Advertising
I am making some Modifications to adapting The source code for pokemon tcg Wagic to play.

On the rules of the games I have to choose the creature for battle. and I Can not change EVERY turn. To change the creature I have to pay the cost.

So I need to check each turn if the player no longer has an active creature to fight.

For this I created these rules

Rule on MTG
Code: Select all
auto=@each my combatbegins:activepokemon


On AllAbilities.cpp

Code: Select all
AActivePokemon::AActivePokemon(int _id, MTGCardInstance * source, MTGCardInstance * _target):
    MTGAbility(_id, source, _target)
{
   _tg = _target;

}

    int AActivePokemon::addToGame()
    {
      Player * player;
      player = game->currentPlayer;
           
      MTGGameZone * zone = player->game->inPlay;
      MTGCardInstance * icard;
      int ifind = 0;
      for (int k = zone->nb_cards - 1; k >= 0; k--)
        {
            MTGCardInstance * _card = zone->cards[k];
            if (_card->isActive())
            {
                return 0;
            }
         if (_card->isCreature())
         {
            icard = _card;
            ifind = 1;
         }
       }
      if (zone->nb_cards == 0 || ifind == 0)return 0;
      
      
      TargetChooserFactory tcf;
      tc = tcf.createTargetChooser("creature|myBattlefield", NULL);
      ManaCost * _cost = new ManaCost();
      _cost->add(0,0);
        MTGAbility * a = new AActiveRetrace(icard->getId(), icard, _tg,1);
      MTGAbility * tr = new GenericTargetAbility(icard->getId(),icard, tc,a,_cost);
      tr->reactToTargetClick(icard);

        return MTGAbility::addToGame();
    }

AActiveRetrace::AActiveRetrace(int _id,MTGCardInstance * source, MTGCardInstance * _target, int iactive):
    MTGAbility(_id, source, _target)
{
   _active = iactive;
   _tg = _target;

}
   int AActiveRetrace::reactToTargetClick(Targetable * object)
   {
      _tg = (MTGCardInstance *)object;
      if (_tg)
        {
         if (_active == 1)
            _tg->addType(Subtypes::TYPE_ACTIVE);
         else
            _tg->removeType(Subtypes::TYPE_ACTIVE);
            return 1;
        }

   }



With the code above I'm not making it through to the target "AActiveRetrace"

What am I doing wrong?
I'm using the svn version 15
rodrigo.demoura
 
Posts: 46
Joined: Wed Jun 02, 2010 6:31 pm

Re: Game Modification - How to Use the 'GenericTargetAbility

Postby wololo » Sat May 21, 2011 9:20 am

There are two types of abilities: the ones that "stay" in game for some time, and the ones that act only once. An example of an ability that acts only once is "draw a card".
These abilities are identified with a variable "oneShot" that is set to "1" by the engine.

Internally, abilities that have oneShot set to 1 will never call the function "addToGame", instead they will call the function "resolve". Inversely, the abilities that have oneShot set to 0 will call addToGame.
So that's the first thing you need to verify.

If you DO enter the addToGame function, he rest can probably be figured out with a few breakpoints.

There are many reasons reactToTargetclick(icard) might not work. The game checks for many things that might not make sense in your context. You will need to add breakpoints in the functions to see where it is not going through.

I'm sorry I can't help more :cry:
wololo
Site Admin
 
Posts: 3716
Joined: Wed Oct 15, 2008 12:42 am
Location: Japan

Re: Game Modification - How to Use the 'GenericTargetAbility

Postby Zethfox » Sat May 21, 2011 11:14 am

heres what i don't understand, from what im seeing here, this does only one thing, give the type "active" to a creature. why are you reinventing the wheel?

theres many ways to give a subtype, heres an example of one....

auto=@each my combatbegins:name(whatever you want to call this) target(creature[-active]) transforms((active)) ueot

this does EXACTLY what you are coding here....if this is not what its supposed to do then i can clearly tell you without a doubt that you are going about this game rule completely wrong.
Zethfox
 
Posts: 2814
Joined: Thu Jun 10, 2010 11:28 pm

Re: Game Modification - How to Use the 'GenericTargetAbility

Postby wololo » Sat May 21, 2011 12:17 pm

Zethfox wrote:auto=@each my combatbegins:name(whatever you want to call this) target(creature[-active]) transforms((active)) ueot

this does EXACTLY what you are coding here....if this is not what its supposed to do then i can clearly tell you without a doubt that you are going about this game rule completely wrong.

That's not exactly what the code does. It seems to be looking for a card at the beginning of each turn, take the first "valid" target creature, and mark it as active if it's not already active. It's not like the user gets to choose a card at any time of the process, in the code posted by rodrigo, so I'm not sure your suggestion works.
wololo
Site Admin
 
Posts: 3716
Joined: Wed Oct 15, 2008 12:42 am
Location: Japan

Re: Game Modification - How to Use the 'GenericTargetAbility

Postby Zethfox » Sat May 21, 2011 1:06 pm

he is activating this as a trigger....

auto=@each my combatbegins:activepokemon
see....

theres so many ways this is incorrect...he logic is not handled correctly for what this is supposed to be...

at all times both players have to have 1 pokemon that is active...when a player has no more pokemon to make active they lose the game...

this should be handled in the mtgrule.cpp as a game rule....not coded into a trigger....becuase what happens if i have a pokemon that is not active....but during "combat" my active one dies....

i lose the game...which is incorrect....
becuase we won't have a chance to set another active pokemon til the next combat...

i was not incorrect in my thought....he is recreating the wheel, and doing it incorrectly.....i did not at all suggest that my code suggestion was correct....i simply suggested that the EXACT thing hes code is doing is already supported....


Code: Select all
   
      TargetChooserFactory tcf;
      tc = tcf.createTargetChooser("creature|myBattlefield", NULL);
      ManaCost * _cost = new ManaCost();
      _cost->add(0,0);
        MTGAbility * a = new AActiveRetrace(icard->getId(), icard, _tg,1);
      MTGAbility * tr = new GenericTargetAbility(icard->getId(),icard, tc,a,_cost);
      tr->reactToTargetClick(icard);


this section for example is absolutely useless....he is going to be activating this with a trigger...use
auto=@blah: target(creature|mybattlefield)

if it is supposed to have a cost, which having an active pokemon is not something that cost anything, you either have one or lose the game.
then lord the ability with a cost to the creatures, instead of attaching it to a trigger....
Code: Select all
  int AActivePokemon::addToGame()
    {
      Player * player;
      player = game->currentPlayer;
           
      MTGGameZone * zone = player->game->inPlay;
      MTGCardInstance * icard;
   [b]   int ifind = 0;
      for (int k = zone->nb_cards - 1; k >= 0; k--)
        {
            MTGCardInstance * _card = zone->cards[k];
            if (_card->isActive())
            {
                return 0;
            }
         if (_card->isCreature())
         {
            icard = _card;
            ifind = 1;
         }
       }
      if (zone->nb_cards == 0 || ifind == 0)return 0;[/b]

he added this becuase he is force creating a TC, and if he didn't have this useless section of code it would lock him in a targetchooser with no way out...so lets review the parts that can be handled with "target(creature|mybattlefield)"

ill edit the code removing the useless things....

Code: Select all
AActivePokemon::AActivePokemon(int _id, MTGCardInstance * source, MTGCardInstance * _target):
    MTGAbility(_id, source, _target)
{
   _tg = _target;

}

    int AActivePokemon::addToGame()
    {
      Player * player;
      player = game->currentPlayer;
           
      MTGGameZone * zone = player->game->inPlay;
        return MTGAbility::addToGame();
    }

AActiveRetrace::AActiveRetrace(int _id,MTGCardInstance * source, MTGCardInstance * _target, int iactive):
    MTGAbility(_id, source, _target)
{
   _active = iactive;
   _tg = _target;

}
   int AActiveRetrace::reactToTargetClick(Targetable * object)
   {
      _tg = (MTGCardInstance *)object;
      if (_tg)
        {
         if (_active == 1)
            _tg->addType(Subtypes::TYPE_ACTIVE);
         else
            _tg->removeType(Subtypes::TYPE_ACTIVE);
            return 1;
        }

   }


ok moving forward we are left with an ability that give the card "active" as a type....hmmmmm transforms((active))...lets further edit out useless stuff....
Code: Select all
AActivePokemon::AActivePokemon(int _id, MTGCardInstance * source, MTGCardInstance * _target):
    MTGAbility(_id, source, _target)
{
   _tg = _target;

}

    int AActivePokemon::addToGame()
    {
      Player * player;
      player = game->currentPlayer;
           
      MTGGameZone * zone = player->game->inPlay;
        return MTGAbility::addToGame();
    }

AActiveRetrace::AActiveRetrace(int _id,MTGCardInstance * source, MTGCardInstance * _target, int iactive):
    MTGAbility(_id, source, _target)
{
   _active = iactive;
   _tg = _target;

}
   int AActiveRetrace::reactToTargetClick(Targetable * object)
   {
      _tg = (MTGCardInstance *)object;

        }

   }


now wololo...tell me again that what i used was not EXACTLY what his ability was doing?
or did you miss the part where he stated the use of this ability? this is why you don't "half read" things...you end up being super wrong.....

this needs to be a game rule....not an ability i have already told him exactly where and how to handle this.....yet he choose to repost in a new thread the same exact thing....if he openly ignores the dev that has been actively adding abilities and rules for over a year now at an extremely alarming rate, i will simply begin locking his threads and moving them to achieves...

to me its like hes asking for help, then you go as far as give him exact code...he then comes back with something completely different from what you suggested....so what is the point in helping someone or wasting time trying to suggest anything to help the code when he won't take any of the suggestions AT ALL....to me, it just becomes useless forum noise.....
Zethfox
 
Posts: 2814
Joined: Thu Jun 10, 2010 11:28 pm

Re: Game Modification - How to Use the 'GenericTargetAbility

Postby wololo » Sat May 21, 2011 1:25 pm

Zethfox wrote:to me its like hes asking for help, then you go as far as give him exact code...he then comes back with something completely different from what you suggested....so what is the point in helping someone or wasting time trying to suggest anything to help the code when he won't take any of the suggestions AT ALL....to me, it just becomes useless forum noise.....

Please be a bit more patient. rodrigo's the first person trying to extend the code into handling more than MTG. Nobody's done that before, it's not a simple task. I understand that you get nervous if you've told him how to do a few things already, but no need to go rampage on this ;) . We're all learning from this, please keep that in mind.
wololo
Site Admin
 
Posts: 3716
Joined: Wed Oct 15, 2008 12:42 am
Location: Japan

Re: Game Modification - How to Use the 'GenericTargetAbility

Postby Zethfox » Sat May 21, 2011 8:48 pm

i actually am being patient...trust me, if i lost my patient i wouldn't even bother to reply to his messages.....
Zethfox
 
Posts: 2814
Joined: Thu Jun 10, 2010 11:28 pm

Re: Game Modification - How to Use the 'GenericTargetAbility

Postby wololo » Sun May 22, 2011 1:55 am

hmm, ok, maybe something happened in PMs that I didn't see then.
Rodrigo, does the detailed answer by Zethfox help? As he said, there has to be a simpler way to do what you want. We never call the function "reactTocCick" from our abilities, we usually let the engine do that, so it is surprising that you do it this way.

If Zeth's answers don't help you, can you describe what you *think* your code does? Maybe we can help more based on that?
wololo
Site Admin
 
Posts: 3716
Joined: Wed Oct 15, 2008 12:42 am
Location: Japan

Re: Game Modification - How to Use the 'GenericTargetAbility

Postby rodrigo.demoura » Mon May 23, 2011 9:54 pm

Zeth,
Thanks for the reply.

Your suggestions were really the best way to code.

What I wanted to do was increase the code to perform other functions together.

I'll look better in the code to create the best possible way.

Please close this Topic

Sorry if I acted invasively. :oops:
rodrigo.demoura
 
Posts: 46
Joined: Wed Jun 02, 2010 6:31 pm

Advertising


Return to SVN & Programmers' section

Who is online

Users browsing this forum: No registered users and 1 guest