use of mage.filter.common.FilterControlledCreaturePermanent in project mage by magefree.
the class ExploitEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Target target = new TargetPermanent(1, 1, new FilterControlledCreaturePermanent("creature to exploit"), true);
if (target.canChoose(source.getSourceId(), controller.getId(), game)) {
controller.chooseTarget(Outcome.Sacrifice, target, source, game);
Permanent permanent = game.getPermanent(target.getFirstTarget());
if (permanent != null) {
if (permanent.sacrifice(source, game)) {
game.fireEvent(GameEvent.getEvent(GameEvent.EventType.EXPLOITED_CREATURE, permanent.getId(), source, controller.getId()));
}
}
}
return true;
}
return false;
}
use of mage.filter.common.FilterControlledCreaturePermanent in project mage by magefree.
the class EntrapmentManeuverSacrificeEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(targetPointer.getFirst(game, source));
if (player == null) {
return false;
}
FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent();
filter.add(AttackingPredicate.instance);
int realCount = game.getBattlefield().countAll(filter, player.getId(), game);
if (realCount > 0) {
Target target = new TargetControlledPermanent(1, 1, filter, true);
while (player.canRespond() && !target.isChosen() && target.canChoose(source.getSourceId(), player.getId(), game)) {
player.chooseTarget(Outcome.Sacrifice, target, source, game);
}
Permanent permanent = game.getPermanent(target.getFirstTarget());
if (permanent != null) {
int amount = permanent.getToughness().getValue();
permanent.sacrifice(source, game);
new CreateTokenEffect(new SoldierToken(), amount).apply(game, source);
} else {
return false;
}
}
return true;
}
use of mage.filter.common.FilterControlledCreaturePermanent in project mage by magefree.
the class GarrukPrimalHunterEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player != null) {
int amount = 0;
for (Permanent p : game.getBattlefield().getActivePermanents(new FilterControlledCreaturePermanent(), source.getControllerId(), game)) {
if (p.getPower().getValue() > amount) {
amount = p.getPower().getValue();
}
}
player.drawCards(amount, source, game);
return true;
}
return false;
}
use of mage.filter.common.FilterControlledCreaturePermanent in project mage by magefree.
the class ChromaLightFromWithinCount method apply.
@Override
public boolean apply(Game game, Ability source) {
for (Permanent creature : game.getBattlefield().getAllActivePermanents(new FilterControlledCreaturePermanent(), source.getControllerId(), game)) {
if (creature != null) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
creature.addPower(new ChromaLightFromWithinCount(creature).calculate(game, source, this));
creature.addToughness(new ChromaLightFromWithinCount(creature).calculate(game, source, this));
boosted = true;
}
}
}
return boosted;
}
use of mage.filter.common.FilterControlledCreaturePermanent in project mage by magefree.
the class MaskwoodNexusEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
// in graveyard
for (UUID cardId : controller.getGraveyard()) {
Card card = game.getCard(cardId);
if (card != null && card.isCreature(game)) {
game.getState().getCreateMageObjectAttribute(card, game).getSubtype().setIsAllCreatureTypes(true);
}
}
// on Hand
for (UUID cardId : controller.getHand()) {
Card card = game.getCard(cardId);
if (card != null && card.isCreature(game)) {
game.getState().getCreateMageObjectAttribute(card, game).getSubtype().setIsAllCreatureTypes(true);
}
}
// in Exile
for (Card card : game.getState().getExile().getAllCards(game)) {
if (card.isCreature(game) && card.isOwnedBy(controller.getId())) {
game.getState().getCreateMageObjectAttribute(card, game).getSubtype().setIsAllCreatureTypes(true);
}
}
// in Library (e.g. for Mystical Teachings)
for (Card card : controller.getLibrary().getCards(game)) {
if (card.isOwnedBy(controller.getId()) && card.isCreature(game)) {
game.getState().getCreateMageObjectAttribute(card, game).getSubtype().setIsAllCreatureTypes(true);
}
}
// commander in command zone
for (CommandObject commandObject : game.getState().getCommand()) {
if (!(commandObject instanceof Commander)) {
continue;
}
Card card = game.getCard(((Commander) commandObject).getId());
if (card != null && card.isOwnedBy(controller.getId()) && card.isCreature(game)) {
game.getState().getCreateMageObjectAttribute(card, game).getSubtype().setIsAllCreatureTypes(true);
}
}
// creature spells you control
for (Iterator<StackObject> iterator = game.getStack().iterator(); iterator.hasNext(); ) {
StackObject stackObject = iterator.next();
if (stackObject instanceof Spell && stackObject.isControlledBy(source.getControllerId()) && stackObject.isCreature(game)) {
Card card = ((Spell) stackObject).getCard();
game.getState().getCreateMageObjectAttribute(card, game).getSubtype().setIsAllCreatureTypes(true);
}
}
// creatures you control
List<Permanent> creatures = game.getBattlefield().getAllActivePermanents(new FilterControlledCreaturePermanent(), source.getControllerId(), game);
for (Permanent creature : creatures) {
if (creature != null) {
creature.setIsAllCreatureTypes(game, true);
}
}
return true;
}
Aggregations