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

WIP: Allow objects to have multiple names #12839

Draft
wants to merge 22 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 5 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
9 changes: 4 additions & 5 deletions Mage.Sets/src/mage/cards/a/AgencyOutfitter.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import mage.target.TargetCard;
import mage.target.common.TargetCardAndOrCard;
import mage.target.common.TargetCardAndOrCardInLibrary;
import mage.util.CardUtil;

import java.util.UUID;

Expand Down Expand Up @@ -83,9 +82,9 @@ public boolean apply(Game game, Ability source) {
for (UUID id : libraryTarget.getTargets()) {
Card card = game.getCard(id);
if (card != null) {
if (CardUtil.haveSameNames(card, glassName, game)) {
if (card.hasName(glassName, game)) {
glassCard = card;
} else if (CardUtil.haveSameNames(card, capName, game)) {
} else if (card.hasName(capName, game)) {
capCard = card;
}
}
Expand Down Expand Up @@ -115,9 +114,9 @@ public boolean apply(Game game, Ability source) {
for (UUID id : target.getTargets()) {
Card card = game.getCard(id);
if (card != null) {
if (CardUtil.haveSameNames(card, glassName, game)) {
if (card.hasName(glassName, game)) {
glassCard = card;
} else if (CardUtil.haveSameNames(card, capName, game)) {
} else if (card.hasName(capName, game)) {
capCard = card;
}
}
Expand Down
3 changes: 1 addition & 2 deletions Mage.Sets/src/mage/cards/a/AlhammarretHighArbiter.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import java.util.UUID;

/**
*
* @author LevelX2
*/
public final class AlhammarretHighArbiter extends CardImpl {
Expand Down Expand Up @@ -162,7 +161,7 @@ public boolean applies(GameEvent event, Ability source, Game game) {
if (card == null) {
return false;
}
return CardUtil.haveSameNames(card, cardName, game);
return card.hasName(cardName, game);
}
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion Mage.Sets/src/mage/cards/a/AnointedPeacekeeper.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,6 @@ public boolean applies(Ability abilityToModify, Ability source, Game game) {
String chosenName = (String) game.getState().getValue(
source.getSourceId().toString() + ChooseACardNameEffect.INFO_KEY
);
return CardUtil.haveSameNames(activatedSource, chosenName, game);
return activatedSource.hasName(chosenName, game);
}
}
4 changes: 1 addition & 3 deletions Mage.Sets/src/mage/cards/b/BileBlight.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public final class BileBlight extends CardImpl {
public BileBlight(UUID ownerId, CardSetInfo setInfo) {
super(ownerId, setInfo, new CardType[]{CardType.INSTANT}, "{B}{B}");


// Target creature and all creatures with the same name as that creature get -3/-3 until end of turn.
this.getSpellAbility().addEffect(new BileBlightEffect());
this.getSpellAbility().addTarget(new TargetCreaturePermanent());
Expand Down Expand Up @@ -64,9 +63,8 @@ public void init(Ability source, Game game) {
affectedObjectList.add(new MageObjectReference(target, game));
return;
}
String name = target.getName();
for (Permanent perm : game.getBattlefield().getActivePermanents(source.getControllerId(), game)) {
if (CardUtil.haveSameNames(perm, name, game)) {
if (CardUtil.haveSameNames(perm, target)) {
affectedObjectList.add(new MageObjectReference(perm, game));
}
}
Expand Down
3 changes: 1 addition & 2 deletions Mage.Sets/src/mage/cards/b/BrainPry.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import mage.game.Game;
import mage.players.Player;
import mage.target.TargetPlayer;
import mage.util.CardUtil;

import java.util.UUID;

Expand Down Expand Up @@ -60,7 +59,7 @@ public boolean apply(Game game, Ability source) {
if (targetPlayer != null && controller != null && sourceObject != null && cardName != null) {
boolean hasDiscarded = false;
for (Card card : targetPlayer.getHand().getCards(game)) {
if (CardUtil.haveSameNames(card, cardName, game)) {
if (card.hasName(cardName, game)) {
targetPlayer.discard(card, false, source, game);
hasDiscarded = true;
break;
Expand Down
4 changes: 1 addition & 3 deletions Mage.Sets/src/mage/cards/c/CabalTherapist.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
import mage.game.Game;
import mage.players.Player;
import mage.target.TargetPlayer;
import mage.target.common.TargetControlledPermanent;
import mage.util.CardUtil;

import java.util.UUID;

Expand Down Expand Up @@ -92,7 +90,7 @@ public boolean apply(Game game, Ability source) {
if (card == null) {
return true;
}
return !CardUtil.haveSameNames(card, cardName, game);
return !card.hasName(cardName, game);
});
targetPlayer.discard(hand, false, source, game);
return true;
Expand Down
4 changes: 1 addition & 3 deletions Mage.Sets/src/mage/cards/c/CabalTherapy.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
import mage.game.Game;
import mage.players.Player;
import mage.target.TargetPlayer;
import mage.target.common.TargetControlledCreaturePermanent;
import mage.util.CardUtil;

import java.util.UUID;

Expand Down Expand Up @@ -75,7 +73,7 @@ public boolean apply(Game game, Ability source) {
if (card == null) {
return true;
}
return !CardUtil.haveSameNames(card, cardName, game);
return !card.hasName(cardName, game);
});
targetPlayer.discard(hand, false, source, game);
return true;
Expand Down
3 changes: 1 addition & 2 deletions Mage.Sets/src/mage/cards/c/ConjurersBan.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import mage.constants.Outcome;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.util.CardUtil;

import java.util.UUID;

Expand Down Expand Up @@ -68,7 +67,7 @@ public boolean checksEventType(GameEvent event, Game game) {
public boolean applies(GameEvent event, Ability source, Game game) {
MageObject object = game.getObject(event.getSourceId());
String cardName = (String) game.getState().getValue(source.getSourceId().toString() + ChooseACardNameEffect.INFO_KEY);
return CardUtil.haveSameNames(object, cardName, game);
return object.hasName(cardName, game);
}

@Override
Expand Down
3 changes: 1 addition & 2 deletions Mage.Sets/src/mage/cards/c/ConundrumSphinx.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import mage.constants.Zone;
import mage.game.Game;
import mage.players.Player;
import mage.util.CardUtil;

import java.util.UUID;

Expand Down Expand Up @@ -81,7 +80,7 @@ public boolean apply(Game game, Ability source) {
}
Cards cards = new CardsImpl(card);
player.revealCards(source, cards, game);
if (CardUtil.haveSameNames(card, cardName, game)) {
if (card.hasName(cardName, game)) {
player.moveCards(cards, Zone.HAND, source, game);
} else {
player.putCardsOnBottomOfLibrary(cards, game, source, false);
Expand Down
50 changes: 22 additions & 28 deletions Mage.Sets/src/mage/cards/c/CorneredMarket.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@
import mage.game.events.GameEvent;
import mage.game.permanent.Permanent;
import mage.game.stack.Spell;
import mage.util.CardUtil;

import java.util.UUID;

/**
*
* @author jeffwadsworth
*/
public final class CorneredMarket extends CardImpl {
Expand Down Expand Up @@ -77,34 +75,30 @@ public boolean applies(GameEvent event, Ability source, Game game) {
return false;
}
Card card = spellAbility.getCharacteristics(game);
if (card != null) {
Spell spell = game.getState().getStack().getSpell(event.getSourceId());
// Face Down cast spell (Morph creature) has no name
if (spell != null
&& spell.isFaceDown(game)) {
return false;
}
// play land check
if (card.isLand(game)
&& !card.isBasic(game)) {
for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source, game)) {
if (permanent != null) {
if (CardUtil.haveSameNames(card, permanent.getName(), game)) {
return true;
}
}
if (card == null) {
return false;
}
Spell spell = game.getState().getStack().getSpell(event.getSourceId());
// Face Down cast spell (Morph creature) has no name
if (spell != null && spell.isFaceDown(game)) {
return false;
}
// play land check
if (card.isLand(game) && !card.isBasic(game)) {
for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source, game)) {
if (card.sharesName(permanent, game)) {
return true;
}
return false;
}
// cast spell check
if (spell != null) {
for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source, game)) {
if (permanent != null) {
if (CardUtil.haveSameNames(card, permanent.getName(), game)) {
return true;
}
}
}
return false;
}
// cast spell check
if (spell == null) {
return false;
}
for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source, game)) {
if (card.sharesName(permanent, game)) {
return true;
}
}
return false;
Expand Down
108 changes: 30 additions & 78 deletions Mage.Sets/src/mage/cards/c/CrownOfEmpires.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
package mage.cards.c;

import mage.abilities.Ability;
import mage.abilities.Mode;
import mage.abilities.common.SimpleActivatedAbility;
import mage.abilities.condition.CompoundCondition;
import mage.abilities.condition.Condition;
import mage.abilities.condition.common.PermanentsOnTheBattlefieldCondition;
import mage.abilities.costs.common.TapSourceCost;
import mage.abilities.costs.mana.GenericManaCost;
import mage.abilities.effects.ContinuousEffect;
import mage.abilities.effects.ContinuousEffectImpl;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.decorator.ConditionalOneShotEffect;
import mage.abilities.effects.common.AddContinuousEffectToGame;
import mage.abilities.effects.common.TapTargetEffect;
import mage.abilities.effects.common.continuous.GainControlTargetEffect;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.*;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.filter.FilterPermanent;
import mage.filter.common.FilterControlledArtifactPermanent;
import mage.filter.predicate.mageobject.NamePredicate;
import mage.target.common.TargetCreaturePermanent;
import mage.target.targetpointer.FixedTarget;
import mage.util.CardUtil;

import java.util.UUID;

Expand All @@ -24,11 +27,28 @@
*/
public final class CrownOfEmpires extends CardImpl {

private static final FilterPermanent filter = new FilterControlledArtifactPermanent();
private static final FilterPermanent filter2 = new FilterControlledArtifactPermanent();

static {
filter.add(new NamePredicate("Scepter of Empires"));
filter2.add(new NamePredicate("Throne of Empires"));
}

private static final Condition condition = new CompoundCondition(
new PermanentsOnTheBattlefieldCondition(filter),
new PermanentsOnTheBattlefieldCondition(filter2)
);

public CrownOfEmpires(UUID ownerId, CardSetInfo setInfo) {
super(ownerId, setInfo, new CardType[]{CardType.ARTIFACT}, "{2}");

// {3}, {tap}: Tap target creature. Gain control of that creature instead if you control artifacts named Scepter of Empires and Throne of Empires.
Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new CrownOfEmpiresEffect(), new GenericManaCost(3));
Ability ability = new SimpleActivatedAbility(new ConditionalOneShotEffect(
new AddContinuousEffectToGame(new GainControlTargetEffect(Duration.Custom)),
new TapTargetEffect(), condition, "tap target creature. Gain control of that creature " +
"instead if you control artifacts named Scepter of Empires and Throne of Empires"
), new GenericManaCost(3));
ability.addTarget(new TargetCreaturePermanent());
ability.addCost(new TapSourceCost());
this.addAbility(ability);
Expand All @@ -43,71 +63,3 @@ public CrownOfEmpires copy() {
return new CrownOfEmpires(this);
}
}

class CrownOfEmpiresEffect extends OneShotEffect {

CrownOfEmpiresEffect() {
super(Outcome.Tap);
staticText = "Tap target creature. Gain control of that creature instead if you control artifacts named Scepter of Empires and Throne of Empires";
}

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

@Override
public boolean apply(Game game, Ability source) {
Permanent target = game.getPermanent(getTargetPointer().getFirst(game, source));
boolean scepter = false;
boolean throne = false;
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(source.getControllerId())) {
if (CardUtil.haveSameNames(permanent, "Scepter of Empires", game)) {
scepter = true;
} else if (CardUtil.haveSameNames(permanent, "Throne of Empires", game)) {
throne = true;
}
if (scepter && throne) break;
}
if (scepter && throne) {
ContinuousEffect effect = new CrownOfEmpiresControlEffect();
effect.setTargetPointer(new FixedTarget(target.getId(), game));
game.getState().setValue(source.getSourceId().toString(), source.getControllerId());
game.addEffect(effect, source);
} else {
target.tap(source, game);
}
return false;
}

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

class CrownOfEmpiresControlEffect extends ContinuousEffectImpl {

CrownOfEmpiresControlEffect() {
super(Duration.EndOfGame, Layer.ControlChangingEffects_2, SubLayer.NA, Outcome.GainControl);
this.staticText = "Gain control of {this}";
}

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

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

@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getPermanent(getTargetPointer().getFirst(game, source));
UUID controllerId = (UUID) game.getState().getValue(source.getSourceId().toString());
if (permanent != null && controllerId != null) {
return permanent.changeControllerId(controllerId, game, source);
}
return false;
}
}
3 changes: 1 addition & 2 deletions Mage.Sets/src/mage/cards/d/DemonicConsultation.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import mage.constants.Zone;
import mage.game.Game;
import mage.players.Player;
import mage.util.CardUtil;

import java.util.UUID;

Expand Down Expand Up @@ -73,7 +72,7 @@ public boolean apply(Game game, Ability source) {
for (Card card : controller.getLibrary().getCards(game)) {
cardsToReveal.add(card);
// Put that card into your hand
if (CardUtil.haveSameNames(card.getName(), cardName)) {
if (card.hasName(cardName, game)) {
cardToHand = card;
break;
}
Expand Down
Loading
Loading