It is currently 23 Apr 2024, 18:52
   
Text Size

Return value of effect.apply()

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

Return value of effect.apply()

Postby LevelX » 15 Jul 2014, 11:11

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?
User avatar
LevelX
DEVELOPER
 
Posts: 1677
Joined: 08 Dec 2011, 15:08
Has thanked: 174 times
Been thanked: 374 times

Re: Return value of effect.apply()

Postby LevelX » 14 Aug 2014, 07:56

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?
User avatar
LevelX
DEVELOPER
 
Posts: 1677
Joined: 08 Dec 2011, 15:08
Has thanked: 174 times
Been thanked: 374 times


Return to Developers Talk

Who is online

Users browsing this forum: No registered users and 14 guests


Who is online

In total there are 14 users online :: 0 registered, 0 hidden and 14 guests (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 14 guests

Login Form