use of mage.abilities.Ability in project mage by magefree.
the class CardTestPlayerAPIImpl method assertAbilityCount.
public void assertAbilityCount(Player player, String cardName, Class<? extends Ability> searchedAbility, int amount) {
Permanent found = null;
for (Permanent permanent : currentGame.getBattlefield().getAllActivePermanents(player.getId())) {
if (isObjectHaveTargetNameOrAlias(player, permanent, cardName)) {
found = permanent;
break;
}
}
Assert.assertNotNull("There is no such permanent under player's control, player=" + player.getName() + ", cardName=" + cardName, found);
Assert.assertEquals(amount, found.getAbilities(currentGame).stream().filter(a -> searchedAbility.isAssignableFrom(a.getClass())).collect(Collectors.toList()).size());
}
use of mage.abilities.Ability in project mage by magefree.
the class CardTestPlayerAPIImpl method assertAbilities.
/**
* {@inheritDoc}
*/
@Override
public void assertAbilities(Player player, String cardName, List<Ability> abilities) throws AssertionError {
// Assert.assertNotEquals("", cardName);
int count = 0;
Permanent found = null;
for (Permanent permanent : currentGame.getBattlefield().getAllActivePermanents(player.getId())) {
if (isObjectHaveTargetNameOrAlias(player, permanent, cardName)) {
found = permanent;
count++;
}
}
Assert.assertNotNull("There is no such permanent under player's control, player=" + player.getName() + ", cardName=" + cardName, found);
assertTrue("There is more than one such permanent under player's control, player=" + player.getName() + ", cardName=" + cardName, count == 1);
for (Ability ability : abilities) {
assertTrue("No such ability=" + ability.toString() + ", player=" + player.getName() + ", cardName" + cardName, found.getAbilities().contains(ability));
}
}
use of mage.abilities.Ability in project mage by magefree.
the class CardTestAPIImpl method assertAbilities.
/**
* {@inheritDoc}
*/
@Override
public void assertAbilities(Player player, String cardName, List<Ability> abilities) throws AssertionError {
int count = 0;
Permanent found = null;
for (Permanent permanent : currentGame.getBattlefield().getAllActivePermanents(player.getId())) {
if (permanent.getName().equals(cardName)) {
found = permanent;
}
}
Assert.assertNotNull("There is no such permanent under player's control, player=" + player.getName() + ", cardName=" + cardName, found);
Assert.assertTrue("There is more than one such permanent under player's control, player=" + player.getName() + ", cardName=" + cardName, count == 1);
for (Ability ability : abilities) {
Assert.assertTrue("No such ability=" + ability.toString() + ", player=" + player.getName() + ", cardName=" + cardName, found.getAbilities().contains(ability));
}
}
use of mage.abilities.Ability in project mage by magefree.
the class ManifestTargetPlayerEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player targetPlayer = game.getPlayer(getTargetPointer().getFirst(game, source));
if (targetPlayer != null) {
Ability newSource = source.copy();
newSource.setWorksFaceDown(true);
Set<Card> cards = targetPlayer.getLibrary().getTopCards(game, amount);
for (Card card : cards) {
ManaCosts manaCosts = null;
if (card.isCreature(game)) {
manaCosts = card.getSpellAbility().getManaCosts();
if (manaCosts == null) {
manaCosts = new ManaCostsImpl("{0}");
}
}
MageObjectReference objectReference = new MageObjectReference(card.getId(), card.getZoneChangeCounter(game) + 1, game);
game.addEffect(new BecomesFaceDownCreatureEffect(manaCosts, objectReference, Duration.Custom, FaceDownType.MANIFESTED), newSource);
}
targetPlayer.moveCards(cards, Zone.BATTLEFIELD, source, game, false, true, false, null);
for (Card card : cards) {
Permanent permanent = game.getPermanent(card.getId());
if (permanent != null) {
permanent.setManifested(true);
}
}
return true;
}
return false;
}
use of mage.abilities.Ability in project mage by magefree.
the class TargetsHaveToTargetPermanentIfAbleEffect method applies.
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
Player controller = game.getPlayer(source.getControllerId());
Player targetingPlayer = game.getPlayer(event.getPlayerId());
if (controller != null && // TODO: This target handling does only work for non AI players so AI logic
targetingPlayer.isHuman() && controller.hasOpponent(event.getPlayerId(), game)) {
StackObject stackObject = game.getStack().getStackObject(event.getSourceId());
if (stackObject.isCopy()) {
return false;
}
Ability stackAbility = stackObject.getStackAbility();
// Ensure that this ability is activated or a cast spell, because Flag Bearer effects don't require triggered abilities to choose a Standard Bearer
if (!(stackAbility instanceof ActivatedAbility) && !(stackAbility instanceof SpellAbility)) {
return false;
}
// Also check that targeting player controls the ability
if (!stackAbility.isControlledBy(targetingPlayer.getId())) {
return false;
}
Ability ability = (Ability) getValue("targetAbility");
if (ability != null) {
// Get all the allowed permanents on the battlefield in range of the abilities controller
List<Permanent> allowedPermanents = game.getBattlefield().getActivePermanents(filter, event.getPlayerId(), event.getSourceId(), game);
if (!allowedPermanents.isEmpty()) {
boolean canTargetAllowedPermanent = false;
for (UUID modeId : ability.getModes().getSelectedModes()) {
ability.getModes().setActiveMode(modeId);
for (Target target : ability.getTargets()) {
// Check if already targeted
for (Permanent allowedPermanent : allowedPermanents) {
if (target.getTargets().contains(allowedPermanent.getId())) {
return false;
}
if (target.canTarget(stackObject.getControllerId(), allowedPermanent.getId(), source, game)) {
canTargetAllowedPermanent = true;
}
}
}
}
return canTargetAllowedPermanent;
}
}
}
return false;
}
Aggregations