* AI: fixed that computer can't target cards on battlefield if it contains tokens;

This commit is contained in:
Oleg Agafonov 2020-01-02 04:46:20 +04:00
parent de07960ee5
commit 50195e8f35
4 changed files with 121 additions and 78 deletions

View file

@ -18,41 +18,40 @@ import mage.view.PermanentView;
import java.awt.*; import java.awt.*;
import java.awt.geom.Rectangle2D; import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.awt.image.RasterFormatException; import java.awt.image.RasterFormatException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.awt.image.BufferedImage;
/** /**
* @author stravant@gmail.com * @author stravant@gmail.com
* * <p>
* Common base class for card renderers for each card frame / card type. * Common base class for card renderers for each card frame / card type.
* * <p>
* Follows the template method pattern to implement a new renderer, implement * Follows the template method pattern to implement a new renderer, implement
* the following methods (they are called in the following order): * the following methods (they are called in the following order):
* * <p>
* * drawBorder() Draws the outermost border of the card, white border or black * * drawBorder() Draws the outermost border of the card, white border or black
* border * border
* * <p>
* * drawBackground() Draws the background texture / color of the card * * drawBackground() Draws the background texture / color of the card
* * <p>
* * drawArt() Draws the card's art * * drawArt() Draws the card's art
* * <p>
* * drawFrame() Draws the card frame (over the art and background) * * drawFrame() Draws the card frame (over the art and background)
* * <p>
* * drawOverlays() Draws summoning sickness and possible other overlays * * drawOverlays() Draws summoning sickness and possible other overlays
* * <p>
* * drawCounters() Draws counters on the card, such as +1/+1 and -1/-1 * * drawCounters() Draws counters on the card, such as +1/+1 and -1/-1
* counters * counters
* * <p>
* Predefined methods that the implementations can use: * Predefined methods that the implementations can use:
* * <p>
* * drawRules(font, bounding box) * * drawRules(font, bounding box)
* * <p>
* * drawNameLine(font, bounding box) * * drawNameLine(font, bounding box)
* * <p>
* * drawTypeLine(font, bounding box) * * drawTypeLine(font, bounding box)
*
*/ */
public abstract class CardRenderer { public abstract class CardRenderer {
@ -253,10 +252,10 @@ public abstract class CardRenderer {
int x2 = (int) (0.8 * cardWidth); int x2 = (int) (0.8 * cardWidth);
int y1 = (int) (0.2 * cardHeight); int y1 = (int) (0.2 * cardHeight);
int y2 = (int) (0.8 * cardHeight); int y2 = (int) (0.8 * cardHeight);
int xPoints[] = { int[] xPoints = {
x1, x2, x1, x2 x1, x2, x1, x2
}; };
int yPoints[] = { int[] yPoints = {
y1, y1, y2, y2 y1, y1, y2, y2
}; };
g.setColor(new Color(255, 255, 255, 200)); g.setColor(new Color(255, 255, 255, 200));
@ -438,6 +437,7 @@ public abstract class CardRenderer {
} }
private Color getRarityColor() { private Color getRarityColor() {
if (cardView.getRarity() != null) {
switch (cardView.getRarity()) { switch (cardView.getRarity()) {
case RARE: case RARE:
return new Color(255, 191, 0); return new Color(255, 191, 0);
@ -453,6 +453,10 @@ public abstract class CardRenderer {
default: default:
return Color.black; return Color.black;
} }
} else {
// tokens
return Color.black;
}
} }
// Get a string representing the type line // Get a string representing the type line

View file

@ -70,4 +70,40 @@ public class EnterLeaveBattlefieldExileTargetTest extends CardTestPlayerBase {
assertHandCount(playerB, "Pillarfield Ox", 1); assertHandCount(playerB, "Pillarfield Ox", 1);
assertExileCount(playerB, 0); assertExileCount(playerB, 0);
} }
@Test
public void testAngelOfSerenityTargets() {
// test NPE error while AI targeting battlefield with tokens
// Flying
// When Angel of Serenity enters the battlefield, you may exile up to three other target creatures from the battlefield and/or creature cards from graveyards.
addCard(Zone.HAND, playerA, "Angel of Serenity");
addCard(Zone.BATTLEFIELD, playerA, "Plains", 7);
//
// Create two 2/2 white Knight Ally creature tokens.
addCard(Zone.HAND, playerA, "Allied Reinforcements", 1);
addCard(Zone.BATTLEFIELD, playerA, "Plains", 4);
//
addCard(Zone.BATTLEFIELD, playerA, "Silvercoat Lion", 2);
addCard(Zone.BATTLEFIELD, playerB, "Balduvian Bears", 2);
addCard(Zone.GRAVEYARD, playerA, "Silvercoat Lion", 2);
addCard(Zone.GRAVEYARD, playerB, "Balduvian Bears", 2);
// create tokens
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Allied Reinforcements");
waitStackResolved(1, PhaseStep.PRECOMBAT_MAIN);
// angel
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Angel of Serenity");
setChoice(playerA, "Yes");
//addTarget(playerA, "Silvercoat Lion^Balduvian Bears"); // AI must target
//setStrictChooseMode(true); // AI must target
setStopAt(1, PhaseStep.POSTCOMBAT_MAIN);
execute();
assertAllCommandsUsed();
assertPermanentCount(playerA, "Knight Ally", 2);
assertPermanentCount(playerA, "Angel of Serenity", 1);
}
} }

View file

@ -1,8 +1,5 @@
package mage.cards; package mage.cards;
import java.util.List;
import java.util.UUID;
import mage.MageObject; import mage.MageObject;
import mage.Mana; import mage.Mana;
import mage.abilities.Abilities; import mage.abilities.Abilities;
@ -17,13 +14,16 @@ import mage.game.Game;
import mage.game.GameState; import mage.game.GameState;
import mage.game.permanent.Permanent; import mage.game.permanent.Permanent;
import java.util.List;
import java.util.UUID;
public interface Card extends MageObject { public interface Card extends MageObject {
UUID getOwnerId(); UUID getOwnerId();
String getCardNumber(); String getCardNumber();
Rarity getRarity(); Rarity getRarity(); // null for tokens
void setOwnerId(UUID ownerId); void setOwnerId(UUID ownerId);
@ -122,7 +122,6 @@ public interface Card extends MageObject {
List<Mana> getMana(); List<Mana> getMana();
/** /**
*
* @return true if there exists various art images for this card * @return true if there exists various art images for this card
*/ */
boolean getUsesVariousArt(); boolean getUsesVariousArt();
@ -149,7 +148,6 @@ public interface Card extends MageObject {
Card copy(); Card copy();
/** /**
*
* @return The main card of a split half card or adventure spell card, otherwise the card itself is * @return The main card of a split half card or adventure spell card, otherwise the card itself is
* returned * returned
*/ */

View file

@ -186,6 +186,7 @@ public final class RateCard {
// ratings from card rarity // ratings from card rarity
// some cards can have different rarity -- it's will be used from first set // some cards can have different rarity -- it's will be used from first set
int newRating; int newRating;
if (card.getRarity() != null) {
switch (card.getRarity()) { switch (card.getRarity()) {
case COMMON: case COMMON:
newRating = DEFAULT_NOT_RATED_CARD_RATING; newRating = DEFAULT_NOT_RATED_CARD_RATING;
@ -203,6 +204,10 @@ public final class RateCard {
newRating = DEFAULT_NOT_RATED_CARD_RATING; newRating = DEFAULT_NOT_RATED_CARD_RATING;
break; break;
} }
} else {
// tokens
newRating = DEFAULT_NOT_RATED_CARD_RATING;
}
int oldRating = baseRatings.getOrDefault(card.getName(), 0); int oldRating = baseRatings.getOrDefault(card.getName(), 0);
if (oldRating != 0 && oldRating != newRating) { if (oldRating != 0 && oldRating != newRating) {