Implement Ability once per turn and in upkeep
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 ");
}
}