forked from External/mage
Implementing "Start your engines!" mechanic (#13259)
* add initial speed handling * finish speed implementation * remove skip list * add initial test * add some more tests * change speed initialization to state-based action * add opponent speed check * add control change test * add check for speed 5
This commit is contained in:
parent
655af10b2e
commit
ef213b1bef
11 changed files with 393 additions and 15 deletions
108
Mage/src/main/java/mage/designations/Speed.java
Normal file
108
Mage/src/main/java/mage/designations/Speed.java
Normal file
|
|
@ -0,0 +1,108 @@
|
|||
package mage.designations;
|
||||
|
||||
import mage.MageObject;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.TriggeredAbilityImpl;
|
||||
import mage.abilities.effects.OneShotEffect;
|
||||
import mage.constants.Outcome;
|
||||
import mage.constants.Zone;
|
||||
import mage.game.Game;
|
||||
import mage.game.events.GameEvent;
|
||||
import mage.players.Player;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* @author TheElk801
|
||||
*/
|
||||
public class Speed extends Designation {
|
||||
|
||||
public Speed() {
|
||||
super(DesignationType.SPEED);
|
||||
addAbility(new SpeedTriggeredAbility());
|
||||
}
|
||||
|
||||
private Speed(final Speed card) {
|
||||
super(card);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Speed copy() {
|
||||
return new Speed(this);
|
||||
}
|
||||
}
|
||||
|
||||
class SpeedTriggeredAbility extends TriggeredAbilityImpl {
|
||||
|
||||
SpeedTriggeredAbility() {
|
||||
super(Zone.ALL, new SpeedEffect());
|
||||
setTriggersLimitEachTurn(1);
|
||||
}
|
||||
|
||||
private SpeedTriggeredAbility(final SpeedTriggeredAbility ability) {
|
||||
super(ability);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SpeedTriggeredAbility copy() {
|
||||
return new SpeedTriggeredAbility(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkEventType(GameEvent event, Game game) {
|
||||
return event.getType() == GameEvent.EventType.LOST_LIFE_BATCH_FOR_ONE_PLAYER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkTrigger(GameEvent event, Game game) {
|
||||
return game.isActivePlayer(getControllerId())
|
||||
&& game
|
||||
.getOpponents(getControllerId())
|
||||
.contains(event.getTargetId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkInterveningIfClause(Game game) {
|
||||
return Optional
|
||||
.ofNullable(getControllerId())
|
||||
.map(game::getPlayer)
|
||||
.map(Player::getSpeed)
|
||||
.map(x -> x < 4)
|
||||
.orElse(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInUseableZone(Game game, MageObject sourceObject, GameEvent event) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRule() {
|
||||
return "Whenever one or more opponents lose life during your turn, if your speed is less than 4, " +
|
||||
"increase your speed by 1. This ability triggers only once each turn.";
|
||||
}
|
||||
}
|
||||
|
||||
class SpeedEffect extends OneShotEffect {
|
||||
|
||||
SpeedEffect() {
|
||||
super(Outcome.Benefit);
|
||||
}
|
||||
|
||||
private SpeedEffect(final SpeedEffect effect) {
|
||||
super(effect);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SpeedEffect copy() {
|
||||
return new SpeedEffect(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Optional.ofNullable(source.getControllerId())
|
||||
.map(game::getPlayer)
|
||||
.ifPresent(player -> player.increaseSpeed(game));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue