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 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
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);
}
}
2 changes: 1 addition & 1 deletion Mage.Sets/src/mage/cards/a/ApproachOfTheSecondSun.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public ApproachOfTheSecondSunWatcher() {
public void watch(GameEvent event, Game game) {
if (event.getType() == GameEvent.EventType.SPELL_CAST) { //A copy of a spell isn’t cast, so it won’t count as the first nor as the second Approach of the Second Sun. (2017-04-18)
Spell spell = game.getStack().getSpell(event.getSourceId());
if (spell != null && spell.getName().equals("Approach of the Second Sun")) {
if (spell != null && spell.hasName("Approach of the Second Sun", game)) {
approachesCast.put(event.getPlayerId(), getApproachesCast(event.getPlayerId()) + 1);
}
}
Expand Down
14 changes: 5 additions & 9 deletions Mage.Sets/src/mage/cards/a/AssemblyHall.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@
import mage.constants.Outcome;
import mage.filter.FilterCard;
import mage.filter.StaticFilters;
import mage.filter.predicate.mageobject.NamePredicate;
import mage.filter.predicate.mageobject.SharesNamePredicate;
import mage.game.Game;
import mage.players.Player;
import mage.target.Target;
import mage.target.common.TargetCardInHand;
import mage.target.common.TargetCardInLibrary;
import mage.util.CardUtil;

import java.util.UUID;

Expand Down Expand Up @@ -74,19 +73,16 @@ public boolean apply(Game game, Ability source) {
if (controller == null || controller.getHand().isEmpty() || sourceObject == null) {
return false;
}
Card cardToReveal = null;
Target target = new TargetCardInHand(StaticFilters.FILTER_CARD_CREATURE);
target.withNotTarget(true);
if (controller.chooseTarget(outcome, target, source, game)) {
cardToReveal = game.getCard(target.getFirstTarget());
}
controller.chooseTarget(outcome, target, source, game);
Card cardToReveal = game.getCard(target.getFirstTarget());
if (cardToReveal == null) {
return false;
}
controller.revealCards("from hand :" + sourceObject.getName(), new CardsImpl(cardToReveal), game);
String nameToSearch = CardUtil.getCardNameForSameNameSearch(cardToReveal);
FilterCard filterCard = new FilterCard("card named " + nameToSearch);
filterCard.add(new NamePredicate(nameToSearch));
FilterCard filterCard = new FilterCard("card with the same name as " + cardToReveal.getName());
filterCard.add(new SharesNamePredicate(cardToReveal));
return new SearchLibraryPutInHandEffect(new TargetCardInLibrary(filterCard), true).apply(game, source);
}
}
33 changes: 16 additions & 17 deletions Mage.Sets/src/mage/cards/a/AudienceWithTrostani.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package mage.cards.a;

import mage.MageObject;
import mage.abilities.Ability;
import mage.abilities.dynamicvalue.DynamicValue;
import mage.abilities.effects.Effect;
Expand All @@ -11,10 +10,12 @@
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.filter.StaticFilters;
import mage.filter.FilterPermanent;
import mage.filter.common.FilterControlledCreaturePermanent;
import mage.filter.predicate.permanent.TokenPredicate;
import mage.game.Game;
import mage.game.permanent.PermanentToken;
import mage.game.permanent.token.PlantToken;
import mage.util.CardUtil;

import java.util.UUID;

Expand Down Expand Up @@ -45,8 +46,14 @@ public AudienceWithTrostani copy() {

enum AudienceWithTrostaniValue implements DynamicValue {
instance;
private static final FilterPermanent filter = new FilterControlledCreaturePermanent();

static {
filter.add(TokenPredicate.TRUE);
}

private static final Hint hint = new ValueHint(
"Different names among creature tokens you control", instance
"Differently named creature tokens you control", instance
);

public static Hint getHint() {
Expand All @@ -55,19 +62,11 @@ public static Hint getHint() {

@Override
public int calculate(Game game, Ability sourceAbility, Effect effect) {
return game
.getBattlefield()
.getActivePermanents(
StaticFilters.FILTER_CONTROLLED_CREATURE,
sourceAbility.getControllerId(), sourceAbility, game
)
.stream()
.filter(PermanentToken.class::isInstance)
.map(MageObject::getName)
.filter(s -> !s.isEmpty())
.distinct()
.mapToInt(x -> 1)
.sum();
return CardUtil.differentlyNamedAmongCollection(
game.getBattlefield().getActivePermanents(
filter, sourceAbility.getControllerId(), sourceAbility, game
), game
);
}

@Override
Expand Down
109 changes: 36 additions & 73 deletions Mage.Sets/src/mage/cards/a/AvenShrine.java
Original file line number Diff line number Diff line change
@@ -1,36 +1,35 @@

package mage.cards.a;

import java.util.UUID;
import mage.MageObject;
import mage.abilities.Ability;
import mage.abilities.TriggeredAbilityImpl;
import mage.abilities.common.SpellCastAllTriggeredAbility;
import mage.abilities.effects.OneShotEffect;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.Outcome;
import mage.constants.Zone;
import mage.filter.FilterCard;
import mage.filter.predicate.mageobject.NamePredicate;
import mage.constants.SetTargetPointer;
import mage.filter.StaticFilters;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.events.GameEvent.EventType;
import mage.game.stack.Spell;
import mage.players.Player;

import java.util.Collection;
import java.util.Objects;
import java.util.UUID;

/**
*
* @author jeffwadsworth
* @author TheElk801
*/
public final class AvenShrine extends CardImpl {

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

// Whenever a player casts a spell, that player gains X life, where X is the number of cards in all graveyards with the same name as that spell.
this.addAbility(new AvenShrineTriggeredAbility());

this.addAbility(new SpellCastAllTriggeredAbility(
new AvenShrineEffect(), StaticFilters.FILTER_SPELL_A,
false, SetTargetPointer.PLAYER
));
}

private AvenShrine(final AvenShrine card) {
Expand All @@ -43,78 +42,42 @@ public AvenShrine copy() {
}
}

class AvenShrineTriggeredAbility extends TriggeredAbilityImpl {

public AvenShrineTriggeredAbility() {
super(Zone.BATTLEFIELD, new AvenShrineEffect(), false);
}

private AvenShrineTriggeredAbility(final AvenShrineTriggeredAbility ability) {
super(ability);
}

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

@Override
public boolean checkEventType(GameEvent event, Game game) {
return event.getType() == GameEvent.EventType.SPELL_CAST;
}

@Override
public boolean checkTrigger(GameEvent event, Game game) {
Spell spell = game.getStack().getSpell(event.getTargetId());
MageObject mageObject = game.getObject(sourceId);
if (spell != null && mageObject != null) {
game.getState().setValue("avenShrine" + mageObject, spell);
return true;
}
return false;
}

}

class AvenShrineEffect extends OneShotEffect {

AvenShrineEffect() {
super(Outcome.GainLife);
staticText = "Whenever a player casts a spell, that player gains X life, where X is the number of cards in all graveyards with the same name as that spell";
super(Outcome.Benefit);
staticText = "that player gains X life, where X is the number " +
"of cards in all graveyards with the same name as that spell";
}

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

@Override
public boolean apply(Game game, Ability source) {
int count = 0;
MageObject mageObject = game.getObject(source);
if(mageObject != null) {
Spell spell = (Spell) game.getState().getValue("avenShrine" + mageObject);
if (spell != null) {
Player controller = game.getPlayer(spell.getControllerId());
if (controller != null) {
String name = spell.getName();
FilterCard filterCardName = new FilterCard();
filterCardName.add(new NamePredicate(name));
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null) {
count += player.getGraveyard().count(filterCardName, game);
}
}
controller.gainLife(count, game, source);
return true;
}
}
}
return false;
public AvenShrineEffect copy() {
return new AvenShrineEffect(this);
}

@Override
public AvenShrineEffect copy() {
return new AvenShrineEffect(this);
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(getTargetPointer().getFirst(game, source));
Spell spell = (Spell) getValue("spellCast");
if (player == null || spell == null) {
return false;
}
int count = game
.getState()
.getPlayersInRange(source.getControllerId(), game)
.stream()
.map(game::getPlayer)
.filter(Objects::nonNull)
.map(Player::getGraveyard)
.map(g -> g.getCards(game))
.flatMap(Collection::stream)
.filter(c -> c.sharesName(spell, game))
.mapToInt(x -> 1)
.sum();
return player.gainLife(count, game, source) > 0;
}
}
Loading