Fixed issue 212, created a getter for the copiedSpell member to use in the copied spells resolution of the rebound effect.

This commit is contained in:
maurer.it 2011-10-13 22:34:03 -04:00
parent 1e91dbe7e3
commit e0fb91f380
3 changed files with 27 additions and 96 deletions

View file

@ -1,75 +0,0 @@
/*
* 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 org.mage.ai;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
import mage.util.Logging;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class ConfigurableComputerConfig {
private final static Logger logger = Logging.getLogger(ConfigurableComputerConfig.class.getName());
// public static final int maxDepth;
public static final int maxNodes;
public static final int evaluatorLifeFactor;
public static final int evaluatorPermanentFactor;
public static final int evaluatorCreatureFactor;
public static final int evaluatorHandFactor;
// public static final int maxThinkSeconds;
static {
Properties p = new Properties();
try {
File file = new File(ConfigurableComputerConfig.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath());
p.load(new FileInputStream(new File(file.getParent() + File.separator + "AIMinimax.properties")));
} catch (IOException ex) {
logger.log(Level.SEVERE, null, ex);
} catch (URISyntaxException ex) {
Logger.getLogger(ConfigurableComputerConfig.class.getName()).log(Level.SEVERE, null, ex);
}
// maxDepth = Integer.parseInt(p.getProperty("maxDepth"));
maxNodes = Integer.parseInt(p.getProperty("maxNodes"));
evaluatorLifeFactor = Integer.parseInt(p.getProperty("evaluatorLifeFactor"));
evaluatorPermanentFactor = Integer.parseInt(p.getProperty("evaluatorPermanentFactor"));
evaluatorCreatureFactor = Integer.parseInt(p.getProperty("evaluatorCreatureFactor"));
evaluatorHandFactor = Integer.parseInt(p.getProperty("evaluatorHandFactor"));
// maxThinkSeconds = Integer.parseInt(p.getProperty("maxThinkSeconds"));
}
}

View file

@ -47,7 +47,6 @@ import mage.game.events.GameEvent.EventType;
import mage.game.events.ZoneChangeEvent;
import mage.game.stack.Spell;
import mage.players.Player;
import org.apache.log4j.Logger;
/**
* This ability has no effect by default and will always return false on the call
@ -104,7 +103,7 @@ public class ReboundAbility extends TriggeredAbilityImpl<ReboundAbility> {
if ( event.getType() == EventType.SPELL_CAST && this.installReboundEffect ) {
Spell spell = game.getStack().getSpell(event.getTargetId());
if (spell != null && spell.getSourceId().equals(this.getSourceId())) {
spell.getSpellAbility().addEffect(new ReboundEffect(spell.getId()));
spell.getSpellAbility().addEffect(new ReboundEffect());
this.installReboundEffect = false;
}
}
@ -132,34 +131,31 @@ public class ReboundAbility extends TriggeredAbilityImpl<ReboundAbility> {
*/
class ReboundEffect extends OneShotEffect<ReboundEffect> {
private Logger log = Logger.getLogger(ReboundEffect.class);
private UUID originalId;
public ReboundEffect(UUID originalId) {
public ReboundEffect() {
super(Outcome.Benefit);
this.originalId = originalId;
}
public ReboundEffect ( ReboundEffect effect ) {
super(effect);
this.originalId = effect.originalId;
}
@Override
public boolean apply(Game game, Ability source) {
if (!originalId.equals(source.getId())) {
log.warn("rebound was ignored. was it copied spell?");
Spell sourceSpell = (Spell)game.getObject(source.getId());
if ( sourceSpell.isCopiedSpell() ) {
return false;
}
else {
Card sourceCard = (Card)game.getObject(source.getSourceId());
ReboundEffectCastFromExileDelayedTrigger trigger = new ReboundEffectCastFromExileDelayedTrigger(sourceCard.getId(), sourceCard.getId());
trigger.setControllerId(source.getControllerId());
game.addDelayedTriggeredAbility(trigger);
Card sourceCard = (Card)game.getObject(source.getSourceId());
ReboundEffectCastFromExileDelayedTrigger trigger = new ReboundEffectCastFromExileDelayedTrigger(sourceCard.getId(), sourceCard.getId());
trigger.setControllerId(source.getControllerId());
game.addDelayedTriggeredAbility(trigger);
game.getContinuousEffects().addEffect(new ReboundCastFromHandReplacementEffect(sourceCard.getId()), source);
return true;
game.getContinuousEffects().addEffect(new ReboundCastFromHandReplacementEffect(sourceCard.getId()), source);
return true;
}
}
@Override
@ -204,13 +200,19 @@ class ReboundCastFromHandReplacementEffect extends ReplacementEffectImpl<Rebound
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
Card sourceCard = (Card)game.getObject(source.getSourceId());
Player player = game.getPlayer(sourceCard.getOwnerId());
Spell sourceSpell = (Spell)game.getObject(source.getId());
if ( sourceSpell.isCopiedSpell() ) {
return false;
}
else {
Card sourceCard = (Card)game.getObject(source.getSourceId());
Player player = game.getPlayer(sourceCard.getOwnerId());
sourceCard.moveToExile(source.getSourceId(), player.getName() + " Rebound Exile", source.getId(), game);
this.used = true;
sourceCard.moveToExile(source.getSourceId(), player.getName() + " Rebound Exile", source.getId(), game);
this.used = true;
return true;
return true;
}
}
@Override

View file

@ -436,5 +436,9 @@ public class Spell<T extends Spell<T>> implements StackObject, Card {
public void setCopiedSpell(boolean isCopied) {
this.copiedSpell = isCopied;
}
public boolean isCopiedSpell ( ) {
return this.copiedSpell;
}
}