Help implementing a card
Posted: 29 Sep 2011, 16:46
I started trying to implement some cards for Mage, which is the more advanced project i have seen so far.
But i couldn't manage to implement the "attacking" part of the rules in this card :
http://magiccards.info/mt/en/20.html
Here is the class (without imports and license):
No method in class Combat seems to be relevant, I'll try adding one (this card is the only card with an effect of that kind)
EDIT : Implemented it, added a method, "If you use the ability, you choose which player or planeswalker the Soldier creature is attacking. It doesn't have to attack the same player or planeswalker as Preeminent Captain." is still not implemented.
But i couldn't manage to implement the "attacking" part of the rules in this card :
http://magiccards.info/mt/en/20.html
Here is the class (without imports and license):
- Code: Select all
public class PreeminentCaptain extends CardImpl<PreeminentCaptain> {
final PreeminentCaptainEffect effect = new PreeminentCaptainEffect();
public PreeminentCaptain(UUID ownerId) {
super(ownerId, 20, "Preeminent Captain", Rarity.RARE,
new CardType[] { CardType.CREATURE }, "{2}{W}");
this.expansionSetCode = "MOR";
this.subtype.add("Kithkin");
this.subtype.add("Soldier");
this.color.setWhite(true);
this.power = new MageInt(2);
this.toughness = new MageInt(2);
this.addAbility(FirstStrikeAbility.getInstance());
// Whenever Preeminent Captain attacks, you may put a Soldier creature
// card from your hand onto the battlefield tapped and attacking.
this.addAbility(new AttacksTriggeredAbility(effect, true));
}
public PreeminentCaptain(final PreeminentCaptain card) {
super(card);
}
@Override
public PreeminentCaptain copy() {
return new PreeminentCaptain(this);
}
}
class PreeminentCaptainEffect extends OneShotEffect<PreeminentCaptainEffect> {
protected TargetCardInHand target;
public PreeminentCaptainEffect() {
super(Outcome.PutCreatureInPlay);
target = new TargetCardInHand(new FilterSoldierCard());
}
public PreeminentCaptainEffect(final PreeminentCaptainEffect effect) {
super(effect);
target = effect.target;
}
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (target.choose(getOutcome(), player.getId(), game)) {
if (target.getTargets().size() > 0) {
UUID cardId = (UUID) target.getTargets().toArray()[0];
Card card = player.getHand().get(cardId, game);
if (card != null) {
if (card.putOntoBattlefield(game, Zone.HAND,
source.getId(), source.getControllerId())) {
Permanent permanent = game.getPermanent(card.getId());
permanent.setTapped(true);
// ? ? ?
}
}
return true;
}
}
return false;
}
@Override
public PreeminentCaptainEffect copy() {
return new PreeminentCaptainEffect(this);
}
}
class FilterSoldierCard extends FilterCard<FilterSoldierCard> {
public FilterSoldierCard() {
this("a soldier creature card.");
}
public FilterSoldierCard(String name) {
super(name);
cardType.add(CardType.CREATURE);
subtype.add("Soldier");
}
public FilterSoldierCard(final FilterSoldierCard filter) {
super(filter);
}
@Override
public FilterSoldierCard copy() {
return new FilterSoldierCard(this);
}
}
No method in class Combat seems to be relevant, I'll try adding one (this card is the only card with an effect of that kind)
EDIT : Implemented it, added a method, "If you use the ability, you choose which player or planeswalker the Soldier creature is attacking. It doesn't have to attack the same player or planeswalker as Preeminent Captain." is still not implemented.