forked from External/mage
Merge pull request #4734 from spjspj/master
Beginning of implementation of Planechase.
This commit is contained in:
commit
8bee825d5c
36 changed files with 2239 additions and 23 deletions
|
|
@ -63,6 +63,7 @@ import java.util.ArrayList;
|
|||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import mage.game.command.Plane;
|
||||
|
||||
/**
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
|
|
@ -621,9 +622,9 @@ public abstract class AbilityImpl implements Ability {
|
|||
@Override
|
||||
public void setControllerId(UUID controllerId) {
|
||||
this.controllerId = controllerId;
|
||||
for (Watcher watcher : watchers) {
|
||||
watcher.setControllerId(controllerId);
|
||||
}
|
||||
for (Watcher watcher : watchers) {
|
||||
watcher.setControllerId(controllerId);
|
||||
}
|
||||
|
||||
if (subAbilities != null) {
|
||||
for (Ability subAbility : subAbilities) {
|
||||
|
|
@ -649,9 +650,9 @@ public abstract class AbilityImpl implements Ability {
|
|||
subAbility.setSourceId(sourceId);
|
||||
}
|
||||
}
|
||||
for (Watcher watcher : watchers) {
|
||||
watcher.setSourceId(sourceId);
|
||||
}
|
||||
for (Watcher watcher : watchers) {
|
||||
watcher.setSourceId(sourceId);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -923,8 +924,8 @@ public abstract class AbilityImpl implements Ability {
|
|||
return true;
|
||||
}
|
||||
MageObject object = game.getObject(this.getSourceId());
|
||||
// emblem are always actual
|
||||
if (object != null && object instanceof Emblem) {
|
||||
// emblem/planes are always actual
|
||||
if (object != null && (object instanceof Emblem || object instanceof Plane)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@ import mage.constants.TimingRule;
|
|||
import mage.constants.Zone;
|
||||
import mage.game.Game;
|
||||
import mage.game.command.Emblem;
|
||||
import mage.game.command.Plane;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.util.CardUtil;
|
||||
|
||||
|
|
@ -240,10 +241,10 @@ public abstract class ActivatedAbilityImpl extends AbilityImpl implements Activa
|
|||
MageObject mageObject = game.getObject(this.sourceId);
|
||||
if (mageObject instanceof Emblem) {
|
||||
return ((Emblem) mageObject).getControllerId().equals(playerId);
|
||||
} else {
|
||||
if (game.getState().getZone(this.sourceId) != Zone.BATTLEFIELD) {
|
||||
return ((Card) mageObject).getOwnerId().equals(playerId);
|
||||
}
|
||||
} else if (mageObject instanceof Plane) {
|
||||
return ((Plane) mageObject).getControllerId().equals(playerId);
|
||||
} else if (game.getState().getZone(this.sourceId) != Zone.BATTLEFIELD) {
|
||||
return ((Card) mageObject).getOwnerId().equals(playerId);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
* 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 java.util.EnumSet;
|
||||
import java.util.Set;
|
||||
|
||||
import mage.constants.TurnPhase;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.condition.Condition;
|
||||
import mage.game.Game;
|
||||
|
||||
/**
|
||||
* @author spjspj
|
||||
*/
|
||||
public enum MainPhaseStackEmptyCondition implements Condition {
|
||||
|
||||
instance;
|
||||
private static final Set<TurnPhase> turnPhases = EnumSet.of(TurnPhase.PRECOMBAT_MAIN, TurnPhase.POSTCOMBAT_MAIN);
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
return game.getStack().isEmpty()
|
||||
&& turnPhases.contains(game.getTurn().getPhase().getType());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "during the main phase and the stack is empty";
|
||||
}
|
||||
}
|
||||
|
|
@ -104,6 +104,9 @@ public class ConditionalContinuousEffect extends ContinuousEffectImpl {
|
|||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
if (condition == null && baseCondition != null) {
|
||||
condition = baseCondition;
|
||||
}
|
||||
boolean conditionState = condition.apply(game, source);
|
||||
if (conditionState) {
|
||||
effect.setTargetPointer(this.targetPointer);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,187 @@
|
|||
/*
|
||||
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
package mage.abilities.effects.common;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.stream.Collectors;
|
||||
import mage.MageObject;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.Mode;
|
||||
import mage.abilities.effects.ContinuousEffect;
|
||||
import mage.abilities.effects.Effect;
|
||||
import mage.abilities.effects.OneShotEffect;
|
||||
import mage.constants.Outcome;
|
||||
import mage.constants.PlanarDieRoll;
|
||||
import mage.constants.Planes;
|
||||
import mage.game.Game;
|
||||
import mage.game.command.CommandObject;
|
||||
import mage.game.command.Plane;
|
||||
import mage.players.Player;
|
||||
import mage.target.Target;
|
||||
import mage.target.targetpointer.FixedTarget;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author spjspj
|
||||
*/
|
||||
public class RollPlanarDieEffect extends OneShotEffect {
|
||||
|
||||
private static final Logger log = Logger.getLogger("Roll Planar Die");
|
||||
|
||||
protected List<Effect> chaosEffects = null;
|
||||
protected List<Target> chaosTargets = null;
|
||||
|
||||
public RollPlanarDieEffect(List<Effect> chaosEffects, List<Target> chaosTargets) {
|
||||
this(chaosEffects, chaosTargets, Outcome.Neutral);
|
||||
}
|
||||
|
||||
public RollPlanarDieEffect(List<Effect> chaosEffects, List<Target> chaosTargets, Outcome outcome) {
|
||||
super(outcome);
|
||||
addChaosEffects(chaosEffects);
|
||||
addChaosTargets(chaosTargets);
|
||||
}
|
||||
|
||||
public RollPlanarDieEffect(final RollPlanarDieEffect effect) {
|
||||
super(effect);
|
||||
this.chaosEffects = effect.chaosEffects.stream().collect(Collectors.toList());
|
||||
this.chaosTargets = effect.chaosTargets.stream().collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public void addChaosEffects(List<Effect> chaosEffects) {
|
||||
if (chaosEffects != null) {
|
||||
this.chaosEffects = chaosEffects;
|
||||
}
|
||||
}
|
||||
|
||||
public void addChaosTargets(List<Target> chaosTargets) {
|
||||
if (chaosTargets != null) {
|
||||
this.chaosTargets = chaosTargets;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Player controller = game.getPlayer(source.getControllerId());
|
||||
MageObject mageObject = game.getObject(source.getSourceId());
|
||||
if (controller != null && mageObject != null) {
|
||||
PlanarDieRoll planarRoll = controller.rollPlanarDie(game);
|
||||
if (planarRoll == PlanarDieRoll.CHAOS_ROLL && chaosEffects != null && chaosTargets != null) {
|
||||
for (int i = 0; i < chaosTargets.size(); i++) {
|
||||
Target target = chaosTargets.get(i);
|
||||
if (target != null) {
|
||||
target.clearChosen();
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < chaosEffects.size(); i++) {
|
||||
Effect effect = chaosEffects.get(i);
|
||||
Target target = null;
|
||||
if (chaosTargets != null && chaosTargets.size() > i) {
|
||||
target = chaosTargets.get(i);
|
||||
}
|
||||
boolean done = false;
|
||||
while (controller.canRespond() && effect != null && !done) {
|
||||
if (target != null && !target.isChosen() && target.canChoose(controller.getId(), game)) {
|
||||
controller.chooseTarget(Outcome.Benefit, target, source, game);
|
||||
source.addTarget(target);
|
||||
}
|
||||
if (target != null) {
|
||||
effect.setTargetPointer(new FixedTarget(target.getFirstTarget()));
|
||||
}
|
||||
try {
|
||||
effect.apply(game, source);
|
||||
} catch (UnsupportedOperationException exception) {
|
||||
}
|
||||
if (effect instanceof ContinuousEffect) {
|
||||
game.addEffect((ContinuousEffect) effect, source);
|
||||
}
|
||||
done = true;
|
||||
}
|
||||
}
|
||||
} else if (planarRoll == PlanarDieRoll.PLANAR_ROLL) {
|
||||
// Steps: 1) Remove the last plane and set its effects to discarded
|
||||
for (CommandObject cobject : game.getState().getCommand()) {
|
||||
if (cobject instanceof Plane) {
|
||||
game.getState().addSeenPlane((Plane) cobject, game, id);
|
||||
if (((Plane) cobject).getAbilities() != null) {
|
||||
for (Ability ability : ((Plane) cobject).getAbilities()) {
|
||||
for (Effect effect : ability.getEffects()) {
|
||||
if (effect instanceof ContinuousEffect) {
|
||||
((ContinuousEffect) effect).discard();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
game.getState().removeTriggersOfSourceId(((Plane) cobject).getId());
|
||||
game.getState().getCommand().remove(cobject);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// 2) Choose a new random plane we haven't been to, or reset if we've been everywhere
|
||||
List<String> planesVisited = game.getState().getSeenPlanes();
|
||||
if (game.getState().getSeenPlanes() != null) {
|
||||
if (planesVisited.size() == Planes.values().length) {
|
||||
game.getState().resetSeenPlanes();
|
||||
}
|
||||
}
|
||||
|
||||
boolean foundNextPlane = false;
|
||||
while (!foundNextPlane) {
|
||||
Plane plane = Plane.getRandomPlane();
|
||||
try {
|
||||
if (plane != null && !planesVisited.contains(plane.getName())) {
|
||||
foundNextPlane = true;
|
||||
plane.setControllerId(controller.getId());
|
||||
game.addPlane(plane, null, controller.getId());
|
||||
game.informPlayers("You have planeswalked to " + plane.getLogName());
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getText(Mode mode) {
|
||||
if (!staticText.isEmpty()) {
|
||||
return staticText;
|
||||
}
|
||||
StringBuilder sb = new StringBuilder("Roll the planar die");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public RollPlanarDieEffect copy() {
|
||||
return new RollPlanarDieEffect(this);
|
||||
}
|
||||
}
|
||||
|
|
@ -24,8 +24,7 @@
|
|||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
|
||||
*/
|
||||
package mage.abilities.effects.common.continuous;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
|
|
@ -44,13 +43,28 @@ import mage.players.Player;
|
|||
*/
|
||||
public class PlayAdditionalLandsAllEffect extends ContinuousEffectImpl {
|
||||
|
||||
private int numExtraLands = 1;
|
||||
|
||||
public PlayAdditionalLandsAllEffect() {
|
||||
super(Duration.WhileOnBattlefield, Layer.PlayerEffects, SubLayer.NA, Outcome.Benefit);
|
||||
staticText = "Each player may play an additional land on each of their turns";
|
||||
numExtraLands = 1;
|
||||
}
|
||||
|
||||
public PlayAdditionalLandsAllEffect(int numExtraLands) {
|
||||
super(Duration.WhileOnBattlefield, Layer.PlayerEffects, SubLayer.NA, Outcome.Benefit);
|
||||
this.numExtraLands = numExtraLands;
|
||||
if (numExtraLands == Integer.MAX_VALUE) {
|
||||
staticText = "Each player may play any number of additional lands on each of their turns";
|
||||
} else {
|
||||
staticText = "Each player may play an additional " + numExtraLands + " lands on each of their turns";
|
||||
}
|
||||
}
|
||||
|
||||
public PlayAdditionalLandsAllEffect(final PlayAdditionalLandsAllEffect effect) {
|
||||
super(effect);
|
||||
this.numExtraLands = effect.numExtraLands;
|
||||
this.staticText = effect.staticText;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -62,10 +76,13 @@ public class PlayAdditionalLandsAllEffect extends ContinuousEffectImpl {
|
|||
public boolean apply(Game game, Ability source) {
|
||||
Player player = game.getPlayer(game.getActivePlayerId());
|
||||
if (player != null) {
|
||||
player.setLandsPerTurn(player.getLandsPerTurn() + 1);
|
||||
if (numExtraLands == Integer.MAX_VALUE) {
|
||||
player.setLandsPerTurn(Integer.MAX_VALUE);
|
||||
} else {
|
||||
player.setLandsPerTurn(player.getLandsPerTurn() + numExtraLands);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue