Page 1 of 1

Return value of effect.apply()

PostPosted: 15 Jul 2014, 11:11
by LevelX
When exactly should the
public boolean apply(Game game, Ability source)
method of the effect give back false?

I would say only in a situation where something happened what couldn't happen normally if no bug is involved.

Example for false:
1) game.getPlayer(ability.getControllerId) gives back null;
2) MageObject sourceObject = game.getObject(source.getSourceId()) gives back null;


Examples for true:
3) All works as intended (that's clear).
2) Counterspell tries to counter a spell but was replaced.
3) Add a counter to source but source is bounced back to hand before the effect resolves.

But that's only my opinion.
Any other opinions or ideas how to handle this best?

Re: Return value of effect.apply()

PostPosted: 14 Aug 2014, 07:56
by LevelX
Any opinions on that topic?

Here an practical example:
Code: Select all
class SkredDamageEffect extends OneShotEffect {

    private static final FilterControlledPermanent filter = new FilterControlledPermanent("equal to the number of snow permanents you control.");
    static {
        filter.add(new SupertypePredicate("Snow"));
    }
   
    public SkredDamageEffect() {
        super(Outcome.Damage);
        this.staticText = "{this} deals damage to target creature equal to the number of snow permanents you control.";
    }

    public SkredDamageEffect(final SkredDamageEffect effect) {
        super(effect);
    }

    @Override
    public SkredDamageEffect copy() {
        return new SkredDamageEffect(this);
    }

    @Override
    public boolean apply(Game game, Ability source) {
        int amount = game.getBattlefield().count(filter, source.getSourceId(), source.getControllerId(), game);
        Permanent permanent = game.getPermanent(targetPointer.getFirst(game, source));
        if(amount > 0) {   
            if (permanent != null) {
                permanent.damage(amount, source.getSourceId(), game, false, true);
                return true;
            }
        }
        return false;
    }
}
I would probably implement the apply method in this way:
Code: Select all
    @Override
    public boolean apply(Game game, Ability source) {
        int amount = game.getBattlefield().count(filter, source.getSourceId(), source.getControllerId(), game);
        Permanent permanent = game.getPermanent(targetPointer.getFirst(game, source));
        if(amount > 0 && permanent != null) {   
            permanent.damage(amount, source.getSourceId(), game, false, true);
        }
        return true;
    }
Because both checked things are perfectly normal conditions that can happen without a problem for the game.
1) You can have no Snow permanents on the battlefield.
2) The permanent can have left the battlefield since the spell went to stack.

So the questions stays, what does the return state mean for the apply method?