foul-magics/Mage/src/main/java/mage/abilities/keyword/RiotAbility.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

93 lines
No EOL
2.8 KiB
Java

package mage.abilities.keyword;
import mage.abilities.Ability;
import mage.abilities.Mode;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.effects.ReplacementEffectImpl;
import mage.abilities.effects.common.continuous.GainAbilitySourceEffect;
import mage.constants.Duration;
import mage.constants.Outcome;
import mage.constants.Zone;
import mage.counters.CounterType;
import mage.game.Game;
import mage.game.events.EntersTheBattlefieldEvent;
import mage.game.events.GameEvent;
import mage.game.permanent.Permanent;
import mage.players.Player;
/**
* @author TheElk801
*/
public class RiotAbility extends SimpleStaticAbility {
public RiotAbility() {
super(Zone.ALL, new RiotReplacementEffect());
}
private RiotAbility(final RiotAbility ability) {
super(ability);
}
@Override
public RiotAbility copy() {
return new RiotAbility(this);
}
@Override
public String getRule() {
return "Riot <i>(This creature enters the battlefield with your choice of a +1/+1 counter or haste.)</i>";
}
}
class RiotReplacementEffect extends ReplacementEffectImpl {
RiotReplacementEffect() {
super(Duration.EndOfGame, Outcome.Detriment);
}
private RiotReplacementEffect(final RiotReplacementEffect effect) {
super(effect);
}
@Override
public boolean checksEventType(GameEvent event, Game game) {
return event.getType() == GameEvent.EventType.ENTERS_THE_BATTLEFIELD;
}
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
return event.getTargetId().equals(source.getSourceId());
}
@Override
public boolean apply(Game game, Ability source) {
return false;
}
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
Permanent creature = ((EntersTheBattlefieldEvent) event).getTarget();
Player controller = game.getPlayer(source.getControllerId());
if (creature != null && controller != null) {
if (controller.chooseUse(outcome, "Have " + creature.getLogName() + " enter the battlefield with a +1/+1 counter on it or with haste?", null, "+1/+1 counter", "Haste", source, game)) {
game.informPlayers(controller.getLogName() + " choose to put a +1/+1 counter on " + creature.getName());
creature.addCounters(CounterType.P1P1.createInstance(), source.getControllerId(), source, game, event.getAppliedEffects());
} else {
game.addEffect(new GainAbilitySourceEffect(HasteAbility.getInstance(), Duration.Custom), source);
}
}
return false;
}
@Override
public String getText(Mode mode) {
return staticText;
}
@Override
public RiotReplacementEffect copy() {
return new RiotReplacementEffect(this);
}
}