Reworked some trap cards using old AlternateCosts class.

This commit is contained in:
LevelX2 2016-02-27 23:44:59 +01:00
parent f87c5bbbec
commit 0f1839af56
38 changed files with 547 additions and 820 deletions

View file

@ -45,7 +45,7 @@ public class NoSpellsWereCastLastTurnCondition implements Condition {
@Override
public boolean apply(Game game, Ability source) {
CastSpellLastTurnWatcher watcher = (CastSpellLastTurnWatcher) game.getState().getWatchers().get("CastSpellLastTurnWatcher");
CastSpellLastTurnWatcher watcher = (CastSpellLastTurnWatcher) game.getState().getWatchers().get(CastSpellLastTurnWatcher.class.getName());
// if any player cast spell, return false
for (Integer count : watcher.getAmountOfSpellsCastOnPrevTurn().values()) {
if (count > 0) {

View file

@ -45,7 +45,7 @@ public class TwoOrMoreSpellsWereCastLastTurnCondition implements Condition {
@Override
public boolean apply(Game game, Ability source) {
CastSpellLastTurnWatcher watcher = (CastSpellLastTurnWatcher) game.getState().getWatchers().get("CastSpellLastTurnWatcher");
CastSpellLastTurnWatcher watcher = (CastSpellLastTurnWatcher) game.getState().getWatchers().get(CastSpellLastTurnWatcher.class.getName());
// if any player cast more than two spells, return true
for (Integer count : watcher.getAmountOfSpellsCastOnPrevTurn().values()) {
if (count >= 2) {

View file

@ -120,7 +120,8 @@ public class AlternativeCostSourceAbility extends StaticAbility implements Alter
}
private AlternativeCost2 convertToAlternativeCost(Cost cost) {
return cost != null ? new AlternativeCost2Impl(null, cost.getText(), cost) : null;
//return cost != null ? new AlternativeCost2Impl(null, cost.getText(), cost) : null;
return cost != null ? new AlternativeCost2Impl(null, "", cost) : null;
}
@Override

View file

@ -38,6 +38,8 @@ import mage.constants.Outcome;
import mage.constants.Zone;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.game.stack.Spell;
import mage.game.stack.StackObject;
import mage.players.Player;
import mage.target.Target;
import mage.target.targetpointer.FirstTargetPointer;
@ -133,6 +135,11 @@ public class ExileTargetEffect extends OneShotEffect {
if (!currentZone.equals(Zone.EXILED) && (onlyFromZone == null || onlyFromZone.equals(currentZone))) {
toExile.add(card);
}
} else {
StackObject stackObject = game.getStack().getStackObject(targetId);
if (stackObject instanceof Spell && ((Spell) stackObject).getCard() != null) {
toExile.add(((Spell) stackObject).getCard());
}
}
}
}

View file

@ -25,7 +25,6 @@
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.abilities.effects.common.continuous;
import mage.abilities.Ability;
@ -43,14 +42,13 @@ import mage.watchers.common.CastSpellLastTurnWatcher;
*
* @author LevelX2
*/
public class CantCastMoreThanOneSpellEffect extends ContinuousRuleModifyingEffectImpl {
private final TargetController targetController;
public CantCastMoreThanOneSpellEffect(TargetController targetController) {
super(Duration.WhileOnBattlefield, Outcome.Detriment);
this.targetController = targetController;
this.targetController = targetController;
}
public CantCastMoreThanOneSpellEffect(final CantCastMoreThanOneSpellEffect effect) {
@ -95,22 +93,22 @@ public class CantCastMoreThanOneSpellEffect extends ContinuousRuleModifyingEffec
Permanent attachment = game.getPermanent(source.getSourceId());
if (attachment == null || !attachment.getAttachedTo().equals(event.getPlayerId())) {
return false;
}
}
}
CastSpellLastTurnWatcher watcher = (CastSpellLastTurnWatcher) game.getState().getWatchers().get("CastSpellLastTurnWatcher");
if (watcher != null && watcher.getAmountOfSpellsPlayerCastOnCurrentTurn(event.getPlayerId())> 0) {
CastSpellLastTurnWatcher watcher = (CastSpellLastTurnWatcher) game.getState().getWatchers().get(CastSpellLastTurnWatcher.class.getName());
if (watcher != null && watcher.getAmountOfSpellsPlayerCastOnCurrentTurn(event.getPlayerId()) > 0) {
return true;
}
return false;
}
@Override
public String getText(Mode mode) {
if (staticText != null && !staticText.isEmpty()) {
return staticText;
}
StringBuilder sb = new StringBuilder();
switch(targetController) {
switch (targetController) {
case YOU:
sb.append("You");
break;

View file

@ -25,7 +25,6 @@
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.abilities.effects.common.ruleModifying;
import mage.abilities.Ability;
@ -40,15 +39,15 @@ import mage.watchers.common.CastSpellLastTurnWatcher;
*
* @author LoneFox
*/
public class CastOnlyIfYouHaveCastAnotherSpellEffect extends ContinuousRuleModifyingEffectImpl {
public CastOnlyIfYouHaveCastAnotherSpellEffect() {
super(Duration.EndOfGame, Outcome.Detriment);
staticText = "Cast {this} only if you've cast another spell this turn";
super(Duration.EndOfGame, Outcome.Detriment);
staticText = "Cast {this} only if you've cast another spell this turn";
}
public CastOnlyIfYouHaveCastAnotherSpellEffect(final CastOnlyIfYouHaveCastAnotherSpellEffect effect) {
super(effect);
super(effect);
}
@Override
@ -58,22 +57,22 @@ public class CastOnlyIfYouHaveCastAnotherSpellEffect extends ContinuousRuleModif
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (event.getSourceId().equals(source.getSourceId())) {
CastSpellLastTurnWatcher watcher = (CastSpellLastTurnWatcher) game.getState().getWatchers().get("CastSpellLastTurnWatcher");
if (watcher != null && watcher.getAmountOfSpellsPlayerCastOnCurrentTurn(source.getControllerId()) == 0) {
return true;
}
}
return false;
if (event.getSourceId().equals(source.getSourceId())) {
CastSpellLastTurnWatcher watcher = (CastSpellLastTurnWatcher) game.getState().getWatchers().get(CastSpellLastTurnWatcher.class.getName());
if (watcher != null && watcher.getAmountOfSpellsPlayerCastOnCurrentTurn(source.getControllerId()) == 0) {
return true;
}
}
return false;
}
@Override
public boolean apply(Game game, Ability source) {
return true;
return true;
}
@Override
public CastOnlyIfYouHaveCastAnotherSpellEffect copy() {
return new CastOnlyIfYouHaveCastAnotherSpellEffect(this);
return new CastOnlyIfYouHaveCastAnotherSpellEffect(this);
}
}

View file

@ -100,7 +100,7 @@ class StormEffect extends OneShotEffect {
public boolean apply(Game game, Ability source) {
MageObjectReference spellRef = (MageObjectReference) this.getValue("StormSpellRef");
if (spellRef != null) {
CastSpellLastTurnWatcher watcher = (CastSpellLastTurnWatcher) game.getState().getWatchers().get("CastSpellLastTurnWatcher");
CastSpellLastTurnWatcher watcher = (CastSpellLastTurnWatcher) game.getState().getWatchers().get(CastSpellLastTurnWatcher.class.getName());
int stormCount = watcher.getSpellOrder(spellRef, game) - 1;
if (stormCount > 0) {
Spell spell = (Spell) this.getValue("StormSpell");

View file

@ -69,7 +69,7 @@ public class SurgeAbility extends SpellAbility {
@Override
public boolean canActivate(UUID playerId, Game game) {
// check if controller or teammate has already cast a spell this turn
CastSpellLastTurnWatcher watcher = (CastSpellLastTurnWatcher) game.getState().getWatchers().get("CastSpellLastTurnWatcher");
CastSpellLastTurnWatcher watcher = (CastSpellLastTurnWatcher) game.getState().getWatchers().get(CastSpellLastTurnWatcher.class.getName());
if (watcher != null) {
Player player = game.getPlayer(playerId);
if (player != null) {

View file

@ -1,16 +1,16 @@
/*
* 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
@ -20,12 +20,11 @@
* 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.watchers;
import java.io.Serializable;
@ -42,20 +41,19 @@ import mage.game.events.GameEvent;
*/
public abstract class Watcher implements Serializable {
protected String basicKey;
protected UUID controllerId;
protected UUID sourceId;
protected String key;
protected boolean condition;
protected WatcherScope scope;
public Watcher(String key, WatcherScope scope) {
this.key = key;
public Watcher(String basicKey, WatcherScope scope) {
this.basicKey = basicKey;
this.scope = scope;
}
public Watcher(final Watcher watcher) {
this.condition = watcher.condition;
this.key = watcher.key;
this.controllerId = watcher.controllerId;
this.sourceId = watcher.sourceId;
this.scope = watcher.scope;
@ -80,19 +78,19 @@ public abstract class Watcher implements Serializable {
public String getKey() {
switch (scope) {
case GAME:
return key;
return basicKey;
case PLAYER:
return controllerId + key;
return controllerId + basicKey;
case CARD:
return sourceId + key;
return sourceId + basicKey;
}
return key;
return basicKey;
}
public boolean conditionMet() {
return condition;
}
public void reset() {
condition = false;
}
@ -100,4 +98,5 @@ public abstract class Watcher implements Serializable {
public abstract void watch(GameEvent event, Game game);
public abstract Watcher copy();
}

View file

@ -50,7 +50,7 @@ public class CastSpellLastTurnWatcher extends Watcher {
private final List<MageObjectReference> spellsCastThisTurnInOrder = new ArrayList<>();
public CastSpellLastTurnWatcher() {
super("CastSpellLastTurnWatcher", WatcherScope.GAME);
super(CastSpellLastTurnWatcher.class.getName(), WatcherScope.GAME);
}
public CastSpellLastTurnWatcher(final CastSpellLastTurnWatcher watcher) {

View file

@ -0,0 +1,65 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package mage.watchers.common;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.UUID;
import mage.constants.WatcherScope;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.permanent.Permanent;
import mage.watchers.Watcher;
/**
*
* @author LevelX2
*/
public class PermanentsEnteredBattlefieldWatcher extends Watcher {
private final HashMap<UUID, List<Permanent>> enteringBattlefield = new HashMap<>();
public PermanentsEnteredBattlefieldWatcher() {
super(PermanentsEnteredBattlefieldWatcher.class.getName(), WatcherScope.GAME);
}
public PermanentsEnteredBattlefieldWatcher(final PermanentsEnteredBattlefieldWatcher watcher) {
super(watcher);
}
@Override
public PermanentsEnteredBattlefieldWatcher copy() {
return new PermanentsEnteredBattlefieldWatcher(this);
}
@Override
public void watch(GameEvent event, Game game) {
if (event.getType() == GameEvent.EventType.ENTERS_THE_BATTLEFIELD) {
Permanent perm = game.getPermanentEntering(event.getTargetId());
if (perm != null) {
List<Permanent> permanents;
if (!enteringBattlefield.containsKey(perm.getControllerId())) {
permanents = new ArrayList<>();
enteringBattlefield.put(perm.getControllerId(), permanents);
} else {
permanents = enteringBattlefield.get(perm.getControllerId());
}
permanents.add(perm.copy()); // copy needed because attributes like color could be changed later
}
}
}
@Override
public void reset() {
super.reset();
enteringBattlefield.clear();
}
public List<Permanent> getThisTurnEnteringPermanents(UUID playerId) {
return enteringBattlefield.get(playerId);
}
}

View file

@ -0,0 +1,74 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package mage.watchers.common;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.UUID;
import mage.MageObject;
import mage.constants.WatcherScope;
import mage.constants.Zone;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.events.GameEvent.EventType;
import mage.game.stack.Spell;
import mage.watchers.Watcher;
/**
*
* @author LevelX2
*/
public class SpellsCastWatcher extends Watcher {
private final HashMap<UUID, List<Spell>> spellsCast = new HashMap<>();
public SpellsCastWatcher() {
super(SpellsCastWatcher.class.getName(), WatcherScope.GAME);
}
public SpellsCastWatcher(final SpellsCastWatcher watcher) {
super(watcher);
}
@Override
public SpellsCastWatcher copy() {
return new SpellsCastWatcher(this);
}
@Override
public void watch(GameEvent event, Game game) {
if (EventType.SPELL_CAST.equals(event.getType())) {
Spell spell = game.getStack().getSpell(event.getTargetId());
if (spell == null) {
MageObject mageObject = game.getLastKnownInformation(event.getTargetId(), Zone.STACK);
if (mageObject instanceof Spell) {
spell = (Spell) mageObject;
}
}
if (spell != null) {
List<Spell> spells;
if (!spellsCast.containsKey(spell.getControllerId())) {
spells = new ArrayList<>();
spellsCast.put(spell.getControllerId(), spells);
} else {
spells = spellsCast.get(spell.getControllerId());
}
spells.add(spell.copy()); // copy needed because attributes like color could be changed later
}
}
}
@Override
public void reset() {
super.reset();
spellsCast.clear();
}
public List<Spell> getSpellsCastThisTurn(UUID playerId) {
return spellsCast.get(playerId);
}
}