use of mage.abilities.effects.common.GainLifeEffect in project mage by magefree.
the class OutcomesTest method test_FromAbility_Multi.
@Test
public void test_FromAbility_Multi() {
Ability abilityGood = new SimpleStaticAbility(new GainLifeEffect(10));
abilityGood.addEffect(new BoostSourceEffect(10, 10, Duration.EndOfTurn));
abilityGood.addCustomOutcome(Outcome.Detriment);
Assert.assertEquals(-1 + -1, abilityGood.getEffects().getOutcomeScore(abilityGood));
Ability abilityBad = new SimpleStaticAbility(new DamageTargetEffect(10));
abilityBad.addEffect(new ExileTargetEffect());
abilityBad.addCustomOutcome(Outcome.Neutral);
Assert.assertEquals(1 + 1, abilityBad.getEffects().getOutcomeScore(abilityBad));
}
use of mage.abilities.effects.common.GainLifeEffect in project mage by magefree.
the class SithEvokerEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Choice choice = new ChoiceImpl(true);
choice.setMessage("Choose mode");
choice.setChoices(choices);
if (!controller.choose(outcome, choice, game)) {
return false;
}
Card sourceCard = game.getCard(source.getSourceId());
if (sourceCard != null) {
for (Object cost : source.getCosts()) {
if (cost instanceof SacrificeTargetCost) {
Permanent p = (Permanent) game.getLastKnownInformation(((SacrificeTargetCost) cost).getPermanents().get(0).getId(), Zone.BATTLEFIELD);
if (p != null) {
String chosen = choice.getChoice();
switch(chosen) {
case "Gain life equal to creature's power":
new GainLifeEffect(p.getPower().getValue()).apply(game, source);
break;
default:
// "Gain life equal to creature's toughness"
new GainLifeEffect(p.getToughness().getValue()).apply(game, source);
break;
}
return true;
}
}
}
}
}
return false;
}
use of mage.abilities.effects.common.GainLifeEffect in project mage by magefree.
the class FlashConscriptionTriggeredAbility method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
DamagedEvent damageEvent = (DamagedEvent) event;
if (damageEvent.isCombatDamage()) {
if (event.getSourceId().equals(this.sourceId)) {
this.getEffects().clear();
this.getEffects().add(new GainLifeEffect(damageEvent.getAmount()));
return true;
}
}
return false;
}
use of mage.abilities.effects.common.GainLifeEffect in project mage by magefree.
the class OrimsPrayerTriggeredAbility method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
boolean applied = false;
Player controller = game.getPlayer(getControllerId());
if (controller == null) {
return false;
}
int numberAttackingController = 0;
for (UUID attackersId : game.getCombat().getAttackers()) {
Permanent attackingCreature = game.getPermanent(attackersId);
if (attackingCreature != null && game.getCombat().getDefenderId(attackersId) == this.getControllerId()) {
numberAttackingController += 1;
applied = true;
}
}
if (applied && numberAttackingController > 0) {
this.getEffects().clear();
this.getEffects().add(new GainLifeEffect(numberAttackingController));
}
return applied;
}
use of mage.abilities.effects.common.GainLifeEffect in project mage by magefree.
the class ShadowgrangeArchfiendEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
List<Permanent> toSacrifice = new ArrayList<>();
// Iterate through each opponent
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
if (!controller.hasOpponent(playerId, game)) {
continue;
}
Player opponent = game.getPlayer(playerId);
if (opponent == null) {
continue;
}
int greatestPower = Integer.MIN_VALUE;
int numberOfCreatures = 0;
Permanent creatureToSacrifice = null;
// Iterature through each creature
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, playerId, game)) {
if (permanent.getPower().getValue() > greatestPower) {
greatestPower = permanent.getPower().getValue();
numberOfCreatures = 1;
creatureToSacrifice = permanent;
} else if (permanent.getPower().getValue() == greatestPower) {
numberOfCreatures++;
}
}
// If multiple creatures are tied for having the greatest power
if (numberOfCreatures > 1) {
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)) {
creatureToSacrifice = game.getPermanent(target.getFirstTarget());
}
}
if (creatureToSacrifice != null) {
toSacrifice.add(creatureToSacrifice);
}
}
int greatestPowerAmongAllCreaturesSacked = Integer.MIN_VALUE;
int powerOfCurrentCreature;
// Sack the creatures and save the greaterest power amoung those which were sacked
for (Permanent permanent : toSacrifice) {
powerOfCurrentCreature = permanent.getPower().getValue();
// Try to sack it
if (permanent.sacrifice(source, game)) {
if (powerOfCurrentCreature > greatestPowerAmongAllCreaturesSacked) {
greatestPowerAmongAllCreaturesSacked = powerOfCurrentCreature;
}
}
}
// Gain life equal to the power of greatest creature sacked, if it is positive
if (greatestPowerAmongAllCreaturesSacked > 0) {
new GainLifeEffect(greatestPowerAmongAllCreaturesSacked).apply(game, source);
}
return true;
}
Aggregations