Merge pull request #9814 from Merlingilb/add-set-expansion-star-wars-rise-of-skywalker

Added set expansion star wars "rise of skywalker"
This commit is contained in:
Oleg Agafonov 2023-03-04 16:48:38 +04:00 committed by GitHub
commit 409f4eb36c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
37 changed files with 2084 additions and 35 deletions

View file

@ -204,6 +204,7 @@ public abstract class TriggeredAbilityImpl extends AbilityImpl implements Trigge
|| ruleLow.startsWith("attach")
|| ruleLow.startsWith("counter")
|| ruleLow.startsWith("destroy")
|| ruleLow.startsWith("sacrifice")
|| ruleLow.startsWith("exchange")
|| ruleLow.startsWith("exile")
|| ruleLow.startsWith("gain")

View file

@ -0,0 +1,89 @@
package mage.abilities.effects.common;
import mage.MageObject;
import mage.abilities.Ability;
import mage.abilities.Mode;
import mage.abilities.effects.OneShotEffect;
import mage.constants.Outcome;
import mage.constants.TargetController;
import mage.game.Game;
import mage.players.Player;
import java.util.UUID;
/**
* @author Merlingilb
*/
public class RevealHandEachPlayerEffect extends OneShotEffect {
private final TargetController targetController;
public RevealHandEachPlayerEffect() {
this(TargetController.ANY);
}
public RevealHandEachPlayerEffect(TargetController targetController) {
super(Outcome.Benefit);
this.targetController = targetController;
}
public RevealHandEachPlayerEffect(final RevealHandEachPlayerEffect effect) {
super(effect);
this.targetController = effect.targetController;
}
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = game.getObject(source);
if (controller == null) {
return true;
}
for (UUID playerId : game.getPlayers().keySet()) {
Player player = game.getPlayer(playerId);
if (player == null) {
continue;
}
switch (targetController) {
case NOT_YOU:
if (playerId.equals(source.getControllerId())) {
continue;
}
break;
case OPPONENT:
if (!game.getOpponents(source.getControllerId()).contains(playerId)) {
continue;
}
break;
}
player.revealCards(sourceObject.getIdName() + player.getName(), player.getHand(), game);
}
return true;
}
@Override
public RevealHandEachPlayerEffect copy() {
return new RevealHandEachPlayerEffect(this);
}
@Override
public String getText(Mode mode) {
if (staticText != null && !staticText.isEmpty()) {
return staticText;
}
StringBuilder sb = new StringBuilder();
sb.append("each ");
switch (targetController) {
case NOT_YOU:
sb.append("other player");
break;
case OPPONENT:
sb.append("opponent");
break;
case ANY:
sb.append("player");
break;
}
sb.append(" reveals their hand");
return sb.toString();
}
}

View file

@ -0,0 +1,159 @@
package mage.abilities.effects.common.continuous;
import mage.abilities.Ability;
import mage.abilities.ActivatedAbility;
import mage.abilities.Mode;
import mage.abilities.condition.Condition;
import mage.abilities.effects.ContinuousEffectImpl;
import mage.constants.Duration;
import mage.constants.Layer;
import mage.constants.Outcome;
import mage.constants.SubLayer;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player;
import mage.target.Target;
import mage.util.CardUtil;
import java.util.UUID;
/**
* @author Merlingilb
*/
public class GainControlAndUntapTargetEffect extends ContinuousEffectImpl {
protected UUID controllingPlayerId;
private boolean fixedControl;
private boolean firstControlChange = true;
private final Condition condition;
public GainControlAndUntapTargetEffect(Duration duration) {
this(duration, false, null);
}
/**
* @param duration
* @param fixedControl Controlling player is fixed even if the controller of
* the ability changes later
*/
public GainControlAndUntapTargetEffect(Duration duration, boolean fixedControl) {
this(duration, fixedControl, null);
}
/**
* @param duration
* @param controllingPlayerId Player that controls the target creature
*/
public GainControlAndUntapTargetEffect(Duration duration, UUID controllingPlayerId) {
this(duration, true, controllingPlayerId);
}
public GainControlAndUntapTargetEffect(Duration duration, boolean fixedControl, UUID controllingPlayerId) {
this(duration, fixedControl, controllingPlayerId, null);
}
public GainControlAndUntapTargetEffect(Duration duration, boolean fixedControl, UUID controllingPlayerId, Condition condition) {
super(duration, Layer.ControlChangingEffects_2, SubLayer.NA, Outcome.GainControl);
this.controllingPlayerId = controllingPlayerId;
this.fixedControl = fixedControl;
this.condition = condition;
}
public GainControlAndUntapTargetEffect(final GainControlAndUntapTargetEffect effect) {
super(effect);
this.controllingPlayerId = effect.controllingPlayerId;
this.fixedControl = effect.fixedControl;
this.condition = effect.condition;
}
@Override
public GainControlAndUntapTargetEffect copy() {
return new GainControlAndUntapTargetEffect(this);
}
@Override
public void init(Ability source, Game game) {
if (this.controllingPlayerId == null && fixedControl) {
this.controllingPlayerId = source.getControllerId();
}
super.init(source, game);
}
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
discard(); // controller no longer exists
return false;
}
boolean oneTargetStillExists = false;
for (UUID permanentId : getTargetPointer().getTargets(game, source)) {
Permanent permanent = game.getPermanent(permanentId);
if (permanent == null) {
continue;
}
oneTargetStillExists = true;
if (permanent.isControlledBy(controllingPlayerId)) {
permanent.untap(game);
continue;
}
boolean controlChanged = false;
if (controllingPlayerId != null) {
if (permanent.changeControllerId(controllingPlayerId, game, source)) {
permanent.untap(game);
controlChanged = true;
}
} else {
if (permanent.changeControllerId(source.getControllerId(), game, source)) {
permanent.untap(game);
controlChanged = true;
}
}
if (source instanceof ActivatedAbility
&& firstControlChange && !controlChanged) {
// If it was not possible to get control of target permanent by the activated ability the first time it took place
// the effect failed (e.g. because of Guardian Beast) and must be discarded
// This does not handle correctly multiple targets at once
discard();
}
if (condition != null && !condition.apply(game, source)) {
discard();
}
}
// no valid target exists and the controller is no longer in the game, effect can be discarded
if (!oneTargetStillExists || !controller.isInGame()) {
discard();
}
firstControlChange = false;
return true;
}
@Override
public String getText(Mode mode) {
if (!staticText.isEmpty()) {
return staticText;
}
if (mode.getTargets().isEmpty()) {
return "gain control of target permanent until end of turn. Untap it.";
}
Target target = mode.getTargets().get(0);
StringBuilder sb = new StringBuilder("gain control of ");
if (target.getMaxNumberOfTargets() > 1) {
if (target.getNumberOfTargets() < target.getMaxNumberOfTargets()) {
sb.append("up to ");
}
sb.append(CardUtil.numberToText(target.getMaxNumberOfTargets())).append(" target ");
} else if (!target.getTargetName().startsWith("another")) {
sb.append("target ");
}
sb.append(mode.getTargets().get(0).getTargetName());
if (!duration.toString().isEmpty()) {
sb.append(' ').append(duration.toString());
}
sb.append("and untap it");
return sb.toString();
}
}

View file

@ -1,6 +1,5 @@
package mage.abilities.keyword;
import java.util.UUID;
import mage.abilities.Ability;
import mage.abilities.TriggeredAbilityImpl;
import mage.abilities.common.BeginningOfUpkeepTriggeredAbility;
@ -8,11 +7,11 @@ import mage.abilities.common.DiesSourceTriggeredAbility;
import mage.abilities.condition.common.SourceHasCounterCondition;
import mage.abilities.decorator.ConditionalInterveningIfTriggeredAbility;
import mage.abilities.dynamicvalue.common.StaticValue;
import mage.abilities.effects.AsThoughEffectImpl;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.asthought.PlayFromNotOwnHandZoneTargetEffect;
import mage.abilities.effects.common.counter.AddCountersSourceEffect;
import mage.abilities.effects.common.counter.RemoveCounterSourceEffect;
import mage.cards.Card;
import mage.constants.AsThoughEffectType;
import mage.constants.Duration;
import mage.constants.Outcome;
import mage.constants.TargetController;
@ -20,17 +19,20 @@ import mage.constants.Zone;
import mage.counters.CounterType;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.players.Player;
import mage.target.targetpointer.FixedTarget;
/**
*
* @author Styxo
* @author Styxo, Merlingilb
*/
public class RepairAbility extends DiesSourceTriggeredAbility {
private String ruleText;
private final String ruleText;
public RepairAbility(int count) {
super(new AddCountersSourceEffect(CounterType.REPAIR.createInstance(), StaticValue.get(count), false, true));
super(new AddCountersSourceEffect(
CounterType.REPAIR.createInstance(), StaticValue.get(count), false, true));
addSubAbility(new RepairBeginningOfUpkeepInterveningIfTriggeredAbility());
addSubAbility(new RepairCastFromGraveyardTriggeredAbility());
@ -56,37 +58,41 @@ public class RepairAbility extends DiesSourceTriggeredAbility {
}
}
class RepairCastFromGraveyardEffect extends AsThoughEffectImpl {
class RepairedCastFromGraveyardEffect extends OneShotEffect {
public RepairCastFromGraveyardEffect() {
super(AsThoughEffectType.PLAY_FROM_NOT_OWN_HAND_ZONE, Duration.EndOfTurn, Outcome.Benefit);
staticText = "You may cast it from graveyard until end of turn";
public RepairedCastFromGraveyardEffect() {
super(Outcome.Benefit);
}
public RepairCastFromGraveyardEffect(final RepairCastFromGraveyardEffect effect) {
private RepairedCastFromGraveyardEffect(final RepairedCastFromGraveyardEffect effect) {
super(effect);
}
@Override
public RepairedCastFromGraveyardEffect copy() {
return new RepairedCastFromGraveyardEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
Card card = game.getCard(source.getSourceId());
if (card == null) {
return false;
}
game.addEffect(new PlayFromNotOwnHandZoneTargetEffect(Zone.GRAVEYARD, Duration.UntilYourNextEndStep)
.setTargetPointer(new FixedTarget(card, game)), source);
return true;
}
@Override
public RepairCastFromGraveyardEffect copy() {
return new RepairCastFromGraveyardEffect(this);
}
@Override
public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) {
return source.isControlledBy(affectedControllerId);
}
}
class RepairCastFromGraveyardTriggeredAbility extends TriggeredAbilityImpl {
public RepairCastFromGraveyardTriggeredAbility() {
super(Zone.GRAVEYARD, new RepairCastFromGraveyardEffect());
super(Zone.GRAVEYARD, new RepairedCastFromGraveyardEffect());
setRuleVisible(false);
}
@ -103,10 +109,8 @@ class RepairCastFromGraveyardTriggeredAbility extends TriggeredAbilityImpl {
public boolean checkTrigger(GameEvent event, Game game) {
if (event.getTargetId().equals(getSourceId())) {
Card card = game.getCard(getSourceId());
if (card != null && game.getState().getZone(card.getId()) == Zone.GRAVEYARD
&& card.getCounters(game).getCount(CounterType.REPAIR) == 0) {
return true;
}
return card != null && game.getState().getZone(card.getId()) == Zone.GRAVEYARD
&& card.getCounters(game).getCount(CounterType.REPAIR) == 0;
}
return false;
}
@ -125,11 +129,11 @@ class RepairCastFromGraveyardTriggeredAbility extends TriggeredAbilityImpl {
class RepairBeginningOfUpkeepInterveningIfTriggeredAbility extends ConditionalInterveningIfTriggeredAbility {
public RepairBeginningOfUpkeepInterveningIfTriggeredAbility() {
super(new BeginningOfUpkeepTriggeredAbility(Zone.GRAVEYARD, new RemoveCounterSourceEffect(CounterType.REPAIR.createInstance()), TargetController.YOU, false),
super(new BeginningOfUpkeepTriggeredAbility(Zone.GRAVEYARD,
new RemoveCounterSourceEffect(CounterType.REPAIR.createInstance()),TargetController.YOU, false),
new SourceHasCounterCondition(CounterType.REPAIR),
"At the beginning of your upkeep, remove a repair counter from {this}");
this.setRuleVisible(false);
}
public RepairBeginningOfUpkeepInterveningIfTriggeredAbility(final RepairBeginningOfUpkeepInterveningIfTriggeredAbility effect) {

View file

@ -58,6 +58,7 @@ public enum SubType {
ALLY("Ally", SubTypeSet.CreatureType),
ANGEL("Angel", SubTypeSet.CreatureType),
ANTELOPE("Antelope", SubTypeSet.CreatureType),
ANZELLAN("Anzellan", SubTypeSet.CreatureType, true), // Star Wars
AQUALISH("Aqualish", SubTypeSet.CreatureType, true), // Star Wars
APE("Ape", SubTypeSet.CreatureType),
ARCONA("Arcona", SubTypeSet.CreatureType, true),
@ -465,6 +466,7 @@ public enum SubType {
OBI_WAN("Obi-Wan", SubTypeSet.PlaneswalkerType, true), // Star Wars
OKO("Oko", SubTypeSet.PlaneswalkerType),
RAL("Ral", SubTypeSet.PlaneswalkerType),
REY("Rey", SubTypeSet.PlaneswalkerType, true), // Star Wars,
ROWAN("Rowan", SubTypeSet.PlaneswalkerType),
SAHEELI("Saheeli", SubTypeSet.PlaneswalkerType),
SAMUT("Samut", SubTypeSet.PlaneswalkerType),

View file

@ -450,6 +450,12 @@ public final class StaticFilters {
FILTER_CONTROLLED_PERMANENT_LANDS.setLockedFilter(true);
}
public static final FilterPermanent FILTER_CONTROLLED_PERMANENT_CREATURE_OR_PLANESWALKER = new FilterControlledCreatureOrPlaneswalkerPermanent("creature or planeswalker you control");
static {
FILTER_CONTROLLED_PERMANENT_CREATURE_OR_PLANESWALKER.setLockedFilter(true);
}
public static final FilterControlledPermanent FILTER_CONTROLLED_PERMANENT_PLANESWALKER = new FilterControlledPlaneswalkerPermanent("planeswalker you control");
static {
@ -470,6 +476,12 @@ public final class StaticFilters {
FILTER_OPPONENTS_PERMANENT_NON_LAND.setLockedFilter(true);
}
public static final FilterNoncreaturePermanent FILTER_PERMANENT_NON_CREATURE = new FilterNoncreaturePermanent();
static {
FILTER_PERMANENT_NON_CREATURE.setLockedFilter(true);
}
public static final FilterCreaturePermanent FILTER_OPPONENTS_PERMANENT_CREATURE = new FilterOpponentsCreaturePermanent();
static {
@ -782,21 +794,21 @@ public final class StaticFilters {
FILTER_SPELL_CREATURE.setLockedFilter(true);
}
public static final FilterSpell FILTER_SPELL_NON_CREATURE = (FilterSpell) new FilterSpell("noncreature spell");
public static final FilterSpell FILTER_SPELL_NON_CREATURE = new FilterSpell("noncreature spell");
static {
FILTER_SPELL_NON_CREATURE.add(Predicates.not(CardType.CREATURE.getPredicate()));
FILTER_SPELL_NON_CREATURE.setLockedFilter(true);
}
public static final FilterSpell FILTER_SPELLS_NON_CREATURE = (FilterSpell) new FilterSpell("noncreature spells");
public static final FilterSpell FILTER_SPELLS_NON_CREATURE = new FilterSpell("noncreature spells");
static {
FILTER_SPELLS_NON_CREATURE.add(Predicates.not(CardType.CREATURE.getPredicate()));
FILTER_SPELLS_NON_CREATURE.setLockedFilter(true);
}
public static final FilterSpell FILTER_SPELL_A_NON_CREATURE = (FilterSpell) new FilterSpell("a noncreature spell");
public static final FilterSpell FILTER_SPELL_A_NON_CREATURE = new FilterSpell("a noncreature spell");
static {
FILTER_SPELL_A_NON_CREATURE.add(Predicates.not(CardType.CREATURE.getPredicate()));

View file

@ -0,0 +1,46 @@
package mage.filter.common;
import mage.constants.CardType;
import mage.constants.SubType;
import mage.filter.predicate.Predicates;
/**
* @author LevelX2
*/
public class FilterControlledCreatureOrPlaneswalkerPermanent extends FilterControlledPermanent {
public FilterControlledCreatureOrPlaneswalkerPermanent() {
this("creature or planeswalker you control");
}
public FilterControlledCreatureOrPlaneswalkerPermanent(SubType subType) {
this(subType, "a " + subType + " creature or a " + subType + " planeswalker");
}
public FilterControlledCreatureOrPlaneswalkerPermanent(SubType subType, String name) {
super(name);
this.add(Predicates.or(
CardType.CREATURE.getPredicate(),
CardType.PLANESWALKER.getPredicate()
));
this.add(subType.getPredicate());
}
public FilterControlledCreatureOrPlaneswalkerPermanent(String name) {
super(name);
this.add(Predicates.or(
CardType.CREATURE.getPredicate(),
CardType.PLANESWALKER.getPredicate()
));
}
public FilterControlledCreatureOrPlaneswalkerPermanent(final FilterControlledCreatureOrPlaneswalkerPermanent filter) {
super(filter);
}
@Override
public FilterControlledCreatureOrPlaneswalkerPermanent copy() {
return new FilterControlledCreatureOrPlaneswalkerPermanent(this);
}
}

View file

@ -0,0 +1,33 @@
package mage.filter.common;
import mage.constants.CardType;
import mage.filter.FilterPermanent;
import mage.filter.predicate.Predicates;
/**
* @author Merlingilb
*/
public class FilterNoncreaturePermanent extends FilterPermanent {
public FilterNoncreaturePermanent() {
this("noncreature permanent");
}
public FilterNoncreaturePermanent(String name) {
super(name);
this.add(Predicates.not(CardType.CREATURE.getPredicate()));
}
public FilterNoncreaturePermanent(final FilterNoncreaturePermanent filter) {
super(filter);
}
@Override
public FilterNoncreaturePermanent copy() {
return new FilterNoncreaturePermanent(this);
}
}