package game.model; /** This abstract base class provides a default implementation for cards that are attached to other cards. * These are generally spells that modify the behaviour of the card they are attached to, for instance they * could change the attack and defense amount of the cards they are attached to.

* * This base class is a convience class and use is not required. The default behaviour it implements is: */ public class AbstractAttachedCard extends AbstractCard implements Card, Command { private final Area attachmentArea; private final Class attachmentClass; private final CardType attachmentType; /** Constructor. * @param name The name of the card. * @param targetArea The area this card can be placed in, generally either {@link Area#TABLE} or * {@link Area#OPPONENT_TABLE}. * @param targetClass The class of card this card can be attached to. For instance, a certain * card may only be attached to a {@link FighterCard}. * @param targetType The type of the target card. * @param desc The description of this card. */ protected AbstractAttachedCard(String name, Area targetArea, Class targetClass, CardType targetType, String desc) { super(CardType.SPELL, name, desc); attachmentArea = targetArea; attachmentClass = targetClass; attachmentType = targetType; } @SuppressWarnings("unchecked") public boolean execute(Game game) { switch (game.getPhase()) { case STANDBY: case RECOVER: game.getPlayer().getUI().print("Select target card for " + this); Action target = game.getPlayer().getUI().getAction(game, (Class) attachmentClass, attachmentArea, attachmentType); if (target instanceof Card) { Card targetCard = (Card) target; if (game.getPlayer().getHand().remove(this)) { game.getOwner(targetCard).setAttached(targetCard, this); printBoth(game, game.getPlayer() + " attaches " + this + " to " + target); return true; } } } game.getPlayer().getUI().print("You cannot play this card at this time."); return false; } public Condition[] conditions() { return new Condition [] { new Condition(Phase.STANDBY), new Condition(Phase.RECOVER) }; } }