use of mage.game.permanent.Permanent in project mage by magefree.
the class ChimericCoilsEffect method apply.
@Override
public boolean apply(Layer layer, SubLayer sublayer, Ability source, Game game) {
Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent == null) {
return false;
}
switch(layer) {
case TypeChangingEffects_4:
if (!permanent.isArtifact(game)) {
permanent.addCardType(game, CardType.ARTIFACT);
}
if (!permanent.isCreature(game)) {
permanent.addCardType(game, CardType.CREATURE);
}
permanent.removeAllCreatureTypes(game);
permanent.addSubType(game, SubType.CONSTRUCT);
break;
case PTChangingEffects_7:
if (sublayer == SubLayer.SetPT_7b) {
int xValue = source.getManaCostsToPay().getX();
permanent.getPower().setValue(xValue);
permanent.getToughness().setValue(xValue);
}
}
return true;
}
use of mage.game.permanent.Permanent in project mage by magefree.
the class CracklingDoomEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
List<Permanent> toSacrifice = new ArrayList<>();
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
if (controller.hasOpponent(playerId, game)) {
Player opponent = game.getPlayer(playerId);
if (opponent != null) {
int greatestPower = Integer.MIN_VALUE;
int numberOfCreatures = 0;
Permanent permanentToSacrifice = null;
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, playerId, game)) {
if (permanent.getPower().getValue() > greatestPower) {
greatestPower = permanent.getPower().getValue();
numberOfCreatures = 1;
permanentToSacrifice = permanent;
} else if (permanent.getPower().getValue() == greatestPower) {
numberOfCreatures++;
}
}
if (numberOfCreatures == 1) {
if (permanentToSacrifice != null) {
toSacrifice.add(permanentToSacrifice);
}
} else if (greatestPower != Integer.MIN_VALUE) {
FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent("creature to sacrifice with power equal to " + greatestPower);
filter.add(new PowerPredicate(ComparisonType.EQUAL_TO, greatestPower));
Target target = new TargetControlledCreaturePermanent(filter);
if (opponent.choose(outcome, target, playerId, game)) {
Permanent permanent = game.getPermanent(target.getFirstTarget());
if (permanent != null) {
toSacrifice.add(permanent);
}
}
}
}
}
}
for (Permanent permanent : toSacrifice) {
permanent.sacrifice(source, game);
}
return true;
}
return false;
}
use of mage.game.permanent.Permanent in project mage by magefree.
the class CradleOfVitalityEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getPermanent(source.getFirstTarget());
int lifeGained = 0;
if (this.getValue("gainedLife") != null) {
lifeGained = (Integer) this.getValue("gainedLife");
}
return permanent != null && lifeGained > 0 && permanent.addCounters(CounterType.P1P1.createInstance(lifeGained), source.getControllerId(), source, game);
}
use of mage.game.permanent.Permanent in project mage by magefree.
the class CounterbalanceEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
if (controller != null && sourcePermanent != null) {
Spell spell = (Spell) game.getStack().getStackObject(targetPointer.getFirst(game, source));
if (spell != null) {
Card topcard = controller.getLibrary().getFromTop(game);
if (topcard != null) {
CardsImpl cards = new CardsImpl();
cards.add(topcard);
controller.revealCards(sourcePermanent.getName(), cards, game);
if (topcard.getManaValue() == spell.getManaValue()) {
return game.getStack().counter(spell.getId(), source, game);
}
}
return true;
}
}
return false;
}
use of mage.game.permanent.Permanent in project mage by magefree.
the class CosmicHorrorEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Permanent cosmicHorror = game.getPermanentOrLKIBattlefield(source.getSourceId());
if (controller != null && cosmicHorror != null) {
StringBuilder sb = new StringBuilder(cost.getText()).append('?');
if (!sb.toString().toLowerCase(Locale.ENGLISH).startsWith("exile ") && !sb.toString().toLowerCase(Locale.ENGLISH).startsWith("return ")) {
sb.insert(0, "Pay ");
}
if (controller.chooseUse(Outcome.Benefit, sb.toString(), source, game)) {
cost.clearPaid();
if (cost.pay(source, game, source, source.getControllerId(), false, null)) {
return true;
}
}
if (cosmicHorror.destroy(source, game, false)) {
controller.damage(7, source.getSourceId(), source, game);
return true;
}
}
return false;
}
Aggregations