Page 1 of 1

beginning of upkeep triggered ability that has two effect...

PostPosted: 27 Sep 2017, 23:15
by MTGfan
I'm trying to code Power Leak. My understanding of this card is that it always does damage in the range of 0 to 2 (or more if it is possible to mod the max?) depending on the target cards controller amount spent from 2 or more to 0 to prevent said damage. My first thought is to do this:

this.addAbility(new BeginningOfUpkeepTriggeredAbility(Zone.BATTLEFIELD, new DoIfCostPaid(new DamageAttachedControllerEffect(new IntMinusDynamicValue(2, new ManacostVariableValue())), new VariableManaCost(), "", false), TargetController.CONTROLLER_ATTACHED_TO, false));

However assuming all of that works correctly to assign the correct amount of damage to the target cards controller it doesn't account for the possibility that damage can't be prevented due to some other card effect. Which is the dilemma because the BeginningOfUpkeepTriggeredAbility needs to both do the damage and prevent the damage so that it correctly abides prevention rules and any other applicable rules. But it can only have one effect but two are needed.

Re: beginning of upkeep triggered ability that has two effec

PostPosted: 28 Sep 2017, 15:42
by TheElk801
You should probably do the whole thing as a single OneShotEffect. Here's the template I use for when I do one:

Code: Select all
class className extends OneShotEffect {
   
    className() {
        super(Outcome.Benefit);
        this.staticText = "effect text goes here";
    }
   
    className(final className effect) {
        super(effect);
    }
   
    @Override
    public className copy() {
        return new className(this);
    }
   
    @Override
    public boolean apply(Game game, Ability source) {
//      this is where the effect goes
        return true;
    }
}
Also you can always chat with the devs in our Gitter.

Re: beginning of upkeep triggered ability that has two effec

PostPosted: 30 Sep 2017, 23:33
by MTGfan
Ah so I should encompass both apply damage and prevent damage in a single OneShotEffect such as your example within the DoIfCostPaid. I should be able to handle that.

Re: beginning of upkeep triggered ability that has two effec

PostPosted: 01 Oct 2017, 03:38
by MTGfan
I can't find an example of calling a prevention effect within an one shot effect. So I am still stuck as to how to do both.

Re: beginning of upkeep triggered ability that has two effec

PostPosted: 02 Oct 2017, 20:46
by LevelX
I guess you have to add the prevention effect (as ContinuousEffect) first (checking that it's damage from that Power Leak source). After that do the damage to the controller of the enchanted enchantment.

So in the one shot effect of Power Leak the following things happen:
1) Ask controller for mana payment amount
2) Add the prevention effect to the game
3) Do the damage

Re: beginning of upkeep triggered ability that has two effec

PostPosted: 10 Oct 2017, 02:32
by MTGfan
I have a couple bugs to work out with the card so I think I have it mostly figured out.