mirror of
https://github.com/magefree/mage.git
synced 2025-12-26 05:22:02 -08:00
reworked champion ability
This commit is contained in:
parent
50b3d3d8d9
commit
e820d9f4f0
13 changed files with 79 additions and 101 deletions
|
|
@ -1,11 +1,5 @@
|
|||
|
||||
package mage.abilities.keyword;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import mage.MageObject;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.StaticAbility;
|
||||
import mage.abilities.common.EntersBattlefieldTriggeredAbility;
|
||||
|
|
@ -15,12 +9,11 @@ import mage.abilities.costs.CostImpl;
|
|||
import mage.abilities.effects.common.ReturnFromExileForSourceEffect;
|
||||
import mage.abilities.effects.common.SacrificeSourceUnlessPaysEffect;
|
||||
import mage.cards.Card;
|
||||
import mage.constants.CardType;
|
||||
import mage.constants.Outcome;
|
||||
import mage.constants.SubType;
|
||||
import mage.constants.Zone;
|
||||
import mage.filter.StaticFilters;
|
||||
import mage.filter.common.FilterControlledPermanent;
|
||||
import mage.filter.predicate.Predicate;
|
||||
import mage.filter.predicate.Predicates;
|
||||
import mage.filter.predicate.mageobject.AnotherPredicate;
|
||||
import mage.game.Game;
|
||||
|
|
@ -30,6 +23,10 @@ import mage.players.Player;
|
|||
import mage.target.common.TargetControlledPermanent;
|
||||
import mage.util.CardUtil;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
/*
|
||||
* @author LevelX2
|
||||
*
|
||||
|
|
@ -49,16 +46,7 @@ import mage.util.CardUtil;
|
|||
*/
|
||||
public class ChampionAbility extends StaticAbility {
|
||||
|
||||
protected EnumSet<SubType> subtypes;
|
||||
protected String objectDescription;
|
||||
|
||||
public ChampionAbility(Card card, SubType subtype, boolean requiresCreature) {
|
||||
this(card, EnumSet.of(subtype), requiresCreature);
|
||||
}
|
||||
|
||||
public ChampionAbility(Card card, boolean requiresCreature) {
|
||||
this(card, EnumSet.noneOf(SubType.class), requiresCreature);
|
||||
}
|
||||
protected final String objectDescription;
|
||||
|
||||
/**
|
||||
* Champion one or more creature types or if the subtype array is empty
|
||||
|
|
@ -66,55 +54,56 @@ public class ChampionAbility extends StaticAbility {
|
|||
*
|
||||
* @param card
|
||||
* @param subtypes subtypes to champion with, if empty all creatures can be
|
||||
* used
|
||||
* @param requiresCreature for cards that specifically require championing
|
||||
* another creature
|
||||
* used
|
||||
*/
|
||||
public ChampionAbility(Card card, EnumSet<SubType> subtypes, boolean requiresCreature) {
|
||||
public ChampionAbility(Card card, SubType... subtypes) {
|
||||
super(Zone.BATTLEFIELD, null);
|
||||
|
||||
this.subtypes = subtypes;
|
||||
StringBuilder sb = new StringBuilder("another ");
|
||||
List<Predicate<MageObject>> subtypesPredicates = new ArrayList<>();
|
||||
if (!subtypes.isEmpty()) {
|
||||
int i = 0;
|
||||
for (SubType subtype : this.subtypes) {
|
||||
subtypesPredicates.add(subtype.getPredicate());
|
||||
if (i == 0) {
|
||||
sb.append(subtype);
|
||||
} else {
|
||||
sb.append(" or ").append(subtype);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
} else {
|
||||
sb.append("creature");
|
||||
List<SubType> subTypes = Arrays.asList(subtypes);
|
||||
FilterControlledPermanent filter;
|
||||
switch (subTypes.size()) {
|
||||
case 0:
|
||||
this.objectDescription = "creature";
|
||||
filter = StaticFilters.FILTER_CONTROLLED_ANOTHER_CREATURE;
|
||||
break;
|
||||
case 1:
|
||||
SubType subType = subTypes.get(0);
|
||||
this.objectDescription = subType.getDescription();
|
||||
filter = new FilterControlledPermanent(subType, "another " + subType + " you control");
|
||||
filter.add(AnotherPredicate.instance);
|
||||
break;
|
||||
case 2:
|
||||
SubType subType1 = subTypes.get(0);
|
||||
SubType subType2 = subTypes.get(1);
|
||||
this.objectDescription = subType1.getDescription() + " or " + subType2.getDescription();
|
||||
filter = new FilterControlledPermanent();
|
||||
filter.add(Predicates.or(
|
||||
subType1.getPredicate(),
|
||||
subType2.getPredicate()
|
||||
));
|
||||
filter.add(AnotherPredicate.instance);
|
||||
break;
|
||||
default:
|
||||
throw new UnsupportedOperationException("can't have more than two subtypes currently");
|
||||
}
|
||||
this.objectDescription = sb.toString();
|
||||
FilterControlledPermanent filter = new FilterControlledPermanent(objectDescription);
|
||||
if (!subtypesPredicates.isEmpty()) {
|
||||
filter.add(Predicates.or(subtypesPredicates));
|
||||
}
|
||||
if (requiresCreature) {
|
||||
filter.add(CardType.CREATURE.getPredicate());
|
||||
}
|
||||
filter.add(AnotherPredicate.instance);
|
||||
|
||||
// When this permanent enters the battlefield, sacrifice it unless you exile another [object] you control.
|
||||
Ability ability1 = new EntersBattlefieldTriggeredAbility(
|
||||
new SacrificeSourceUnlessPaysEffect(new ChampionExileCost(filter, card.getName() + " championed permanents")), false);
|
||||
new SacrificeSourceUnlessPaysEffect(new ChampionExileCost(filter)), false
|
||||
);
|
||||
ability1.setRuleVisible(false);
|
||||
addSubAbility(ability1);
|
||||
|
||||
// When this permanent leaves the battlefield, return the exiled card to the battlefield under its owner's control.
|
||||
Ability ability2 = new LeavesBattlefieldTriggeredAbility(new ReturnFromExileForSourceEffect(Zone.BATTLEFIELD), false);
|
||||
Ability ability2 = new LeavesBattlefieldTriggeredAbility(
|
||||
new ReturnFromExileForSourceEffect(Zone.BATTLEFIELD), false
|
||||
);
|
||||
ability2.setRuleVisible(false);
|
||||
addSubAbility(ability2);
|
||||
}
|
||||
|
||||
public ChampionAbility(final ChampionAbility ability) {
|
||||
super(ability);
|
||||
this.subtypes = ability.subtypes;
|
||||
this.objectDescription = ability.objectDescription;
|
||||
}
|
||||
|
||||
|
|
@ -125,46 +114,41 @@ public class ChampionAbility extends StaticAbility {
|
|||
|
||||
@Override
|
||||
public String getRule() {
|
||||
StringBuilder sb = new StringBuilder("Champion ").append(objectDescription);
|
||||
sb.append(" <i>(When this enters the battlefield, sacrifice it unless you exile another ");
|
||||
sb.append(objectDescription);
|
||||
sb.append(" you control. When this leaves the battlefield, that card returns to the battlefield.)</i>");
|
||||
return sb.toString();
|
||||
return "Champion " + CardUtil.addArticle(objectDescription)
|
||||
+ " <i>(When this enters the battlefield, sacrifice it unless you exile another " + objectDescription
|
||||
+ " you control. When this leaves the battlefield, that card returns to the battlefield.)</i>";
|
||||
}
|
||||
}
|
||||
|
||||
class ChampionExileCost extends CostImpl {
|
||||
|
||||
private String exileZone;
|
||||
|
||||
public ChampionExileCost(FilterControlledPermanent filter, String exileZone) {
|
||||
ChampionExileCost(FilterControlledPermanent filter) {
|
||||
this.addTarget(new TargetControlledPermanent(1, 1, filter, true));
|
||||
this.text = "exile " + filter.getMessage() + " you control";
|
||||
this.exileZone = exileZone;
|
||||
}
|
||||
|
||||
public ChampionExileCost(ChampionExileCost cost) {
|
||||
private ChampionExileCost(ChampionExileCost cost) {
|
||||
super(cost);
|
||||
this.exileZone = cost.exileZone;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean pay(Ability ability, Game game, Ability source, UUID controllerId, boolean noMana, Cost costToPay) {
|
||||
Player controller = game.getPlayer(controllerId);
|
||||
MageObject sourceObject = ability.getSourceObject(game);
|
||||
if (controller != null && sourceObject != null) {
|
||||
if (targets.choose(Outcome.Exile, controllerId, source.getSourceId(), game)) {
|
||||
UUID exileId = CardUtil.getExileZoneId(game, ability.getSourceId(), ability.getSourceObjectZoneChangeCounter()); // exileId important for return effect
|
||||
for (UUID targetId : targets.get(0).getTargets()) {
|
||||
Permanent permanent = game.getPermanent(targetId);
|
||||
if (permanent == null) {
|
||||
return false;
|
||||
}
|
||||
paid |= controller.moveCardToExileWithInfo(permanent, exileId, sourceObject.getIdName() + " championed permanents", source, game, Zone.BATTLEFIELD, true);
|
||||
if (paid) {
|
||||
game.fireEvent(GameEvent.getEvent(GameEvent.EventType.CREATURE_CHAMPIONED, permanent.getId(), source, controllerId));
|
||||
}
|
||||
}
|
||||
if (controller == null || !targets.choose(Outcome.Exile, controllerId, source.getSourceId(), game)) {
|
||||
return paid;
|
||||
}
|
||||
for (UUID targetId : targets.get(0).getTargets()) {
|
||||
Permanent permanent = game.getPermanent(targetId);
|
||||
if (permanent == null) {
|
||||
return false;
|
||||
}
|
||||
paid |= controller.moveCardsToExile(
|
||||
permanent, source, game, true,
|
||||
CardUtil.getExileZoneId(game, source),
|
||||
CardUtil.getSourceName(game, source)
|
||||
);
|
||||
if (paid) {
|
||||
game.fireEvent(GameEvent.getEvent(GameEvent.EventType.CREATURE_CHAMPIONED, permanent.getId(), source, controllerId));
|
||||
}
|
||||
}
|
||||
return paid;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue