mirror of
https://github.com/magefree/mage.git
synced 2025-12-22 03:22:00 -08:00
* Deflecting Palm - Fixed that damage dealing did not work if the source was a spell.
This commit is contained in:
parent
a3505b6dba
commit
08b26ae57a
4 changed files with 123 additions and 3 deletions
|
|
@ -315,7 +315,7 @@ public class ComputerPlayer extends PlayerImpl implements Player {
|
||||||
|
|
||||||
if (target instanceof TargetCardInYourGraveyard) {
|
if (target instanceof TargetCardInYourGraveyard) {
|
||||||
List<UUID> alreadyTargetted = target.getTargets();
|
List<UUID> alreadyTargetted = target.getTargets();
|
||||||
List<Card> cards = new ArrayList<Card>(game.getPlayer(playerId).getGraveyard().getCards(game));
|
List<Card> cards = new ArrayList<>(game.getPlayer(playerId).getGraveyard().getCards(game));
|
||||||
while(!cards.isEmpty()) {
|
while(!cards.isEmpty()) {
|
||||||
Card card = pickTarget(cards, outcome, target, null, game);
|
Card card = pickTarget(cards, outcome, target, null, game);
|
||||||
if (card != null && alreadyTargetted != null && !alreadyTargetted.contains(card.getId())) {
|
if (card != null && alreadyTargetted != null && !alreadyTargetted.contains(card.getId())) {
|
||||||
|
|
@ -325,6 +325,27 @@ public class ComputerPlayer extends PlayerImpl implements Player {
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (target instanceof TargetSource) {
|
||||||
|
Set<UUID> targets;
|
||||||
|
TargetSource t = ((TargetSource) target);
|
||||||
|
targets = t.possibleTargets(sourceId, playerId, game);
|
||||||
|
for (UUID targetId : targets) {
|
||||||
|
MageObject targetObject = game.getObject(targetId);
|
||||||
|
if (targetObject != null) {
|
||||||
|
List<UUID> alreadyTargetted = target.getTargets();
|
||||||
|
if (t.canTarget(targetObject.getId(), game)) {
|
||||||
|
if (alreadyTargetted != null && !alreadyTargetted.contains(targetObject.getId())) {
|
||||||
|
target.add(targetObject.getId(), game);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!target.isRequired(sourceId, game)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
throw new IllegalStateException("TargetSource wasn't handled. class:" + target.getClass().toString());
|
||||||
|
}
|
||||||
|
|
||||||
throw new IllegalStateException("Target wasn't handled. class:" + target.getClass().toString());
|
throw new IllegalStateException("Target wasn't handled. class:" + target.getClass().toString());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,7 @@ import mage.constants.Rarity;
|
||||||
import mage.game.Game;
|
import mage.game.Game;
|
||||||
import mage.game.events.GameEvent;
|
import mage.game.events.GameEvent;
|
||||||
import mage.game.permanent.Permanent;
|
import mage.game.permanent.Permanent;
|
||||||
|
import mage.game.stack.Spell;
|
||||||
import mage.players.Player;
|
import mage.players.Player;
|
||||||
import mage.target.TargetSource;
|
import mage.target.TargetSource;
|
||||||
|
|
||||||
|
|
@ -112,6 +113,8 @@ class DeflectingPalmEffect extends PreventionEffectImpl {
|
||||||
objectControllerId = ((Permanent) damageDealingObject).getControllerId();
|
objectControllerId = ((Permanent) damageDealingObject).getControllerId();
|
||||||
} else if (damageDealingObject instanceof Ability) {
|
} else if (damageDealingObject instanceof Ability) {
|
||||||
objectControllerId = ((Ability) damageDealingObject).getControllerId();
|
objectControllerId = ((Ability) damageDealingObject).getControllerId();
|
||||||
|
} else if (damageDealingObject instanceof Spell) {
|
||||||
|
objectControllerId = ((Spell) damageDealingObject).getControllerId();
|
||||||
}
|
}
|
||||||
if (objectControllerId != null) {
|
if (objectControllerId != null) {
|
||||||
Player objectController = game.getPlayer(objectControllerId);
|
Player objectController = game.getPlayer(objectControllerId);
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,71 @@
|
||||||
|
/*
|
||||||
|
* 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.test.cards.replacement.prevent;
|
||||||
|
|
||||||
|
import mage.constants.PhaseStep;
|
||||||
|
import mage.constants.Zone;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.mage.test.serverside.base.CardTestPlayerBase;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deflecting Palm Instant {R}{W}
|
||||||
|
* The next time a source of your choice would deal damage to you this turn, prevent that damage.
|
||||||
|
* If damage is prevented this way, Deflecting Palm deals that much damage to that source's controller.
|
||||||
|
*
|
||||||
|
* @author LevelX2
|
||||||
|
*/
|
||||||
|
public class DeflectingPalmTest extends CardTestPlayerBase {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests if a damage spell is selected as source the damge is prevented and is dealt to the controller of the damage spell
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testPreventDamageFromSpell() {
|
||||||
|
addCard(Zone.HAND, playerA, "Lightning Bolt");
|
||||||
|
addCard(Zone.BATTLEFIELD, playerA, "Mountain");
|
||||||
|
|
||||||
|
addCard(Zone.HAND, playerB, "Deflecting Palm");
|
||||||
|
addCard(Zone.BATTLEFIELD, playerB, "Mountain");
|
||||||
|
addCard(Zone.BATTLEFIELD, playerB, "Plains");
|
||||||
|
|
||||||
|
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Lightning Bolt", playerB);
|
||||||
|
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerB, "Deflecting Palm", "", "Lightning Bolt");
|
||||||
|
setChoice(playerB, "Lightning Bolt");
|
||||||
|
|
||||||
|
setStopAt(1, PhaseStep.BEGIN_COMBAT);
|
||||||
|
execute();
|
||||||
|
|
||||||
|
assertLife(playerA, 17);
|
||||||
|
assertLife(playerB, 20);
|
||||||
|
|
||||||
|
assertGraveyardCount(playerA, "Lightning Bolt", 1);
|
||||||
|
assertGraveyardCount(playerB, "Deflecting Palm", 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -61,9 +61,10 @@ import java.io.Serializable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import mage.abilities.mana.ManaAbility;
|
|
||||||
import mage.constants.Zone;
|
import mage.constants.Zone;
|
||||||
|
import mage.target.TargetSource;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
|
@ -318,7 +319,28 @@ public class TestPlayer extends ComputerPlayer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (target instanceof TargetSource) {
|
||||||
|
Set<UUID> possibleTargets;
|
||||||
|
TargetSource t = ((TargetSource) target);
|
||||||
|
possibleTargets = t.possibleTargets(sourceId, playerId, game);
|
||||||
|
for (UUID targetId : possibleTargets) {
|
||||||
|
MageObject targetObject = game.getObject(targetId);
|
||||||
|
if (targetObject != null) {
|
||||||
|
for (String choose2: choices) {
|
||||||
|
if (targetObject.getName().equals(choose2)) {
|
||||||
|
List<UUID> alreadyTargetted = target.getTargets();
|
||||||
|
if (t.canTarget(targetObject.getId(), game)) {
|
||||||
|
if (alreadyTargetted != null && !alreadyTargetted.contains(targetObject.getId())) {
|
||||||
|
target.add(targetObject.getId(), game);
|
||||||
|
choices.remove(choose2);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return super.choose(outcome, target, sourceId, game, options);
|
return super.choose(outcome, target, sourceId, game, options);
|
||||||
}
|
}
|
||||||
|
|
@ -511,6 +533,9 @@ public class TestPlayer extends ComputerPlayer {
|
||||||
|
|
||||||
private boolean handleNonPlayerTargetTarget(String target, Ability ability, Game game) {
|
private boolean handleNonPlayerTargetTarget(String target, Ability ability, Game game) {
|
||||||
boolean result = true;
|
boolean result = true;
|
||||||
|
if (target.isEmpty()) {
|
||||||
|
return true; // needed if spell has no target but waits until spell is on the stack
|
||||||
|
}
|
||||||
String[] targetList = target.split("\\^");
|
String[] targetList = target.split("\\^");
|
||||||
int index = 0;
|
int index = 0;
|
||||||
int targetsSet = 0;
|
int targetsSet = 0;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue