fixed implementation of Cradle of Vitality (fixes #6428)

This commit is contained in:
Evan Kranzler 2020-04-20 17:51:50 -04:00
parent 506b734235
commit 1f85dcb334
3 changed files with 27 additions and 60 deletions

View file

@ -1,40 +1,38 @@
package mage.cards.c;
import java.util.UUID;
import mage.abilities.Ability;
import mage.abilities.TriggeredAbilityImpl;
import mage.abilities.common.GainLifeControllerTriggeredAbility;
import mage.abilities.costs.mana.ManaCostsImpl;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.DoIfCostPaid;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.Outcome;
import mage.constants.Zone;
import mage.counters.CounterType;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.events.GameEvent.EventType;
import mage.game.permanent.Permanent;
import mage.target.common.TargetCreaturePermanent;
import java.util.UUID;
/**
*
* @author Alvin
* @author TheElk801
*/
public final class CradleOfVitality extends CardImpl {
public CradleOfVitality(UUID ownerId, CardSetInfo setInfo) {
super(ownerId,setInfo,new CardType[]{CardType.ENCHANTMENT},"{3}{W}");
super(ownerId, setInfo, new CardType[]{CardType.ENCHANTMENT}, "{3}{W}");
// Whenever you gain life, you may pay {1}{W}. If you do, put a +1/+1 counter on target creature for each 1 life you gained.
Ability ability = new CradleOfVitalityGainLifeTriggeredAbility();
Ability ability = new GainLifeControllerTriggeredAbility(new DoIfCostPaid(
new CradleOfVitalityEffect(), new ManaCostsImpl("{1}{W}")
), false);
ability.addTarget(new TargetCreaturePermanent());
this.addAbility(ability);
}
public CradleOfVitality(final CradleOfVitality card) {
private CradleOfVitality(final CradleOfVitality card) {
super(card);
}
@ -44,51 +42,14 @@ public final class CradleOfVitality extends CardImpl {
}
}
class CradleOfVitalityGainLifeTriggeredAbility extends TriggeredAbilityImpl {
public CradleOfVitalityGainLifeTriggeredAbility() {
super(Zone.BATTLEFIELD, new CradleOfVitalityEffect(), false);
addManaCost(new ManaCostsImpl("{1}{W}"));
}
public CradleOfVitalityGainLifeTriggeredAbility(final CradleOfVitalityGainLifeTriggeredAbility ability) {
super(ability);
}
@Override
public CradleOfVitalityGainLifeTriggeredAbility copy() {
return new CradleOfVitalityGainLifeTriggeredAbility(this);
}
@Override
public boolean checkEventType(GameEvent event, Game game) {
return event.getType() == EventType.GAINED_LIFE;
}
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (event.getPlayerId().equals(this.controllerId)) {
this.getEffects().get(0).setValue("amount", event.getAmount());
return true;
}
return false;
}
@Override
public String getRule() {
return "Whenever you gain life, you may pay {1}{W}. If you do, put a +1/+1 counter on target creature for each 1 life you gained";
}
}
class CradleOfVitalityEffect extends OneShotEffect {
public CradleOfVitalityEffect() {
CradleOfVitalityEffect() {
super(Outcome.Benefit);
staticText = "Put a +1/+1 counter on target creature for each 1 life you gained";
staticText = "put a +1/+1 counter on target creature for each 1 life you gained";
}
public CradleOfVitalityEffect(final CradleOfVitalityEffect effect) {
private CradleOfVitalityEffect(final CradleOfVitalityEffect effect) {
super(effect);
}
@ -99,13 +60,9 @@ class CradleOfVitalityEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
int affectedTargets = 0;
Integer amount = (Integer) getValue("amount");
for (UUID uuid : targetPointer.getTargets(game, source)) {
Permanent permanent = game.getPermanent(uuid);
permanent.addCounters(CounterType.P1P1.createInstance(amount), source, game);
affectedTargets ++;
}
return affectedTargets > 0;
Permanent permanent = game.getPermanent(source.getFirstTarget());
int lifeGained = (Integer) this.getValue("gainedLife");
return permanent != null && lifeGained > 0
&& permanent.addCounters(CounterType.P1P1.createInstance(lifeGained), source, game);
}
}

View file

@ -167,4 +167,7 @@ public class Effects extends ArrayList<Effect> {
}
}
public void setValue(String key, Object value) {
this.stream().forEach(effect -> effect.setValue(key, value));
}
}

View file

@ -167,6 +167,13 @@ public class DoIfCostPaid extends OneShotEffect {
return sb.append(costText).toString();
}
@Override
public void setValue(String key, Object value) {
super.setValue(key, value);
this.executingEffects.setValue(key, value);
this.otherwiseEffects.setValue(key, value);
}
@Override
public DoIfCostPaid copy() {
return new DoIfCostPaid(this);