Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WHO] Implement Everybody Lives! #13369

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions Mage.Sets/src/mage/cards/e/EverybodyLives.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package mage.cards.e;

import java.util.UUID;
import mage.abilities.effects.common.continuous.GainAbilityAllEffect;
import mage.abilities.effects.common.continuous.GainAbilityAllPlayersEffect;
import mage.abilities.effects.common.continuous.CantLoseLifeAllEffect;
import mage.abilities.effects.common.continuous.CantLoseOrWinGameAllEffect;
import mage.abilities.keyword.HexproofAbility;
import mage.abilities.keyword.IndestructibleAbility;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.TargetController;
import mage.filter.StaticFilters;

/**
*
* @author padfoot
*/
public final class EverybodyLives extends CardImpl {

public EverybodyLives(UUID ownerId, CardSetInfo setInfo) {
super(ownerId, setInfo, new CardType[]{CardType.INSTANT}, "{1}{W}");


// All creatures gain hexproof and indestructible until end of turn.
this.getSpellAbility().addEffect(new GainAbilityAllEffect(
HexproofAbility.getInstance(),
Duration.EndOfTurn,
StaticFilters.FILTER_PERMANENT_ALL_CREATURES
).setText("all creatures gain hexproof"));
this.getSpellAbility().addEffect(new GainAbilityAllEffect(
IndestructibleAbility.getInstance(),
Duration.EndOfTurn,
StaticFilters.FILTER_PERMANENT_ALL_CREATURES
).setText("and indestructible until end of turn"));
// Players gain hexproof until end of turn.
this.getSpellAbility().addEffect(new GainAbilityAllPlayersEffect(HexproofAbility.getInstance(), Duration.EndOfTurn));
// Players can't lose life this turn and players can't lose the game or win the this turn.
this.getSpellAbility().addEffect(new CantLoseLifeAllEffect(Duration.EndOfTurn, TargetController.ANY));
this.getSpellAbility().addEffect(new CantLoseOrWinGameAllEffect(Duration.EndOfTurn).concatBy("and"));
}

private EverybodyLives(final EverybodyLives card) {
super(card);
}

@Override
public EverybodyLives copy() {
return new EverybodyLives(this);
}
}
8 changes: 4 additions & 4 deletions Mage.Sets/src/mage/sets/DoctorWho.java
Original file line number Diff line number Diff line change
Expand Up @@ -295,10 +295,10 @@ private DoctorWho() {
//cards.add(new SetCardInfo("Ensnared by the Mara", 689, Rarity.RARE, mage.cards.e.EnsnaredByTheMara.class, NON_FULL_USE_VARIOUS));
//cards.add(new SetCardInfo("Ensnared by the Mara", 84, Rarity.RARE, mage.cards.e.EnsnaredByTheMara.class, NON_FULL_USE_VARIOUS));
//cards.add(new SetCardInfo("Ensnared by the Mara", 975, Rarity.RARE, mage.cards.e.EnsnaredByTheMara.class, NON_FULL_USE_VARIOUS));
//cards.add(new SetCardInfo("Everybody Lives!", 18, Rarity.RARE, mage.cards.e.EverybodyLives.class, NON_FULL_USE_VARIOUS));
//cards.add(new SetCardInfo("Everybody Lives!", 338, Rarity.RARE, mage.cards.e.EverybodyLives.class, NON_FULL_USE_VARIOUS));
//cards.add(new SetCardInfo("Everybody Lives!", 623, Rarity.RARE, mage.cards.e.EverybodyLives.class, NON_FULL_USE_VARIOUS));
//cards.add(new SetCardInfo("Everybody Lives!", 929, Rarity.RARE, mage.cards.e.EverybodyLives.class, NON_FULL_USE_VARIOUS));
cards.add(new SetCardInfo("Everybody Lives!", 18, Rarity.RARE, mage.cards.e.EverybodyLives.class, NON_FULL_USE_VARIOUS));
cards.add(new SetCardInfo("Everybody Lives!", 338, Rarity.RARE, mage.cards.e.EverybodyLives.class, NON_FULL_USE_VARIOUS));
cards.add(new SetCardInfo("Everybody Lives!", 623, Rarity.RARE, mage.cards.e.EverybodyLives.class, NON_FULL_USE_VARIOUS));
cards.add(new SetCardInfo("Everybody Lives!", 929, Rarity.RARE, mage.cards.e.EverybodyLives.class, NON_FULL_USE_VARIOUS));
cards.add(new SetCardInfo("Everything Comes to Dust", 19, Rarity.RARE, mage.cards.e.EverythingComesToDust.class, NON_FULL_USE_VARIOUS));
cards.add(new SetCardInfo("Everything Comes to Dust", 339, Rarity.RARE, mage.cards.e.EverythingComesToDust.class, NON_FULL_USE_VARIOUS));
cards.add(new SetCardInfo("Everything Comes to Dust", 624, Rarity.RARE, mage.cards.e.EverythingComesToDust.class, NON_FULL_USE_VARIOUS));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
package mage.abilities.effects.common.continuous;

import mage.abilities.Ability;
import mage.abilities.effects.ContinuousEffectImpl;
import mage.constants.*;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player;

import java.util.Optional;
import java.util.UUID;

/**
* @author padfoot
* copied from CantGainLifeAllEffect.
*/
public class CantLoseLifeAllEffect extends ContinuousEffectImpl {

private TargetController targetController;

public CantLoseLifeAllEffect() {
this(Duration.WhileOnBattlefield);
}

public CantLoseLifeAllEffect(Duration duration) {
this(duration, TargetController.ANY);
}

public CantLoseLifeAllEffect(Duration duration, TargetController targetController) {
super(duration, Layer.PlayerEffects, SubLayer.NA, Outcome.Benefit);
this.targetController = targetController;
staticText = setText();

}

protected CantLoseLifeAllEffect(final CantLoseLifeAllEffect effect) {
super(effect);
this.targetController = effect.targetController;
}

@Override
public CantLoseLifeAllEffect copy() {
return new CantLoseLifeAllEffect(this);
}

@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
switch (targetController) {
case YOU:
controller.setCanLoseLife(false);
break;
case NOT_YOU:
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null && !player.equals(controller)) {
player.setCanLoseLife(false);
}
}
break;
case OPPONENT:
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
if (controller.hasOpponent(playerId, game)) {
Player player = game.getPlayer(playerId);
if (player != null) {
player.setCanLoseLife(false);
}
}
}
break;
case ANY:
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null) {
player.setCanLoseLife(false);
}
}
break;
case ENCHANTED:
Optional
.ofNullable(source.getSourcePermanentIfItStillExists(game))
.map(Permanent::getAttachedTo)
.map(game::getPlayer)
.ifPresent(player -> player.setCanLoseLife(false));
}
return true;
}

private String setText() {
StringBuilder sb = new StringBuilder();
switch (targetController) {
case YOU:
sb.append("You");
break;
case NOT_YOU:
sb.append("Other players");
break;
case OPPONENT:
sb.append("Your opponents");
break;
case ANY:
sb.append("Players");
break;
case ENCHANTED:
sb.append("enchanted player");
}
sb.append(" can't lose life");
if (!this.duration.toString().isEmpty()) {
sb.append(' ');
if (duration == Duration.EndOfTurn) {
sb.append("this turn");
} else {
sb.append(duration.toString());
}

}
return sb.toString();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package mage.abilities.effects.common.continuous;

import mage.abilities.Ability;
import mage.abilities.effects.ContinuousRuleModifyingEffectImpl;
import mage.constants.Duration;
import mage.constants.Outcome;
import mage.game.Game;
import mage.game.events.GameEvent;

/**
* @author padfoot
*/
public class CantLoseOrWinGameAllEffect extends ContinuousRuleModifyingEffectImpl {

public CantLoseOrWinGameAllEffect() {
this(Duration.WhileOnBattlefield);
}

public CantLoseOrWinGameAllEffect(Duration duration) {
super(duration, Outcome.Benefit, false, false);
staticText = "players can't lose the game or win the game "
+ (duration == Duration.EndOfTurn ? "this turn":duration.toString());
}

private CantLoseOrWinGameAllEffect(final CantLoseOrWinGameAllEffect effect) {
super(effect);
}

@Override
public CantLoseOrWinGameAllEffect copy() {
return new CantLoseOrWinGameAllEffect(this);
}

@Override
public boolean checksEventType(GameEvent event, Game game) {
return (event.getType() == GameEvent.EventType.LOSES || event.getType() == GameEvent.EventType.WINS);
}

@Override
public boolean applies(GameEvent event, Ability source, Game game) {
return true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package mage.abilities.effects.common.continuous;

import mage.constants.Duration;
import mage.constants.Layer;
import mage.constants.Outcome;
import mage.constants.SubLayer;
import mage.abilities.Ability;
import mage.abilities.effects.ContinuousEffectImpl;
import mage.constants.TargetController;
import mage.game.Game;
import mage.players.Player;

import java.util.UUID;

/**
* @author padfoot
*/

public class GainAbilityAllPlayersEffect extends ContinuousEffectImpl {

private TargetController targetController;
protected Ability ability;

public GainAbilityAllPlayersEffect(Ability ability) {
this(ability, Duration.WhileOnBattlefield);
}

public GainAbilityAllPlayersEffect(Ability ability, Duration duration) {
this(ability, duration, TargetController.ANY);
}

/**
* @param ability
* @param duration custom - effect will be discarded as soon there is no sourceId - permanent on the battlefield
*/
public GainAbilityAllPlayersEffect(Ability ability, Duration duration, TargetController targetController) {
super(duration, Layer.PlayerEffects, SubLayer.NA, Outcome.AddAbility);
this.ability = ability.copy();
this.targetController = targetController;
this.staticText = "Players gain " + ability.getRule();
if (!duration.toString().isEmpty()) {
staticText += ' ' + duration.toString();
}
}

protected GainAbilityAllPlayersEffect(final GainAbilityAllPlayersEffect effect) {
super(effect);
this.ability = effect.ability.copy();
this.targetController = effect.targetController;
}

@Override
public GainAbilityAllPlayersEffect copy() {
return new GainAbilityAllPlayersEffect(this);
}

@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
switch (targetController) {
case ANY:
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null) {
player.addAbility(ability);
if (duration == Duration.Custom) {
if (game.getPermanent(source.getSourceId()) == null) {
discard();
}
}
} else {
discard();
}
}
break;
case OPPONENT:
for (UUID playerId : game.getOpponents(controller.getId())) {
Player player = game.getPlayer(playerId);
if (player != null) {
player.addAbility(ability);
if (duration == Duration.Custom) {
if (game.getPermanent(source.getSourceId()) == null) {
discard();
}
}
} else {
discard();
}
}
break;
}
return true;
}
}