forked from External/mage
reworked/simplified/consolidated effects which exchange life totals, added test (fixes #7668)
This commit is contained in:
parent
1abeec9595
commit
d4792e3665
16 changed files with 284 additions and 274 deletions
|
|
@ -0,0 +1,44 @@
|
|||
|
||||
package mage.abilities.effects.common;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.Mode;
|
||||
import mage.abilities.effects.OneShotEffect;
|
||||
import mage.constants.Outcome;
|
||||
import mage.game.Game;
|
||||
import mage.players.Player;
|
||||
|
||||
/**
|
||||
* @author Styxo
|
||||
*/
|
||||
public class ExchangeLifeControllerTargetEffect extends OneShotEffect {
|
||||
|
||||
public ExchangeLifeControllerTargetEffect() {
|
||||
super(Outcome.Neutral);
|
||||
}
|
||||
|
||||
private ExchangeLifeControllerTargetEffect(final ExchangeLifeControllerTargetEffect effect) {
|
||||
super(effect);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExchangeLifeControllerTargetEffect copy() {
|
||||
return new ExchangeLifeControllerTargetEffect(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Player controller = game.getPlayer(source.getControllerId());
|
||||
Player player = game.getPlayer(source.getFirstTarget());
|
||||
if (controller == null || player == null) {
|
||||
return false;
|
||||
}
|
||||
controller.exchangeLife(player, source, game);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getText(Mode mode) {
|
||||
return "Exchange life totals with target " + mode.getTargets().get(0).getTargetName();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,65 +0,0 @@
|
|||
|
||||
package mage.abilities.effects.common;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.Mode;
|
||||
import mage.abilities.effects.OneShotEffect;
|
||||
import mage.constants.Outcome;
|
||||
import mage.game.Game;
|
||||
import mage.players.Player;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Styxo
|
||||
*/
|
||||
public class ExchangeLifeTargetEffect extends OneShotEffect {
|
||||
|
||||
public ExchangeLifeTargetEffect() {
|
||||
super(Outcome.Neutral);
|
||||
}
|
||||
|
||||
public ExchangeLifeTargetEffect(final ExchangeLifeTargetEffect effect) {
|
||||
super(effect);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExchangeLifeTargetEffect copy() {
|
||||
return new ExchangeLifeTargetEffect(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Player controller = game.getPlayer(source.getControllerId());
|
||||
Player player = game.getPlayer(source.getFirstTarget());
|
||||
if (controller != null && player != null) {
|
||||
int lifeController = controller.getLife();
|
||||
int lifePlayer = player.getLife();
|
||||
|
||||
if (lifeController == lifePlayer) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!controller.isLifeTotalCanChange() || !player.isLifeTotalCanChange()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (lifeController < lifePlayer && (!controller.isCanGainLife() || !player.isCanLoseLife())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (lifeController > lifePlayer && (!controller.isCanLoseLife() || !player.isCanGainLife())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
controller.setLife(lifePlayer, game, source);
|
||||
player.setLife(lifeController, game, source);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getText(Mode mode) {
|
||||
return "Exchange life totals with target " + mode.getTargets().get(0).getTargetName();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
package mage.abilities.effects.common;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.effects.OneShotEffect;
|
||||
import mage.constants.Outcome;
|
||||
import mage.game.Game;
|
||||
import mage.players.Player;
|
||||
|
||||
/**
|
||||
* @author TheElk801
|
||||
*/
|
||||
public class ExchangeLifeTwoTargetEffect extends OneShotEffect {
|
||||
|
||||
public ExchangeLifeTwoTargetEffect() {
|
||||
super(Outcome.Neutral);
|
||||
staticText = "two target players exchange life totals";
|
||||
}
|
||||
|
||||
private ExchangeLifeTwoTargetEffect(final ExchangeLifeTwoTargetEffect effect) {
|
||||
super(effect);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExchangeLifeTwoTargetEffect copy() {
|
||||
return new ExchangeLifeTwoTargetEffect(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
if (source.getTargets().get(0).getTargets().size() < 2) {
|
||||
return false;
|
||||
}
|
||||
Player player1 = game.getPlayer(source.getTargets().get(0).getTargets().get(0));
|
||||
Player player2 = game.getPlayer(source.getTargets().get(0).getTargets().get(1));
|
||||
if (player1 == null || player2 == null) {
|
||||
return false;
|
||||
}
|
||||
player1.exchangeLife(player2, source, game);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue