diff --git a/Mage.Common/src/mage/view/CombatGroupView.java b/Mage.Common/src/mage/view/CombatGroupView.java index 6f3f929f9fb..2a4c1b698fd 100644 --- a/Mage.Common/src/mage/view/CombatGroupView.java +++ b/Mage.Common/src/mage/view/CombatGroupView.java @@ -31,7 +31,6 @@ package mage.view; import java.io.Serializable; import java.util.UUID; import mage.game.Game; -import mage.game.GameState; import mage.game.combat.CombatGroup; import mage.game.permanent.Permanent; import mage.players.Player; @@ -44,7 +43,7 @@ public class CombatGroupView implements Serializable { private CardsView attackers = new CardsView(); private CardsView blockers = new CardsView(); - private String defenderName; + private String defenderName = ""; public CombatGroupView(CombatGroup combatGroup, Game game) { Player player = game.getPlayer(combatGroup.getDefenderId()); @@ -53,7 +52,8 @@ public class CombatGroupView implements Serializable { } else { Permanent perm = game.getPermanent(combatGroup.getDefenderId()); - this.defenderName = perm.getName(); + if (perm != null) + this.defenderName = perm.getName(); } for (UUID id: combatGroup.getAttackers()) { Permanent attacker = game.getPermanent(id); diff --git a/Mage.Player.AI/src/mage/player/ai/ComputerPlayer.java b/Mage.Player.AI/src/mage/player/ai/ComputerPlayer.java index 8bb239904ef..d96e56fe441 100644 --- a/Mage.Player.AI/src/mage/player/ai/ComputerPlayer.java +++ b/Mage.Player.AI/src/mage/player/ai/ComputerPlayer.java @@ -720,7 +720,7 @@ public class ComputerPlayer> extends PlayerImpl i public void assignDamage(int damage, List targets, UUID sourceId, Game game) { logger.fine("assignDamage"); //TODO: improve this - game.getPermanent(targets.get(0)).damage(damage, sourceId, game, true); + game.getPermanent(targets.get(0)).damage(damage, sourceId, game, true, false); } @Override diff --git a/Mage.Player.Human/src/mage/player/human/HumanPlayer.java b/Mage.Player.Human/src/mage/player/human/HumanPlayer.java index c3a0ad9d447..c51679eaed7 100644 --- a/Mage.Player.Human/src/mage/player/human/HumanPlayer.java +++ b/Mage.Player.Human/src/mage/player/human/HumanPlayer.java @@ -440,7 +440,7 @@ public class HumanPlayer extends PlayerImpl { int damageAmount = getAmount(0, remainingDamage, "Select amount", game); Permanent permanent = game.getPermanent(target.getFirstTarget()); if (permanent != null) { - permanent.damage(damageAmount, sourceId, game, true); + permanent.damage(damageAmount, sourceId, game, true, false); remainingDamage -= damageAmount; } else { diff --git a/Mage.Server/plugins/mage-deck-constructed.jar b/Mage.Server/plugins/mage-deck-constructed.jar index 8a11731b1e0..f41775255bd 100644 Binary files a/Mage.Server/plugins/mage-deck-constructed.jar and b/Mage.Server/plugins/mage-deck-constructed.jar differ diff --git a/Mage.Server/plugins/mage-game-freeforall.jar b/Mage.Server/plugins/mage-game-freeforall.jar index 24f9d2e89f4..59b39d07087 100644 Binary files a/Mage.Server/plugins/mage-game-freeforall.jar and b/Mage.Server/plugins/mage-game-freeforall.jar differ diff --git a/Mage.Server/plugins/mage-game-twoplayerduel.jar b/Mage.Server/plugins/mage-game-twoplayerduel.jar index cf7a4305be1..3cddc1d3e33 100644 Binary files a/Mage.Server/plugins/mage-game-twoplayerduel.jar and b/Mage.Server/plugins/mage-game-twoplayerduel.jar differ diff --git a/Mage.Server/plugins/mage-player-ai.jar b/Mage.Server/plugins/mage-player-ai.jar index 5eb2e70c8ad..5af375336e5 100644 Binary files a/Mage.Server/plugins/mage-player-ai.jar and b/Mage.Server/plugins/mage-player-ai.jar differ diff --git a/Mage.Server/plugins/mage-player-aiminimax.jar b/Mage.Server/plugins/mage-player-aiminimax.jar index 8f800429c12..6ec2d2a440a 100644 Binary files a/Mage.Server/plugins/mage-player-aiminimax.jar and b/Mage.Server/plugins/mage-player-aiminimax.jar differ diff --git a/Mage.Server/plugins/mage-player-human.jar b/Mage.Server/plugins/mage-player-human.jar index 8c98d5ef01e..09b3ca52c52 100644 Binary files a/Mage.Server/plugins/mage-player-human.jar and b/Mage.Server/plugins/mage-player-human.jar differ diff --git a/Mage.Sets/src/mage/sets/alarareborn/VengefulRebirth.java b/Mage.Sets/src/mage/sets/alarareborn/VengefulRebirth.java index 17676d23c5b..3a588d01367 100644 --- a/Mage.Sets/src/mage/sets/alarareborn/VengefulRebirth.java +++ b/Mage.Sets/src/mage/sets/alarareborn/VengefulRebirth.java @@ -103,7 +103,7 @@ class VengefulRebirthEffect extends OneShotEffect { if (!card.getCardType().contains(CardType.LAND)) { Permanent permanent = game.getPermanent(source.getTargets().get(1).getTargets().get(0)); if (permanent != null) { - permanent.damage(damage, source.getSourceId(), game, true); + permanent.damage(damage, source.getSourceId(), game, true, false); return true; } Player targetPlayer = game.getPlayer(source.getTargets().get(1).getTargets().get(0)); diff --git a/Mage.Sets/src/mage/sets/magic2010/Earthquake.java b/Mage.Sets/src/mage/sets/magic2010/Earthquake.java index 4a98ddc3a2c..81423c5d424 100644 --- a/Mage.Sets/src/mage/sets/magic2010/Earthquake.java +++ b/Mage.Sets/src/mage/sets/magic2010/Earthquake.java @@ -96,7 +96,7 @@ class EarthquakeEffect extends OneShotEffect { int amount = source.getManaCosts().getVariableCosts().get(0).getAmount(); for (Permanent permanent: game.getBattlefield().getActivePermanents(filter, source.getControllerId(), game)) { - permanent.damage(amount, source.getId(), game, true); + permanent.damage(amount, source.getId(), game, true, false); } for (UUID playerId: game.getPlayer(source.getControllerId()).getInRange()) { Player player = game.getPlayer(playerId); diff --git a/Mage.Sets/src/mage/sets/magic2010/Fireball.java b/Mage.Sets/src/mage/sets/magic2010/Fireball.java index 0d4fb9d3d98..202699ad8fe 100644 --- a/Mage.Sets/src/mage/sets/magic2010/Fireball.java +++ b/Mage.Sets/src/mage/sets/magic2010/Fireball.java @@ -98,7 +98,7 @@ class FireballEffect extends OneShotEffect { for (UUID targetId: source.getTargets().get(0).getTargets()) { Permanent permanent = game.getPermanent(targetId); if (permanent != null) { - permanent.damage(damagePer, source.getSourceId(), game, true); + permanent.damage(damagePer, source.getSourceId(), game, true, false); } else { Player player = game.getPlayer(targetId); diff --git a/Mage.Sets/src/mage/sets/magic2010/MasterOfTheWildHunt.java b/Mage.Sets/src/mage/sets/magic2010/MasterOfTheWildHunt.java index 2ed7826de80..52feb09a9fe 100644 --- a/Mage.Sets/src/mage/sets/magic2010/MasterOfTheWildHunt.java +++ b/Mage.Sets/src/mage/sets/magic2010/MasterOfTheWildHunt.java @@ -119,7 +119,7 @@ class MasterOfTheWildHuntEffect extends OneShotEffect if (target != null && game.getBattlefield().countAll(filter, source.getControllerId()) > 0) { for (Permanent permanent: game.getBattlefield().getAllActivePermanents(filter, source.getControllerId())) { permanent.tap(game); - target.damage(permanent.getToughness().getValue(), permanent.getId(), game, true); + target.damage(permanent.getToughness().getValue(), permanent.getId(), game, true, false); wolves.add(permanent.getId()); } Player player = game.getPlayer(target.getControllerId()); diff --git a/Mage.Sets/src/mage/sets/magic2010/MerfolkSovereign.java b/Mage.Sets/src/mage/sets/magic2010/MerfolkSovereign.java index 0c5d968a5f7..dd7f6ff4982 100644 --- a/Mage.Sets/src/mage/sets/magic2010/MerfolkSovereign.java +++ b/Mage.Sets/src/mage/sets/magic2010/MerfolkSovereign.java @@ -39,9 +39,7 @@ import mage.abilities.common.SimpleActivatedAbility; import mage.abilities.common.SimpleStaticAbility; import mage.abilities.costs.common.TapSourceCost; import mage.abilities.effects.common.BoostControlledEffect; -import mage.abilities.effects.common.GainAbilityControlledEffect; import mage.abilities.effects.common.GainAbilityTargetEffect; -import mage.abilities.keyword.HasteAbility; import mage.abilities.keyword.UnblockableAbility; import mage.cards.CardImpl; import mage.filter.common.FilterCreaturePermanent; diff --git a/Mage.Sets/src/mage/sets/magic2011/ChandrasOutrage.java b/Mage.Sets/src/mage/sets/magic2011/ChandrasOutrage.java index 69ed657fb34..481cbe5b657 100644 --- a/Mage.Sets/src/mage/sets/magic2011/ChandrasOutrage.java +++ b/Mage.Sets/src/mage/sets/magic2011/ChandrasOutrage.java @@ -86,7 +86,7 @@ class ChandrasOutrageEffect extends OneShotEffect { if (permanent != null) { Player player = game.getPlayer(permanent.getControllerId()); if (player != null) { - permanent.damage(4, source.getSourceId(), game, true); + permanent.damage(4, source.getSourceId(), game, true, false); player.damage(2, source.getSourceId(), game, false, true); return true; } diff --git a/Mage.Sets/src/mage/sets/magic2011/ChandrasSpitfire.java b/Mage.Sets/src/mage/sets/magic2011/ChandrasSpitfire.java index f6e095a6d3e..8014e6b9122 100644 --- a/Mage.Sets/src/mage/sets/magic2011/ChandrasSpitfire.java +++ b/Mage.Sets/src/mage/sets/magic2011/ChandrasSpitfire.java @@ -41,6 +41,7 @@ import mage.abilities.effects.common.BoostSourceEffect; import mage.abilities.keyword.FlyingAbility; import mage.cards.CardImpl; import mage.game.Game; +import mage.game.events.DamagedPlayerEvent; import mage.game.events.GameEvent; import mage.game.events.GameEvent.EventType; @@ -90,9 +91,12 @@ class ChandrasSpitfireAbility extends TriggeredAbilityImpl { int damageDealt = amount; Permanent permanent = game.getPermanent(source.getFirstTarget()); if (permanent != null) { - damageDealt = permanent.damage(amount, source.getSourceId(), game, true); + damageDealt = permanent.damage(amount, source.getSourceId(), game, true, false); } else { Player player = game.getPlayer(source.getFirstTarget()); diff --git a/Mage.Sets/src/mage/sets/magic2011/CyclopsGladiator.java b/Mage.Sets/src/mage/sets/magic2011/CyclopsGladiator.java index 5ccb698b88d..6cdf2eb217e 100644 --- a/Mage.Sets/src/mage/sets/magic2011/CyclopsGladiator.java +++ b/Mage.Sets/src/mage/sets/magic2011/CyclopsGladiator.java @@ -107,8 +107,8 @@ class CyclopsGladiatorEffect extends OneShotEffect { Permanent permanent = game.getPermanent(target.getFirstTarget()); Permanent cyclops = game.getPermanent(source.getSourceId()); if (permanent != null && cyclops != null) { - permanent.damage(cyclops.getPower().getValue(), cyclops.getId(), game, true); - cyclops.damage(permanent.getPower().getValue(), permanent.getId(), game, true); + permanent.damage(cyclops.getPower().getValue(), cyclops.getId(), game, true, false); + cyclops.damage(permanent.getPower().getValue(), permanent.getId(), game, true, false); return true; } } diff --git a/Mage.Sets/src/mage/sets/magic2011/Fling.java b/Mage.Sets/src/mage/sets/magic2011/Fling.java index 76c2b94cb0b..76ba7a74ae1 100644 --- a/Mage.Sets/src/mage/sets/magic2011/Fling.java +++ b/Mage.Sets/src/mage/sets/magic2011/Fling.java @@ -95,7 +95,7 @@ class FlingEffect extends OneShotEffect { if (amount > 0) { Permanent permanent = game.getPermanent(source.getFirstTarget()); if (permanent != null) { - permanent.damage(amount, source.getSourceId(), game, true); + permanent.damage(amount, source.getSourceId(), game, true, false); return true; } Player player = game.getPlayer(source.getFirstTarget()); diff --git a/Mage.Sets/src/mage/sets/magic2011/VengefulArchon.java b/Mage.Sets/src/mage/sets/magic2011/VengefulArchon.java index f4a3b15d9ef..c2474954af4 100644 --- a/Mage.Sets/src/mage/sets/magic2011/VengefulArchon.java +++ b/Mage.Sets/src/mage/sets/magic2011/VengefulArchon.java @@ -101,6 +101,7 @@ class VengefulArchonEffect extends PreventionEffectImpl { @Override public void init(Ability source, Game game) { + super.init(source, game); if (source.getManaCosts().getVariableCosts().size() > 0) amount = source.getManaCosts().getVariableCosts().get(0).getAmount(); } diff --git a/Mage.Sets/src/mage/sets/worldwake/SearingBlaze.java b/Mage.Sets/src/mage/sets/worldwake/SearingBlaze.java index c67881e64f0..c53b2a9145d 100644 --- a/Mage.Sets/src/mage/sets/worldwake/SearingBlaze.java +++ b/Mage.Sets/src/mage/sets/worldwake/SearingBlaze.java @@ -132,7 +132,7 @@ class SearingBlazeEffect extends OneShotEffect { player.damage(3, source.getId(), game, false, true); } if (creature != null) { - creature.damage(3, source.getId(), game, true); + creature.damage(3, source.getId(), game, true, false); } } else { @@ -140,7 +140,7 @@ class SearingBlazeEffect extends OneShotEffect { player.damage(1, source.getId(), game, false, true); } if (creature != null) { - creature.damage(1, source.getId(), game, true); + creature.damage(1, source.getId(), game, true, false); } } return true; diff --git a/Mage/src/mage/abilities/effects/ContinuousEffectImpl.java b/Mage/src/mage/abilities/effects/ContinuousEffectImpl.java index 9ed1ee404a4..0f1f956b242 100644 --- a/Mage/src/mage/abilities/effects/ContinuousEffectImpl.java +++ b/Mage/src/mage/abilities/effects/ContinuousEffectImpl.java @@ -28,13 +28,17 @@ package mage.abilities.effects; +import java.util.ArrayList; import java.util.Date; +import java.util.List; +import java.util.UUID; import mage.Constants.Duration; import mage.Constants.EffectType; import mage.Constants.Layer; import mage.Constants.Outcome; import mage.Constants.SubLayer; import mage.abilities.Ability; +import mage.abilities.ActivatedAbility; import mage.game.Game; /** @@ -48,6 +52,8 @@ public abstract class ContinuousEffectImpl> ex protected SubLayer sublayer; protected Date timestamp; protected boolean used = false; + protected boolean affectedObjectsSet = false; + protected List objects = new ArrayList(); public ContinuousEffectImpl(Duration duration, Outcome outcome) { super(outcome); @@ -62,13 +68,17 @@ public abstract class ContinuousEffectImpl> ex this.sublayer = sublayer; } - public ContinuousEffectImpl(final ContinuousEffectImpl effect) { + public ContinuousEffectImpl(final ContinuousEffectImpl effect) { super(effect); this.duration = effect.duration; this.layer = effect.layer; this.sublayer = effect.sublayer; this.timestamp = new Date(effect.timestamp.getTime()); this.used = effect.used; + this.affectedObjectsSet = effect.affectedObjectsSet; + for (UUID objectId: effect.objects) { + this.objects.add(objectId); + } } @Override @@ -105,6 +115,20 @@ public abstract class ContinuousEffectImpl> ex } @Override - public void init(Ability source, Game game) {} + public void init(Ability source, Game game) { + //20100716 - 611.2c + if (source instanceof ActivatedAbility) { + switch (layer) { + case CopyEffects_1: + case ControlChangingEffects_2: + case TextChangingEffects_3: + case TypeChangingEffects_4: + case ColorChangingEffects_5: + case AbilityAddingRemovingEffects_6: + case PTChangingEffects_7: + this.affectedObjectsSet = true; + } + } + } } diff --git a/Mage/src/mage/abilities/effects/PlaneswalkerRedirectionEffect.java b/Mage/src/mage/abilities/effects/PlaneswalkerRedirectionEffect.java index ca7e2ab30df..2906b732301 100644 --- a/Mage/src/mage/abilities/effects/PlaneswalkerRedirectionEffect.java +++ b/Mage/src/mage/abilities/effects/PlaneswalkerRedirectionEffect.java @@ -34,6 +34,7 @@ import mage.Constants.Outcome; import mage.abilities.Ability; import mage.filter.common.FilterPlaneswalkerPermanent; import mage.game.Game; +import mage.game.events.DamageEvent; import mage.game.events.GameEvent; import mage.game.events.GameEvent.EventType; import mage.game.permanent.Permanent; @@ -65,8 +66,9 @@ public class PlaneswalkerRedirectionEffect extends RedirectionEffect> extends @Override public boolean replaceEvent(GameEvent event, Ability source, Game game) { + DamageEvent damageEvent = (DamageEvent)event; Permanent permanent = game.getPermanent(redirectTarget.getFirstTarget()); - Ability damageSource = getSource(event.getSourceId(), game); + Ability damageSource = getSource(damageEvent.getSourceId(), game); if (permanent != null) { - permanent.damage(event.getAmount(), damageSource.getId(), game, event.getFlag()); + permanent.damage(damageEvent.getAmount(), damageSource.getId(), game, damageEvent.isPreventable(), damageEvent.isCombatDamage()); return true; } Player player = game.getPlayer(redirectTarget.getFirstTarget()); if (player != null) { - player.damage(event.getAmount(), damageSource.getId(), game, false, event.getFlag()); + player.damage(damageEvent.getAmount(), damageSource.getId(), game, damageEvent.isCombatDamage(), damageEvent.isPreventable()); return true; } return false; diff --git a/Mage/src/mage/abilities/effects/common/BoostControlledEffect.java b/Mage/src/mage/abilities/effects/common/BoostControlledEffect.java index cdd49eaeda4..113694875af 100644 --- a/Mage/src/mage/abilities/effects/common/BoostControlledEffect.java +++ b/Mage/src/mage/abilities/effects/common/BoostControlledEffect.java @@ -78,12 +78,26 @@ public class BoostControlledEffect extends ContinuousEffectImpl { @Override public boolean apply(Game game, Ability source) { for (Permanent permanent: game.getBattlefield().getActivePermanents(filter, source.getControllerId(), game)) { - permanent.damage(amount, source.getId(), game, true); + permanent.damage(amount, source.getId(), game, true, false); } return true; } diff --git a/Mage/src/mage/abilities/effects/common/DamageEverythingEffect.java b/Mage/src/mage/abilities/effects/common/DamageEverythingEffect.java index 971505bbcd0..6b819d39f5f 100644 --- a/Mage/src/mage/abilities/effects/common/DamageEverythingEffect.java +++ b/Mage/src/mage/abilities/effects/common/DamageEverythingEffect.java @@ -63,7 +63,7 @@ public class DamageEverythingEffect extends OneShotEffect { for (UUID target: multiTarget.getTargets()) { Permanent permanent = game.getPermanent(target); if (permanent != null) { - permanent.damage(multiTarget.getTargetAmount(target), source.getId(), game, true); + permanent.damage(multiTarget.getTargetAmount(target), source.getId(), game, true, false); } else { Player player = game.getPlayer(target); diff --git a/Mage/src/mage/abilities/effects/common/DamageTargetEffect.java b/Mage/src/mage/abilities/effects/common/DamageTargetEffect.java index 872df05f36c..3de36a38652 100644 --- a/Mage/src/mage/abilities/effects/common/DamageTargetEffect.java +++ b/Mage/src/mage/abilities/effects/common/DamageTargetEffect.java @@ -73,7 +73,7 @@ public class DamageTargetEffect extends OneShotEffect { public boolean apply(Game game, Ability source) { Permanent permanent = game.getPermanent(source.getFirstTarget()); if (permanent != null) { - permanent.damage(amount, source.getId(), game, preventable); + permanent.damage(amount, source.getId(), game, preventable, false); return true; } Player player = game.getPlayer(source.getFirstTarget()); diff --git a/Mage/src/mage/abilities/effects/common/DamageXTargetEffect.java b/Mage/src/mage/abilities/effects/common/DamageXTargetEffect.java index 2f08285e395..d3e0e016ba2 100644 --- a/Mage/src/mage/abilities/effects/common/DamageXTargetEffect.java +++ b/Mage/src/mage/abilities/effects/common/DamageXTargetEffect.java @@ -59,7 +59,7 @@ public class DamageXTargetEffect extends OneShotEffect { int amount = source.getManaCosts().getVariableCosts().get(0).getAmount(); Permanent permanent = game.getPermanent(source.getFirstTarget()); if (permanent != null) { - permanent.damage(amount, source.getId(), game, true); + permanent.damage(amount, source.getId(), game, true, false); return true; } Player player = game.getPlayer(source.getFirstTarget()); diff --git a/Mage/src/mage/abilities/effects/common/GainAbilityAttachedEffect.java b/Mage/src/mage/abilities/effects/common/GainAbilityAttachedEffect.java index 2b3bdd467dd..262c328ba79 100644 --- a/Mage/src/mage/abilities/effects/common/GainAbilityAttachedEffect.java +++ b/Mage/src/mage/abilities/effects/common/GainAbilityAttachedEffect.java @@ -66,8 +66,7 @@ public class GainAbilityAttachedEffect extends ContinuousEffectImpl { - - protected Ability ability; - protected boolean excludeSource; - protected FilterPermanent permanentFilter; - - public GainAbilityControlledEffect(Ability ability, Duration duration) { - this(ability, duration, new FilterPermanent()); - } - - public GainAbilityControlledEffect(Ability ability, Duration duration, FilterPermanent filter) { - this(ability, duration, filter, false); - } - - public GainAbilityControlledEffect(Ability ability, Duration duration, FilterPermanent filter, boolean excludeSource) { - super(duration, Layer.AbilityAddingRemovingEffects_6, SubLayer.NA, Outcome.AddAbility); - this.ability = ability; - this.permanentFilter = filter; - this.excludeSource = excludeSource; - } - - public GainAbilityControlledEffect(final GainAbilityControlledEffect effect) { - super(effect); - this.ability = effect.ability.copy(); - this.permanentFilter = effect.permanentFilter.copy(); - this.excludeSource = effect.excludeSource; - } - - @Override - public GainAbilityControlledEffect copy() { - return new GainAbilityControlledEffect(this); - } - - @Override - public boolean apply(Game game, Ability source) { - for (Permanent perm: game.getBattlefield().getAllActivePermanents(permanentFilter, source.getControllerId())) { - if (!(excludeSource && perm.getId().equals(source.getSourceId()))) { - perm.addAbility(ability.copy()); - } - } - return true; - } - - @Override - public String getText(Ability source) { - StringBuilder sb = new StringBuilder(); - if (excludeSource) - sb.append("Other "); - sb.append(permanentFilter.getMessage()).append(" you control gain ").append(ability.getRule()); - sb.append(" ").append(duration.toString()); - return sb.toString(); - } - -} +/* + * Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of BetaSteward_at_googlemail.com. + */ + +package mage.abilities.effects.common; + +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; +import mage.Constants.Duration; +import mage.Constants.Layer; +import mage.Constants.Outcome; +import mage.Constants.SubLayer; +import mage.abilities.Ability; +import mage.abilities.effects.ContinuousEffectImpl; +import mage.filter.FilterPermanent; +import mage.game.Game; +import mage.game.permanent.Permanent; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class GainAbilityControlledEffect extends ContinuousEffectImpl { + + protected Ability ability; + protected boolean excludeSource; + protected FilterPermanent filter; + + public GainAbilityControlledEffect(Ability ability, Duration duration) { + this(ability, duration, new FilterPermanent()); + } + + public GainAbilityControlledEffect(Ability ability, Duration duration, FilterPermanent filter) { + this(ability, duration, filter, false); + } + + public GainAbilityControlledEffect(Ability ability, Duration duration, FilterPermanent filter, boolean excludeSource) { + super(duration, Layer.AbilityAddingRemovingEffects_6, SubLayer.NA, Outcome.AddAbility); + this.ability = ability; + this.filter = filter; + this.excludeSource = excludeSource; + } + + public GainAbilityControlledEffect(final GainAbilityControlledEffect effect) { + super(effect); + this.ability = effect.ability.copy(); + this.filter = effect.filter.copy(); + this.excludeSource = effect.excludeSource; + } + + @Override + public void init(Ability source, Game game) { + super.init(source, game); + if (this.affectedObjectsSet) { + for (Permanent perm: game.getBattlefield().getAllActivePermanents(filter, source.getControllerId())) { + if (!(excludeSource && perm.getId().equals(source.getSourceId()))) { + objects.add(perm.getId()); + } + } + } + } + + @Override + public GainAbilityControlledEffect copy() { + return new GainAbilityControlledEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + for (Permanent perm: game.getBattlefield().getAllActivePermanents(filter, source.getControllerId())) { + if (!this.affectedObjectsSet || objects.contains(perm.getId())) { + if (!(excludeSource && perm.getId().equals(source.getSourceId()))) { + perm.addAbility(ability.copy()); + } + } + } + return true; + } + + @Override + public String getText(Ability source) { + StringBuilder sb = new StringBuilder(); + if (excludeSource) + sb.append("Other "); + sb.append(filter.getMessage()).append(" you control gain ").append(ability.getRule()); + sb.append(" ").append(duration.toString()); + return sb.toString(); + } + +} diff --git a/Mage/src/mage/abilities/effects/common/GainAbilitySourceEffect.java b/Mage/src/mage/abilities/effects/common/GainAbilitySourceEffect.java index 8bed43abcda..78a29109088 100644 --- a/Mage/src/mage/abilities/effects/common/GainAbilitySourceEffect.java +++ b/Mage/src/mage/abilities/effects/common/GainAbilitySourceEffect.java @@ -64,8 +64,7 @@ public class GainAbilitySourceEffect extends ContinuousEffectImpl { + private static FilterPlaneswalkerPermanent filterPlaneswalker = new FilterPlaneswalkerPermanent(); + protected List groups = new ArrayList(); protected Set defenders = new HashSet(); protected UUID attackerId; @@ -118,12 +121,9 @@ public class Combat implements Serializable, Copyable { public void selectBlockers(Game game) { if (!game.replaceEvent(GameEvent.getEvent(GameEvent.EventType.DECLARING_BLOCKERS, attackerId, attackerId))) { - for (UUID defenderId: defenders) { - //check if defender is being attacked - if (isAttacked(defenderId, game)) { - game.getPlayer(defenderId).selectBlockers(game); - game.fireEvent(GameEvent.getEvent(GameEvent.EventType.DECLARED_BLOCKERS, defenderId, defenderId)); - } + for (UUID defenderId: getPlayerDefenders(game)) { + game.getPlayer(defenderId).selectBlockers(game); + game.fireEvent(GameEvent.getEvent(GameEvent.EventType.DECLARED_BLOCKERS, defenderId, defenderId)); } } } @@ -137,7 +137,7 @@ public class Combat implements Serializable, Copyable { while (true) { Player opponent = players.getNext(game); if (opponents.contains(opponent.getId())) { - defenders.add(opponent.getId()); + addDefender(opponent.getId(), game); break; } } @@ -147,17 +147,26 @@ public class Combat implements Serializable, Copyable { while (true) { Player opponent = players.getPrevious(game); if (opponents.contains(opponent.getId())) { - defenders.add(opponent.getId()); + addDefender(opponent.getId(), game); break; } } break; case MULITPLE: - defenders.addAll(game.getOpponents(attackerId)); + for (UUID opponentId: game.getOpponents(attackerId)) { + addDefender(opponentId, game); + } break; } } + private void addDefender(UUID defenderId, Game game) { + defenders.add(defenderId); + for (Permanent permanent: game.getBattlefield().getAllActivePermanents(filterPlaneswalker, defenderId)) { + defenders.add(permanent.getId()); + } + } + public void declareAttacker(UUID attackerId, UUID defenderId, Game game) { if (!defenders.contains(defenderId)) return; @@ -252,6 +261,21 @@ public class Combat implements Serializable, Copyable { return false; } + private Set getPlayerDefenders(Game game) { + Set playerDefenders = new HashSet(); + for (CombatGroup group: groups) { + if (group.defenderIsPlaneswalker) { + Permanent permanent = game.getPermanent(group.getDefenderId()); + if (permanent != null) + playerDefenders.add(permanent.getControllerId()); + } + else { + playerDefenders.add(group.getDefenderId()); + } + } + return playerDefenders; + } + public void damageAssignmentOrder(Game game) { //TODO: set damage assignment order } diff --git a/Mage/src/mage/game/combat/CombatGroup.java b/Mage/src/mage/game/combat/CombatGroup.java index 43dafe1b0ca..de1028618e7 100644 --- a/Mage/src/mage/game/combat/CombatGroup.java +++ b/Mage/src/mage/game/combat/CombatGroup.java @@ -171,23 +171,23 @@ public class CombatGroup implements Serializable, Copyable { if (hasTrample(attacker)) { int lethalDamage = blocker.getToughness().getValue() - blocker.getDamage(); if (lethalDamage >= damage) { - blocker.damage(damage, attacker.getId(), game, true); + blocker.damage(damage, attacker.getId(), game, true, true); } else { Player player = game.getPlayer(attacker.getControllerId()); int damageAssigned = player.getAmount(lethalDamage, damage, "Assign damage to " + blocker.getName(), game); - blocker.damage(damageAssigned, attacker.getId(), game, true); + blocker.damage(damageAssigned, attacker.getId(), game, true, true); damage -= damageAssigned; if (damage > 0) defenderDamage(attacker, damage, game); } } else { - blocker.damage(damage, attacker.getId(), game, true); + blocker.damage(damage, attacker.getId(), game, true, true); } } if (canDamage(blocker, first)) { - attacker.damage(blocker.getPower().getValue(), blocker.getId(), game, true); + attacker.damage(blocker.getPower().getValue(), blocker.getId(), game, true, true); } } } @@ -202,12 +202,12 @@ public class CombatGroup implements Serializable, Copyable { Permanent blocker = game.getPermanent(blockerId); int lethalDamage = blocker.getToughness().getValue() - blocker.getDamage(); if (lethalDamage >= damage) { - blocker.damage(damage, attacker.getId(), game, true); + blocker.damage(damage, attacker.getId(), game, true, true); damage = 0; break; } int damageAssigned = player.getAmount(lethalDamage, damage, "Assign damage to " + blocker.getName(), game); - blocker.damage(damageAssigned, attacker.getId(), game, true); + blocker.damage(damageAssigned, attacker.getId(), game, true, true); damage -= damageAssigned; } if (damage > 0 && hasTrample(attacker)) { @@ -216,7 +216,7 @@ public class CombatGroup implements Serializable, Copyable { for (UUID blockerId: blockerOrder) { Permanent blocker = game.getPermanent(blockerId); if (canDamage(blocker, first)) { - attacker.damage(blocker.getPower().getValue(), blocker.getId(), game, true); + attacker.damage(blocker.getPower().getValue(), blocker.getId(), game, true, true); } } } @@ -226,7 +226,7 @@ public class CombatGroup implements Serializable, Copyable { if (this.defenderIsPlaneswalker) { Permanent defender = game.getPermanent(defenderId); if (defender != null) { - defender.damage(amount, attacker.getId(), game, true); + defender.damage(amount, attacker.getId(), game, true, true); } } else { diff --git a/Mage/src/mage/game/events/DamageCreatureEvent.java b/Mage/src/mage/game/events/DamageCreatureEvent.java new file mode 100644 index 00000000000..7110ad3d233 --- /dev/null +++ b/Mage/src/mage/game/events/DamageCreatureEvent.java @@ -0,0 +1,43 @@ +/* + * Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of BetaSteward_at_googlemail.com. + */ + +package mage.game.events; + +import java.util.UUID; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class DamageCreatureEvent extends DamageEvent { + + public DamageCreatureEvent(UUID targetId, UUID sourceId, UUID playerId, int amount, boolean preventable, boolean combat) { + super(EventType.DAMAGE_CREATURE, targetId, sourceId, playerId, amount, preventable, combat); + } + +} diff --git a/Mage/src/mage/game/events/DamageEvent.java b/Mage/src/mage/game/events/DamageEvent.java new file mode 100644 index 00000000000..47e8b5fd821 --- /dev/null +++ b/Mage/src/mage/game/events/DamageEvent.java @@ -0,0 +1,54 @@ +/* + * Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of BetaSteward_at_googlemail.com. + */ + +package mage.game.events; + +import java.util.UUID; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public abstract class DamageEvent extends GameEvent { + + protected boolean combat; + + public DamageEvent(EventType type, UUID targetId, UUID sourceId, UUID playerId, int amount, boolean preventable, boolean combat) { + super(type, targetId, sourceId, playerId, amount, preventable); + this.combat = combat; + } + + public boolean isCombatDamage() { + return combat; + } + + public boolean isPreventable() { + return flag; + } + +} diff --git a/Mage/src/mage/game/events/DamagePlaneswalkerEvent.java b/Mage/src/mage/game/events/DamagePlaneswalkerEvent.java new file mode 100644 index 00000000000..cf3414bba70 --- /dev/null +++ b/Mage/src/mage/game/events/DamagePlaneswalkerEvent.java @@ -0,0 +1,43 @@ +/* + * Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of BetaSteward_at_googlemail.com. + */ + +package mage.game.events; + +import java.util.UUID; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class DamagePlaneswalkerEvent extends DamageEvent { + + public DamagePlaneswalkerEvent(UUID targetId, UUID sourceId, UUID playerId, int amount, boolean preventable, boolean combat) { + super(EventType.DAMAGE_PLANESWALKER, targetId, sourceId, playerId, amount, preventable, combat); + } + +} diff --git a/Mage/src/mage/game/events/DamagePlayerEvent.java b/Mage/src/mage/game/events/DamagePlayerEvent.java new file mode 100644 index 00000000000..c25f60c8e97 --- /dev/null +++ b/Mage/src/mage/game/events/DamagePlayerEvent.java @@ -0,0 +1,43 @@ +/* + * Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of BetaSteward_at_googlemail.com. + */ + +package mage.game.events; + +import java.util.UUID; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class DamagePlayerEvent extends DamageEvent { + + public DamagePlayerEvent(UUID targetId, UUID sourceId, UUID playerId, int amount, boolean preventable, boolean combat) { + super(EventType.DAMAGE_PLAYER, targetId, sourceId, playerId, amount, preventable, combat); + } + +} diff --git a/Mage/src/mage/game/events/DamagedCreatureEvent.java b/Mage/src/mage/game/events/DamagedCreatureEvent.java new file mode 100644 index 00000000000..11075283e37 --- /dev/null +++ b/Mage/src/mage/game/events/DamagedCreatureEvent.java @@ -0,0 +1,43 @@ +/* + * Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of BetaSteward_at_googlemail.com. + */ + +package mage.game.events; + +import java.util.UUID; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class DamagedCreatureEvent extends DamagedEvent { + + public DamagedCreatureEvent(UUID targetId, UUID sourceId, UUID playerId, int amount, boolean combat) { + super(EventType.DAMAGED_CREATURE, targetId, sourceId, playerId, amount, combat); + } + +} diff --git a/Mage/src/mage/game/events/DamagedEvent.java b/Mage/src/mage/game/events/DamagedEvent.java new file mode 100644 index 00000000000..03f31209be6 --- /dev/null +++ b/Mage/src/mage/game/events/DamagedEvent.java @@ -0,0 +1,54 @@ +/* + * Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of BetaSteward_at_googlemail.com. + */ + +package mage.game.events; + +import java.util.UUID; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public abstract class DamagedEvent extends GameEvent { + + protected boolean combat; + + public DamagedEvent(EventType type, UUID targetId, UUID sourceId, UUID playerId, int amount, boolean combat) { + super(type, targetId, sourceId, playerId, amount, false); + this.combat = combat; + } + + public boolean isCombatDamage() { + return combat; + } + + public boolean isPreventable() { + return flag; + } + +} diff --git a/Mage/src/mage/game/events/DamagedPlaneswalkerEvent.java b/Mage/src/mage/game/events/DamagedPlaneswalkerEvent.java new file mode 100644 index 00000000000..f15e237aff4 --- /dev/null +++ b/Mage/src/mage/game/events/DamagedPlaneswalkerEvent.java @@ -0,0 +1,43 @@ +/* + * Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of BetaSteward_at_googlemail.com. + */ + +package mage.game.events; + +import java.util.UUID; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class DamagedPlaneswalkerEvent extends DamagedEvent { + + public DamagedPlaneswalkerEvent(UUID targetId, UUID sourceId, UUID playerId, int amount, boolean combat) { + super(EventType.DAMAGED_PLANESWALKER, targetId, sourceId, playerId, amount, combat); + } + +} diff --git a/Mage/src/mage/game/events/DamagedPlayerEvent.java b/Mage/src/mage/game/events/DamagedPlayerEvent.java new file mode 100644 index 00000000000..172f8edaaea --- /dev/null +++ b/Mage/src/mage/game/events/DamagedPlayerEvent.java @@ -0,0 +1,43 @@ +/* + * Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of BetaSteward_at_googlemail.com. + */ + +package mage.game.events; + +import java.util.UUID; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class DamagedPlayerEvent extends DamagedEvent { + + public DamagedPlayerEvent(UUID targetId, UUID sourceId, UUID playerId, int amount, boolean combat) { + super(EventType.DAMAGED_PLAYER, targetId, sourceId, playerId, amount, combat); + } + +} diff --git a/Mage/src/mage/game/events/GameEvent.java b/Mage/src/mage/game/events/GameEvent.java index 8d480c3be32..1379509af83 100644 --- a/Mage/src/mage/game/events/GameEvent.java +++ b/Mage/src/mage/game/events/GameEvent.java @@ -36,13 +36,13 @@ import java.util.UUID; */ public class GameEvent { - private EventType type; - private UUID targetId; - private UUID sourceId; - private UUID playerId; - private int amount; - private boolean flag; - private String data; + protected EventType type; + protected UUID targetId; + protected UUID sourceId; + protected UUID playerId; + protected int amount; + protected boolean flag; + protected String data; public enum EventType { @@ -79,8 +79,6 @@ public class GameEvent { DISCARDED_CARD, CYCLE_CARD, CYCLED_CARD, DAMAGE_PLAYER, DAMAGED_PLAYER, - COMBAT_DAMAGE_PLAYER, COMBAT_DAMAGED_PLAYER, - NONCOMBAT_DAMAGE_PLAYER, NONCOMBAT_DAMAGED_PLAYER, PLAYER_LIFE_CHANGE, GAIN_LIFE, GAINED_LIFE, LOSE_LIFE, LOST_LIFE, diff --git a/Mage/src/mage/game/permanent/Permanent.java b/Mage/src/mage/game/permanent/Permanent.java index 51a8d1b36ed..c34de155501 100644 --- a/Mage/src/mage/game/permanent/Permanent.java +++ b/Mage/src/mage/game/permanent/Permanent.java @@ -70,7 +70,7 @@ public interface Permanent extends Card { public boolean hasProtectionFrom(MageObject source); public boolean hasSummoningSickness(); public int getDamage(); - public int damage(int damage, UUID sourceId, Game game, boolean preventable); + public int damage(int damage, UUID sourceId, Game game, boolean preventable, boolean combat); public void removeAllDamage(Game game); public Counters getCounters(); public void addCounters(String name, int amount); diff --git a/Mage/src/mage/game/permanent/PermanentImpl.java b/Mage/src/mage/game/permanent/PermanentImpl.java index 9f24584760a..ddeaf18d7fb 100644 --- a/Mage/src/mage/game/permanent/PermanentImpl.java +++ b/Mage/src/mage/game/permanent/PermanentImpl.java @@ -48,6 +48,10 @@ import mage.cards.CardImpl; import mage.counters.Counter; import mage.counters.Counters; import mage.game.Game; +import mage.game.events.DamageCreatureEvent; +import mage.game.events.DamagePlaneswalkerEvent; +import mage.game.events.DamagedCreatureEvent; +import mage.game.events.DamagedPlaneswalkerEvent; import mage.game.events.GameEvent; import mage.game.events.GameEvent.EventType; import mage.players.Player; @@ -408,14 +412,14 @@ public abstract class PermanentImpl> extends CardImpl } @Override - public int damage(int damageAmount, UUID sourceId, Game game, boolean preventable) { + public int damage(int damageAmount, UUID sourceId, Game game, boolean preventable, boolean combat) { int damageDone = 0; if (damageAmount > 0 && canDamage(game.getObject(sourceId))) { if (cardType.contains(CardType.PLANESWALKER)) { - damageDone = damagePlaneswalker(damageAmount, sourceId, game, preventable); + damageDone = damagePlaneswalker(damageAmount, sourceId, game, preventable, combat); } else { - damageDone = damageCreature(damageAmount, sourceId, game, preventable); + damageDone = damageCreature(damageAmount, sourceId, game, preventable, combat); } if (damageDone > 0) { Permanent source = game.getPermanent(sourceId); @@ -436,8 +440,8 @@ public abstract class PermanentImpl> extends CardImpl damage = 0; } - protected int damagePlaneswalker(int damage, UUID sourceId, Game game, boolean preventable) { - GameEvent event = new GameEvent(GameEvent.EventType.DAMAGE_PLANESWALKER, objectId, sourceId, controllerId, damage, preventable); + protected int damagePlaneswalker(int damage, UUID sourceId, Game game, boolean preventable, boolean combat) { + GameEvent event = new DamagePlaneswalkerEvent(objectId, sourceId, controllerId, damage, preventable, combat); if (!game.replaceEvent(event)) { int actualDamage = event.getAmount(); if (actualDamage > 0) { @@ -445,15 +449,15 @@ public abstract class PermanentImpl> extends CardImpl actualDamage = this.loyalty.getValue(); } this.loyalty.boostValue(-actualDamage); - game.fireEvent(GameEvent.getEvent(EventType.DAMAGED_PLANESWALKER, objectId, sourceId, controllerId, actualDamage)); + game.fireEvent(new DamagedPlaneswalkerEvent(objectId, sourceId, controllerId, actualDamage, combat)); return actualDamage; } } return 0; } - protected int damageCreature(int damage, UUID sourceId, Game game, boolean preventable) { - GameEvent event = new GameEvent(GameEvent.EventType.DAMAGE_CREATURE, objectId, sourceId, controllerId, damage, preventable); + protected int damageCreature(int damage, UUID sourceId, Game game, boolean preventable, boolean combat) { + GameEvent event = new DamageCreatureEvent(objectId, sourceId, controllerId, damage, preventable, combat); if (!game.replaceEvent(event)) { int actualDamage = event.getAmount(); if (actualDamage > 0) { @@ -461,7 +465,7 @@ public abstract class PermanentImpl> extends CardImpl actualDamage = this.toughness.getValue() - this.damage; } this.damage += actualDamage; - game.fireEvent(GameEvent.getEvent(EventType.DAMAGED_CREATURE, objectId, sourceId, controllerId, actualDamage)); + game.fireEvent(new DamagedCreatureEvent(objectId, sourceId, controllerId, actualDamage, combat)); return actualDamage; } } diff --git a/Mage/src/mage/players/PlayerImpl.java b/Mage/src/mage/players/PlayerImpl.java index 00168710bf8..128e1f328f1 100644 --- a/Mage/src/mage/players/PlayerImpl.java +++ b/Mage/src/mage/players/PlayerImpl.java @@ -68,6 +68,8 @@ import mage.filter.common.FilterCreatureForAttack; import mage.filter.common.FilterCreatureForCombat; import mage.game.Game; import mage.game.combat.CombatGroup; +import mage.game.events.DamagePlayerEvent; +import mage.game.events.DamagedPlayerEvent; import mage.game.permanent.Permanent; import mage.game.events.GameEvent; import mage.game.stack.StackAbility; @@ -616,7 +618,7 @@ public abstract class PlayerImpl> implements Player, Ser @Override public int damage(int damage, UUID sourceId, Game game, boolean combatDamage, boolean preventable) { if (damage > 0 && canDamage(game.getObject(sourceId))) { - GameEvent event = new GameEvent(GameEvent.EventType.DAMAGE_PLAYER, playerId, sourceId, playerId, damage, preventable); + GameEvent event = new DamagePlayerEvent(playerId, sourceId, playerId, damage, preventable, combatDamage); if (!game.replaceEvent(event)) { int actualDamage = event.getAmount(); if (actualDamage > 0) { @@ -626,11 +628,12 @@ public abstract class PlayerImpl> implements Player, Ser Player player = game.getPlayer(source.getControllerId()); player.gainLife(actualDamage, game); } - game.fireEvent(GameEvent.getEvent(GameEvent.EventType.DAMAGED_PLAYER, playerId, sourceId, playerId, actualDamage)); - if (combatDamage) - game.fireEvent(GameEvent.getEvent(GameEvent.EventType.COMBAT_DAMAGED_PLAYER, playerId, sourceId, playerId, actualDamage)); - else - game.fireEvent(GameEvent.getEvent(GameEvent.EventType.NONCOMBAT_DAMAGED_PLAYER, playerId, sourceId, playerId, actualDamage)); + game.fireEvent(new DamagedPlayerEvent(playerId, sourceId, playerId, actualDamage, combatDamage)); +// game.fireEvent(GameEvent.getEvent(GameEvent.EventType.DAMAGED_PLAYER, playerId, sourceId, playerId, actualDamage)); +// if (combatDamage) +// game.fireEvent(GameEvent.getEvent(GameEvent.EventType.COMBAT_DAMAGED_PLAYER, playerId, sourceId, playerId, actualDamage)); +// else +// game.fireEvent(GameEvent.getEvent(GameEvent.EventType.NONCOMBAT_DAMAGED_PLAYER, playerId, sourceId, playerId, actualDamage)); return actualDamage; } }