mirror of
https://github.com/magefree/mage.git
synced 2025-12-25 04:52:07 -08:00
Refactored cards that use similar abilities
This commit is contained in:
parent
292105f60e
commit
b29c70a3c7
15 changed files with 305 additions and 373 deletions
|
|
@ -0,0 +1,71 @@
|
|||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package mage.abilities.common;
|
||||
|
||||
import java.util.UUID;
|
||||
import mage.abilities.TriggeredAbilityImpl;
|
||||
import mage.abilities.effects.Effect;
|
||||
import mage.constants.Zone;
|
||||
import mage.filter.common.FilterCreaturePermanent;
|
||||
import mage.game.Game;
|
||||
import mage.game.events.GameEvent;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Styxo
|
||||
*/
|
||||
public class AttacksWithCreaturesTriggeredAbility extends TriggeredAbilityImpl {
|
||||
|
||||
private FilterCreaturePermanent filter;
|
||||
private int minAttackers;
|
||||
|
||||
public AttacksWithCreaturesTriggeredAbility(Effect effect, int minAttackers) {
|
||||
this(effect, minAttackers, new FilterCreaturePermanent("creatures"));
|
||||
}
|
||||
|
||||
public AttacksWithCreaturesTriggeredAbility(Effect effect, int minAttackers, FilterCreaturePermanent filter) {
|
||||
super(Zone.BATTLEFIELD, effect);
|
||||
this.filter = filter;
|
||||
this.minAttackers = minAttackers;
|
||||
}
|
||||
|
||||
public AttacksWithCreaturesTriggeredAbility(final AttacksWithCreaturesTriggeredAbility ability) {
|
||||
super(ability);
|
||||
this.filter = ability.filter;
|
||||
this.minAttackers = ability.minAttackers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AttacksWithCreaturesTriggeredAbility copy() {
|
||||
return new AttacksWithCreaturesTriggeredAbility(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkEventType(GameEvent event, Game game) {
|
||||
return event.getType() == GameEvent.EventType.DECLARED_ATTACKERS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkTrigger(GameEvent event, Game game) {
|
||||
int attackerCount = 0;
|
||||
for (UUID attacker : game.getCombat().getAttackers()) {
|
||||
if (filter.match(game.getPermanent(attacker), game)) {
|
||||
attackerCount++;
|
||||
}
|
||||
}
|
||||
return attackerCount >= minAttackers && game.getCombat().getAttackerId().equals(getControllerId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRule() {
|
||||
StringBuilder sb = new StringBuilder("Whenever you attack with " + minAttackers + " or more ");
|
||||
sb.append(filter.getMessage());
|
||||
sb.append(", ");
|
||||
sb.append(super.getRule());
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -30,9 +30,11 @@ package mage.abilities.effects.common;
|
|||
import mage.MageObject;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.effects.OneShotEffect;
|
||||
import mage.cards.Card;
|
||||
import mage.cards.Cards;
|
||||
import mage.cards.CardsImpl;
|
||||
import mage.constants.Outcome;
|
||||
import mage.constants.Zone;
|
||||
import mage.game.Game;
|
||||
import mage.players.Player;
|
||||
import mage.util.CardUtil;
|
||||
|
|
@ -44,10 +46,19 @@ import mage.util.CardUtil;
|
|||
public class LookLibraryTopCardTargetPlayerEffect extends OneShotEffect {
|
||||
|
||||
protected int amount;
|
||||
|
||||
protected boolean putToGraveyard;
|
||||
|
||||
public LookLibraryTopCardTargetPlayerEffect(int amount) {
|
||||
super(Outcome.Benefit);
|
||||
this.amount = amount;
|
||||
this.putToGraveyard = false;
|
||||
setText();
|
||||
}
|
||||
|
||||
public LookLibraryTopCardTargetPlayerEffect(int amount, boolean putToGraveyard) {
|
||||
super(Outcome.Benefit);
|
||||
this.amount = amount;
|
||||
this.putToGraveyard = putToGraveyard;
|
||||
setText();
|
||||
}
|
||||
|
||||
|
|
@ -58,6 +69,7 @@ public class LookLibraryTopCardTargetPlayerEffect extends OneShotEffect {
|
|||
public LookLibraryTopCardTargetPlayerEffect(final LookLibraryTopCardTargetPlayerEffect effect) {
|
||||
super(effect);
|
||||
amount = effect.amount;
|
||||
putToGraveyard = effect.putToGraveyard;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -74,21 +86,38 @@ public class LookLibraryTopCardTargetPlayerEffect extends OneShotEffect {
|
|||
Cards cards = new CardsImpl();
|
||||
cards.addAll(targetPlayer.getLibrary().getTopCards(game, amount));
|
||||
player.lookAtCards(sourceObject.getName(), cards, game);
|
||||
if (putToGraveyard) {
|
||||
for (Card card : cards.getCards(game)) {
|
||||
if (player.chooseUse(outcome, "Do you wish to put card into the player's graveyard?", source, game)) {
|
||||
player.moveCardToGraveyardWithInfo(card, source.getSourceId(), game, Zone.LIBRARY);
|
||||
} else {
|
||||
game.informPlayers(player.getLogName() + " puts the card back on top of the library.");
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
private void setText() {
|
||||
StringBuilder sb = new StringBuilder("look at the top ");
|
||||
StringBuilder sb = new StringBuilder("look at the top ");
|
||||
if (amount > 1) {
|
||||
sb.append(CardUtil.numberToText(amount));
|
||||
sb.append(" cards ");
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
sb.append(" card ");
|
||||
}
|
||||
sb.append("of target player's library");
|
||||
if (putToGraveyard) {
|
||||
sb.append(". You may put ");
|
||||
if (amount > 1) {
|
||||
sb.append("those cards");
|
||||
} else {
|
||||
sb.append("that card");
|
||||
}
|
||||
sb.append(" into that player's graveyard");
|
||||
}
|
||||
this.staticText = sb.toString();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package mage.abilities.effects.common;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.Mode;
|
||||
import mage.abilities.effects.OneShotEffect;
|
||||
import mage.constants.Outcome;
|
||||
import mage.constants.Zone;
|
||||
import mage.game.Game;
|
||||
import mage.game.permanent.Permanent;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Styxo
|
||||
*/
|
||||
public class ShuffleIntoLibraryTargetEffect extends OneShotEffect {
|
||||
|
||||
public ShuffleIntoLibraryTargetEffect() {
|
||||
super(Outcome.Detriment);
|
||||
}
|
||||
|
||||
public ShuffleIntoLibraryTargetEffect(String effectText) {
|
||||
super(Outcome.Detriment);
|
||||
this.staticText = effectText;
|
||||
}
|
||||
|
||||
public ShuffleIntoLibraryTargetEffect(final ShuffleIntoLibraryTargetEffect effect) {
|
||||
super(effect);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ShuffleIntoLibraryTargetEffect copy() {
|
||||
return new ShuffleIntoLibraryTargetEffect(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Permanent permanent = game.getPermanent(targetPointer.getFirst(game, source));
|
||||
if (permanent != null) {
|
||||
if (permanent.moveToZone(Zone.LIBRARY, source.getSourceId(), game, true)) {
|
||||
game.getPlayer(permanent.getOwnerId()).shuffleLibrary(source, game);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getText(Mode mode) {
|
||||
if (staticText != null && !staticText.isEmpty()) {
|
||||
return staticText;
|
||||
} else {
|
||||
return "choose target " + mode.getTargets().get(0).getTargetName() + ". Its owner shuffles it into his or her library";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package mage.abilities.effects.common.continuous;
|
||||
|
||||
import java.util.UUID;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.effects.AsThoughEffectImpl;
|
||||
import mage.constants.AsThoughEffectType;
|
||||
import mage.constants.Duration;
|
||||
import mage.constants.Outcome;
|
||||
import mage.game.Game;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Styxo
|
||||
*/
|
||||
public class ActivateAbilitiesAnyTimeYouCouldCastInstantEffect extends AsThoughEffectImpl {
|
||||
|
||||
private Class activatedAbility;
|
||||
|
||||
public ActivateAbilitiesAnyTimeYouCouldCastInstantEffect(Class activatedAbility, String activatedAbilityName) {
|
||||
super(AsThoughEffectType.ACTIVATE_AS_INSTANT, Duration.EndOfGame, Outcome.Benefit);
|
||||
this.activatedAbility = activatedAbility;
|
||||
staticText = "You may activate " + activatedAbilityName + " any time you could cast an instant";
|
||||
}
|
||||
|
||||
public ActivateAbilitiesAnyTimeYouCouldCastInstantEffect(final ActivateAbilitiesAnyTimeYouCouldCastInstantEffect effect) {
|
||||
super(effect);
|
||||
this.activatedAbility = effect.activatedAbility;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActivateAbilitiesAnyTimeYouCouldCastInstantEffect copy() {
|
||||
return new ActivateAbilitiesAnyTimeYouCouldCastInstantEffect(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean applies(UUID objectId, Ability affectedAbility, Ability source, Game game) {
|
||||
if (affectedAbility.getControllerId().equals(source.getControllerId())
|
||||
&& activatedAbility.isInstance(affectedAbility)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) {
|
||||
return false; // Not used
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package mage.abilities.effects.common.cost;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
import mage.constants.CostModificationType;
|
||||
import mage.constants.Duration;
|
||||
import mage.constants.Outcome;
|
||||
import mage.game.Game;
|
||||
import mage.util.CardUtil;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Styxo
|
||||
*/
|
||||
public class AbilitiesCostReductionControllerEffect extends CostModificationEffectImpl {
|
||||
|
||||
private Class activatedAbility;
|
||||
|
||||
public AbilitiesCostReductionControllerEffect(Class activatedAbility, String activatedAbilityName) {
|
||||
super(Duration.WhileOnBattlefield, Outcome.Benefit, CostModificationType.REDUCE_COST);
|
||||
this.activatedAbility = activatedAbility;
|
||||
staticText = activatedAbilityName + " costs you pay cost {1} less";
|
||||
}
|
||||
|
||||
public AbilitiesCostReductionControllerEffect(AbilitiesCostReductionControllerEffect effect) {
|
||||
super(effect);
|
||||
this.activatedAbility = effect.activatedAbility;
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
public AbilitiesCostReductionControllerEffect copy() {
|
||||
return new AbilitiesCostReductionControllerEffect(this);
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
public boolean apply(Game game, Ability source, Ability abilityToModify) {
|
||||
CardUtil.reduceCost(abilityToModify, 1);
|
||||
return true;
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
public boolean applies(Ability abilityToModify, Ability source, Game game) {
|
||||
return abilityToModify.getControllerId().equals(source.getControllerId())
|
||||
&& activatedAbility.isInstance(abilityToModify);
|
||||
}
|
||||
}
|
||||
|
|
@ -25,7 +25,6 @@
|
|||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
|
||||
package mage.target.common;
|
||||
|
||||
import mage.filter.common.FilterControlledCreaturePermanent;
|
||||
|
|
@ -44,6 +43,10 @@ public class TargetControlledCreaturePermanent extends TargetControlledPermanent
|
|||
this(numTargets, numTargets, new FilterControlledCreaturePermanent(), false);
|
||||
}
|
||||
|
||||
public TargetControlledCreaturePermanent(int minNumTargets, int maxNumTargets) {
|
||||
this(minNumTargets, maxNumTargets, new FilterControlledCreaturePermanent(), false);
|
||||
}
|
||||
|
||||
public TargetControlledCreaturePermanent(FilterControlledCreaturePermanent filter) {
|
||||
super(1, 1, filter, false);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue