use of mage.game.permanent.PermanentCard in project mage by magefree.
the class CardTestAPIImpl method addCard.
/**
* Add any amount of cards to specified zone of specified player.
*
* @param gameZone {@link mage.constants.Zone} to add cards to.
* @param player {@link Player} to add cards for. Use either playerA or playerB.
* @param cardName Card name in string format.
* @param count Amount of cards to be added.
* @param tapped In case gameZone is Battlefield, determines whether permanent should be tapped.
* In case gameZone is other than Battlefield, {@link IllegalArgumentException} is thrown
*/
@Override
public void addCard(Zone gameZone, TestPlayer player, String cardName, int count, boolean tapped) {
if (gameZone == Zone.BATTLEFIELD) {
for (int i = 0; i < count; i++) {
CardInfo cardInfo = CardRepository.instance.findCard(cardName);
Card card = cardInfo != null ? cardInfo.getCard() : null;
if (card == null) {
throw new IllegalArgumentException("[TEST] Couldn't find a card: " + cardName);
}
PermanentCard p = new PermanentCard(card, null, currentGame);
p.setTapped(tapped);
if (player.equals(playerA)) {
battlefieldCardsA.add(p);
} else if (player.equals(playerB)) {
battlefieldCardsB.add(p);
}
}
} else {
if (tapped) {
throw new IllegalArgumentException("Parameter tapped=true can be used only for Zone.BATTLEFIELD.");
}
List<Card> cards = getCardList(gameZone, player);
for (int i = 0; i < count; i++) {
CardInfo cardInfo = CardRepository.instance.findCard(cardName);
Card card = cardInfo != null ? cardInfo.getCard() : null;
cards.add(card);
}
}
}
use of mage.game.permanent.PermanentCard in project mage by magefree.
the class AbilityPickerTest method getAbilitiesFromCard.
private Abilities<Ability> getAbilitiesFromCard(String cardName) {
CardInfo info = CardRepository.instance.findCard(cardName);
PermanentImpl permanent = new PermanentCard(info.getCard(), playerA.getId(), currentGame);
return permanent.getAbilities(currentGame);
}
use of mage.game.permanent.PermanentCard in project mage by magefree.
the class LazavDimirMastermindCopyApplier method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Permanent lazavDimirMastermind = game.getPermanent(source.getSourceId());
Permanent newBluePrint = null;
if (controller != null && lazavDimirMastermind != null) {
Card copyFromCard = game.getCard(((FixedTarget) getTargetPointer()).getTarget());
if (copyFromCard != null) {
newBluePrint = new PermanentCard(copyFromCard, source.getControllerId(), game);
newBluePrint.assignNewId();
CopyApplier applier = new LazavDimirMastermindCopyApplier();
applier.apply(game, newBluePrint, source, lazavDimirMastermind.getId());
CopyEffect copyEffect = new CopyEffect(Duration.Custom, newBluePrint, lazavDimirMastermind.getId());
copyEffect.newId();
copyEffect.setApplier(applier);
Ability newAbility = source.copy();
copyEffect.init(newAbility, game);
game.addEffect(copyEffect, newAbility);
}
return true;
}
return false;
}
use of mage.game.permanent.PermanentCard in project mage by magefree.
the class ContinuousEffects method checkAbilityStillExists.
private boolean checkAbilityStillExists(Ability ability, ContinuousEffect effect, GameEvent event, Game game) {
switch(// effects with fixed duration don't need an object with the source ability (e.g. a silence cast with isochronic Scepter has no more a card object
effect.getDuration()) {
case EndOfCombat:
case EndOfGame:
case EndOfStep:
case EndOfTurn:
case OneUse:
case // custom duration means the effect ends itself if needed
Custom:
return true;
}
if (ability.getSourceId() == null) {
// commander replacement effect
return true;
}
MageObject object;
if (event.getType() == GameEvent.EventType.ZONE_CHANGE && ((ZoneChangeEvent) event).getFromZone() == Zone.BATTLEFIELD && event.getTargetId().equals(ability.getSourceId())) {
object = ((ZoneChangeEvent) event).getTarget();
} else {
object = game.getObject(ability.getSourceId());
}
if (object == null) {
return false;
}
boolean exists = true;
if (!object.hasAbility(ability, game)) {
exists = false;
if (object instanceof PermanentCard) {
PermanentCard permanent = (PermanentCard) object;
if (permanent.isTransformable() && event.getType() == GameEvent.EventType.TRANSFORMED) {
exists = permanent.getCard().hasAbility(ability, game);
}
}
} else if (object instanceof PermanentCard) {
PermanentCard permanent = (PermanentCard) object;
if (permanent.isFaceDown(game) && !ability.getWorksFaceDown()) {
return false;
}
} else if (object instanceof Spell) {
Spell spell = (Spell) object;
if (spell.isFaceDown(game) && !ability.getWorksFaceDown()) {
return false;
}
}
return exists;
}
use of mage.game.permanent.PermanentCard in project mage by magefree.
the class GameImpl method cheat.
@Override
public void cheat(UUID ownerId, List<Card> library, List<Card> hand, List<PermanentCard> battlefield, List<Card> graveyard, List<Card> command) {
// fake test ability for triggers and events
Ability fakeSourceAbilityTemplate = new SimpleStaticAbility(Zone.OUTSIDE, new InfoEffect("adding testing cards"));
fakeSourceAbilityTemplate.setControllerId(ownerId);
Player player = getPlayer(ownerId);
if (player != null) {
loadCards(ownerId, library);
loadCards(ownerId, hand);
loadCards(ownerId, battlefield);
loadCards(ownerId, graveyard);
loadCards(ownerId, command);
for (Card card : library) {
player.getLibrary().putOnTop(card, this);
}
for (Card card : hand) {
card.setZone(Zone.HAND, this);
player.getHand().add(card);
}
for (Card card : graveyard) {
card.setZone(Zone.GRAVEYARD, this);
player.getGraveyard().add(card);
}
// as commander (only commander games, look at init code in GameCommanderImpl)
if (this instanceof GameCommanderImpl) {
for (Card card : command) {
((GameCommanderImpl) this).addCommander(card, player);
// no needs in initCommander call -- it's uses on game startup (init)
}
} else if (!command.isEmpty()) {
throw new IllegalArgumentException("Command zone supports in commander test games");
}
for (PermanentCard permanentCard : battlefield) {
Ability fakeSourceAbility = fakeSourceAbilityTemplate.copy();
fakeSourceAbility.setSourceId(permanentCard.getId());
CardUtil.putCardOntoBattlefieldWithEffects(fakeSourceAbility, this, permanentCard, player);
}
applyEffects();
}
}
Aggregations