diff --git a/Mage.Client/src/main/java/mage/client/components/layout/RelativeLayout.java b/Mage.Client/src/main/java/mage/client/components/layout/RelativeLayout.java index d7c5a21d68..a139a2a144 100644 --- a/Mage.Client/src/main/java/mage/client/components/layout/RelativeLayout.java +++ b/Mage.Client/src/main/java/mage/client/components/layout/RelativeLayout.java @@ -57,7 +57,7 @@ public class RelativeLayout implements LayoutManager2, java.io.Serializable { private static final int MINIMUM = 0; private static final int PREFERRED = 1; - private Map constraints = new HashMap(); + private final Map constraints = new HashMap<>(); /** * The axis of the Components within the Container. @@ -222,6 +222,7 @@ public class RelativeLayout implements LayoutManager2, java.io.Serializable { /** * Change size of relative components to fill the space available For X-AXIS aligned components the height will be * filled. For Y-AXIS aligned components the width will be filled. + * @param fill */ public void setFill(boolean fill) { this.fill = fill; @@ -238,6 +239,7 @@ public class RelativeLayout implements LayoutManager2, java.io.Serializable { /** * Specify the number of pixels by which the fill size is decreased when setFill(true) has been specified. + * @param fillGap */ public void setFillGap(int fillGap) { this.fillGap = fillGap; @@ -258,6 +260,7 @@ public class RelativeLayout implements LayoutManager2, java.io.Serializable { * DO_NOTHING FIRST - extra pixels added to the first relative component LAST - extra pixels added to the last * relative component LARGEST (default) - extra pixels added to the larger relative component EQUAL - a single pixel * is added to each relative component (until pixels are used up) + * @param roundingPolicy */ public void setRoundingPolicy(int roundingPolicy) { this.roundingPolicy = roundingPolicy; @@ -275,6 +278,8 @@ public class RelativeLayout implements LayoutManager2, java.io.Serializable { /** * Not supported + * @param name + * @param component */ @Override public void addLayoutComponent(String name, Component component) { @@ -310,7 +315,7 @@ public class RelativeLayout implements LayoutManager2, java.io.Serializable { * of a column layout is the largest preferred height of each row in the container, plus the vertical padding times * the number of rows minus one, plus the top and bottom insets of the target container. * - * @param target the container in which to do the layout + * @param parent the container in which to do the layout * @return the preferred dimensions to lay out the subcomponents of the specified container * @see java.awt.RelativeLayout#minimumLayoutSize * @see java.awt.Container#getPreferredSize() @@ -329,7 +334,7 @@ public class RelativeLayout implements LayoutManager2, java.io.Serializable { * layout is the largest minimum height of each row in the container, plus the vertical padding times the number of * rows minus one, plus the top and bottom insets of the target container. * - * @param target the container in which to do the layout + * @param parent the container in which to do the layout * @return the minimum dimensions needed to lay out the subcomponents of the specified container * @see java.awt.RelativeLayout#preferredLayoutSize * @see java.awt.Container#doLayout @@ -349,7 +354,7 @@ public class RelativeLayout implements LayoutManager2, java.io.Serializable { * the layout. The container's free space equals the container's size minus any insets and any specified horizontal * or vertical gap. All components in a grid layout are given the same size. * - * @param target the container in which to do the layout + * @param parent the container in which to do the layout * @see java.awt.Container * @see java.awt.Container#doLayout */ @@ -581,7 +586,7 @@ public class RelativeLayout implements LayoutManager2, java.io.Serializable { Float constraint = constraints.get(component); if (constraint != null) { - int space = (int) (spaceAvailable * constraint.floatValue() / relativeTotal); + int space = (int) (spaceAvailable * constraint / relativeTotal); relativeSpace[i] = space; spaceUsed += space; } @@ -750,6 +755,8 @@ public class RelativeLayout implements LayoutManager2, java.io.Serializable { /** * There is no maximum. + * @param target + * @return */ @Override public Dimension maximumLayoutSize(Container target) { @@ -758,6 +765,8 @@ public class RelativeLayout implements LayoutManager2, java.io.Serializable { /** * Returns the alignment along the x axis. Use center alignment. + * @param parent + * @return */ @Override public float getLayoutAlignmentX(Container parent) { @@ -766,6 +775,8 @@ public class RelativeLayout implements LayoutManager2, java.io.Serializable { /** * Returns the alignment along the y axis. Use center alignment. + * @param parent + * @return */ @Override public float getLayoutAlignmentY(Container parent) { @@ -774,6 +785,7 @@ public class RelativeLayout implements LayoutManager2, java.io.Serializable { /** * Invalidates the layout, indicating that if the layout manager has cached information it should be discarded. + * @param target */ @Override public void invalidateLayout(Container target) { diff --git a/Mage.Client/src/main/java/mage/client/game/BattlefieldPanel.java b/Mage.Client/src/main/java/mage/client/game/BattlefieldPanel.java index 8c0d9f45f4..d5ac6cebfb 100644 --- a/Mage.Client/src/main/java/mage/client/game/BattlefieldPanel.java +++ b/Mage.Client/src/main/java/mage/client/game/BattlefieldPanel.java @@ -41,7 +41,6 @@ import mage.client.plugins.impl.Plugins; import mage.client.util.Config; import mage.client.util.audio.AudioManager; import mage.client.util.layout.CardLayoutStrategy; -import mage.client.util.layout.impl.OldCardLayoutStrategy; import mage.constants.CardType; import mage.utils.CardUtil; import mage.view.CounterView; @@ -56,6 +55,7 @@ import java.awt.event.ComponentEvent; import java.util.*; import java.util.List; import java.util.Map.Entry; +import mage.client.util.layout.impl.OldCardLayoutStrategy; /** * @@ -75,7 +75,7 @@ public class BattlefieldPanel extends javax.swing.JLayeredPane { private JScrollPane jScrollPane; private int width; - private CardLayoutStrategy layoutStrategy = new OldCardLayoutStrategy(); + private final CardLayoutStrategy layoutStrategy = new OldCardLayoutStrategy(); //private static int iCounter = 0; @@ -137,7 +137,7 @@ public class BattlefieldPanel extends javax.swing.JLayeredPane { if (s1 != s2) { changed = true; } else if (s1 > 0) { - Set attachmentIds = new HashSet(); + Set attachmentIds = new HashSet<>(); attachmentIds.addAll(permanent.getAttachments()); for (MagePermanent magePermanent : oldMagePermanent.getLinks()) { if (!attachmentIds.contains(magePermanent.getOriginalPermanent().getId())) { @@ -164,7 +164,7 @@ public class BattlefieldPanel extends javax.swing.JLayeredPane { List counters2 = permanent.getCounters(); if (counters1 == null && counters2 != null || counters1 != null && counters2 == null) { changed = true; - } else if (counters1 != null && counters1.size() != counters2.size()) { + } else if (counters1 != null && counters2 != null && counters1.size() != counters2.size()) { changed = true; } } diff --git a/Mage.Sets/src/mage/sets/limitedalpha/AnimateDead.java b/Mage.Sets/src/mage/sets/limitedalpha/AnimateDead.java index 9c8b2d7a64..de9e18efb9 100644 --- a/Mage.Sets/src/mage/sets/limitedalpha/AnimateDead.java +++ b/Mage.Sets/src/mage/sets/limitedalpha/AnimateDead.java @@ -29,24 +29,27 @@ package mage.sets.limitedalpha; import java.util.UUID; import mage.abilities.Ability; -import mage.abilities.StaticAbility; import mage.abilities.common.EntersBattlefieldTriggeredAbility; import mage.abilities.common.LeavesBattlefieldTriggeredAbility; import mage.abilities.common.SimpleStaticAbility; import mage.abilities.condition.common.SourceOnBattelfieldCondition; import mage.abilities.decorator.ConditionalTriggeredAbility; +import mage.abilities.effects.ContinuousEffectImpl; import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.common.continious.BoostEnchantedEffect; +import mage.abilities.effects.common.continious.SourceEffect; +import mage.abilities.keyword.EnchantAbility; import mage.cards.Card; import mage.cards.CardImpl; import mage.constants.CardType; import mage.constants.Duration; +import mage.constants.Layer; import mage.constants.Outcome; import mage.constants.Rarity; +import mage.constants.SubLayer; import mage.constants.Zone; import mage.filter.common.FilterCreatureCard; import mage.filter.common.FilterCreaturePermanent; -import mage.filter.predicate.other.AuraPermanentCanAttachToPermanentId; import mage.filter.predicate.permanent.PermanentIdPredicate; import mage.game.Game; import mage.game.permanent.Permanent; @@ -72,15 +75,17 @@ public class AnimateDead extends CardImpl { TargetCardInGraveyard auraTarget = new TargetCardInGraveyard(new FilterCreatureCard("creature card in a graveyard")); this.getSpellAbility().addTarget(auraTarget); this.getSpellAbility().addEffect(new AnimateDeadAttachEffect(Outcome.PutCreatureInPlay)); - Ability enchantAbility = new AnimateDeadEnchantAbility(auraTarget.getTargetName()); + Ability enchantAbility = new EnchantAbility(auraTarget.getTargetName()); this.addAbility(enchantAbility); // When Animate Dead enters the battlefield, if it's on the battlefield, it loses "enchant creature card in a graveyard" // and gains "enchant creature put onto the battlefield with Animate Dead." Return enchanted creature card to the battlefield // under your control and attach Animate Dead to it. When Animate Dead leaves the battlefield, that creature's controller sacrifices it. - this.addAbility(new ConditionalTriggeredAbility( + Ability ability = new ConditionalTriggeredAbility( new EntersBattlefieldTriggeredAbility(new AnimateDeadReAttachEffect(), false), SourceOnBattelfieldCondition.getInstance(), - "When Animate Dead enters the battlefield, if it's on the battlefield, it loses \"enchant creature card in a graveyard\" and gains \"enchant creature put onto the battlefield with Animate Dead.\" Return enchanted creature card to the battlefield under your control and attach Animate Dead to it.")); + "When Animate Dead enters the battlefield, if it's on the battlefield, it loses \"enchant creature card in a graveyard\" and gains \"enchant creature put onto the battlefield with Animate Dead.\" Return enchanted creature card to the battlefield under your control and attach Animate Dead to it."); + ability.addEffect(new AnimateDeadChangeAbilityEffect()); + this.addAbility(ability); this.addAbility(new LeavesBattlefieldTriggeredAbility(new AnimateDeadLeavesBattlefieldTriggeredEffect(), false)); // Enchanted creature gets -1/-0. @@ -102,7 +107,7 @@ class AnimateDeadReAttachEffect extends OneShotEffect { public AnimateDeadReAttachEffect() { super(Outcome.Benefit); - this.staticText = "if it's on the battlefield, it loses \"enchant creature card in a graveyard\" and gains \"enchant creature put onto the battlefield with Animate Dead.\" Return enchanted creature card to the battlefield under your control and attach Animate Dead to it"; + this.staticText = "Return enchanted creature card to the battlefield under your control and attach {this} to it"; } public AnimateDeadReAttachEffect(final AnimateDeadReAttachEffect effect) { @@ -129,20 +134,10 @@ class AnimateDeadReAttachEffect extends OneShotEffect { controller.putOntoBattlefieldWithInfo(cardInGraveyard, game, Zone.GRAVEYARD, source.getSourceId()); Permanent enchantedCreature = game.getPermanent(cardInGraveyard.getId()); - AnimateDeadEnchantAbility enchantAbility = null; - for (Ability ability : enchantment.getAbilities()) { - if (ability instanceof AnimateDeadEnchantAbility) { - enchantAbility = (AnimateDeadEnchantAbility) ability; - break; - } - } - if (enchantAbility == null) { - return false; - } FilterCreaturePermanent filter = new FilterCreaturePermanent("enchant creature put onto the battlefield with Animate Dead"); filter.add(new PermanentIdPredicate(cardInGraveyard.getId())); Target target = new TargetCreaturePermanent(filter); - enchantAbility.setTargetName(target.getTargetName()); + //enchantAbility.setTargetName(target.getTargetName()); if (enchantedCreature != null) { target.addTarget(enchantedCreature.getId(), source, game); enchantment.getSpellAbility().getTargets().clear(); @@ -225,36 +220,51 @@ class AnimateDeadAttachEffect extends OneShotEffect { } -class AnimateDeadEnchantAbility extends StaticAbility { +class AnimateDeadChangeAbilityEffect extends ContinuousEffectImpl implements SourceEffect { - protected String targetName; - - public AnimateDeadEnchantAbility(String targetName) { - super(Zone.BATTLEFIELD, null); - this.targetName = targetName; + private final static Ability newAbility = new EnchantAbility("creature put onto the battlefield with Animate Dead"); + + static { + newAbility.setRuleAtTheTop(true); + } + + public AnimateDeadChangeAbilityEffect() { + super(Duration.WhileOnBattlefield, Layer.AbilityAddingRemovingEffects_6, SubLayer.NA, Outcome.AddAbility); + staticText = "it loses \"enchant creature card in a graveyard\" and gains \"enchant creature put onto the battlefield with Animate Dead\""; } - public AnimateDeadEnchantAbility(final AnimateDeadEnchantAbility ability) { - super(ability); - this.targetName = ability.targetName; + + public AnimateDeadChangeAbilityEffect(final AnimateDeadChangeAbilityEffect effect) { + super(effect); } @Override - public AnimateDeadEnchantAbility copy() { - return new AnimateDeadEnchantAbility(this); + public AnimateDeadChangeAbilityEffect copy() { + return new AnimateDeadChangeAbilityEffect(this); } - - public void setTargetName(String name) { - this.targetName = name; + + @Override + public void init(Ability source, Game game) { + super.init(source, game); + getAffectedObjects().add(source.getSourceId()); } @Override - public String getRule() { - StringBuilder sb = new StringBuilder(); - sb.append("Enchant ").append(targetName); - if (!this.getEffects().isEmpty()) { - sb.append(". ").append(super.getRule()); - } - return sb.toString(); + public boolean apply(Game game, Ability source) { + Permanent permanent = game.getPermanent(source.getSourceId()); + if (permanent != null) { + Ability abilityToRemove = null; + for (Ability ability: permanent.getAbilities()) { + if (ability instanceof EnchantAbility) { + abilityToRemove = ability; + } + } + if (abilityToRemove != null) { + permanent.getAbilities().remove(abilityToRemove); + } + permanent.addAbility(newAbility, source.getSourceId(), game); + return true; + } + return false; } } diff --git a/Mage/src/mage/abilities/AbilityImpl.java b/Mage/src/mage/abilities/AbilityImpl.java index 42a80aff69..201d831c8c 100644 --- a/Mage/src/mage/abilities/AbilityImpl.java +++ b/Mage/src/mage/abilities/AbilityImpl.java @@ -471,6 +471,7 @@ public abstract class AbilityImpl implements Ability { return variableManaCost; } + // called at end of turn for each Permanent @Override public void reset(Game game) {}