From b1958d9761e003728b78c2e2a319221901bd6584 Mon Sep 17 00:00:00 2001 From: BetaSteward Date: Sun, 2 May 2010 14:50:58 +0000 Subject: [PATCH] ... --- .../abilities/DelayedTriggeredAbilities.java | 72 +++++++++++++++++++ .../abilities/DelayedTriggeredAbility.java | 44 ++++++++++++ Mage/src/mage/abilities/PlayLandAbility.java | 2 +- Mage/src/mage/abilities/SpecialAction.java | 43 +++++++++++ Mage/src/mage/abilities/SpecialActions.java | 51 +++++++++++++ .../mage/abilities/TriggeredAbilities.java | 20 ------ Mage/src/mage/abilities/TriggeredAbility.java | 2 +- .../common/AttacksTriggeredAbility.java | 4 +- .../EntersBattlefieldTriggeredAbility.java | 7 +- .../abilities/common/LandfallAbility.java | 7 +- .../LeavesBattlefieldTriggeredAbility.java | 7 +- .../common/OnEventTriggeredAbility.java | 4 +- ...oGraveFromBattlefieldTriggeredAbility.java | 7 +- .../common/SimpleTriggeredAbility.java | 4 +- .../abilities/keyword/CascadeAbility.java | 4 +- .../abilities/keyword/ExaltedAbility.java | 4 +- Mage/src/mage/game/Game.java | 1 + Mage/src/mage/game/GameImpl.java | 5 ++ Mage/src/mage/game/GameState.java | 25 ++++++- .../game/events/PlayerQueryEventSource.java | 1 - Mage/src/mage/game/events/TableEvent.java | 11 ++- .../mage/game/events/TableEventSource.java | 8 ++- .../mage/game/permanent/PermanentCard.java | 1 - Mage/src/mage/players/PlayerImpl.java | 38 +++++++--- .../common/TargetSacrificePermanent.java | 54 ++++++++++++++ .../mage/util/CopierObjectInputStream.java | 1 - Mage/src/mage/watchers/Watcher.java | 1 + Mage/src/mage/watchers/WatcherImpl.java | 8 ++- 28 files changed, 383 insertions(+), 53 deletions(-) create mode 100644 Mage/src/mage/abilities/DelayedTriggeredAbilities.java create mode 100644 Mage/src/mage/abilities/DelayedTriggeredAbility.java create mode 100644 Mage/src/mage/abilities/SpecialAction.java create mode 100644 Mage/src/mage/abilities/SpecialActions.java create mode 100644 Mage/src/mage/target/common/TargetSacrificePermanent.java diff --git a/Mage/src/mage/abilities/DelayedTriggeredAbilities.java b/Mage/src/mage/abilities/DelayedTriggeredAbilities.java new file mode 100644 index 0000000000..b28ec81a05 --- /dev/null +++ b/Mage/src/mage/abilities/DelayedTriggeredAbilities.java @@ -0,0 +1,72 @@ +/* + * 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; + +import java.util.ArrayList; +import java.util.Iterator; +import mage.game.Game; +import mage.game.events.GameEvent; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class DelayedTriggeredAbilities extends ArrayList { + + public void checkTriggers(GameEvent event, Game game) { + Iterator it = this.iterator(); + while (it.hasNext()) { + DelayedTriggeredAbility ability = it.next(); + if (ability.checkTrigger(event, game)) + it.remove(); + } + } + +// public boolean check(Game game) { +// boolean played = false; +// Iterator it = this.iterator(); +// while(it.hasNext()) { +// TriggeredAbility ability = it.next(); +// it.remove(); +// played |= game.getPlayer(ability.getControllerId()).triggerAbility(ability, game); +// } +// return played; +// } + +// public TriggeredAbilities getControlledBy(UUID controllerId) { +// TriggeredAbilities controlledBy = new TriggeredAbilities(); +// for (TriggeredAbility ability: this) { +// if (ability.getControllerId().equals(controllerId)) +// controlledBy.add(ability); +// } +// return controlledBy; +// } + +} + diff --git a/Mage/src/mage/abilities/DelayedTriggeredAbility.java b/Mage/src/mage/abilities/DelayedTriggeredAbility.java new file mode 100644 index 0000000000..24bbddd3a2 --- /dev/null +++ b/Mage/src/mage/abilities/DelayedTriggeredAbility.java @@ -0,0 +1,44 @@ +/* + * 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; + +import mage.Constants.Zone; +import mage.abilities.effects.Effect; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public abstract class DelayedTriggeredAbility extends TriggeredAbilityImpl { + + public DelayedTriggeredAbility(Effect effect) { + super(Zone.ALL, effect); + } + +} diff --git a/Mage/src/mage/abilities/PlayLandAbility.java b/Mage/src/mage/abilities/PlayLandAbility.java index 346c5c763b..fdbd90d0be 100644 --- a/Mage/src/mage/abilities/PlayLandAbility.java +++ b/Mage/src/mage/abilities/PlayLandAbility.java @@ -39,7 +39,7 @@ import mage.game.Game; public class PlayLandAbility extends ActivatedAbilityImpl { public PlayLandAbility() { - super(Zone.HAND, null); + super(Zone.HAND); this.name = "Play"; } diff --git a/Mage/src/mage/abilities/SpecialAction.java b/Mage/src/mage/abilities/SpecialAction.java new file mode 100644 index 0000000000..7e7aaec4dd --- /dev/null +++ b/Mage/src/mage/abilities/SpecialAction.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.abilities; + +import mage.Constants.Zone; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public abstract class SpecialAction extends ActivatedAbilityImpl { + + public SpecialAction() { + super(Zone.ALL); + } + +} \ No newline at end of file diff --git a/Mage/src/mage/abilities/SpecialActions.java b/Mage/src/mage/abilities/SpecialActions.java new file mode 100644 index 0000000000..fe53c0f200 --- /dev/null +++ b/Mage/src/mage/abilities/SpecialActions.java @@ -0,0 +1,51 @@ +/* +* 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; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class SpecialActions extends ArrayList { + + public Map getControlledBy(UUID controllerId) { + HashMap controlledBy = new HashMap(); + for (SpecialAction action: this) { + if (action.getControllerId().equals(controllerId)) + controlledBy.put(action.id, action); + } + return controlledBy; + } + +} diff --git a/Mage/src/mage/abilities/TriggeredAbilities.java b/Mage/src/mage/abilities/TriggeredAbilities.java index e324b69791..71f090e416 100644 --- a/Mage/src/mage/abilities/TriggeredAbilities.java +++ b/Mage/src/mage/abilities/TriggeredAbilities.java @@ -29,10 +29,7 @@ package mage.abilities; import java.util.ArrayList; -import java.util.Iterator; import java.util.UUID; -import mage.game.Game; -import mage.game.events.GameEvent; /** * @@ -40,23 +37,6 @@ import mage.game.events.GameEvent; */ public class TriggeredAbilities extends ArrayList { - public void handleEvent(GameEvent event, Game game) { - for(TriggeredAbility ability: this) { - ability.checkTrigger(event, game); - } - } - -// public boolean check(Game game) { -// boolean played = false; -// Iterator it = this.iterator(); -// while(it.hasNext()) { -// TriggeredAbility ability = it.next(); -// it.remove(); -// played |= game.getPlayer(ability.getControllerId()).triggerAbility(ability, game); -// } -// return played; -// } - public TriggeredAbilities getControlledBy(UUID controllerId) { TriggeredAbilities controlledBy = new TriggeredAbilities(); for (TriggeredAbility ability: this) { diff --git a/Mage/src/mage/abilities/TriggeredAbility.java b/Mage/src/mage/abilities/TriggeredAbility.java index e5e77ba93d..e1299fd248 100644 --- a/Mage/src/mage/abilities/TriggeredAbility.java +++ b/Mage/src/mage/abilities/TriggeredAbility.java @@ -39,7 +39,7 @@ import mage.game.events.GameEvent; public interface TriggeredAbility extends Ability { public void trigger(Game game, UUID controllerId); - public void checkTrigger(GameEvent event, Game game); + public boolean checkTrigger(GameEvent event, Game game); public boolean checkIfClause(Game game); } diff --git a/Mage/src/mage/abilities/common/AttacksTriggeredAbility.java b/Mage/src/mage/abilities/common/AttacksTriggeredAbility.java index d2f47dd6d5..86036232ef 100644 --- a/Mage/src/mage/abilities/common/AttacksTriggeredAbility.java +++ b/Mage/src/mage/abilities/common/AttacksTriggeredAbility.java @@ -46,10 +46,12 @@ public class AttacksTriggeredAbility extends TriggeredAbilityImpl { } @Override - public void checkTrigger(GameEvent event, Game game) { + public boolean checkTrigger(GameEvent event, Game game) { if (event.getType() == EventType.ATTACKER_DECLARED && event.getSourceId().equals(this.getSourceId()) ) { trigger(game, this.controllerId); + return true; } + return false; } @Override diff --git a/Mage/src/mage/abilities/common/EntersBattlefieldTriggeredAbility.java b/Mage/src/mage/abilities/common/EntersBattlefieldTriggeredAbility.java index 5b3547e8a7..2bba79e359 100644 --- a/Mage/src/mage/abilities/common/EntersBattlefieldTriggeredAbility.java +++ b/Mage/src/mage/abilities/common/EntersBattlefieldTriggeredAbility.java @@ -47,12 +47,15 @@ public class EntersBattlefieldTriggeredAbility extends TriggeredAbilityImpl { } @Override - public void checkTrigger(GameEvent event, Game game) { + public boolean checkTrigger(GameEvent event, Game game) { if (event.getType() == EventType.ZONE_CHANGE && event.getTargetId().equals(this.getSourceId()) ) { ZoneChangeEvent zEvent = (ZoneChangeEvent)event; - if (zEvent.getToZone() == Zone.BATTLEFIELD) + if (zEvent.getToZone() == Zone.BATTLEFIELD) { trigger(game, this.controllerId); + return true; + } } + return false; } @Override diff --git a/Mage/src/mage/abilities/common/LandfallAbility.java b/Mage/src/mage/abilities/common/LandfallAbility.java index 6d576fef23..b8c06ebace 100644 --- a/Mage/src/mage/abilities/common/LandfallAbility.java +++ b/Mage/src/mage/abilities/common/LandfallAbility.java @@ -49,12 +49,15 @@ public class LandfallAbility extends TriggeredAbilityImpl { } @Override - public void checkTrigger(GameEvent event, Game game) { + public boolean checkTrigger(GameEvent event, Game game) { if (event.getType() == EventType.ZONE_CHANGE && ((ZoneChangeEvent)event).getToZone() == Zone.BATTLEFIELD) { Permanent permanent = game.getPermanent(event.getTargetId()); - if (permanent != null && permanent.getCardType().contains(CardType.LAND) && permanent.getControllerId().equals(this.controllerId)) + if (permanent != null && permanent.getCardType().contains(CardType.LAND) && permanent.getControllerId().equals(this.controllerId)) { trigger(game, this.controllerId); + return true; + } } + return false; } @Override diff --git a/Mage/src/mage/abilities/common/LeavesBattlefieldTriggeredAbility.java b/Mage/src/mage/abilities/common/LeavesBattlefieldTriggeredAbility.java index 113f44b86a..ac33afe522 100644 --- a/Mage/src/mage/abilities/common/LeavesBattlefieldTriggeredAbility.java +++ b/Mage/src/mage/abilities/common/LeavesBattlefieldTriggeredAbility.java @@ -47,12 +47,15 @@ public class LeavesBattlefieldTriggeredAbility extends TriggeredAbilityImpl { } @Override - public void checkTrigger(GameEvent event, Game game) { + public boolean checkTrigger(GameEvent event, Game game) { if (event.getType() == EventType.ZONE_CHANGE && event.getTargetId().equals(this.getSourceId()) ) { ZoneChangeEvent zEvent = (ZoneChangeEvent)event; - if (zEvent.getFromZone() == Zone.BATTLEFIELD) + if (zEvent.getFromZone() == Zone.BATTLEFIELD) { trigger(game, this.controllerId); + return true; + } } + return false; } @Override diff --git a/Mage/src/mage/abilities/common/OnEventTriggeredAbility.java b/Mage/src/mage/abilities/common/OnEventTriggeredAbility.java index e2687d95ef..9246c8109a 100644 --- a/Mage/src/mage/abilities/common/OnEventTriggeredAbility.java +++ b/Mage/src/mage/abilities/common/OnEventTriggeredAbility.java @@ -59,12 +59,14 @@ public class OnEventTriggeredAbility extends TriggeredAbilityImpl { } @Override - public void checkTrigger(GameEvent event, Game game) { + public boolean checkTrigger(GameEvent event, Game game) { if (event.getType() == eventType) { if (allPlayers || event.getPlayerId().equals(this.controllerId) ) { trigger(game, this.controllerId); + return true; } } + return false; } @Override diff --git a/Mage/src/mage/abilities/common/PutIntoGraveFromBattlefieldTriggeredAbility.java b/Mage/src/mage/abilities/common/PutIntoGraveFromBattlefieldTriggeredAbility.java index 7b12e5e0f4..20002471f3 100644 --- a/Mage/src/mage/abilities/common/PutIntoGraveFromBattlefieldTriggeredAbility.java +++ b/Mage/src/mage/abilities/common/PutIntoGraveFromBattlefieldTriggeredAbility.java @@ -47,12 +47,15 @@ public class PutIntoGraveFromBattlefieldTriggeredAbility extends TriggeredAbilit } @Override - public void checkTrigger(GameEvent event, Game game) { + public boolean checkTrigger(GameEvent event, Game game) { if (event.getType() == EventType.ZONE_CHANGE && event.getTargetId().equals(this.getSourceId()) ) { ZoneChangeEvent zEvent = (ZoneChangeEvent)event; - if (zEvent.getFromZone() == Zone.BATTLEFIELD && zEvent.getToZone() == Zone.GRAVEYARD) + if (zEvent.getFromZone() == Zone.BATTLEFIELD && zEvent.getToZone() == Zone.GRAVEYARD) { trigger(game, event.getPlayerId()); + return true; + } } + return false; } @Override diff --git a/Mage/src/mage/abilities/common/SimpleTriggeredAbility.java b/Mage/src/mage/abilities/common/SimpleTriggeredAbility.java index bb722456b9..b39b3fdc62 100644 --- a/Mage/src/mage/abilities/common/SimpleTriggeredAbility.java +++ b/Mage/src/mage/abilities/common/SimpleTriggeredAbility.java @@ -49,9 +49,11 @@ public class SimpleTriggeredAbility extends TriggeredAbilityImpl { } @Override - public void checkTrigger(GameEvent event, Game game) { + public boolean checkTrigger(GameEvent event, Game game) { if (event.getType() == eventType) { trigger(game, event.getPlayerId()); + return true; } + return false; } } diff --git a/Mage/src/mage/abilities/keyword/CascadeAbility.java b/Mage/src/mage/abilities/keyword/CascadeAbility.java index a906c4fec4..3cbc6da51f 100644 --- a/Mage/src/mage/abilities/keyword/CascadeAbility.java +++ b/Mage/src/mage/abilities/keyword/CascadeAbility.java @@ -52,10 +52,12 @@ public class CascadeAbility extends TriggeredAbilityImpl { } @Override - public void checkTrigger(GameEvent event, Game game) { + public boolean checkTrigger(GameEvent event, Game game) { if (event.getType() == EventType.SPELL_CAST && event.getTargetId().equals(this.getSourceId()) ) { trigger(game, event.getPlayerId()); + return true; } + return false; } @Override diff --git a/Mage/src/mage/abilities/keyword/ExaltedAbility.java b/Mage/src/mage/abilities/keyword/ExaltedAbility.java index 11c61b9a03..8d2c4614d0 100644 --- a/Mage/src/mage/abilities/keyword/ExaltedAbility.java +++ b/Mage/src/mage/abilities/keyword/ExaltedAbility.java @@ -48,14 +48,16 @@ public class ExaltedAbility extends TriggeredAbilityImpl { } @Override - public void checkTrigger(GameEvent event, Game game) { + public boolean checkTrigger(GameEvent event, Game game) { if (event.getType() == EventType.DECLARED_ATTACKERS && game.getActivePlayerId().equals(this.controllerId) ) { if (game.getCombat().attacksAlone()) { this.targets.add(new TargetCreaturePermanent()); this.targets.get(0).getTargets().add(game.getCombat().getAttackers().get(0)); trigger(game, event.getPlayerId()); + return true; } } + return false; } @Override diff --git a/Mage/src/mage/game/Game.java b/Mage/src/mage/game/Game.java index eeb30c4af1..e48f34218f 100644 --- a/Mage/src/mage/game/Game.java +++ b/Mage/src/mage/game/Game.java @@ -92,6 +92,7 @@ public interface Game extends MageItem, Serializable { public void fireSelectTargetEvent(UUID playerId, String message, boolean required); public void fireSelectTargetEvent(UUID playerId, String message, Cards cards, boolean required); public void fireSelectTargetEvent(UUID playerId, String message, TriggeredAbilities abilities, boolean required); + public void fireRevealCardsEvent(String message, Cards cards); public void fireSelectEvent(UUID playerId, String message); public void firePriorityEvent(UUID playerId); public void firePlayManaEvent(UUID playerId, String message); diff --git a/Mage/src/mage/game/GameImpl.java b/Mage/src/mage/game/GameImpl.java index 263ab6a80b..2ec41a247d 100644 --- a/Mage/src/mage/game/GameImpl.java +++ b/Mage/src/mage/game/GameImpl.java @@ -708,6 +708,11 @@ public abstract class GameImpl implements Game, Serializable { playerQueryEventSource.target(playerId, message, abilities, required); } + @Override + public void fireRevealCardsEvent(String message, Cards cards) { + tableEventSource.fireTableEvent(EventType.REVEAL, message, cards, this); + } + @Override public void fireGetAmountEvent(UUID playerId, String message, int min, int max) { playerQueryEventSource.amount(playerId, message, min, max); diff --git a/Mage/src/mage/game/GameState.java b/Mage/src/mage/game/GameState.java index 20a07c9ab9..c1a9c2f628 100644 --- a/Mage/src/mage/game/GameState.java +++ b/Mage/src/mage/game/GameState.java @@ -38,6 +38,9 @@ import java.util.List; import java.util.UUID; import mage.Constants.Zone; import mage.MageObject; +import mage.abilities.DelayedTriggeredAbilities; +import mage.abilities.DelayedTriggeredAbility; +import mage.abilities.SpecialActions; import mage.abilities.TriggeredAbilities; import mage.abilities.effects.ContinuousEffect; import mage.abilities.effects.ContinuousEffects; @@ -49,7 +52,6 @@ import mage.game.turn.TurnMods; import mage.players.Player; import mage.players.PlayerList; import mage.players.Players; -import mage.util.Copier; import mage.watchers.Watchers; /** @@ -64,7 +66,6 @@ import mage.watchers.Watchers; */ public class GameState implements Serializable { -// private static final transient Copier copier = new Copier(); private Players players = new Players(); private UUID activePlayerId; private UUID priorityPlayerId; @@ -77,6 +78,8 @@ public class GameState implements Serializable { private List messages = new ArrayList(); private ContinuousEffects effects = new ContinuousEffects(); private TriggeredAbilities triggers = new TriggeredAbilities(); + private DelayedTriggeredAbilities delayed = new DelayedTriggeredAbilities(); + private SpecialActions specialActions = new SpecialActions(); private Combat combat = new Combat(); private TurnMods turnMods = new TurnMods(); private Watchers watchers = new Watchers(); @@ -149,6 +152,10 @@ public class GameState implements Serializable { return this.watchers; } + public SpecialActions getSpecialActions() { + return this.specialActions; + } + public void endGame() { this.gameOver = true; } @@ -254,6 +261,7 @@ public class GameState implements Serializable { } battlefield.checkTriggers(event, game); stack.checkTriggers(event, game); + delayed.checkTriggers(event, game); exile.checkTriggers(event, game); watchers.watch(event, game); } @@ -267,6 +275,19 @@ public class GameState implements Serializable { this.triggers.add(ability); } + public void addDelayedTriggeredAbility(DelayedTriggeredAbility ability) { + this.delayed.add(ability); + } + + public void removeDelayedTriggeredAbility(UUID abilityId) { + for (DelayedTriggeredAbility ability: delayed) { + if (ability.getId().equals(abilityId)) { + delayed.remove(ability); + break; + } + } + } + public TriggeredAbilities getTriggered() { return this.triggers; } diff --git a/Mage/src/mage/game/events/PlayerQueryEventSource.java b/Mage/src/mage/game/events/PlayerQueryEventSource.java index 1b07b22031..e40293f766 100644 --- a/Mage/src/mage/game/events/PlayerQueryEventSource.java +++ b/Mage/src/mage/game/events/PlayerQueryEventSource.java @@ -30,7 +30,6 @@ package mage.game.events; import java.io.Serializable; import java.util.Collection; -import java.util.List; import java.util.UUID; import mage.abilities.ActivatedAbility; import mage.abilities.TriggeredAbilities; diff --git a/Mage/src/mage/game/events/TableEvent.java b/Mage/src/mage/game/events/TableEvent.java index d1e13cba75..4422f6188f 100644 --- a/Mage/src/mage/game/events/TableEvent.java +++ b/Mage/src/mage/game/events/TableEvent.java @@ -30,6 +30,7 @@ package mage.game.events; import java.io.Serializable; import java.util.EventObject; +import mage.cards.Cards; import mage.game.Game; /** @@ -39,17 +40,19 @@ import mage.game.Game; public class TableEvent extends EventObject implements ExternalEvent, Serializable { public enum EventType { - UPDATE, INFO + UPDATE, INFO, REVEAL } private Game game; private EventType eventType; private String message; + private Cards cards; - public TableEvent(EventType eventType, String message, Game game) { + public TableEvent(EventType eventType, String message, Cards cards, Game game) { super(game); this.game = game; this.message = message; + this.cards = cards; this.eventType = eventType; } @@ -65,4 +68,8 @@ public class TableEvent extends EventObject implements ExternalEvent, Serializab return message; } + public Cards getCards() { + return cards; + } + } diff --git a/Mage/src/mage/game/events/TableEventSource.java b/Mage/src/mage/game/events/TableEventSource.java index fc25eb500b..410df526ca 100644 --- a/Mage/src/mage/game/events/TableEventSource.java +++ b/Mage/src/mage/game/events/TableEventSource.java @@ -29,6 +29,7 @@ package mage.game.events; import java.io.Serializable; +import mage.cards.Cards; import mage.game.Game; /** @@ -39,11 +40,16 @@ public class TableEventSource implements EventSource, Serializable { protected final EventDispatcher dispatcher = new EventDispatcher() {}; + @Override public void addListener(Listener listener) { dispatcher.addListener(listener); } public void fireTableEvent(TableEvent.EventType eventType, String message, Game game) { - dispatcher.fireEvent(new TableEvent(eventType, message, game)); + dispatcher.fireEvent(new TableEvent(eventType, message, null, game)); + } + + public void fireTableEvent(TableEvent.EventType eventType, String message, Cards cards, Game game) { + dispatcher.fireEvent(new TableEvent(eventType, message, cards, game)); } } diff --git a/Mage/src/mage/game/permanent/PermanentCard.java b/Mage/src/mage/game/permanent/PermanentCard.java index 1c6b4915e3..1789449ab7 100644 --- a/Mage/src/mage/game/permanent/PermanentCard.java +++ b/Mage/src/mage/game/permanent/PermanentCard.java @@ -66,7 +66,6 @@ public class PermanentCard extends PermanentImpl { this.cardType = copy.getCardType(); this.color = copy.getColor(); this.manaCost = copy.getManaCost(); -// this.loyalty = copy.getLoyalty(); this.power = copy.getPower(); this.toughness = copy.getToughness(); this.subtype = copy.getSubtype(); diff --git a/Mage/src/mage/players/PlayerImpl.java b/Mage/src/mage/players/PlayerImpl.java index 659813673d..9c2425f8e9 100644 --- a/Mage/src/mage/players/PlayerImpl.java +++ b/Mage/src/mage/players/PlayerImpl.java @@ -40,6 +40,7 @@ import mage.abilities.Abilities; import mage.abilities.AbilitiesImpl; import mage.abilities.ActivatedAbility; import mage.abilities.PlayLandAbility; +import mage.abilities.SpecialAction; import mage.abilities.SpellAbility; import mage.abilities.TriggeredAbility; import mage.abilities.keyword.KickerAbility; @@ -65,12 +66,10 @@ import mage.game.stack.StackAbility; import mage.target.common.TargetCardInLibrary; import mage.target.common.TargetDiscard; import mage.util.Copier; +import mage.watchers.Watcher; public abstract class PlayerImpl implements Player, Serializable { -// private static final transient Copier copier = new Copier(); - private static final long serialVersionUID = 1L; - protected UUID playerId; protected String name; protected boolean human; @@ -110,7 +109,10 @@ public abstract class PlayerImpl implements Player, Serializable { this.passedTurn = false; library.addAll(deck.getCards()); for (Card card: deck.getCards().values()) { - game.getState().getWatchers().addAll(card.getWatchers()); + for (Watcher watcher: card.getWatchers()) { + watcher.setControllerId(playerId); + game.getState().getWatchers().add(watcher); + } } } @@ -298,8 +300,8 @@ public abstract class PlayerImpl implements Player, Serializable { game.removeLastBookmark(); return true; } + game.restoreState(); } - game.restoreState(); return false; } @@ -316,8 +318,8 @@ public abstract class PlayerImpl implements Player, Serializable { game.removeLastBookmark(); return true; } + game.restoreState(); } - game.restoreState(); return false; } @@ -343,8 +345,25 @@ public abstract class PlayerImpl implements Player, Serializable { game.removeLastBookmark(); return true; } + game.restoreState(); + } + return false; + } + + protected boolean specialAction(SpecialAction action, Game game) { + //20091005 - 114 + if (!game.replaceEvent(GameEvent.getEvent(GameEvent.EventType.ACTIVATE_ABILITY, action.getId(), playerId))) { + game.bookmarkState(); + if (action.activate(game, false)) { + game.fireEvent(GameEvent.getEvent(GameEvent.EventType.ACTIVATED_ABILITY, action.getId(), playerId)); + game.fireInformEvent(name + action.getActivatedMessage(game)); + if (action.resolve(game)) { + game.removeLastBookmark(); + return true; + } + } + game.restoreState(); } - game.restoreState(); return false; } @@ -357,6 +376,9 @@ public abstract class PlayerImpl implements Player, Serializable { if (ability instanceof PlayLandAbility) { result = playLand(hand.get(ability.getSourceId()), game); } + else if (ability instanceof SpecialAction) { + result = specialAction((SpecialAction)ability.copy(), game); + } else if (ability instanceof ManaAbility) { result = playManaAbility((ManaAbility)ability.copy(), game); } @@ -411,7 +433,7 @@ public abstract class PlayerImpl implements Player, Serializable { @Override public void revealCards(Cards cards, Game game) { - //TODO: implement this + game.fireRevealCardsEvent(this.name + " revealed", cards); } @Override diff --git a/Mage/src/mage/target/common/TargetSacrificePermanent.java b/Mage/src/mage/target/common/TargetSacrificePermanent.java new file mode 100644 index 0000000000..fd52240a44 --- /dev/null +++ b/Mage/src/mage/target/common/TargetSacrificePermanent.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.target.common; + +import mage.Constants.TargetController; +import mage.filter.FilterPermanent; +import mage.target.TargetPermanent; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class TargetSacrificePermanent extends TargetPermanent { + + public TargetSacrificePermanent() { + this(1, 1, new FilterPermanent()); + } + + public TargetSacrificePermanent(int numTargets) { + this(numTargets, numTargets, new FilterPermanent()); + } + + public TargetSacrificePermanent(int minNumTargets, int maxNumTargets, FilterPermanent filter) { + super(1, 1, filter, TargetController.YOU); + this.targetName = filter.getMessage(); + } + +} diff --git a/Mage/src/mage/util/CopierObjectInputStream.java b/Mage/src/mage/util/CopierObjectInputStream.java index 5482ba31a1..0948247496 100644 --- a/Mage/src/mage/util/CopierObjectInputStream.java +++ b/Mage/src/mage/util/CopierObjectInputStream.java @@ -33,7 +33,6 @@ import java.io.InputStream; import java.io.ObjectInputStream; import java.io.ObjectStreamClass; import java.io.StreamCorruptedException; -import java.net.URLClassLoader; /** * diff --git a/Mage/src/mage/watchers/Watcher.java b/Mage/src/mage/watchers/Watcher.java index 6f34a55e42..b1128e9038 100644 --- a/Mage/src/mage/watchers/Watcher.java +++ b/Mage/src/mage/watchers/Watcher.java @@ -40,6 +40,7 @@ import mage.game.events.GameEvent; public interface Watcher extends Serializable { public UUID getControllerId(); + public void setControllerId(UUID controllerId); public String getKey(); public void watch(GameEvent event, Game game); public boolean conditionMet(); diff --git a/Mage/src/mage/watchers/WatcherImpl.java b/Mage/src/mage/watchers/WatcherImpl.java index 33a4aa05ad..95f284328b 100644 --- a/Mage/src/mage/watchers/WatcherImpl.java +++ b/Mage/src/mage/watchers/WatcherImpl.java @@ -42,8 +42,7 @@ public abstract class WatcherImpl implements Watcher { protected String key; protected boolean condition = false; - public WatcherImpl(UUID controllerId, String key) { - this.controllerId = controllerId; + public WatcherImpl(String key) { this.key = key; } @@ -52,6 +51,11 @@ public abstract class WatcherImpl implements Watcher { return controllerId; } + @Override + public void setControllerId(UUID controllerId) { + this.controllerId = controllerId; + } + @Override public String getKey() { return key;