Fixed false min target handling of computer player. Some minor changes and additions to framework.

This commit is contained in:
LevelX2 2013-08-16 10:15:20 +02:00
parent b772ee224e
commit e6c42edc4f
6 changed files with 190 additions and 15 deletions

View file

@ -0,0 +1,89 @@
/*
* 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.common;
import mage.abilities.TriggeredAbilityImpl;
import mage.abilities.effects.Effect;
import mage.constants.Zone;
import mage.game.Game;
import mage.game.events.DamagedCreatureEvent;
import mage.game.events.GameEvent;
import mage.target.targetpointer.FixedTarget;
/**
*
* @author LevelX
*/
public class DealsCombatDamageTriggeredAbility extends TriggeredAbilityImpl<DealsCombatDamageTriggeredAbility> {
private boolean setTargetPointer;
public DealsCombatDamageTriggeredAbility(Effect effect, boolean optional) {
this(effect, optional, false);
}
public DealsCombatDamageTriggeredAbility(Effect effect, boolean optional, boolean setTargetPointer) {
super(Zone.BATTLEFIELD, effect, optional);
this.setTargetPointer = setTargetPointer;
}
public DealsCombatDamageTriggeredAbility(final DealsCombatDamageTriggeredAbility ability) {
super(ability);
this.setTargetPointer = ability.setTargetPointer;
}
@Override
public DealsCombatDamageTriggeredAbility copy() {
return new DealsCombatDamageTriggeredAbility(this);
}
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (event.getType() == GameEvent.EventType.DAMAGED_CREATURE || event.getType() == GameEvent.EventType.DAMAGED_PLANESWALKER || event.getType() == GameEvent.EventType.DAMAGED_PLAYER) {
if (event.getSourceId().equals(this.sourceId)
&& ((DamagedCreatureEvent) event).isCombatDamage()) {
if (setTargetPointer) {
for (Effect effect : this.getEffects()) {
effect.setTargetPointer(new FixedTarget(event.getTargetId()));
effect.setValue("damage", event.getAmount());
}
}
return true;
}
}
return false;
}
@Override
public String getRule() {
return "Whenever {this} deals combat damage, " + super.getRule();
}
}

View file

@ -0,0 +1,78 @@
/*
* 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.dynamicvalue;
import mage.abilities.Ability;
import mage.game.Game;
/**
*
* @author LevelX2
*/
public class MultipliedValue implements DynamicValue {
private DynamicValue value;
private int multplier;
public MultipliedValue(DynamicValue value, int multiplier) {
this.value = value.copy();
this.multplier = multiplier;
}
MultipliedValue(final MultipliedValue dynamicValue) {
this.value = dynamicValue.value.copy();
this.multplier = dynamicValue.multplier;
}
@Override
public int calculate(Game game, Ability sourceAbility) {
return multplier * value.calculate(game, sourceAbility);
}
@Override
public DynamicValue copy() {
return new MultipliedValue(this);
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
if (multplier == 2) {
sb.append("twice ");
} else {
sb.append(multplier).append(" * ");
}
return sb.append(value.toString()).toString();
}
@Override
public String getMessage() {
return value.getMessage();
}
}

View file

@ -47,10 +47,12 @@ public class DestroyAllEffect extends OneShotEffect {
super(Outcome.DestroyPermanent);
this.filter = filter;
this.noRegen = noRegen;
if (noRegen)
if (noRegen) {
staticText = "Destroy all " + filter.getMessage() + ". They can't be regenerated";
else
}
else {
staticText = "Destroy all " + filter.getMessage();
}
}
public DestroyAllEffect(FilterPermanent filter) {

View file

@ -31,7 +31,7 @@ public class DoIfCostPaid extends OneShotEffect<DoIfCostPaid> {
Player player = game.getPlayer(source.getControllerId());
MageObject mageObject = game.getObject(source.getSourceId());
if (player != null && mageObject != null) {
String message = new StringBuilder("Pay ").append(cost.getText()).append(" and ").append(executingEffect.getText(source.getModes().getMode())).toString();
String message = new StringBuilder(getCostText()).append(" and ").append(executingEffect.getText(source.getModes().getMode())).append("?").toString();
message = CardUtil.replaceSourceName(message, mageObject.getName());
if (player.chooseUse(executingEffect.getOutcome(), message, game)) {
cost.clearPaid();
@ -47,12 +47,16 @@ public class DoIfCostPaid extends OneShotEffect<DoIfCostPaid> {
@Override
public String getText(Mode mode) {
StringBuilder sb = new StringBuilder("you may ");
return new StringBuilder("you may ").append(getCostText()).append(". If you do, ").append(executingEffect.getText(mode)).toString();
}
private String getCostText() {
StringBuilder sb = new StringBuilder();
String costText = cost.getText();
if (costText.length() <7 || !costText.substring(0, 7).toLowerCase().equals("discard")) {
if (costText != null && !costText.toLowerCase().startsWith("discard") && !costText.toLowerCase().startsWith("sacrifice")) {
sb.append("pay ");
}
return sb.append(costText).append(". If you do, ").append(executingEffect.getText(mode)).toString();
return sb.append(costText).toString();
}
@Override

View file

@ -371,10 +371,9 @@ public class CardUtil {
/**
* Creates and saves a (card + zoneChangeCounter) specific exileId.
*
*
* @param game
* @param source - source ability
* @return - the specific UUID
* @param game the current game
* @param source source ability
* @return the specific UUID
*/
public static UUID getCardExileZoneId(Game game, Ability source) {
String key = getCardZoneString("SourceExileZone", source.getSourceId(), game);
@ -391,9 +390,9 @@ public class CardUtil {
* This string can be used to save and get values that must be specific to a permanent instance.
* So they won't match, if a permanent was e.g. exiled and came back immediately.
*
* @param text
* @param cardId
* @param game
* @param text short value to describe the value
* @param cardId id of the card
* @param game the game
* @return
*/
public static String getCardZoneString(String text, UUID cardId, Game game) {