Merge remote-tracking branch 'fork/master'

This commit is contained in:
vraskulin 2017-02-27 16:33:47 +03:00
commit f309717616
131 changed files with 1655 additions and 755 deletions

View file

@ -88,11 +88,7 @@ public class AttacksAttachedTriggeredAbility extends TriggeredAbilityImpl {
@Override
public String getRule() {
StringBuilder sb = new StringBuilder("Whenever ");
if (attachmentType.equals(AttachmentType.EQUIPMENT)) {
sb.append("equipped");
} else {
sb.append("enchanted");
}
sb.append(attachmentType.verb().toLowerCase());
return sb.append(" creature attacks, ").append(super.getRule()).toString();
}
}

View file

@ -23,8 +23,7 @@ public class AfterUpkeepStepCondtion implements Condition {
@Override
public boolean apply(Game game, Ability source) {
return !(game.getStep().getType() == PhaseStep.UNTAP
|| game.getStep().getType() == PhaseStep.UPKEEP);
return game.getStep().getType().isAfter(PhaseStep.UPKEEP);
}
@Override

View file

@ -26,10 +26,7 @@ public class BeforeBlockersAreDeclaredCondition implements Condition {
@Override
public boolean apply(Game game, Ability source) {
return !(game.getStep().getType().equals(PhaseStep.DECLARE_BLOCKERS)
|| game.getStep().getType().equals(PhaseStep.FIRST_COMBAT_DAMAGE)
|| game.getStep().getType().equals(PhaseStep.COMBAT_DAMAGE)
|| game.getStep().getType().equals(PhaseStep.END_COMBAT));
return game.getStep().getType().isBefore(PhaseStep.DECLARE_BLOCKERS);
}
@Override

View file

@ -27,11 +27,6 @@
*/
package mage.abilities.costs.mana;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import mage.Mana;
import mage.abilities.Ability;
import mage.abilities.costs.Cost;
@ -45,13 +40,15 @@ import mage.players.Player;
import mage.target.Targets;
import mage.util.ManaUtil;
import java.util.*;
/**
* @author BetaSteward_at_googlemail.com
* @param <T>
*/
public class ManaCostsImpl<T extends ManaCost> extends ArrayList<T> implements ManaCosts<T> {
protected UUID id;
protected final UUID id;
protected String text = null;
private static Map<String, ManaCosts> costs = new HashMap<>();
@ -323,7 +320,7 @@ public class ManaCostsImpl<T extends ManaCost> extends ArrayList<T> implements M
if (mana == null || mana.isEmpty()) {
return;
}
String[] symbols = mana.split("^\\{|\\}\\{|\\}$");
String[] symbols = mana.split("^\\{|}\\{|}$");
int modifierForX = 0;
for (String symbol : symbols) {
if (!symbol.isEmpty()) {

View file

@ -28,6 +28,7 @@
package mage.abilities.decorator;
import java.util.UUID;
import mage.abilities.Ability;
import mage.abilities.condition.Condition;
import mage.abilities.effects.AsThoughEffect;
@ -36,10 +37,9 @@ import mage.constants.Duration;
import mage.game.Game;
/**
*
* @author LevelX2
*/
public class ConditionalAsThoughEffect extends AsThoughEffectImpl {
public class ConditionalAsThoughEffect extends AsThoughEffectImpl {
protected AsThoughEffect effect;
protected AsThoughEffect otherwiseEffect;
@ -59,9 +59,9 @@ public class ConditionalAsThoughEffect extends AsThoughEffectImpl {
public ConditionalAsThoughEffect(final ConditionalAsThoughEffect effect) {
super(effect);
this.effect = (AsThoughEffect) effect.effect.copy();
this.effect = effect.effect.copy();
if (effect.otherwiseEffect != null) {
this.otherwiseEffect = (AsThoughEffect) effect.otherwiseEffect.copy();
this.otherwiseEffect = effect.otherwiseEffect.copy();
}
this.condition = effect.condition;
this.conditionState = effect.conditionState;

View file

@ -28,6 +28,7 @@
package mage.abilities.effects;
import java.util.UUID;
import mage.MageObject;
import mage.abilities.Ability;
import mage.abilities.SpellAbility;
@ -55,10 +56,10 @@ import mage.target.common.TargetCardInGraveyard;
* was not cast (so from Zone != Hand), this effect gets the target to whitch to
* attach it and adds the Aura the the battlefield and attachs it to the target.
* The "attachTo:" value in game state has to be set therefore.
*
* <p>
* If no "attachTo:" value is defined, the controlling player has to chose the
* aura target.
*
* <p>
* This effect is automatically added to ContinuousEffects at the start of a
* game
*
@ -204,15 +205,15 @@ public class AuraReplacementEffect extends ReplacementEffectImpl {
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (((ZoneChangeEvent) event).getToZone().equals(Zone.BATTLEFIELD)
&& !(((ZoneChangeEvent) event).getFromZone().equals(Zone.STACK))) {
if (((ZoneChangeEvent) event).getToZone() == Zone.BATTLEFIELD
&& (((ZoneChangeEvent) event).getFromZone() != Zone.STACK)) {
Card card = game.getCard(event.getTargetId());
if (card != null && (card.getCardType().contains(CardType.ENCHANTMENT) && card.hasSubtype("Aura", game)
|| // in case of transformable enchantments
(game.getState().getValue(TransformAbility.VALUE_KEY_ENTER_TRANSFORMED + card.getId()) != null
&& card.getSecondCardFace() != null
&& card.getSecondCardFace().getCardType().contains(CardType.ENCHANTMENT)
&& card.getSecondCardFace().hasSubtype("Aura", game)))) {
&& card.getSecondCardFace() != null
&& card.getSecondCardFace().getCardType().contains(CardType.ENCHANTMENT)
&& card.getSecondCardFace().hasSubtype("Aura", game)))) {
return true;
}
}

View file

@ -33,6 +33,8 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
import mage.MageObjectReference;
import mage.abilities.Ability;
import mage.abilities.MageSingleton;
@ -51,7 +53,6 @@ import mage.game.Game;
import mage.players.Player;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public abstract class ContinuousEffectImpl extends EffectImpl implements ContinuousEffect {
@ -171,9 +172,9 @@ public abstract class ContinuousEffectImpl extends EffectImpl implements Continu
public void init(Ability source, Game game) {
targetPointer.init(game, source);
//20100716 - 611.2c
if (AbilityType.ACTIVATED.equals(source.getAbilityType())
|| AbilityType.SPELL.equals(source.getAbilityType())
|| AbilityType.TRIGGERED.equals(source.getAbilityType())) {
if (AbilityType.ACTIVATED == source.getAbilityType()
|| AbilityType.SPELL == source.getAbilityType()
|| AbilityType.TRIGGERED == source.getAbilityType()) {
if (layer != null) {
switch (layer) {
case CopyEffects_1:
@ -197,7 +198,7 @@ public abstract class ContinuousEffectImpl extends EffectImpl implements Continu
@Override
public boolean isInactive(Ability source, Game game) {
if (duration.equals(Duration.UntilYourNextTurn)) {
if (duration == Duration.UntilYourNextTurn) {
Player player = game.getPlayer(startingControllerId);
if (player != null) {
if (player.isInGame()) {
@ -271,19 +272,13 @@ public abstract class ContinuousEffectImpl extends EffectImpl implements Continu
@Override
public Set<UUID> isDependentTo(List<ContinuousEffect> allEffectsInLayer) {
if (dependendToType != null) {
// the dependent classes needs to be an enclosed class for dependent check of continuous effects
Set<UUID> dependentTo = null;
for (ContinuousEffect effect : allEffectsInLayer) {
if (effect.getDependencyTypes().contains(dependendToType)) {
if (dependentTo == null) {
dependentTo = new HashSet<>();
}
dependentTo.add(effect.getId());
}
}
return dependentTo;
return allEffectsInLayer.stream()
.filter(effect -> effect.getDependencyTypes().contains(dependendToType))
.map(Effect::getId)
.collect(Collectors.toSet());
}
return null;
return new HashSet<>();
}
@Override

View file

@ -27,40 +27,12 @@
*/
package mage.abilities.effects;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.EnumMap;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.UUID;
import mage.MageObject;
import mage.abilities.Ability;
import mage.abilities.ActivatedAbility;
import mage.abilities.MageSingleton;
import mage.abilities.SpellAbility;
import mage.abilities.StaticAbility;
import mage.abilities.*;
import mage.abilities.keyword.SpliceOntoArcaneAbility;
import mage.cards.Cards;
import mage.cards.CardsImpl;
import mage.constants.AbilityType;
import mage.constants.AsThoughEffectType;
import mage.constants.CostModificationType;
import mage.constants.Duration;
import mage.constants.EffectType;
import mage.constants.Layer;
import mage.constants.ManaType;
import mage.constants.Outcome;
import mage.constants.SpellAbilityType;
import mage.constants.SubLayer;
import mage.constants.Zone;
import mage.constants.*;
import mage.filter.FilterCard;
import mage.filter.predicate.Predicate;
import mage.filter.predicate.Predicates;
@ -77,8 +49,11 @@ import mage.players.Player;
import mage.target.common.TargetCardInHand;
import org.apache.log4j.Logger;
import java.io.Serializable;
import java.util.*;
import java.util.Map.Entry;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class ContinuousEffects implements Serializable {
@ -218,7 +193,7 @@ public class ContinuousEffects implements Serializable {
case WhileOnStack:
case WhileInGraveyard:
HashSet<Ability> abilities = layeredEffects.getAbility(effect.getId());
if (abilities != null) {
if (!abilities.isEmpty()) {
for (Ability ability : abilities) {
// If e.g. triggerd abilities (non static) created the effect, the ability must not be in usable zone (e.g. Unearth giving Haste effect)
if (!(ability instanceof StaticAbility) || ability.isInUseableZone(game, null, null)) {
@ -358,7 +333,6 @@ public class ContinuousEffects implements Serializable {
}
/**
*
* @param event
* @param game
* @return a list of all {@link ReplacementEffect} that apply to the current
@ -717,7 +691,8 @@ public class ContinuousEffects implements Serializable {
spliceAbilities.remove(selectedAbility);
}
}
} while (!spliceAbilities.isEmpty() && controller.chooseUse(Outcome.Benefit, "Splice another card?", abilityToModify, game));
}
while (!spliceAbilities.isEmpty() && controller.chooseUse(Outcome.Benefit, "Splice another card?", abilityToModify, game));
controller.revealCards("Spliced cards", cardsToReveal, game);
}
}
@ -727,10 +702,10 @@ public class ContinuousEffects implements Serializable {
* Checks if an event won't happen because of an rule modifying effect
*
* @param event
* @param targetAbility ability the event is attached to. can be null.
* @param targetAbility ability the event is attached to. can be null.
* @param game
* @param checkPlayableMode true if the event does not really happen but
* it's checked if the event would be replaced
* it's checked if the event would be replaced
* @return
*/
public boolean preventedByRuleModification(GameEvent event, Ability targetAbility, Game game, boolean checkPlayableMode) {
@ -777,7 +752,7 @@ public class ContinuousEffects implements Serializable {
do {
HashMap<ReplacementEffect, HashSet<Ability>> rEffects = getApplicableReplacementEffects(event, game);
// Remove all consumed effects (ability dependant)
for (Iterator<ReplacementEffect> it1 = rEffects.keySet().iterator(); it1.hasNext();) {
for (Iterator<ReplacementEffect> it1 = rEffects.keySet().iterator(); it1.hasNext(); ) {
ReplacementEffect entry = it1.next();
if (consumed.containsKey(entry.getId())) {
HashSet<UUID> consumedAbilitiesIds = consumed.get(entry.getId());
@ -865,9 +840,8 @@ public class ContinuousEffects implements Serializable {
if (consumed.containsKey(rEffect.getId())) {
HashSet<UUID> set = consumed.get(rEffect.getId());
if (rAbility != null) {
if (!set.contains(rAbility.getId())) {
set.add(rAbility.getId());
}
set.add(rAbility.getId());
}
} else {
HashSet<UUID> set = new HashSet<>();
@ -936,7 +910,7 @@ public class ContinuousEffects implements Serializable {
for (ContinuousEffect effect : layer) {
if (activeLayerEffects.contains(effect) && !appliedEffects.contains(effect.getId())) { // Effect does still exist and was not applied yet
Set<UUID> dependentTo = effect.isDependentTo(layer);
if (dependentTo != null && !appliedEffects.containsAll(dependentTo)) {
if (!appliedEffects.containsAll(dependentTo)) {
waitingEffects.put(effect, dependentTo);
continue;
}
@ -959,7 +933,7 @@ public class ContinuousEffects implements Serializable {
if (!waitingEffects.isEmpty()) {
// check if waiting effects can be applied now
for (Iterator<Map.Entry<ContinuousEffect, Set<UUID>>> iterator = waitingEffects.entrySet().iterator(); iterator.hasNext();) {
for (Iterator<Map.Entry<ContinuousEffect, Set<UUID>>> iterator = waitingEffects.entrySet().iterator(); iterator.hasNext(); ) {
Map.Entry<ContinuousEffect, Set<UUID>> entry = iterator.next();
if (appliedEffects.containsAll(entry.getValue())) { // all dependent to effects are applied now so apply the effect itself
appliedAbilities = appliedEffectAbilities.get(entry.getKey());
@ -1039,7 +1013,7 @@ public class ContinuousEffects implements Serializable {
for (ContinuousEffect effect : layer) {
if (numberOfEffects > 1) { // If an effect is dependent to not applied effects yet of this layer, so wait to apply this effect
Set<UUID> dependentTo = effect.isDependentTo(layer);
if (dependentTo != null && !appliedEffects.containsAll(dependentTo)) {
if (!appliedEffects.containsAll(dependentTo)) {
waitingEffects.put(effect, dependentTo);
continue;
}
@ -1162,17 +1136,16 @@ public class ContinuousEffects implements Serializable {
private void setControllerForEffect(ContinuousEffectsList<?> effects, UUID sourceId, UUID controllerId) {
for (Effect effect : effects) {
HashSet<Ability> abilities = effects.getAbility(effect.getId());
if (abilities != null) {
for (Ability ability : abilities) {
if (ability.getSourceId() != null) {
if (ability.getSourceId().equals(sourceId)) {
ability.setControllerId(controllerId);
}
} else if (!ability.getZone().equals(Zone.COMMAND)) {
logger.fatal("Continuous effect for ability with no sourceId Ability: " + ability);
for (Ability ability : abilities) {
if (ability.getSourceId() != null) {
if (ability.getSourceId().equals(sourceId)) {
ability.setControllerId(controllerId);
}
} else if (ability.getZone() != Zone.COMMAND) {
logger.fatal("Continuous effect for ability with no sourceId Ability: " + ability);
}
}
}
}

View file

@ -34,6 +34,7 @@ import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import mage.abilities.Ability;
import mage.abilities.MageSingleton;
import mage.constants.Duration;
@ -41,9 +42,8 @@ import mage.game.Game;
import org.apache.log4j.Logger;
/**
*
* @author BetaSteward_at_googlemail.com
* @param <T>
* @author BetaSteward_at_googlemail.com
*/
public class ContinuousEffectsList<T extends ContinuousEffect> extends ArrayList<T> {
@ -74,7 +74,7 @@ public class ContinuousEffectsList<T extends ContinuousEffect> extends ArrayList
}
public void removeEndOfTurnEffects() {
for (Iterator<T> i = this.iterator(); i.hasNext();) {
for (Iterator<T> i = this.iterator(); i.hasNext(); ) {
T entry = i.next();
if (entry.getDuration() == Duration.EndOfTurn) {
i.remove();
@ -84,7 +84,7 @@ public class ContinuousEffectsList<T extends ContinuousEffect> extends ArrayList
}
public void removeEndOfCombatEffects() {
for (Iterator<T> i = this.iterator(); i.hasNext();) {
for (Iterator<T> i = this.iterator(); i.hasNext(); ) {
T entry = i.next();
if (entry.getDuration() == Duration.EndOfCombat) {
i.remove();
@ -94,7 +94,7 @@ public class ContinuousEffectsList<T extends ContinuousEffect> extends ArrayList
}
public void removeInactiveEffects(Game game) {
for (Iterator<T> i = this.iterator(); i.hasNext();) {
for (Iterator<T> i = this.iterator(); i.hasNext(); ) {
T entry = i.next();
if (isInactive(entry, game)) {
i.remove();
@ -169,7 +169,7 @@ public class ContinuousEffectsList<T extends ContinuousEffect> extends ArrayList
}
public HashSet<Ability> getAbility(UUID effectId) {
return effectAbilityMap.get(effectId);
return effectAbilityMap.getOrDefault(effectId, new HashSet<>());
}
public void removeEffects(UUID effectIdToRemove, Set<Ability> abilitiesToRemove) {
@ -178,7 +178,7 @@ public class ContinuousEffectsList<T extends ContinuousEffect> extends ArrayList
abilities.removeAll(abilitiesToRemove);
}
if (abilities == null || abilities.isEmpty()) {
for (Iterator<T> iterator = this.iterator(); iterator.hasNext();) {
for (Iterator<T> iterator = this.iterator(); iterator.hasNext(); ) {
ContinuousEffect effect = iterator.next();
if (effect.getId().equals(effectIdToRemove)) {
iterator.remove();

View file

@ -97,13 +97,13 @@ public class EntersBattlefieldEffect extends ReplacementEffectImpl {
public boolean checksEventType(GameEvent event, Game game) {
switch (enterEventType) {
case OTHER:
return EventType.ENTERS_THE_BATTLEFIELD.equals(event.getType());
return EventType.ENTERS_THE_BATTLEFIELD == event.getType();
case SELF:
return EventType.ENTERS_THE_BATTLEFIELD_SELF.equals(event.getType());
return EventType.ENTERS_THE_BATTLEFIELD_SELF == event.getType();
case CONTROL:
return EventType.ENTERS_THE_BATTLEFIELD_CONTROL.equals(event.getType());
return EventType.ENTERS_THE_BATTLEFIELD_CONTROL == event.getType();
case COPY:
return EventType.ENTERS_THE_BATTLEFIELD_COPY.equals(event.getType());
return EventType.ENTERS_THE_BATTLEFIELD_COPY == event.getType();
}
return false;
}

View file

@ -44,7 +44,7 @@ import mage.players.Player;
*/
public abstract class PayCostToAttackBlockEffectImpl extends ReplacementEffectImpl implements PayCostToAttackBlockEffect {
public static enum RestrictType {
public enum RestrictType {
ATTACK("attack"),
ATTACK_AND_BLOCK("attack or block"),
@ -111,7 +111,7 @@ public abstract class PayCostToAttackBlockEffectImpl extends ReplacementEffectIm
case BLOCK:
return event.getType().equals(GameEvent.EventType.DECLARE_BLOCKER);
case ATTACK_AND_BLOCK:
return event.getType() == GameEvent.EventType.DECLARE_ATTACKER || event.getType().equals(GameEvent.EventType.DECLARE_BLOCKER);
return event.getType() == GameEvent.EventType.DECLARE_ATTACKER || event.getType() == EventType.DECLARE_BLOCKER;
}
return false;
}

View file

@ -61,8 +61,8 @@ public class AddCombatAndMainPhaseEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
// 15.07.2006 If it's somehow not a main phase when Fury of the Horde resolves, all it does is untap all creatures that attacked that turn. No new phases are created.
if (TurnPhase.PRECOMBAT_MAIN.equals(game.getTurn().getPhaseType())
|| TurnPhase.POSTCOMBAT_MAIN.equals(game.getTurn().getPhaseType())) {
if (game.getTurn().getPhaseType() == TurnPhase.PRECOMBAT_MAIN
|| game.getTurn().getPhaseType() == TurnPhase.POSTCOMBAT_MAIN) {
// we can't add two turn modes at once, will add additional post combat on delayed trigger resolution
TurnMod combat = new TurnMod(source.getControllerId(), TurnPhase.COMBAT, TurnPhase.POSTCOMBAT_MAIN, false);
game.getState().getTurnMods().add(combat);

View file

@ -109,16 +109,12 @@ public class CantBeTargetedAttachedEffect extends ContinuousRuleModifyingEffectI
return staticText;
}
StringBuilder sb = new StringBuilder();
if (attachmentType.equals(AttachmentType.AURA)) {
sb.append("Enchanted creature");
} else {
sb.append("Equipped creature");
}
sb.append(attachmentType.verb() + " creature");
sb.append(" can't be the target of ");
sb.append(filterSource.getMessage());
if (!duration.toString().isEmpty()) {
sb.append(' ');
if (duration.equals(Duration.EndOfTurn)) {
if (duration == Duration.EndOfTurn) {
sb.append("this turn");
} else {
sb.append(duration.toString());

View file

@ -114,7 +114,7 @@ public class DontUntapInControllersNextUntapStepTargetEffect extends ContinuousR
public boolean applies(GameEvent event, Ability source, Game game) {
// the check if a permanent untap pahse is already handled is needed if multiple effects are added to prevent untap in next untap step of controller
// if we don't check it for every untap step of a turn only one effect would be consumed instead of all be valid for the next untap step
if (GameEvent.EventType.UNTAP_STEP.equals(event.getType())) {
if (event.getType() == EventType.UNTAP_STEP) {
boolean allHandled = true;
for (UUID targetId : getTargetPointer().getTargets(game, source)) {
Permanent permanent = game.getPermanent(targetId);

View file

@ -56,7 +56,7 @@ public class DontUntapInControllersUntapStepEnchantedEffect extends ContinuousRu
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (PhaseStep.UNTAP.equals(game.getTurn().getStepType())) {
if (game.getTurn().getStepType() == PhaseStep.UNTAP) {
Permanent enchantment = game.getPermanent(source.getSourceId());
if (enchantment != null && enchantment.getAttachedTo() != null && event.getTargetId().equals(enchantment.getAttachedTo())) {
Permanent permanent = game.getPermanent(enchantment.getAttachedTo());

View file

@ -81,7 +81,7 @@ public class DontUntapInControllersUntapStepTargetEffect extends ContinuousRuleM
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (PhaseStep.UNTAP.equals(game.getTurn().getStepType())) {
if (game.getTurn().getStepType() == PhaseStep.UNTAP) {
for (UUID targetId : targetPointer.getTargets(game, source)) {
if (event.getTargetId().equals(targetId)) {
Permanent permanent = game.getPermanent(targetId);

View file

@ -107,7 +107,7 @@ public class DontUntapInOpponentsNextUntapStepAllEffect extends ContinuousRuleMo
return false;
}
// remember the turn of the untap step the effect has to be applied
if (GameEvent.EventType.UNTAP_STEP.equals(event.getType())) {
if (event.getType() == EventType.UNTAP_STEP) {
if (game.getActivePlayerId().equals(getTargetPointer().getFirst(game, source))) {
if (validForTurnNum == game.getTurnNum()) { // the turn has a second untap step but the effect is already related to the first untap step
discard();

View file

@ -190,7 +190,7 @@ public class LookLibraryAndPickControllerEffect extends LookLibraryControllerEff
if (player.choose(Outcome.DrawCard, cards, target, game)) {
Cards pickedCards = new CardsImpl(target.getTargets());
cards.removeAll(pickedCards);
if (targetPickedCards.equals(Zone.LIBRARY) && !putOnTopSelected) {
if (targetPickedCards == Zone.LIBRARY && !putOnTopSelected) {
player.putCardsOnBottomOfLibrary(pickedCards, game, source, true);
} else {
player.moveCards(pickedCards.getCards(game), targetPickedCards, source, game);

View file

@ -40,7 +40,6 @@ import mage.game.events.GameEvent;
import mage.game.permanent.Permanent;
/**
*
* @author jeff
*/
public class RegenerateAttachedEffect extends ReplacementEffectImpl {
@ -102,13 +101,8 @@ public class RegenerateAttachedEffect extends ReplacementEffectImpl {
}
return false;
}
private void setText() {
StringBuilder sb = new StringBuilder();
if (attachmentType == AttachmentType.AURA) {
sb.append("Regenerate enchanted creature");
} else if (attachmentType == AttachmentType.EQUIPMENT) {
sb.append("Regenerate equipped creature");
}
staticText = sb.toString();
staticText = "Regenerate " + attachmentType.verb().toLowerCase() + " creature";
}
}

View file

@ -44,11 +44,7 @@ public class AttacksIfAbleAttachedEffect extends RequirementEffect {
public AttacksIfAbleAttachedEffect(Duration duration, AttachmentType attachmentType) {
super(duration);
if (attachmentType.equals(AttachmentType.AURA)) {
this.staticText = "Enchanted creature attacks each turn if able";
} else {
this.staticText = "Equipped creature attacks each turn if able";
}
this.staticText = attachmentType.verb() + " creature attacks each turn if able";
}
public AttacksIfAbleAttachedEffect(final AttacksIfAbleAttachedEffect effect) {

View file

@ -51,7 +51,7 @@ public class BlocksIfAbleAllEffect extends RequirementEffect {
super(duration);
staticText = new StringBuilder(filter.getMessage())
.append(" block ")
.append(duration.equals(Duration.EndOfTurn) ? "this":"each")
.append(duration == Duration.EndOfTurn ? "this":"each")
.append(" turn if able").toString();
this.filter = filter;
}

View file

@ -36,7 +36,6 @@ import mage.game.Game;
import mage.game.permanent.Permanent;
/**
*
* @author LevelX2
*/
@ -44,11 +43,7 @@ public class BlocksIfAbleAttachedEffect extends RequirementEffect {
public BlocksIfAbleAttachedEffect(Duration duration, AttachmentType attachmentType) {
super(duration);
if (attachmentType.equals(AttachmentType.AURA)) {
this.staticText = "Enchanted creature blocks each turn if able";
} else {
this.staticText = "Equipped creature blocks each turn if able";
}
this.staticText = attachmentType.verb() + " creature blocks each turn if able";
}
public BlocksIfAbleAttachedEffect(final BlocksIfAbleAttachedEffect effect) {

View file

@ -27,7 +27,6 @@
*/
package mage.abilities.effects.common.combat;
import java.util.UUID;
import mage.abilities.Ability;
import mage.abilities.effects.AsThoughEffectImpl;
import mage.constants.AsThoughEffectType;
@ -38,18 +37,19 @@ import mage.filter.common.FilterCreaturePermanent;
import mage.game.Game;
import mage.game.permanent.Permanent;
import java.util.UUID;
/**
*
* @author Quercitron
*/
public class CanAttackAsThoughItDidntHaveDefenderAllEffect extends AsThoughEffectImpl {
private final FilterPermanent filter;
public CanAttackAsThoughItDidntHaveDefenderAllEffect(Duration duration) {
this(duration, new FilterCreaturePermanent());
}
public CanAttackAsThoughItDidntHaveDefenderAllEffect(Duration duration, FilterPermanent filter) {
super(AsThoughEffectType.ATTACK, duration, Outcome.Benefit);
this.filter = filter;
@ -76,12 +76,12 @@ public class CanAttackAsThoughItDidntHaveDefenderAllEffect extends AsThoughEffec
Permanent permanent = game.getPermanent(objectId);
return permanent != null && filter.match(permanent, game);
}
private String getText() {
StringBuilder sb = new StringBuilder(filter.getMessage());
sb.append(" can attack ");
if (!duration.toString().isEmpty()) {
if(Duration.EndOfTurn.equals(duration)) {
if (!duration.toString().isEmpty()) {
if (Duration.EndOfTurn == duration) {
sb.append("this turn");
} else {
sb.append(duration.toString());
@ -89,6 +89,6 @@ public class CanAttackAsThoughItDidntHaveDefenderAllEffect extends AsThoughEffec
sb.append(' ');
}
sb.append("as though they didn't have defender");
return sb.toString();
return sb.toString();
}
}

View file

@ -44,7 +44,7 @@ public class CanAttackAsThoughItDidntHaveDefenderSourceEffect extends AsThoughEf
public CanAttackAsThoughItDidntHaveDefenderSourceEffect(Duration duration) {
super(AsThoughEffectType.ATTACK, duration, Outcome.Benefit);
staticText = "{this} can attack "
+ (duration.equals(Duration.EndOfTurn) ? "this turn " : "")
+ (duration == Duration.EndOfTurn ? "this turn " : "")
+ "as though it didn't have defender";
}

View file

@ -37,7 +37,6 @@ import mage.game.Game;
import mage.game.permanent.Permanent;
/**
*
* @author LevelX2
*/
@ -45,11 +44,7 @@ public class CanBlockOnlyFlyingAttachedEffect extends RestrictionEffect {
public CanBlockOnlyFlyingAttachedEffect(AttachmentType attachmentType) {
super(Duration.WhileOnBattlefield);
if (attachmentType.equals(AttachmentType.AURA)) {
this.staticText = "Enchanted creature can block only creatures with flying";
} else {
this.staticText = "Equipped creature can block only creatures with flying";
}
this.staticText = attachmentType.verb() + " creature can block only creatures with flying";
}
public CanBlockOnlyFlyingAttachedEffect(final CanBlockOnlyFlyingAttachedEffect effect) {

View file

@ -20,11 +20,7 @@ public class CantAttackAloneAttachedEffect extends RestrictionEffect {
public CantAttackAloneAttachedEffect(AttachmentType attachmentType) {
super(Duration.WhileOnBattlefield);
if (attachmentType.equals(AttachmentType.AURA)) {
this.staticText = "Enchanted creature can't attack alone";
} else {
this.staticText = "Equipped creature can't attack alone";
}
this.staticText = attachmentType.verb() + " creature can't attack alone";
}
public CantAttackAloneAttachedEffect(final CantAttackAloneAttachedEffect effect) {

View file

@ -44,11 +44,7 @@ public class CantAttackAttachedEffect extends RestrictionEffect {
public CantAttackAttachedEffect(AttachmentType attachmentType) {
super(Duration.WhileOnBattlefield);
if (attachmentType.equals(AttachmentType.AURA)) {
this.staticText = "Enchanted creature can't attack";
} else {
this.staticText = "Equipped creature can't attack";
}
this.staticText = attachmentType.verb() + " creature can't attack";
}
public CantAttackAttachedEffect(final CantAttackAttachedEffect effect) {

View file

@ -48,7 +48,7 @@ public class CantAttackBlockAllEffect extends RestrictionEffect {
StringBuilder sb = new StringBuilder(filter.getMessage()).append(" can't attack or block");
if (!duration.toString().isEmpty()) {
sb.append(' ');
if (duration.equals(Duration.EndOfTurn)) {
if (duration == Duration.EndOfTurn) {
sb.append(" this turn");
} else {
sb.append(' ').append(duration.toString());

View file

@ -35,18 +35,13 @@ import mage.game.Game;
import mage.game.permanent.Permanent;
/**
*
* @author LevelX2
*/
public class CantAttackBlockAttachedEffect extends RestrictionEffect {
public CantAttackBlockAttachedEffect(AttachmentType attachmentType) {
super(Duration.WhileOnBattlefield);
if (attachmentType.equals(AttachmentType.AURA)) {
this.staticText = "Enchanted creature can't attack or block";
} else {
this.staticText = "Equipped creature can't attack or block";
}
this.staticText = attachmentType.verb() + " creature can't attack or block";
}
public CantAttackBlockAttachedEffect(final CantAttackBlockAttachedEffect effect) {

View file

@ -46,8 +46,8 @@ public class CantAttackBlockUnlessPaysAttachedEffect extends PayCostToAttackBloc
public CantAttackBlockUnlessPaysAttachedEffect(ManaCosts manaCosts, AttachmentType attachmentType) {
super(Duration.WhileOnBattlefield, Outcome.Detriment, RestrictType.ATTACK_AND_BLOCK, manaCosts);
staticText = (attachmentType.equals(AttachmentType.AURA) ? "Enchanted " : "Equipped ")
+ "creature can't attack or block unless its controller pays "
staticText = attachmentType.verb()
+ " creature can't attack or block unless its controller pays "
+ (manaCosts == null ? "" : manaCosts.getText());
}
@ -59,10 +59,10 @@ public class CantAttackBlockUnlessPaysAttachedEffect extends PayCostToAttackBloc
public boolean applies(GameEvent event, Ability source, Game game) {
Permanent enchantment = game.getPermanent(source.getSourceId());
if (enchantment != null && enchantment.getAttachedTo() != null) {
if (event.getType().equals(EventType.DECLARE_ATTACKER)) {
if (event.getType() == EventType.DECLARE_ATTACKER) {
return event.getSourceId().equals(enchantment.getAttachedTo());
}
if (event.getType().equals(EventType.DECLARE_BLOCKER)) {
if (event.getType() == EventType.DECLARE_BLOCKER) {
return event.getSourceId().equals(enchantment.getAttachedTo());
}
}

View file

@ -47,7 +47,7 @@ public class CantAttackBlockUnlessPaysSourceEffect extends PayCostToAttackBlockE
super(Duration.WhileOnBattlefield, Outcome.Detriment, restrictType, cost);
staticText = "{this} can't " + restrictType.toString() + " unless you "
+ cost == null ? "" : cost.getText()
+ (restrictType.equals(RestrictType.ATTACK) ? " <i>(This cost is paid as attackers are declared.)</i>" : "");
+ (restrictType == RestrictType.ATTACK ? " <i>(This cost is paid as attackers are declared.)</i>" : "");
}
public CantAttackBlockUnlessPaysSourceEffect(ManaCosts manaCosts, RestrictType restrictType) {
@ -62,10 +62,10 @@ public class CantAttackBlockUnlessPaysSourceEffect extends PayCostToAttackBlockE
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (!restrictType.equals(RestrictType.BLOCK) && event.getType().equals(EventType.DECLARE_ATTACKER)) {
if (!(restrictType == RestrictType.BLOCK) && event.getType() == EventType.DECLARE_ATTACKER) {
return event.getSourceId().equals(source.getSourceId());
}
if (!restrictType.equals(RestrictType.ATTACK) && event.getType().equals(EventType.DECLARE_BLOCKER)) {
if (!(restrictType == RestrictType.ATTACK) && event.getType() == EventType.DECLARE_BLOCKER) {
return event.getSourceId().equals(source.getSourceId());
}
return false;

View file

@ -46,11 +46,7 @@ public class CantAttackControllerAttachedEffect extends RestrictionEffect {
public CantAttackControllerAttachedEffect(AttachmentType attachmentType) {
super(Duration.WhileOnBattlefield);
if (attachmentType.equals(AttachmentType.AURA)) {
this.staticText = "Enchanted creature can't attack you or a planeswalker you control";
} else {
this.staticText = "Equipped creature can't attack you or a planeswalker you control";
}
this.staticText = attachmentType.verb() + " creature can't attack you or a planeswalker you control";
}
public CantAttackControllerAttachedEffect(final CantAttackControllerAttachedEffect effect) {

View file

@ -46,8 +46,8 @@ public class CantAttackUnlessPaysAttachedEffect extends PayCostToAttackBlockEffe
public CantAttackUnlessPaysAttachedEffect(ManaCosts manaCosts, AttachmentType attachmentType) {
super(Duration.WhileOnBattlefield, Outcome.Detriment, RestrictType.ATTACK, manaCosts);
staticText = (attachmentType.equals(AttachmentType.AURA) ? "Enchanted " : "Equipped ")
+ "creature can't attack unless its controller pays "
staticText = attachmentType.verb()
+ " creature can't attack unless its controller pays "
+ (manaCosts == null ? "" : manaCosts.getText());
}
@ -59,7 +59,7 @@ public class CantAttackUnlessPaysAttachedEffect extends PayCostToAttackBlockEffe
public boolean applies(GameEvent event, Ability source, Game game) {
Permanent enchantment = game.getPermanent(source.getSourceId());
if (enchantment != null && enchantment.getAttachedTo() != null) {
if (event.getType().equals(EventType.DECLARE_ATTACKER)) {
if (event.getType() == EventType.DECLARE_ATTACKER) {
return event.getSourceId().equals(enchantment.getAttachedTo());
}
}

View file

@ -59,7 +59,7 @@ public class CantAttackYouAllEffect extends RestrictionEffect {
this.alsoPlaneswalker = alsoPlaneswalker;
staticText = filterAttacker.getMessage() + " can't attack you"
+ (alsoPlaneswalker ? " or a planeswalker you control" : "")
+ (duration.equals(Duration.UntilYourNextTurn) ? " until your next turn" : "");
+ (duration == Duration.UntilYourNextTurn ? " until your next turn" : "");
}
CantAttackYouAllEffect(final CantAttackYouAllEffect effect) {

View file

@ -47,7 +47,7 @@ public class CantBeBlockedAllEffect extends RestrictionEffect {
this.filter = filter;
this.staticText = filter.getMessage() + " can't be blocked";
if (duration.equals(Duration.EndOfTurn)) {
if (duration == Duration.EndOfTurn) {
this.staticText += " this turn";
}
}

View file

@ -42,11 +42,7 @@ public class CantBeBlockedAttachedEffect extends RestrictionEffect {
public CantBeBlockedAttachedEffect(AttachmentType attachmentType) {
super(Duration.WhileOnBattlefield);
if (attachmentType.equals(AttachmentType.AURA)) {
this.staticText = "Enchanted creature can't be blocked";
} else {
this.staticText = "Equipped creature can't be blocked";
}
this.staticText = attachmentType.verb() + " creature can't be blocked";
}
public CantBeBlockedAttachedEffect(CantBeBlockedAttachedEffect effect) {

View file

@ -36,7 +36,6 @@ import mage.game.Game;
import mage.game.permanent.Permanent;
/**
*
* @author LevelX2
*/
public class CantBeBlockedByCreaturesAttachedEffect extends RestrictionEffect {
@ -47,13 +46,9 @@ public class CantBeBlockedByCreaturesAttachedEffect extends RestrictionEffect {
super(duration);
this.filter = filter;
StringBuilder sb = new StringBuilder();
if (attachmentType.equals(AttachmentType.AURA)) {
sb.append("Enchanted ");
} else {
sb.append("Equipped ");
}
staticText = sb.append("creature can't be blocked ")
.append(filter.getMessage().startsWith("except by") ? "":"by ").append(filter.getMessage()).toString();
sb.append(attachmentType.verb());
staticText = sb.append(" creature can't be blocked ")
.append(filter.getMessage().startsWith("except by") ? "" : "by ").append(filter.getMessage()).toString();
}
public CantBeBlockedByCreaturesAttachedEffect(final CantBeBlockedByCreaturesAttachedEffect effect) {

View file

@ -56,7 +56,7 @@ public class CantBeBlockedByOneAllEffect extends ContinuousEffectImpl {
this.amount = amount;
this.filter = filter;
StringBuilder sb = new StringBuilder("each ").append(filter.getMessage()).append(" can't be blocked ");
if (duration.equals(Duration.EndOfTurn)) {
if (duration == Duration.EndOfTurn) {
sb.append("this turn ");
}
sb.append("except by ").append(CardUtil.numberToText(amount)).append(" or more creatures");

View file

@ -54,7 +54,7 @@ public class CantBeBlockedByOneAttachedEffect extends ContinuousEffectImpl {
super(duration, Outcome.Benefit);
this.amount = amount;
this.attachmentType = attachmentType;
staticText = (attachmentType.equals(AttachmentType.AURA) ? "Enchanted" : "Equipped") + " creature can't be blocked except by " + amount + " or more creatures";
staticText = attachmentType.verb() + " creature can't be blocked except by " + amount + " or more creatures";
}
public CantBeBlockedByOneAttachedEffect(final CantBeBlockedByOneAttachedEffect effect) {

View file

@ -93,7 +93,7 @@ public class CantBeBlockedByTargetSourceEffect extends RestrictionEffect {
sb.append("Target ");
}
sb.append(target.getTargetName()).append(" can't block {this}");
if (duration.equals(Duration.EndOfTurn)) {
if (duration == Duration.EndOfTurn) {
sb.append(" this turn");
}

View file

@ -45,7 +45,7 @@ public class CantBeBlockedSourceEffect extends RestrictionEffect {
public CantBeBlockedSourceEffect(Duration duration) {
super(duration);
this.staticText = "{this} can't be blocked";
if (Duration.EndOfTurn.equals(this.duration)) {
if (this.duration == Duration.EndOfTurn) {
this.staticText += " this turn";
}
}

View file

@ -72,7 +72,7 @@ public class CantBlockAllEffect extends RestrictionEffect {
public String getText(Mode mode) {
StringBuilder sb = new StringBuilder();
sb.append(filter.getMessage()).append(" can't block");
if (Duration.EndOfTurn.equals(this.duration)) {
if (this.duration == Duration.EndOfTurn) {
sb.append(" this turn");
}
return sb.toString();

View file

@ -56,11 +56,8 @@ public class CantBlockAttachedEffect extends RestrictionEffect {
super(duration);
this.filter = filter;
StringBuilder sb = new StringBuilder();
if (attachmentType.equals(AttachmentType.AURA)) {
sb.append("Enchanted creature can't block");
} else {
sb.append("Equipped creature can't block");
}
sb.append(attachmentType.verb());
sb.append(" creature can't block");
if (!filter.getMessage().equals("creature")) {
sb.append(' ').append(filter.getMessage());
}

View file

@ -43,7 +43,7 @@ public class CantBlockSourceEffect extends RestrictionEffect {
public CantBlockSourceEffect(Duration duration) {
super(duration);
this.staticText = "{this} can't block";
if (duration.equals(Duration.EndOfTurn)) {
if (duration == Duration.EndOfTurn) {
this.staticText += " this turn";
}
}

View file

@ -89,7 +89,7 @@ public class CantBlockTargetEffect extends RestrictionEffect {
}
sb.append(" can't block");
if (Duration.EndOfTurn.equals(this.duration)) {
if (this.duration == Duration.EndOfTurn) {
sb.append(" this turn");
}

View file

@ -29,6 +29,7 @@
package mage.abilities.effects.common.combat;
import java.util.UUID;
import mage.constants.AttachmentType;
import mage.constants.Duration;
import mage.abilities.Ability;
@ -37,7 +38,6 @@ import mage.game.Game;
import mage.game.permanent.Permanent;
/**
*
* @author LevelX2
*/
public class MustBeBlockedByAllAttachedEffect extends RequirementEffect {
@ -51,7 +51,7 @@ public class MustBeBlockedByAllAttachedEffect extends RequirementEffect {
public MustBeBlockedByAllAttachedEffect(Duration duration, AttachmentType attachmentType) {
super(duration);
this.attachmentType = attachmentType;
staticText = "All creatures able to block " + (attachmentType.equals(AttachmentType.AURA) ? "enchanted":"equipped") + " creature do so";
staticText = "All creatures able to block " + attachmentType.verb().toLowerCase() + " creature do so";
}
public MustBeBlockedByAllAttachedEffect(final MustBeBlockedByAllAttachedEffect effect) {
@ -84,7 +84,7 @@ public class MustBeBlockedByAllAttachedEffect extends RequirementEffect {
public UUID mustBlockAttacker(Ability source, Game game) {
Permanent attachment = game.getPermanent(source.getSourceId());
if (attachment != null && attachment.getAttachedTo() != null) {
return attachment.getAttachedTo() ;
return attachment.getAttachedTo();
}
return null;
}

View file

@ -46,7 +46,7 @@ public class MustBeBlockedByAllTargetEffect extends RequirementEffect {
public MustBeBlockedByAllTargetEffect(Duration duration) {
super(duration);
staticText = new StringBuilder("All creatures able to block target creature ")
.append(this.getDuration().equals(Duration.EndOfTurn) ? "this turn ":"")
.append(this.getDuration() == Duration.EndOfTurn ? "this turn ":"")
.append("do so").toString();
}
@ -58,7 +58,7 @@ public class MustBeBlockedByAllTargetEffect extends RequirementEffect {
public boolean applies(Permanent permanent, Ability source, Game game) {
Permanent attackingCreature = game.getPermanent(this.getTargetPointer().getFirst(game, source));
if (attackingCreature != null && attackingCreature.isAttacking()) {
if (!source.getAbilityType().equals(AbilityType.STATIC)) {
if (source.getAbilityType() != AbilityType.STATIC) {
BlockedAttackerWatcher blockedAttackerWatcher = (BlockedAttackerWatcher) game.getState().getWatchers().get("BlockedAttackerWatcher");
if (blockedAttackerWatcher != null && blockedAttackerWatcher.creatureHasBlockedAttacker(attackingCreature, permanent, game)) {
// has already blocked this turn, so no need to do again

View file

@ -84,11 +84,7 @@ public class AddCardColorAttachedEffect extends ContinuousEffectImpl {
private void setText() {
StringBuilder sb = new StringBuilder();
if (attachmentType == AttachmentType.AURA)
sb.append("Enchanted");
else if (attachmentType == AttachmentType.EQUIPMENT)
sb.append("Equipped");
sb.append(attachmentType.verb());
sb.append(" creature is a ").append(addedColor.getDescription()).append(" in addition to its colors");
staticText = sb.toString();
}

View file

@ -62,7 +62,7 @@ public class AddCardSubTypeTargetEffect extends ContinuousEffectImpl {
target.getSubtype(game).add(addedSubType);
}
} else {
if (Duration.Custom.equals(duration)) {
if (duration == Duration.Custom) {
discard();
}
}

View file

@ -72,11 +72,8 @@ public class AddCardSubtypeAttachedEffect extends ContinuousEffectImpl {
private void setText() {
StringBuilder sb = new StringBuilder();
if (attachmentType == AttachmentType.AURA)
sb.append("Enchanted");
else if (attachmentType == AttachmentType.EQUIPMENT)
sb.append("Equipped");
sb.append(attachmentType.verb());
sb.append(" creature becomes ").append(addedSubtype).append(" in addition to its other types"); //TODO add attacked card type detection
staticText = sb.toString();
}

View file

@ -72,11 +72,7 @@ public class AddCardTypeAttachedEffect extends ContinuousEffectImpl {
private void setText() {
StringBuilder sb = new StringBuilder();
if (attachmentType == AttachmentType.AURA)
sb.append("Enchanted");
else if (attachmentType == AttachmentType.EQUIPMENT)
sb.append("Equipped");
sb.append(attachmentType.verb());
sb.append(" creature becomes ").append(addedCardType.toString()).append(" in addition to its other types"); //TODO add attacked card type detection
staticText = sb.toString();
}

View file

@ -27,6 +27,7 @@
*/
package mage.abilities.effects.common.continuous;
import mage.MageObjectReference;
import mage.abilities.Ability;
import mage.abilities.Mode;
import mage.abilities.effects.ContinuousEffectImpl;
@ -49,7 +50,7 @@ public class AddCardTypeSourceEffect extends ContinuousEffectImpl {
public AddCardTypeSourceEffect(CardType addedCardType, Duration duration) {
super(duration, Layer.TypeChangingEffects_4, SubLayer.NA, Outcome.Benefit);
this.addedCardType = addedCardType;
if (addedCardType.equals(CardType.ENCHANTMENT)) {
if (addedCardType == CardType.ENCHANTMENT) {
dependencyTypes.add(DependencyType.EnchantmentAddingRemoving);
}
}
@ -59,16 +60,27 @@ public class AddCardTypeSourceEffect extends ContinuousEffectImpl {
this.addedCardType = effect.addedCardType;
}
@Override
public void init(Ability source, Game game) {
super.init(source, game);
if (Duration.Custom.equals(this.duration) || this.duration.toString().startsWith("End")) {
affectedObjectList.add(new MageObjectReference(source.getSourceId(), game.getState().getZoneChangeCounter(source.getSourceId()), game));
if (affectedObjectList.isEmpty()) {
this.discard();
}
}
}
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent != null) {
if (permanent != null
&& (affectedObjectList.isEmpty() || affectedObjectList.contains(new MageObjectReference(permanent, game)))) {
if (!permanent.getCardType().contains(addedCardType)) {
permanent.getCardType().add(addedCardType);
}
return true;
}
else if (this.getDuration().equals(Duration.Custom)) {
} else if (this.getDuration().equals(Duration.Custom)) {
this.discard();
}
return false;

View file

@ -50,9 +50,9 @@ public class AddCardTypeTargetEffect extends ContinuousEffectImpl {
public AddCardTypeTargetEffect(CardType addedCardType, Duration duration) {
super(duration, Layer.TypeChangingEffects_4, SubLayer.NA, Outcome.Benefit);
this.addedCardType = addedCardType;
if (addedCardType.equals(CardType.ENCHANTMENT)) {
if (addedCardType == CardType.ENCHANTMENT) {
dependencyTypes.add(DependencyType.EnchantmentAddingRemoving);
} else if (addedCardType.equals(CardType.ARTIFACT)) {
} else if (addedCardType == CardType.ARTIFACT) {
dependencyTypes.add(DependencyType.ArtifactAddingRemoving);
}
}
@ -75,7 +75,7 @@ public class AddCardTypeTargetEffect extends ContinuousEffectImpl {
}
}
if (!result) {
if (this.getDuration().equals(Duration.Custom)) {
if (this.getDuration() == Duration.Custom) {
this.discard();
}
}

View file

@ -130,7 +130,7 @@ public class CantGainLifeAllEffect extends ContinuousEffectImpl {
sb.append(" can't gain life");
if (!this.duration.toString().isEmpty()) {
sb.append(' ');
if (duration.equals(Duration.EndOfTurn)) {
if (duration == Duration.EndOfTurn) {
sb.append("this turn");
} else {
sb.append(duration.toString());

View file

@ -48,7 +48,7 @@ public class CantGainLifeTargetEffect extends ContinuousEffectImpl {
super(duration, Layer.PlayerEffects, SubLayer.NA, Outcome.Benefit);
StringBuilder sb = new StringBuilder("If that player would gain life");
if (!this.duration.toString().isEmpty()) {
if (duration.equals(Duration.EndOfTurn)) {
if (duration == Duration.EndOfTurn) {
sb.append("this turn, ");
} else {
sb.append(' ').append(duration.toString());

View file

@ -94,7 +94,7 @@ public class CastAsThoughItHadFlashAllEffect extends AsThoughEffectImpl {
sb.append(" may cast ");
sb.append(filter.getMessage());
if (!duration.toString().isEmpty()) {
if (duration.equals(Duration.EndOfTurn)) {
if (duration == Duration.EndOfTurn) {
sb.append(" this turn");
} else {
sb.append(' ');

View file

@ -29,7 +29,7 @@ public class DamageCantBePreventedEffect extends ContinuousRuleModifyingEffectIm
@Override
public boolean checksEventType(GameEvent event, Game game) {
return event.getType().equals(GameEvent.EventType.PREVENT_DAMAGE);
return event.getType() == GameEvent.EventType.PREVENT_DAMAGE;
}
@Override

View file

@ -124,11 +124,7 @@ public class GainAbilityAttachedEffect extends ContinuousEffectImpl {
private void setText() {
StringBuilder sb = new StringBuilder();
if (attachmentType == AttachmentType.AURA) {
sb.append("Enchanted");
} else if (attachmentType == AttachmentType.EQUIPMENT) {
sb.append("Equipped");
}
sb.append(attachmentType.verb());
sb.append(" creature ");
if (duration == Duration.WhileOnBattlefield) {
sb.append("has ");

View file

@ -83,11 +83,7 @@ public class LoseAbilityAttachedEffect extends ContinuousEffectImpl {
private void setText() {
StringBuilder sb = new StringBuilder();
if (attachmentType == AttachmentType.AURA) {
sb.append("Enchanted");
} else if (attachmentType == AttachmentType.EQUIPMENT) {
sb.append("Equipped");
}
sb.append(attachmentType.verb());
sb.append(" creature ");
if (duration == Duration.WhileOnBattlefield) {
sb.append("loses ");

View file

@ -46,7 +46,7 @@ import mage.util.CardUtil;
*/
public class MaximumHandSizeControllerEffect extends ContinuousEffectImpl {
public static enum HandSizeModification {
public enum HandSizeModification {
SET, INCREASE, REDUCE
}
@ -90,8 +90,8 @@ public class MaximumHandSizeControllerEffect extends ContinuousEffectImpl {
protected static Outcome defineOutcome(HandSizeModification handSizeModification, TargetController targetController) {
Outcome newOutcome = Outcome.Benefit;
if ((targetController.equals(TargetController.YOU) || targetController.equals(TargetController.ANY))
&& handSizeModification.equals(HandSizeModification.REDUCE)) {
if ((targetController == TargetController.YOU || targetController == TargetController.ANY)
&& handSizeModification == HandSizeModification.REDUCE) {
newOutcome = Outcome.Detriment;
}
return newOutcome;

View file

@ -38,7 +38,6 @@ import mage.game.Game;
import mage.players.Player;
/**
*
* @author Viserion
*/
public class PlayAdditionalLandsControllerEffect extends ContinuousEffectImpl {
@ -65,10 +64,9 @@ public class PlayAdditionalLandsControllerEffect extends ContinuousEffectImpl {
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player != null) {
if(player.getLandsPerTurn() == Integer.MAX_VALUE || this.additionalCards == Integer.MAX_VALUE){
if (player.getLandsPerTurn() == Integer.MAX_VALUE || this.additionalCards == Integer.MAX_VALUE) {
player.setLandsPerTurn(Integer.MAX_VALUE);
}
else{
} else {
player.setLandsPerTurn(player.getLandsPerTurn() + this.additionalCards);
}
return true;
@ -79,15 +77,13 @@ public class PlayAdditionalLandsControllerEffect extends ContinuousEffectImpl {
private void setText() {
StringBuilder sb = new StringBuilder();
sb.append("You may play ");
if(additionalCards == Integer.MAX_VALUE){
if (additionalCards == Integer.MAX_VALUE) {
sb.append("any number of");
} else {
sb.append(Integer.toString(additionalCards));
}
else
{
sb.append(Integer.toString(additionalCards));
}
sb.append(" additional land").append((additionalCards == 1 ? "" : "s"))
.append(duration == Duration.EndOfTurn ? " this turn" : " on each of your turns");
sb.append(" additional land").append((additionalCards == 1 ? "" : "s"))
.append(duration == Duration.EndOfTurn ? " this turn" : " on each of your turns");
staticText = sb.toString();
}

View file

@ -71,7 +71,7 @@ public class PlayWithHandRevealedEffect extends ContinuousEffectImpl {
affectedPlayers = game.getOpponents(source.getControllerId());
break;
case YOU:
ArrayList tmp = new ArrayList<>();
ArrayList<UUID> tmp = new ArrayList<>();
tmp.add(source.getControllerId());
affectedPlayers = tmp;
break;

View file

@ -75,11 +75,7 @@ public class SetCardColorAttachedEffect extends ContinuousEffectImpl {
private void setText() {
StringBuilder sb = new StringBuilder();
if (attachmentType == AttachmentType.AURA)
sb.append("Enchanted");
else if (attachmentType == AttachmentType.EQUIPMENT)
sb.append("Equipped");
sb.append(attachmentType.verb());
sb.append(" creature is ").append(setColor.getDescription());
staticText = sb.toString();
}

View file

@ -29,6 +29,7 @@ package mage.abilities.effects.common.continuous;
import java.util.ArrayList;
import java.util.List;
import mage.abilities.Ability;
import mage.abilities.effects.ContinuousEffectImpl;
import mage.cards.repository.CardRepository;
@ -88,12 +89,7 @@ public class SetCardSubtypeAttachedEffect extends ContinuousEffectImpl {
private void setText() {
StringBuilder sb = new StringBuilder();
if (attachmentType == AttachmentType.AURA) {
sb.append("Enchanted");
} else if (attachmentType == AttachmentType.EQUIPMENT) {
sb.append("Equipped");
}
sb.append(attachmentType.verb());
sb.append(" creature is a");
for (String subtype : this.setSubtypes) {
sb.append(' ').append(subtype);

View file

@ -85,7 +85,7 @@ public class SetPowerToughnessSourceEffect extends ContinuousEffectImpl {
public boolean apply(Game game, Ability source) {
MageObject mageObject = game.getPermanentEntering(source.getSourceId());
if (mageObject == null) {
if (duration.equals(Duration.Custom) || isTemporary()) {
if (duration == Duration.Custom || isTemporary()) {
mageObject = game.getPermanent(source.getSourceId());
} else {
mageObject = game.getObject(source.getSourceId());

View file

@ -37,7 +37,6 @@ import mage.game.Game;
import mage.game.permanent.Permanent;
/**
*
* @author North
*/
public class SwitchPowerToughnessSourceEffect extends ContinuousEffectImpl {
@ -58,7 +57,7 @@ public class SwitchPowerToughnessSourceEffect extends ContinuousEffectImpl {
@Override
public boolean apply(Game game, Ability source) {
Permanent target = (Permanent) game.getPermanent(source.getSourceId());
Permanent target = game.getPermanent(source.getSourceId());
if (target != null) {
int power = target.getPower().getValue();
target.getPower().setValue(target.getToughness().getValue());
@ -68,4 +67,4 @@ public class SwitchPowerToughnessSourceEffect extends ContinuousEffectImpl {
return false;
}
}
}

View file

@ -39,7 +39,6 @@ import mage.game.Game;
import mage.game.permanent.Permanent;
/**
*
* @author ayratn
*/
public class SwitchPowerToughnessTargetEffect extends ContinuousEffectImpl {
@ -59,7 +58,7 @@ public class SwitchPowerToughnessTargetEffect extends ContinuousEffectImpl {
@Override
public boolean apply(Game game, Ability source) {
Permanent target = (Permanent) game.getPermanent(source.getFirstTarget());
Permanent target = game.getPermanent(source.getFirstTarget());
if (target != null) {
int power = target.getPower().getValue();
target.getPower().setValue(target.getToughness().getValue());
@ -73,7 +72,7 @@ public class SwitchPowerToughnessTargetEffect extends ContinuousEffectImpl {
public String getText(Mode mode) {
StringBuilder sb = new StringBuilder();
sb.append("Switch target ").append(mode.getTargets().get(0).getTargetName()).append("'s power and toughness")
.append(' ').append(duration.toString());
.append(' ').append(duration.toString());
return sb.toString();
}

View file

@ -69,7 +69,7 @@ public class UntapAllDuringEachOtherPlayersUntapStepEffect extends ContinuousEff
if (applied == null) {
applied = Boolean.FALSE;
}
if (!applied && layer.equals(Layer.RulesEffects)) {
if (!applied && layer == Layer.RulesEffects) {
if (!source.getControllerId().equals(game.getActivePlayerId()) && game.getStep().getType() == PhaseStep.UNTAP) {
game.getState().setValue(source.getSourceId() + "applied", true);
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(filter, source.getControllerId(), game)) {

View file

@ -64,7 +64,7 @@ public class UntapSourceDuringEachOtherPlayersUntapStepEffect extends Continuous
if (applied == null) {
applied = Boolean.FALSE;
}
if (!applied && layer.equals(Layer.RulesEffects)) {
if (!applied && layer == Layer.RulesEffects) {
if (!source.getControllerId().equals(game.getActivePlayerId())
&& game.getStep() != null
&& game.getStep().getType() == PhaseStep.UNTAP) {
@ -80,7 +80,7 @@ public class UntapSourceDuringEachOtherPlayersUntapStepEffect extends Continuous
}
}
}
} else if (applied && layer.equals(Layer.RulesEffects)) {
} else if (applied && layer == Layer.RulesEffects) {
if (game.getStep() != null && game.getStep().getType() == PhaseStep.END_TURN) {
game.getState().setValue(source.getSourceId() + "applied", false);
}

View file

@ -71,8 +71,7 @@ public class ProliferateEffect extends OneShotEffect {
options.put("UI.right.btn.text", "Done");
controller.choose(Outcome.Benefit, target, source.getSourceId(), game, options);
for (int idx = 0; idx < target.getTargets().size(); idx++) {
UUID chosen = (UUID) target.getTargets().get(idx);
for (UUID chosen : target.getTargets()) {
Permanent permanent = game.getPermanent(chosen);
if (permanent != null) {
if (!permanent.getCounters(game).isEmpty()) {

View file

@ -16,7 +16,6 @@ import mage.game.Game;
import mage.game.events.GameEvent;
/**
*
* @author LevelX2
*/
public class CastOnlyDuringPhaseStepSourceEffect extends ContinuousRuleModifyingEffectImpl {
@ -49,8 +48,8 @@ public class CastOnlyDuringPhaseStepSourceEffect extends ContinuousRuleModifying
public boolean applies(GameEvent event, Ability source, Game game) {
// has to return true, if the spell cannot be cast in the current phase / step
if (event.getSourceId().equals(source.getSourceId())) {
if ((turnPhase != null && !game.getPhase().getType().equals(turnPhase))
|| (phaseStep != null && !game.getTurn().getStepType().equals(phaseStep))
if ((turnPhase != null && game.getPhase().getType() != turnPhase)
|| (phaseStep != null && (game.getTurn().getStepType() != phaseStep))
|| (condition != null && !condition.apply(game, source))) {
return true;
}

View file

@ -5,6 +5,16 @@ package mage.constants;
* @author North
*/
public enum AttachmentType {
EQUIPMENT,
AURA
EQUIPMENT("Equipped"),
AURA("Enchanted");
String verb;
public String verb(){
return verb;
}
AttachmentType(String verb){
this.verb = verb;
}
}

View file

@ -1,5 +1,7 @@
package mage.constants;
import mage.game.turn.Phase;
/**
*
* @author North
@ -33,6 +35,14 @@ public enum PhaseStep {
this.stepText = stepText;
}
public boolean isBefore(PhaseStep other){
return this.getIndex()<other.getIndex();
}
public boolean isAfter(PhaseStep other){
return this.getIndex()>other.getIndex();
}
public int getIndex() {
return index;
}

View file

@ -30,7 +30,9 @@ package mage.game;
import java.io.Serializable;
import java.util.Arrays;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import mage.cards.decks.DeckValidator;
import mage.constants.TableState;
@ -63,6 +65,7 @@ public class Table implements Serializable {
private Match match;
private Tournament tournament;
private TableRecorder recorder;
private Set<String> bannedUsernames;
@FunctionalInterface
public interface TableRecorder {
@ -71,21 +74,21 @@ public class Table implements Serializable {
protected TableEventSource tableEventSource = new TableEventSource();
public Table(UUID roomId, String gameType, String name, String controllerName, DeckValidator validator, List<String> playerTypes, TableRecorder recorder, Tournament tournament) {
this(roomId, gameType, name, controllerName, validator, playerTypes, recorder);
public Table(UUID roomId, String gameType, String name, String controllerName, DeckValidator validator, List<String> playerTypes, TableRecorder recorder, Tournament tournament, Set<String> bannedUsernames) {
this(roomId, gameType, name, controllerName, validator, playerTypes, recorder, bannedUsernames);
this.tournament = tournament;
this.isTournament = true;
setState(TableState.WAITING);
}
public Table(UUID roomId, String gameType, String name, String controllerName, DeckValidator validator, List<String> playerTypes, TableRecorder recorder, Match match) {
this(roomId, gameType, name, controllerName, validator, playerTypes, recorder);
public Table(UUID roomId, String gameType, String name, String controllerName, DeckValidator validator, List<String> playerTypes, TableRecorder recorder, Match match, Set<String> bannedUsernames) {
this(roomId, gameType, name, controllerName, validator, playerTypes, recorder, bannedUsernames);
this.match = match;
this.isTournament = false;
setState(TableState.WAITING);
}
protected Table(UUID roomId, String gameType, String name, String controllerName, DeckValidator validator, List<String> playerTypes, TableRecorder recorder) {
protected Table(UUID roomId, String gameType, String name, String controllerName, DeckValidator validator, List<String> playerTypes, TableRecorder recorder, Set<String> bannedUsernames) {
tableId = UUID.randomUUID();
this.roomId = roomId;
this.numSeats = playerTypes.size();
@ -96,6 +99,7 @@ public class Table implements Serializable {
createSeats(playerTypes);
this.validator = validator;
this.recorder = recorder;
this.bannedUsernames = new HashSet<>(bannedUsernames);
}
private void createSeats(List<String> playerTypes) {
@ -308,6 +312,10 @@ public class Table implements Serializable {
}
}
public boolean userIsBanned(String username) {
return bannedUsernames.contains(username);
}
public TableProto toProto() {
TableProto.Builder builder = TableProto.newBuilder();
if (this.isTournament()) {

View file

@ -30,7 +30,9 @@ package mage.game.match;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import mage.constants.MatchTimeLimit;
import mage.constants.MultiplayerAttackOption;
import mage.constants.RangeOfInfluence;
@ -61,6 +63,7 @@ public class MatchOptions implements Serializable {
protected int edhPowerLevel;
protected boolean rated;
protected int numSeatsForMatch;
protected Set<String> bannedUsers = new HashSet<>();
/**
* Time each player has during the game to play using his\her priority.
@ -226,6 +229,14 @@ public class MatchOptions implements Serializable {
this.rated = rated;
}
public Set<String> getBannedUsers() {
return bannedUsers;
}
public void setBannedUsers(Set<String> bannedUsers) {
this.bannedUsers = bannedUsers;
}
public ResultProtos.MatchOptionsProto toProto() {
ResultProtos.MatchOptionsProto.Builder builder = ResultProtos.MatchOptionsProto.newBuilder()
.setName(this.getName())

View file

@ -28,7 +28,6 @@
package mage.game.permanent;
import java.util.*;
import mage.MageObject;
import mage.MageObjectReference;
import mage.ObjectColor;
@ -751,7 +750,7 @@ public abstract class PermanentImpl extends CardImpl implements Permanent {
if (source != null && sourceAbilities != null) {
if (sourceAbilities.containsKey(LifelinkAbility.getInstance().getId())) {
Player player = game.getPlayer(sourceControllerId);
player.gainLife(damageAmount, game);
player.gainLife(damageDone, game);
}
if (sourceAbilities.containsKey(DeathtouchAbility.getInstance().getId())) {
deathtouched = true;

View file

@ -3067,7 +3067,7 @@ public abstract class PlayerImpl implements Player, Serializable {
@Override
public boolean canJoinTable(Table table) {
return true;
return !table.userIsBanned(name);
}
@Override

View file

@ -3,7 +3,6 @@ package mage.watchers.common;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import mage.constants.WatcherScope;
import mage.game.Game;
import mage.game.events.GameEvent;
@ -26,7 +25,7 @@ public class FirstSpellCastThisTurnWatcher extends Watcher {
public FirstSpellCastThisTurnWatcher(final FirstSpellCastThisTurnWatcher watcher) {
super(watcher);
playerFirstSpellCast.putAll(watcher.playerFirstSpellCast);
playerFirstCastSpell.putAll(watcher.playerFirstSpellCast);
playerFirstCastSpell.putAll(watcher.playerFirstCastSpell);
}
@Override

View file

@ -9,6 +9,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.UUID;
import mage.constants.CardType;
import mage.constants.WatcherScope;
import mage.game.Game;
import mage.game.events.GameEvent;
@ -75,7 +76,8 @@ public class PermanentsEnteredBattlefieldWatcher extends Watcher {
if (enteringBattlefieldLastTurn.containsKey(sourcePermanent.getControllerId())) {
for (Permanent permanent : enteringBattlefieldLastTurn.get(sourcePermanent.getControllerId())) {
if (!permanent.getId().equals(sourcePermanent.getId())
|| permanent.getZoneChangeCounter(game) != sourcePermanent.getZoneChangeCounter(game)) {
//|| permanent.getZoneChangeCounter(game) == sourcePermanent.getZoneChangeCounter(game) why is this needed?
&& permanent.getCardType().contains(CardType.CREATURE)) {
return true;
}
}