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
by 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.
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 ");
}
}
Re: Implement Ability once per turn and in upkeep
by 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.
So simply look how ForecastAbility is implemted.
-
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
by Morfi » 15 Jul 2015, 15:39
Well, I've seen it and it's very very similar to mine.
Mine (assuming true)
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)
Mine (assuming true)
- Code: Select all
game.getStep().getType().equals(PhaseStep.UPKEEP) && game.getActivePlayerId().equals(this.getActivatorId())
- Code: Select all
!game.getActivePlayerId().equals(controllerId) || !PhaseStep.UPKEEP.equals(game.getStep().getType()
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)
Re: Implement Ability once per turn and in upkeep
by LevelX » 15 Jul 2015, 17:00
trueMorfi 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.
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.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)
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.
-
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
by 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.
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 ");
}
}
}
Re: Implement Ability once per turn and in upkeep
by 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.
I can only use the ability in my upkeep and NOT during opponent's upkeep.
-
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
by 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),
Re: Implement Ability once per turn and in upkeep
by LevelX » 16 Jul 2015, 11:15
Did you build the correct project?Morfi wrote:Then I'm lost I still can use it anytime (not only during my opponents turn but also in any phase),
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).
-
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
by 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
It hits the canActivate of the Limited* method
Re: Implement Ability once per turn and in upkeep
by LevelX » 16 Jul 2015, 12:27
No, if youMorfi 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?
1) build the Sets project
2) kill still running server processes
3) start server (in debug mode)
-
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
by 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.
11 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 1 guest