foul-magics/Mage/src/main/java/mage/abilities/effects/common/EntersBattlefieldWithXCountersEffect.java
Evan Kranzler a535cb5adc
Refactoring methods which add counters to track which player adds the counters (ready for review) (#7448)
* added parameter for player adding counters to players

* added parameter for player adding counters to cards/permanents

* updated methods to use new parameter

* fixed a few initial errors

* refactored instances of cards that add counters by a player other than the controller

* fixed some instances of incorrect arguments

* refactored abilities that trigger off of a particular player adding counters

* a few more cards that were missed

* [KHM] Implemented Vorinclex, Monstrous Raider

* added test for Vorinclex, Monstrous Raider

* fixed a test failure
2021-01-26 19:06:13 -05:00

70 lines
2.5 KiB
Java

package mage.abilities.effects.common;
import mage.abilities.Ability;
import mage.abilities.SpellAbility;
import mage.abilities.effects.EntersBattlefieldEffect;
import mage.abilities.effects.OneShotEffect;
import mage.constants.AbilityType;
import mage.constants.Outcome;
import mage.counters.Counter;
import mage.game.Game;
import mage.game.permanent.Permanent;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
/**
* Use this effect only (I guess) with EntersBattlefieldAbility like abilities
*
* @author LevelX2
*/
public class EntersBattlefieldWithXCountersEffect extends OneShotEffect {
protected final Counter counter;
public EntersBattlefieldWithXCountersEffect(Counter counter) {
super(Outcome.BoostCreature);
this.counter = counter;
staticText = "with X " + counter.getName() + " counters on it";
}
public EntersBattlefieldWithXCountersEffect(final EntersBattlefieldWithXCountersEffect effect) {
super(effect);
this.counter = effect.counter;
}
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent == null) {
if (source.getAbilityType() == AbilityType.STATIC) {
permanent = game.getPermanentEntering(source.getSourceId());
}
}
if (permanent != null) {
SpellAbility spellAbility = (SpellAbility) getValue(EntersBattlefieldEffect.SOURCE_CAST_SPELL_ABILITY);
if (spellAbility != null
&& spellAbility.getSourceId().equals(source.getSourceId())
&& permanent.getZoneChangeCounter(game) == spellAbility.getSourceObjectZoneChangeCounter()) {
if (spellAbility.getSourceId().equals(source.getSourceId())) { // put into play by normal cast
int amount = spellAbility.getManaCostsToPay().getX();
if (amount > 0) {
Counter counterToAdd = counter.copy();
counterToAdd.add(amount - counter.getCount());
List<UUID> appliedEffects = (ArrayList<UUID>) this.getValue("appliedEffects");
permanent.addCounters(counterToAdd, source.getControllerId(), source, game, appliedEffects);
}
}
}
}
return true;
}
@Override
public EntersBattlefieldWithXCountersEffect copy() {
return new EntersBattlefieldWithXCountersEffect(this);
}
}