"No spell and two spells were cast last turn" conditions.

This commit is contained in:
magenoxx 2011-10-01 16:32:20 +04:00
parent c5ceae2038
commit 7b711715ab
5 changed files with 183 additions and 0 deletions

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.condition.common;
import mage.abilities.Ability;
import mage.abilities.condition.Condition;
import mage.game.Game;
import mage.watchers.common.CastSpellLastTurnWatcher;
/**
* @author nantuko
*/
public class NoSpellsWereCastLastTurnCondition implements Condition {
private static NoSpellsWereCastLastTurnCondition fInstance = new NoSpellsWereCastLastTurnCondition();
public static Condition getInstance() {
return fInstance;
}
@Override
public boolean apply(Game game, Ability source) {
CastSpellLastTurnWatcher watcher = (CastSpellLastTurnWatcher) game.getState().getWatchers().get(source.getControllerId(), "CastSpellLastTurnWatcher");
return watcher.getAmountOfSpellsCastOnPrevTurn() == 0;
}
}

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.condition.common;
import mage.abilities.Ability;
import mage.abilities.condition.Condition;
import mage.game.Game;
import mage.watchers.common.CastSpellLastTurnWatcher;
/**
* @author nantuko
*/
public class TwoOrMoreSpellsWereCastLastTurnCondition implements Condition {
private static TwoOrMoreSpellsWereCastLastTurnCondition fInstance = new TwoOrMoreSpellsWereCastLastTurnCondition();
public static Condition getInstance() {
return fInstance;
}
@Override
public boolean apply(Game game, Ability source) {
CastSpellLastTurnWatcher watcher = (CastSpellLastTurnWatcher) game.getState().getWatchers().get(source.getControllerId(), "CastSpellLastTurnWatcher");
return watcher.getAmountOfSpellsCastOnPrevTurn() >= 2;
}
}

View file

@ -41,6 +41,9 @@ import mage.game.permanent.Permanent;
*/
public class TransformAbility extends SimpleStaticAbility {
public static final String NO_SPELLS_TRANSFORM_RULE = "At the beginning of each upkeep, if no spells were cast last turn, transform {this}";
public static final String TWO_OR_MORE_SPELLS_TRANSFORM_RULE = "At the beginning of each upkeep, if a player cast two or more spells last turn, transform {this}";
public TransformAbility() {
super(Constants.Zone.BATTLEFIELD, new TransformEffect());
}

View file

@ -66,6 +66,7 @@ import mage.abilities.mana.TriggeredManaAbility;
import mage.cards.CardsImpl;
import mage.target.Target;
import mage.target.TargetPermanent;
import mage.watchers.common.CastSpellLastTurnWatcher;
import mage.watchers.common.MorbidWatcher;
import org.apache.log4j.Logger;
@ -435,6 +436,7 @@ public abstract class GameImpl<T extends GameImpl<T>> implements Game, Serializa
}
state.getWatchers().add(new MorbidWatcher());
state.getWatchers().add(new CastSpellLastTurnWatcher());
//20100716 - 103.5
for (UUID playerId: state.getPlayerList(startingPlayerId)) {

View file

@ -0,0 +1,76 @@
/*
* 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.watchers.common;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.watchers.WatcherImpl;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class CastSpellLastTurnWatcher extends WatcherImpl<CastSpellLastTurnWatcher> {
private int amountOfSpellsCastOnPrevTurn;
private int amountOfSpellsCastOnCurrentTurn;
public CastSpellLastTurnWatcher() {
super("CastSpellLastTurnWatcher");
}
public CastSpellLastTurnWatcher(final CastSpellLastTurnWatcher watcher) {
super(watcher);
this.amountOfSpellsCastOnCurrentTurn = watcher.amountOfSpellsCastOnCurrentTurn;
this.amountOfSpellsCastOnPrevTurn = watcher.amountOfSpellsCastOnPrevTurn;
}
@Override
public void watch(GameEvent event, Game game) {
if (event.getType() == GameEvent.EventType.SPELL_CAST) {
amountOfSpellsCastOnCurrentTurn++;
}
}
@Override
public void reset() {
amountOfSpellsCastOnPrevTurn = amountOfSpellsCastOnCurrentTurn;
amountOfSpellsCastOnCurrentTurn = 0;
}
public int getAmountOfSpellsCastOnPrevTurn() {
return amountOfSpellsCastOnPrevTurn;
}
@Override
public CastSpellLastTurnWatcher copy() {
return new CastSpellLastTurnWatcher(this);
}
}