Added Mana Drain and Spell Crumple. Fixed replacement effect of Hinder.

This commit is contained in:
LevelX2 2014-08-25 13:54:47 +02:00
parent 97276cbd2a
commit 48e8be4fc2
14 changed files with 599 additions and 48 deletions

View file

@ -99,6 +99,10 @@ public class MageObjectReference implements Comparable<MageObjectReference> {
return hash;
}
public boolean refersTo(UUID id, Game game) {
return refersTo(game.getObject(id));
}
public boolean refersTo(Permanent permanent) {
return permanent.getZoneChangeCounter()== zoneChangeCounter && permanent.getId().equals(sourceId);
}

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.common.delayed;
import mage.constants.TargetController;
@ -33,35 +32,57 @@ import mage.abilities.DelayedTriggeredAbility;
import mage.abilities.effects.Effect;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.events.GameEvent.EventType;
import mage.game.permanent.Permanent;
/**
*
* @author LevelX2
*/
public class AtTheBeginOMainPhaseDelayedTriggeredAbility extends DelayedTriggeredAbility {
public class AtTheBeginOfPreCombatMainDelayedTriggeredAbility extends DelayedTriggeredAbility {
public enum PhaseSelection {
private TargetController targetController;
NEXT_PRECOMBAT_MAIN("next precombat"),
NEXT_POSTCOMAT_MAIN("next postcombat"),
NEXT_MAIN("next");
public AtTheBeginOfPreCombatMainDelayedTriggeredAbility(Effect effect, TargetController targetController) {
super(effect);
this.targetController = targetController;
private final String text;
PhaseSelection(String text) {
this.text = text;
}
@Override
public String toString() {
return text;
}
}
public AtTheBeginOfPreCombatMainDelayedTriggeredAbility(AtTheBeginOfPreCombatMainDelayedTriggeredAbility ability) {
private final TargetController targetController;
private final PhaseSelection phaseSelection;
public AtTheBeginOMainPhaseDelayedTriggeredAbility(Effect effect, TargetController targetController, PhaseSelection phaseSelection) {
super(effect);
this.targetController = targetController;
this.phaseSelection = phaseSelection;
}
public AtTheBeginOMainPhaseDelayedTriggeredAbility(final AtTheBeginOMainPhaseDelayedTriggeredAbility ability) {
super(ability);
this.targetController = ability.targetController;
this.phaseSelection = ability.phaseSelection;
}
@Override
public AtTheBeginOfPreCombatMainDelayedTriggeredAbility copy() {
return new AtTheBeginOfPreCombatMainDelayedTriggeredAbility(this);
public AtTheBeginOMainPhaseDelayedTriggeredAbility copy() {
return new AtTheBeginOMainPhaseDelayedTriggeredAbility(this);
}
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (event.getType() == GameEvent.EventType.PRECOMBAT_MAIN_PHASE_PRE) {
if (checkPhase(event.getType())) {
switch (targetController) {
case ANY:
return true;
@ -87,21 +108,34 @@ public class AtTheBeginOfPreCombatMainDelayedTriggeredAbility extends DelayedTri
return false;
}
private boolean checkPhase(EventType eventType) {
switch (phaseSelection) {
case NEXT_MAIN:
return EventType.PRECOMBAT_MAIN_PHASE_PRE.equals(eventType) || EventType.PRECOMBAT_MAIN_PHASE_POST.equals(eventType);
case NEXT_POSTCOMAT_MAIN:
return EventType.PRECOMBAT_MAIN_PHASE_POST.equals(eventType);
case NEXT_PRECOMBAT_MAIN:
return EventType.PRECOMBAT_MAIN_PHASE_PRE.equals(eventType);
default:
return false;
}
}
@Override
public String getRule() {
StringBuilder sb = new StringBuilder();
switch (targetController) {
case YOU:
sb.append("At the beginning of your next precombat main phase, ");
sb.append("At the beginning of your ").append(phaseSelection.toString()).append(" main phase, ");
break;
case OPPONENT:
sb.append("At the beginning of an opponent's next precombat main phase, ");
sb.append("At the beginning of an opponent's ").append(phaseSelection.toString()).append(" main phase, ");
break;
case ANY:
sb.append("At the beginning of the next precombat main phase, ");
sb.append("At the beginning of the ").append(phaseSelection.toString()).append(" main phase, ");
break;
case CONTROLLER_ATTACHED_TO:
sb.append("At the beginning of the next precombat main phase of enchanted creature's controller, ");
sb.append("At the beginning of the ").append(phaseSelection.toString()).append(" main phase of enchanted creature's controller, ");
break;
}
sb.append(getEffects().getText(modes.getMode()));

View file

@ -22,10 +22,10 @@ public class AddManaToManaPoolEffect extends OneShotEffect {
protected Mana mana;
public AddManaToManaPoolEffect(Mana mana) {
public AddManaToManaPoolEffect(Mana mana, String textManaPoolOwner) {
super(Outcome.PutManaInPool);
this.mana = mana;
this.staticText = "add " + mana.toString() + " to that player's mana pool";
this.staticText = "add " + mana.toString() + " to " + textManaPoolOwner + " mana pool";
}
public AddManaToManaPoolEffect(final AddManaToManaPoolEffect effect) {

View file

@ -9,6 +9,7 @@ import mage.game.Game;
import java.io.ObjectStreamException;
import java.util.UUID;
import mage.players.Player;
/**
*
@ -41,7 +42,10 @@ public class ReturnToHandSpellEffect extends PostResolveEffect implements MageSi
@Override
public void postResolve(Card card, Ability source, UUID controllerId, Game game) {
card.moveToZone(Zone.HAND, source.getSourceId(), game, false);
Player controller = game.getPlayer(controllerId);
if (controller != null) {
controller.moveCardToHandWithInfo(card, source.getSourceId(), game, Zone.STACK);
}
}
}

View file

@ -0,0 +1,73 @@
/*
* 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.UUID;
import mage.abilities.Ability;
import mage.abilities.effects.PostResolveEffect;
import mage.cards.Card;
import mage.constants.Zone;
import mage.game.Game;
import mage.players.Player;
/**
*
* @author LevelX2
*/
public class ReturnToLibrarySpellEffect extends PostResolveEffect {
private final boolean toTop;
public ReturnToLibrarySpellEffect(boolean top) {
staticText = "Put {this} on "+ (top ? "top":"the bottom") + " of its owner's library";
this.toTop = top;
}
public ReturnToLibrarySpellEffect(final ReturnToLibrarySpellEffect effect) {
super(effect);
this.toTop = effect.toTop;
}
@Override
public boolean apply(Game game, Ability source) {
return true;
}
@Override
public ReturnToLibrarySpellEffect copy() {
return new ReturnToLibrarySpellEffect(this);
}
@Override
public void postResolve(Card card, Ability source, UUID controllerId, Game game) {
Player controller = game.getPlayer(controllerId);
if (controller != null) {
controller.moveCardToLibraryWithInfo(card, source.getSourceId(), game, Zone.STACK, toTop, true);
}
}
}

View file

@ -73,6 +73,9 @@ public class SpellStack extends ArrayDeque<StackObject> {
}
public boolean counter(UUID objectId, UUID sourceId, Game game) {
// the counter logic is copied by some spells to handle replacement effects of the countered spell
// so if logic is changed here check those spells for needed changes too
// Concerned cards to check: Hinder, Spell Crumple
StackObject stackObject = getStackObject(objectId);
MageObject sourceObject = game.getObject(sourceId);
if (stackObject != null && sourceObject != null) {
@ -81,7 +84,7 @@ public class SpellStack extends ArrayDeque<StackObject> {
game.rememberLKI(objectId, Zone.STACK, (Spell)stackObject);
}
this.remove(stackObject);
stackObject.counter(sourceId, game);
stackObject.counter(sourceId, game); // tries to move to graveyard
game.informPlayers(new StringBuilder(stackObject.getName()).append(" is countered by ").append(sourceObject.getLogName()).toString());
game.fireEvent(GameEvent.getEvent(GameEvent.EventType.COUNTERED, objectId, sourceId, stackObject.getControllerId()));
} else {