It is currently 24 Apr 2024, 13:46
   
Text Size

Implement Ability once per turn and in upkeep

Moderators: North, BetaSteward, noxx, jeffwadsworth, JayDi, TheElk801, LevelX, CCGHQ Admins

Implement Ability once per turn and in upkeep

Postby Morfi » 15 Jul 2015, 14:32

It's my first implementation.
So I'm trying to implement activated ability that can be triggered only once per turn and only during owner's upkeep.

I found that there is Conditional Ability and Limited Times per turn ability but not both.
What I did is I extended Limited Times AA and overrode canActivate, however I can still activate it in any phase and in my opponents turn.

Code: Select all
class GateToPhyrexiaActivatedAbility extends LimitedTimesPerTurnActivatedAbility
{
   public GateToPhyrexiaActivatedAbility()
   {
      super(Zone.BATTLEFIELD,
         new DestroyTargetEffect(),
         new SacrificeTargetCost(new TargetControlledCreaturePermanent()));
   }
   
   @Override
   public boolean canActivate(UUID playerId, Game game)
   {
      if (super.canActivate(playerId, game))
      {
         return game.getStep().getType().equals(PhaseStep.UPKEEP) && game.getActivePlayerId().equals(this.getActivatorId());
      }
      return false;
   }
   
   @Override
   public String getRule()
   {
      return super.getRule().replace("Activate this ability", "Activate this ability only during your upkeep and ");
   }
}
User avatar
Morfi
 
Posts: 28
Joined: 04 Feb 2014, 00:22
Has thanked: 0 time
Been thanked: 2 times

Re: Implement Ability once per turn and in upkeep

Postby LevelX » 15 Jul 2015, 15:32

A search for "Activate this ability only during your upkeep and only" in the rule filter field in the card tracker (http://ct-magefree.rhcloud.com/cards) shows that Forecast has exactly the same wording as rule reminder.

So simply look how ForecastAbility is implemted.
User avatar
LevelX
DEVELOPER
 
Posts: 1677
Joined: 08 Dec 2011, 15:08
Has thanked: 174 times
Been thanked: 374 times

Re: Implement Ability once per turn and in upkeep

Postby Morfi » 15 Jul 2015, 15:39

Well, I've seen it and it's very very similar to mine.

Mine (assuming true)
Code: Select all
game.getStep().getType().equals(PhaseStep.UPKEEP) && game.getActivePlayerId().equals(this.getActivatorId())
Forecast (assuming false):
Code: Select all
!game.getActivePlayerId().equals(controllerId) || !PhaseStep.UPKEEP.equals(game.getStep().getType()
Even though I'm using this.getActivatorId() and forecast is using controllerId, it still doesn't explain why my code allowed it to activate during opponent's turn if condition regarding Phase is the same as in forecast.

EDIT:
After implementing the forecast code, problem persists.

Or maybe I'm simply not updating the card correctly to test. What I do is:
1. Delete files from Mage.Server\db
2. Delete files from Mage.Client\db
3. Clean & Build Mage.Sets
4. Run Mage.Server and Mage.Client (no rebuilds)
User avatar
Morfi
 
Posts: 28
Joined: 04 Feb 2014, 00:22
Has thanked: 0 time
Been thanked: 2 times

Re: Implement Ability once per turn and in upkeep

Postby LevelX » 15 Jul 2015, 17:00

Morfi wrote:Even though I'm using this.getActivatorId() and forecast is using controllerId, it still doesn't explain why my code allowed it to activate during opponent's turn if condition regarding Phase is the same as in forecast.
true
Morfi wrote:EDIT:
After implementing the forecast code, problem persists.

Or maybe I'm simply not updating the card correctly to test. What I do is:
1. Delete files from Mage.Server\db
2. Delete files from Mage.Client\db
3. Clean & Build Mage.Sets
4. Run Mage.Server and Mage.Client (no rebuilds)
1 & 2 you only need if you want to change the text in the DB so not always needed. Does not change anything in how it works.
3. Only build is enough

And you did really kill the running server.
Happens sometimes, that I forget to kill the old server start the new one that won't run with port already used and wonder why the chnage does not apply.
User avatar
LevelX
DEVELOPER
 
Posts: 1677
Joined: 08 Dec 2011, 15:08
Has thanked: 174 times
Been thanked: 374 times

Re: Implement Ability once per turn and in upkeep

Postby Morfi » 15 Jul 2015, 17:33

It was running in the IDE so I just shut it down using stop symbol (red square).
For now, I'll post whole class (it's not big), perhaps I did some idiotic mistake and I don't see.

Code: Select all
public class GateToPhyrexia extends CardImpl {

    public GateToPhyrexia(UUID ownerId) {
        super(ownerId, 82, "Gate to Phyrexia", Rarity.UNCOMMON, new CardType[]{CardType.ENCHANTMENT}, "{B}{B}");
        this.expansionSetCode = "ME4";

      // Sacrifice a creature: Destroy target artifact. Activate this ability only during your upkeep and only once each turn.
      Ability ability = new GateToPhyrexiaActivatedAbility();
      ability.addTarget(new TargetPermanent(new FilterArtifactPermanent()));
      this.addAbility(ability);
    }

    public GateToPhyrexia(final GateToPhyrexia card) {
        super(card);
    }

    @Override
    public GateToPhyrexia copy() {
        return new GateToPhyrexia(this);
    }
   
   class GateToPhyrexiaActivatedAbility extends LimitedTimesPerTurnActivatedAbility
   {
      public GateToPhyrexiaActivatedAbility()
      {
         super(Zone.BATTLEFIELD,
            new DestroyTargetEffect(),
            new SacrificeTargetCost(new TargetControlledCreaturePermanent()));
      }
      
      @Override
      public boolean canActivate(UUID playerId, Game game)
      {
         // May be activated only during the upkeep step of the card's owner
         if (!game.getActivePlayerId().equals(controllerId) || !PhaseStep.UPKEEP.equals(game.getStep().getType()))
         {
            return false;
         }
         return super.canActivate(playerId, game);
         
         /*if (super.canActivate(playerId, game))
         {
            return game.getStep().getType().equals(PhaseStep.UPKEEP) && game.getActivePlayerId().equals(this.getActivatorId());
         }
         return false;*/
      }
      
      @Override
      public String getRule()
      {
         return super.getRule().replace("Activate this ability", "Activate this ability only during your upkeep and ");
      }
   }
}
User avatar
Morfi
 
Posts: 28
Joined: 04 Feb 2014, 00:22
Has thanked: 0 time
Been thanked: 2 times

Re: Implement Ability once per turn and in upkeep

Postby LevelX » 16 Jul 2015, 07:48

I tested your code last posted. Does work correctly.

I can only use the ability in my upkeep and NOT during opponent's upkeep.
User avatar
LevelX
DEVELOPER
 
Posts: 1677
Joined: 08 Dec 2011, 15:08
Has thanked: 174 times
Been thanked: 374 times

Re: Implement Ability once per turn and in upkeep

Postby Morfi » 16 Jul 2015, 11:02

Then I'm lost :( I still can use it anytime (not only during my opponents turn but also in any phase),
User avatar
Morfi
 
Posts: 28
Joined: 04 Feb 2014, 00:22
Has thanked: 0 time
Been thanked: 2 times

Re: Implement Ability once per turn and in upkeep

Postby LevelX » 16 Jul 2015, 11:15

Morfi wrote:Then I'm lost :( I still can use it anytime (not only during my opponents turn but also in any phase),
Did you build the correct project?
What happens if you debug the canActivate method of GateToPhyrexiaActivatedAbility?

If you debug you have to see exactly what's wrong (also if you are debugging a program different from the source code you see).
User avatar
LevelX
DEVELOPER
 
Posts: 1677
Joined: 08 Dec 2011, 15:08
Has thanked: 174 times
Been thanked: 374 times

Re: Implement Ability once per turn and in upkeep

Postby Morfi » 16 Jul 2015, 12:05

It never hits this method. I believe that the server is still using some old Mage Sets, even though both were rebuilt. Any caching system that may cause that?
It hits the canActivate of the Limited* method
User avatar
Morfi
 
Posts: 28
Joined: 04 Feb 2014, 00:22
Has thanked: 0 time
Been thanked: 2 times

Re: Implement Ability once per turn and in upkeep

Postby LevelX » 16 Jul 2015, 12:27

Morfi wrote:It never hits this method. I believe that the server is still using some old Mage Sets, even though both were rebuilt. Any caching system that may cause that?
No, if you
1) build the Sets project
2) kill still running server processes
3) start server (in debug mode)
User avatar
LevelX
DEVELOPER
 
Posts: 1677
Joined: 08 Dec 2011, 15:08
Has thanked: 174 times
Been thanked: 374 times

Re: Implement Ability once per turn and in upkeep

Postby Morfi » 16 Jul 2015, 12:30

I tried to record the screen and I got bluscreen while the video was nearly completed. I need to take a deep breath before I smash the screen with the keyboard. :evil: :evil: :evil:
User avatar
Morfi
 
Posts: 28
Joined: 04 Feb 2014, 00:22
Has thanked: 0 time
Been thanked: 2 times


Return to Developers Talk

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 4143 on 23 Jan 2024, 08:21

Users browsing this forum: No registered users and 1 guest

Login Form