This commit is contained in:
BetaSteward 2010-05-02 14:50:58 +00:00
parent 99728d7f81
commit b1958d9761
28 changed files with 383 additions and 53 deletions

View file

@ -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<DelayedTriggeredAbility> {
public void checkTriggers(GameEvent event, Game game) {
Iterator<DelayedTriggeredAbility> 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<TriggeredAbility> 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;
// }
}

View file

@ -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);
}
}

View file

@ -39,7 +39,7 @@ import mage.game.Game;
public class PlayLandAbility extends ActivatedAbilityImpl { public class PlayLandAbility extends ActivatedAbilityImpl {
public PlayLandAbility() { public PlayLandAbility() {
super(Zone.HAND, null); super(Zone.HAND);
this.name = "Play"; this.name = "Play";
} }

View file

@ -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);
}
}

View file

@ -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<SpecialAction> {
public Map<UUID, SpecialAction> getControlledBy(UUID controllerId) {
HashMap<UUID, SpecialAction> controlledBy = new HashMap<UUID, SpecialAction>();
for (SpecialAction action: this) {
if (action.getControllerId().equals(controllerId))
controlledBy.put(action.id, action);
}
return controlledBy;
}
}

View file

@ -29,10 +29,7 @@
package mage.abilities; package mage.abilities;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator;
import java.util.UUID; 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<TriggeredAbility> { public class TriggeredAbilities extends ArrayList<TriggeredAbility> {
public void handleEvent(GameEvent event, Game game) {
for(TriggeredAbility ability: this) {
ability.checkTrigger(event, game);
}
}
// public boolean check(Game game) {
// boolean played = false;
// Iterator<TriggeredAbility> 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) { public TriggeredAbilities getControlledBy(UUID controllerId) {
TriggeredAbilities controlledBy = new TriggeredAbilities(); TriggeredAbilities controlledBy = new TriggeredAbilities();
for (TriggeredAbility ability: this) { for (TriggeredAbility ability: this) {

View file

@ -39,7 +39,7 @@ import mage.game.events.GameEvent;
public interface TriggeredAbility extends Ability { public interface TriggeredAbility extends Ability {
public void trigger(Game game, UUID controllerId); 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); public boolean checkIfClause(Game game);
} }

View file

@ -46,10 +46,12 @@ public class AttacksTriggeredAbility extends TriggeredAbilityImpl {
} }
@Override @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()) ) { if (event.getType() == EventType.ATTACKER_DECLARED && event.getSourceId().equals(this.getSourceId()) ) {
trigger(game, this.controllerId); trigger(game, this.controllerId);
return true;
} }
return false;
} }
@Override @Override

View file

@ -47,13 +47,16 @@ public class EntersBattlefieldTriggeredAbility extends TriggeredAbilityImpl {
} }
@Override @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()) ) { if (event.getType() == EventType.ZONE_CHANGE && event.getTargetId().equals(this.getSourceId()) ) {
ZoneChangeEvent zEvent = (ZoneChangeEvent)event; ZoneChangeEvent zEvent = (ZoneChangeEvent)event;
if (zEvent.getToZone() == Zone.BATTLEFIELD) if (zEvent.getToZone() == Zone.BATTLEFIELD) {
trigger(game, this.controllerId); trigger(game, this.controllerId);
return true;
} }
} }
return false;
}
@Override @Override
public String getRule() { public String getRule() {

View file

@ -49,13 +49,16 @@ public class LandfallAbility extends TriggeredAbilityImpl {
} }
@Override @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) { if (event.getType() == EventType.ZONE_CHANGE && ((ZoneChangeEvent)event).getToZone() == Zone.BATTLEFIELD) {
Permanent permanent = game.getPermanent(event.getTargetId()); 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); trigger(game, this.controllerId);
return true;
} }
} }
return false;
}
@Override @Override
public String getRule() { public String getRule() {

View file

@ -47,13 +47,16 @@ public class LeavesBattlefieldTriggeredAbility extends TriggeredAbilityImpl {
} }
@Override @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()) ) { if (event.getType() == EventType.ZONE_CHANGE && event.getTargetId().equals(this.getSourceId()) ) {
ZoneChangeEvent zEvent = (ZoneChangeEvent)event; ZoneChangeEvent zEvent = (ZoneChangeEvent)event;
if (zEvent.getFromZone() == Zone.BATTLEFIELD) if (zEvent.getFromZone() == Zone.BATTLEFIELD) {
trigger(game, this.controllerId); trigger(game, this.controllerId);
return true;
} }
} }
return false;
}
@Override @Override
public String getRule() { public String getRule() {

View file

@ -59,12 +59,14 @@ public class OnEventTriggeredAbility extends TriggeredAbilityImpl {
} }
@Override @Override
public void checkTrigger(GameEvent event, Game game) { public boolean checkTrigger(GameEvent event, Game game) {
if (event.getType() == eventType) { if (event.getType() == eventType) {
if (allPlayers || event.getPlayerId().equals(this.controllerId) ) { if (allPlayers || event.getPlayerId().equals(this.controllerId) ) {
trigger(game, this.controllerId); trigger(game, this.controllerId);
return true;
} }
} }
return false;
} }
@Override @Override

View file

@ -47,13 +47,16 @@ public class PutIntoGraveFromBattlefieldTriggeredAbility extends TriggeredAbilit
} }
@Override @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()) ) { if (event.getType() == EventType.ZONE_CHANGE && event.getTargetId().equals(this.getSourceId()) ) {
ZoneChangeEvent zEvent = (ZoneChangeEvent)event; 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()); trigger(game, event.getPlayerId());
return true;
} }
} }
return false;
}
@Override @Override
public String getRule() { public String getRule() {

View file

@ -49,9 +49,11 @@ public class SimpleTriggeredAbility extends TriggeredAbilityImpl {
} }
@Override @Override
public void checkTrigger(GameEvent event, Game game) { public boolean checkTrigger(GameEvent event, Game game) {
if (event.getType() == eventType) { if (event.getType() == eventType) {
trigger(game, event.getPlayerId()); trigger(game, event.getPlayerId());
return true;
} }
return false;
} }
} }

View file

@ -52,10 +52,12 @@ public class CascadeAbility extends TriggeredAbilityImpl {
} }
@Override @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()) ) { if (event.getType() == EventType.SPELL_CAST && event.getTargetId().equals(this.getSourceId()) ) {
trigger(game, event.getPlayerId()); trigger(game, event.getPlayerId());
return true;
} }
return false;
} }
@Override @Override

View file

@ -48,14 +48,16 @@ public class ExaltedAbility extends TriggeredAbilityImpl {
} }
@Override @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 (event.getType() == EventType.DECLARED_ATTACKERS && game.getActivePlayerId().equals(this.controllerId) ) {
if (game.getCombat().attacksAlone()) { if (game.getCombat().attacksAlone()) {
this.targets.add(new TargetCreaturePermanent()); this.targets.add(new TargetCreaturePermanent());
this.targets.get(0).getTargets().add(game.getCombat().getAttackers().get(0)); this.targets.get(0).getTargets().add(game.getCombat().getAttackers().get(0));
trigger(game, event.getPlayerId()); trigger(game, event.getPlayerId());
return true;
} }
} }
return false;
} }
@Override @Override

View file

@ -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, boolean required);
public void fireSelectTargetEvent(UUID playerId, String message, Cards cards, 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 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 fireSelectEvent(UUID playerId, String message);
public void firePriorityEvent(UUID playerId); public void firePriorityEvent(UUID playerId);
public void firePlayManaEvent(UUID playerId, String message); public void firePlayManaEvent(UUID playerId, String message);

View file

@ -708,6 +708,11 @@ public abstract class GameImpl implements Game, Serializable {
playerQueryEventSource.target(playerId, message, abilities, required); playerQueryEventSource.target(playerId, message, abilities, required);
} }
@Override
public void fireRevealCardsEvent(String message, Cards cards) {
tableEventSource.fireTableEvent(EventType.REVEAL, message, cards, this);
}
@Override @Override
public void fireGetAmountEvent(UUID playerId, String message, int min, int max) { public void fireGetAmountEvent(UUID playerId, String message, int min, int max) {
playerQueryEventSource.amount(playerId, message, min, max); playerQueryEventSource.amount(playerId, message, min, max);

View file

@ -38,6 +38,9 @@ import java.util.List;
import java.util.UUID; import java.util.UUID;
import mage.Constants.Zone; import mage.Constants.Zone;
import mage.MageObject; import mage.MageObject;
import mage.abilities.DelayedTriggeredAbilities;
import mage.abilities.DelayedTriggeredAbility;
import mage.abilities.SpecialActions;
import mage.abilities.TriggeredAbilities; import mage.abilities.TriggeredAbilities;
import mage.abilities.effects.ContinuousEffect; import mage.abilities.effects.ContinuousEffect;
import mage.abilities.effects.ContinuousEffects; import mage.abilities.effects.ContinuousEffects;
@ -49,7 +52,6 @@ import mage.game.turn.TurnMods;
import mage.players.Player; import mage.players.Player;
import mage.players.PlayerList; import mage.players.PlayerList;
import mage.players.Players; import mage.players.Players;
import mage.util.Copier;
import mage.watchers.Watchers; import mage.watchers.Watchers;
/** /**
@ -64,7 +66,6 @@ import mage.watchers.Watchers;
*/ */
public class GameState implements Serializable { public class GameState implements Serializable {
// private static final transient Copier<GameState> copier = new Copier<GameState>();
private Players players = new Players(); private Players players = new Players();
private UUID activePlayerId; private UUID activePlayerId;
private UUID priorityPlayerId; private UUID priorityPlayerId;
@ -77,6 +78,8 @@ public class GameState implements Serializable {
private List<String> messages = new ArrayList<String>(); private List<String> messages = new ArrayList<String>();
private ContinuousEffects effects = new ContinuousEffects(); private ContinuousEffects effects = new ContinuousEffects();
private TriggeredAbilities triggers = new TriggeredAbilities(); private TriggeredAbilities triggers = new TriggeredAbilities();
private DelayedTriggeredAbilities delayed = new DelayedTriggeredAbilities();
private SpecialActions specialActions = new SpecialActions();
private Combat combat = new Combat(); private Combat combat = new Combat();
private TurnMods turnMods = new TurnMods(); private TurnMods turnMods = new TurnMods();
private Watchers watchers = new Watchers(); private Watchers watchers = new Watchers();
@ -149,6 +152,10 @@ public class GameState implements Serializable {
return this.watchers; return this.watchers;
} }
public SpecialActions getSpecialActions() {
return this.specialActions;
}
public void endGame() { public void endGame() {
this.gameOver = true; this.gameOver = true;
} }
@ -254,6 +261,7 @@ public class GameState implements Serializable {
} }
battlefield.checkTriggers(event, game); battlefield.checkTriggers(event, game);
stack.checkTriggers(event, game); stack.checkTriggers(event, game);
delayed.checkTriggers(event, game);
exile.checkTriggers(event, game); exile.checkTriggers(event, game);
watchers.watch(event, game); watchers.watch(event, game);
} }
@ -267,6 +275,19 @@ public class GameState implements Serializable {
this.triggers.add(ability); 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() { public TriggeredAbilities getTriggered() {
return this.triggers; return this.triggers;
} }

View file

@ -30,7 +30,6 @@ package mage.game.events;
import java.io.Serializable; import java.io.Serializable;
import java.util.Collection; import java.util.Collection;
import java.util.List;
import java.util.UUID; import java.util.UUID;
import mage.abilities.ActivatedAbility; import mage.abilities.ActivatedAbility;
import mage.abilities.TriggeredAbilities; import mage.abilities.TriggeredAbilities;

View file

@ -30,6 +30,7 @@ package mage.game.events;
import java.io.Serializable; import java.io.Serializable;
import java.util.EventObject; import java.util.EventObject;
import mage.cards.Cards;
import mage.game.Game; import mage.game.Game;
/** /**
@ -39,17 +40,19 @@ import mage.game.Game;
public class TableEvent extends EventObject implements ExternalEvent, Serializable { public class TableEvent extends EventObject implements ExternalEvent, Serializable {
public enum EventType { public enum EventType {
UPDATE, INFO UPDATE, INFO, REVEAL
} }
private Game game; private Game game;
private EventType eventType; private EventType eventType;
private String message; 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); super(game);
this.game = game; this.game = game;
this.message = message; this.message = message;
this.cards = cards;
this.eventType = eventType; this.eventType = eventType;
} }
@ -65,4 +68,8 @@ public class TableEvent extends EventObject implements ExternalEvent, Serializab
return message; return message;
} }
public Cards getCards() {
return cards;
}
} }

View file

@ -29,6 +29,7 @@
package mage.game.events; package mage.game.events;
import java.io.Serializable; import java.io.Serializable;
import mage.cards.Cards;
import mage.game.Game; import mage.game.Game;
/** /**
@ -39,11 +40,16 @@ public class TableEventSource implements EventSource<TableEvent>, Serializable {
protected final EventDispatcher<TableEvent> dispatcher = new EventDispatcher<TableEvent>() {}; protected final EventDispatcher<TableEvent> dispatcher = new EventDispatcher<TableEvent>() {};
@Override
public void addListener(Listener<TableEvent> listener) { public void addListener(Listener<TableEvent> listener) {
dispatcher.addListener(listener); dispatcher.addListener(listener);
} }
public void fireTableEvent(TableEvent.EventType eventType, String message, Game game) { 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));
} }
} }

View file

@ -66,7 +66,6 @@ public class PermanentCard extends PermanentImpl {
this.cardType = copy.getCardType(); this.cardType = copy.getCardType();
this.color = copy.getColor(); this.color = copy.getColor();
this.manaCost = copy.getManaCost(); this.manaCost = copy.getManaCost();
// this.loyalty = copy.getLoyalty();
this.power = copy.getPower(); this.power = copy.getPower();
this.toughness = copy.getToughness(); this.toughness = copy.getToughness();
this.subtype = copy.getSubtype(); this.subtype = copy.getSubtype();

View file

@ -40,6 +40,7 @@ import mage.abilities.Abilities;
import mage.abilities.AbilitiesImpl; import mage.abilities.AbilitiesImpl;
import mage.abilities.ActivatedAbility; import mage.abilities.ActivatedAbility;
import mage.abilities.PlayLandAbility; import mage.abilities.PlayLandAbility;
import mage.abilities.SpecialAction;
import mage.abilities.SpellAbility; import mage.abilities.SpellAbility;
import mage.abilities.TriggeredAbility; import mage.abilities.TriggeredAbility;
import mage.abilities.keyword.KickerAbility; import mage.abilities.keyword.KickerAbility;
@ -65,12 +66,10 @@ import mage.game.stack.StackAbility;
import mage.target.common.TargetCardInLibrary; import mage.target.common.TargetCardInLibrary;
import mage.target.common.TargetDiscard; import mage.target.common.TargetDiscard;
import mage.util.Copier; import mage.util.Copier;
import mage.watchers.Watcher;
public abstract class PlayerImpl implements Player, Serializable { public abstract class PlayerImpl implements Player, Serializable {
// private static final transient Copier<Player> copier = new Copier<Player>();
private static final long serialVersionUID = 1L;
protected UUID playerId; protected UUID playerId;
protected String name; protected String name;
protected boolean human; protected boolean human;
@ -110,7 +109,10 @@ public abstract class PlayerImpl implements Player, Serializable {
this.passedTurn = false; this.passedTurn = false;
library.addAll(deck.getCards()); library.addAll(deck.getCards());
for (Card card: deck.getCards().values()) { 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(); game.removeLastBookmark();
return true; return true;
} }
}
game.restoreState(); game.restoreState();
}
return false; return false;
} }
@ -316,8 +318,8 @@ public abstract class PlayerImpl implements Player, Serializable {
game.removeLastBookmark(); game.removeLastBookmark();
return true; return true;
} }
}
game.restoreState(); game.restoreState();
}
return false; return false;
} }
@ -343,8 +345,25 @@ public abstract class PlayerImpl implements Player, Serializable {
game.removeLastBookmark(); game.removeLastBookmark();
return true; 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; return false;
} }
@ -357,6 +376,9 @@ public abstract class PlayerImpl implements Player, Serializable {
if (ability instanceof PlayLandAbility) { if (ability instanceof PlayLandAbility) {
result = playLand(hand.get(ability.getSourceId()), game); result = playLand(hand.get(ability.getSourceId()), game);
} }
else if (ability instanceof SpecialAction) {
result = specialAction((SpecialAction)ability.copy(), game);
}
else if (ability instanceof ManaAbility) { else if (ability instanceof ManaAbility) {
result = playManaAbility((ManaAbility)ability.copy(), game); result = playManaAbility((ManaAbility)ability.copy(), game);
} }
@ -411,7 +433,7 @@ public abstract class PlayerImpl implements Player, Serializable {
@Override @Override
public void revealCards(Cards cards, Game game) { public void revealCards(Cards cards, Game game) {
//TODO: implement this game.fireRevealCardsEvent(this.name + " revealed", cards);
} }
@Override @Override

View file

@ -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();
}
}

View file

@ -33,7 +33,6 @@ import java.io.InputStream;
import java.io.ObjectInputStream; import java.io.ObjectInputStream;
import java.io.ObjectStreamClass; import java.io.ObjectStreamClass;
import java.io.StreamCorruptedException; import java.io.StreamCorruptedException;
import java.net.URLClassLoader;
/** /**
* *

View file

@ -40,6 +40,7 @@ import mage.game.events.GameEvent;
public interface Watcher extends Serializable { public interface Watcher extends Serializable {
public UUID getControllerId(); public UUID getControllerId();
public void setControllerId(UUID controllerId);
public String getKey(); public String getKey();
public void watch(GameEvent event, Game game); public void watch(GameEvent event, Game game);
public boolean conditionMet(); public boolean conditionMet();

View file

@ -42,8 +42,7 @@ public abstract class WatcherImpl implements Watcher {
protected String key; protected String key;
protected boolean condition = false; protected boolean condition = false;
public WatcherImpl(UUID controllerId, String key) { public WatcherImpl(String key) {
this.controllerId = controllerId;
this.key = key; this.key = key;
} }
@ -52,6 +51,11 @@ public abstract class WatcherImpl implements Watcher {
return controllerId; return controllerId;
} }
@Override
public void setControllerId(UUID controllerId) {
this.controllerId = controllerId;
}
@Override @Override
public String getKey() { public String getKey() {
return key; return key;